diff --git a/maven-deploy-plugin/src/it/deploy-at-end-extension/module1/pom.xml b/maven-deploy-plugin/src/it/deploy-at-end-extension/module1/pom.xml
new file mode 100644
index 0000000000..3c1ac98e23
--- /dev/null
+++ b/maven-deploy-plugin/src/it/deploy-at-end-extension/module1/pom.xml
@@ -0,0 +1,55 @@
+
+
+
+
+
+ 4.0.0
+
+
+ org.apache.maven.its.deploy.dae.extension
+ dae
+ 1.0
+
+ module1
+
+
+
+
+ org.apache.maven.wagon
+ wagon-ftp
+ 2.10
+
+
+
+
+ org.apache.maven.plugins
+ maven-enforcer-plugin
+ 1.2
+
+
+ enforce
+
+ enforce
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/maven-deploy-plugin/src/it/deploy-at-end-extension/pom.xml b/maven-deploy-plugin/src/it/deploy-at-end-extension/pom.xml
new file mode 100644
index 0000000000..fb861b5864
--- /dev/null
+++ b/maven-deploy-plugin/src/it/deploy-at-end-extension/pom.xml
@@ -0,0 +1,100 @@
+
+
+
+
+
+ 4.0.0
+
+ org.apache.maven.its.deploy.dae.extension
+ dae
+ 1.0
+ pom
+
+
+ Tests deployment at end when modules have different extensions.
+
+
+
+ true
+
+
+
+
+ it
+ file:///${basedir}/target/repo
+ false
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 2.0.2
+
+
+ org.apache.maven.plugins
+ maven-deploy-plugin
+ @project.version@
+
+ true
+
+
+
+ org.apache.maven.plugins
+ maven-install-plugin
+ 2.2
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 2.1
+
+
+ org.apache.maven.plugins
+ maven-resources-plugin
+ 2.2
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+ 2.0.4
+
+
+ attach-sources
+
+ jar
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.3.1
+
+
+
+
+
+ module1
+
+
diff --git a/maven-deploy-plugin/src/it/deploy-at-end-extension/verify.groovy b/maven-deploy-plugin/src/it/deploy-at-end-extension/verify.groovy
new file mode 100644
index 0000000000..3e3220f118
--- /dev/null
+++ b/maven-deploy-plugin/src/it/deploy-at-end-extension/verify.groovy
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+
+assert new File( basedir, "target/repo/org/apache/maven/its/deploy/dae/extension/dae/1.0/dae-1.0.pom" ).exists()
+assert new File( basedir, "module1/target/repo/org/apache/maven/its/deploy/dae/extension/module1/1.0/module1-1.0.pom" ).exists()
+
+File buildLog = new File( basedir, 'build.log' )
+assert buildLog.exists()
+assert buildLog.text.contains( "[INFO] Deploying org.apache.maven.its.deploy.dae.extension:dae:1.0 at end" )
+
diff --git a/maven-deploy-plugin/src/it/deploy-at-end-override-skip/module1/pom.xml b/maven-deploy-plugin/src/it/deploy-at-end-override-skip/module1/pom.xml
new file mode 100644
index 0000000000..409fb86e28
--- /dev/null
+++ b/maven-deploy-plugin/src/it/deploy-at-end-override-skip/module1/pom.xml
@@ -0,0 +1,62 @@
+
+
+
+
+
+ 4.0.0
+
+
+ org.apache.maven.its.deploy.dae.overide-skip
+ dae
+ 1.0
+
+ module1
+
+
+
+
+ org.apache.maven.wagon
+ wagon-ftp
+ 2.10
+
+
+
+
+ org.apache.maven.plugins
+ maven-deploy-plugin
+
+ false
+
+
+
+ org.apache.maven.plugins
+ maven-enforcer-plugin
+ 1.2
+
+
+ enforce
+
+ enforce
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/maven-deploy-plugin/src/it/deploy-at-end-override-skip/pom.xml b/maven-deploy-plugin/src/it/deploy-at-end-override-skip/pom.xml
new file mode 100644
index 0000000000..385b27d421
--- /dev/null
+++ b/maven-deploy-plugin/src/it/deploy-at-end-override-skip/pom.xml
@@ -0,0 +1,101 @@
+
+
+
+
+
+ 4.0.0
+
+ org.apache.maven.its.deploy.dae.overide-skip
+ dae
+ 1.0
+ pom
+
+
+ Tests deployment at end when module overrides parent skip.
+
+
+
+ true
+
+
+
+
+ it
+ file:///${basedir}/target/repo
+ false
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 2.0.2
+
+
+ org.apache.maven.plugins
+ maven-deploy-plugin
+ @project.version@
+
+ true
+ true
+
+
+
+ org.apache.maven.plugins
+ maven-install-plugin
+ 2.2
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 2.1
+
+
+ org.apache.maven.plugins
+ maven-resources-plugin
+ 2.2
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+ 2.0.4
+
+
+ attach-sources
+
+ jar
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.3.1
+
+
+
+
+
+ module1
+
+
diff --git a/maven-deploy-plugin/src/it/deploy-at-end-override-skip/verify.groovy b/maven-deploy-plugin/src/it/deploy-at-end-override-skip/verify.groovy
new file mode 100644
index 0000000000..3dd737d6fc
--- /dev/null
+++ b/maven-deploy-plugin/src/it/deploy-at-end-override-skip/verify.groovy
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+
+assert !new File( basedir, "target/repo/org/apache/maven/its/deploy/dae/overide-skip/dae/1.0/dae-1.0.pom" ).exists()
+assert new File( basedir, "module1/target/repo/org/apache/maven/its/deploy/dae/overide-skip/module1/1.0/module1-1.0.pom" ).exists()
+
+File buildLog = new File( basedir, 'build.log' )
+assert buildLog.exists()
+assert !buildLog.text.contains( "[INFO] Deploying org.apache.maven.its.deploy.dae.overide-skip:module1:1.0 at end" )
+assert !buildLog.text.contains( "[INFO] Deploying org.apache.maven.its.deploy.dae.overide-skip:dae:1.0 at end" )
+
diff --git a/maven-deploy-plugin/src/it/deploy-at-end-override/module1/pom.xml b/maven-deploy-plugin/src/it/deploy-at-end-override/module1/pom.xml
new file mode 100644
index 0000000000..1911c97f30
--- /dev/null
+++ b/maven-deploy-plugin/src/it/deploy-at-end-override/module1/pom.xml
@@ -0,0 +1,62 @@
+
+
+
+
+
+ 4.0.0
+
+
+ org.apache.maven.its.deploy.dae.overide
+ dae
+ 1.0
+
+ module1
+
+
+
+
+ org.apache.maven.wagon
+ wagon-ftp
+ 2.10
+
+
+
+
+ org.apache.maven.plugins
+ maven-deploy-plugin
+
+ true
+
+
+
+ org.apache.maven.plugins
+ maven-enforcer-plugin
+ 1.2
+
+
+ enforce
+
+ enforce
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/maven-deploy-plugin/src/it/deploy-at-end-override/module2/pom.xml b/maven-deploy-plugin/src/it/deploy-at-end-override/module2/pom.xml
new file mode 100644
index 0000000000..2174b3acf4
--- /dev/null
+++ b/maven-deploy-plugin/src/it/deploy-at-end-override/module2/pom.xml
@@ -0,0 +1,62 @@
+
+
+
+
+
+ 4.0.0
+
+
+ org.apache.maven.its.deploy.dae.overide
+ dae
+ 1.0
+
+ module2
+
+
+
+
+ org.apache.maven.wagon
+ wagon-ftp
+ 2.10
+
+
+
+
+ org.apache.maven.plugins
+ maven-deploy-plugin
+
+ true
+
+
+
+ org.apache.maven.plugins
+ maven-enforcer-plugin
+ 1.2
+
+
+ enforce
+
+ enforce
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/maven-deploy-plugin/src/it/deploy-at-end-override/pom.xml b/maven-deploy-plugin/src/it/deploy-at-end-override/pom.xml
new file mode 100644
index 0000000000..6581abd13a
--- /dev/null
+++ b/maven-deploy-plugin/src/it/deploy-at-end-override/pom.xml
@@ -0,0 +1,98 @@
+
+
+
+
+
+ 4.0.0
+
+ org.apache.maven.its.deploy.dae.overide
+ dae
+ 1.0
+ pom
+
+
+ Tests deployment at end when module overrides parent deployAtEnd.
+
+
+
+ true
+
+
+
+
+ it
+ file:///${basedir}/target/repo
+ false
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 2.0.2
+
+
+ org.apache.maven.plugins
+ maven-deploy-plugin
+ @project.version@
+
+
+ org.apache.maven.plugins
+ maven-install-plugin
+ 2.2
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 2.1
+
+
+ org.apache.maven.plugins
+ maven-resources-plugin
+ 2.2
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+ 2.0.4
+
+
+ attach-sources
+
+ jar
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.3.1
+
+
+
+
+
+ module1
+ module2
+
+
diff --git a/maven-deploy-plugin/src/it/deploy-at-end-override/verify.groovy b/maven-deploy-plugin/src/it/deploy-at-end-override/verify.groovy
new file mode 100644
index 0000000000..77296acc55
--- /dev/null
+++ b/maven-deploy-plugin/src/it/deploy-at-end-override/verify.groovy
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+assert new File( basedir, "target/repo/org/apache/maven/its/deploy/dae/overide/dae/1.0/dae-1.0.pom" ).exists()
+assert new File( basedir, "module1/target/repo/org/apache/maven/its/deploy/dae/overide/module1/1.0/module1-1.0.pom" ).exists()
+assert new File( basedir, "module2/target/repo/org/apache/maven/its/deploy/dae/overide/module2/1.0/module2-1.0.pom" ).exists()
+
+File buildLog = new File( basedir, 'build.log' )
+assert buildLog.exists()
+assert buildLog.text.contains( "[INFO] Deploying org.apache.maven.its.deploy.dae.overide:module1:1.0 at end" )
+assert !buildLog.text.contains( "[INFO] Deploying org.apache.maven.its.deploy.dae.overide:module2:1.0 at end" )
+assert !buildLog.text.contains( "[INFO] Deploying org.apache.maven.its.deploy.dae.overide:dae:1.0 at end" )
+
diff --git a/maven-deploy-plugin/src/main/java/org/apache/maven/plugins/deploy/AbstractDeployMojo.java b/maven-deploy-plugin/src/main/java/org/apache/maven/plugins/deploy/AbstractDeployMojo.java
index 77e811f835..7d91a7415c 100644
--- a/maven-deploy-plugin/src/main/java/org/apache/maven/plugins/deploy/AbstractDeployMojo.java
+++ b/maven-deploy-plugin/src/main/java/org/apache/maven/plugins/deploy/AbstractDeployMojo.java
@@ -29,7 +29,7 @@
import org.apache.maven.plugins.annotations.Parameter;
/**
- * @version $Id$
+ * @version $Id: AbstractDeployMojo.java 1791602 2017-04-16 11:20:59Z khmarbaise $
*/
public abstract class AbstractDeployMojo
extends AbstractMojo
diff --git a/maven-deploy-plugin/src/main/java/org/apache/maven/plugins/deploy/CastHelper.java b/maven-deploy-plugin/src/main/java/org/apache/maven/plugins/deploy/CastHelper.java
new file mode 100644
index 0000000000..bea0473d90
--- /dev/null
+++ b/maven-deploy-plugin/src/main/java/org/apache/maven/plugins/deploy/CastHelper.java
@@ -0,0 +1,109 @@
+package org.apache.maven.plugins.deploy;
+
+/*
+ * 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.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * Cast or copy instance across ClassLoaders
+ *
+ * @version $Id: $
+ */
+class CastHelper
+{
+ private static final String GET = "get";
+ private static final int GET_LEN = GET.length();
+
+ private static final String IS = "is";
+ private static final int IS_LEN = IS.length();
+
+ /**
+ * Cast an instance, or copy if the instance is in a different ClassLoader
+ * @param dstType The class of the returned instance
+ * @param src The source instance.
+ * @return The original instance if it was of the proper type; otherwise a copy in the correct ClassLoader
+ * @throws MojoFailureException
+ */
+ static T castToSameClassLoader( Class dstType, Object src ) throws MojoFailureException
+ {
+ try
+ {
+ return dstType.cast( src );
+ }
+ catch ( ClassCastException cce )
+ {
+ // copy contents to a across ClassLoaders.
+ try
+ {
+ return copyAttributes( dstType.newInstance(), src );
+ }
+ catch ( Exception e )
+ {
+ throw new MojoFailureException( e.getMessage(), e );
+ }
+ }
+ }
+
+ /**
+ * Simplistic copy of fields from src instance to dst instance. All fields must match.
+ */
+ private static T copyAttributes( T dst, Object src )
+ throws NoSuchMethodException, InvocationTargetException, IllegalAccessException
+ {
+ for ( Method getter : src.getClass().getMethods() )
+ {
+ if ( getter.getParameterTypes().length != 0 )
+ {
+ continue;
+ }
+ String capitalName = extractAttributeNameFromGetter( getter.getName() );
+ if ( capitalName == null )
+ {
+ continue;
+ }
+ try
+ {
+ Method setter = dst.getClass().getMethod( "set" + capitalName, getter.getReturnType() );
+ Object attribute = getter.invoke( src );
+ setter.invoke( dst, attribute );
+ }
+ catch ( NoSuchMethodException ignore )
+ {
+ continue;
+ }
+ }
+ return dst;
+ }
+
+ private static String extractAttributeNameFromGetter( String name )
+ {
+ if ( name.startsWith( GET ) )
+ {
+ return name.substring( GET_LEN );
+ }
+ if ( name.startsWith( IS ) )
+ {
+ return name.substring( IS_LEN );
+ }
+ return null;
+ }
+}
diff --git a/maven-deploy-plugin/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java b/maven-deploy-plugin/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
index 812b22d97a..878663446c 100644
--- a/maven-deploy-plugin/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
+++ b/maven-deploy-plugin/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
@@ -20,12 +20,10 @@
*/
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
-import java.util.concurrent.atomic.AtomicInteger;
+import java.util.Properties;
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;
@@ -54,15 +52,6 @@ public class DeployMojo
private static final Pattern ALT_REPO_SYNTAX_PATTERN = Pattern.compile( "(.+)::(.+)" );
- /**
- * When building with multiple threads, reaching the last project doesn't have to mean that all projects are ready
- * to be deployed
- */
- private static final AtomicInteger READYPROJECTSCOUNTER = new AtomicInteger();
-
- private static final List DEPLOYREQUESTS =
- Collections.synchronizedList( new ArrayList() );
-
/**
*/
@Parameter( defaultValue = "${project}", readonly = true, required = true )
@@ -131,10 +120,10 @@ public class DeployMojo
public void execute()
throws MojoExecutionException, MojoFailureException
{
- boolean addedDeployRequest = false;
if ( skip )
{
getLog().info( "Skipping artifact deployment" );
+ queueDeployment( null );
}
else
{
@@ -152,42 +141,93 @@ public void execute()
// @formatter:on
// CHECKSTYLE_ON: LineLength
- ArtifactRepository repo = getDeploymentRepository( pdr );
-
if ( !deployAtEnd )
{
- deployProject( getSession().getProjectBuildingRequest(), pdr, repo );
+ queueDeployment( null );
+ deployProject( pdr );
}
else
{
- DEPLOYREQUESTS.add( pdr );
- addedDeployRequest = true;
+ queueDeployment( pdr );
}
}
+ deployQueuedRequests();
+ }
+
+ /**
+ * Queue a deployment request. In a reactor, some deployments may be delayed or skipped while others are not
+ * @param pdr The deployment request. Null indicates that the deployment was not delayed
+ * @throws MojoExecutionException
+ * @throws MojoFailureException
+ */
+ private void queueDeployment( ProjectDeployerRequest pdr )
+ throws MojoExecutionException, MojoFailureException
+ {
+ List deployRequests = getDeployRequests();
- boolean projectsReady = READYPROJECTSCOUNTER.incrementAndGet() == reactorProjects.size();
- if ( projectsReady )
+ // build may be parallel, protect against multiple threads accessing
+ synchronized ( deployRequests )
{
- synchronized ( DEPLOYREQUESTS )
+
+ deployRequests.add( pdr );
+ if ( pdr != null && deployRequests.size() != reactorProjects.size() )
{
- while ( !DEPLOYREQUESTS.isEmpty() )
- {
- ArtifactRepository repo = getDeploymentRepository( DEPLOYREQUESTS.get( 0 ) );
+ getLog().info( "Deploying " + project.getGroupId() + ":" + project.getArtifactId() + ":"
+ + project.getVersion() + " at end" );
+ }
+ }
+ }
- deployProject( getSession().getProjectBuildingRequest(), DEPLOYREQUESTS.remove( 0 ), repo );
+ public void deployQueuedRequests() throws MojoExecutionException, MojoFailureException
+ {
+ List deployRequests = getDeployRequests();
+ // build may be parallel, protect against multiple threads accessing
+ synchronized ( deployRequests )
+ {
+ if ( deployRequests.size() != reactorProjects.size() )
+ {
+ return;
+ }
+ for ( Object dr : deployRequests )
+ {
+ if ( dr != null )
+ {
+ /*
+ * Cast the instance to a ProjectDeployerRequest. This specialized casting would
+ * not be necessary if ProjectDeployerRequest were in core.
+ */
+ deployProject( CastHelper.castToSameClassLoader( ProjectDeployerRequest.class, dr ) );
}
}
}
- else if ( addedDeployRequest )
+ }
+
+ private List getDeployRequests()
+ {
+ Properties projectProperties = getSession().getUserProperties();
+
+ // Plugin instances may be in different Classworlds if they are loaded in different modules
+ // containing different extensions. The plugin cannot rely on static variables, only injected
+ // or session shared variables
+ synchronized ( projectProperties )
{
- getLog().info( "Deploying " + project.getGroupId() + ":" + project.getArtifactId() + ":"
- + project.getVersion() + " at end" );
+ String propertyKey = getClass().getCanonicalName();
+ List reqs = (List) projectProperties.get( propertyKey );
+ if ( reqs == null )
+ {
+ reqs = new ArrayList( reactorProjects.size() );
+ projectProperties.put( propertyKey, reqs );
+ }
+ return reqs;
}
}
- private void deployProject( ProjectBuildingRequest pbr, ProjectDeployerRequest pir, ArtifactRepository repo )
+ private void deployProject( ProjectDeployerRequest pir )
throws MojoFailureException, MojoExecutionException
{
+ ArtifactRepository repo = getDeploymentRepository( pir );
+ ProjectBuildingRequest pbr = getSession().getProjectBuildingRequest();
+
try
{
projectDeployer.deploy( pbr, pir, repo );
@@ -200,7 +240,6 @@ private void deployProject( ProjectBuildingRequest pbr, ProjectDeployerRequest p
}
ArtifactRepository getDeploymentRepository( ProjectDeployerRequest pdr )
-
throws MojoExecutionException, MojoFailureException
{
MavenProject project = pdr.getProject();
@@ -259,5 +298,4 @@ else if ( !ArtifactUtils.isSnapshot( project.getVersion() ) && altReleaseDeploym
return repo;
}
-
}
diff --git a/maven-deploy-plugin/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java b/maven-deploy-plugin/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java
index 6c7064bbb2..2601350e5c 100644
--- a/maven-deploy-plugin/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java
+++ b/maven-deploy-plugin/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java
@@ -26,6 +26,7 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.Properties;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Model;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
@@ -69,6 +70,19 @@ public void setUp()
}
}
+ private void initializeMocksForMojo() {
+ assertNotNull( mojo );
+
+ MockitoAnnotations.initMocks( this );
+
+ ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
+ when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
+ when( session.getUserProperties() ).thenReturn( new Properties() );
+ MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
+ repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( LOCAL_REPO ) );
+ when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
+ }
+
public void testDeployTestEnvironment()
throws Exception
{
@@ -86,16 +100,8 @@ public void testBasicDeployFile()
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 );
-
+ initializeMocksForMojo();
+
String groupId = (String) getVariableValueFromObject( mojo, "groupId" );
String artifactId = (String) getVariableValueFromObject( mojo, "artifactId" );
@@ -187,15 +193,7 @@ public void testDeployIfClassifierIsSet()
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 );
+ initializeMocksForMojo();
String classifier = ( String ) getVariableValueFromObject( mojo, "classifier" );
@@ -235,10 +233,8 @@ public void testDeployIfArtifactIsNotJar()
mojo = (DeployFileMojo) lookupMojo( "deploy-file", testPom );
- MockitoAnnotations.initMocks( this );
-
- assertNotNull( mojo );
-
+ initializeMocksForMojo();
+
ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
diff --git a/maven-deploy-plugin/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java b/maven-deploy-plugin/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
index 4db5b2def7..9847e3cf92 100644
--- a/maven-deploy-plugin/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
+++ b/maven-deploy-plugin/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
@@ -92,8 +92,6 @@ public void setUp()
{
FileUtils.deleteDirectory( remoteRepo );
}
-
-
}
public void tearDown()
@@ -106,7 +104,20 @@ public void tearDown()
//FileUtils.deleteDirectory( remoteRepo );
}
}
-
+
+ private void initializeMocksForMojo() {
+ assertNotNull( mojo );
+
+ MockitoAnnotations.initMocks( this );
+
+ ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
+ when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
+ when( session.getUserProperties() ).thenReturn( new Properties() );
+ MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
+ repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( LOCAL_REPO ) );
+ when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
+ }
+
public void testDeployTestEnvironment()
throws Exception
{
@@ -124,17 +135,9 @@ public void testBasicDeploy()
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 );
-
+
+ initializeMocksForMojo();
+
File file = new File( getBasedir(),
"target/test-classes/unit/basic-deploy-test/target/" +
"deploy-test-file-1.0-SNAPSHOT.jar" );
@@ -239,9 +242,9 @@ public void testSkippingDeploy()
{
File testPom = new File( getBasedir(), "target/test-classes/unit/basic-deploy-test/plugin-config.xml" );
- DeployMojo mojo = (DeployMojo) lookupMojo( "deploy", testPom );
+ mojo = (DeployMojo) lookupMojo( "deploy", testPom );
- assertNotNull( mojo );
+ initializeMocksForMojo();
File file = new File( getBasedir(), "target/test-classes/unit/basic-deploy-test/target/"
+ "deploy-test-file-1.0-SNAPSHOT.jar" );
@@ -295,17 +298,9 @@ public void testBasicDeployWithPackagingAsPom()
"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 );
-
+
+ initializeMocksForMojo();
+
File pomFile = new File( getBasedir(),
"target/test-classes/unit/basic-deploy-pom/target/" +
"deploy-test-file-1.0-SNAPSHOT.pom" );
@@ -366,17 +361,9 @@ public void testUpdateReleaseParamSetToTrue()
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 );
-
+
+ initializeMocksForMojo();
+
boolean updateReleaseInfo = (Boolean) getVariableValueFromObject(mojo, "updateReleaseInfo");
assertTrue( updateReleaseInfo );
@@ -404,17 +391,10 @@ public void testDeployIfArtifactFileIsNull()
File testPom = new File( getBasedir(),
"target/test-classes/unit/basic-deploy-test/plugin-config.xml" );
- DeployMojo mojo = ( DeployMojo ) lookupMojo( "deploy", testPom );
+ mojo = ( DeployMojo ) lookupMojo( "deploy", testPom );
- MockitoAnnotations.initMocks( this );
+ initializeMocksForMojo();
- ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
- when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
-
- setVariableValueToObject( mojo, "session", session );
-
- assertNotNull( mojo );
-
MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );
setVariableValueToObject( mojo, "reactorProjects", Collections.singletonList( project ) );
@@ -445,16 +425,8 @@ public void testDeployWithAttachedArtifacts()
"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 );
+
+ initializeMocksForMojo();
MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );
@@ -522,7 +494,7 @@ public void testDeployWithAttachedArtifacts()
assertEquals( 0, getSizeOfExpectedFiles( fileList, expectedFiles ) );
}
-
+
@Ignore( "SCP is not part of Maven3 distribution. Aether handles transport extensions." )
public void _testBasicDeployWithScpAsProtocol()
throws Exception