LocalRepository.pm

filter: Statementstmt 51.2% 40 / 78 Branchbran 8.3% 2 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 73.3% 11 / 15 Podpod n/a totaltotal 45.3% 53 / 117 CC 13 SCAR 34.7
CC
13
Cov
41%
_list_versions
90.0
_by_maven_version
12.0
_init
2.0
CRAP 32.1
↑ Summary RemoteRepository.pm »
1 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Maven::LocalRepository;
5 5 $Maven::LocalRepository::VERSION = '1.12';
6 # ABSTRACT: An local repository from which to resolve artifacts
7 # PODNAME: Maven::LocalRepository
8  
9 5 ▶use parent qw(Maven::Repository);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 __PACKAGE__->follow_best_practice;
11 5 __PACKAGE__->mk_ro_accessors(qw(url));
12  
13 5 ▶use Log::Any;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use Maven::Xml::Metadata;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶use Maven::Xml::Settings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 ▶use Sort::Versions;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use URI::file;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 5 my $logger = Log::Any->get_logger();
20  
21 sub _by_maven_version {
22 0 ▶ if ( $a =~ /^$b-SNAPSHOT$/ ) {
Subroutine _by_maven_version: not called CC=3 SCAR=24.8
Branch: 2 branches
BranchTrueFalseTotal
if ($a =~ /^$b-SNAPSHOT$/) { } 0 0 0
elsif ($b =~ /^$a-SNAPSHOT$/) { } 0 0 0
23 0 return -1;
24 }
25 elsif ( $b =~ /^$a-SNAPSHOT$/ ) {
26 0 return 1;
27 }
28 else {
29 0 return versioncmp( $a, $b );
30 }
31 }
32  
33 sub _detect_latest_snapshotVersion {
34 0 ▶ my ( $self, $base_url, $extension, $classifier ) = @_;
Subroutine _detect_latest_snapshotVersion: not called CC=1 SCAR=6.9
35  
36 0 $logger->tracef( 'loading snapshot metadata from %s', $base_url );
37 0 my @versions = sort _by_maven_version $self->_list_versions( $base_url, 1 );
38  
39 0 return pop(@versions);
40 }
41  
42 sub _detect_latest_version {
43 0 ▶ my ( $self, $base_url ) = @_;
Subroutine _detect_latest_version: not called CC=1 SCAR=6.9
44  
45 0 $logger->tracef( 'loading metadata from %s', $base_url );
46 0 my @versions = sort _by_maven_version $self->_list_versions($base_url);
47  
48 0 return pop(@versions);
49 }
50  
51 sub _has_version {
52 4 ▶ my ( $self, $url ) = @_;
Subroutine _has_version: called CC=2 SCAR=7.0
53  
54 4 my $has_version = ( -f $self->_path_from_url($url) );
55 4 ▶ $logger->debugf( 'version %s at %s', ( $has_version ? 'found' : 'not found' ), $url );
Branch: 1 branch
BranchTrueFalseTotal
$has_version ? : 4 0 4
56  
57 4 return $has_version;
58 }
59  
60 sub _init {
61 9 ▶ my ( $self, $local_repository_path, @args ) = @_;
Subroutine _init: called CC=2 SCAR=7.1
62  
63 9 ▶ $self->Maven::Repository::_init(
Branch: 1 branch
BranchTrueFalseTotal
$^O =~ /^cygwin$/i ? : 0 9 9
64 URI::file->new(
65 $^O =~ /^cygwin$/i
66  
67 #? Cygwin::win_to_posix_path($local_repository_path)
68 ? `cygpath -u $local_repository_path`
69 : $local_repository_path
70 )->as_string()
71 );
72  
73 9 return $self;
74 }
75  
76 sub _list_versions {
77 0 ▶ my ( $self, $base_url, $snapshot ) = @_;
Subroutine _list_versions: not called CC=9 SCAR=45.0
78 0 my $base_path = $self->_path_from_url($base_url);
79  
80 0 my ( $artifact, $version );
81 0 ▶ if ($snapshot) {
Branch: 1 branch
BranchTrueFalseTotal
if ($snapshot) 0 0 0
82 0 my @parts = File::Spec->splitdir($base_path);
83 0 $version = pop(@parts);
84 0 $artifact = pop(@parts);
85 0 $version =~ s/-SNAPSHOT$//;
86 }
87  
88 0 my @versions = ();
89 0 ▶ opendir( my $dir_handle, $base_path ) || return ();
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dir_handle, $base_path or return () 0 0 0
90 0 ▶ while ( my $entry = readdir($dir_handle) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $entry = readdir $dir_handle)) 0 0 0
91 0 ▶ next if ( $entry =~ /^\.+$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $entry =~ /^\.+$/ 0 0 0
92 0 my $path = File::Spec->catdir( $base_path, $entry );
93 0 ▶ if ($snapshot) {
Branch: 1 branch
BranchTrueFalseTotal
if ($snapshot) { } 0 0 0
94 0 ▶ if ( $path =~ /.*\/$artifact-$version-(.*)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ m[.*/$artifact-$version-(.*)]) 0 0 0
95 0 my $rest = $1;
96 0 ▶ if ( $rest =~ /^SNAPSHOT(?:-(.*?))?\.([^\.]*)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rest =~ /^SNAPSHOT(?:-(.*?))?\.([^\.]*)$/) 0 0 0
97 0 my $snapshotVersion = Maven::Xml::Metadata::SnapshotVersion->new();
98 0 $snapshotVersion->{value} = "$version-SNAPSHOT";
99 0 $snapshotVersion->{extension} = $2;
100 0 $snapshotVersion->{classifier} = $1;
101 0 push( @versions, $snapshotVersion );
102 }
103 }
104 }
105 else {
106 0 ▶ if ( -d $path ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $path) 0 0 0
107 0 push( @versions, $entry );
108 }
109 }
110 }
111 0 closedir($dir_handle);
112 0 return @versions;
113 }
114  
115 sub _path_from_url {
116 4 ▶ my ( $self, $url ) = @_;
Subroutine _path_from_url: called CC=1 SCAR=0.0
117 4 my $path = URI->new($url)->path();
118  
119 # if windows, we have to strip the leading /
120 # from /C:/...
121 4 $path =~ s/^\/([A-Za-z]:)/$1/;
122  
123 4 return $path;
124 }
125  
126 5 1;
127  
128 __END__
↑ Summary RemoteRepository.pm »