line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
21103
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
59
|
|
2
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
98
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Maven::Agent; |
5
|
|
|
|
|
|
|
$Maven::Agent::VERSION = '1.13'; |
6
|
|
|
|
|
|
|
# ABSTRACT: A base agent for working with maven |
7
|
|
|
|
|
|
|
# PODNAME: Maven::Agent |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
9
|
use Carp qw(croak); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
138
|
|
10
|
2
|
|
|
2
|
|
1196
|
use File::Copy; |
|
2
|
|
|
|
|
8349
|
|
|
2
|
|
|
|
|
169
|
|
11
|
2
|
|
|
2
|
|
770
|
use Maven::Maven; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
|
|
|
|
|
|
return bless( {}, shift )->_init(@_); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub download { |
18
|
|
|
|
|
|
|
my ( $self, $artifact, %options ) = @_; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
if ( !ref($artifact) |
21
|
|
|
|
|
|
|
|| !$artifact->isa('Maven::Artifact') |
22
|
|
|
|
|
|
|
|| !$artifact->get_uri() ) |
23
|
|
|
|
|
|
|
{ |
24
|
|
|
|
|
|
|
$artifact = $self->resolve_or_die($artifact); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
if ( $self->is_local($artifact) ) { |
28
|
|
|
|
|
|
|
my $path = $artifact->get_uri()->path(); |
29
|
|
|
|
|
|
|
if ( $options{to} ) { |
30
|
|
|
|
|
|
|
my $file = _to_file( $options{to}, $artifact ); |
31
|
|
|
|
|
|
|
if ( $file ne $path ) { |
32
|
|
|
|
|
|
|
copy( $path, $file ); |
33
|
|
|
|
|
|
|
$path = $file; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
return $path; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
return $self->_download_remote( $artifact, $options{to} |
40
|
|
|
|
|
|
|
? _to_file( $options{to}, $artifact ) |
41
|
|
|
|
|
|
|
: () ); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _default_agent { |
45
|
|
|
|
|
|
|
my ( $self, @options ) = @_; |
46
|
|
|
|
|
|
|
require LWP::UserAgent; |
47
|
|
|
|
|
|
|
my $agent = LWP::UserAgent->new(@options); |
48
|
|
|
|
|
|
|
$agent->env_proxy(); # because why not? |
49
|
|
|
|
|
|
|
return $agent; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _download_remote { |
53
|
|
|
|
|
|
|
my ( $self, $artifact, $file ) = @_; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
$file ||= Maven::Agent::DownloadedFile->new(); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
$self->{agent}->get( $artifact->get_uri(), ':content_file' => "$file" ); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
return $file; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub get_maven { |
63
|
|
|
|
|
|
|
return shift->{maven}; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _init { |
67
|
|
|
|
|
|
|
my ( $self, %options ) = @_; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
$options{agent} = $self->_default_agent(%options) |
70
|
|
|
|
|
|
|
unless ( $options{agent} ); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
$self->{agent} = $options{agent}; |
73
|
|
|
|
|
|
|
$self->{maven} = Maven::Maven->new(%options); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
return $self; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub is_local { |
79
|
|
|
|
|
|
|
my ( $self, $artifact ) = @_; |
80
|
|
|
|
|
|
|
my $uri = $artifact->get_uri(); |
81
|
|
|
|
|
|
|
return ( $uri->scheme() =~ /^file$/i |
82
|
|
|
|
|
|
|
&& ( $uri->host() eq '' || $uri->host() =~ /^localhost$/ ) ); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub resolve { |
86
|
|
|
|
|
|
|
return shift->{maven}->get_repositories()->resolve(@_); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub resolve_or_die { |
90
|
|
|
|
|
|
|
return shift->{maven}->get_repositories()->resolve_or_die(@_); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _to_file { |
94
|
|
|
|
|
|
|
my ( $to, $artifact ) = @_; |
95
|
|
|
|
|
|
|
if ( -d $to ) { |
96
|
|
|
|
|
|
|
$to = File::Spec->catfile( $to, "$artifact->{artifactId}." . $artifact->get_packaging() ); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
return $to; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
package Maven::Agent::DownloadedFile; |
102
|
|
|
|
|
|
|
$Maven::Agent::DownloadedFile::VERSION = '1.13'; |
103
|
|
|
|
|
|
|
# Wraps a temp file to hold a reference so as to keep the destructor from |
104
|
|
|
|
|
|
|
# getting called. It will provide the filename when used as a string. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
use overload q{""} => 'filename', fallback => 1; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub new { |
109
|
|
|
|
|
|
|
my $self = bless( {}, shift ); |
110
|
|
|
|
|
|
|
my $file = File::Temp->new(); |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
$self->{handle} = $file; |
113
|
|
|
|
|
|
|
$self->{name} = $file->filename(); |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
return $self; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub filename { |
119
|
|
|
|
|
|
|
return $_[0]->{name}; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
__END__ |