Maven.pm

filter: Statementstmt 86.9% 93 / 107 Branchbran 64.7% 22 / 34 Conditioncond 45.7% 16 / 35 MC/DCmcdc 10.0% 2 / 20 Subroutinesub 95.4% 21 / 22 Podpod 100% 7 / 7 totaltotal 71.5% 161 / 225 CC 33 SCAR 27.1
CC
33
Cov
74%
_load_active_profiles
35.2
_init
9.3
_default_m2_home
6.8
CRAP 15.0
« RemoteRepository.pm ↑ Summary Xml/XmlFile.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::Maven;
5 5 $Maven::Maven::VERSION = '1.12';
6 # ABSTRACT: The main interface to maven
7 # PODNAME: Maven::Maven
8  
9 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use File::ShareDir;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use Log::Any;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use Maven::Repositories;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use Maven::SettingsLoader qw(load_settings);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶use Maven::Xml::Pom;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 5 my $logger = Log::Any->get_logger();
18  
19 sub new {
20 9 ▶ return bless( {}, shift )->_init(@_);
Subroutine new: called CC=1 SCAR=0.0
Pod documented
21 }
22  
23 sub dot_m2 {
24 14 ▶ return shift->user_home( '.m2', @_ );
Subroutine dot_m2: called CC=1 SCAR=0.0
Pod documented
25 }
26  
27 sub _default_agent {
28 6 ▶ my ( $self, @options ) = @_;
Subroutine _default_agent: called CC=1 SCAR=0.0
29 6 require LWP::UserAgent;
30 6 my $agent = LWP::UserAgent->new(@options);
31 6 $agent->env_proxy(); # because why not?
32 6 return $agent;
33 }
34  
35 sub _default_m2_home {
36 2 ▶ return unless ( $ENV{M2_HOME} );
Subroutine _default_m2_home: called CC=3 SCAR=19.2
Branch: 1 branch
BranchTrueFalseTotal
unless $ENV{"M2_HOME"} 2 0 2
37 0 ▶ if ( $^O eq 'cygwin' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'cygwin') { } 0 0 0
38 0 return Cygwin::win_to_posix_path( $ENV{M2_HOME} );
39 }
40 else {
41 0 return $ENV{M2_HOME};
42 }
43 }
44  
45 sub _default_user_home {
46 2 ▶ if ( $^O eq 'cygwin' ) {
Subroutine _default_user_home: called CC=3 SCAR=14.2
Branch: 2 branches
BranchTrueFalseTotal
if ($^O eq 'cygwin') { } 0 2 2
elsif ($^O eq 'MSWin32') { } 0 2 2
47 0 return Cygwin::win_to_posix_path( $ENV{USERPROFILE} );
48 }
49 elsif ( $^O eq 'MSWin32' ) {
50 0 return $ENV{USERPROFILE};
51 }
52 else {
53 2 return $ENV{HOME};
54 }
55 }
56  
57 sub _init {
58 9 ▶ my ( $self, %options ) = @_;
Subroutine _init: called CC=9 SCAR=22.3
59  
60 9 ▶ my $m2_home = $options{M2_HOME} || _default_m2_home();
Condition66%2/3
$options{'M2_HOME'} || _default_m2_home()
l!l&&r!l&&!r
702
MC/DC50%1/2
$options{'M2_HOME'} || _default_m2_home()
$options{'M2_HOME'} _default_m2_home()
Truth table66%2/3
A || B
A= $options{'M2_HOME'}B= _default_m2_home()
ABresult
1X1
011
000
61 $self->{properties} = {
62 ( $m2_home ? ( 'env.M2_HOME' => $m2_home ) : () ),
63 9 ▶ 'user.home' => $options{'user.home'} || _default_user_home()
Branch: 1 branch
BranchTrueFalseTotal
$m2_home ? : 7 2 9
Condition66%2/3
$options{'user.home'} || _default_user_home()
l!l&&r!l&&!r
720
MC/DC0%0/2
$options{'user.home'} || _default_user_home()
$options{'user.home'} _default_user_home()
Truth table66%2/3
A || B
A= $options{'user.home'}B= _default_user_home()
ABresult
1X1
011
000
64 };
65  
66 9 my $global_settings = $self->m2_home( 'conf', 'settings.xml' );
67 9 my $user_settings = $self->dot_m2('settings.xml');
68 $self->{settings} =
69 9 load_settings( [ $global_settings, $user_settings ], $self->{properties} );
70  
71 # some day we should load pom...
72  
73 9 $self->_load_active_profiles();
74  
75 9 ▶ my $agent = $options{agent} || $self->_default_agent();
Condition66%2/3
$options{'agent'} || $self->_default_agent
l!l&&r!l&&!r
630
MC/DC0%0/2
$options{'agent'} || $self->_default_agent
$options{'agent'} $self->_default_agent
Truth table66%2/3
A || B
A= $options{'agent'}B= $self->_default_agent
ABresult
1X1
011
000
76  
77 $self->{repositories} =
78 9 Maven::Repositories->new()->add_local( $self->{settings}->get_localRepository() );
79 9 foreach my $profile ( @{ $self->{active_profiles} } ) {
80 11 my $repositories = $profile->get_repositories();
81 11 ▶ if ( $repositories && scalar(@$repositories) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($repositories and scalar @$repositories) 11 0 11
Condition50%1/2
$repositories and scalar @$repositories
!ll
011
MC/DC0%0/1
$repositories and scalar @$repositories
$repositories
Truth table50%1/2
A
A= $repositories
Aresult
00
11
82 11 foreach my $repository (@$repositories) {
83 11 $self->{repositories}->add_repository( $repository->get_url(), agent => $agent );
84 }
85 }
86 }
87  
88 9 return $self;
89 }
90  
91 sub get_property {
92 3 ▶ my ( $self, $key ) = @_;
Subroutine get_property: called CC=2 SCAR=7.6
Pod documented
93 3 $logger->tracef( 'get_property(\'%s\')', $key );
94 3 ▶ return $self->{properties}{$key} || $key;
Condition33%1/3
$self->{'properties'}{$key} || $key
l!l&&r!l&&!r
300
MC/DC0%0/2
$self->{'properties'}{$key} || $key
$self->{'properties'}{$key} $key
Truth table33%1/3
A || B
A= $self->{'properties'}{$key}B= $key
ABresult
1X1
011
000
95 }
96  
97 sub get_repositories {
98 7 ▶ return $_[0]->{repositories};
Subroutine get_repositories: called CC=1 SCAR=0.0
Pod documented
99 }
100  
101 sub get_settings {
102 2 ▶ return $_[0]->{settings};
Subroutine get_settings: called CC=1 SCAR=0.0
Pod documented
103 }
104  
105 sub _is_active_profile {
106 0 ▶ my ( $self, $profile ) = @_;
Subroutine _is_active_profile: not called CC=1 SCAR=6.9
107 }
108  
109 sub _load_active_profiles {
110 9 ▶ my ($self) = @_;
Subroutine _load_active_profiles: called CC=19 SCAR=35.6
111  
112 9 my @active_profiles = ();
113  
114 my %settings_active_profiles =
115 $self->{settings}->get_activeProfiles()
116 9 ▶ ? map { $_ => 1 } @{ $self->{settings}->get_activeProfiles() }
Branch: 1 branch
BranchTrueFalseTotal
$self->{'settings'}->get_activeProfiles ? : 4 5 9
117 : ();
118 9 foreach my $profile ( @{ $self->{settings}->{profiles} } ) {
119 12 ▶ if ( $settings_active_profiles{ $profile->get_id() } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($settings_active_profiles{$profile->get_id}) 8 4 12
120 8 push( @active_profiles, $profile );
121 8 next;
122 }
123  
124 # add support for other ways of being active...
125 4 my $activation = $profile->get_activation();
126 4 ▶ if ($activation) {
Branch: 1 branch
BranchTrueFalseTotal
if ($activation) 4 0 4
127 4 my $activeByDefault = $activation->get_activeByDefault();
128 4 ▶ if ( $activeByDefault && $activeByDefault =~ /^true$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($activeByDefault and $activeByDefault =~ /^true$/i) 3 1 4
Condition66%2/3
$activeByDefault and $activeByDefault =~ /^true$/i
!ll&&!rl&&r
103
MC/DC50%1/2
$activeByDefault and $activeByDefault =~ /^true$/i
$activeByDefault $activeByDefault =~ /^true$/i
Truth table66%2/3
A and B
A= $activeByDefaultB= $activeByDefault =~ /^true$/i
ABresult
0X0
100
111
129 3 push( @active_profiles, $profile );
130 3 next;
131 }
132  
133 # not using jdk, so lets ignore it
134 # OS is complicated by cygwin, so we bow out for now...
135 1 my $property = $activation->get_property();
136 1 ▶ if ( $property
Branch: 1 branch
BranchTrueFalseTotal
if ($property and $property->get_name and $property->get_value and $self->{"properties"}{$property->get_name} and $self->{"properties"}{$property->get_name} eq $property->get_value) 0 1 1
Condition33%4/12
$property and $property->get_name and $property->get_value and $self->{"properties"}{$property->get_name} and $self->{"properties"}{$property->get_name} eq $property->get_value
!ll&&!rl&&r
100
$property and $property->get_name and $property->get_value and $self->{"properties"}{$property->get_name}
!ll&&!rl&&r
100
$property and $property->get_name and $property->get_value
!ll&&!rl&&r
100
$property and $property->get_name
!ll&&!rl&&r
010
MC/DC0%0/5
$property and $property->get_name and $property->get_value and $self->{"properties"}{$property->get_name} and $self->{"properties"}{$property->get_name} eq $property->get_value
$property $property->get_name $property->get_value $self->{"properties"}{$property->get_name} $self->{"properties"}{$property->get_name} eq $property->get_value
Truth table16%1/6
A and B and C and D and E
A= $propertyB= $property->get_nameC= $property->get_valueD= $self->{"properties"}{$property->get_name}E= $self->{"properties"}{$property->get_name} eq $property->get_value
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
137 && $property->get_name()
138 && $property->get_value()
139 && $self->{properties}{ $property->get_name() }
140 && $self->{properties}{ $property->get_name() } eq $property->get_value() )
141 {
142 0 push( @active_profiles, $profile );
143 0 next;
144 }
145 1 my $file = $activation->get_file();
146 1 ▶ if ($file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file) 1 0 1
147 1 my $missing = $file->get_missing();
148 1 ▶ if ( $missing && !-f $missing ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($missing and not -f $missing) 0 1 1
Condition33%1/3
$missing and not -f $missing
!ll&&!rl&&r
100
MC/DC0%0/2
$missing and not -f $missing
$missing not -f $missing
Truth table33%1/3
A and not(B)
A= $missingB= not -f $missing
ABresult
0X0
100
111
149 0 push( @active_profiles, $profile );
150 0 next;
151 }
152 1 my $exists = $file->get_exists();
153 1 ▶ if ( $exists && -f $exists ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exists and -f $exists) 0 1 1
Condition33%1/3
$exists and -f $exists
!ll&&!rl&&r
100
MC/DC0%0/2
$exists and -f $exists
$exists -f $exists
Truth table33%1/3
A and B
A= $existsB= -f $exists
ABresult
0X0
100
111
154 0 push( @active_profiles, $profile );
155 0 next;
156 }
157 }
158 }
159 }
160  
161 9 ▶ if (@active_profiles) {
Branch: 1 branch
BranchTrueFalseTotal
if (@active_profiles) 7 2 9
162 7 ▶ if ( $self->{active_profiles} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'active_profiles'}) { } 0 7 7
163 0 push( @{ $self->{active_profiles} }, @active_profiles );
164 }
165 else {
166 7 $self->{active_profiles} = \@active_profiles;
167 }
168 }
169 }
170  
171 sub m2_home {
172 12 ▶ my ( $self, @parts ) = @_;
Subroutine m2_home: called CC=2 SCAR=6.9
Pod documented
173 12 ▶ return unless ( $self->{properties}{'env.M2_HOME'} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"properties"}{"env.M2_HOME"} 2 10 12
174 10 return File::Spec->catdir( $self->{properties}{'env.M2_HOME'}, @parts );
175 }
176  
177 sub user_home {
178 14 ▶ my ( $self, @parts ) = @_;
Subroutine user_home: called CC=1 SCAR=0.0
Pod documented
179 14 return File::Spec->catdir( $self->{properties}{'user.home'}, @parts );
180 }
181  
182 5 1;
183  
184 __END__
« RemoteRepository.pm ↑ Summary Xml/XmlFile.pm »