Author: rfscholte Date: Thu May 14 17:16:50 2015 New Revision: 1679410 URL: http://svn.apache.org/r1679410 Log: 3.0 version without maven-compat
Added: maven/plugins/branches/m-deploy-p-3.0/src/test/resources/unit/basic-deploy-pom/target/deploy-test-file-1.0-SNAPSHOT.pom Removed: maven/plugins/branches/m-deploy-p-3.0/src/test/resources/unit/basic-deploy-pom/target/deploy-test-file-1.0-SNAPSHOT.jar Modified: maven/plugins/branches/m-deploy-p-3.0/pom.xml maven/plugins/branches/m-deploy-p-3.0/src/main/java/org/apache/maven/plugin/deploy/AbstractDeployMojo.java maven/plugins/branches/m-deploy-p-3.0/src/main/java/org/apache/maven/plugin/deploy/DeployFileMojo.java maven/plugins/branches/m-deploy-p-3.0/src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java maven/plugins/branches/m-deploy-p-3.0/src/test/java/org/apache/maven/plugin/deploy/DeployFileMojoTest.java maven/plugins/branches/m-deploy-p-3.0/src/test/java/org/apache/maven/plugin/deploy/DeployMojoTest.java maven/plugins/branches/m-deploy-p-3.0/src/test/java/org/apache/maven/plugin/deploy/stubs/ArtifactDeployerStub.java maven/plugins/branches/m-deploy-p-3.0/src/test/java/org/apache/maven/plugin/deploy/stubs/ArtifactRepositoryStub.java maven/plugins/branches/m-deploy-p-3.0/src/test/java/org/apache/maven/plugin/deploy/stubs/ArtifactRepositoryStub2.java maven/plugins/branches/m-deploy-p-3.0/src/test/java/org/apache/maven/plugin/deploy/stubs/DeployArtifactStub.java Modified: maven/plugins/branches/m-deploy-p-3.0/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/branches/m-deploy-p-3.0/pom.xml?rev=1679410&r1=1679409&r2=1679410&view=diff ============================================================================== --- maven/plugins/branches/m-deploy-p-3.0/pom.xml (original) +++ maven/plugins/branches/m-deploy-p-3.0/pom.xml Thu May 14 17:16:50 2015 @@ -30,7 +30,7 @@ under the License. </parent> <artifactId>maven-deploy-plugin</artifactId> - <version>2.8.3-SNAPSHOT</version> + <version>3.0-SNAPSHOT</version> <packaging>maven-plugin</packaging> <name>Apache Maven Deploy Plugin</name> @@ -58,7 +58,9 @@ under the License. </distributionManagement> <properties> - <mavenVersion>2.2.1</mavenVersion> + <mavenVersion>3.0</mavenVersion> + <maven.compiler.source>1.6</maven.compiler.source> + <maven.compiler.target>1.6</maven.compiler.target> </properties> <dependencies> @@ -69,7 +71,7 @@ under the License. </dependency> <dependency> <groupId>org.apache.maven</groupId> - <artifactId>maven-project</artifactId> + <artifactId>maven-core</artifactId> <version>${mavenVersion}</version> </dependency> <dependency> @@ -82,6 +84,13 @@ under the License. <artifactId>maven-artifact</artifactId> <version>${mavenVersion}</version> </dependency> + + <dependency> + <groupId>org.apache.maven.shared</groupId> + <artifactId>maven-artifact-transfer</artifactId> + <version>0.0.1-SNAPSHOT</version> + </dependency> + <!-- dependencies to annotations --> <dependency> <groupId>org.apache.maven.plugin-tools</groupId> @@ -96,7 +105,13 @@ under the License. <dependency> <groupId>org.apache.maven.plugin-testing</groupId> <artifactId>maven-plugin-testing-harness</artifactId> - <version>1.3</version> + <version>2.1</version> + <scope>test</scope> + </dependency> + <dependency> <!-- used by maven-plugin-testing-harness, don't give it compile scope! --> + <groupId>org.apache.maven</groupId> + <artifactId>maven-compat</artifactId> + <version>${mavenVersion}</version> <scope>test</scope> </dependency> <dependency> @@ -108,7 +123,13 @@ under the License. <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> - <version>3.8.2</version> + <version>4.11</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.sonatype.aether</groupId> + <artifactId>aether-connector-file</artifactId> + <version>1.7</version> <scope>test</scope> </dependency> </dependencies> Modified: maven/plugins/branches/m-deploy-p-3.0/src/main/java/org/apache/maven/plugin/deploy/AbstractDeployMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/branches/m-deploy-p-3.0/src/main/java/org/apache/maven/plugin/deploy/AbstractDeployMojo.java?rev=1679410&r1=1679409&r2=1679410&view=diff ============================================================================== --- maven/plugins/branches/m-deploy-p-3.0/src/main/java/org/apache/maven/plugin/deploy/AbstractDeployMojo.java (original) +++ maven/plugins/branches/m-deploy-p-3.0/src/main/java/org/apache/maven/plugin/deploy/AbstractDeployMojo.java Thu May 14 17:16:50 2015 @@ -19,21 +19,23 @@ package org.apache.maven.plugin.deploy; * under the License. */ -import java.io.File; +import java.util.Collection; import java.util.Map; import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.deployer.ArtifactDeployer; -import org.apache.maven.artifact.deployer.ArtifactDeploymentException; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; +import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; +import org.apache.maven.artifact.repository.MavenArtifactRepository; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +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.shared.artifact.deploy.ArtifactDeployer; +import org.apache.maven.shared.artifact.deploy.ArtifactDeployerException; /** * @version $Id$ @@ -53,12 +55,6 @@ public abstract class AbstractDeployMojo protected ArtifactFactory artifactFactory; /** - * Component used to create a repository. - */ - @Component - ArtifactRepositoryFactory repositoryFactory; - - /** * Map that contains the layouts. */ @Component( role = ArtifactRepositoryLayout.class ) @@ -90,6 +86,9 @@ public abstract class AbstractDeployMojo @Parameter( property = "retryFailedDeploymentCount", defaultValue = "1" ) private int retryFailedDeploymentCount; + @Parameter( defaultValue = "${session}", readonly = true, required = true ) + private MavenSession session; + /* Setters and Getters */ public ArtifactDeployer getDeployer() @@ -146,20 +145,21 @@ public abstract class AbstractDeployMojo /** * Deploy an artifact from a particular file. - * - * @param source the file to deploy - * @param artifact the artifact definition + * @param artifacts the artifact definitions * @param deploymentRepository the repository to deploy to * @param localRepository the local repository to install into * @param retryFailedDeploymentCount TODO - * @throws ArtifactDeploymentException if an error occurred deploying the artifact + * + * @throws ArtifactDeployerException if an error occurred deploying the artifact */ - protected void deploy( File source, Artifact artifact, ArtifactRepository deploymentRepository, + protected void deploy( Collection<Artifact> artifacts, ArtifactRepository deploymentRepository, ArtifactRepository localRepository, int retryFailedDeploymentCount ) - throws ArtifactDeploymentException + throws ArtifactDeployerException { + + // for now retry means redeploy the complete artifacts collection int retryFailedDeploymentCounter = Math.max( 1, Math.min( 10, retryFailedDeploymentCount ) ); - ArtifactDeploymentException exception = null; + ArtifactDeployerException exception = null; for ( int count = 0; count < retryFailedDeploymentCounter; count++ ) { try @@ -169,11 +169,12 @@ public abstract class AbstractDeployMojo getLog().info( "Retrying deployment attempt " + ( count + 1 ) + " of " + retryFailedDeploymentCounter ); } - getDeployer().deploy( source, artifact, deploymentRepository, localRepository ); + + getDeployer().deploy( session.getProjectBuildingRequest(), artifacts ); exception = null; break; } - catch ( ArtifactDeploymentException e ) + catch ( ArtifactDeployerException e ) { if ( count + 1 < retryFailedDeploymentCounter ) { @@ -191,4 +192,12 @@ public abstract class AbstractDeployMojo throw exception; } } + + protected ArtifactRepository createDeploymentArtifactRepository( String id, String url, + ArtifactRepositoryLayout layout, + boolean uniqueVersion2 ) + { + return new MavenArtifactRepository( id, url, layout, new ArtifactRepositoryPolicy(), + new ArtifactRepositoryPolicy() ); + } } Modified: maven/plugins/branches/m-deploy-p-3.0/src/main/java/org/apache/maven/plugin/deploy/DeployFileMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/branches/m-deploy-p-3.0/src/main/java/org/apache/maven/plugin/deploy/DeployFileMojo.java?rev=1679410&r1=1679409&r2=1679410&view=diff ============================================================================== --- maven/plugins/branches/m-deploy-p-3.0/src/main/java/org/apache/maven/plugin/deploy/DeployFileMojo.java (original) +++ maven/plugins/branches/m-deploy-p-3.0/src/main/java/org/apache/maven/plugin/deploy/DeployFileMojo.java Thu May 14 17:16:50 2015 @@ -27,6 +27,7 @@ import java.io.InputStream; 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.jar.JarEntry; @@ -34,14 +35,19 @@ import java.util.jar.JarFile; import java.util.regex.Pattern; import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.deployer.ArtifactDeploymentException; import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.model.InputLocation; import org.apache.maven.model.Model; import org.apache.maven.model.Parent; +import org.apache.maven.model.building.DefaultModelBuildingRequest; +import org.apache.maven.model.building.ModelBuildingRequest; +import org.apache.maven.model.building.ModelProblemCollector; +import org.apache.maven.model.building.ModelProblem.Severity; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.model.io.xpp3.MavenXpp3Writer; +import org.apache.maven.model.validation.ModelValidator; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Component; @@ -50,8 +56,7 @@ import org.apache.maven.plugins.annotati import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectHelper; import org.apache.maven.project.artifact.ProjectArtifactMetadata; -import org.apache.maven.project.validation.ModelValidationResult; -import org.apache.maven.project.validation.ModelValidator; +import org.apache.maven.shared.artifact.deploy.ArtifactDeployerException; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.ReaderFactory; @@ -145,6 +150,7 @@ public class DeployFileMojo /** * The type of remote repository layout to deploy to. Try <i>legacy</i> for a Maven 1.x-style repository layout. */ + @Deprecated @Parameter( property = "repositoryLayout", defaultValue = "default" ) private String repositoryLayout; @@ -314,7 +320,7 @@ public class DeployFileMojo ArtifactRepositoryLayout layout = getLayout( repositoryLayout ); ArtifactRepository deploymentRepository = - repositoryFactory.createDeploymentArtifactRepository( repositoryId, url, layout, uniqueVersion ); + createDeploymentArtifactRepository( repositoryId, url, layout, uniqueVersion ); String protocol = deploymentRepository.getProtocol(); @@ -354,14 +360,13 @@ public class DeployFileMojo project.setArtifact( artifact ); - try - { - deploy( file, artifact, deploymentRepository, getLocalRepository(), getRetryFailedDeploymentCount() ); - } - catch ( ArtifactDeploymentException e ) - { - throw new MojoExecutionException( e.getMessage(), e ); - } + artifact.setFile( file ); + + artifact.setRepository( deploymentRepository ); + + List<Artifact> deployableArtifacts = new ArrayList<Artifact>(); + + deployableArtifacts.add( artifact ); if ( sources != null ) { @@ -455,23 +460,21 @@ public class DeployFileMojo } } - @SuppressWarnings( "unchecked" ) List<Artifact> attachedArtifacts = project.getAttachedArtifacts(); for ( Artifact attached : attachedArtifacts ) { - try - { - deploy( attached.getFile(), attached, deploymentRepository, getLocalRepository(), - getRetryFailedDeploymentCount() ); - } - catch ( ArtifactDeploymentException e ) - { - throw new MojoExecutionException( "Error deploying attached artifact " + attached.getFile() + ": " - + e.getMessage(), e ); - } + deployableArtifacts.add( attached ); } + try + { + deploy( deployableArtifacts, deploymentRepository, getLocalRepository(), getRetryFailedDeploymentCount() ); + } + catch ( ArtifactDeployerException e ) + { + throw new MojoExecutionException( e.getMessage(), e ); + } } /** @@ -598,12 +601,16 @@ public class DeployFileMojo { Model model = generateModel(); - ModelValidationResult result = modelValidator.validate( model ); + ModelBuildingRequest buildingRequest = new DefaultModelBuildingRequest(); + + DeployModelProblemCollector problemCollector = new DeployModelProblemCollector(); + + modelValidator.validateEffectiveModel( model, buildingRequest, problemCollector ); - if ( result.getMessageCount() > 0 ) + if ( problemCollector.getMessageCount() > 0 ) { throw new MojoExecutionException( "The artifact information is incomplete or not valid:\n" - + result.render( " " ) ); + + problemCollector.render( " " ) ); } } @@ -687,4 +694,41 @@ public class DeployFileMojo { this.classifier = classifier; } + + private static class DeployModelProblemCollector implements ModelProblemCollector + { + /** */ + private static final String NEWLINE = System.getProperty( "line.separator" ); + + /** */ + private List<String> messages = new ArrayList<String>(); + + @Override + public void add( Severity severity, String message, InputLocation location, Exception cause ) + { + messages.add( message ); + } + + public int getMessageCount() + { + return messages.size(); + } + + public String render( String indentation ) + { + if ( messages.size() == 0 ) + { + return indentation + "There were no validation errors."; + } + + StringBuilder message = new StringBuilder(); + + for ( int i = 0; i < messages.size(); i++ ) + { + message.append( indentation + "[" + i + "] " + messages.get( i ).toString() + NEWLINE ); + } + + return message.toString(); + } + }; } Modified: maven/plugins/branches/m-deploy-p-3.0/src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/branches/m-deploy-p-3.0/src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java?rev=1679410&r1=1679409&r2=1679410&view=diff ============================================================================== --- maven/plugins/branches/m-deploy-p-3.0/src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java (original) +++ maven/plugins/branches/m-deploy-p-3.0/src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java Thu May 14 17:16:50 2015 @@ -29,7 +29,6 @@ import java.util.regex.Pattern; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.ArtifactUtils; -import org.apache.maven.artifact.deployer.ArtifactDeploymentException; import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; @@ -40,6 +39,7 @@ import org.apache.maven.plugins.annotati import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.apache.maven.project.artifact.ProjectArtifactMetadata; +import org.apache.maven.shared.artifact.deploy.ArtifactDeployerException; /** * Deploys an artifact to remote repository. @@ -174,11 +174,12 @@ public class DeployMojo private void deployProject( DeployRequest request ) throws MojoExecutionException, MojoFailureException { + List<Artifact> deployableArtifacts = new ArrayList<Artifact>(); + Artifact artifact = request.getProject().getArtifact(); String packaging = request.getProject().getPackaging(); File pomFile = request.getProject().getFile(); - @SuppressWarnings( "unchecked" ) List<Artifact> attachedArtifacts = request.getProject().getAttachedArtifacts(); ArtifactRepository repo = @@ -205,19 +206,25 @@ public class DeployMojo ArtifactMetadata metadata = new ProjectArtifactMetadata( artifact, pomFile ); artifact.addMetadata( metadata ); } + else + { + artifact.setFile( pomFile ); + } if ( request.isUpdateReleaseInfo() ) { artifact.setRelease( true ); } + artifact.setRepository( repo ); + int retryFailedDeploymentCount = request.getRetryFailedDeploymentCount(); try { if ( isPomArtifact ) { - deploy( pomFile, artifact, repo, getLocalRepository(), retryFailedDeploymentCount ); + deployableArtifacts.add( artifact ); } else { @@ -225,7 +232,7 @@ public class DeployMojo if ( file != null && file.isFile() ) { - deploy( file, artifact, repo, getLocalRepository(), retryFailedDeploymentCount ); + deployableArtifacts.add( artifact ); } else if ( !attachedArtifacts.isEmpty() ) { @@ -240,7 +247,7 @@ public class DeployMojo pomArtifact.setRelease( true ); } - deploy( pomFile, pomArtifact, repo, getLocalRepository(), retryFailedDeploymentCount ); + deployableArtifacts.add( pomArtifact ); // propagate the timestamped version to the main artifact for the attached artifacts to pick it up artifact.setResolvedVersion( pomArtifact.getVersion() ); @@ -254,10 +261,23 @@ public class DeployMojo for ( Artifact attached : attachedArtifacts ) { - deploy( attached.getFile(), attached, repo, getLocalRepository(), retryFailedDeploymentCount ); + // This is here when AttachedArtifact is used, like m-sources-plugin:2.0.4 + try + { + attached.setRepository( repo ); + } + catch ( UnsupportedOperationException e ) + { + getLog().warn( attached.getId() + " has been attached with deprecated code, " + + "try to upgrade the responsible plugin" ); + } + + deployableArtifacts.add( attached ); } + + deploy( deployableArtifacts, repo, getLocalRepository(), retryFailedDeploymentCount ); } - catch ( ArtifactDeploymentException e ) + catch ( ArtifactDeployerException e ) { throw new MojoExecutionException( e.getMessage(), e ); } @@ -303,7 +323,7 @@ public class DeployMojo ArtifactRepositoryLayout repoLayout = getLayout( layout ); - repo = repositoryFactory.createDeploymentArtifactRepository( id, url, repoLayout, true ); + repo = createDeploymentArtifactRepository( id, url, repoLayout, true ); } } Modified: maven/plugins/branches/m-deploy-p-3.0/src/test/java/org/apache/maven/plugin/deploy/DeployFileMojoTest.java URL: http://svn.apache.org/viewvc/maven/plugins/branches/m-deploy-p-3.0/src/test/java/org/apache/maven/plugin/deploy/DeployFileMojoTest.java?rev=1679410&r1=1679409&r2=1679410&view=diff ============================================================================== --- maven/plugins/branches/m-deploy-p-3.0/src/test/java/org/apache/maven/plugin/deploy/DeployFileMojoTest.java (original) +++ maven/plugins/branches/m-deploy-p-3.0/src/test/java/org/apache/maven/plugin/deploy/DeployFileMojoTest.java Thu May 14 17:16:50 2015 @@ -19,14 +19,25 @@ package org.apache.maven.plugin.deploy; * under the License. */ +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + import java.io.File; import java.util.ArrayList; import java.util.List; import org.apache.maven.artifact.Artifact; +import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Model; +import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.testing.AbstractMojoTestCase; import org.apache.maven.plugin.testing.stubs.MavenProjectStub; +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; /** * @author <a href="mailto:arami...@apache.org">Allan Ramirez</a> @@ -34,6 +45,8 @@ import org.apache.maven.plugin.testing.s public class DeployFileMojoTest extends AbstractMojoTestCase { + private String LOCAL_REPO = getBasedir() + "/target/local-repo"; + private List<String> expectedFiles; private List<String> fileList; @@ -42,6 +55,12 @@ public class DeployFileMojoTest MavenProjectStub projectStub = new MavenProjectStub(); + @Mock + private MavenSession session; + + @InjectMocks + private DeployFileMojo mojo; + public void setUp() throws Exception { @@ -62,7 +81,7 @@ public class DeployFileMojoTest { File testPom = new File( getBasedir(), "target/test-classes/unit/deploy-file-test/plugin-config.xml" ); - DeployFileMojo mojo = (DeployFileMojo) lookupMojo( "deploy-file", testPom ); + AbstractDeployMojo mojo = (AbstractDeployMojo) lookupMojo( "deploy-file", testPom ); assertNotNull( mojo ); } @@ -72,10 +91,18 @@ public class DeployFileMojoTest { File testPom = new File( getBasedir(), "target/test-classes/unit/deploy-file-test/plugin-config.xml" ); - DeployFileMojo mojo = (DeployFileMojo) lookupMojo( "deploy-file", testPom ); + 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 ); + setVariableValueToObject( mojo, "project", projectStub ); String groupId = (String) getVariableValueFromObject( mojo, "groupId" ); @@ -167,9 +194,17 @@ public class DeployFileMojoTest { File testPom = new File( getBasedir(), "target/test-classes/unit/deploy-file-classifier/plugin-config.xml" ); - DeployFileMojo mojo = (DeployFileMojo) lookupMojo( "deploy-file", testPom ); + 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 ); setVariableValueToObject( mojo, "project", projectStub ); @@ -209,9 +244,17 @@ public class DeployFileMojoTest { File testPom = new File( getBasedir(), "target/test-classes/unit/deploy-file-artifact-not-jar/plugin-config.xml" ); - DeployFileMojo mojo = (DeployFileMojo) lookupMojo( "deploy-file", testPom ); + 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 ); setVariableValueToObject( mojo, "project", projectStub ); @@ -241,7 +284,7 @@ public class DeployFileMojoTest { File testPom = new File( getBasedir(), "target/test-classes/unit/deploy-file-legacy-repository-layout/plugin-config.xml" ); - DeployFileMojo mojo = (DeployFileMojo) lookupMojo( "deploy-file", testPom ); + AbstractDeployMojo mojo = (AbstractDeployMojo) lookupMojo( "deploy-file", testPom ); assertNotNull( mojo ); @@ -257,40 +300,16 @@ public class DeployFileMojoTest assertEquals( "legacy", repositoryLayout ); - mojo.execute(); - - File artifactFile = new File( remoteRepo, "deploy-file-legacy-repository-layout/" + groupId + "/jars/" + artifactId + "-" + version + ".jar" ); - - assertTrue( artifactFile.exists() ); - - //check the remote-repo - expectedFiles = new ArrayList<String>(); - fileList = new ArrayList<String>(); - - File repo = new File( remoteRepo, "deploy-file-legacy-repository-layout" ); - - File[] files = repo.listFiles(); - - for (File file : files) { - addFileToList(file, fileList); + try + { + mojo.execute(); + fail( "legacy is not supported anymore" ); + } + catch ( MojoExecutionException e ) + { + assertEquals( "Invalid repository layout: legacy", e.getMessage() ); } - expectedFiles.add( "org.apache.maven.test" ); - expectedFiles.add( "jars" ); - 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( "poms" ); - 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" ); - expectedFiles.add( "maven-metadata.xml" ); - expectedFiles.add( "maven-metadata.xml.md5" ); - expectedFiles.add( "maven-metadata.xml.sha1" ); - - assertEquals( expectedFiles.size(), fileList.size() ); - - assertEquals( 0, getSizeOfExpectedFiles( fileList, expectedFiles ) ); } private void addFileToList( File file, List<String> fileList ) Modified: maven/plugins/branches/m-deploy-p-3.0/src/test/java/org/apache/maven/plugin/deploy/DeployMojoTest.java URL: http://svn.apache.org/viewvc/maven/plugins/branches/m-deploy-p-3.0/src/test/java/org/apache/maven/plugin/deploy/DeployMojoTest.java?rev=1679410&r1=1679409&r2=1679410&view=diff ============================================================================== --- maven/plugins/branches/m-deploy-p-3.0/src/test/java/org/apache/maven/plugin/deploy/DeployMojoTest.java (original) +++ maven/plugins/branches/m-deploy-p-3.0/src/test/java/org/apache/maven/plugin/deploy/DeployMojoTest.java Thu May 14 17:16:50 2015 @@ -20,6 +20,7 @@ package org.apache.maven.plugin.deploy; */ import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; import java.io.File; @@ -28,18 +29,31 @@ import java.util.Collections; import java.util.List; import java.util.Properties; +import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.deploy.stubs.ArtifactDeployerStub; import org.apache.maven.plugin.deploy.stubs.ArtifactRepositoryStub; -import org.apache.maven.plugin.deploy.stubs.AttachedArtifactStub; import org.apache.maven.plugin.deploy.stubs.DeployArtifactStub; import org.apache.maven.plugin.testing.AbstractMojoTestCase; import org.apache.maven.plugin.testing.stubs.MavenProjectStub; import org.apache.maven.project.MavenProject; +import org.apache.maven.project.ProjectBuildingRequest; +import org.apache.maven.repository.internal.MavenRepositorySystemSession; +import org.apache.maven.shared.artifact.deploy.ArtifactDeployer; import org.codehaus.plexus.util.FileUtils; +import org.junit.Assume; +import org.junit.Ignore; +import org.junit.internal.builders.IgnoredBuilder; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.sonatype.aether.RepositorySystemSession; +import org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager; +import org.sonatype.aether.repository.LocalRepositoryManager; /** * @author <a href="mailto:arami...@apache.org">Allan Ramirez</a> @@ -58,7 +72,13 @@ public class DeployMojoTest DeployArtifactStub artifact; MavenProjectStub project = new MavenProjectStub(); + + @Mock + private MavenSession session; + @InjectMocks + private DeployMojo mojo; + public void setUp() throws Exception { @@ -79,6 +99,8 @@ public class DeployMojoTest { FileUtils.deleteDirectory( remoteRepo ); } + + } public void tearDown() @@ -106,13 +128,20 @@ public class DeployMojoTest public void testBasicDeploy() throws Exception { - File testPom = new File( getBasedir(), - "target/test-classes/unit/basic-deploy-test/plugin-config.xml" ); + 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 ); 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" ); @@ -155,10 +184,13 @@ public class DeployMojoTest 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" ); + // 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, "" ); @@ -269,10 +301,24 @@ public class DeployMojoTest File testPom = new File( getBasedir(), "target/test-classes/unit/basic-deploy-pom/plugin-config.xml" ); - DeployMojo mojo = ( DeployMojo ) lookupMojo( "deploy", testPom ); + 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" ); + + assertTrue( pomFile.exists() ); + MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" ); setVariableValueToObject( mojo, "reactorProjects", Collections.singletonList( project ) ); @@ -281,6 +327,8 @@ public class DeployMojoTest artifact.setArtifactHandlerExtension( project.getPackaging() ); + artifact.setFile( pomFile ); + ArtifactRepositoryStub repo = getRepoStub( mojo ); repo.setAppendToUrl( "basic-deploy-pom" ); @@ -324,11 +372,18 @@ public class DeployMojoTest { File testPom = new File( getBasedir(), "target/test-classes/unit/basic-deploy-pom/plugin-config.xml" ); + mojo = ( DeployMojo ) lookupMojo( "deploy", testPom ); - DeployMojo 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 ); + boolean updateReleaseInfo = (Boolean) getVariableValueFromObject(mojo, "updateReleaseInfo"); assertTrue( updateReleaseInfo ); @@ -389,9 +444,17 @@ public class DeployMojoTest "target/test-classes/unit/basic-deploy-with-attached-artifacts/" + "plugin-config.xml" ); - DeployMojo mojo = ( DeployMojo ) lookupMojo( "deploy", testPom ); - + 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" ); @@ -405,28 +468,16 @@ public class DeployMojoTest artifact.setFile( file ); + for( Artifact attachment :project.getAttachedArtifacts() ) + {} + - @SuppressWarnings( "unchecked" ) - List<AttachedArtifactStub> attachedArtifacts = project.getAttachedArtifacts(); - ArtifactRepositoryStub repo = getRepoStub( mojo ); repo.setAppendToUrl( "basic-deploy-with-attached-artifacts" ); mojo.execute(); - String packaging = project.getPackaging(); - - for( AttachedArtifactStub attachedArtifact : attachedArtifacts ) - { - File deployedArtifact = new File( remoteRepo, "basic-deploy-with-attached-artifacts" + "/" + - attachedArtifact.getGroupId().replace( '.', '/' ) + "/" + - attachedArtifact.getArtifactId() + "/" + - attachedArtifact.getVersion() + "/" + attachedArtifact.getArtifactId() + "-" + - attachedArtifact.getVersion() + "." + packaging ); - assertTrue( deployedArtifact.exists() ); - } - //check the artifacts in remote repository List<String> expectedFiles = new ArrayList<String>(); List<String> fileList = new ArrayList<String>(); @@ -476,8 +527,8 @@ public class DeployMojoTest assertEquals( 0, getSizeOfExpectedFiles( fileList, expectedFiles ) ); } - - public void testBasicDeployWithScpAsProtocol() + @Ignore( "SCP is not part of Maven3 distribution. Aether handles transport extensions." ) + public void _testBasicDeployWithScpAsProtocol() throws Exception { String originalUserHome = System.getProperty( "user.home" ); @@ -496,7 +547,7 @@ public class DeployMojoTest File testPom = new File( getBasedir(), "target/test-classes/unit/basic-deploy-scp/plugin-config.xml" ); - DeployMojo mojo = ( DeployMojo ) lookupMojo( "deploy", testPom ); + mojo = ( DeployMojo ) lookupMojo( "deploy", testPom ); assertNotNull( mojo ); @@ -543,40 +594,45 @@ public class DeployMojoTest FileUtils.deleteDirectory( sshFile ); } - public void testAltSnapshotDeploymentRepository() throws Exception + public void testAltSnapshotDeploymentRepository() + throws Exception { - DeployMojo mojo = new DeployMojo(); - + DeployMojo mojo = spy( new DeployMojo() ); + ArtifactRepositoryLayout repositoryLayout = mock( ArtifactRepositoryLayout.class ); setVariableValueToObject( mojo, "repositoryLayouts", Collections.singletonMap( "default", repositoryLayout ) ); - ArtifactRepositoryFactory repositoryFactory = mock( ArtifactRepositoryFactory.class ); - ArtifactRepository repository = mock( ArtifactRepository.class); - when( repositoryFactory.createDeploymentArtifactRepository( "altSnapshotDeploymentRepository", "http://localhost", repositoryLayout, true ) ).thenReturn( repository ); - setVariableValueToObject( mojo, "repositoryFactory", repositoryFactory ); - + ArtifactRepository repository = mock( ArtifactRepository.class ); + when( + mojo.createDeploymentArtifactRepository( "altSnapshotDeploymentRepository", "http://localhost", + repositoryLayout, true ) ).thenReturn( repository ); + project.setVersion( "1.0-SNAPSHOT" ); - - assertEquals( repository, mojo.getDeploymentRepository( project, null, null, "altSnapshotDeploymentRepository::default::http://localhost" ) ); + + assertEquals( repository, + mojo.getDeploymentRepository( project, null, null, + "altSnapshotDeploymentRepository::default::http://localhost" ) ); } - public void testAltReleaseDeploymentRepository() throws Exception + public void testAltReleaseDeploymentRepository() + throws Exception { - DeployMojo mojo = new DeployMojo(); - + DeployMojo mojo = spy( new DeployMojo() ); + ArtifactRepositoryLayout repositoryLayout = mock( ArtifactRepositoryLayout.class ); setVariableValueToObject( mojo, "repositoryLayouts", Collections.singletonMap( "default", repositoryLayout ) ); - ArtifactRepositoryFactory repositoryFactory = mock( ArtifactRepositoryFactory.class ); - ArtifactRepository repository = mock( ArtifactRepository.class); - when( repositoryFactory.createDeploymentArtifactRepository( "altReleaseDeploymentRepository", "http://localhost", repositoryLayout, true ) ).thenReturn( repository ); - setVariableValueToObject( mojo, "repositoryFactory", repositoryFactory ); - + ArtifactRepository repository = mock( ArtifactRepository.class ); + when( + mojo.createDeploymentArtifactRepository( "altReleaseDeploymentRepository", "http://localhost", + repositoryLayout, true ) ).thenReturn( repository ); + project.setVersion( "1.0" ); - - assertEquals( repository, mojo.getDeploymentRepository( project, null, "altReleaseDeploymentRepository::default::http://localhost", null ) ); - } + assertEquals( repository, + mojo.getDeploymentRepository( project, null, + "altReleaseDeploymentRepository::default::http://localhost", null ) ); + } private void addFileToList( File file, List<String> fileList ) { @@ -600,6 +656,9 @@ public class DeployMojoTest { for( String fileName : fileList ) { + // translate uniqueVersion to -SNAPSHOT + fileName = fileName.replaceFirst( "-\\d{8}\\.\\d{6}-\\d+", "-SNAPSHOT" ); + if( !expectedFiles.remove( fileName ) ) { fail( fileName + " is not included in the expected files" ); Modified: maven/plugins/branches/m-deploy-p-3.0/src/test/java/org/apache/maven/plugin/deploy/stubs/ArtifactDeployerStub.java URL: http://svn.apache.org/viewvc/maven/plugins/branches/m-deploy-p-3.0/src/test/java/org/apache/maven/plugin/deploy/stubs/ArtifactDeployerStub.java?rev=1679410&r1=1679409&r2=1679410&view=diff ============================================================================== --- maven/plugins/branches/m-deploy-p-3.0/src/test/java/org/apache/maven/plugin/deploy/stubs/ArtifactDeployerStub.java (original) +++ maven/plugins/branches/m-deploy-p-3.0/src/test/java/org/apache/maven/plugin/deploy/stubs/ArtifactDeployerStub.java Thu May 14 17:16:50 2015 @@ -19,29 +19,20 @@ package org.apache.maven.plugin.deploy.s * under the License. */ -import java.io.File; +import java.util.Collection; import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.deployer.ArtifactDeployer; -import org.apache.maven.artifact.deployer.ArtifactDeploymentException; -import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.project.ProjectBuildingRequest; +import org.apache.maven.shared.artifact.deploy.ArtifactDeployer; +import org.apache.maven.shared.artifact.deploy.ArtifactDeployerException; public class ArtifactDeployerStub implements ArtifactDeployer { - public void deploy( String basedir, String finalName, Artifact artifact, ArtifactRepository deploymentRepository, - ArtifactRepository localRepository ) - throws ArtifactDeploymentException - { - String extension = artifact.getArtifactHandler().getExtension(); - File source = new File( basedir, finalName + "." + extension ); - deploy( source, artifact, deploymentRepository, localRepository ); - } - - public void deploy( File source, Artifact artifact, ArtifactRepository deploymentRepository, - ArtifactRepository localRepository ) - throws ArtifactDeploymentException + @Override + public void deploy( ProjectBuildingRequest request, Collection<Artifact> mavenArtifacts ) + throws ArtifactDeployerException { // does nothing } Modified: maven/plugins/branches/m-deploy-p-3.0/src/test/java/org/apache/maven/plugin/deploy/stubs/ArtifactRepositoryStub.java URL: http://svn.apache.org/viewvc/maven/plugins/branches/m-deploy-p-3.0/src/test/java/org/apache/maven/plugin/deploy/stubs/ArtifactRepositoryStub.java?rev=1679410&r1=1679409&r2=1679410&view=diff ============================================================================== --- maven/plugins/branches/m-deploy-p-3.0/src/test/java/org/apache/maven/plugin/deploy/stubs/ArtifactRepositoryStub.java (original) +++ maven/plugins/branches/m-deploy-p-3.0/src/test/java/org/apache/maven/plugin/deploy/stubs/ArtifactRepositoryStub.java Thu May 14 17:16:50 2015 @@ -25,9 +25,10 @@ import org.apache.maven.artifact.reposit 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 - implements ArtifactRepository + extends StubArtifactRepository { private boolean blacklisted; @@ -36,6 +37,16 @@ public class ArtifactRepositoryStub private String url; private String basedir = System.getProperty( "basedir" ); + + public ArtifactRepositoryStub() + { + super( null ); + } + + public ArtifactRepositoryStub( String dir ) + { + super( dir ); + } public String pathOf( Artifact artifact ) { Modified: maven/plugins/branches/m-deploy-p-3.0/src/test/java/org/apache/maven/plugin/deploy/stubs/ArtifactRepositoryStub2.java URL: http://svn.apache.org/viewvc/maven/plugins/branches/m-deploy-p-3.0/src/test/java/org/apache/maven/plugin/deploy/stubs/ArtifactRepositoryStub2.java?rev=1679410&r1=1679409&r2=1679410&view=diff ============================================================================== --- maven/plugins/branches/m-deploy-p-3.0/src/test/java/org/apache/maven/plugin/deploy/stubs/ArtifactRepositoryStub2.java (original) +++ maven/plugins/branches/m-deploy-p-3.0/src/test/java/org/apache/maven/plugin/deploy/stubs/ArtifactRepositoryStub2.java Thu May 14 17:16:50 2015 @@ -24,6 +24,16 @@ public class ArtifactRepositoryStub2 { 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"; Modified: maven/plugins/branches/m-deploy-p-3.0/src/test/java/org/apache/maven/plugin/deploy/stubs/DeployArtifactStub.java URL: http://svn.apache.org/viewvc/maven/plugins/branches/m-deploy-p-3.0/src/test/java/org/apache/maven/plugin/deploy/stubs/DeployArtifactStub.java?rev=1679410&r1=1679409&r2=1679410&view=diff ============================================================================== --- maven/plugins/branches/m-deploy-p-3.0/src/test/java/org/apache/maven/plugin/deploy/stubs/DeployArtifactStub.java (original) +++ maven/plugins/branches/m-deploy-p-3.0/src/test/java/org/apache/maven/plugin/deploy/stubs/DeployArtifactStub.java Thu May 14 17:16:50 2015 @@ -61,6 +61,12 @@ public class DeployArtifactStub return getVersion(); } + @Override + public String getType() + { + return "jar"; + } + public void setFile( File file ) { this.file = file; Added: maven/plugins/branches/m-deploy-p-3.0/src/test/resources/unit/basic-deploy-pom/target/deploy-test-file-1.0-SNAPSHOT.pom URL: http://svn.apache.org/viewvc/maven/plugins/branches/m-deploy-p-3.0/src/test/resources/unit/basic-deploy-pom/target/deploy-test-file-1.0-SNAPSHOT.pom?rev=1679410&view=auto ============================================================================== --- maven/plugins/branches/m-deploy-p-3.0/src/test/resources/unit/basic-deploy-pom/target/deploy-test-file-1.0-SNAPSHOT.pom (added) +++ maven/plugins/branches/m-deploy-p-3.0/src/test/resources/unit/basic-deploy-pom/target/deploy-test-file-1.0-SNAPSHOT.pom Thu May 14 17:16:50 2015 @@ -0,0 +1,28 @@ +<!-- +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. +--> + +<project> + + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.maven.test</groupId> + <artifactId>maven-deploy-file-test</artifactId> + <version>1.0</version> + <packaging>pom</packaging> + +</project> \ No newline at end of file