diff --git a/pom.xml b/pom.xml
index bb3114c5..a58ad77c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -25,8 +25,7 @@ under the License.
org.apache.maven.plugins
maven-plugins
- 34
- ../../pom/maven/maven-plugins/pom.xml
+ 35-SNAPSHOT
maven-deploy-plugin
@@ -63,92 +62,64 @@ under the License.
- 3.0
- 7
+ 4.0.0-alpha-1-SNAPSHOT
+ 8
2021-12-27T14:11:19Z
org.apache.maven
- maven-plugin-api
- ${mavenVersion}
-
-
- org.apache.maven
- maven-core
+ maven-core-api
${mavenVersion}
+ provided
org.apache.maven
- maven-model
+ maven-model-builder
${mavenVersion}
+ provided
- org.apache.maven
- maven-artifact
- ${mavenVersion}
+ org.slf4j
+ slf4j-api
+ 1.7.5
+ provided
-
org.apache.maven.shared
- maven-artifact-transfer
- 0.13.1
-
-
-
- commons-io
- commons-io
- 2.5
-
-
-
-
- org.apache.maven.plugin-tools
- maven-plugin-annotations
- provided
+ maven-shared-utils
+ 4.0.0-SNAPSHOT
org.codehaus.plexus
plexus-utils
- 3.2.0
+
org.apache.maven.plugin-testing
maven-plugin-testing-harness
- 2.1
- test
-
-
- org.apache.maven
- maven-compat
- ${mavenVersion}
+ 3.4.0-SNAPSHOT
test
- org.mockito
- mockito-core
- 2.28.2
+ commons-io
+ commons-io
+ 2.6
test
- junit
- junit
- 4.13.1
+ org.apache.maven
+ maven-core
+ ${mavenVersion}
test
- org.sonatype.aether
- aether-connector-file
- 1.7
+ org.mockito
+ mockito-junit-jupiter
+ 2.28.2
test
-
- org.slf4j
- slf4j-api
- 1.7.5
- provided
-
org.slf4j
slf4j-nop
@@ -177,6 +148,11 @@ under the License.
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 3.0.0-M5
+
diff --git a/src/it/attach-jar-checksum-snapshot/verify.groovy b/src/it/attach-jar-checksum-snapshot/verify.groovy
index 0a4a14f9..df5425b1 100644
--- a/src/it/attach-jar-checksum-snapshot/verify.groovy
+++ b/src/it/attach-jar-checksum-snapshot/verify.groovy
@@ -67,7 +67,7 @@ filesInDirectory.each { existingFile ->
def result = false
pathsInTargetDirectory.each { searchItem ->
def expected = existingFile ==~ searchItem
- println "existingFile: ${existingFile} ${searchItem} expeced:${expected}"
+ println "existingFile: ${existingFile} ${searchItem} expected:${expected}"
if (expected) {
result = true
}
diff --git a/src/it/deploy-at-end-pass/module1/pom.xml b/src/it/deploy-at-end-pass/module1/pom.xml
index 1a91fc56..03d6c0d2 100644
--- a/src/it/deploy-at-end-pass/module1/pom.xml
+++ b/src/it/deploy-at-end-pass/module1/pom.xml
@@ -27,7 +27,7 @@
org.apache.maven.plugins
maven-enforcer-plugin
- 1.2
+ 3.0.0
enforce
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 f933e36c..e7088996 100644
--- a/src/main/java/org/apache/maven/plugins/deploy/AbstractDeployMojo.java
+++ b/src/main/java/org/apache/maven/plugins/deploy/AbstractDeployMojo.java
@@ -19,22 +19,24 @@
* under the License.
*/
-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.MojoFailureException;
-import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.api.RemoteRepository;
+import org.apache.maven.api.Session;
+import org.apache.maven.api.plugin.Mojo;
+import org.apache.maven.api.plugin.MojoException;
+import org.apache.maven.api.plugin.annotations.Parameter;
+import org.apache.maven.api.plugin.annotations.Component;
+import org.apache.maven.api.services.RepositoryFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Abstract class for Deploy mojo's.
*/
-public abstract class AbstractDeployMojo
- extends AbstractMojo
+public abstract class AbstractDeployMojo implements Mojo
{
+ protected Logger logger = LoggerFactory.getLogger( getClass() );
+
/**
* Flag whether Maven is currently in online/offline mode.
*/
@@ -50,17 +52,17 @@ public abstract class AbstractDeployMojo
@Parameter( property = "retryFailedDeploymentCount", defaultValue = "1" )
private int retryFailedDeploymentCount;
- @Parameter( defaultValue = "${session}", readonly = true, required = true )
- private MavenSession session;
+ @Component
+ private Session session;
/* Setters and Getters */
void failIfOffline()
- throws MojoFailureException
+ throws MojoException
{
if ( offline )
{
- throw new MojoFailureException( "Cannot deploy artifacts when Maven is in offline mode" );
+ throw new MojoException( "Cannot deploy artifacts when Maven is in offline mode" );
}
}
@@ -69,14 +71,15 @@ int getRetryFailedDeploymentCount()
return retryFailedDeploymentCount;
}
- protected ArtifactRepository createDeploymentArtifactRepository( String id, String url )
+ protected RemoteRepository createDeploymentArtifactRepository( String id, String url )
{
- return new MavenArtifactRepository( id, url, new DefaultRepositoryLayout(), new ArtifactRepositoryPolicy(),
- new ArtifactRepositoryPolicy() );
+ return getSession().getService( RepositoryFactory.class )
+ .createRemote( id, url );
}
- protected final MavenSession getSession()
+ protected Session getSession()
{
return session;
}
+
}
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 43044218..ea20d53e 100644
--- a/src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java
+++ b/src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java
@@ -19,6 +19,7 @@
* under the License.
*/
+import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
@@ -27,37 +28,36 @@
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Path;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.regex.Pattern;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.api.Artifact;
+import org.apache.maven.api.Project;
+import org.apache.maven.api.RemoteRepository;
+import org.apache.maven.api.plugin.MojoException;
+import org.apache.maven.api.plugin.annotations.Mojo;
+import org.apache.maven.api.plugin.annotations.Parameter;
+import org.apache.maven.api.services.ArtifactDeployer;
+import org.apache.maven.api.services.ArtifactDeployerException;
+import org.apache.maven.api.services.ArtifactManager;
+import org.apache.maven.api.services.ProjectBuilder;
+import org.apache.maven.api.services.ProjectBuilderException;
+import org.apache.maven.api.services.ProjectBuilderRequest;
+import org.apache.maven.api.services.ProjectBuilderResult;
+import org.apache.maven.api.services.ProjectBuilderSource;
+import org.apache.maven.api.services.ProjectManager;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
import org.apache.maven.model.building.ModelBuildingException;
-import org.apache.maven.model.building.ModelSource;
-import org.apache.maven.model.building.StringModelSource;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
-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.Mojo;
-import org.apache.maven.plugins.annotations.Parameter;
-import org.apache.maven.project.DefaultProjectBuildingRequest;
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.MavenProjectHelper;
-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;
@@ -71,25 +71,10 @@
*
* @author Allan Ramirez
*/
-@Mojo( name = "deploy-file", requiresProject = false, threadSafe = true )
+@Mojo( name = "deploy-file", requiresProject = false )
public class DeployFileMojo
extends AbstractDeployMojo
{
- @Component
- private ArtifactDeployer artifactDeployer;
-
- /**
- * Used for attaching the artifacts to deploy to the project.
- */
- @Component
- private MavenProjectHelper projectHelper;
-
- /**
- * Used for creating the project to which the artifacts to deploy will be attached.
- */
- @Component
- private ProjectBuilder projectBuilder;
-
/**
* GroupId of the artifact to be deployed. Retrieved from POM file if specified.
*/
@@ -208,11 +193,8 @@ public class DeployFileMojo
@Parameter( property = "files" )
private String files;
- @Component
- private RepositoryManager repoManager;
-
void initProperties()
- throws MojoExecutionException
+ throws MojoException
{
if ( pomFile == null )
{
@@ -233,7 +215,7 @@ void initProperties()
if ( pomEntry.matcher( entry.getName() ).matches() )
{
- getLog().debug( "Using " + entry.getName() + " as pomFile" );
+ logger.debug( "Using " + entry.getName() + " as pomFile" );
foundPom = true;
@@ -274,7 +256,7 @@ void initProperties()
if ( !foundPom )
{
- getLog().info( "pom.xml not found in " + file.getName() );
+ logger.info( "pom.xml not found in " + file.getName() );
}
}
catch ( IOException e )
@@ -308,11 +290,11 @@ void initProperties()
}
public void execute()
- throws MojoExecutionException, MojoFailureException
+ throws MojoException
{
if ( uniqueVersion != null )
{
- throw new MojoExecutionException( "You are using 'uniqueVersion' which has been removed"
+ throw new MojoException( "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." );
}
@@ -321,38 +303,42 @@ public void execute()
if ( !file.exists() )
{
- throw new MojoExecutionException( file.getPath() + " not found." );
+ throw new MojoException( file.getPath() + " not found." );
}
initProperties();
- ArtifactRepository deploymentRepository = createDeploymentArtifactRepository( repositoryId, url );
+ RemoteRepository deploymentRepository = createDeploymentArtifactRepository( repositoryId, url );
String protocol = deploymentRepository.getProtocol();
if ( StringUtils.isEmpty( protocol ) )
{
- throw new MojoExecutionException( "No transfer protocol found." );
+ throw new MojoException( "No transfer protocol found." );
}
- MavenProject project = createMavenProject();
+ ArtifactManager artifactManager = getSession().getService( ArtifactManager.class );
+ ProjectManager projectManager = getSession().getService( ProjectManager.class );
+ ArtifactDeployer artifactDeployer = getSession().getService( ArtifactDeployer.class );
+
+ Project project = createMavenProject();
Artifact artifact = project.getArtifact();
- if ( file.equals( getLocalRepoFile() ) )
+ if ( file.equals( getLocalRepoFile().toFile() ) )
{
- throw new MojoFailureException( "Cannot deploy artifact from the local repository: " + file );
+ throw new MojoException( "Cannot deploy artifact from the local repository: " + file );
}
- List deployableArtifacts = new ArrayList();
+ List deployableArtifacts = new ArrayList<>();
if ( classifier == null )
{
- artifact.setFile( file );
+ artifactManager.setPath( artifact, file.toPath() );
deployableArtifacts.add( artifact );
}
else
{
- projectHelper.attachArtifact( project, packaging, classifier, file );
+ projectManager.attachArtifact( getSession(), project, packaging, classifier, file.toPath() );
}
// Upload the POM if requested, generating one if need be
@@ -367,50 +353,51 @@ public void execute()
{
if ( classifier == null )
{
- ProjectArtifactMetadata metadata = new ProjectArtifactMetadata( artifact, pom );
- artifact.addMetadata( metadata );
+ Artifact pomArtifact = getSession().createArtifact(
+ groupId, artifactId, "", version, "pom"
+ );
+ artifactManager.setPath( pomArtifact, pom.toPath() );
+ deployableArtifacts.add( pomArtifact );
}
else
{
- artifact.setFile( pom );
+ artifactManager.setPath( artifact, pom.toPath() );
deployableArtifacts.add( artifact );
}
}
}
- artifact.setRepository( deploymentRepository );
-
if ( sources != null )
{
- projectHelper.attachArtifact( project, "jar", "sources", sources );
+ projectManager.attachArtifact( getSession(), project, "jar", "sources", sources.toPath() );
}
if ( javadoc != null )
{
- projectHelper.attachArtifact( project, "jar", "javadoc", javadoc );
+ projectManager.attachArtifact( getSession(), project, "jar", "javadoc", javadoc.toPath() );
}
if ( files != null )
{
if ( types == null )
{
- throw new MojoExecutionException( "You must specify 'types' if you specify 'files'" );
+ throw new MojoException( "You must specify 'types' if you specify 'files'" );
}
if ( classifiers == null )
{
- throw new MojoExecutionException( "You must specify 'classifiers' if you specify 'files'" );
+ throw new MojoException( "You must specify 'classifiers' if you specify 'files'" );
}
int filesLength = StringUtils.countMatches( files, "," );
int typesLength = StringUtils.countMatches( types, "," );
int classifiersLength = StringUtils.countMatches( classifiers, "," );
if ( typesLength != filesLength )
{
- throw new MojoExecutionException( "You must specify the same number of entries in 'files' and "
+ throw new MojoException( "You must specify the same number of entries in 'files' and "
+ "'types' (respectively " + filesLength + " and " + typesLength + " entries )" );
}
if ( classifiersLength != filesLength )
{
- throw new MojoExecutionException( "You must specify the same number of entries in 'files' and "
+ throw new MojoException( "You must specify the same number of entries in 'files' and "
+ "'classifiers' (respectively " + filesLength + " and " + classifiersLength + " entries )" );
}
int fi = 0;
@@ -437,23 +424,17 @@ public void execute()
if ( !file.isFile() )
{
// try relative to the project basedir just in case
- file = new File( project.getBasedir(), files.substring( fi, nfi ) );
+ file = new File( project.getBasedir().toFile(), files.substring( fi, nfi ) );
}
if ( file.isFile() )
{
- if ( StringUtils.isWhitespace( classifiers.substring( ci, nci ) ) )
- {
- projectHelper.attachArtifact( project, types.substring( ti, nti ).trim(), file );
- }
- else
- {
- projectHelper.attachArtifact( project, types.substring( ti, nti ).trim(),
- classifiers.substring( ci, nci ).trim(), file );
- }
+ String classifier = classifiers.substring( ci, nci ).trim();
+ String type = types.substring( ti, nti ).trim();
+ projectManager.attachArtifact( getSession(), project, type, classifier, file.toPath() );
}
else
{
- throw new MojoExecutionException( "Specified side artifact " + file + " does not exist" );
+ throw new MojoException( "Specified side artifact " + file + " does not exist" );
}
fi = nfi + 1;
ti = nti + 1;
@@ -464,29 +445,25 @@ public void execute()
{
if ( types != null )
{
- throw new MojoExecutionException( "You must specify 'files' if you specify 'types'" );
+ throw new MojoException( "You must specify 'files' if you specify 'types'" );
}
if ( classifiers != null )
{
- throw new MojoExecutionException( "You must specify 'files' if you specify 'classifiers'" );
+ throw new MojoException( "You must specify 'files' if you specify 'classifiers'" );
}
}
- List attachedArtifacts = project.getAttachedArtifacts();
+ Collection attachedArtifacts = projectManager.getAttachedArtifacts( project );
- for ( Artifact attached : attachedArtifacts )
- {
- deployableArtifacts.add( attached );
- }
+ deployableArtifacts.addAll( attachedArtifacts );
try
{
- artifactDeployer.deploy( getSession().getProjectBuildingRequest(), deploymentRepository,
- deployableArtifacts );
+ artifactDeployer.deploy( getSession(), deploymentRepository, deployableArtifacts );
}
catch ( ArtifactDeployerException e )
{
- throw new MojoExecutionException( e.getMessage(), e );
+ throw new MojoException( e.getMessage(), e );
}
}
@@ -496,36 +473,45 @@ public void execute()
* to attach the artifacts to deploy to.
*
* @return The created Maven project, never null
.
- * @throws MojoExecutionException When the model of the project could not be built.
- * @throws MojoFailureException When building the project failed.
+ * @throws MojoException When the model of the project could not be built.
*/
- private MavenProject createMavenProject()
- throws MojoExecutionException, MojoFailureException
+ private Project createMavenProject()
+ throws MojoException
{
if ( groupId == null || artifactId == null || version == null || packaging == null )
{
- throw new MojoExecutionException( "The artifact information is incomplete: 'groupId', 'artifactId', "
+ throw new MojoException( "The artifact information is incomplete: 'groupId', 'artifactId', "
+ "'version' and 'packaging' are required." );
}
- ModelSource modelSource =
- new StringModelSource( "" + "4.0.0" + "" + groupId
- + "" + "" + artifactId + "" + "" + version + ""
- + "" + ( classifier == null ? packaging : "pom" ) + "" + "" );
- DefaultProjectBuildingRequest buildingRequest =
- new DefaultProjectBuildingRequest( getSession().getProjectBuildingRequest() );
- buildingRequest.setProcessPlugins( false );
try
{
- return projectBuilder.build( modelSource, buildingRequest ).getProject();
- }
- catch ( ProjectBuildingException e )
- {
- if ( e.getCause() instanceof ModelBuildingException )
+ String prj = ""
+ + "4.0.0"
+ + "" + groupId + ""
+ + "" + artifactId + ""
+ + "" + version + ""
+ + "" + ( classifier == null ? packaging : "pom" ) + ""
+ + "";
+ ProjectBuilderResult result = getSession().getService( ProjectBuilder.class )
+ .build( ProjectBuilderRequest.builder()
+ .session( getSession() )
+ .source( new StringSource( prj ) )
+ .processPlugins( false )
+ .resolveDependencies( false )
+ .build() );
+
+ return result.getProject().get();
+ }
+ catch ( ProjectBuilderException e )
+ {
+ for ( Throwable c = e.getCause(); c != null; c = c.getCause() )
{
- throw new MojoExecutionException( "The artifact information is not valid:" + Os.LINE_SEP
- + e.getCause().getMessage() );
+ if ( c instanceof ModelBuildingException )
+ {
+ throw new MojoException( "The artifact information is not valid:" + Os.LINE_SEP + c.getMessage() );
+ }
}
- throw new MojoFailureException( "Unable to create the project.", e );
+ throw new MojoException( "Unable to create the project.", e );
}
}
@@ -535,16 +521,10 @@ private MavenProject createMavenProject()
*
* @return The absolute path to the artifact when installed, never null
.
*/
- private File getLocalRepoFile()
+ private Path getLocalRepoFile()
{
- 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 );
+ Artifact artifact = getSession().createArtifact( groupId, artifactId, classifier, version, packaging );
+ return getSession().getPathForLocalArtifact( artifact );
}
/**
@@ -587,10 +567,10 @@ private void processModel( Model model )
*
* @param pomFile The path of the POM file to parse, must not be null
.
* @return The model from the POM file, never null
.
- * @throws MojoExecutionException If the file doesn't exist of cannot be read.
+ * @throws MojoException If the file doesn't exist of cannot be read.
*/
Model readModel( File pomFile )
- throws MojoExecutionException
+ throws MojoException
{
Reader reader = null;
try
@@ -603,15 +583,15 @@ Model readModel( File pomFile )
}
catch ( FileNotFoundException e )
{
- throw new MojoExecutionException( "POM not found " + pomFile, e );
+ throw new MojoException( "POM not found " + pomFile, e );
}
catch ( IOException e )
{
- throw new MojoExecutionException( "Error reading POM " + pomFile, e );
+ throw new MojoException( "Error reading POM " + pomFile, e );
}
catch ( XmlPullParserException e )
{
- throw new MojoExecutionException( "Error parsing POM " + pomFile, e );
+ throw new MojoException( "Error parsing POM " + pomFile, e );
}
finally
{
@@ -623,10 +603,10 @@ Model readModel( File pomFile )
* Generates a minimal POM from the user-supplied artifact information.
*
* @return The path to the generated POM file, never null
.
- * @throws MojoExecutionException If the generation failed.
+ * @throws MojoException If the generation failed.
*/
private File generatePomFile()
- throws MojoExecutionException
+ throws MojoException
{
Model model = generateModel();
@@ -647,7 +627,7 @@ private File generatePomFile()
}
catch ( IOException e )
{
- throw new MojoExecutionException( "Error writing temporary pom file: " + e.getMessage(), e );
+ throw new MojoException( "Error writing temporary pom file: " + e.getMessage(), e );
}
finally
{
@@ -736,4 +716,26 @@ void setClassifier( String classifier )
this.classifier = classifier;
}
+ private static class StringSource implements ProjectBuilderSource
+ {
+ private final String prj;
+
+ StringSource( String prj )
+ {
+ this.prj = prj;
+ }
+
+ @Override
+ public InputStream getInputStream() throws IOException
+ {
+ return new ByteArrayInputStream( prj.getBytes( StandardCharsets.UTF_8 ) );
+ }
+
+ @Override
+ public String getLocation()
+ {
+ return null;
+ }
+ }
+
}
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 ae26134b..d1f09b15 100644
--- a/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
+++ b/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
@@ -19,6 +19,8 @@
* under the License.
*/
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -26,20 +28,21 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-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.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.api.Artifact;
+import org.apache.maven.api.Project;
+import org.apache.maven.api.RemoteRepository;
+import org.apache.maven.api.plugin.MojoException;
+import org.apache.maven.api.plugin.annotations.LifecyclePhase;
+import org.apache.maven.api.plugin.annotations.Mojo;
+import org.apache.maven.api.plugin.annotations.Parameter;
+import org.apache.maven.api.services.ArtifactDeployer;
+import org.apache.maven.api.services.ArtifactDeployerException;
+import org.apache.maven.api.services.ArtifactDeployerRequest;
+import org.apache.maven.api.services.ArtifactManager;
+import org.apache.maven.api.services.ProjectManager;
+import org.apache.maven.api.services.RepositoryFactory;
+import org.apache.maven.model.DistributionManagement;
+import org.apache.maven.shared.utils.StringUtils;
/**
* Deploys an artifact to remote repository.
@@ -47,7 +50,7 @@
* @author Emmanuel Venisse
* @author John Casey (refactoring only)
*/
-@Mojo( name = "deploy", defaultPhase = LifecyclePhase.DEPLOY, threadSafe = true )
+@Mojo( name = "deploy", defaultPhase = LifecyclePhase.DEPLOY )
public class DeployMojo
extends AbstractDeployMojo
{
@@ -61,16 +64,16 @@ public class DeployMojo
*/
private static final AtomicInteger READYPROJECTSCOUNTER = new AtomicInteger();
- private static final List DEPLOYREQUESTS =
- Collections.synchronizedList( new ArrayList() );
+ private static final List DEPLOYREQUESTS =
+ Collections.synchronizedList( new ArrayList<>() );
/**
*/
@Parameter( defaultValue = "${project}", readonly = true, required = true )
- private MavenProject project;
+ private Project project;
@Parameter( defaultValue = "${reactorProjects}", required = true, readonly = true )
- private List reactorProjects;
+ private List reactorProjects;
/**
* Whether every project should be deployed during its own deploy-phase or at the end of the multimodule build. If
@@ -97,7 +100,7 @@ public class DeployMojo
* has been removed because Maven 3 only supports Maven 2 repository layout.
*/
@Parameter( property = "altDeploymentRepository" )
- private String altDeploymentRepository;
+ String altDeploymentRepository;
/**
* The alternative repository to use when the project has a snapshot version.
@@ -137,47 +140,80 @@ 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;
-
public void execute()
- throws MojoExecutionException, MojoFailureException
+ throws MojoException
{
+ ArtifactManager artifactManager = getSession().getService( ArtifactManager.class );
+
boolean addedDeployRequest = false;
+ boolean isSnapshot = artifactManager.isSnapshot( project.getVersion() );
if ( Boolean.parseBoolean( skip )
- || ( "releases".equals( skip ) && !ArtifactUtils.isSnapshot( project.getVersion() ) )
- || ( "snapshots".equals( skip ) && ArtifactUtils.isSnapshot( project.getVersion() ) )
+ || ( "releases".equals( skip ) && !isSnapshot )
+ || ( "snapshots".equals( skip ) && isSnapshot )
)
{
- getLog().info( "Skipping artifact deployment" );
+ logger.info( "Skipping artifact deployment" );
}
else
{
failIfOffline();
+ List deployables = new ArrayList<>();
+
+ deployables.add( project.getArtifact() );
+
+ Path pomPath = project.getPomPath();
+
+ if ( !"pom".equals( project.getPackaging() ) )
+ {
+ Artifact pomArtifact = getSession().createArtifact(
+ project.getGroupId(), project.getArtifactId(), "",
+ project.getVersion(), "pom" );
+ if ( pomPath != null )
+ {
+ artifactManager.setPath( pomArtifact, pomPath );
+ }
+ deployables.add( pomArtifact );
+ }
+ else
+ {
+ if ( pomPath != null )
+ {
+ artifactManager.setPath( project.getArtifact(), pomPath );
+ }
+ }
+
+ ProjectManager projectManager = getSession().getService( ProjectManager.class );
+ deployables.addAll( projectManager.getAttachedArtifacts( project ) );
+
+ for ( Artifact artifact : deployables )
+ {
+ Path path = artifactManager.getPath( artifact ).orElse( null );
+ if ( path == null || !Files.isRegularFile( path ) )
+ {
+ throw new MojoException( "The packaging plugin for this project did not assign "
+ + "a main file to the project but it has attachments. Change packaging to 'pom'." );
+ }
+ }
+
// CHECKSTYLE_OFF: LineLength
// @formatter:off
- ProjectDeployerRequest pdr = new ProjectDeployerRequest()
- .setProject( project )
- .setRetryFailedDeploymentCount( getRetryFailedDeploymentCount() )
- .setAltReleaseDeploymentRepository( altReleaseDeploymentRepository )
- .setAltSnapshotDeploymentRepository( altSnapshotDeploymentRepository )
- .setAltDeploymentRepository( altDeploymentRepository );
+ ArtifactDeployerRequest adr = ArtifactDeployerRequest.builder()
+ .session( getSession() )
+ .repository( getDeploymentRepository( isSnapshot ) )
+ .artifacts( deployables )
+ .retryFailedDeploymentCount( getRetryFailedDeploymentCount() )
+ .build();
// @formatter:on
// CHECKSTYLE_ON: LineLength
- ArtifactRepository repo = getDeploymentRepository( pdr );
-
if ( !deployAtEnd )
{
- deployProject( getSession().getProjectBuildingRequest(), pdr, repo );
+ deployProject( adr );
}
else
{
- DEPLOYREQUESTS.add( pdr );
+ DEPLOYREQUESTS.add( adr );
addedDeployRequest = true;
}
}
@@ -189,54 +225,43 @@ public void execute()
{
while ( !DEPLOYREQUESTS.isEmpty() )
{
- ArtifactRepository repo = getDeploymentRepository( DEPLOYREQUESTS.get( 0 ) );
-
- deployProject( getSession().getProjectBuildingRequest(), DEPLOYREQUESTS.remove( 0 ), repo );
+ deployProject( DEPLOYREQUESTS.remove( 0 ) );
}
}
}
else if ( addedDeployRequest )
{
- getLog().info( "Deploying " + project.getGroupId() + ":" + project.getArtifactId() + ":"
+ logger.info( "Deploying " + project.getGroupId() + ":" + project.getArtifactId() + ":"
+ project.getVersion() + " at end" );
}
}
- private void deployProject( ProjectBuildingRequest pbr, ProjectDeployerRequest pir, ArtifactRepository repo )
- throws MojoFailureException, MojoExecutionException
+ private void deployProject( ArtifactDeployerRequest adr )
+ throws MojoException
{
try
{
- projectDeployer.deploy( pbr, pir, repo );
- }
- catch ( NoFileAssignedException e )
- {
- throw new MojoExecutionException( "NoFileAssignedException", e );
+ ArtifactDeployer artifactDeployer = getSession().getService( ArtifactDeployer.class );
+ artifactDeployer.deploy( adr );
}
catch ( ArtifactDeployerException e )
{
- throw new MojoExecutionException( "ArtifactDeployerException", e );
+ throw new MojoException( "ProjectDeployerException", e );
}
}
- ArtifactRepository getDeploymentRepository( ProjectDeployerRequest pdr )
-
- throws MojoExecutionException, MojoFailureException
+ RemoteRepository getDeploymentRepository( boolean isSnapshot )
+ throws MojoException
{
- MavenProject project = pdr.getProject();
- String altDeploymentRepository = pdr.getAltDeploymentRepository();
- String altReleaseDeploymentRepository = pdr.getAltReleaseDeploymentRepository();
- String altSnapshotDeploymentRepository = pdr.getAltSnapshotDeploymentRepository();
-
- ArtifactRepository repo = null;
+ RemoteRepository repo = null;
String altDeploymentRepo;
- if ( ArtifactUtils.isSnapshot( project.getVersion() ) && altSnapshotDeploymentRepository != null )
+ if ( isSnapshot && altSnapshotDeploymentRepository != null )
{
altDeploymentRepo = altSnapshotDeploymentRepository;
}
- else if ( !ArtifactUtils.isSnapshot( project.getVersion() ) && altReleaseDeploymentRepository != null )
+ else if ( !isSnapshot && altReleaseDeploymentRepository != null )
{
altDeploymentRepo = altReleaseDeploymentRepository;
}
@@ -247,7 +272,7 @@ else if ( !ArtifactUtils.isSnapshot( project.getVersion() ) && altReleaseDeploym
if ( altDeploymentRepo != null )
{
- getLog().info( "Using alternate deployment repository " + altDeploymentRepo );
+ logger.info( "Using alternate deployment repository " + altDeploymentRepo );
Matcher matcher = ALT_LEGACY_REPO_SYNTAX_PATTERN.matcher( altDeploymentRepo );
@@ -259,13 +284,13 @@ else if ( !ArtifactUtils.isSnapshot( project.getVersion() ) && altReleaseDeploym
if ( "default".equals( layout ) )
{
- getLog().warn( "Using legacy syntax for alternative repository. "
+ logger.warn( "Using legacy syntax for alternative repository. "
+ "Use \"" + id + "::" + url + "\" instead." );
repo = createDeploymentArtifactRepository( id, url );
}
else
{
- throw new MojoFailureException( altDeploymentRepo,
+ throw new MojoException( altDeploymentRepo,
"Invalid legacy syntax and layout for repository.",
"Invalid legacy syntax and layout for alternative repository. Use \""
+ id + "::" + url + "\" instead, and only default layout is supported."
@@ -278,7 +303,7 @@ else if ( !ArtifactUtils.isSnapshot( project.getVersion() ) && altReleaseDeploym
if ( !matcher.matches() )
{
- throw new MojoFailureException( altDeploymentRepo,
+ throw new MojoException( altDeploymentRepo,
"Invalid syntax for repository.",
"Invalid syntax for alternative repository. Use \"id::url\"."
);
@@ -295,7 +320,25 @@ else if ( !ArtifactUtils.isSnapshot( project.getVersion() ) && altReleaseDeploym
if ( repo == null )
{
- repo = project.getDistributionManagementArtifactRepository();
+ DistributionManagement dm = project.getModel().getDistributionManagement();
+ if ( dm != null )
+ {
+ boolean snapshot = isSnapshot;
+ if ( snapshot && dm.getSnapshotRepository() != null
+ && StringUtils.isNotEmpty( dm.getSnapshotRepository().getId() )
+ && StringUtils.isNotEmpty( dm.getSnapshotRepository().getUrl() ) )
+ {
+ repo = getSession().getService( RepositoryFactory.class )
+ .createRemote( dm.getSnapshotRepository() );
+ }
+ else if ( dm.getRepository() != null
+ && StringUtils.isNotEmpty( dm.getRepository().getId() )
+ && StringUtils.isNotEmpty( dm.getRepository().getUrl() ) )
+ {
+ repo = getSession().getService( RepositoryFactory.class )
+ .createRemote( dm.getRepository() );
+ }
+ }
}
if ( repo == null )
@@ -303,7 +346,7 @@ else if ( !ArtifactUtils.isSnapshot( project.getVersion() ) && altReleaseDeploym
String msg = "Deployment failed: repository element was not specified in the POM inside"
+ " distributionManagement element or in -DaltDeploymentRepository=id::url parameter";
- throw new MojoExecutionException( msg );
+ throw new MojoException( msg );
}
return repo;
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 6c7064bb..5a0c89c4 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java
@@ -19,285 +19,218 @@
* under the License.
*/
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
+import static org.apache.maven.api.plugin.testing.MojoExtension.getVariableValueFromObject;
+import static org.codehaus.plexus.testing.PlexusExtension.getBasedir;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.doNothing;
import java.io.File;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
-import org.apache.maven.execution.MavenSession;
+import com.google.inject.Inject;
+import com.google.inject.Provides;
+import com.google.inject.Singleton;
+import org.apache.maven.api.Artifact;
+import org.apache.maven.api.Session;
+import org.apache.maven.api.services.ArtifactDeployer;
+import org.apache.maven.api.services.ArtifactDeployerRequest;
+import org.apache.maven.api.services.ArtifactManager;
+import org.apache.maven.api.services.ProjectBuilder;
+import org.apache.maven.api.services.ProjectManager;
import org.apache.maven.model.Model;
-import org.apache.maven.plugin.testing.AbstractMojoTestCase;
-import org.apache.maven.project.ProjectBuildingRequest;
-import org.apache.maven.repository.internal.MavenRepositorySystemSession;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager;
+import org.apache.maven.api.plugin.testing.InjectMojo;
+import org.apache.maven.api.plugin.testing.MojoTest;
+import org.apache.maven.plugins.deploy.stubs.ArtifactStub;
+import org.apache.maven.plugins.deploy.stubs.SessionStub;
+import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentCaptor;
/**
* @author Allan Ramirez
*/
+@MojoTest
public class DeployFileMojoTest
- extends AbstractMojoTestCase
{
- private String LOCAL_REPO = getBasedir() + "/target/local-repo";
+ private static final String LOCAL_REPO = getBasedir() + "/target/local-repo";
- private List expectedFiles;
+ @Inject @SuppressWarnings( "unused" )
+ private Session session;
- private List fileList;
+ @Inject @SuppressWarnings( "unused" )
+ private ArtifactDeployer artifactDeployer;
- private File remoteRepo;
-
- @Mock
- private MavenSession session;
-
- @InjectMocks
- private DeployFileMojo mojo;
+ @Inject @SuppressWarnings( "unused" )
+ private ArtifactManager artifactManager;
- public void setUp()
- throws Exception
+ @Test
+ @InjectMojo( goal = "deploy-file", pom = "classpath:/unit/deploy-file/plugin-config-test.xml" )
+ public void testDeployTestEnvironment( DeployFileMojo mojo )
{
- super.setUp();
-
- remoteRepo = new File( getBasedir(), "target/remote-repo" );
-
- if ( !remoteRepo.exists() )
- {
- remoteRepo.mkdirs();
- }
- }
-
- public void testDeployTestEnvironment()
- throws Exception
- {
- File testPom = new File( getBasedir(), "target/test-classes/unit/deploy-file-test/plugin-config.xml" );
-
- AbstractDeployMojo mojo = (AbstractDeployMojo) lookupMojo( "deploy-file", testPom );
-
assertNotNull( mojo );
}
- public void testBasicDeployFile()
+ @Test
+ @InjectMojo( goal = "deploy-file", pom = "classpath:/unit/deploy-file/plugin-config-test.xml" )
+ public void testBasicDeployFile( DeployFileMojo mojo )
throws Exception
{
- File testPom = new File( getBasedir(), "target/test-classes/unit/deploy-file-test/plugin-config.xml" );
-
- mojo = (DeployFileMojo) lookupMojo( "deploy-file", testPom );
-
- MockitoAnnotations.initMocks( this );
-
assertNotNull( mojo );
- ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
- when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
- MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
- repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( LOCAL_REPO ) );
- when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
-
String groupId = (String) getVariableValueFromObject( mojo, "groupId" );
-
String artifactId = (String) getVariableValueFromObject( mojo, "artifactId" );
-
String version = (String) getVariableValueFromObject( mojo, "version" );
-
String packaging = (String) getVariableValueFromObject( mojo, "packaging" );
-
File file = (File) getVariableValueFromObject( mojo, "file" );
-
String repositoryId = (String) getVariableValueFromObject( mojo, "repositoryId" );
-
String url = (String) getVariableValueFromObject( mojo, "url" );
assertEquals( "org.apache.maven.test", groupId );
-
assertEquals( "maven-deploy-file-test", artifactId );
-
assertEquals( "1.0", version );
-
assertEquals( "jar", packaging );
-
assertTrue( file.exists() );
-
assertEquals( "deploy-test", repositoryId );
-
assertEquals( "file://" + getBasedir() + "/target/remote-repo/deploy-file-test", url );
-
- mojo.execute();
- //check the generated pom
- File pom = new File( remoteRepo, "deploy-file-test/" + groupId.replace( '.', '/' ) +
- "/" + artifactId + "/" + version + "/" + artifactId +
- "-" + version + ".pom" );
+ ArtifactDeployerRequest request = execute( mojo );
+
+ assertNotNull( request );
+ List artifacts = new ArrayList<>( request.getArtifacts() );
+ assertEquals( 2, artifacts.size() );
+ Artifact a1 = artifacts.get( 0 );
+ Path p1 = artifactManager.getPath( a1 ).orElse( null );
+ assertEquals( file.toPath(), p1 );
+ Artifact a2 = artifacts.get( 1 );
+ Path p2 = artifactManager.getPath( a2 ).orElse( null );
+ assertNotNull( p2 );
+ assertTrue( p2.toString().endsWith( ".pom" ) );
+
+ assertNotNull( request.getRepository() );
+ assertEquals( url, request.getRepository().getUrl() );
+ //check the generated pom
+ File pom = p2.toFile();
assertTrue( pom.exists() );
Model model = mojo.readModel( pom );
-
assertEquals( "4.0.0", model.getModelVersion() );
-
assertEquals( groupId, model.getGroupId() );
-
assertEquals( artifactId, model.getArtifactId() );
-
assertEquals( version, model.getVersion() );
-
assertEquals( packaging, model.getPackaging() );
-
assertEquals( "POM was created from deploy:deploy-file", model.getDescription() );
-
- //check the remote-repo
- expectedFiles = new ArrayList();
- fileList = new ArrayList();
-
- File repo = new File( remoteRepo, "deploy-file-test" );
-
- File[] files = repo.listFiles();
-
- for (File file1 : files) {
- addFileToList(file1, fileList);
- }
-
- expectedFiles.add( "org" );
- expectedFiles.add( "apache" );
- expectedFiles.add( "maven" );
- expectedFiles.add( "test" );
- expectedFiles.add( "maven-deploy-file-test" );
- expectedFiles.add( "1.0" );
- expectedFiles.add( "maven-metadata.xml" );
- expectedFiles.add( "maven-metadata.xml.md5" );
- expectedFiles.add( "maven-metadata.xml.sha1" );
- expectedFiles.add( "maven-deploy-file-test-1.0.jar" );
- expectedFiles.add( "maven-deploy-file-test-1.0.jar.md5" );
- expectedFiles.add( "maven-deploy-file-test-1.0.jar.sha1" );
- expectedFiles.add( "maven-deploy-file-test-1.0.pom" );
- expectedFiles.add( "maven-deploy-file-test-1.0.pom.md5" );
- expectedFiles.add( "maven-deploy-file-test-1.0.pom.sha1" );
-
- assertEquals( expectedFiles.size(), fileList.size() );
-
- assertEquals( 0, getSizeOfExpectedFiles( fileList, expectedFiles ) );
}
- public void testDeployIfClassifierIsSet()
+ @Test
+ @InjectMojo( goal = "deploy-file", pom = "classpath:/unit/deploy-file/plugin-config-classifier.xml" )
+ public void testDeployIfClassifierIsSet( DeployFileMojo mojo )
throws Exception
{
- File testPom = new File( getBasedir(), "target/test-classes/unit/deploy-file-classifier/plugin-config.xml" );
-
- mojo = (DeployFileMojo) lookupMojo( "deploy-file", testPom );
-
- MockitoAnnotations.initMocks( this );
-
assertNotNull( mojo );
- ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
- when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
- MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
- repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( LOCAL_REPO ) );
- when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
-
- String classifier = ( String ) getVariableValueFromObject( mojo, "classifier" );
-
String groupId = ( String ) getVariableValueFromObject( mojo, "groupId" );
-
String artifactId = ( String ) getVariableValueFromObject( mojo, "artifactId" );
-
- String version = ( String ) getVariableValueFromObject( mojo, "version" );
-
+ String classifier = ( String ) getVariableValueFromObject( mojo, "classifier" );
assertEquals( "bin", classifier );
+ String version = ( String ) getVariableValueFromObject( mojo, "version" );
+ String url = (String) getVariableValueFromObject( mojo, "url" );
- mojo.execute();
-
- File deployedArtifact = new File( remoteRepo, "deploy-file-classifier/" + groupId.replace( '.', '/' ) +
- "/" + artifactId + "/" + version + "/" + artifactId +
- "-" + version + "-" + classifier + ".jar");
-
- assertTrue( deployedArtifact.exists() );
-
- mojo.setClassifier( "prod" );
-
- assertEquals( "prod", mojo.getClassifier() );
-
- mojo.execute();
-
- File prodDeployedArtifact = new File( remoteRepo, "deploy-file-classifier/" + groupId.replace( '.', '/' ) +
- "/" + artifactId + "/" + version + "/" + artifactId +
- "-" + version + "-" + mojo.getClassifier() + ".jar");
-
- assertTrue( prodDeployedArtifact.exists() );
+ ArtifactDeployerRequest request = execute( mojo );
+
+ assertNotNull( request );
+ List artifacts = new ArrayList<>( request.getArtifacts() );
+ assertEquals( 2, artifacts.size() );
+ // first artifact
+ Artifact a1 = artifacts.get( 0 );
+ assertEquals( new ArtifactStub( groupId, artifactId, "", version, "pom" ), a1 );
+ Path p1 = artifactManager.getPath( a1 ).orElse( null );
+ assertNotNull( p1 );
+ assertTrue( p1.toString().endsWith( ".pom" ) );
+ // second artifact
+ Artifact a2 = artifacts.get( 1 );
+ assertEquals( new ArtifactStub( groupId, artifactId, "bin", version, "jar" ), a2 );
+ Path p2 = artifactManager.getPath( a2 ).orElse( null );
+ assertNotNull( p2 );
+ assertTrue( p2.toString().endsWith( "deploy-test-file-1.0-SNAPSHOT.jar" ) );
+ // remote repository
+ assertNotNull( request.getRepository() );
+ assertEquals( url, request.getRepository().getUrl() );
}
- public void testDeployIfArtifactIsNotJar()
+ @Test
+ @InjectMojo( goal = "deploy-file", pom = "classpath:/unit/deploy-file/plugin-config-artifact-not-jar.xml" )
+ public void testDeployIfArtifactIsNotJar( DeployFileMojo mojo )
throws Exception
{
- File testPom = new File( getBasedir(), "target/test-classes/unit/deploy-file-artifact-not-jar/plugin-config.xml" );
-
- mojo = (DeployFileMojo) lookupMojo( "deploy-file", testPom );
-
- MockitoAnnotations.initMocks( this );
-
assertNotNull( mojo );
-
- ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
- when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
- MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
- repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( LOCAL_REPO ) );
- when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
String groupId = (String) getVariableValueFromObject( mojo, "groupId" );
-
String artifactId = (String) getVariableValueFromObject( mojo, "artifactId" );
-
String version = (String) getVariableValueFromObject( mojo, "version" );
-
assertEquals( "org.apache.maven.test", groupId );
-
assertEquals( "maven-deploy-file-test", artifactId );
-
assertEquals( "1.0", version );
+ ArtifactDeployerRequest request = execute( mojo );
+
+ assertNotNull( request );
+ List artifacts = new ArrayList<>( request.getArtifacts() );
+ assertEquals( 2, artifacts.size() );
+ Artifact a1 = artifacts.get( 0 );
+ Artifact a2 = artifacts.get( 1 );
+ Path p1 = artifactManager.getPath( a1 ).orElse( null );
+ Path p2 = artifactManager.getPath( a2 ).orElse( null );
+ assertNotNull( p1 );
+ assertTrue( p1.toString().endsWith( "deploy-test-file.zip" ) );
+ assertNotNull( p2 );
+ assertTrue( p2.toString().endsWith( ".pom" ) );
+
+ assertNotNull( request.getRepository() );
+ assertEquals( "file://" + getBasedir() + "/target/remote-repo/deploy-file", request.getRepository().getUrl() );
+ }
+
+ private ArtifactDeployerRequest execute( DeployFileMojo mojo )
+ {
+ ArgumentCaptor requestCaptor = ArgumentCaptor.forClass( ArtifactDeployerRequest.class );
+ doNothing().when( artifactDeployer ).deploy( requestCaptor.capture() );
+
mojo.execute();
- File file = new File( remoteRepo, "deploy-file-artifact-not-jar/" + groupId.replace( '.', '/' ) +
- "/" + artifactId + "/" + version + "/" + artifactId +
- "-" + version + ".zip");
+ return requestCaptor.getValue();
+ }
- assertTrue( file.exists() );
+ @Provides @Singleton @SuppressWarnings( "unused" )
+ private Session getMockSession()
+ {
+ return SessionStub.getMockSession( LOCAL_REPO );
+ }
+
+ @Provides @SuppressWarnings( "unused" )
+ private ArtifactDeployer getMockArtifactDeployer( Session session )
+ {
+ return session.getService( ArtifactDeployer.class );
+ }
+
+ @Provides @SuppressWarnings( "unused" )
+ private ArtifactManager getMockArtifactManager( Session session )
+ {
+ return session.getService( ArtifactManager.class );
}
- private void addFileToList( File file, List fileList )
+ @Provides @SuppressWarnings( "unused" )
+ private ProjectManager getMockProjectManager( Session session )
{
- if ( !file.isDirectory() )
- {
- fileList.add( file.getName() );
- }
- else
- {
- fileList.add( file.getName() );
-
- File[] files = file.listFiles();
-
- for (File file1 : files) {
- addFileToList(file1, fileList);
- }
- }
+ return session.getService( ProjectManager.class );
}
- private int getSizeOfExpectedFiles( List fileList, List expectedFiles )
+ @Provides @SuppressWarnings( "unused" )
+ private ProjectBuilder getMockProjectBuilder( Session session )
{
- for ( String fileName : fileList )
- {
- if ( expectedFiles.contains( fileName ) )
- {
- expectedFiles.remove( fileName );
- }
- else
- {
- fail( fileName + " is not included in the expected files" );
- }
- }
- return expectedFiles.size();
+ return session.getService( ProjectBuilder.class );
}
}
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 6131f79d..ea7c1cd9 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,25 @@
* under the License.
*/
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
+import org.apache.maven.api.plugin.MojoException;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
-import org.apache.maven.plugin.MojoExecutionException;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.io.File;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
/**
* @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;
+ @BeforeEach
public void setUp()
{
Model pomModel = new Model();
@@ -62,114 +51,55 @@ public void setUp()
mojo = new MockDeployFileMojo( pomModel );
}
- public void tearDown()
- {
- mojo = null;
- }
-
- class MockDeployFileMojo extends DeployFileMojo {
- private Model model;
+ static class MockDeployFileMojo extends DeployFileMojo {
+ private final Model model;
public MockDeployFileMojo(Model model) {
this.model = model;
}
- public void setModel(Model model) {
- this.model = model;
- }
-
- protected Model readModel(File pomFile) throws MojoExecutionException {
+ protected Model readModel(File pomFile) throws MojoException {
return model;
}
}
- public void testProcessPomFromPomFileWithParent1() throws MojoExecutionException
- {
- mojo.setPomFile( new File( "foo.bar" ) );
-
- setMojoModel( mojo.model, null, null, null, null, parent );
-
- try {
- mojo.initProperties();
- } catch (MojoExecutionException expected) {
- assertTrue( true ); // missing artifactId and packaging
- }
-
- checkMojoProperties("parentGroup", null, "parentVersion", null);
- }
-
- public void testProcessPomFromPomFileWithParent2() throws MojoExecutionException
- {
- mojo.setPomFile( new File( "foo.bar" ) );
- setMojoModel( mojo.model, null, "artifact", null, null, parent );
-
- try {
- mojo.initProperties();
- } catch (MojoExecutionException expected) {
- assertTrue( true ); // missing packaging
- }
-
- checkMojoProperties("parentGroup", "artifact", "parentVersion", null );
-
- }
-
- public void testProcessPomFromPomFileWithParent3() throws MojoExecutionException
- {
- mojo.setPomFile( new File( "foo.bar" ) );
- setMojoModel( mojo.model, null, "artifact", "version", null, parent );
-
- try {
- mojo.initProperties();
- } catch (MojoExecutionException expected) {
- assertTrue( true ); // missing version and packaging
- }
-
- checkMojoProperties( "parentGroup", "artifact", "version", null );
- }
-
- public void testProcessPomFromPomFileWithParent4() throws MojoExecutionException
+ @Test
+ public void testProcessPomFromPomFileWithParent4()
{
mojo.setPomFile( new File( "foo.bar" ) );
setMojoModel( mojo.model, null, "artifact", "version", "packaging", parent );
-
mojo.initProperties();
-
checkMojoProperties("parentGroup", "artifact", "version", "packaging");
}
- public void testProcessPomFromPomFileWithParent5() throws MojoExecutionException
+ @Test
+ public void testProcessPomFromPomFileWithParent5()
{
mojo.setPomFile( new File( "foo.bar" ) );
setMojoModel( mojo.model, "group", "artifact", "version", "packaging", parent );
-
mojo.initProperties();
-
checkMojoProperties("group", "artifact", "version", "packaging");
}
- public void testProcessPomFromPomFileWithParent6() throws MojoExecutionException
+ @Test
+ public void testProcessPomFromPomFileWithParent6()
{
mojo.setPomFile( new File( "foo.bar" ) );
setMojoModel( mojo.model, "group", "artifact", "version", "packaging", null );
-
mojo.initProperties();
-
checkMojoProperties("group", "artifact", "version", "packaging");
-
}
- public void testProcessPomFromPomFileWithOverrides() throws MojoExecutionException
+ @Test
+ public void testProcessPomFromPomFileWithOverrides()
{
mojo.setPomFile( new File( "foo.bar" ) );
setMojoModel( mojo.model, "group", "artifact", "version", "packaging", null );
-
mojo.setGroupId( "groupO" );
mojo.setArtifactId( "artifactO" );
mojo.setVersion( "versionO" );
mojo.setPackaging( "packagingO" );
-
mojo.initProperties();
-
checkMojoProperties("groupO", "artifactO", "versionO", "packagingO");
}
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 63fe2dee..ff6e661d 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
@@ -19,737 +19,339 @@
* under the License.
*/
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-
import java.io.File;
-import java.util.ArrayList;
+import java.nio.file.Paths;
+import java.util.Arrays;
import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
-import java.util.Properties;
-
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.execution.MavenSession;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-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.repository.internal.MavenRepositorySystemSession;
-import org.apache.maven.shared.transfer.project.deploy.ProjectDeployerRequest;
-import org.codehaus.plexus.util.FileUtils;
-import org.junit.Ignore;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager;
+import java.util.Set;
+
+import com.google.inject.Inject;
+import com.google.inject.Provides;
+import com.google.inject.Singleton;
+import org.apache.maven.api.Artifact;
+import org.apache.maven.api.Project;
+import org.apache.maven.api.RemoteRepository;
+import org.apache.maven.api.Session;
+import org.apache.maven.api.plugin.MojoException;
+import org.apache.maven.api.services.ArtifactDeployer;
+import org.apache.maven.api.services.ArtifactDeployerRequest;
+import org.apache.maven.api.services.ArtifactManager;
+import org.apache.maven.api.services.ProjectBuilder;
+import org.apache.maven.api.services.ProjectManager;
+import org.apache.maven.api.plugin.testing.InjectMojo;
+import org.apache.maven.api.plugin.testing.MojoTest;
+import org.apache.maven.plugins.deploy.stubs.ArtifactStub;
+import org.apache.maven.plugins.deploy.stubs.ProjectStub;
+import org.apache.maven.plugins.deploy.stubs.SessionStub;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static org.apache.maven.api.plugin.testing.MojoExtension.getVariableValueFromObject;
+import static org.apache.maven.api.plugin.testing.MojoExtension.setVariableValueToObject;
+import static org.codehaus.plexus.testing.PlexusExtension.getBasedir;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
/**
* @author Allan Ramirez
*/
+@MojoTest
+@ExtendWith( MockitoExtension.class )
public class DeployMojoTest
- extends AbstractMojoTestCase
-{
- private File remoteRepo;
-
- private File localRepo;
-
- private String LOCAL_REPO = getBasedir() + "/target/local-repo";
-
- private String REMOTE_REPO = getBasedir() + "/target/remote-repo";
-
- DeployArtifactStub artifact;
-
- MavenProjectStub project = new MavenProjectStub();
+{
- @Mock
- private MavenSession session;
+ private final String LOCAL_REPO = getBasedir() + "/target/local-repo";
- @InjectMocks
- private DeployMojo mojo;
+ @Inject @SuppressWarnings( "unused" )
+ private Session session;
- public void setUp()
- throws Exception
- {
- super.setUp();
-
- remoteRepo = new File( REMOTE_REPO );
-
- remoteRepo.mkdirs();
-
- localRepo = new File( LOCAL_REPO );
+ @Inject @SuppressWarnings( "unused" )
+ private ArtifactManager artifactManager;
- if ( localRepo.exists() )
- {
- FileUtils.deleteDirectory( localRepo );
- }
+ @Inject @SuppressWarnings( "unused" )
+ private ProjectManager projectManager;
- if ( remoteRepo.exists() )
- {
- FileUtils.deleteDirectory( remoteRepo );
- }
-
-
- }
+ @Inject @SuppressWarnings( "unused" )
+ private ArtifactDeployer artifactDeployer;
- public void tearDown()
- throws Exception
+ @Test
+ @InjectMojo( goal = "deploy", pom = "classpath:/unit/basic-deploy/plugin-config.xml" )
+ public void testDeployTestEnvironment( DeployMojo mojo )
{
- super.tearDown();
-
- if( remoteRepo.exists() )
- {
- //FileUtils.deleteDirectory( remoteRepo );
- }
- }
-
- public void testDeployTestEnvironment()
- throws Exception
- {
- File testPom = new File( getBasedir(),
- "target/test-classes/unit/basic-deploy-test/plugin-config.xml" );
-
- DeployMojo mojo = ( DeployMojo ) lookupMojo( "deploy", testPom );
-
assertNotNull( mojo );
}
-
- public void testBasicDeploy()
+
+ @Test
+ @InjectMojo( goal = "deploy", pom = "classpath:/unit/basic-deploy/plugin-config.xml" )
+ public void testBasicDeploy( DeployMojo mojo )
throws Exception
{
- File testPom = new File( getBasedir(), "target/test-classes/unit/basic-deploy-test/plugin-config.xml" );
-
- mojo = ( DeployMojo ) lookupMojo( "deploy", testPom );
-
- MockitoAnnotations.initMocks( this );
-
assertNotNull( mojo );
- ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
- when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
- MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
- repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( LOCAL_REPO ) );
- when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
-
- File file = new File( getBasedir(),
- "target/test-classes/unit/basic-deploy-test/target/" +
- "deploy-test-file-1.0-SNAPSHOT.jar" );
-
+ File file = new File( getBasedir(), "target/test-classes/unit/basic-deploy/deploy-test-file-1.0-SNAPSHOT.jar" );
assertTrue( file.exists() );
-
- MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );
-
+ Project project = (Project) getVariableValueFromObject( mojo, "project" );
setVariableValueToObject( mojo, "reactorProjects", Collections.singletonList( project ) );
-
- artifact = ( DeployArtifactStub ) project.getArtifact();
-
String packaging = project.getPackaging();
-
assertEquals( "jar", packaging );
-
- artifact.setFile( file );
-
- ArtifactRepositoryStub repo = getRepoStub( mojo );
-
- assertNotNull( repo );
-
- repo.setAppendToUrl( "basic-deploy-test" );
-
- assertEquals( "deploy-test", repo.getId() );
- assertEquals( "deploy-test", repo.getKey() );
- assertEquals( "file", repo.getProtocol() );
- assertEquals( "file://" + getBasedir() + "/target/remote-repo/basic-deploy-test", repo.getUrl() );
-
- mojo.execute();
-
- //check the artifact in local repository
- List expectedFiles = new ArrayList();
- List fileList = new ArrayList();
-
- expectedFiles.add( "org" );
- expectedFiles.add( "apache" );
- expectedFiles.add( "maven" );
- expectedFiles.add( "test" );
- expectedFiles.add( "maven-deploy-test" );
- expectedFiles.add( "1.0-SNAPSHOT" );
- expectedFiles.add( "maven-metadata-deploy-test.xml" );
- // expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.jar" );
- // expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.pom" );
- // as we are in SNAPSHOT the file is here twice
- expectedFiles.add( "maven-metadata-deploy-test.xml" );
- // extra Aether files
- expectedFiles.add( "resolver-status.properties" );
- expectedFiles.add( "resolver-status.properties" );
-
- File localRepo = new File( LOCAL_REPO, "" );
-
- File[] files = localRepo.listFiles();
-
- for (File file2 : files) {
- addFileToList(file2, fileList);
- }
-
- assertEquals( expectedFiles.size(), fileList.size() );
-
- assertEquals( 0, getSizeOfExpectedFiles( fileList, expectedFiles ) );
-
- //check the artifact in remote repository
- expectedFiles = new ArrayList();
- fileList = new ArrayList();
-
- expectedFiles.add( "org" );
- expectedFiles.add( "apache" );
- expectedFiles.add( "maven" );
- expectedFiles.add( "test" );
- expectedFiles.add( "maven-deploy-test" );
- expectedFiles.add( "1.0-SNAPSHOT" );
- expectedFiles.add( "maven-metadata.xml" );
- expectedFiles.add( "maven-metadata.xml.md5" );
- expectedFiles.add( "maven-metadata.xml.sha1" );
- expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.jar" );
- expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.jar.md5" );
- expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.jar.sha1" );
- expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.pom" );
- expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.pom.md5" );
- expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.pom.sha1" );
- // as we are in SNAPSHOT the file is here twice
- expectedFiles.add( "maven-metadata.xml" );
- expectedFiles.add( "maven-metadata.xml.md5" );
- expectedFiles.add( "maven-metadata.xml.sha1" );
-
- remoteRepo = new File( remoteRepo, "basic-deploy-test" );
-
- files = remoteRepo.listFiles();
+ artifactManager.setPath( project.getArtifact(), file.toPath() );
- for (File file1 : files) {
- addFileToList(file1, fileList);
- }
-
- assertEquals( expectedFiles.size(), fileList.size() );
+ ArtifactDeployerRequest request = execute( mojo );
- assertEquals( 0, getSizeOfExpectedFiles( fileList, expectedFiles ) );
+ assertNotNull( request );
+ Set artifacts = new HashSet<>( request.getArtifacts() );
+ assertEquals( new HashSet<>( Arrays.asList(
+ new ArtifactStub( "org.apache.maven.test", "maven-deploy-test", "", "1.0-SNAPSHOT", "jar"),
+ new ArtifactStub( "org.apache.maven.test", "maven-deploy-test", "", "1.0-SNAPSHOT", "pom")
+ ) ), artifacts );
+ assertEquals( getBasedir(), request.getRepository().getUrl() );
}
- public void testSkippingDeploy()
+ @Test
+ @InjectMojo( goal = "deploy", pom = "classpath:/unit/basic-deploy/plugin-config.xml" )
+ public void testSkippingDeploy( DeployMojo mojo )
throws Exception
{
- File testPom = new File( getBasedir(), "target/test-classes/unit/basic-deploy-test/plugin-config.xml" );
-
- DeployMojo mojo = (DeployMojo) lookupMojo( "deploy", testPom );
-
assertNotNull( mojo );
- File file = new File( getBasedir(), "target/test-classes/unit/basic-deploy-test/target/"
- + "deploy-test-file-1.0-SNAPSHOT.jar" );
-
+ File file = new File( getBasedir(), "target/test-classes/unit/basic-deploy/deploy-test-file-1.0-SNAPSHOT.jar" );
assertTrue( file.exists() );
-
- MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );
-
+ Project project = (Project) getVariableValueFromObject( mojo, "project" );
setVariableValueToObject( mojo, "reactorProjects", Collections.singletonList( project ) );
-
- artifact = (DeployArtifactStub) project.getArtifact();
-
String packaging = project.getPackaging();
-
assertEquals( "jar", packaging );
-
- artifact.setFile( file );
-
- ArtifactRepositoryStub repo = getRepoStub( mojo );
-
- assertNotNull( repo );
-
- repo.setAppendToUrl( "basic-deploy-test" );
-
- assertEquals( "deploy-test", repo.getId() );
- assertEquals( "deploy-test", repo.getKey() );
- assertEquals( "file", repo.getProtocol() );
- assertEquals( "file://" + getBasedir() + "/target/remote-repo/basic-deploy-test", repo.getUrl() );
+ artifactManager.setPath( project.getArtifact(), file.toPath() );
setVariableValueToObject( mojo, "skip", Boolean.TRUE.toString() );
-
- mojo.execute();
-
- File localRepo = new File( LOCAL_REPO, "" );
- File[] files = localRepo.listFiles();
-
- assertNull( files );
-
- remoteRepo = new File( remoteRepo, "basic-deploy-test" );
-
- files = remoteRepo.listFiles();
+ ArtifactDeployerRequest request = execute( mojo );
+ assertNull( request );
+ }
- assertNull( files );
- }
-
- public void testBasicDeployWithPackagingAsPom()
+ @Test
+ @InjectMojo( goal = "deploy", pom = "classpath:/unit/basic-deploy/plugin-config.xml" )
+ public void testBasicDeployWithPackagingAsPom( DeployMojo mojo )
throws Exception
{
- File testPom = new File( getBasedir(),
- "target/test-classes/unit/basic-deploy-pom/plugin-config.xml" );
-
- mojo = ( DeployMojo ) lookupMojo( "deploy", testPom );
-
- MockitoAnnotations.initMocks( this );
-
assertNotNull( mojo );
- ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
- when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
- MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
- repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( LOCAL_REPO ) );
- when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
-
- File pomFile = new File( getBasedir(),
- "target/test-classes/unit/basic-deploy-pom/target/" +
- "deploy-test-file-1.0-SNAPSHOT.pom" );
-
+ File pomFile = new File( getBasedir(), "target/test-classes/unit/basic-deploy/deploy-test-file-1.0-SNAPSHOT.pom" );
assertTrue( pomFile.exists() );
-
- MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );
-
+ ProjectStub project = (ProjectStub) getVariableValueFromObject( mojo, "project" );
+ project.setPackaging( "pom" );
+ ((ArtifactStub) project.getArtifact()).setExtension( "pom" );
setVariableValueToObject( mojo, "reactorProjects", Collections.singletonList( project ) );
+ artifactManager.setPath( project.getArtifact(), pomFile.toPath() );
- artifact = (DeployArtifactStub) project.getArtifact();
-
- artifact.setArtifactHandlerExtension( project.getPackaging() );
-
- artifact.setFile( pomFile );
-
- ArtifactRepositoryStub repo = getRepoStub( mojo );
-
- repo.setAppendToUrl( "basic-deploy-pom" );
-
- mojo.execute();
-
- List expectedFiles = new ArrayList();
- List fileList = new ArrayList();
-
- expectedFiles.add( "org" );
- expectedFiles.add( "apache" );
- expectedFiles.add( "maven" );
- expectedFiles.add( "test" );
- expectedFiles.add( "maven-deploy-test" );
- expectedFiles.add( "1.0-SNAPSHOT" );
- expectedFiles.add( "maven-metadata.xml" );
- expectedFiles.add( "maven-metadata.xml.md5" );
- expectedFiles.add( "maven-metadata.xml.sha1" );
- expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.pom" );
- expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.pom.md5" );
- expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.pom.sha1" );
- // as we are in SNAPSHOT the file is here twice
- expectedFiles.add( "maven-metadata.xml" );
- expectedFiles.add( "maven-metadata.xml.md5" );
- expectedFiles.add( "maven-metadata.xml.sha1" );
- remoteRepo = new File( remoteRepo, "basic-deploy-pom" );
-
- File[] files = remoteRepo.listFiles();
+ ArtifactDeployerRequest request = execute( mojo );
- for (File file : files) {
- addFileToList(file, fileList);
- }
-
- assertEquals( expectedFiles.size(), fileList.size() );
-
- assertEquals( 0, getSizeOfExpectedFiles( fileList, expectedFiles ) );
+ assertNotNull( request );
+ Set artifacts = new HashSet<>( request.getArtifacts() );
+ assertEquals( new HashSet<>( Collections.singletonList(
+ new ArtifactStub( "org.apache.maven.test", "maven-deploy-test", "", "1.0-SNAPSHOT", "pom" )
+ ) ), artifacts );
+ assertEquals( getBasedir(), request.getRepository().getUrl() );
}
- public void testDeployIfArtifactFileIsNull()
+ @Test
+ @InjectMojo( goal = "deploy", pom = "classpath:/unit/basic-deploy/plugin-config.xml" )
+ public void testDeployIfArtifactFileIsNull( DeployMojo mojo )
throws Exception
{
- File testPom = new File( getBasedir(),
- "target/test-classes/unit/basic-deploy-test/plugin-config.xml" );
-
- DeployMojo mojo = ( DeployMojo ) lookupMojo( "deploy", testPom );
-
- MockitoAnnotations.initMocks( this );
-
- ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
- when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
-
- setVariableValueToObject( mojo, "session", session );
-
assertNotNull( mojo );
- MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );
-
+ Project project = (Project) getVariableValueFromObject( mojo, "project" );
setVariableValueToObject( mojo, "reactorProjects", Collections.singletonList( project ) );
+ artifactManager.setPath( project.getArtifact(), null );
- artifact = (DeployArtifactStub) project.getArtifact();
-
- artifact.setFile( null );
-
- assertNull( artifact.getFile() );
-
- try
- {
- mojo.execute();
-
- fail( "Did not throw mojo execution exception" );
- }
- catch( MojoExecutionException e )
- {
- //expected
- }
+ assertThrows( MojoException.class, mojo::execute, "Did not throw mojo execution exception" );
}
-
- public void testDeployWithAttachedArtifacts()
- throws Exception
- {
- File testPom = new File( getBasedir(),
- "target/test-classes/unit/basic-deploy-with-attached-artifacts/" +
- "plugin-config.xml" );
-
- mojo = ( DeployMojo ) lookupMojo( "deploy", testPom );
-
- MockitoAnnotations.initMocks( this );
-
- assertNotNull( mojo );
-
- ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
- when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
- MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
- repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( LOCAL_REPO ) );
- when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
-
- MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );
-
- setVariableValueToObject( mojo, "reactorProjects", Collections.singletonList( project ) );
-
- artifact = (DeployArtifactStub) project.getArtifact();
-
- File file = new File( getBasedir(),
- "target/test-classes/unit/basic-deploy-with-attached-artifacts/target/" +
- "deploy-test-file-1.0-SNAPSHOT.jar" );
-
- artifact.setFile( file );
-
- ArtifactRepositoryStub repo = getRepoStub( mojo );
-
- repo.setAppendToUrl( "basic-deploy-with-attached-artifacts" );
-
- mojo.execute();
-
- //check the artifacts in remote repository
- List expectedFiles = new ArrayList();
- List fileList = new ArrayList();
-
- expectedFiles.add( "org" );
- expectedFiles.add( "apache" );
- expectedFiles.add( "maven" );
- expectedFiles.add( "test" );
- expectedFiles.add( "maven-deploy-test" );
- expectedFiles.add( "1.0-SNAPSHOT" );
- expectedFiles.add( "maven-metadata.xml" );
- expectedFiles.add( "maven-metadata.xml.md5" );
- expectedFiles.add( "maven-metadata.xml.sha1" );
- expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.jar" );
- expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.jar.md5" );
- expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.jar.sha1" );
- expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.pom" );
- expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.pom.md5" );
- expectedFiles.add( "maven-deploy-test-1.0-SNAPSHOT.pom.sha1" );
- // as we are in SNAPSHOT the file is here twice
- expectedFiles.add( "maven-metadata.xml" );
- expectedFiles.add( "maven-metadata.xml.md5" );
- expectedFiles.add( "maven-metadata.xml.sha1" );
- expectedFiles.add( "attached-artifact-test-0" );
- expectedFiles.add( "1.0-SNAPSHOT" );
- expectedFiles.add( "maven-metadata.xml" );
- expectedFiles.add( "maven-metadata.xml.md5" );
- expectedFiles.add( "maven-metadata.xml.sha1" );
- expectedFiles.add( "attached-artifact-test-0-1.0-SNAPSHOT.jar" );
- expectedFiles.add( "attached-artifact-test-0-1.0-SNAPSHOT.jar.md5" );
- expectedFiles.add( "attached-artifact-test-0-1.0-SNAPSHOT.jar.sha1" );
- // as we are in SNAPSHOT the file is here twice
- expectedFiles.add( "maven-metadata.xml" );
- expectedFiles.add( "maven-metadata.xml.md5" );
- expectedFiles.add( "maven-metadata.xml.sha1" );
-
- remoteRepo = new File( remoteRepo, "basic-deploy-with-attached-artifacts" );
-
- File[] files = remoteRepo.listFiles();
- for (File file1 : files) {
- addFileToList(file1, fileList);
- }
-
- assertEquals( expectedFiles.size(), fileList.size() );
-
- assertEquals( 0, getSizeOfExpectedFiles( fileList, expectedFiles ) );
- }
-
- @Ignore( "SCP is not part of Maven3 distribution. Aether handles transport extensions." )
- public void _testBasicDeployWithScpAsProtocol()
+ @Test
+ @InjectMojo( goal = "deploy", pom = "classpath:/unit/basic-deploy/plugin-config.xml" )
+ public void testDeployWithAttachedArtifacts( DeployMojo mojo )
throws Exception
{
- String originalUserHome = System.getProperty( "user.home" );
-
- // FIX THE DAMN user.home BEFORE YOU DELETE IT!!!
- File altHome = new File( getBasedir(), "target/ssh-user-home" );
- altHome.mkdirs();
-
- System.out.println( "Testing user.home value for .ssh dir: " + altHome.getCanonicalPath() );
-
- Properties props = System.getProperties();
- props.setProperty( "user.home", altHome.getCanonicalPath() );
-
- System.setProperties( props );
-
- File testPom = new File( getBasedir(),
- "target/test-classes/unit/basic-deploy-scp/plugin-config.xml" );
-
- mojo = ( DeployMojo ) lookupMojo( "deploy", testPom );
-
assertNotNull( mojo );
-
- ArtifactDeployerStub deployer = new ArtifactDeployerStub();
-
- setVariableValueToObject( mojo, "deployer", deployer );
-
- File file = new File( getBasedir(),
- "target/test-classes/unit/basic-deploy-scp/target/" +
- "deploy-test-file-1.0-SNAPSHOT.jar" );
-
- assertTrue( file.exists() );
-
- MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );
-
+ Project project = (Project) getVariableValueFromObject( mojo, "project" );
setVariableValueToObject( mojo, "reactorProjects", Collections.singletonList( project ) );
-
- artifact = (DeployArtifactStub) project.getArtifact();
-
- artifact.setFile( file );
-
- String altUserHome = System.getProperty( "user.home" );
-
- if ( altUserHome.equals( originalUserHome ) )
- {
- // this is *very* bad!
- throw new IllegalStateException( "Setting 'user.home' system property to alternate value did NOT work. Aborting test." );
- }
-
- File sshFile = new File( altUserHome, ".ssh" );
-
- System.out.println( "Testing .ssh dir: " + sshFile.getCanonicalPath() );
-
- //delete first the .ssh folder if existing before executing the mojo
- if( sshFile.exists() )
- {
- FileUtils.deleteDirectory( sshFile );
- }
-
- mojo.execute();
-
- assertTrue( sshFile.exists() );
-
- FileUtils.deleteDirectory( sshFile );
+ File file = new File( getBasedir(), "target/test-classes/unit/basic-deploy/deploy-test-file-1.0-SNAPSHOT.jar" );
+ artifactManager.setPath( project.getArtifact(), file.toPath() );
+ projectManager.attachArtifact( project,
+ new ArtifactStub( "org.apache.maven.test", "attached-artifact-test", "", "1.0-SNAPSHOT", "jar" ),
+ Paths.get( getBasedir(), "target/test-classes/unit/basic-deploy/attached-artifact-test-1.0-SNAPSHOT.jar" ) );
+
+ ArtifactDeployerRequest request = execute( mojo );
+
+ assertNotNull( request );
+ Set artifacts = new HashSet<>( request.getArtifacts() );
+ assertEquals( new HashSet<>( Arrays.asList(
+ new ArtifactStub( "org.apache.maven.test", "maven-deploy-test", "", "1.0-SNAPSHOT", "jar"),
+ new ArtifactStub( "org.apache.maven.test", "maven-deploy-test", "", "1.0-SNAPSHOT", "pom"),
+ new ArtifactStub( "org.apache.maven.test", "attached-artifact-test", "", "1.0-SNAPSHOT", "jar")
+ ) ), artifacts );
+ assertEquals( getBasedir(), request.getRepository().getUrl() );
}
+ @Test
public void testLegacyAltDeploymentRepositoryWithDefaultLayout()
- throws Exception
{
- DeployMojo mojo = spy( new DeployMojo() );
-
- ArtifactRepository repository = mock( ArtifactRepository.class );
- when( mojo.createDeploymentArtifactRepository( "altDeploymentRepository", "http://localhost"
- ) ).thenReturn( repository );
-
- project.setVersion( "1.0-SNAPSHOT" );
+ DeployMojo mojo = spy( new TestDeployMojo() );
+ RemoteRepository repository = mock( RemoteRepository.class );
+ when( mojo.createDeploymentArtifactRepository( "altDeploymentRepository", "http://localhost" ) )
+ .thenReturn( repository );
+ mojo.altDeploymentRepository = "altDeploymentRepository::default::http://localhost";
- ProjectDeployerRequest pdr =
- new ProjectDeployerRequest()
- .setProject( project )
- .setAltDeploymentRepository( "altDeploymentRepository::default::http://localhost" );
-
- assertEquals( repository,
- mojo.getDeploymentRepository( pdr ) );
+ assertEquals( repository, mojo.getDeploymentRepository( true ) );
}
+ @Test
public void testLegacyAltDeploymentRepositoryWithLegacyLayout()
- throws Exception
{
- DeployMojo mojo = spy( new DeployMojo() );
-
- 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 );
- fail( "Should throw: Invalid legacy syntax and layout for repository." );
- }
- catch( MojoFailureException e )
- {
- assertEquals( e.getMessage(), "Invalid legacy syntax and layout for repository.");
- assertEquals( e.getLongMessage(), "Invalid legacy syntax and layout for alternative repository. Use \"altDeploymentRepository::http://localhost\" instead, and only default layout is supported.");
- }
+ DeployMojo mojo = spy( new TestDeployMojo() );
+ RemoteRepository repository = mock( RemoteRepository.class );
+ when( mojo.createDeploymentArtifactRepository( "altDeploymentRepository", "http://localhost" ) )
+ .thenReturn( repository );
+ mojo.altDeploymentRepository = "altDeploymentRepository::legacy::http://localhost";
+
+ MojoException e = assertThrows( MojoException.class, () -> mojo.getDeploymentRepository( true ), "Should throw: Invalid legacy syntax and layout for repository." );
+ assertEquals( e.getMessage(), "Invalid legacy syntax and layout for repository.");
+ assertEquals( e.getLongMessage(), "Invalid legacy syntax and layout for alternative repository. Use \"altDeploymentRepository::http://localhost\" instead, and only default layout is supported.");
}
+ @Test
public void testInsaneAltDeploymentRepository()
- throws Exception
{
- DeployMojo mojo = spy( new DeployMojo() );
-
- 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 );
- fail( "Should throw: Invalid legacy syntax and layout for repository." );
- }
- catch( MojoFailureException e )
- {
- assertEquals( e.getMessage(), "Invalid legacy syntax and layout for repository.");
- assertEquals( e.getLongMessage(), "Invalid legacy syntax and layout for alternative repository. Use \"altDeploymentRepository::wow::foo::http://localhost\" instead, and only default layout is supported.");
- }
+ DeployMojo mojo = spy( new TestDeployMojo() );
+ RemoteRepository repository = mock( RemoteRepository.class );
+ when( mojo.createDeploymentArtifactRepository( "altDeploymentRepository", "http://localhost" ) )
+ .thenReturn( repository );
+ mojo.altDeploymentRepository = "altDeploymentRepository::hey::wow::foo::http://localhost";
+
+ MojoException e = assertThrows( MojoException.class, () -> mojo.getDeploymentRepository( true ), "Should throw: Invalid legacy syntax and layout for repository." );
+ assertEquals( e.getMessage(), "Invalid legacy syntax and layout for repository.");
+ assertEquals( e.getLongMessage(), "Invalid legacy syntax and layout for alternative repository. Use \"altDeploymentRepository::wow::foo::http://localhost\" instead, and only default layout is supported.");
}
+ @Test
public void testDefaultScmSvnAltDeploymentRepository()
- throws Exception
{
- DeployMojo mojo = spy( new DeployMojo() );
-
- 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" );
+ DeployMojo mojo = spy( new TestDeployMojo() );
+ RemoteRepository repository = mock( RemoteRepository.class );
+ when( mojo.createDeploymentArtifactRepository( "altDeploymentRepository", "scm:svn:http://localhost" ) )
+ .thenReturn( repository );
+ mojo.altDeploymentRepository = "altDeploymentRepository::default::scm:svn:http://localhost";
- assertEquals( repository,
- mojo.getDeploymentRepository( pdr ) );
+ assertEquals( repository, mojo.getDeploymentRepository( true ) );
}
+
+ @Test
public void testLegacyScmSvnAltDeploymentRepository()
- throws Exception
{
- DeployMojo mojo = spy( new DeployMojo() );
-
- 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 );
- fail( "Should throw: Invalid legacy syntax and layout for repository." );
- }
- catch( MojoFailureException e )
- {
- assertEquals( e.getMessage(), "Invalid legacy syntax and layout for repository.");
- assertEquals( e.getLongMessage(), "Invalid legacy syntax and layout for alternative repository. Use \"altDeploymentRepository::scm:svn:http://localhost\" instead, and only default layout is supported.");
- }
+ DeployMojo mojo = spy( new TestDeployMojo() );
+ RemoteRepository repository = mock( RemoteRepository.class );
+ when( mojo.createDeploymentArtifactRepository( "altDeploymentRepository", "http://localhost" ) )
+ .thenReturn( repository );
+ mojo.altDeploymentRepository = "altDeploymentRepository::legacy::scm:svn:http://localhost";
+
+ MojoException e = assertThrows( MojoException.class, () -> mojo.getDeploymentRepository( true ), "Should throw: Invalid legacy syntax and layout for repository." );
+ assertEquals( e.getMessage(), "Invalid legacy syntax and layout for repository.");
+ assertEquals( e.getLongMessage(), "Invalid legacy syntax and layout for alternative repository. Use \"altDeploymentRepository::scm:svn:http://localhost\" instead, and only default layout is supported.");
}
+ @Test
public void testAltSnapshotDeploymentRepository()
- throws Exception
{
- DeployMojo mojo = spy( new DeployMojo() );
-
- ArtifactRepository repository = mock( ArtifactRepository.class );
- when( mojo.createDeploymentArtifactRepository( "altSnapshotDeploymentRepository", "http://localhost"
- ) ).thenReturn( repository );
+ DeployMojo mojo = spy( new TestDeployMojo() );
+ RemoteRepository repository = mock( RemoteRepository.class );
+ when( mojo.createDeploymentArtifactRepository( "altSnapshotDeploymentRepository", "http://localhost" ) )
+ .thenReturn( repository );
- project.setVersion( "1.0-SNAPSHOT" );
+ mojo.altDeploymentRepository = "altSnapshotDeploymentRepository::http://localhost";
- ProjectDeployerRequest pdr =
- new ProjectDeployerRequest()
- .setProject( project )
- .setAltDeploymentRepository( "altSnapshotDeploymentRepository::http://localhost" );
- assertEquals( repository,
- mojo.getDeploymentRepository( pdr ));
+ assertEquals( repository, mojo.getDeploymentRepository( true ));
}
+ @Test
public void testAltReleaseDeploymentRepository()
- throws Exception
{
- DeployMojo mojo = spy( new DeployMojo() );
-
- ArtifactRepository repository = mock( ArtifactRepository.class );
+ DeployMojo mojo = spy( new TestDeployMojo() );
+ RemoteRepository repository = mock( RemoteRepository.class );
when( mojo.createDeploymentArtifactRepository( "altReleaseDeploymentRepository", "http://localhost" ) ).thenReturn( repository );
+ mojo.altDeploymentRepository = "altReleaseDeploymentRepository::http://localhost";
- project.setVersion( "1.0" );
-
- ProjectDeployerRequest pdr =
- new ProjectDeployerRequest()
- .setProject( project )
- .setAltReleaseDeploymentRepository( "altReleaseDeploymentRepository::http://localhost" );
-
- assertEquals( repository,
- mojo.getDeploymentRepository( pdr ));
+ assertEquals( repository, mojo.getDeploymentRepository( false ));
}
- private void addFileToList( File file, List fileList )
+
+ private ArtifactDeployerRequest execute( DeployMojo mojo )
{
- if( !file.isDirectory() )
- {
- fileList.add( file.getName() );
- }
- else
- {
- fileList.add( file.getName() );
+ ArgumentCaptor requestCaptor = ArgumentCaptor.forClass( ArtifactDeployerRequest.class );
+ doNothing().when( artifactDeployer ).deploy( requestCaptor.capture() );
- File[] files = file.listFiles();
+ mojo.execute();
- for (File file1 : files) {
- addFileToList(file1, fileList);
- }
- }
- }
-
- private int getSizeOfExpectedFiles( List fileList, List expectedFiles )
+ List requests = requestCaptor.getAllValues();
+ assertNotNull( requests );
+ return requests.isEmpty() ? null : requests.get( requests.size() - 1 );
+ }
+
+ class TestDeployMojo extends DeployMojo
{
- for( String fileName : fileList )
+ TestDeployMojo( )
{
- // translate uniqueVersion to -SNAPSHOT
- fileName = fileName.replaceFirst( "-\\d{8}\\.\\d{6}-\\d+", "-SNAPSHOT" );
-
- if( !expectedFiles.remove( fileName ) )
+ super();
+ try
+ {
+ setVariableValueToObject( this, "session", session );
+ }
+ catch ( IllegalAccessException e )
{
- fail( fileName + " is not included in the expected files" );
+ throw new IllegalStateException( "Unable to inject session", e );
}
}
- return expectedFiles.size();
- }
+ }
- private ArtifactRepositoryStub getRepoStub( Object mojo )
- throws Exception
+ @Provides @Singleton @SuppressWarnings( "unused" )
+ private Session getMockSession()
+ {
+ return SessionStub.getMockSession( LOCAL_REPO );
+ }
+
+ @Provides @SuppressWarnings( "unused" )
+ private ArtifactDeployer getMockArtifactDeployer( Session session )
+ {
+ return session.getService( ArtifactDeployer.class );
+ }
+
+ @Provides @SuppressWarnings( "unused" )
+ private ArtifactManager getMockArtifactManager( Session session )
+ {
+ return session.getService( ArtifactManager.class );
+ }
+
+ @Provides @SuppressWarnings( "unused" )
+ private ProjectManager getMockProjectManager( Session session )
+ {
+ return session.getService( ProjectManager.class );
+ }
+
+ @Provides @SuppressWarnings( "unused" )
+ private ProjectBuilder getMockProjectBuilder( Session session )
{
- MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );
- return (ArtifactRepositoryStub) project.getDistributionManagementArtifactRepository();
+ return session.getService( ProjectBuilder.class );
}
}
diff --git a/src/test/java/org/apache/maven/plugins/deploy/Utils.java b/src/test/java/org/apache/maven/plugins/deploy/Utils.java
index 4df74424..f4acbc9d 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/Utils.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/Utils.java
@@ -26,7 +26,7 @@
import java.util.Map;
import org.apache.maven.plugin.MojoExecutionException;
-import org.sonatype.aether.util.ChecksumUtils;
+import org.eclipse.aether.util.ChecksumUtils;
/**
* A utility class to assist testing.
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 d0b47d43..00000000
--- 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
- }
-}
diff --git a/src/test/java/org/apache/maven/plugins/deploy/stubs/ArtifactRepositoryStub.java b/src/test/java/org/apache/maven/plugins/deploy/stubs/ArtifactRepositoryStub.java
deleted file mode 100644
index 0b94ebed..00000000
--- a/src/test/java/org/apache/maven/plugins/deploy/stubs/ArtifactRepositoryStub.java
+++ /dev/null
@@ -1,134 +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 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.layout.ArtifactRepositoryLayout;
-import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
-import org.apache.maven.plugin.testing.stubs.StubArtifactRepository;
-
-public class ArtifactRepositoryStub
- extends StubArtifactRepository
-{
- private boolean blacklisted;
-
- private ArtifactRepositoryLayout layout;
-
- private String url;
-
- private String basedir = System.getProperty( "basedir" );
-
- public ArtifactRepositoryStub()
- {
- super( null );
- }
-
- public ArtifactRepositoryStub( String dir )
- {
- super( dir );
- }
-
- public String pathOf( Artifact artifact )
- {
- return getLayout().pathOf( artifact );
- }
-
- public String pathOfRemoteRepositoryMetadata( ArtifactMetadata artifactMetadata )
- {
- return getLayout().pathOfRemoteRepositoryMetadata( artifactMetadata );
- }
-
- public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository )
- {
- return getLayout().pathOfLocalRepositoryMetadata( metadata, repository );
- }
-
- public String getUrl()
- {
- return url;
- }
-
- public void setAppendToUrl( String dir )
- {
- this.url = "file://" + basedir + "/target/remote-repo/" + dir;
- }
-
- public String getBasedir()
- {
- return basedir;
- }
-
- public String getProtocol()
- {
- return "file";
- }
-
- public String getId()
- {
- return "deploy-test";
- }
-
- public ArtifactRepositoryPolicy getSnapshots()
- {
- return new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS,
- ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE );
- }
-
- public ArtifactRepositoryPolicy getReleases()
- {
- return new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS,
- ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE );
- }
-
- public ArtifactRepositoryLayout getLayout()
- {
- if( layout != null )
- {
- return layout;
- }
- else
- {
- return new DefaultRepositoryLayout();
- }
- }
-
- public String getKey()
- {
- return getId();
- }
-
- public boolean isUniqueVersion()
- {
- return false;
- }
-
- public void setBlacklisted( boolean blackListed )
- {
- this.blacklisted = blackListed;
- }
-
- public boolean isBlacklisted()
- {
- return blacklisted;
- }
-}
diff --git a/src/test/java/org/apache/maven/plugins/deploy/stubs/ArtifactRepositoryStub2.java b/src/test/java/org/apache/maven/plugins/deploy/stubs/ArtifactRepositoryStub2.java
deleted file mode 100644
index 0e3338fc..00000000
--- a/src/test/java/org/apache/maven/plugins/deploy/stubs/ArtifactRepositoryStub2.java
+++ /dev/null
@@ -1,60 +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.
- */
-
-public class ArtifactRepositoryStub2
- extends ArtifactRepositoryStub
-{
- private String protocol;
-
- public ArtifactRepositoryStub2()
- {
- super();
- }
-
- public ArtifactRepositoryStub2( String dir )
- {
- super( dir );
- }
-
- public String getUrl()
- {
- return "file://" + System.getProperty( "basedir" ) + "/target/remote-repo/basic-deploy-scp";
- }
-
- public String getBasedir()
- {
- return System.getProperty( "basedir" );
- }
-
- public String getProtocol()
- {
- if( this.protocol == null || this.protocol.equals("") )
- {
- this.protocol = "scp";
- }
- return this.protocol;
- }
-
- public void setProtocol( String protocol )
- {
- this.protocol = protocol;
- }
-}
diff --git a/src/test/java/org/apache/maven/plugins/deploy/stubs/ArtifactStub.java b/src/test/java/org/apache/maven/plugins/deploy/stubs/ArtifactStub.java
new file mode 100644
index 00000000..f17dcd20
--- /dev/null
+++ b/src/test/java/org/apache/maven/plugins/deploy/stubs/ArtifactStub.java
@@ -0,0 +1,189 @@
+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 javax.annotation.Nonnull;
+
+import java.nio.file.Path;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.regex.Pattern;
+
+import org.apache.maven.api.Artifact;
+
+public class ArtifactStub implements Artifact
+{
+ private static final String SNAPSHOT = "SNAPSHOT";
+
+ private static final Pattern SNAPSHOT_TIMESTAMP = Pattern.compile( "^(.*-)?([0-9]{8}\\.[0-9]{6}-[0-9]+)$" );
+
+ private String groupId;
+ private String artifactId;
+ private String classifier = "";
+ private String version;
+ private String extension;
+ private String baseVersion;
+ private Path path;
+
+ public ArtifactStub()
+ {
+ }
+
+ public ArtifactStub( String groupId, String artifactId, String classifier, String version, String extension )
+ {
+ this.groupId = groupId;
+ this.artifactId = artifactId;
+ this.classifier = classifier;
+ this.version = version;
+ this.extension = extension;
+ }
+
+ @Nonnull
+ @Override
+ public String getGroupId()
+ {
+ return groupId;
+ }
+
+ public void setGroupId( String groupId )
+ {
+ this.groupId = groupId;
+ }
+
+ @Nonnull
+ @Override
+ public String getArtifactId()
+ {
+ return artifactId;
+ }
+
+ public void setArtifactId( String artifactId )
+ {
+ this.artifactId = artifactId;
+ }
+
+ @Nonnull
+ @Override
+ public String getClassifier()
+ {
+ return classifier;
+ }
+
+ public void setClassifier( String classifier )
+ {
+ this.classifier = classifier;
+ }
+
+ @Nonnull
+ @Override
+ public String getVersion()
+ {
+ return version;
+ }
+
+ public void setVersion( String version )
+ {
+ this.version = version;
+ }
+
+ @Nonnull
+ @Override
+ public String getExtension()
+ {
+ return extension;
+ }
+
+ public void setExtension( String extension )
+ {
+ this.extension = extension;
+ }
+
+ @Nonnull
+ @Override
+ public String getBaseVersion()
+ {
+ if ( baseVersion == null && version != null )
+ {
+ baseVersion = version;
+ }
+ return baseVersion;
+ }
+
+ public void setBaseVersion( String baseVersion )
+ {
+ this.baseVersion = baseVersion;
+ }
+
+ @Nonnull
+ @Override
+ public Optional getPath()
+ {
+ return Optional.ofNullable( path );
+ }
+
+ public void setPath( Path path )
+ {
+ this.path = path;
+ }
+
+ @Override
+ public boolean isSnapshot()
+ {
+ return version.endsWith( SNAPSHOT ) || SNAPSHOT_TIMESTAMP.matcher( version ).matches();
+ }
+
+ @Override
+ public boolean equals( Object o )
+ {
+ if ( this == o )
+ {
+ return true;
+ }
+ if ( o == null || getClass() != o.getClass() )
+ {
+ return false;
+ }
+ ArtifactStub that = (ArtifactStub) o;
+ return Objects.equals( groupId, that.groupId ) && Objects.equals( artifactId, that.artifactId )
+ && Objects.equals( classifier, that.classifier ) && Objects.equals( version,
+ that.version ) && Objects.equals( extension, that.extension ) && Objects.equals(
+ baseVersion, that.baseVersion ) && Objects.equals( path, that.path );
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return Objects.hash( groupId, artifactId, classifier, version, extension, baseVersion, path );
+ }
+
+ @Override
+ public String toString()
+ {
+ return "ArtifactStub{" +
+ "groupId='" + groupId + '\'' +
+ ", artifactId='" + artifactId + '\'' +
+ ", classifier='" + classifier + '\'' +
+ ", version='" + version + '\'' +
+ ", extension='" + extension + '\'' +
+ ", baseVersion='" + baseVersion + '\'' +
+ ", path=" + path +
+ '}';
+ }
+}
diff --git a/src/test/java/org/apache/maven/plugins/deploy/stubs/AttachedArtifactStub.java b/src/test/java/org/apache/maven/plugins/deploy/stubs/AttachedArtifactStub.java
deleted file mode 100644
index 0419a85c..00000000
--- a/src/test/java/org/apache/maven/plugins/deploy/stubs/AttachedArtifactStub.java
+++ /dev/null
@@ -1,38 +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.io.File;
-
-public class AttachedArtifactStub
- extends DeployArtifactStub
-{
- public String getArtifactId()
- {
- return "attached-artifact-test-0";
- }
-
- public File getFile()
- {
- return new File( System.getProperty( "basedir" ),
- "target/test-classes/unit/basic-deploy-with-attached-artifacts/" +
- "target/deploy-test-file-1.0-SNAPSHOT.jar" );
- }
-}
diff --git a/src/test/java/org/apache/maven/plugins/deploy/stubs/DeployArtifactStub.java b/src/test/java/org/apache/maven/plugins/deploy/stubs/DeployArtifactStub.java
deleted file mode 100644
index 24f31d58..00000000
--- a/src/test/java/org/apache/maven/plugins/deploy/stubs/DeployArtifactStub.java
+++ /dev/null
@@ -1,139 +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.io.File;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.maven.artifact.handler.ArtifactHandler;
-import org.apache.maven.artifact.handler.DefaultArtifactHandler;
-import org.apache.maven.artifact.metadata.ArtifactMetadata;
-import org.apache.maven.plugin.testing.stubs.ArtifactStub;
-
-public class DeployArtifactStub
- extends ArtifactStub
-{
- private Map
diff --git a/src/test/resources/unit/deploy-file-classifier/plugin-config.xml b/src/test/resources/unit/deploy-file/plugin-config-classifier.xml
similarity index 86%
rename from src/test/resources/unit/deploy-file-classifier/plugin-config.xml
rename to src/test/resources/unit/deploy-file/plugin-config-classifier.xml
index b77961b4..2ec0268a 100644
--- a/src/test/resources/unit/deploy-file-classifier/plugin-config.xml
+++ b/src/test/resources/unit/deploy-file/plugin-config-classifier.xml
@@ -27,9 +27,9 @@ under the License.
maven-deploy-file-test
1.0
jar
- ${basedir}/src/test/resources/unit/deploy-file-classifier/target/deploy-test-file-1.0-SNAPSHOT.jar
+ ${basedir}/src/test/resources/unit/deploy-file/deploy-test-file-1.0-SNAPSHOT.jar
deploy-test
- file://${basedir}/target/remote-repo/deploy-file-classifier
+ file://${basedir}/target/remote-repo/deploy-file
bin
true
diff --git a/src/test/resources/unit/deploy-file-pom-file/plugin-config.xml b/src/test/resources/unit/deploy-file/plugin-config-pom-file.xml
similarity index 89%
rename from src/test/resources/unit/deploy-file-pom-file/plugin-config.xml
rename to src/test/resources/unit/deploy-file/plugin-config-pom-file.xml
index 3a4e2ce0..42b15e10 100644
Binary files a/src/test/resources/unit/deploy-file-pom-file/plugin-config.xml and b/src/test/resources/unit/deploy-file/plugin-config-pom-file.xml differ
diff --git a/src/test/resources/unit/deploy-file-test/plugin-config.xml b/src/test/resources/unit/deploy-file/plugin-config-test.xml
similarity index 92%
rename from src/test/resources/unit/deploy-file-test/plugin-config.xml
rename to src/test/resources/unit/deploy-file/plugin-config-test.xml
index 67b98a17..6ab5d91b 100644
--- a/src/test/resources/unit/deploy-file-test/plugin-config.xml
+++ b/src/test/resources/unit/deploy-file/plugin-config-test.xml
@@ -27,7 +27,7 @@ under the License.
maven-deploy-file-test
1.0
jar
- ${basedir}/src/test/resources/unit/deploy-file-test/target/deploy-test-file-1.0-SNAPSHOT.jar
+ ${basedir}/src/test/resources/unit/deploy-file/deploy-test-file-1.0-SNAPSHOT.jar
deploy-test
file://${basedir}/target/remote-repo/deploy-file-test
POM was created from deploy:deploy-file