diff --git a/pom.xml b/pom.xml
index 1284f13..385b4d9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -63,10 +63,10 @@ under the License.
+ 7
3.2.5
1.7.5
1.0.0.v20140518
- 7
2021-12-27T14:11:19Z
@@ -102,16 +102,6 @@ under the License.
${slf4jVersion}
provided
-
- org.apache.maven.shared
- maven-artifact-transfer
- 0.13.1
-
-
- commons-io
- commons-io
- 2.6
-
org.codehaus.plexus
plexus-utils
@@ -121,11 +111,13 @@ under the License.
org.eclipse.aether
aether-api
${resolverVersion}
+ provided
org.eclipse.aether
aether-util
${resolverVersion}
+ compile
diff --git a/src/main/java/org/apache/maven/plugins/deploy/AbstractDeployMojo.java b/src/main/java/org/apache/maven/plugins/deploy/AbstractDeployMojo.java
index 3939a8e..6fe7f60 100644
--- a/src/main/java/org/apache/maven/plugins/deploy/AbstractDeployMojo.java
+++ b/src/main/java/org/apache/maven/plugins/deploy/AbstractDeployMojo.java
@@ -19,16 +19,28 @@
* under the License.
*/
+import java.util.List;
+
+import org.apache.maven.RepositoryUtils;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.artifact.repository.MavenArtifactRepository;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.project.artifact.ProjectArtifactMetadata;
import org.apache.maven.rtinfo.RuntimeInformation;
+import org.eclipse.aether.RepositorySystem;
+import org.eclipse.aether.deployment.DeployRequest;
+import org.eclipse.aether.deployment.DeploymentException;
+import org.eclipse.aether.repository.RemoteRepository;
+import org.eclipse.aether.util.artifact.SubArtifact;
import org.eclipse.aether.util.version.GenericVersionScheme;
import org.eclipse.aether.version.InvalidVersionSpecificationException;
import org.eclipse.aether.version.Version;
@@ -37,9 +49,8 @@
* Abstract class for Deploy mojo's.
*/
public abstract class AbstractDeployMojo
- extends AbstractMojo
+ extends AbstractMojo
{
-
/**
* Flag whether Maven is currently in online/offline mode.
*/
@@ -49,17 +60,20 @@ public abstract class AbstractDeployMojo
/**
* Parameter used to control how many times a failed deployment will be retried before giving up and failing. If a
* value outside the range 1-10 is specified it will be pulled to the nearest value within the range 1-10.
- *
+ *
* @since 2.7
*/
@Parameter( property = "retryFailedDeploymentCount", defaultValue = "1" )
private int retryFailedDeploymentCount;
+ @Component
+ private RuntimeInformation runtimeInformation;
+
@Parameter( defaultValue = "${session}", readonly = true, required = true )
- private MavenSession session;
+ protected MavenSession session;
@Component
- private RuntimeInformation runtimeInformation;
+ protected RepositorySystem repositorySystem;
private static final String AFFECTED_MAVEN_PACKAGING = "maven-plugin";
@@ -68,7 +82,7 @@ public abstract class AbstractDeployMojo
/* Setters and Getters */
void failIfOffline()
- throws MojoFailureException
+ throws MojoFailureException
{
if ( offline )
{
@@ -76,20 +90,10 @@ void failIfOffline()
}
}
- int getRetryFailedDeploymentCount()
- {
- return retryFailedDeploymentCount;
- }
-
protected ArtifactRepository createDeploymentArtifactRepository( String id, String url )
{
return new MavenArtifactRepository( id, url, new DefaultRepositoryLayout(), new ArtifactRepositoryPolicy(),
- new ArtifactRepositoryPolicy() );
- }
-
- protected final MavenSession getSession()
- {
- return session;
+ new ArtifactRepositoryPolicy() );
}
protected void warnIfAffectedPackagingAndMaven( final String packaging )
@@ -116,4 +120,88 @@ protected void warnIfAffectedPackagingAndMaven( final String packaging )
}
}
}
+
+ private RemoteRepository getRemoteRepository( ArtifactRepository remoteRepository )
+ {
+ RemoteRepository aetherRepo = RepositoryUtils.toRepo( remoteRepository );
+
+ if ( aetherRepo.getAuthentication() == null || aetherRepo.getProxy() == null )
+ {
+ RemoteRepository.Builder builder = new RemoteRepository.Builder( aetherRepo );
+
+ if ( aetherRepo.getAuthentication() == null )
+ {
+ builder.setAuthentication( session.getRepositorySession().getAuthenticationSelector()
+ .getAuthentication( aetherRepo ) );
+ }
+
+ if ( aetherRepo.getProxy() == null )
+ {
+ builder.setProxy( session.getRepositorySession().getProxySelector().getProxy( aetherRepo ) );
+ }
+
+ aetherRepo = builder.build();
+ }
+
+ return aetherRepo;
+ }
+
+ protected DeployRequest deployRequest( ArtifactRepository repository, List artifacts )
+ {
+ DeployRequest deployRequest = new DeployRequest();
+ deployRequest.setRepository( getRemoteRepository( repository ) );
+ for ( Artifact artifact : artifacts )
+ {
+ org.eclipse.aether.artifact.Artifact aetherArtifact = RepositoryUtils.toArtifact( artifact );
+ deployRequest.addArtifact( aetherArtifact );
+
+ for ( ArtifactMetadata metadata : artifact.getMetadataList() )
+ {
+ if ( metadata instanceof ProjectArtifactMetadata )
+ {
+ org.eclipse.aether.artifact.Artifact pomArtifact = new SubArtifact( aetherArtifact, "", "pom" );
+ pomArtifact = pomArtifact.setFile( ( (ProjectArtifactMetadata) metadata ).getFile() );
+ deployRequest.addArtifact( pomArtifact );
+ }
+ }
+ }
+ return deployRequest;
+ }
+
+ protected void deploy( DeployRequest deployRequest ) throws MojoExecutionException
+ {
+ int retryFailedDeploymentCounter = Math.max( 1, Math.min( 10, retryFailedDeploymentCount ) );
+ DeploymentException exception = null;
+ for ( int count = 0; count < retryFailedDeploymentCounter; count++ )
+ {
+ try
+ {
+ if ( count > 0 )
+ {
+ getLog().info( "Retrying deployment attempt " + ( count + 1 ) + " of "
+ + retryFailedDeploymentCounter );
+ }
+
+ repositorySystem.deploy( session.getRepositorySession(), deployRequest );
+ exception = null;
+ break;
+ }
+ catch ( DeploymentException e )
+ {
+ if ( count + 1 < retryFailedDeploymentCounter )
+ {
+ getLog().warn( "Encountered issue during deployment: " + e.getLocalizedMessage() );
+ getLog().debug( e.getMessage() );
+ }
+ if ( exception == null )
+ {
+ exception = e;
+ }
+ }
+ }
+ if ( exception != null )
+ {
+ throw new MojoExecutionException( exception.getMessage(), exception );
+ }
+ }
}
diff --git a/src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java b/src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java
index 12267e7..eb2e42d 100644
--- a/src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java
+++ b/src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java
@@ -34,6 +34,7 @@
import java.util.jar.JarFile;
import java.util.regex.Pattern;
+import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Model;
@@ -54,11 +55,6 @@
import org.apache.maven.project.ProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.artifact.ProjectArtifactMetadata;
-import org.apache.maven.shared.transfer.artifact.DefaultArtifactCoordinate;
-import org.apache.maven.shared.transfer.artifact.deploy.ArtifactDeployer;
-import org.apache.maven.shared.transfer.artifact.deploy.ArtifactDeployerException;
-import org.apache.maven.shared.transfer.repository.RepositoryManager;
-import org.apache.maven.shared.utils.Os;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.ReaderFactory;
@@ -75,8 +71,7 @@
public class DeployFileMojo
extends AbstractDeployMojo
{
- @Component
- private ArtifactDeployer artifactDeployer;
+ private static final String LINE_SEP = System.getProperty( "line.separator" );
/**
* Used for attaching the artifacts to deploy to the project.
@@ -177,16 +172,6 @@ public class DeployFileMojo
@Parameter( property = "classifier" )
private String classifier;
- /**
- * Whether to deploy snapshots with a unique version or not.
- *
- * @deprecated As of Maven 3, this isn't supported anymore and this parameter is only present to break the build if
- * you use it!
- */
- @Parameter( property = "uniqueVersion" )
- @Deprecated
- private Boolean uniqueVersion;
-
/**
* A comma separated list of types for each of the extra side artifacts to deploy. If there is a mis-match in the
* number of entries in {@link #files} or {@link #classifiers}, then an error will be raised.
@@ -208,9 +193,6 @@ public class DeployFileMojo
@Parameter( property = "files" )
private String files;
- @Component
- private RepositoryManager repoManager;
-
void initProperties()
throws MojoExecutionException
{
@@ -310,13 +292,6 @@ void initProperties()
public void execute()
throws MojoExecutionException, MojoFailureException
{
- if ( uniqueVersion != null )
- {
- throw new MojoExecutionException( "You are using 'uniqueVersion' which has been removed"
- + " from the maven-deploy-plugin. "
- + "Please see the >>Major Version Upgrade to version 3.0.0<< on the plugin site." );
- }
-
failIfOffline();
if ( !file.exists() )
@@ -338,7 +313,7 @@ public void execute()
MavenProject project = createMavenProject();
Artifact artifact = project.getArtifact();
- if ( file.equals( getLocalRepoFile() ) )
+ if ( file.equals( getLocalRepoFile( artifact ) ) )
{
throw new MojoFailureException( "Cannot deploy artifact from the local repository: " + file );
}
@@ -472,23 +447,10 @@ public void execute()
}
}
- List attachedArtifacts = project.getAttachedArtifacts();
+ deployableArtifacts.addAll( project.getAttachedArtifacts() );
- for ( Artifact attached : attachedArtifacts )
- {
- deployableArtifacts.add( attached );
- }
-
- try
- {
- warnIfAffectedPackagingAndMaven( packaging );
- artifactDeployer.deploy( getSession().getProjectBuildingRequest(), deploymentRepository,
- deployableArtifacts );
- }
- catch ( ArtifactDeployerException e )
- {
- throw new MojoExecutionException( e.getMessage(), e );
- }
+ warnIfAffectedPackagingAndMaven( packaging );
+ deploy( deployRequest( deploymentRepository, deployableArtifacts ) );
}
/**
@@ -513,7 +475,7 @@ private MavenProject createMavenProject()
+ "" + "" + artifactId + "" + "" + version + ""
+ "" + ( classifier == null ? packaging : "pom" ) + "" + "" );
DefaultProjectBuildingRequest buildingRequest =
- new DefaultProjectBuildingRequest( getSession().getProjectBuildingRequest() );
+ new DefaultProjectBuildingRequest( session.getProjectBuildingRequest() );
buildingRequest.setProcessPlugins( false );
try
{
@@ -523,7 +485,7 @@ private MavenProject createMavenProject()
{
if ( e.getCause() instanceof ModelBuildingException )
{
- throw new MojoExecutionException( "The artifact information is not valid:" + Os.LINE_SEP
+ throw new MojoExecutionException( "The artifact information is not valid:" + LINE_SEP
+ e.getCause().getMessage() );
}
throw new MojoFailureException( "Unable to create the project.", e );
@@ -536,16 +498,11 @@ private MavenProject createMavenProject()
*
* @return The absolute path to the artifact when installed, never null
.
*/
- private File getLocalRepoFile()
+ private File getLocalRepoFile( Artifact artifact )
{
- DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
- coordinate.setGroupId( groupId );
- coordinate.setArtifactId( artifactId );
- coordinate.setVersion( version );
- coordinate.setClassifier( classifier );
- coordinate.setExtension( packaging );
- String path = repoManager.getPathForLocalArtifact( getSession().getProjectBuildingRequest(), coordinate );
- return new File( repoManager.getLocalRepositoryBasedir( getSession().getProjectBuildingRequest() ), path );
+ String path = session.getRepositorySession().getLocalRepositoryManager().getPathForLocalArtifact(
+ RepositoryUtils.toArtifact( artifact ) );
+ return new File( session.getRepositorySession().getLocalRepository().getBasedir(), path );
}
/**
diff --git a/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java b/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
index bec6b38..98223ee 100644
--- a/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
+++ b/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
@@ -19,26 +19,25 @@
* under the License.
*/
+import java.io.File;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
-import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.ProjectBuildingRequest;
-import org.apache.maven.shared.transfer.artifact.deploy.ArtifactDeployerException;
-import org.apache.maven.shared.transfer.project.NoFileAssignedException;
-import org.apache.maven.shared.transfer.project.deploy.ProjectDeployer;
-import org.apache.maven.shared.transfer.project.deploy.ProjectDeployerRequest;
+import org.apache.maven.project.artifact.ProjectArtifactMetadata;
+import org.eclipse.aether.deployment.DeployRequest;
/**
* Deploys an artifact to remote repository.
@@ -128,12 +127,6 @@ public class DeployMojo
@Parameter( property = "maven.deploy.skip", defaultValue = "false" )
private String skip = Boolean.FALSE.toString();
- /**
- * Component used to deploy project.
- */
- @Component
- private ProjectDeployer projectDeployer;
-
private enum State
{
SKIPPED, DEPLOYED, TO_BE_DEPLOYED
@@ -175,7 +168,7 @@ private State getState( Map pluginContext )
private boolean hasState( MavenProject project )
{
- Map pluginContext = getSession().getPluginContext( pluginDescriptor, project );
+ Map pluginContext = session.getPluginContext( pluginDescriptor, project );
return pluginContext.containsKey( DEPLOY_PROCESSED_MARKER );
}
@@ -196,28 +189,16 @@ public void execute()
if ( !deployAtEnd )
{
- // CHECKSTYLE_OFF: LineLength
- // @formatter:off
- ProjectDeployerRequest pdr = new ProjectDeployerRequest()
- .setProject( project )
- .setRetryFailedDeploymentCount( getRetryFailedDeploymentCount() )
- .setAltReleaseDeploymentRepository( altReleaseDeploymentRepository )
- .setAltSnapshotDeploymentRepository( altSnapshotDeploymentRepository )
- .setAltDeploymentRepository( altDeploymentRepository );
- // @formatter:on
- // CHECKSTYLE_ON: LineLength
-
- ArtifactRepository repo = getDeploymentRepository( pdr );
-
- deployProject( getSession().getProjectBuildingRequest(), pdr, repo );
+ deploy( processProject( project,
+ altSnapshotDeploymentRepository, altReleaseDeploymentRepository, altDeploymentRepository ) );
putState( State.DEPLOYED );
}
else
{
- putState( State.TO_BE_DEPLOYED );
putPluginContextValue( DEPLOY_ALT_RELEASE_DEPLOYMENT_REPOSITORY, altReleaseDeploymentRepository );
putPluginContextValue( DEPLOY_ALT_SNAPSHOT_DEPLOYMENT_REPOSITORY, altSnapshotDeploymentRepository );
putPluginContextValue( DEPLOY_ALT_DEPLOYMENT_REPOSITORY, altDeploymentRepository );
+ putState( State.TO_BE_DEPLOYED );
getLog().info( "Deferring deploy for " + getProjectReferenceId( project ) + " at end" );
}
}
@@ -226,7 +207,7 @@ public void execute()
{
for ( MavenProject reactorProject : reactorProjects )
{
- Map pluginContext = getSession().getPluginContext( pluginDescriptor, reactorProject );
+ Map pluginContext = session.getPluginContext( pluginDescriptor, reactorProject );
State state = getState( pluginContext );
if ( state == State.TO_BE_DEPLOYED )
{
@@ -237,16 +218,9 @@ public void execute()
String altDeploymentRepository =
getPluginContextValue( pluginContext, DEPLOY_ALT_DEPLOYMENT_REPOSITORY );
- ProjectDeployerRequest pdr = new ProjectDeployerRequest()
- .setProject( reactorProject )
- .setRetryFailedDeploymentCount( getRetryFailedDeploymentCount() )
- .setAltReleaseDeploymentRepository( altReleaseDeploymentRepository )
- .setAltSnapshotDeploymentRepository( altSnapshotDeploymentRepository )
- .setAltDeploymentRepository( altDeploymentRepository );
-
- ArtifactRepository repo = getDeploymentRepository( pdr );
-
- deployProject( getSession().getProjectBuildingRequest(), pdr, repo );
+ deploy( processProject( reactorProject,
+ altSnapshotDeploymentRepository, altReleaseDeploymentRepository, altDeploymentRepository )
+ );
}
}
}
@@ -269,34 +243,71 @@ private boolean allProjectsMarked()
return true;
}
- private void deployProject( ProjectBuildingRequest pbr, ProjectDeployerRequest pir, ArtifactRepository repo )
- throws MojoFailureException, MojoExecutionException
+ private DeployRequest processProject( final MavenProject project,
+ final String altSnapshotDeploymentRepository,
+ final String altReleaseDeploymentRepository,
+ final String altDeploymentRepository )
+ throws MojoExecutionException, MojoFailureException
{
- try
+ ArrayList deployableArtifacts = new ArrayList<>();
+ Artifact artifact = project.getArtifact();
+ String packaging = project.getPackaging();
+ File pomFile = project.getFile();
+ List attachedArtifacts = project.getAttachedArtifacts();
+
+ // Deploy the POM
+ boolean isPomArtifact = "pom".equals( packaging );
+ if ( isPomArtifact )
{
- warnIfAffectedPackagingAndMaven( pir.getProject().getPackaging() );
- projectDeployer.deploy( pbr, pir, repo );
+ artifact.setFile( pomFile );
}
- catch ( NoFileAssignedException e )
+ else
{
- throw new MojoExecutionException( "NoFileAssignedException", e );
+ ProjectArtifactMetadata metadata = new ProjectArtifactMetadata( artifact, pomFile );
+ artifact.addMetadata( metadata );
}
- catch ( ArtifactDeployerException e )
+
+ if ( isPomArtifact )
{
- throw new MojoExecutionException( "ArtifactDeployerException", e );
+ deployableArtifacts.add( artifact );
}
+ else
+ {
+ File file = artifact.getFile();
+ if ( file != null && file.isFile() )
+ {
+ deployableArtifacts.add( artifact );
+ }
+ else if ( !attachedArtifacts.isEmpty() )
+ {
+ throw new MojoExecutionException( "The packaging plugin for this project did not assign "
+ + "a main file to the project but it has attachments. Change packaging to 'pom'." );
+ }
+ else
+ {
+ throw new MojoExecutionException( "The packaging for this project did not assign "
+ + "a file to the build artifact" );
+ }
+ }
+ deployableArtifacts.addAll( attachedArtifacts );
+ return deployRequest(
+ getDeploymentRepository( project,
+ altSnapshotDeploymentRepository, altReleaseDeploymentRepository, altDeploymentRepository ),
+ deployableArtifacts
+ );
}
- ArtifactRepository getDeploymentRepository( ProjectDeployerRequest pdr )
+ /**
+ * Visible for testing.
+ */
+ ArtifactRepository getDeploymentRepository( final MavenProject project,
+ final String altSnapshotDeploymentRepository,
+ final String altReleaseDeploymentRepository,
+ final String altDeploymentRepository )
throws MojoExecutionException, MojoFailureException
{
- MavenProject project = pdr.getProject();
- String altDeploymentRepository = pdr.getAltDeploymentRepository();
- String altReleaseDeploymentRepository = pdr.getAltReleaseDeploymentRepository();
- String altSnapshotDeploymentRepository = pdr.getAltSnapshotDeploymentRepository();
-
ArtifactRepository repo = null;
String altDeploymentRepo;
diff --git a/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java b/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java
index 371838b..d853870 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java
@@ -97,7 +97,8 @@ public void testBasicDeployFile()
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance( repositorySession, new LocalRepository( LOCAL_REPO ) ) );
when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
-
+ when( session.getRepositorySession() ).thenReturn( repositorySession );
+
String groupId = (String) getVariableValueFromObject( mojo, "groupId" );
String artifactId = (String) getVariableValueFromObject( mojo, "artifactId" );
@@ -199,6 +200,7 @@ public void testDeployIfClassifierIsSet()
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance( repositorySession, new LocalRepository( LOCAL_REPO ) ) );
when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
+ when( session.getRepositorySession() ).thenReturn( repositorySession );
String classifier = ( String ) getVariableValueFromObject( mojo, "classifier" );
@@ -248,6 +250,7 @@ public void testDeployIfArtifactIsNotJar()
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance( repositorySession, new LocalRepository( LOCAL_REPO ) ) );
when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
+ when( session.getRepositorySession() ).thenReturn( repositorySession );
String groupId = (String) getVariableValueFromObject( mojo, "groupId" );
diff --git a/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoUnitTest.java b/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoUnitTest.java
index 6131f79..a7bbd8b 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoUnitTest.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoUnitTest.java
@@ -19,36 +19,27 @@
* under the License.
*/
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
import org.apache.maven.plugin.MojoExecutionException;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
import java.io.File;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
/**
* @author Jerome Lacoste
*/
public class DeployFileMojoUnitTest
- extends TestCase
{
- public static void main( String[] args )
- {
- junit.textui.TestRunner.run( suite() );
- }
-
- public static Test suite()
- {
- TestSuite suite = new TestSuite( DeployFileMojoUnitTest.class );
-
- return suite;
- }
-
MockDeployFileMojo mojo;
Parent parent;
+ @Before
public void setUp()
{
Model pomModel = new Model();
@@ -62,12 +53,13 @@ public void setUp()
mojo = new MockDeployFileMojo( pomModel );
}
+ @After
public void tearDown()
{
mojo = null;
}
- class MockDeployFileMojo extends DeployFileMojo {
+ static class MockDeployFileMojo extends DeployFileMojo {
private Model model;
public MockDeployFileMojo(Model model) {
@@ -83,6 +75,7 @@ protected Model readModel(File pomFile) throws MojoExecutionException {
}
}
+ @Test
public void testProcessPomFromPomFileWithParent1() throws MojoExecutionException
{
mojo.setPomFile( new File( "foo.bar" ) );
@@ -98,6 +91,7 @@ public void testProcessPomFromPomFileWithParent1() throws MojoExecutionException
checkMojoProperties("parentGroup", null, "parentVersion", null);
}
+ @Test
public void testProcessPomFromPomFileWithParent2() throws MojoExecutionException
{
mojo.setPomFile( new File( "foo.bar" ) );
@@ -113,6 +107,7 @@ public void testProcessPomFromPomFileWithParent2() throws MojoExecutionException
}
+ @Test
public void testProcessPomFromPomFileWithParent3() throws MojoExecutionException
{
mojo.setPomFile( new File( "foo.bar" ) );
@@ -127,6 +122,7 @@ public void testProcessPomFromPomFileWithParent3() throws MojoExecutionException
checkMojoProperties( "parentGroup", "artifact", "version", null );
}
+ @Test
public void testProcessPomFromPomFileWithParent4() throws MojoExecutionException
{
mojo.setPomFile( new File( "foo.bar" ) );
@@ -137,6 +133,7 @@ public void testProcessPomFromPomFileWithParent4() throws MojoExecutionException
checkMojoProperties("parentGroup", "artifact", "version", "packaging");
}
+ @Test
public void testProcessPomFromPomFileWithParent5() throws MojoExecutionException
{
mojo.setPomFile( new File( "foo.bar" ) );
@@ -147,6 +144,7 @@ public void testProcessPomFromPomFileWithParent5() throws MojoExecutionException
checkMojoProperties("group", "artifact", "version", "packaging");
}
+ @Test
public void testProcessPomFromPomFileWithParent6() throws MojoExecutionException
{
mojo.setPomFile( new File( "foo.bar" ) );
@@ -158,6 +156,7 @@ public void testProcessPomFromPomFileWithParent6() throws MojoExecutionException
}
+ @Test
public void testProcessPomFromPomFileWithOverrides() throws MojoExecutionException
{
mojo.setPomFile( new File( "foo.bar" ) );
diff --git a/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java b/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
index c8350c4..49f645b 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
@@ -38,14 +38,13 @@
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
-import org.apache.maven.plugins.deploy.stubs.ArtifactDeployerStub;
import org.apache.maven.plugins.deploy.stubs.ArtifactRepositoryStub;
import org.apache.maven.plugins.deploy.stubs.DeployArtifactStub;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingRequest;
-import org.apache.maven.shared.transfer.project.deploy.ProjectDeployerRequest;
import org.codehaus.plexus.util.FileUtils;
import org.eclipse.aether.DefaultRepositorySystemSession;
+import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.repository.LocalRepository;
import org.junit.Ignore;
import org.mockito.InjectMocks;
@@ -142,7 +141,8 @@ public void testBasicDeploy()
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance( repositorySession, new LocalRepository( LOCAL_REPO ) ) );
when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
-
+ when( session.getRepositorySession() ).thenReturn( repositorySession );
+
File file = new File( getBasedir(),
"target/test-classes/unit/basic-deploy-test/target/" +
"deploy-test-file-1.0-SNAPSHOT.jar" );
@@ -317,6 +317,7 @@ public void testBasicDeployWithPackagingAsPom()
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance( repositorySession, new LocalRepository( LOCAL_REPO ) ) );
when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
+ when( session.getRepositorySession() ).thenReturn( repositorySession );
File pomFile = new File( getBasedir(),
"target/test-classes/unit/basic-deploy-pom/target/" +
@@ -431,6 +432,7 @@ public void testDeployWithAttachedArtifacts()
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance( repositorySession, new LocalRepository( LOCAL_REPO ) ) );
when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
+ when( session.getRepositorySession() ).thenReturn( repositorySession );
MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );
@@ -524,9 +526,9 @@ public void _testBasicDeployWithScpAsProtocol()
assertNotNull( mojo );
- ArtifactDeployerStub deployer = new ArtifactDeployerStub();
+ RepositorySystem repositorySystem = mock( RepositorySystem.class );
- setVariableValueToObject( mojo, "deployer", deployer );
+ setVariableValueToObject( mojo, "repositorySystem", repositorySystem );
File file = new File( getBasedir(),
"target/test-classes/unit/basic-deploy-scp/target/" +
@@ -573,19 +575,17 @@ public void testLegacyAltDeploymentRepositoryWithDefaultLayout()
{
DeployMojo mojo = spy( new DeployMojo() );
+ setVariableValueToObject( mojo, "project", project );
+ setVariableValueToObject( mojo, "altDeploymentRepository", "altDeploymentRepository::default::http://localhost" );
+
ArtifactRepository repository = mock( ArtifactRepository.class );
when( mojo.createDeploymentArtifactRepository( "altDeploymentRepository", "http://localhost"
) ).thenReturn( repository );
project.setVersion( "1.0-SNAPSHOT" );
- ProjectDeployerRequest pdr =
- new ProjectDeployerRequest()
- .setProject( project )
- .setAltDeploymentRepository( "altDeploymentRepository::default::http://localhost" );
-
assertEquals( repository,
- mojo.getDeploymentRepository( pdr ) );
+ mojo.getDeploymentRepository( project, null, null, "altDeploymentRepository::default::http://localhost") );
}
@@ -594,19 +594,18 @@ public void testLegacyAltDeploymentRepositoryWithLegacyLayout()
{
DeployMojo mojo = spy( new DeployMojo() );
+ setVariableValueToObject( mojo, "project", project );
+ setVariableValueToObject( mojo, "altDeploymentRepository", "altDeploymentRepository::legacy::http://localhost" );
+
ArtifactRepository repository = mock( ArtifactRepository.class );
when( mojo.createDeploymentArtifactRepository( "altDeploymentRepository", "http://localhost"
) ).thenReturn( repository );
project.setVersion( "1.0-SNAPSHOT" );
- ProjectDeployerRequest pdr =
- new ProjectDeployerRequest()
- .setProject( project )
- .setAltDeploymentRepository( "altDeploymentRepository::legacy::http://localhost" );
try
{
- mojo.getDeploymentRepository( pdr );
+ mojo.getDeploymentRepository( project, null, null, "altDeploymentRepository::legacy::http://localhost" );
fail( "Should throw: Invalid legacy syntax and layout for repository." );
}
catch( MojoFailureException e )
@@ -621,19 +620,17 @@ public void testInsaneAltDeploymentRepository()
{
DeployMojo mojo = spy( new DeployMojo() );
+ setVariableValueToObject( mojo, "project", project );
+ setVariableValueToObject( mojo, "altDeploymentRepository", "altDeploymentRepository::hey::wow::foo::http://localhost" );
+
ArtifactRepository repository = mock( ArtifactRepository.class );
when( mojo.createDeploymentArtifactRepository( "altDeploymentRepository", "http://localhost"
) ).thenReturn( repository );
project.setVersion( "1.0-SNAPSHOT" );
-
- ProjectDeployerRequest pdr =
- new ProjectDeployerRequest()
- .setProject( project )
- .setAltDeploymentRepository( "altDeploymentRepository::hey::wow::foo::http://localhost" );
try
{
- mojo.getDeploymentRepository( pdr );
+ mojo.getDeploymentRepository( project, null, null, "altDeploymentRepository::hey::wow::foo::http://localhost" );
fail( "Should throw: Invalid legacy syntax and layout for repository." );
}
catch( MojoFailureException e )
@@ -648,38 +645,34 @@ public void testDefaultScmSvnAltDeploymentRepository()
{
DeployMojo mojo = spy( new DeployMojo() );
+ setVariableValueToObject( mojo, "project", project );
+ setVariableValueToObject( mojo, "altDeploymentRepository", "altDeploymentRepository::default::scm:svn:http://localhost" );
+
ArtifactRepository repository = mock( ArtifactRepository.class );
when( mojo.createDeploymentArtifactRepository( "altDeploymentRepository", "scm:svn:http://localhost"
) ).thenReturn( repository );
project.setVersion( "1.0-SNAPSHOT" );
- ProjectDeployerRequest pdr =
- new ProjectDeployerRequest()
- .setProject( project )
- .setAltDeploymentRepository( "altDeploymentRepository::default::scm:svn:http://localhost" );
-
assertEquals( repository,
- mojo.getDeploymentRepository( pdr ) );
+ mojo.getDeploymentRepository( project, null, null, "altDeploymentRepository::default::scm:svn:http://localhost" ) );
}
public void testLegacyScmSvnAltDeploymentRepository()
throws Exception
{
DeployMojo mojo = spy( new DeployMojo() );
+ setVariableValueToObject( mojo, "project", project );
+ setVariableValueToObject( mojo, "altDeploymentRepository", "altDeploymentRepository::legacy::scm:svn:http://localhost" );
+
ArtifactRepository repository = mock( ArtifactRepository.class );
when( mojo.createDeploymentArtifactRepository( "altDeploymentRepository", "http://localhost"
) ).thenReturn( repository );
project.setVersion( "1.0-SNAPSHOT" );
-
- ProjectDeployerRequest pdr =
- new ProjectDeployerRequest()
- .setProject( project )
- .setAltDeploymentRepository( "altDeploymentRepository::legacy::scm:svn:http://localhost" );
try
{
- mojo.getDeploymentRepository( pdr );
+ mojo.getDeploymentRepository( project, null, null, "altDeploymentRepository::legacy::scm:svn:http://localhost" );
fail( "Should throw: Invalid legacy syntax and layout for repository." );
}
catch( MojoFailureException e )
@@ -694,18 +687,17 @@ public void testAltSnapshotDeploymentRepository()
{
DeployMojo mojo = spy( new DeployMojo() );
+ setVariableValueToObject( mojo, "project", project );
+ setVariableValueToObject( mojo, "altSnapshotDeploymentRepository", "altSnapshotDeploymentRepository::http://localhost" );
+
ArtifactRepository repository = mock( ArtifactRepository.class );
when( mojo.createDeploymentArtifactRepository( "altSnapshotDeploymentRepository", "http://localhost"
) ).thenReturn( repository );
project.setVersion( "1.0-SNAPSHOT" );
- ProjectDeployerRequest pdr =
- new ProjectDeployerRequest()
- .setProject( project )
- .setAltDeploymentRepository( "altSnapshotDeploymentRepository::http://localhost" );
assertEquals( repository,
- mojo.getDeploymentRepository( pdr ));
+ mojo.getDeploymentRepository( project, "altSnapshotDeploymentRepository::http://localhost", null, null ));
}
public void testAltReleaseDeploymentRepository()
@@ -713,18 +705,16 @@ public void testAltReleaseDeploymentRepository()
{
DeployMojo mojo = spy( new DeployMojo() );
+ setVariableValueToObject( mojo, "project", project );
+ setVariableValueToObject( mojo, "altReleaseDeploymentRepository", "altReleaseDeploymentRepository::http://localhost" );
+
ArtifactRepository repository = mock( ArtifactRepository.class );
when( mojo.createDeploymentArtifactRepository( "altReleaseDeploymentRepository", "http://localhost" ) ).thenReturn( repository );
project.setVersion( "1.0" );
- ProjectDeployerRequest pdr =
- new ProjectDeployerRequest()
- .setProject( project )
- .setAltReleaseDeploymentRepository( "altReleaseDeploymentRepository::http://localhost" );
-
assertEquals( repository,
- mojo.getDeploymentRepository( pdr ));
+ mojo.getDeploymentRepository( project, null, "altReleaseDeploymentRepository::http://localhost", null ));
}
private void addFileToList( File file, List fileList )
diff --git a/src/test/java/org/apache/maven/plugins/deploy/stubs/ArtifactDeployerStub.java b/src/test/java/org/apache/maven/plugins/deploy/stubs/ArtifactDeployerStub.java
deleted file mode 100644
index d0b47d4..0000000
--- a/src/test/java/org/apache/maven/plugins/deploy/stubs/ArtifactDeployerStub.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package org.apache.maven.plugins.deploy.stubs;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.util.Collection;
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.project.ProjectBuildingRequest;
-import org.apache.maven.shared.transfer.artifact.deploy.ArtifactDeployer;
-import org.apache.maven.shared.transfer.artifact.deploy.ArtifactDeployerException;
-
-public class ArtifactDeployerStub
- implements ArtifactDeployer
-{
-
- @Override
- public void deploy( ProjectBuildingRequest request, Collection mavenArtifacts )
- throws ArtifactDeployerException
- {
- // does nothing
- }
-
- @Override
- public void deploy( ProjectBuildingRequest arg0, ArtifactRepository arg1, Collection arg2)
- throws ArtifactDeployerException
- {
- // does nothing
- }
-}