diff --git a/pom.xml b/pom.xml
index 1284f130..385b4d9f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -63,10 +63,10 @@ under the License.
+ 7
3.2.5
1.7.5
1.0.0.v20140518
- 7
2021-12-27T14:11:19Z
@@ -102,16 +102,6 @@ under the License.
${slf4jVersion}
provided
-
- org.apache.maven.shared
- maven-artifact-transfer
- 0.13.1
-
-
- commons-io
- commons-io
- 2.6
-
org.codehaus.plexus
plexus-utils
@@ -121,11 +111,13 @@ under the License.
org.eclipse.aether
aether-api
${resolverVersion}
+ provided
org.eclipse.aether
aether-util
${resolverVersion}
+ compile
diff --git a/src/main/java/org/apache/maven/plugins/deploy/AbstractDeployMojo.java b/src/main/java/org/apache/maven/plugins/deploy/AbstractDeployMojo.java
index 3939a8ea..4a66ecd8 100644
--- a/src/main/java/org/apache/maven/plugins/deploy/AbstractDeployMojo.java
+++ b/src/main/java/org/apache/maven/plugins/deploy/AbstractDeployMojo.java
@@ -19,16 +19,18 @@
* 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.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.rtinfo.RuntimeInformation;
+import org.eclipse.aether.RepositorySystem;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.deployment.DeployRequest;
+import org.eclipse.aether.deployment.DeploymentException;
+import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.util.version.GenericVersionScheme;
import org.eclipse.aether.version.InvalidVersionSpecificationException;
import org.eclipse.aether.version.Version;
@@ -37,9 +39,8 @@
* Abstract class for Deploy mojo's.
*/
public abstract class AbstractDeployMojo
- extends AbstractMojo
+ extends AbstractMojo
{
-
/**
* Flag whether Maven is currently in online/offline mode.
*/
@@ -49,17 +50,20 @@ public abstract class AbstractDeployMojo
/**
* Parameter used to control how many times a failed deployment will be retried before giving up and failing. If a
* value outside the range 1-10 is specified it will be pulled to the nearest value within the range 1-10.
- *
+ *
* @since 2.7
*/
@Parameter( property = "retryFailedDeploymentCount", defaultValue = "1" )
private int retryFailedDeploymentCount;
+ @Component
+ private RuntimeInformation runtimeInformation;
+
@Parameter( defaultValue = "${session}", readonly = true, required = true )
- private MavenSession session;
+ protected MavenSession session;
@Component
- private RuntimeInformation runtimeInformation;
+ protected RepositorySystem repositorySystem;
private static final String AFFECTED_MAVEN_PACKAGING = "maven-plugin";
@@ -68,7 +72,7 @@ public abstract class AbstractDeployMojo
/* Setters and Getters */
void failIfOffline()
- throws MojoFailureException
+ throws MojoFailureException
{
if ( offline )
{
@@ -76,22 +80,9 @@ void failIfOffline()
}
}
- int getRetryFailedDeploymentCount()
- {
- return retryFailedDeploymentCount;
- }
-
- protected ArtifactRepository createDeploymentArtifactRepository( String id, String url )
- {
- return new MavenArtifactRepository( id, url, new DefaultRepositoryLayout(), new ArtifactRepositoryPolicy(),
- new ArtifactRepositoryPolicy() );
- }
-
- protected final MavenSession getSession()
- {
- return session;
- }
-
+ /**
+ * If this plugin used in pre-3.9.0 Maven, the packaging {@code maven-plugin} will not deploy G level metadata.
+ */
protected void warnIfAffectedPackagingAndMaven( final String packaging )
{
if ( AFFECTED_MAVEN_PACKAGING.equals( packaging ) )
@@ -116,4 +107,72 @@ protected void warnIfAffectedPackagingAndMaven( final String packaging )
}
}
}
+
+ /**
+ * Creates resolver {@link RemoteRepository} equipped with needed whistles and bells.
+ */
+ protected RemoteRepository getRemoteRepository( final String repositoryId, final String url )
+ {
+ RemoteRepository result = new RemoteRepository.Builder( repositoryId, "default", url ).build();
+
+ if ( result.getAuthentication() == null || result.getProxy() == null )
+ {
+ RemoteRepository.Builder builder = new RemoteRepository.Builder( result );
+
+ if ( result.getAuthentication() == null )
+ {
+ builder.setAuthentication( session.getRepositorySession().getAuthenticationSelector()
+ .getAuthentication( result ) );
+ }
+
+ if ( result.getProxy() == null )
+ {
+ builder.setProxy( session.getRepositorySession().getProxySelector().getProxy( result ) );
+ }
+
+ result = builder.build();
+ }
+
+ return result;
+ }
+
+ /**
+ * Handles high level retries (this was buried into MAT).
+ */
+ protected void deploy( RepositorySystemSession session, DeployRequest deployRequest ) throws MojoExecutionException
+ {
+ int retryFailedDeploymentCounter = Math.max( 1, Math.min( 10, retryFailedDeploymentCount ) );
+ DeploymentException exception = null;
+ for ( int count = 0; count < retryFailedDeploymentCounter; count++ )
+ {
+ try
+ {
+ if ( count > 0 )
+ {
+ getLog().info( "Retrying deployment attempt " + ( count + 1 ) + " of "
+ + retryFailedDeploymentCounter );
+ }
+
+ repositorySystem.deploy( session, deployRequest );
+ exception = null;
+ break;
+ }
+ catch ( DeploymentException e )
+ {
+ if ( count + 1 < retryFailedDeploymentCounter )
+ {
+ getLog().warn( "Encountered issue during deployment: " + e.getLocalizedMessage() );
+ getLog().debug( e );
+ }
+ if ( exception == null )
+ {
+ exception = e;
+ }
+ }
+ }
+ if ( exception != null )
+ {
+ throw new MojoExecutionException( exception.getMessage(), exception );
+ }
+ }
}
diff --git a/src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java b/src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java
index 12267e7e..5d950438 100644
--- a/src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java
+++ b/src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java
@@ -27,44 +27,34 @@
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
-import java.util.ArrayList;
import java.util.Enumeration;
-import java.util.List;
+import java.util.Objects;
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.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;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.WriterFactory;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.artifact.ArtifactType;
+import org.eclipse.aether.artifact.DefaultArtifact;
+import org.eclipse.aether.deployment.DeployRequest;
+import org.eclipse.aether.deployment.DeploymentException;
+import org.eclipse.aether.repository.RemoteRepository;
+import org.eclipse.aether.util.artifact.SubArtifact;
/**
* Installs the artifact in the remote repository.
@@ -75,21 +65,6 @@
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.
*/
@@ -177,16 +152,6 @@ public class DeployFileMojo
@Parameter( property = "classifier" )
private String classifier;
- /**
- * Whether to deploy snapshots with a unique version or not.
- *
- * @deprecated As of Maven 3, this isn't supported anymore and this parameter is only present to break the build if
- * you use it!
- */
- @Parameter( property = "uniqueVersion" )
- @Deprecated
- private Boolean uniqueVersion;
-
/**
* A comma separated list of types for each of the extra side artifacts to deploy. If there is a mis-match in the
* number of entries in {@link #files} or {@link #classifiers}, then an error will be raised.
@@ -208,9 +173,6 @@ public class DeployFileMojo
@Parameter( property = "files" )
private String files;
- @Component
- private RepositoryManager repoManager;
-
void initProperties()
throws MojoExecutionException
{
@@ -303,22 +265,13 @@ void initProperties()
if ( packaging == null && file != null )
{
- packaging = FileUtils.getExtension( file.getName() );
+ packaging = getExtension( file );
}
}
public void execute()
throws MojoExecutionException, MojoFailureException
{
- if ( uniqueVersion != null )
- {
- throw new MojoExecutionException( "You are using 'uniqueVersion' which has been removed"
- + " from the maven-deploy-plugin. "
- + "Please see the >>Major Version Upgrade to version 3.0.0<< on the plugin site." );
- }
-
- failIfOffline();
-
if ( !file.exists() )
{
throw new MojoExecutionException( file.getPath() + " not found." );
@@ -326,68 +279,86 @@ public void execute()
initProperties();
- ArtifactRepository deploymentRepository = createDeploymentArtifactRepository( repositoryId, url );
-
- String protocol = deploymentRepository.getProtocol();
+ RemoteRepository remoteRepository = getRemoteRepository( repositoryId, url );
- if ( StringUtils.isEmpty( protocol ) )
+ if ( StringUtils.isEmpty( remoteRepository.getProtocol() ) )
{
throw new MojoExecutionException( "No transfer protocol found." );
}
- MavenProject project = createMavenProject();
- Artifact artifact = project.getArtifact();
+ if ( groupId == null || artifactId == null || version == null || packaging == null )
+ {
+ throw new MojoExecutionException( "The artifact information is incomplete: 'groupId', 'artifactId', "
+ + "'version' and 'packaging' are required." );
+ }
- if ( file.equals( getLocalRepoFile() ) )
+ if ( !isValidId( groupId )
+ || !isValidId( artifactId )
+ || !isValidVersion( version ) )
{
- throw new MojoFailureException( "Cannot deploy artifact from the local repository: " + file );
+ throw new MojoExecutionException( "The artifact information is not valid: uses invalid characters." );
}
- List deployableArtifacts = new ArrayList();
+ failIfOffline();
+ warnIfAffectedPackagingAndMaven( packaging );
- if ( classifier == null )
+ DeployRequest deployRequest = new DeployRequest();
+ deployRequest.setRepository( remoteRepository );
+
+ boolean isFilePom = classifier == null && "pom".equals( packaging );
+ if ( !isFilePom )
{
- artifact.setFile( file );
- deployableArtifacts.add( artifact );
+ ArtifactType artifactType = session.getRepositorySession().getArtifactTypeRegistry().get( packaging );
+ if ( artifactType != null
+ && StringUtils.isEmpty( classifier )
+ && !StringUtils.isEmpty( artifactType.getClassifier() ) )
+ {
+ classifier = artifactType.getClassifier();
+ }
}
- else
+ Artifact mainArtifact = new DefaultArtifact(
+ groupId,
+ artifactId,
+ classifier,
+ isFilePom ? "pom" : getExtension( file ),
+ version
+ ).setFile( file );
+ deployRequest.addArtifact( mainArtifact );
+
+ File artifactLocalFile = getLocalRepositoryFile( session.getRepositorySession(), mainArtifact );
+
+ if ( file.equals( artifactLocalFile ) )
{
- projectHelper.attachArtifact( project, packaging, classifier, file );
+ throw new MojoFailureException( "Cannot deploy artifact from the local repository: " + file );
}
- // Upload the POM if requested, generating one if need be
+ File temporaryPom = null;
if ( !"pom".equals( packaging ) )
{
- File pom = pomFile;
- if ( pom == null && generatePom )
+ if ( pomFile != null )
{
- pom = generatePomFile();
+ deployRequest.addArtifact( new SubArtifact( mainArtifact, "", "pom", pomFile ) );
}
- if ( pom != null )
+ else if ( generatePom )
{
- if ( classifier == null )
- {
- ProjectArtifactMetadata metadata = new ProjectArtifactMetadata( artifact, pom );
- artifact.addMetadata( metadata );
- }
- else
- {
- artifact.setFile( pom );
- deployableArtifacts.add( artifact );
- }
+ temporaryPom = generatePomFile();
+ getLog().debug( "Deploying generated POM" );
+ deployRequest.addArtifact( new SubArtifact( mainArtifact, "", "pom", temporaryPom ) );
+ }
+ else
+ {
+ getLog().debug( "Skipping deploying POM" );
}
}
- artifact.setRepository( deploymentRepository );
-
if ( sources != null )
{
- projectHelper.attachArtifact( project, "jar", "sources", sources );
+ deployRequest.addArtifact( new SubArtifact( mainArtifact, "sources", "jar", sources ) );
}
if ( javadoc != null )
{
- projectHelper.attachArtifact( project, "jar", "javadoc", javadoc );
+ deployRequest.addArtifact( new SubArtifact( mainArtifact, "javadoc", "jar", javadoc ) );
}
if ( files != null )
@@ -406,12 +377,12 @@ public void execute()
if ( typesLength != filesLength )
{
throw new MojoExecutionException( "You must specify the same number of entries in 'files' and "
- + "'types' (respectively " + filesLength + " and " + typesLength + " entries )" );
+ + "'types' (respectively " + filesLength + " and " + typesLength + " entries )" );
}
if ( classifiersLength != filesLength )
{
throw new MojoExecutionException( "You must specify the same number of entries in 'files' and "
- + "'classifiers' (respectively " + filesLength + " and " + classifiersLength + " entries )" );
+ + "'classifiers' (respectively " + filesLength + " and " + classifiersLength + " entries )" );
}
int fi = 0;
int ti = 0;
@@ -437,19 +408,21 @@ 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( files.substring( fi, nfi ) );
}
if ( file.isFile() )
{
- if ( StringUtils.isWhitespace( classifiers.substring( ci, nci ) ) )
+ String extension = getExtension( file );
+ ArtifactType artifactType = session.getRepositorySession().getArtifactTypeRegistry()
+ .get( types.substring( ti, nti ).trim() );
+ if ( artifactType != null && !Objects.equals( extension, artifactType.getExtension() ) )
{
- projectHelper.attachArtifact( project, types.substring( ti, nti ).trim(), file );
- }
- else
- {
- projectHelper.attachArtifact( project, types.substring( ti, nti ).trim(),
- classifiers.substring( ci, nci ).trim(), file );
+ extension = artifactType.getExtension();
}
+
+ deployRequest.addArtifact(
+ new SubArtifact( mainArtifact, classifiers.substring( ci, nci ).trim(), extension, file )
+ );
}
else
{
@@ -472,80 +445,32 @@ public void execute()
}
}
- List attachedArtifacts = project.getAttachedArtifacts();
-
- for ( Artifact attached : attachedArtifacts )
- {
- deployableArtifacts.add( attached );
- }
-
try
{
- warnIfAffectedPackagingAndMaven( packaging );
- artifactDeployer.deploy( getSession().getProjectBuildingRequest(), deploymentRepository,
- deployableArtifacts );
+ repositorySystem.deploy( session.getRepositorySession(), deployRequest );
}
- catch ( ArtifactDeployerException e )
+ catch ( DeploymentException e )
{
throw new MojoExecutionException( e.getMessage(), e );
}
- }
-
- /**
- * Creates a Maven project in-memory from the user-supplied groupId, artifactId and version. When a classifier is
- * supplied, the packaging must be POM because the project with only have attachments. This project serves as basis
- * 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.
- */
- private MavenProject createMavenProject()
- throws MojoExecutionException, MojoFailureException
- {
- if ( groupId == null || artifactId == null || version == null || packaging == null )
- {
- throw new MojoExecutionException( "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 )
+ finally
{
- if ( e.getCause() instanceof ModelBuildingException )
+ if ( temporaryPom != null )
{
- throw new MojoExecutionException( "The artifact information is not valid:" + Os.LINE_SEP
- + e.getCause().getMessage() );
+ // noinspection ResultOfMethodCallIgnored
+ temporaryPom.delete();
}
- throw new MojoFailureException( "Unable to create the project.", e );
}
}
/**
- * Gets the path of the artifact constructed from the supplied groupId, artifactId, version, classifier and
- * packaging within the local repository. Note that the returned path need not exist (yet).
- *
- * @return The absolute path to the artifact when installed, never null
.
+ * Gets the path of the specified artifact within the local repository. Note that the returned path need not exist
+ * (yet).
*/
- private File getLocalRepoFile()
+ private File getLocalRepositoryFile( RepositorySystemSession session, Artifact artifact )
{
- DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
- coordinate.setGroupId( groupId );
- coordinate.setArtifactId( artifactId );
- coordinate.setVersion( version );
- coordinate.setClassifier( classifier );
- coordinate.setExtension( packaging );
- String path = repoManager.getPathForLocalArtifact( getSession().getProjectBuildingRequest(), coordinate );
- return new File( repoManager.getLocalRepositoryBasedir( getSession().getProjectBuildingRequest() ), path );
+ String path = session.getLocalRepositoryManager().getPathForLocalArtifact( artifact );
+ return new File( session.getLocalRepository().getBasedir(), path );
}
/**
@@ -737,4 +662,63 @@ void setClassifier( String classifier )
this.classifier = classifier;
}
+ // these below should be shared (duplicated in m-install-p, m-deploy-p)
+
+ /**
+ * Specialization of {@link FileUtils#getExtension(String)} that honors various {@code tar.xxx} combinations.
+ */
+ private String getExtension( final File file )
+ {
+ String filename = file.getName();
+ if ( filename.contains( ".tar." ) )
+ {
+ return "tar." + FileUtils.getExtension( filename );
+ }
+ else
+ {
+ return FileUtils.getExtension( filename );
+ }
+ }
+
+ /**
+ * Returns {@code true} if passed in string is "valid Maven ID" (groupId or artifactId).
+ */
+ private boolean isValidId( String id )
+ {
+ if ( id == null )
+ {
+ return false;
+ }
+ for ( int i = 0; i < id.length(); i++ )
+ {
+ char c = id.charAt( i );
+ if ( !( c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z'
+ || c >= '0' && c <= '9' || c == '-' || c == '_' || c == '.' ) )
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private static final String ILLEGAL_VERSION_CHARS = "\\/:\"<>|?*[](){},";
+
+ /**
+ * Returns {@code true} if passed in string is "valid Maven (simple. non range, expression, etc) version".
+ */
+ private boolean isValidVersion( String version )
+ {
+ if ( version == null )
+ {
+ return false;
+ }
+ for ( int i = version.length() - 1; i >= 0; i-- )
+ {
+ if ( ILLEGAL_VERSION_CHARS.indexOf( version.charAt( i ) ) >= 0 )
+ {
+ return false;
+ }
+ }
+ return true;
+ }
}
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 bec6b384..d169ab8a 100644
--- a/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
+++ b/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
@@ -19,26 +19,26 @@
* under the License.
*/
+import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.ArtifactUtils;
-import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
-import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.ProjectBuildingRequest;
-import org.apache.maven.shared.transfer.artifact.deploy.ArtifactDeployerException;
-import org.apache.maven.shared.transfer.project.NoFileAssignedException;
-import org.apache.maven.shared.transfer.project.deploy.ProjectDeployer;
-import org.apache.maven.shared.transfer.project.deploy.ProjectDeployerRequest;
+import org.apache.maven.project.artifact.ProjectArtifact;
+import org.apache.maven.project.artifact.ProjectArtifactMetadata;
+import org.eclipse.aether.deployment.DeployRequest;
+import org.eclipse.aether.repository.RemoteRepository;
+import org.eclipse.aether.util.artifact.SubArtifact;
/**
* Deploys an artifact to remote repository.
@@ -128,12 +128,6 @@ public class DeployMojo
@Parameter( property = "maven.deploy.skip", defaultValue = "false" )
private String skip = Boolean.FALSE.toString();
- /**
- * Component used to deploy project.
- */
- @Component
- private ProjectDeployer projectDeployer;
-
private enum State
{
SKIPPED, DEPLOYED, TO_BE_DEPLOYED
@@ -175,7 +169,7 @@ private State getState( Map pluginContext )
private boolean hasState( MavenProject project )
{
- Map pluginContext = getSession().getPluginContext( pluginDescriptor, project );
+ Map pluginContext = session.getPluginContext( pluginDescriptor, project );
return pluginContext.containsKey( DEPLOY_PROCESSED_MARKER );
}
@@ -193,32 +187,23 @@ public void execute()
else
{
failIfOffline();
+ warnIfAffectedPackagingAndMaven( project.getPackaging() );
if ( !deployAtEnd )
{
- // CHECKSTYLE_OFF: LineLength
- // @formatter:off
- ProjectDeployerRequest pdr = new ProjectDeployerRequest()
- .setProject( project )
- .setRetryFailedDeploymentCount( getRetryFailedDeploymentCount() )
- .setAltReleaseDeploymentRepository( altReleaseDeploymentRepository )
- .setAltSnapshotDeploymentRepository( altSnapshotDeploymentRepository )
- .setAltDeploymentRepository( altDeploymentRepository );
- // @formatter:on
- // CHECKSTYLE_ON: LineLength
-
- ArtifactRepository repo = getDeploymentRepository( pdr );
-
- deployProject( getSession().getProjectBuildingRequest(), pdr, repo );
+ deploy( session.getRepositorySession(),
+ processProject( project,
+ altSnapshotDeploymentRepository, altReleaseDeploymentRepository, altDeploymentRepository ) );
putState( State.DEPLOYED );
}
else
{
- putState( State.TO_BE_DEPLOYED );
putPluginContextValue( DEPLOY_ALT_RELEASE_DEPLOYMENT_REPOSITORY, altReleaseDeploymentRepository );
putPluginContextValue( DEPLOY_ALT_SNAPSHOT_DEPLOYMENT_REPOSITORY, altSnapshotDeploymentRepository );
putPluginContextValue( DEPLOY_ALT_DEPLOYMENT_REPOSITORY, altDeploymentRepository );
- getLog().info( "Deferring deploy for " + getProjectReferenceId( project ) + " at end" );
+ putState( State.TO_BE_DEPLOYED );
+ getLog().info( "Deferring deploy for " + project.getGroupId()
+ + ":" + project.getArtifactId() + ":" + project.getVersion() + " at end" );
}
}
@@ -226,7 +211,7 @@ public void execute()
{
for ( MavenProject reactorProject : reactorProjects )
{
- Map pluginContext = getSession().getPluginContext( pluginDescriptor, reactorProject );
+ Map pluginContext = session.getPluginContext( pluginDescriptor, reactorProject );
State state = getState( pluginContext );
if ( state == State.TO_BE_DEPLOYED )
{
@@ -237,26 +222,15 @@ public void execute()
String altDeploymentRepository =
getPluginContextValue( pluginContext, DEPLOY_ALT_DEPLOYMENT_REPOSITORY );
- ProjectDeployerRequest pdr = new ProjectDeployerRequest()
- .setProject( reactorProject )
- .setRetryFailedDeploymentCount( getRetryFailedDeploymentCount() )
- .setAltReleaseDeploymentRepository( altReleaseDeploymentRepository )
- .setAltSnapshotDeploymentRepository( altSnapshotDeploymentRepository )
- .setAltDeploymentRepository( altDeploymentRepository );
-
- ArtifactRepository repo = getDeploymentRepository( pdr );
-
- deployProject( getSession().getProjectBuildingRequest(), pdr, repo );
+ deploy( session.getRepositorySession(),
+ processProject( reactorProject,
+ altSnapshotDeploymentRepository, altReleaseDeploymentRepository, altDeploymentRepository )
+ );
}
}
}
}
- private String getProjectReferenceId( MavenProject mavenProject )
- {
- return mavenProject.getGroupId() + ":" + mavenProject.getArtifactId() + ":" + mavenProject.getVersion();
- }
-
private boolean allProjectsMarked()
{
for ( MavenProject reactorProject : reactorProjects )
@@ -269,35 +243,89 @@ private boolean allProjectsMarked()
return true;
}
- private void deployProject( ProjectBuildingRequest pbr, ProjectDeployerRequest pir, ArtifactRepository repo )
- throws MojoFailureException, MojoExecutionException
+ private DeployRequest processProject( final MavenProject project,
+ final String altSnapshotDeploymentRepository,
+ final String altReleaseDeploymentRepository,
+ final String altDeploymentRepository )
+ throws MojoExecutionException, MojoFailureException
{
- try
+ DeployRequest request = new DeployRequest();
+ request.setRepository( getDeploymentRepository( project,
+ altSnapshotDeploymentRepository, altReleaseDeploymentRepository, altDeploymentRepository ) );
+
+ org.apache.maven.artifact.Artifact mavenMainArtifact = project.getArtifact();
+ String packaging = project.getPackaging();
+ File pomFile = project.getFile();
+ boolean isPomArtifact = "pom".equals( packaging );
+ boolean pomArtifactAttached = false;
+
+ if ( pomFile != null )
{
- warnIfAffectedPackagingAndMaven( pir.getProject().getPackaging() );
- projectDeployer.deploy( pbr, pir, repo );
+ request.addArtifact( RepositoryUtils.toArtifact( new ProjectArtifact( project ) ) );
+ pomArtifactAttached = true;
}
- catch ( NoFileAssignedException e )
+
+ if ( !isPomArtifact )
{
- throw new MojoExecutionException( "NoFileAssignedException", e );
+ File file = mavenMainArtifact.getFile();
+ if ( file != null && file.isFile() )
+ {
+ org.eclipse.aether.artifact.Artifact mainArtifact = RepositoryUtils.toArtifact( mavenMainArtifact );
+ request.addArtifact( mainArtifact );
+
+ if ( !pomArtifactAttached )
+ {
+ for ( Object metadata : mavenMainArtifact.getMetadataList() )
+ {
+ if ( metadata instanceof ProjectArtifactMetadata )
+ {
+ request.addArtifact( new SubArtifact(
+ mainArtifact,
+ "",
+ "pom"
+ ).setFile( ( (ProjectArtifactMetadata) metadata ).getFile() ) );
+ pomArtifactAttached = true;
+ }
+ }
+ }
+ }
+ else if ( !project.getAttachedArtifacts().isEmpty() )
+ {
+ throw new MojoExecutionException( "The packaging plugin for this project did not assign "
+ + "a main file to the project but it has attachments. Change packaging to 'pom'." );
+ }
+ else
+ {
+ throw new MojoExecutionException( "The packaging for this project did not assign "
+ + "a file to the build artifact" );
+ }
}
- catch ( ArtifactDeployerException e )
+
+ if ( !pomArtifactAttached )
+ {
+ throw new MojoExecutionException( "The POM could not be attached" );
+ }
+
+ for ( org.apache.maven.artifact.Artifact attached : project.getAttachedArtifacts() )
{
- throw new MojoExecutionException( "ArtifactDeployerException", e );
+ getLog().debug( "Attaching for install: " + attached.getId() );
+ request.addArtifact( RepositoryUtils.toArtifact( attached ) );
}
+ return request;
}
- ArtifactRepository getDeploymentRepository( ProjectDeployerRequest pdr )
+ /**
+ * Visible for testing.
+ */
+ RemoteRepository getDeploymentRepository( final MavenProject project,
+ final String altSnapshotDeploymentRepository,
+ final String altReleaseDeploymentRepository,
+ final String altDeploymentRepository )
throws MojoExecutionException, MojoFailureException
{
- MavenProject project = pdr.getProject();
- String altDeploymentRepository = pdr.getAltDeploymentRepository();
- String altReleaseDeploymentRepository = pdr.getAltReleaseDeploymentRepository();
- String altSnapshotDeploymentRepository = pdr.getAltSnapshotDeploymentRepository();
-
- ArtifactRepository repo = null;
+ RemoteRepository repo = null;
String altDeploymentRepo;
if ( ArtifactUtils.isSnapshot( project.getVersion() ) && altSnapshotDeploymentRepository != null )
@@ -329,7 +357,7 @@ else if ( !ArtifactUtils.isSnapshot( project.getVersion() ) && altReleaseDeploym
{
getLog().warn( "Using legacy syntax for alternative repository. "
+ "Use \"" + id + "::" + url + "\" instead." );
- repo = createDeploymentArtifactRepository( id, url );
+ repo = getRemoteRepository( id, url );
}
else
{
@@ -356,14 +384,14 @@ else if ( !ArtifactUtils.isSnapshot( project.getVersion() ) && altReleaseDeploym
String id = matcher.group( 1 ).trim();
String url = matcher.group( 2 ).trim();
- repo = createDeploymentArtifactRepository( id, url );
+ repo = getRemoteRepository( id, url );
}
}
}
if ( repo == null )
{
- repo = project.getDistributionManagementArtifactRepository();
+ repo = RepositoryUtils.toRepo( project.getDistributionManagementArtifactRepository() );
}
if ( repo == null )
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 371838bd..d8538705 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java
@@ -97,7 +97,8 @@ public void testBasicDeployFile()
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance( repositorySession, new LocalRepository( LOCAL_REPO ) ) );
when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
-
+ when( session.getRepositorySession() ).thenReturn( repositorySession );
+
String groupId = (String) getVariableValueFromObject( mojo, "groupId" );
String artifactId = (String) getVariableValueFromObject( mojo, "artifactId" );
@@ -199,6 +200,7 @@ public void testDeployIfClassifierIsSet()
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance( repositorySession, new LocalRepository( LOCAL_REPO ) ) );
when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
+ when( session.getRepositorySession() ).thenReturn( repositorySession );
String classifier = ( String ) getVariableValueFromObject( mojo, "classifier" );
@@ -248,6 +250,7 @@ public void testDeployIfArtifactIsNotJar()
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance( repositorySession, new LocalRepository( LOCAL_REPO ) ) );
when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
+ when( session.getRepositorySession() ).thenReturn( repositorySession );
String groupId = (String) getVariableValueFromObject( mojo, "groupId" );
diff --git a/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoUnitTest.java b/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoUnitTest.java
index 6131f79d..a7bbd8b7 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoUnitTest.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoUnitTest.java
@@ -19,36 +19,27 @@
* under the License.
*/
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
import org.apache.maven.plugin.MojoExecutionException;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
import java.io.File;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
/**
* @author Jerome Lacoste
*/
public class DeployFileMojoUnitTest
- extends TestCase
{
- public static void main( String[] args )
- {
- junit.textui.TestRunner.run( suite() );
- }
-
- public static Test suite()
- {
- TestSuite suite = new TestSuite( DeployFileMojoUnitTest.class );
-
- return suite;
- }
-
MockDeployFileMojo mojo;
Parent parent;
+ @Before
public void setUp()
{
Model pomModel = new Model();
@@ -62,12 +53,13 @@ public void setUp()
mojo = new MockDeployFileMojo( pomModel );
}
+ @After
public void tearDown()
{
mojo = null;
}
- class MockDeployFileMojo extends DeployFileMojo {
+ static class MockDeployFileMojo extends DeployFileMojo {
private Model model;
public MockDeployFileMojo(Model model) {
@@ -83,6 +75,7 @@ protected Model readModel(File pomFile) throws MojoExecutionException {
}
}
+ @Test
public void testProcessPomFromPomFileWithParent1() throws MojoExecutionException
{
mojo.setPomFile( new File( "foo.bar" ) );
@@ -98,6 +91,7 @@ public void testProcessPomFromPomFileWithParent1() throws MojoExecutionException
checkMojoProperties("parentGroup", null, "parentVersion", null);
}
+ @Test
public void testProcessPomFromPomFileWithParent2() throws MojoExecutionException
{
mojo.setPomFile( new File( "foo.bar" ) );
@@ -113,6 +107,7 @@ public void testProcessPomFromPomFileWithParent2() throws MojoExecutionException
}
+ @Test
public void testProcessPomFromPomFileWithParent3() throws MojoExecutionException
{
mojo.setPomFile( new File( "foo.bar" ) );
@@ -127,6 +122,7 @@ public void testProcessPomFromPomFileWithParent3() throws MojoExecutionException
checkMojoProperties( "parentGroup", "artifact", "version", null );
}
+ @Test
public void testProcessPomFromPomFileWithParent4() throws MojoExecutionException
{
mojo.setPomFile( new File( "foo.bar" ) );
@@ -137,6 +133,7 @@ public void testProcessPomFromPomFileWithParent4() throws MojoExecutionException
checkMojoProperties("parentGroup", "artifact", "version", "packaging");
}
+ @Test
public void testProcessPomFromPomFileWithParent5() throws MojoExecutionException
{
mojo.setPomFile( new File( "foo.bar" ) );
@@ -147,6 +144,7 @@ public void testProcessPomFromPomFileWithParent5() throws MojoExecutionException
checkMojoProperties("group", "artifact", "version", "packaging");
}
+ @Test
public void testProcessPomFromPomFileWithParent6() throws MojoExecutionException
{
mojo.setPomFile( new File( "foo.bar" ) );
@@ -158,6 +156,7 @@ public void testProcessPomFromPomFileWithParent6() throws MojoExecutionException
}
+ @Test
public void testProcessPomFromPomFileWithOverrides() throws MojoExecutionException
{
mojo.setPomFile( new File( "foo.bar" ) );
diff --git a/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java b/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
index c8350c47..f34abd06 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
@@ -20,6 +20,7 @@
*/
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@@ -31,25 +32,23 @@
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
-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.descriptor.PluginDescriptor;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
-import org.apache.maven.plugins.deploy.stubs.ArtifactDeployerStub;
import org.apache.maven.plugins.deploy.stubs.ArtifactRepositoryStub;
import org.apache.maven.plugins.deploy.stubs.DeployArtifactStub;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingRequest;
-import org.apache.maven.shared.transfer.project.deploy.ProjectDeployerRequest;
import org.codehaus.plexus.util.FileUtils;
import org.eclipse.aether.DefaultRepositorySystemSession;
+import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.repository.LocalRepository;
+import org.eclipse.aether.repository.RemoteRepository;
import org.junit.Ignore;
import org.mockito.InjectMocks;
-import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
@@ -84,6 +83,9 @@ public void setUp()
session = mock( MavenSession.class );
when( session.getPluginContext(any(PluginDescriptor.class), any(MavenProject.class)))
.thenReturn( new ConcurrentHashMap() );
+ DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
+ repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance( repositorySession, new LocalRepository( LOCAL_REPO ) ) );
+ when( session.getRepositorySession() ).thenReturn( repositorySession );
remoteRepo = new File( REMOTE_REPO );
@@ -100,8 +102,6 @@ public void setUp()
{
FileUtils.deleteDirectory( remoteRepo );
}
-
-
}
public void tearDown()
@@ -136,13 +136,14 @@ public void testBasicDeploy()
MockitoAnnotations.initMocks( this );
assertNotNull( mojo );
-
+
ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance( repositorySession, new LocalRepository( LOCAL_REPO ) ) );
when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
-
+ when( session.getRepositorySession() ).thenReturn( repositorySession );
+
File file = new File( getBasedir(),
"target/test-classes/unit/basic-deploy-test/target/" +
"deploy-test-file-1.0-SNAPSHOT.jar" );
@@ -150,6 +151,9 @@ public void testBasicDeploy()
assertTrue( file.exists() );
MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );
+ project.setGroupId( "org.apache.maven.test" );
+ project.setArtifactId( "maven-deploy-test" );
+ project.setVersion( "1.0-SNAPSHOT" );
setVariableValueToObject( mojo, "pluginContext", new ConcurrentHashMap<>() );
setVariableValueToObject( mojo, "reactorProjects", Collections.singletonList( project ) );
@@ -317,6 +321,7 @@ public void testBasicDeployWithPackagingAsPom()
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance( repositorySession, new LocalRepository( LOCAL_REPO ) ) );
when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
+ when( session.getRepositorySession() ).thenReturn( repositorySession );
File pomFile = new File( getBasedir(),
"target/test-classes/unit/basic-deploy-pom/target/" +
@@ -325,6 +330,9 @@ public void testBasicDeployWithPackagingAsPom()
assertTrue( pomFile.exists() );
MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );
+ project.setGroupId( "org.apache.maven.test" );
+ project.setArtifactId( "maven-deploy-test" );
+ project.setVersion( "1.0-SNAPSHOT" );
setVariableValueToObject( mojo, "pluginContext", new ConcurrentHashMap<>() );
setVariableValueToObject( mojo, "reactorProjects", Collections.singletonList( project ) );
@@ -391,6 +399,9 @@ public void testDeployIfArtifactFileIsNull()
assertNotNull( mojo );
MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );
+ project.setGroupId( "org.apache.maven.test" );
+ project.setArtifactId( "maven-deploy-test" );
+ project.setVersion( "1.0-SNAPSHOT" );
setVariableValueToObject( mojo, "pluginContext", new ConcurrentHashMap<>() );
setVariableValueToObject( mojo, "reactorProjects", Collections.singletonList( project ) );
@@ -431,8 +442,12 @@ public void testDeployWithAttachedArtifacts()
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance( repositorySession, new LocalRepository( LOCAL_REPO ) ) );
when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
+ when( session.getRepositorySession() ).thenReturn( repositorySession );
MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );
+ project.setGroupId( "org.apache.maven.test" );
+ project.setArtifactId( "maven-deploy-test" );
+ project.setVersion( "1.0-SNAPSHOT" );
setVariableValueToObject( mojo, "pluginContext", new ConcurrentHashMap<>() );
setVariableValueToObject( mojo, "reactorProjects", Collections.singletonList( project ) );
@@ -524,9 +539,9 @@ public void _testBasicDeployWithScpAsProtocol()
assertNotNull( mojo );
- ArtifactDeployerStub deployer = new ArtifactDeployerStub();
+ RepositorySystem repositorySystem = mock( RepositorySystem.class );
- setVariableValueToObject( mojo, "deployer", deployer );
+ setVariableValueToObject( mojo, "repositorySystem", repositorySystem );
File file = new File( getBasedir(),
"target/test-classes/unit/basic-deploy-scp/target/" +
@@ -571,42 +586,32 @@ public void _testBasicDeployWithScpAsProtocol()
public void testLegacyAltDeploymentRepositoryWithDefaultLayout()
throws Exception
{
- DeployMojo mojo = spy( new DeployMojo() );
+ DeployMojo mojo = new DeployMojo();
- ArtifactRepository repository = mock( ArtifactRepository.class );
- when( mojo.createDeploymentArtifactRepository( "altDeploymentRepository", "http://localhost"
- ) ).thenReturn( repository );
+ setVariableValueToObject( mojo, "project", project );
+ setVariableValueToObject( mojo, "session", session );
+ setVariableValueToObject( mojo, "altDeploymentRepository", "altDeploymentRepository::default::http://localhost" );
project.setVersion( "1.0-SNAPSHOT" );
- ProjectDeployerRequest pdr =
- new ProjectDeployerRequest()
- .setProject( project )
- .setAltDeploymentRepository( "altDeploymentRepository::default::http://localhost" );
-
- assertEquals( repository,
- mojo.getDeploymentRepository( pdr ) );
+ assertEquals( new RemoteRepository.Builder( "altDeploymentRepository", "default", "http://localhost" ).build(),
+ mojo.getDeploymentRepository( project, null, null, "altDeploymentRepository::default::http://localhost") );
}
public void testLegacyAltDeploymentRepositoryWithLegacyLayout()
throws Exception
{
- DeployMojo mojo = spy( new DeployMojo() );
+ DeployMojo mojo = new DeployMojo();
- ArtifactRepository repository = mock( ArtifactRepository.class );
- when( mojo.createDeploymentArtifactRepository( "altDeploymentRepository", "http://localhost"
- ) ).thenReturn( repository );
+ setVariableValueToObject( mojo, "project", project );
+ setVariableValueToObject( mojo, "session", session );
+ setVariableValueToObject( mojo, "altDeploymentRepository", "altDeploymentRepository::legacy::http://localhost" );
project.setVersion( "1.0-SNAPSHOT" );
-
- ProjectDeployerRequest pdr =
- new ProjectDeployerRequest()
- .setProject( project )
- .setAltDeploymentRepository( "altDeploymentRepository::legacy::http://localhost" );
try
{
- mojo.getDeploymentRepository( pdr );
+ mojo.getDeploymentRepository( project, null, null, "altDeploymentRepository::legacy::http://localhost" );
fail( "Should throw: Invalid legacy syntax and layout for repository." );
}
catch( MojoFailureException e )
@@ -619,21 +624,16 @@ public void testLegacyAltDeploymentRepositoryWithLegacyLayout()
public void testInsaneAltDeploymentRepository()
throws Exception
{
- DeployMojo mojo = spy( new DeployMojo() );
+ DeployMojo mojo = new DeployMojo();
- ArtifactRepository repository = mock( ArtifactRepository.class );
- when( mojo.createDeploymentArtifactRepository( "altDeploymentRepository", "http://localhost"
- ) ).thenReturn( repository );
+ setVariableValueToObject( mojo, "project", project );
+ setVariableValueToObject( mojo, "session", session );
+ setVariableValueToObject( mojo, "altDeploymentRepository", "altDeploymentRepository::hey::wow::foo::http://localhost" );
project.setVersion( "1.0-SNAPSHOT" );
-
- ProjectDeployerRequest pdr =
- new ProjectDeployerRequest()
- .setProject( project )
- .setAltDeploymentRepository( "altDeploymentRepository::hey::wow::foo::http://localhost" );
try
{
- mojo.getDeploymentRepository( pdr );
+ mojo.getDeploymentRepository( project, null, null, "altDeploymentRepository::hey::wow::foo::http://localhost" );
fail( "Should throw: Invalid legacy syntax and layout for repository." );
}
catch( MojoFailureException e )
@@ -646,40 +646,29 @@ public void testInsaneAltDeploymentRepository()
public void testDefaultScmSvnAltDeploymentRepository()
throws Exception
{
- DeployMojo mojo = spy( new DeployMojo() );
+ DeployMojo mojo = new DeployMojo();
- ArtifactRepository repository = mock( ArtifactRepository.class );
- when( mojo.createDeploymentArtifactRepository( "altDeploymentRepository", "scm:svn:http://localhost"
- ) ).thenReturn( repository );
+ setVariableValueToObject( mojo, "project", project );
+ setVariableValueToObject( mojo, "session", session );
+ setVariableValueToObject( mojo, "altDeploymentRepository", "altDeploymentRepository::default::scm:svn:http://localhost" );
project.setVersion( "1.0-SNAPSHOT" );
- ProjectDeployerRequest pdr =
- new ProjectDeployerRequest()
- .setProject( project )
- .setAltDeploymentRepository( "altDeploymentRepository::default::scm:svn:http://localhost" );
-
- assertEquals( repository,
- mojo.getDeploymentRepository( pdr ) );
+ assertEquals( new RemoteRepository.Builder( "altDeploymentRepository", "default", "scm:svn:http://localhost" ).build(),
+ mojo.getDeploymentRepository( project, null, null, "altDeploymentRepository::default::scm:svn:http://localhost" ) );
}
public void testLegacyScmSvnAltDeploymentRepository()
throws Exception
{
- DeployMojo mojo = spy( new DeployMojo() );
+ DeployMojo mojo = new DeployMojo();
- ArtifactRepository repository = mock( ArtifactRepository.class );
- when( mojo.createDeploymentArtifactRepository( "altDeploymentRepository", "http://localhost"
- ) ).thenReturn( repository );
+ setVariableValueToObject( mojo, "project", project );
+ setVariableValueToObject( mojo, "altDeploymentRepository", "altDeploymentRepository::legacy::scm:svn:http://localhost" );
project.setVersion( "1.0-SNAPSHOT" );
-
- ProjectDeployerRequest pdr =
- new ProjectDeployerRequest()
- .setProject( project )
- .setAltDeploymentRepository( "altDeploymentRepository::legacy::scm:svn:http://localhost" );
try
{
- mojo.getDeploymentRepository( pdr );
+ mojo.getDeploymentRepository( project, null, null, "altDeploymentRepository::legacy::scm:svn:http://localhost" );
fail( "Should throw: Invalid legacy syntax and layout for repository." );
}
catch( MojoFailureException e )
@@ -692,39 +681,31 @@ public void testLegacyScmSvnAltDeploymentRepository()
public void testAltSnapshotDeploymentRepository()
throws Exception
{
- DeployMojo mojo = spy( new DeployMojo() );
+ DeployMojo mojo = new DeployMojo();
- ArtifactRepository repository = mock( ArtifactRepository.class );
- when( mojo.createDeploymentArtifactRepository( "altSnapshotDeploymentRepository", "http://localhost"
- ) ).thenReturn( repository );
+ setVariableValueToObject( mojo, "project", project );
+ setVariableValueToObject( mojo, "session", session );
+ setVariableValueToObject( mojo, "altSnapshotDeploymentRepository", "altSnapshotDeploymentRepository::http://localhost" );
project.setVersion( "1.0-SNAPSHOT" );
- ProjectDeployerRequest pdr =
- new ProjectDeployerRequest()
- .setProject( project )
- .setAltDeploymentRepository( "altSnapshotDeploymentRepository::http://localhost" );
- assertEquals( repository,
- mojo.getDeploymentRepository( pdr ));
+ assertEquals( new RemoteRepository.Builder( "altSnapshotDeploymentRepository", "default", "http://localhost" ).build(),
+ mojo.getDeploymentRepository( project, "altSnapshotDeploymentRepository::http://localhost", null, null ));
}
public void testAltReleaseDeploymentRepository()
throws Exception
{
- DeployMojo mojo = spy( new DeployMojo() );
+ DeployMojo mojo = new DeployMojo();
- ArtifactRepository repository = mock( ArtifactRepository.class );
- when( mojo.createDeploymentArtifactRepository( "altReleaseDeploymentRepository", "http://localhost" ) ).thenReturn( repository );
+ setVariableValueToObject( mojo, "project", project );
+ setVariableValueToObject( mojo, "session", session );
+ setVariableValueToObject( mojo, "altReleaseDeploymentRepository", "altReleaseDeploymentRepository::http://localhost" );
project.setVersion( "1.0" );
- ProjectDeployerRequest pdr =
- new ProjectDeployerRequest()
- .setProject( project )
- .setAltReleaseDeploymentRepository( "altReleaseDeploymentRepository::http://localhost" );
-
- assertEquals( repository,
- mojo.getDeploymentRepository( pdr ));
+ assertEquals( new RemoteRepository.Builder("altReleaseDeploymentRepository", "default", "http://localhost").build(),
+ mojo.getDeploymentRepository( project, null, "altReleaseDeploymentRepository::http://localhost", null ));
}
private void addFileToList( File file, List fileList )
diff --git a/src/test/java/org/apache/maven/plugins/deploy/stubs/ArtifactDeployerStub.java b/src/test/java/org/apache/maven/plugins/deploy/stubs/ArtifactDeployerStub.java
deleted file mode 100644
index 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
- }
-}