line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
5
|
|
|
5
|
|
53729
|
use strict; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
151
|
|
2
|
5
|
|
|
5
|
|
18
|
use warnings; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
246
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Maven::Maven; |
5
|
|
|
|
|
|
|
$Maven::Maven::VERSION = '1.13'; |
6
|
|
|
|
|
|
|
# ABSTRACT: The main interface to maven |
7
|
|
|
|
|
|
|
# PODNAME: Maven::Maven |
8
|
|
|
|
|
|
|
|
9
|
5
|
|
|
5
|
|
22
|
use Carp; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
329
|
|
10
|
5
|
|
|
5
|
|
2130
|
use Data::Dumper; |
|
5
|
|
|
|
|
24331
|
|
|
5
|
|
|
|
|
364
|
|
11
|
5
|
|
|
5
|
|
3069
|
use File::ShareDir; |
|
5
|
|
|
|
|
32250
|
|
|
5
|
|
|
|
|
341
|
|
12
|
5
|
|
|
5
|
|
2929
|
use Log::Any; |
|
5
|
|
|
|
|
25209
|
|
|
5
|
|
|
|
|
23
|
|
13
|
5
|
|
|
5
|
|
2417
|
use Maven::Repositories; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use Maven::SettingsLoader qw(load_settings); |
15
|
|
|
|
|
|
|
use Maven::Xml::Pom; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $logger = Log::Any->get_logger(); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new { |
20
|
|
|
|
|
|
|
return bless( {}, shift )->_init(@_); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub dot_m2 { |
24
|
|
|
|
|
|
|
return shift->user_home( '.m2', @_ ); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _default_agent { |
28
|
|
|
|
|
|
|
my ( $self, @options ) = @_; |
29
|
|
|
|
|
|
|
require LWP::UserAgent; |
30
|
|
|
|
|
|
|
my $agent = LWP::UserAgent->new(@options); |
31
|
|
|
|
|
|
|
$agent->env_proxy(); # because why not? |
32
|
|
|
|
|
|
|
return $agent; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _default_m2_home { |
36
|
|
|
|
|
|
|
return unless ( $ENV{M2_HOME} ); |
37
|
|
|
|
|
|
|
if ( $^O eq 'cygwin' ) { |
38
|
|
|
|
|
|
|
return Cygwin::win_to_posix_path( $ENV{M2_HOME} ); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
else { |
41
|
|
|
|
|
|
|
return $ENV{M2_HOME}; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _default_user_home { |
46
|
|
|
|
|
|
|
if ( $^O eq 'cygwin' ) { |
47
|
|
|
|
|
|
|
return Cygwin::win_to_posix_path( $ENV{USERPROFILE} ); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
elsif ( $^O eq 'MSWin32' ) { |
50
|
|
|
|
|
|
|
return $ENV{USERPROFILE}; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
else { |
53
|
|
|
|
|
|
|
return $ENV{HOME}; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub _init { |
58
|
|
|
|
|
|
|
my ( $self, %options ) = @_; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my $m2_home = $options{M2_HOME} || _default_m2_home(); |
61
|
|
|
|
|
|
|
$self->{properties} = { |
62
|
|
|
|
|
|
|
( $m2_home ? ( 'env.M2_HOME' => $m2_home ) : () ), |
63
|
|
|
|
|
|
|
'user.home' => $options{'user.home'} || _default_user_home() |
64
|
|
|
|
|
|
|
}; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
my $global_settings = $self->m2_home( 'conf', 'settings.xml' ); |
67
|
|
|
|
|
|
|
my $user_settings = $self->dot_m2('settings.xml'); |
68
|
|
|
|
|
|
|
$self->{settings} = |
69
|
|
|
|
|
|
|
load_settings( [ $global_settings, $user_settings ], $self->{properties} ); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# some day we should load pom... |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
$self->_load_active_profiles(); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my $agent = $options{agent} || $self->_default_agent(); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
$self->{repositories} = |
78
|
|
|
|
|
|
|
Maven::Repositories->new()->add_local( $self->{settings}->get_localRepository() ); |
79
|
|
|
|
|
|
|
foreach my $profile ( @{ $self->{active_profiles} } ) { |
80
|
|
|
|
|
|
|
my $repositories = $profile->get_repositories(); |
81
|
|
|
|
|
|
|
if ( $repositories && scalar(@$repositories) ) { |
82
|
|
|
|
|
|
|
foreach my $repository (@$repositories) { |
83
|
|
|
|
|
|
|
$self->{repositories}->add_repository( $repository->get_url(), agent => $agent ); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
return $self; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub get_property { |
92
|
|
|
|
|
|
|
my ( $self, $key ) = @_; |
93
|
|
|
|
|
|
|
$logger->tracef( 'get_property(\'%s\')', $key ); |
94
|
|
|
|
|
|
|
return $self->{properties}{$key} || $key; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub get_repositories { |
98
|
|
|
|
|
|
|
return $_[0]->{repositories}; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub get_settings { |
102
|
|
|
|
|
|
|
return $_[0]->{settings}; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub _is_active_profile { |
106
|
|
|
|
|
|
|
my ( $self, $profile ) = @_; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub _load_active_profiles { |
110
|
|
|
|
|
|
|
my ($self) = @_; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
my @active_profiles = (); |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
my %settings_active_profiles = |
115
|
|
|
|
|
|
|
$self->{settings}->get_activeProfiles() |
116
|
|
|
|
|
|
|
? map { $_ => 1 } @{ $self->{settings}->get_activeProfiles() } |
117
|
|
|
|
|
|
|
: (); |
118
|
|
|
|
|
|
|
foreach my $profile ( @{ $self->{settings}->{profiles} } ) { |
119
|
|
|
|
|
|
|
if ( $settings_active_profiles{ $profile->get_id() } ) { |
120
|
|
|
|
|
|
|
push( @active_profiles, $profile ); |
121
|
|
|
|
|
|
|
next; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# add support for other ways of being active... |
125
|
|
|
|
|
|
|
my $activation = $profile->get_activation(); |
126
|
|
|
|
|
|
|
if ($activation) { |
127
|
|
|
|
|
|
|
my $activeByDefault = $activation->get_activeByDefault(); |
128
|
|
|
|
|
|
|
if ( $activeByDefault && $activeByDefault =~ /^true$/i ) { |
129
|
|
|
|
|
|
|
push( @active_profiles, $profile ); |
130
|
|
|
|
|
|
|
next; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
# not using jdk, so lets ignore it |
134
|
|
|
|
|
|
|
# OS is complicated by cygwin, so we bow out for now... |
135
|
|
|
|
|
|
|
my $property = $activation->get_property(); |
136
|
|
|
|
|
|
|
if ( $property |
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
|
|
|
|
|
|
|
push( @active_profiles, $profile ); |
143
|
|
|
|
|
|
|
next; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
my $file = $activation->get_file(); |
146
|
|
|
|
|
|
|
if ($file) { |
147
|
|
|
|
|
|
|
my $missing = $file->get_missing(); |
148
|
|
|
|
|
|
|
if ( $missing && !-f $missing ) { |
149
|
|
|
|
|
|
|
push( @active_profiles, $profile ); |
150
|
|
|
|
|
|
|
next; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
my $exists = $file->get_exists(); |
153
|
|
|
|
|
|
|
if ( $exists && -f $exists ) { |
154
|
|
|
|
|
|
|
push( @active_profiles, $profile ); |
155
|
|
|
|
|
|
|
next; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
if (@active_profiles) { |
162
|
|
|
|
|
|
|
if ( $self->{active_profiles} ) { |
163
|
|
|
|
|
|
|
push( @{ $self->{active_profiles} }, @active_profiles ); |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
else { |
166
|
|
|
|
|
|
|
$self->{active_profiles} = \@active_profiles; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub m2_home { |
172
|
|
|
|
|
|
|
my ( $self, @parts ) = @_; |
173
|
|
|
|
|
|
|
return unless ( $self->{properties}{'env.M2_HOME'} ); |
174
|
|
|
|
|
|
|
return File::Spec->catdir( $self->{properties}{'env.M2_HOME'}, @parts ); |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub user_home { |
178
|
|
|
|
|
|
|
my ( $self, @parts ) = @_; |
179
|
|
|
|
|
|
|
return File::Spec->catdir( $self->{properties}{'user.home'}, @parts ); |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
1; |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
__END__ |