| 1 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | |||||||||||||
| 4 | package Maven::MvnAgent; | ||||||||||||
| 5 | 1 | $Maven::MvnAgent::VERSION = '1.12'; | |||||||||||
| 6 | # ABSTRACT: An agent for downloading artifacts using the mvn command | ||||||||||||
| 7 | # PODNAME: Maven::MvnAgent | ||||||||||||
| 8 | |||||||||||||
| 9 | 1 | ▶ | use parent qw(Maven::Agent); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | 1 | ▶ | use Carp qw(croak); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 1 | ▶ | use File::Copy qw(copy); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | 1 | ▶ | use Log::Any; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | 1 | use Maven::Command qw( | |||||||||||
| 15 | mvn_artifact_params | ||||||||||||
| 16 | mvn_command | ||||||||||||
| 17 | 1 | ▶ | ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | |||||||||||||
| 19 | 1 | my $logger = Log::Any->get_logger(); | |||||||||||
| 20 | |||||||||||||
| 21 | sub _artifact_command { | ||||||||||||
| 22 | |||||||||||||
| 23 | # [\%maven_options] $artifact @_ | ||||||||||||
| 24 | 3 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
_artifact_command: called CC=9 SCAR=22.1
| |||||||||||||
| 25 | 3 | ▶ | my $maven_options = ref( $_[0] ) eq 'HASH' ? shift : {}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 26 | 3 | my $artifact = shift; | |||||||||||
| 27 | |||||||||||||
| 28 | 3 | ▶ | if ( !$artifact->isa('Maven::Artifact') ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 29 | 2 | $artifact = Maven::Artifact->new($artifact); | |||||||||||
| 30 | } | ||||||||||||
| 31 | |||||||||||||
| 32 | 3 | ▶ | if ( !$maven_options->{'--settings'} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 33 | 2 | my $file = $self->{maven}->dot_m2('settings.xml'); | |||||||||||
| 34 | 2 | ▶ | $maven_options->{'--settings'} = | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 35 | $^O eq 'cygwin' | ||||||||||||
| 36 | ? Cygwin::posix_to_win_path($file) | ||||||||||||
| 37 | : $file; | ||||||||||||
| 38 | } | ||||||||||||
| 39 | 3 | ▶ | if ( !$maven_options->{'--global-settings'} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 40 | 2 | my $file = $self->{maven}->m2_home( 'conf', 'settings.xml' ); | |||||||||||
| 41 | 2 | ▶ | $maven_options->{'--global-settings'} = | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 42 | $^O eq 'cygwin' | ||||||||||||
| 43 | ? Cygwin::posix_to_win_path($file) | ||||||||||||
| 44 | : $file; | ||||||||||||
| 45 | } | ||||||||||||
| 46 | 3 | ▶ | if ( !$maven_options->{'-Duser.home'} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 47 | 2 | my $path = $self->{maven}->get_property('user.home'); | |||||||||||
| 48 | 2 | ▶ | $maven_options->{'-Duser.home'} = | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 49 | $^O eq 'cygwin' | ||||||||||||
| 50 | ? Cygwin::posix_to_win_path($path) | ||||||||||||
| 51 | : $path; | ||||||||||||
| 52 | } | ||||||||||||
| 53 | |||||||||||||
| 54 | 3 | return $self, $maven_options, $artifact, @_; | |||||||||||
| 55 | } | ||||||||||||
| 56 | |||||||||||||
| 57 | sub deploy { | ||||||||||||
| 58 | |||||||||||||
| 59 | # [\%maven_options], $artifact, $file, $repository_id, $repository_url, [%options] | ||||||||||||
| 60 | 0 | ▶ | my ( $self, @args ) = _artifact_command(@_); | ||||||||||
|
Subroutine
deploy: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 61 | 0 | $self->_run_or_die( $self->deploy_command(@args) ); | |||||||||||
| 62 | } | ||||||||||||
| 63 | |||||||||||||
| 64 | sub deploy_command { | ||||||||||||
| 65 | |||||||||||||
| 66 | # [\%maven_options], $artifact, $file, $repository_id, $repository_url, [%options] | ||||||||||||
| 67 | 0 | ▶ | my ( $self, $maven_options, $artifact, $file, $repository_id, $repository_url, %options ) = | ||||||||||
|
Subroutine
deploy_command: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 68 | _artifact_command(@_); | ||||||||||||
| 69 | |||||||||||||
| 70 | 0 | ▶ | my $maven_deploy_plugin_version = $options{maven_deploy_plugin_version} || '2.8.2'; | ||||||||||
|
Condition0%0/2
$options{'maven_deploy_plugin_version'} || '2.8.2'
MC/DC0%0/1
$options{'maven_deploy_plugin_version'} || '2.8.2'
$options{'maven_deploy_plugin_version'}
Truth table0%0/2
A
A= $options{'maven_deploy_plugin_version'}
| |||||||||||||
| 71 | |||||||||||||
| 72 | 0 | ▶ | return mvn_command( | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 73 | $maven_options, | ||||||||||||
| 74 | "org.apache.maven.plugins:maven-deploy-plugin:$maven_deploy_plugin_version:deploy-file", | ||||||||||||
| 75 | { mvn_artifact_params($artifact), | ||||||||||||
| 76 | file => $^O eq 'cygwin' | ||||||||||||
| 77 | ? Cygwin::posix_to_win_path($file) | ||||||||||||
| 78 | : $file, | ||||||||||||
| 79 | repositoryId => $repository_id, | ||||||||||||
| 80 | url => $repository_url | ||||||||||||
| 81 | } | ||||||||||||
| 82 | ); | ||||||||||||
| 83 | } | ||||||||||||
| 84 | |||||||||||||
| 85 | sub _download_remote { | ||||||||||||
| 86 | 0 | ▶ | my ( $self, $artifact, $file ) = @_; | ||||||||||
|
Subroutine
_download_remote: not called CC=3 SCAR=24.8
| |||||||||||||
| 87 | |||||||||||||
| 88 | 0 | my $uri = $self->get($artifact)->get_uri(); | |||||||||||
| 89 | |||||||||||||
| 90 | 0 | ▶ | if ($file) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 91 | 0 | ▶ | copy( $uri->path(), $file ) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 92 | || croak('failed to copy file $!'); | ||||||||||||
| 93 | } | ||||||||||||
| 94 | else { | ||||||||||||
| 95 | 0 | $file = $uri->path(); | |||||||||||
| 96 | } | ||||||||||||
| 97 | |||||||||||||
| 98 | 0 | return $file; | |||||||||||
| 99 | } | ||||||||||||
| 100 | |||||||||||||
| 101 | sub get { | ||||||||||||
| 102 | |||||||||||||
| 103 | # [\%maven_options], $artifact, [%options] | ||||||||||||
| 104 | 1 | ▶ | my ( $self, $maven_options, $artifact, %options ) = _artifact_command(@_); | ||||||||||
|
Subroutine
get: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 105 | |||||||||||||
| 106 | 1 | $self->_run_or_die( $self->get_command( $maven_options, $artifact, %options ) ); | |||||||||||
| 107 | |||||||||||||
| 108 | 1 | return $self->resolve_or_die( $artifact->get_coordinate() ); | |||||||||||
| 109 | } | ||||||||||||
| 110 | |||||||||||||
| 111 | sub get_command { | ||||||||||||
| 112 | |||||||||||||
| 113 | # [\%maven_options], $artifact, [%options] | ||||||||||||
| 114 | 2 | ▶ | my ( $self, $maven_options, $artifact, %options ) = _artifact_command(@_); | ||||||||||
|
Subroutine
get_command: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||
| 115 | |||||||||||||
| 116 | 2 | ▶ | my $maven_dependency_plugin_version = $options{maven_dependency_plugin_version} || '2.10'; | ||||||||||
|
Condition50%1/2
$options{'maven_dependency_plugin_version'} || '2.10'
MC/DC0%0/1
$options{'maven_dependency_plugin_version'} || '2.10'
$options{'maven_dependency_plugin_version'}
Truth table50%1/2
A
A= $options{'maven_dependency_plugin_version'}
| |||||||||||||
| 117 | |||||||||||||
| 118 | 2 | my @repositories = (); | |||||||||||
| 119 | 2 | foreach my $repository ( @{ $self->{maven}->get_repositories()->get_repositories() } ) { | |||||||||||
| 120 | 4 | ▶ | next if ( $repository->isa('Maven::LocalRepository') ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 121 | 2 | push( @repositories, $repository->get_url() ); | |||||||||||
| 122 | } | ||||||||||||
| 123 | |||||||||||||
| 124 | 2 | return mvn_command( | |||||||||||
| 125 | $maven_options, | ||||||||||||
| 126 | "org.apache.maven.plugins:maven-dependency-plugin:$maven_dependency_plugin_version:get", | ||||||||||||
| 127 | { mvn_artifact_params($artifact), remoteRepositories => join( ',', @repositories ) } | ||||||||||||
| 128 | ); | ||||||||||||
| 129 | } | ||||||||||||
| 130 | |||||||||||||
| 131 | sub _init { | ||||||||||||
| 132 | 4 | ▶ | my ( $self, %options ) = @_; | ||||||||||
|
Subroutine
_init: called CC=1 SCAR=0.0
| |||||||||||||
| 133 | |||||||||||||
| 134 | 4 | $self->Maven::Agent::_init(%options); | |||||||||||
| 135 | 4 | $self->{command_runner} = $options{command_runner}; | |||||||||||
| 136 | |||||||||||||
| 137 | 4 | return $self; | |||||||||||
| 138 | } | ||||||||||||
| 139 | |||||||||||||
| 140 | sub install { | ||||||||||||
| 141 | |||||||||||||
| 142 | # [\%maven_options], $artifact, $file, [%options] | ||||||||||||
| 143 | 0 | ▶ | my ( $self, @args ) = _artifact_command(@_); | ||||||||||
|
Subroutine
install: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 144 | 0 | $self->_run_or_die( $self->install_command(@args) ); | |||||||||||
| 145 | } | ||||||||||||
| 146 | |||||||||||||
| 147 | sub install_command { | ||||||||||||
| 148 | |||||||||||||
| 149 | # [\%maven_options], $artifact, $file, [%options] | ||||||||||||
| 150 | 0 | ▶ | my ( $self, $maven_options, $artifact, $file, %options ) = _artifact_command(@_); | ||||||||||
|
Subroutine
install_command: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 151 | |||||||||||||
| 152 | 0 | ▶ | my $maven_install_plugin_version = $options{maven_install_plugin_version} || '2.5.2'; | ||||||||||
|
Condition0%0/2
$options{'maven_install_plugin_version'} || '2.5.2'
MC/DC0%0/1
$options{'maven_install_plugin_version'} || '2.5.2'
$options{'maven_install_plugin_version'}
Truth table0%0/2
A
A= $options{'maven_install_plugin_version'}
| |||||||||||||
| 153 | |||||||||||||
| 154 | 0 | ▶ | return mvn_command( | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 155 | $maven_options, | ||||||||||||
| 156 | "org.apache.maven.plugins:maven-install-plugin:$maven_install_plugin_version:install-file", | ||||||||||||
| 157 | { mvn_artifact_params($artifact), | ||||||||||||
| 158 | file => $^O eq 'cygwin' | ||||||||||||
| 159 | ? Cygwin::posix_to_win_path($file) | ||||||||||||
| 160 | : $file | ||||||||||||
| 161 | } | ||||||||||||
| 162 | ); | ||||||||||||
| 163 | } | ||||||||||||
| 164 | |||||||||||||
| 165 | sub _run_or_die { | ||||||||||||
| 166 | 1 | ▶ | my ( $self, $command ) = @_; | ||||||||||
|
Subroutine
_run_or_die: called CC=3 SCAR=12.3
| |||||||||||||
| 167 | |||||||||||||
| 168 | 1 | ▶ | if ( $self->{command_runner} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 169 | 1 | &{ $self->{command_runner} }($command); | |||||||||||
| 170 | } | ||||||||||||
| 171 | else { | ||||||||||||
| 172 | 0 | my $output = `$command`; | |||||||||||
| 173 | 0 | $logger->tracef( "%s\n---- STDOUT ----\n%s\n---- END STDOUT ----", $command, $output ); | |||||||||||
| 174 | } | ||||||||||||
| 175 | |||||||||||||
| 176 | 1 | ▶ | croak( "Command [$command] failed: " . ( $? >> 8 ) ) if ($?); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 177 | } | ||||||||||||
| 178 | |||||||||||||
| 179 | 1 | 1; | |||||||||||
| 180 | |||||||||||||
| 181 | __END__ | ||||||||||||