Repository.pm

filter: Statementstmt 75.3% 52 / 69 Branchbran 34.6% 9 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 68.7% 11 / 16 Podpod 100% 4 / 4 totaltotal 66.0% 76 / 115 CC 14 SCAR 22.5
CC
14
Cov
64%
_build_url
23.5
resolve
7.7
contains
2.0
CRAP 9.5
« SettingsLoader.pm ↑ Summary Artifact.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::Repository;
5 5 $Maven::Repository::VERSION = '1.12';
6 # ABSTRACT: An repository from which to resolve artifacts
7 # PODNAME: Maven::Repository
8  
9 5 ▶use parent qw(Class::Accessor);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 __PACKAGE__->follow_best_practice;
11 5 __PACKAGE__->mk_ro_accessors(qw(agent url));
12  
13 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use Log::Any;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶use Maven::Artifact;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 ▶use Maven::Xml::Metadata;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 5 my $logger = Log::Any->get_logger();
19  
20 sub new {
21 20 ▶ return bless( {}, shift )->_init(@_);
Subroutine new: called CC=1 SCAR=0.0
Pod documented
22 }
23  
24 sub _build_url {
25 4 ▶ my ( $self, $artifact ) = @_;
Subroutine _build_url: called CC=9 SCAR=31.6
26  
27 my @url =
28 4 ( $self->{url}, split( /\./, $artifact->get_groupId() ), $artifact->get_artifactId() );
29  
30 4 my $artifact_name;
31 4 ▶ if ( !$artifact->get_version() ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($artifact->get_version) 0 4 4
32  
33 # no version specified, detect latest
34 0 $logger->trace('version not specified, detecting...');
35 0 my $version = $self->_detect_latest_version( join( '/', @url ) );
36  
37 0 ▶ return if ( !$version );
Branch: 1 branch
BranchTrueFalseTotal
unless $version 0 0 0
38  
39 0 $artifact->set_version($version);
40 }
41 4 ▶ if ( $artifact->get_version() =~ /^.*-SNAPSHOT$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($artifact->get_version =~ /^.*-SNAPSHOT$/) { } 0 4 4
42  
43 # snapshot version, detect most recent timestamp
44 0 my $snapshotVersion = $self->_detect_latest_snapshotVersion(
45 join( '/', @url, $artifact->get_version() ),
46 $artifact->get_packaging(),
47 $artifact->get_classifier()
48 );
49  
50 0 ▶ return if ( !$snapshotVersion );
Branch: 1 branch
BranchTrueFalseTotal
unless $snapshotVersion 0 0 0
51  
52 0 $artifact_name = join( '-', $artifact->get_artifactId(), $snapshotVersion->get_value() );
53 0 ▶ if ( $artifact->get_classifier() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($artifact->get_classifier) 0 0 0
54 0 $artifact_name .= '-' . $artifact->get_classifier();
55 }
56 0 $artifact_name .= '.' . $artifact->get_packaging();
57 }
58 else {
59 4 $artifact_name = join( '-', $artifact->get_artifactId(), $artifact->get_version() );
60 4 ▶ if ( $artifact->get_classifier() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($artifact->get_classifier) 0 4 4
61 0 $artifact_name .= '-' . $artifact->get_classifier();
62 }
63 4 $artifact_name .= '.' . $artifact->get_packaging();
64 }
65 4 $artifact->set_artifact_name($artifact_name);
66  
67 4 my $url = join( '/', @url, $artifact->get_version(), $artifact_name );
68  
69 # verify version is available in repo
70 4 ▶ $logger->tracef(
Branch: 1 branch
BranchTrueFalseTotal
if $logger->is_trace 0 4 4
71 'verifying version %s is available on %s',
72 $artifact->get_version(),
73 $self->to_string()
74 ) if ( $logger->is_trace() );
75 4 ▶ return $self->_has_version($url) ? $url : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->_has_version($url) ? : 4 0 4
76 }
77  
78 sub contains {
79 0 ▶ my ( $self, $url ) = @_;
Subroutine contains: not called CC=1 SCAR=6.9
Pod documented
80 0 return $self->{url} eq substr( $url, 0, length( $self->{url} ) );
81 }
82  
83 ▶sub _detect_latest_snapshotVersion {
Subroutine _detect_latest_snapshotVersion: not called CC=1 SCAR=0.0
84 }
85  
86 ▶sub _detect_latest_version {
Subroutine _detect_latest_version: not called CC=1 SCAR=0.0
87 }
88  
89 ▶sub _has_version {
Subroutine _has_version: not called CC=1 SCAR=0.0
90 }
91  
92 sub _init {
93 20 ▶ my ( $self, $url, %args ) = @_;
Subroutine _init: called CC=1 SCAR=0.0
94  
95 20 $self->{url} = $url;
96  
97 20 return $self;
98 }
99  
100 sub resolve {
101 4 ▶ my ( $self, $artifact, @parts ) = @_;
Subroutine resolve: called CC=6 SCAR=20.5
Pod documented
102  
103 4 ▶ if ( ref($artifact) eq 'Maven::Artifact' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $artifact eq 'Maven::Artifact') { } 0 4 4
104  
105 # already resolved, no need to do so again
106 0 ▶ return $artifact if ( $artifact->get_url() );
Branch: 1 branch
BranchTrueFalseTotal
if $artifact->get_url 0 0 0
107 }
108 else {
109 4 $artifact = Maven::Artifact->new( $artifact, @parts );
110 4 $logger->trace( 'resolving ', $artifact );
111 }
112 4 ▶ croak('invalid artifact, no groupId') if ( !$artifact->get_groupId() );
Branch: 1 branch
BranchTrueFalseTotal
unless $artifact->get_groupId 0 4 4
113 4 ▶ croak('invalid artifact, no artifactId') if ( !$artifact->get_artifactId() );
Branch: 1 branch
BranchTrueFalseTotal
unless $artifact->get_artifactId 0 4 4
114  
115 4 my $url = $self->_build_url($artifact);
116 4 ▶ if ( defined($url) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $url) 4 0 4
117 4 $artifact->set_url($url);
118 4 return $artifact;
119 }
120 0 return;
121 }
122  
123 sub to_string {
124 0 ▶ my ($self) = @_;
Subroutine to_string: not called CC=1 SCAR=6.9
Pod documented
125 0 return $self->{url};
126 }
127  
128 5 1;
129  
130 __END__
« SettingsLoader.pm ↑ Summary Artifact.pm »