You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kh...@apache.org on 2018/02/14 20:04:38 UTC
[maven-artifact-transfer] 02/07: Reformatted code * Added null
checks for parameters in ProjectDeployer and ProjectInstaller included
tests to check this. * Added working IT for ProjectInstaller.
This is an automated email from the ASF dual-hosted git repository.
khmarbaise pushed a commit to branch MSHARED-656
in repository https://gitbox.apache.org/repos/asf/maven-artifact-transfer.git
commit 144b9d602e794c60887f31e193cb0eab571e1adb
Author: Karl Heinz Marbaise <kh...@apache.org>
AuthorDate: Sun Jan 28 13:02:07 2018 +0100
Reformatted code
* Added null checks for parameters in ProjectDeployer and ProjectInstaller
included tests to check this.
* Added working IT for ProjectInstaller.
---
src/it/maven-artifact-deployer-plugin/pom.xml | 5 +-
.../artifact/deployer/ArtifactDeployerMojo.java | 6 +-
.../artifact/deployer/ArtifactDeployerTest.java | 48 +++++----
src/it/maven-artifact-installer-plugin/pom.xml | 5 +-
.../artifact/installer/ArtifactInstallerMojo.java | 4 +-
.../artifact/installer/ArtifactInstallerTest.java | 58 +++++++----
.../pom.xml | 9 +-
.../project/install/ProjectInstallerMojo.java} | 57 +++++------
.../project/install/ProjectInstallerTest.java | 110 +++++++++++++++++++++
.../src/test/projects/example/pom.xml | 68 +++++++++++++
.../artifact/deploy/ArtifactDeployerException.java | 1 +
.../shared/project/deploy/ProjectDeployer.java | 13 ++-
.../deploy/internal/DefaultProjectDeployer.java | 94 +++++++++---------
.../shared/project/install/ProjectInstaller.java | 14 ++-
.../install/internal/DefaultProjectInstaller.java | 3 +-
.../DefaultDependencyCoordinateTest.java | 1 +
.../internal/DefaultProjectDeployerTest.java | 82 +++++++++++++++
.../internal/DefaultProjectInstallerTest.java | 27 ++---
18 files changed, 451 insertions(+), 154 deletions(-)
diff --git a/src/it/maven-artifact-deployer-plugin/pom.xml b/src/it/maven-artifact-deployer-plugin/pom.xml
index 64ce850..9ebabc3 100644
--- a/src/it/maven-artifact-deployer-plugin/pom.xml
+++ b/src/it/maven-artifact-deployer-plugin/pom.xml
@@ -36,7 +36,8 @@
<packaging>maven-plugin</packaging>
<name>Apache Maven Artifact Deployer Plugin</name>
- <description>The plugin is only intended as a real testing environment for maven-artifact-deployer component.</description>
+ <description>The plugin is only intended as a real testing environment for parts
+ of the maven-artifact-transfer component. In this test we check the ArtifactDeployer</description>
<prerequisites>
<maven>${mavenVersion}</maven>
</prerequisites>
@@ -61,7 +62,7 @@
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-artifact-transfer</artifactId>
<version>@project.version@</version>
-<!-- <version>0.10.0-SNAPSHOT</version> -->
+<!-- <version>0.9.2-SNAPSHOT</version> -->
</dependency>
<!-- dependencies to annotations -->
diff --git a/src/it/maven-artifact-deployer-plugin/src/main/java/org/apache/maven/plugin/artifact/deployer/ArtifactDeployerMojo.java b/src/it/maven-artifact-deployer-plugin/src/main/java/org/apache/maven/plugin/artifact/deployer/ArtifactDeployerMojo.java
index e97a7bf..d5bf396 100644
--- a/src/it/maven-artifact-deployer-plugin/src/main/java/org/apache/maven/plugin/artifact/deployer/ArtifactDeployerMojo.java
+++ b/src/it/maven-artifact-deployer-plugin/src/main/java/org/apache/maven/plugin/artifact/deployer/ArtifactDeployerMojo.java
@@ -20,12 +20,10 @@ package org.apache.maven.plugin.artifact.deployer;
*/
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
-import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
@@ -101,13 +99,13 @@ public class ArtifactDeployerMojo
File tmpFile = File.createTempFile( "test-deploy", ".jar", artifactsDirectory );
createFileContent( tmpFile );
- DefaultArtifact artifact = new DefaultArtifact( "DEPLOYER-GROUPID-" + mvnVersion, "ARTIFACTID", "VERSION",
+ DefaultArtifact artifact = new DefaultArtifact( "ARTIFACT-DEPLOYER-GROUPID-" + mvnVersion, "ARTIFACTID", "VERSION",
"compile", "jar", null, artifactHandler );
artifact.setFile( tmpFile );
artifact.setRepository( session.getProjectBuildingRequest().getLocalRepository() );
DefaultArtifact artifactWithClassifier =
- new DefaultArtifact( "DEPLOYER-GROUPID-" + mvnVersion, "ARTIFACTID", "VERSION", "compile", "jar",
+ new DefaultArtifact( "ARTIFACT-DEPLOYER-GROUPID-" + mvnVersion, "ARTIFACTID", "VERSION", "compile", "jar",
"CLASSIFIER", artifactHandler );
File tmpFileClassifier = File.createTempFile( "test-deploy-classifier", ".jar", artifactsDirectory );
createFileContent( tmpFileClassifier );
diff --git a/src/it/maven-artifact-deployer-plugin/src/test/java/org/apache/maven/plugin/artifact/deployer/ArtifactDeployerTest.java b/src/it/maven-artifact-deployer-plugin/src/test/java/org/apache/maven/plugin/artifact/deployer/ArtifactDeployerTest.java
index e5a7fa5..ca7b8fb 100644
--- a/src/it/maven-artifact-deployer-plugin/src/test/java/org/apache/maven/plugin/artifact/deployer/ArtifactDeployerTest.java
+++ b/src/it/maven-artifact-deployer-plugin/src/test/java/org/apache/maven/plugin/artifact/deployer/ArtifactDeployerTest.java
@@ -35,9 +35,10 @@ import io.takari.maven.testing.executor.MavenVersions;
import io.takari.maven.testing.executor.junit.MavenJUnitTestRunner;
/**
- * This will check if the ArtifactInstaller works for all Maven versions 3.0.5, 3.1.1, 3.2.5, 3.3.1, 3.3.9, 3.5.0. This
- * is done by using the test plugin <code>maven-artifact-deployer-plugin</code> which uses the ArtifactInstaller as component.
- * By using this way we get a real runtime environment which supports all Maven versions.
+ * This will check if the ArtifactInstaller works for all Maven versions 3.0.5, 3.1.1, 3.2.5, 3.3.1, 3.3.9, 3.5.0,
+ * 3.5.2. This is done by using the test plugin <code>maven-artifact-deployer-plugin</code> which uses the
+ * ArtifactInstaller as component. By using this way we get a real runtime environment which supports all Maven
+ * versions.
*
* @author Karl Heinz Marbaise
*/
@@ -77,7 +78,8 @@ public class ArtifactDeployerTest
result.assertLogText( "[INFO] --- maven-artifact-deployer-plugin:1.0.0:artifact-deployer (id-artifact-deployer) @ maven-artifact-deployer-plugin-it ---" );
String mvnVersion = mavenRuntime.getMavenVersion();
- // The "." will be replaced by "/" in the running of the artifact-installer-plugin so I need to do the same here.
+ // The "." will be replaced by "/" in the running of the artifact-installer-plugin so I need to do the same
+ // here.
// Maybe there is a more elegant way to do that?
mvnVersion = mvnVersion.replaceAll( "\\.", "/" );
@@ -87,22 +89,32 @@ public class ArtifactDeployerTest
System.out.println( "localRepo='" + localRepo.getAbsolutePath() + "'" );
System.out.println( "mvnVersion='" + mvnVersion + "'" );
- // The real checking of what should had happen..
-
- assertTrue( new File( localRepo,
- "DEPLOYER-GROUPID-" + mvnVersion + "/ARTIFACTID/VERSION/ARTIFACTID-VERSION.EXTENSION" ).exists() );
- assertTrue( new File( localRepo,
- "DEPLOYER-GROUPID-" + mvnVersion + "/ARTIFACTID/VERSION/ARTIFACTID-VERSION.EXTENSION.md5" ).exists() );
+ File baseDirectoy = new File( localRepo, "ARTIFACT-DEPLOYER-GROUPID-" + mvnVersion + "/ARTIFACTID/VERSION/" );
+
+ checkForArtifactFile( baseDirectoy );
+ checkForArtifactClassifierFile( baseDirectoy );
+
assertTrue( new File( localRepo,
- "DEPLOYER-GROUPID-" + mvnVersion + "/ARTIFACTID/VERSION/ARTIFACTID-VERSION.EXTENSION.sha1" ).exists() );
+ "ARTIFACT-DEPLOYER-GROUPID-" + mvnVersion + "/ARTIFACTID/maven-metadata-local.xml" ).exists() ); // ??
- assertTrue( new File( localRepo, "DEPLOYER-GROUPID-" + mvnVersion
- + "/ARTIFACTID/VERSION/ARTIFACTID-VERSION-CLASSIFIER.EXTENSION" ).exists() );
- assertTrue( new File( localRepo, "DEPLOYER-GROUPID-" + mvnVersion
- + "/ARTIFACTID/VERSION/ARTIFACTID-VERSION-CLASSIFIER.EXTENSION.md5" ).exists() );
- assertTrue( new File( localRepo, "DEPLOYER-GROUPID-" + mvnVersion
- + "/ARTIFACTID/VERSION/ARTIFACTID-VERSION-CLASSIFIER.EXTENSION.sha1" ).exists() );
- assertTrue( new File( localRepo, "DEPLOYER-GROUPID-" + mvnVersion + "/ARTIFACTID/maven-metadata-local.xml" ).exists() ); // ??
+ }
+ private void checkForArtifactClassifierFile( File baseDirectoy )
+ {
+ File artifactClassifierFile = new File( baseDirectoy, "ARTIFACTID-VERSION-CLASSIFIER.EXTENSION" );
+ assertTrue( "artifactClassifierFile '" + artifactClassifierFile.getAbsolutePath() + "'",
+ artifactClassifierFile.exists() );
+ assertTrue( "artifactClassifierFile md5 not found.",
+ new File( artifactClassifierFile.getAbsolutePath() + ".md5" ).exists() );
+ assertTrue( "artifactClassifierFile sha1 not found.",
+ new File( artifactClassifierFile.getAbsolutePath() + ".sha1" ).exists() );
+ }
+
+ private void checkForArtifactFile( File baseDirectoy )
+ {
+ File artifactFile = new File( baseDirectoy, "ARTIFACTID-VERSION.EXTENSION" );
+ assertTrue( "artifactFile '" + artifactFile.getAbsolutePath() + "'", artifactFile.exists() );
+ assertTrue( "artifactFile md5 not found.", new File( artifactFile.getAbsolutePath() + ".md5" ).exists() );
+ assertTrue( "artifactFile sha1 not found.", new File( artifactFile.getAbsolutePath() + ".sha1" ).exists() );
}
}
\ No newline at end of file
diff --git a/src/it/maven-artifact-installer-plugin/pom.xml b/src/it/maven-artifact-installer-plugin/pom.xml
index dd3b6fc..32e88fd 100644
--- a/src/it/maven-artifact-installer-plugin/pom.xml
+++ b/src/it/maven-artifact-installer-plugin/pom.xml
@@ -36,7 +36,8 @@
<packaging>maven-plugin</packaging>
<name>Apache Maven Artifact Installer Plugin</name>
- <description>The plugin is only intended as a real testing environment for maven-artifact-transfer component.</description>
+ <description>The plugin is only intended as a real testing environment for parts
+ of the maven-artifact-transfer component. In this test we check the ArtifactInstaller</description>
<prerequisites>
<maven>${mavenVersion}</maven>
</prerequisites>
@@ -61,7 +62,7 @@
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-artifact-transfer</artifactId>
<version>@project.version@</version>
-<!-- <version>0.10.0-SNAPSHOT</version> -->
+<!-- <version>0.9.2-SNAPSHOT</version> -->
</dependency>
<!-- dependencies to annotations -->
diff --git a/src/it/maven-artifact-installer-plugin/src/main/java/org/apache/maven/plugin/artifact/installer/ArtifactInstallerMojo.java b/src/it/maven-artifact-installer-plugin/src/main/java/org/apache/maven/plugin/artifact/installer/ArtifactInstallerMojo.java
index d95ccfb..8bc83ad 100644
--- a/src/it/maven-artifact-installer-plugin/src/main/java/org/apache/maven/plugin/artifact/installer/ArtifactInstallerMojo.java
+++ b/src/it/maven-artifact-installer-plugin/src/main/java/org/apache/maven/plugin/artifact/installer/ArtifactInstallerMojo.java
@@ -99,11 +99,11 @@ public class ArtifactInstallerMojo
File tmpFile = File.createTempFile( "test-install", ".jar", artifactsDirectory );
createFileContent( tmpFile );
- DefaultArtifact artifact = new DefaultArtifact( "GROUPID-" + mvnVersion, "ARTIFACTID", "VERSION", "compile",
+ DefaultArtifact artifact = new DefaultArtifact( "ARTIFACT-INSTALLER-GROUPID-" + mvnVersion, "ARTIFACTID", "VERSION", "compile",
"jar", null, artifactHandler );
artifact.setFile( tmpFile );
DefaultArtifact artifactWithClassifier =
- new DefaultArtifact( "GROUPID-" + mvnVersion, "ARTIFACTID", "VERSION", "compile", "jar", "CLASSIFIER",
+ new DefaultArtifact( "ARTIFACT-INSTALLER-GROUPID-" + mvnVersion, "ARTIFACTID", "VERSION", "compile", "jar", "CLASSIFIER",
artifactHandler );
File tmpFileClassifier = File.createTempFile( "test-install-classifier", ".jar", artifactsDirectory );
diff --git a/src/it/maven-artifact-installer-plugin/src/test/java/org/apache/maven/plugin/artifact/installer/ArtifactInstallerTest.java b/src/it/maven-artifact-installer-plugin/src/test/java/org/apache/maven/plugin/artifact/installer/ArtifactInstallerTest.java
index 08ad0fd..fc43dee 100644
--- a/src/it/maven-artifact-installer-plugin/src/test/java/org/apache/maven/plugin/artifact/installer/ArtifactInstallerTest.java
+++ b/src/it/maven-artifact-installer-plugin/src/test/java/org/apache/maven/plugin/artifact/installer/ArtifactInstallerTest.java
@@ -36,14 +36,15 @@ import io.takari.maven.testing.executor.MavenVersions;
import io.takari.maven.testing.executor.junit.MavenJUnitTestRunner;
/**
- * This will check if the ArtifactInstaller works for all Maven versions 3.0.5, 3.1.1, 3.2.5, 3.3.1, 3.3.9, 3.5.0. This
- * is done by using the test plugin <code>maven-artifact-installer-plugin</code> which uses the ArtifactInstaller as component.
- * By using this way we get a real runtime environment which supports all Maven versions.
+ * This will check if the ArtifactInstaller works for all Maven versions 3.0.5, 3.1.1, 3.2.5, 3.3.1, 3.3.9, 3.5.0,
+ * 3.5.2. This is done by using the test plugin <code>maven-artifact-installer-plugin</code> which uses the
+ * ArtifactInstaller as component. By using this way we get a real runtime environment which supports all Maven
+ * versions.
*
* @author Karl Heinz Marbaise
*/
@RunWith( MavenJUnitTestRunner.class )
-@MavenVersions( { "3.0.5", "3.1.1", "3.2.5", "3.3.1", "3.3.9", "3.5.0" } )
+@MavenVersions( { "3.0.5", "3.1.1", "3.2.5", "3.3.1", "3.3.9", "3.5.0", "3.5.2" } )
public class ArtifactInstallerTest
{
@@ -77,7 +78,7 @@ public class ArtifactInstallerTest
// Check that the current plugins has been called at least once.
result.assertLogText( "[INFO] --- maven-artifact-installer-plugin:1.0.0:artifact-installer (id-artifact-installer) @ maven-artifact-installer-plugin-it ---" );
- String mvnVersion = mavenRuntime.getMavenVersion();
+ String mvnVersion = mavenRuntime.getMavenVersion() + "/";
// The "." will be replaced by "/" in the running of the artifact-installer-plugin so I need to do the same
// here.
// Maybe there is a more elegant way to do that?
@@ -89,21 +90,38 @@ public class ArtifactInstallerTest
System.out.println( "localRepo='" + localRepo.getAbsolutePath() + "'" );
System.out.println( "mvnVersion='" + mvnVersion + "'" );
- // The real checking of what should had happen..
- assertTrue( new File( localRepo,
- "GROUPID-" + mvnVersion + "/ARTIFACTID/VERSION/ARTIFACTID-VERSION.EXTENSION" ).exists() );
- assertFalse( new File( localRepo, "GROUPID-" + mvnVersion
- + "/ARTIFACTID/VERSION/ARTIFACTID-VERSION.EXTENSION.md5" ).exists() );
- assertFalse( new File( localRepo, "GROUPID-" + mvnVersion
- + "/ARTIFACTID/VERSION/ARTIFACTID-VERSION.EXTENSION.sha1" ).exists() );
-
- assertTrue( new File( localRepo, "GROUPID-" + mvnVersion
- + "/ARTIFACTID/VERSION/ARTIFACTID-VERSION-CLASSIFIER.EXTENSION" ).exists() );
- assertFalse( new File( localRepo, "GROUPID-" + mvnVersion
- + "/ARTIFACTID/VERSION/ARTIFACTID-VERSION-CLASSIFIER.EXTENSION.md5" ).exists() );
- assertFalse( new File( localRepo, "GROUPID-" + mvnVersion
- + "/ARTIFACTID/VERSION/ARTIFACTID-VERSION-CLASSIFIER.EXTENSION.sha1" ).exists() );
- assertTrue( new File( localRepo, "GROUPID-" + mvnVersion + "/ARTIFACTID/maven-metadata-local.xml" ).exists() ); // ??
+ File baseDirectoy = new File( localRepo, "ARTIFACT-INSTALLER-GROUPID-" + mvnVersion + "/ARTIFACTID/VERSION/" );
+ // We don't have a pom file.
+ checkForNonExistingPomFile( baseDirectoy );
+ checkForArtifact( baseDirectoy );
+ checkForArtifactClassifier( baseDirectoy );
+ }
+
+ private void checkForArtifactClassifier( File baseDirectoy )
+ {
+ File jarArtifactClassifierFile = new File( baseDirectoy, "ARTIFACTID-VERSION-CLASSIFIER.EXTENSION" );
+ assertTrue( "jarClassifierFile '" + jarArtifactClassifierFile.getAbsolutePath() + "'",
+ jarArtifactClassifierFile.exists() );
+ assertFalse( "jarClassifier md5 not found.",
+ new File( jarArtifactClassifierFile.getAbsolutePath() + ".md5" ).exists() );
+ assertFalse( "jarClassifier sha1 not found.",
+ new File( jarArtifactClassifierFile.getAbsolutePath() + ".sha1" ).exists() );
+ }
+
+ private void checkForArtifact( File baseDirectoy )
+ {
+ File artifactFile = new File( baseDirectoy, "ARTIFACTID-VERSION.EXTENSION" );
+ assertTrue( "artifactFile '" + artifactFile.getAbsolutePath() + "'", artifactFile.exists() );
+ assertFalse( "artifactFile md5 not found.", new File( artifactFile.getAbsolutePath() + ".md5" ).exists() );
+ assertFalse( "artifactFile sha1 not found.", new File( artifactFile.getAbsolutePath() + ".sha1" ).exists() );
+ }
+
+ private void checkForNonExistingPomFile( File baseDirectoy )
+ {
+ File pomFile = new File( baseDirectoy, "ARTIFACTID-VERSION.EXTENSION.pom" );
+ assertFalse( "pomFile '" + pomFile.getAbsolutePath() + "'", pomFile.exists() );
+ assertFalse( "pom md5 not found.", new File( pomFile.getAbsolutePath() + ".md5" ).exists() );
+ assertFalse( "pom sha1 not found.", new File( pomFile.getAbsolutePath() + ".sha1" ).exists() );
}
}
\ No newline at end of file
diff --git a/src/it/maven-artifact-deployer-plugin/pom.xml b/src/it/maven-project-installer-plugin/pom.xml
similarity index 93%
copy from src/it/maven-artifact-deployer-plugin/pom.xml
copy to src/it/maven-project-installer-plugin/pom.xml
index 64ce850..3d83a97 100644
--- a/src/it/maven-artifact-deployer-plugin/pom.xml
+++ b/src/it/maven-project-installer-plugin/pom.xml
@@ -31,12 +31,13 @@
<relativePath />
</parent>
- <artifactId>maven-artifact-deployer-plugin</artifactId>
+ <artifactId>maven-project-installer-plugin</artifactId>
<version>1.0.0</version>
<packaging>maven-plugin</packaging>
- <name>Apache Maven Artifact Deployer Plugin</name>
- <description>The plugin is only intended as a real testing environment for maven-artifact-deployer component.</description>
+ <name>Apache Maven Project Installer Plugin</name>
+ <description>The plugin is only intended as a real testing environment for parts
+ of the maven-artifact-transfer component. In this test we check the ProjectInstaller</description>
<prerequisites>
<maven>${mavenVersion}</maven>
</prerequisites>
@@ -61,7 +62,7 @@
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-artifact-transfer</artifactId>
<version>@project.version@</version>
-<!-- <version>0.10.0-SNAPSHOT</version> -->
+<!-- <version>0.9.2-SNAPSHOT</version> -->
</dependency>
<!-- dependencies to annotations -->
diff --git a/src/it/maven-artifact-installer-plugin/src/main/java/org/apache/maven/plugin/artifact/installer/ArtifactInstallerMojo.java b/src/it/maven-project-installer-plugin/src/main/java/org/apache/maven/plugin/project/install/ProjectInstallerMojo.java
similarity index 64%
copy from src/it/maven-artifact-installer-plugin/src/main/java/org/apache/maven/plugin/artifact/installer/ArtifactInstallerMojo.java
copy to src/it/maven-project-installer-plugin/src/main/java/org/apache/maven/plugin/project/install/ProjectInstallerMojo.java
index d95ccfb..24a57be 100644
--- a/src/it/maven-artifact-installer-plugin/src/main/java/org/apache/maven/plugin/artifact/installer/ArtifactInstallerMojo.java
+++ b/src/it/maven-project-installer-plugin/src/main/java/org/apache/maven/plugin/project/install/ProjectInstallerMojo.java
@@ -1,4 +1,4 @@
-package org.apache.maven.plugin.artifact.installer;
+package org.apache.maven.plugin.project.install;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@@ -25,12 +25,8 @@ import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
-import java.util.Collection;
import java.util.List;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.DefaultArtifact;
-import org.apache.maven.artifact.handler.DefaultArtifactHandler;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
@@ -39,16 +35,19 @@ 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.MavenProjectHelper;
import org.apache.maven.project.ProjectBuildingRequest;
-import org.apache.maven.shared.artifact.install.ArtifactInstaller;
import org.apache.maven.shared.artifact.install.ArtifactInstallerException;
+import org.apache.maven.shared.project.NoFileAssignedException;
+import org.apache.maven.shared.project.install.ProjectInstaller;
+import org.apache.maven.shared.project.install.ProjectInstallerRequest;
import org.apache.maven.shared.repository.RepositoryManager;
/**
- * This mojo is implemented to test the ArtifactInstaller part of the maven-artifact-transfer shared component.
+ * This mojo is implemented to test the {@link ProjectInstaller} part of the maven-artifact-transfer shared component.
*/
-@Mojo( name = "artifact-installer", defaultPhase = LifecyclePhase.VERIFY, threadSafe = true )
-public class ArtifactInstallerMojo
+@Mojo( name = "project-installer", defaultPhase = LifecyclePhase.VERIFY, threadSafe = true )
+public class ProjectInstallerMojo
extends AbstractMojo
{
@@ -65,14 +64,17 @@ public class ArtifactInstallerMojo
protected MavenSession session;
@Component
- private ArtifactInstaller installer;
+ private ProjectInstaller installer;
+
+ @Component
+ private MavenProjectHelper projectHelper;
public void execute()
throws MojoExecutionException, MojoFailureException
{
- getLog().info( "Hello from artifact-installer plugin" );
+ getLog().info( "Hello from project-installer plugin" );
installProject( session.getProjectBuildingRequest() );
- getLog().info( "Bye bye from artifact-installer plugin" );
+ getLog().info( "Bye bye from project-installer plugin" );
}
private void createFileContent( File outputFile )
@@ -88,31 +90,26 @@ public class ArtifactInstallerMojo
{
try
{
- DefaultArtifactHandler artifactHandler = new DefaultArtifactHandler();
- artifactHandler.setExtension( "EXTENSION" );
File artifactsDirectory =
new File( session.getCurrentProject().getBuild().getDirectory(), "tests/artifacts" );
- getLog().info( "Directory: '" + artifactsDirectory.getAbsolutePath() + "'" );
artifactsDirectory.mkdirs();
- File tmpFile = File.createTempFile( "test-install", ".jar", artifactsDirectory );
- createFileContent( tmpFile );
+ getLog().info( "Directory: '" + artifactsDirectory.getAbsolutePath() + "'" );
- DefaultArtifact artifact = new DefaultArtifact( "GROUPID-" + mvnVersion, "ARTIFACTID", "VERSION", "compile",
- "jar", null, artifactHandler );
- artifact.setFile( tmpFile );
- DefaultArtifact artifactWithClassifier =
- new DefaultArtifact( "GROUPID-" + mvnVersion, "ARTIFACTID", "VERSION", "compile", "jar", "CLASSIFIER",
- artifactHandler );
+ File tmpFile = File.createTempFile( "project-install", ".jar", artifactsDirectory );
+ createFileContent( tmpFile );
- File tmpFileClassifier = File.createTempFile( "test-install-classifier", ".jar", artifactsDirectory );
+ File tmpFileClassifier = File.createTempFile( "project-install-classifier", ".jar", artifactsDirectory );
createFileContent( tmpFileClassifier );
- artifactWithClassifier.setFile( tmpFileClassifier );
-
- Collection<Artifact> mavenArtifacts = Arrays.<Artifact>asList( artifact, artifactWithClassifier );
- installer.install( session.getProjectBuildingRequest(), mavenArtifacts );
+ projectHelper.attachArtifact( session.getCurrentProject(), "jar", "classifier", tmpFileClassifier );
+ session.getCurrentProject().getArtifact().setFile( tmpFile );
+
+ ProjectInstallerRequest pir = new ProjectInstallerRequest();
+ pir.setCreateChecksum( true );
+ pir.setProject( session.getCurrentProject());
+ installer.install( pbr, pir );
}
catch ( ArtifactInstallerException e )
{
@@ -122,6 +119,10 @@ public class ArtifactInstallerMojo
{
throw new MojoExecutionException( "IOException", e );
}
+ catch ( NoFileAssignedException e )
+ {
+ throw new MojoExecutionException( "NoFileAssignedException", e );
+ }
}
diff --git a/src/it/maven-project-installer-plugin/src/test/java/org/apache/maven/plugin/project/install/ProjectInstallerTest.java b/src/it/maven-project-installer-plugin/src/test/java/org/apache/maven/plugin/project/install/ProjectInstallerTest.java
new file mode 100644
index 0000000..e22a0ca
--- /dev/null
+++ b/src/it/maven-project-installer-plugin/src/test/java/org/apache/maven/plugin/project/install/ProjectInstallerTest.java
@@ -0,0 +1,110 @@
+package org.apache.maven.plugin.project.install;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import io.takari.maven.testing.TestResources;
+import io.takari.maven.testing.executor.MavenExecutionResult;
+import io.takari.maven.testing.executor.MavenRuntime;
+import io.takari.maven.testing.executor.MavenRuntime.MavenRuntimeBuilder;
+import io.takari.maven.testing.executor.MavenVersions;
+import io.takari.maven.testing.executor.junit.MavenJUnitTestRunner;
+
+/**
+ * This will check if the ProjectInstaller works for all Maven versions 3.0.5, 3.1.1, 3.2.5, 3.3.1, 3.3.9, 3.5.0, 3.5.2
+ * This is done by using the test plugin <code>maven-project-installer-plugin</code> which uses the ProjectInstaller as
+ * component. By using this way we get a real runtime environment which supports all Maven versions.
+ *
+ * @author Karl Heinz Marbaise
+ */
+@RunWith( MavenJUnitTestRunner.class )
+@MavenVersions( { "3.0.5", "3.1.1", "3.2.5", "3.3.1", "3.3.9", "3.5.0", "3.5.2" } )
+public class ProjectInstallerTest
+{
+
+ @Rule
+ public final TestResources resources = new TestResources();
+
+ public final MavenRuntime mavenRuntime;
+
+ public ProjectInstallerTest( MavenRuntimeBuilder builder )
+ throws Exception
+ {
+ this.mavenRuntime = builder.build();
+ }
+
+ @Test
+ public void buildExample()
+ throws Exception
+ {
+ File basedir = resources.getBasedir( "example" );
+ //@formatter:off
+ MavenExecutionResult result =
+ mavenRuntime
+ .forProject( basedir )
+ .withCliOption( "-DmvnVersion=" + mavenRuntime.getMavenVersion() ) // Might be superfluous
+ .withCliOption( "-B" )
+ .withCliOption( "-V" )
+ // We use verify to prevent running maven-install-plugin.
+ .execute( "clean", "verify" );
+ //@formatter:on
+
+ result.assertErrorFreeLog();
+
+ // Check that the current plugins has been called at least once.
+ result.assertLogText( "[INFO] --- maven-project-installer-plugin:1.0.0:project-installer (id-project-installer) @ maven-project-installer-plugin-it ---" );
+
+ String mvnVersion = mavenRuntime.getMavenVersion() + "/";
+ // The "." will be replaced by "/" in the running of the artifact-installer-plugin so I need to do the same
+ // here.
+ // Maybe there is a more elegant way to do that?
+ mvnVersion = mvnVersion.replaceAll( "\\.", "/" );
+
+ String mavenRepoLocal = System.getProperty( "maven.repo.local" );
+ File localRepo = new File( mavenRepoLocal );
+
+ System.out.println( "localRepo='" + localRepo.getAbsolutePath() + "'" );
+ System.out.println( "mvnVersion='" + mvnVersion + "'" );
+
+ File baseDirectoy =
+ new File( localRepo,
+ "PROJECT-INSTALLER-GROUPID-" + mvnVersion + "maven-project-installer-plugin-it/1.0.0-A/" );
+
+ checkForPomFile( baseDirectoy );
+
+ checkForJarFile( baseDirectoy );
+
+ checkForJarClassifierFile( baseDirectoy );
+
+ }
+
+ private void checkForJarClassifierFile( File baseDirectoy )
+ {
+ File jarClassifierFile = new File( baseDirectoy, "maven-project-installer-plugin-it-1.0.0-A-classifier.jar" );
+ assertTrue( "jarClassifierFile '" + jarClassifierFile.getAbsolutePath() + "'", jarClassifierFile.exists() );
+ assertTrue( "jarClassifier md5 not found.", new File( jarClassifierFile.getAbsolutePath() + ".md5" ).exists() );
+ assertTrue( "jarClassifier sha1 not found.",
+ new File( jarClassifierFile.getAbsolutePath() + ".sha1" ).exists() );
+ }
+
+ private void checkForJarFile( File baseDirectoy )
+ {
+ File jarFile = new File( baseDirectoy, "maven-project-installer-plugin-it-1.0.0-A.jar" );
+ assertTrue( "jarFile '" + jarFile.getAbsolutePath() + "'", jarFile.exists() );
+ assertTrue( "jar md5 not found.", new File( jarFile.getAbsolutePath() + ".md5" ).exists() );
+ assertTrue( "jar sha1 not found.", new File( jarFile.getAbsolutePath() + ".sha1" ).exists() );
+ }
+
+ private void checkForPomFile( File baseDirectoy )
+ {
+ File pomFile = new File( baseDirectoy, "maven-project-installer-plugin-it-1.0.0-A.pom" );
+ assertTrue( "pomFile '" + pomFile.getAbsolutePath() + "'", pomFile.exists() );
+ assertTrue( "pom md5 not found.", new File( pomFile.getAbsolutePath() + ".md5" ).exists() );
+ assertTrue( "pom sha1 not found.", new File( pomFile.getAbsolutePath() + ".sha1" ).exists() );
+ }
+}
\ No newline at end of file
diff --git a/src/it/maven-project-installer-plugin/src/test/projects/example/pom.xml b/src/it/maven-project-installer-plugin/src/test/projects/example/pom.xml
new file mode 100644
index 0000000..3cff491
--- /dev/null
+++ b/src/it/maven-project-installer-plugin/src/test/projects/example/pom.xml
@@ -0,0 +1,68 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!--
+ 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 xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+>
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-shared-components</artifactId>
+ <version>30</version>
+ <relativePath />
+ </parent>
+
+ <groupId>PROJECT-INSTALLER-GROUPID-${mvnVersion}</groupId>
+ <artifactId>maven-project-installer-plugin-it</artifactId>
+ <version>1.0.0-A</version>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-project-installer-plugin</artifactId>
+ <version>${it-plugin.version}</version>
+ <configuration>
+ <localRepositoryPath>${localRepositoryPath}</localRepositoryPath>
+ <mvnVersion>${mvnVersion}</mvnVersion>
+ </configuration>
+ <executions>
+ <execution>
+ <id>id-project-installer</id>
+ <goals>
+ <goal>project-installer</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/src/main/java/org/apache/maven/shared/artifact/deploy/ArtifactDeployerException.java b/src/main/java/org/apache/maven/shared/artifact/deploy/ArtifactDeployerException.java
index b0dac8d..a66f6f0 100644
--- a/src/main/java/org/apache/maven/shared/artifact/deploy/ArtifactDeployerException.java
+++ b/src/main/java/org/apache/maven/shared/artifact/deploy/ArtifactDeployerException.java
@@ -20,6 +20,7 @@ package org.apache.maven.shared.artifact.deploy;
*/
/**
+ * An artifact could not correctly being deployed.
*
*/
public class ArtifactDeployerException
diff --git a/src/main/java/org/apache/maven/shared/project/deploy/ProjectDeployer.java b/src/main/java/org/apache/maven/shared/project/deploy/ProjectDeployer.java
index ce99e78..98e131d 100644
--- a/src/main/java/org/apache/maven/shared/project/deploy/ProjectDeployer.java
+++ b/src/main/java/org/apache/maven/shared/project/deploy/ProjectDeployer.java
@@ -21,6 +21,7 @@ package org.apache.maven.shared.project.deploy;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.project.ProjectBuildingRequest;
+import org.apache.maven.shared.artifact.deploy.ArtifactDeployerException;
import org.apache.maven.shared.project.NoFileAssignedException;
/**
@@ -55,14 +56,12 @@ public interface ProjectDeployer
* @param request {@link ProjectDeployerRequest}
* @param artifactRepository {@link ArtifactRepository}
* @throws NoFileAssignedException In case of missing file which has not been assigned to project.
- * @throws IllegalArgumentException in case of artifact is not correctly assigned.
+ * @throws ArtifactDeployerException in case of artifact could not correctly deployed.
+ * @throws IllegalArgumentException in case <code>buildingRequest</code> is <code>null</code>, <code>request</code>
+ * is <code>null</code> or <code>artifactRepository</code> is <code>null</code>.
*/
- // TODO: Think about null check for projectBuildingRequest?
- // TODO: Think about null check for projectDeployerRequest?
- // TODO: Think about null check for artifactRepository?
void deploy( ProjectBuildingRequest buildingRequest, ProjectDeployerRequest request,
- ArtifactRepository artifactRepository )
- throws NoFileAssignedException, IllegalArgumentException;
-
+ ArtifactRepository artifactRepository )
+ throws NoFileAssignedException, IllegalArgumentException, ArtifactDeployerException;
}
diff --git a/src/main/java/org/apache/maven/shared/project/deploy/internal/DefaultProjectDeployer.java b/src/main/java/org/apache/maven/shared/project/deploy/internal/DefaultProjectDeployer.java
index c15ef4f..b4d88ff 100644
--- a/src/main/java/org/apache/maven/shared/project/deploy/internal/DefaultProjectDeployer.java
+++ b/src/main/java/org/apache/maven/shared/project/deploy/internal/DefaultProjectDeployer.java
@@ -54,24 +54,19 @@ public class DefaultProjectDeployer
private ArtifactDeployer deployer;
/**
- * This will deploy a single project which may contain several artifacts into the appropriate remote repository.
- *
- * @param buildingRequest {@link ProjectBuildingRequest}
- * @param request {@link ProjectDeployerRequest}
- * @param artifactRepository {@link ArtifactRepository}
- * @throws IllegalArgumentException in case of artifact is not correctly assigned.
- * @throws NoFileAssignedException In case no file has been assigned to main file.
+ * {@inheritDoc}
*/
- public void deploy( ProjectBuildingRequest buildingRequest, ProjectDeployerRequest request,
+ public void deploy( ProjectBuildingRequest buildingRequest, ProjectDeployerRequest projectDeployerRequest,
ArtifactRepository artifactRepository )
- throws NoFileAssignedException, IllegalArgumentException
+ throws NoFileAssignedException, IllegalArgumentException, ArtifactDeployerException
{
+ validateParameters( buildingRequest, projectDeployerRequest, artifactRepository );
- Artifact artifact = request.getProject().getArtifact();
- String packaging = request.getProject().getPackaging();
- File pomFile = request.getProject().getFile();
+ Artifact artifact = projectDeployerRequest.getProject().getArtifact();
+ String packaging = projectDeployerRequest.getProject().getPackaging();
+ File pomFile = projectDeployerRequest.getProject().getFile();
- List<Artifact> attachedArtifacts = request.getProject().getAttachedArtifacts();
+ List<Artifact> attachedArtifacts = projectDeployerRequest.getProject().getAttachedArtifacts();
// Deploy the POM
boolean isPomArtifact = "pom".equals( packaging );
@@ -85,57 +80,68 @@ public class DefaultProjectDeployer
artifact.addMetadata( metadata );
}
- //FIXME: It does not make sense to set an artifact explicitly to a "Release"
+ // FIXME: It does not make sense to set an artifact explicitly to a "Release"
// cause this should be choosen only by the not existing of "-SNAPSHOT" in the
// version.
- if ( request.isUpdateReleaseInfo() )
+ if ( projectDeployerRequest.isUpdateReleaseInfo() )
{
artifact.setRelease( true );
}
artifact.setRepository( artifactRepository );
- int retryFailedDeploymentCount = request.getRetryFailedDeploymentCount();
+ int retryFailedDeploymentCount = projectDeployerRequest.getRetryFailedDeploymentCount();
- try
+ List<Artifact> deployableArtifacts = new ArrayList<Artifact>();
+ if ( isPomArtifact )
+ {
+ deployableArtifacts.add( artifact );
+ }
+ else
{
- List<Artifact> deployableArtifacts = new ArrayList<Artifact>();
- if ( isPomArtifact )
+ File file = artifact.getFile();
+
+ if ( file != null && file.isFile() )
{
deployableArtifacts.add( artifact );
}
- else
+ else if ( !attachedArtifacts.isEmpty() )
{
- File file = artifact.getFile();
-
- if ( file != null && file.isFile() )
- {
- deployableArtifacts.add( artifact );
- }
- else if ( !attachedArtifacts.isEmpty() )
- {
- // TODO: Reconsider this exception? Better Exception type?
- throw new NoFileAssignedException( "The packaging plugin for this project did not assign "
- + "a main file to the project but it has attachments. Change packaging to 'pom'." );
- }
- else
- {
- // TODO: Reconsider this exception? Better Exception type?
- throw new NoFileAssignedException( "The packaging for this project did not assign "
- + "a file to the build artifact" );
- }
+ // TODO: Reconsider this exception? Better Exception type?
+ throw new NoFileAssignedException( "The packaging plugin for this project did not assign "
+ + "a main file to the project but it has attachments. Change packaging to 'pom'." );
}
-
- for ( Artifact attached : attachedArtifacts )
+ else
{
- deployableArtifacts.add( attached );
+ // TODO: Reconsider this exception? Better Exception type?
+ throw new NoFileAssignedException( "The packaging for this project did not assign "
+ + "a file to the build artifact" );
}
+ }
+
+ for ( Artifact attached : attachedArtifacts )
+ {
+ deployableArtifacts.add( attached );
+ }
- deploy( buildingRequest, deployableArtifacts, artifactRepository, retryFailedDeploymentCount );
+ deploy( buildingRequest, deployableArtifacts, artifactRepository, retryFailedDeploymentCount );
+ }
+
+ private void validateParameters( ProjectBuildingRequest buildingRequest,
+ ProjectDeployerRequest projectDeployerRequest,
+ ArtifactRepository artifactRepository )
+ {
+ if ( buildingRequest == null )
+ {
+ throw new IllegalArgumentException( "The parameter buildingRequest is not allowed to be null." );
+ }
+ if ( projectDeployerRequest == null )
+ {
+ throw new IllegalArgumentException( "The parameter projectDeployerRequest is not allowed to be null." );
}
- catch ( ArtifactDeployerException e )
+ if ( artifactRepository == null )
{
- throw new IllegalArgumentException( e.getMessage(), e );
+ throw new IllegalArgumentException( "The parameter artifactRepository is not allowed to be null." );
}
}
diff --git a/src/main/java/org/apache/maven/shared/project/install/ProjectInstaller.java b/src/main/java/org/apache/maven/shared/project/install/ProjectInstaller.java
index 247fd7d..8d92cf5 100644
--- a/src/main/java/org/apache/maven/shared/project/install/ProjectInstaller.java
+++ b/src/main/java/org/apache/maven/shared/project/install/ProjectInstaller.java
@@ -54,15 +54,15 @@ public interface ProjectInstaller
* installer.install( session.getProjectBuildingRequest(), pir );
* </pre>
*
- * To set a different local repository than the current one in the Maven session, you can inject an instance of
- * the <code>RepositoryManager</code> and set the path to the local repository, called
- * <code>localRepositoryPath</code>, as such:
+ * To set a different local repository than the current one in the Maven session, you can inject an instance of the
+ * <code>RepositoryManager</code> and set the path to the local repository, called <code>localRepositoryPath</code>,
+ * as such:
*
* <pre class="java">
- * @Component
- * private RepositoryManager repositoryManager;
+ * @Component
+ * private RepositoryManager repositoryManager;
*
- * buildingRequest = repositoryManager.setLocalRepositoryBasedir( buildingRequest, localRepositoryPath );
+ * buildingRequest = repositoryManager.setLocalRepositoryBasedir( buildingRequest, localRepositoryPath );
* </pre>
*
* @param projectBuildingRequest {@link ProjectBuildingRequest}
@@ -73,8 +73,6 @@ public interface ProjectInstaller
* @throws IllegalArgumentException in case of parameter <code>projectBuildingRequest</code> is <code>null</code> or
* parameter <code>projectInstallerRequest</code> is <code>null</code>.
*/
- // TODO: Think about null check for projectBuildingRequest?
- // TODO: Think about null check for projectInstallerRequest?
void install( ProjectBuildingRequest projectBuildingRequest, ProjectInstallerRequest projectInstallerRequest )
throws IOException, ArtifactInstallerException, NoFileAssignedException, IllegalArgumentException;
diff --git a/src/main/java/org/apache/maven/shared/project/install/internal/DefaultProjectInstaller.java b/src/main/java/org/apache/maven/shared/project/install/internal/DefaultProjectInstaller.java
index 5d277d3..799790a 100644
--- a/src/main/java/org/apache/maven/shared/project/install/internal/DefaultProjectInstaller.java
+++ b/src/main/java/org/apache/maven/shared/project/install/internal/DefaultProjectInstaller.java
@@ -71,7 +71,6 @@ public class DefaultProjectInstaller
public void install( ProjectBuildingRequest buildingRequest, ProjectInstallerRequest installerRequest )
throws IOException, ArtifactInstallerException, NoFileAssignedException, IllegalArgumentException
{
-
validateParameters( buildingRequest, installerRequest );
MavenProject project = installerRequest.getProject();
boolean createChecksum = installerRequest.isCreateChecksum();
@@ -157,7 +156,7 @@ public class DefaultProjectInstaller
throw new IllegalArgumentException( "The parameter installerRequest is not allowed to be null." );
}
}
-
+
/**
* Installs the checksums for the specified artifact if this has been enabled in the plugin configuration. This
* method creates checksums for files that have already been installed to the local repo to account for on-the-fly
diff --git a/src/test/java/org/apache/maven/shared/dependency/DefaultDependencyCoordinateTest.java b/src/test/java/org/apache/maven/shared/dependency/DefaultDependencyCoordinateTest.java
index a52d055..f3d00ea 100644
--- a/src/test/java/org/apache/maven/shared/dependency/DefaultDependencyCoordinateTest.java
+++ b/src/test/java/org/apache/maven/shared/dependency/DefaultDependencyCoordinateTest.java
@@ -18,6 +18,7 @@ package org.apache.maven.shared.dependency;
* specific language governing permissions and limitations
* under the License.
*/
+
import static org.junit.Assert.assertEquals;
import org.apache.maven.shared.dependencies.DefaultDependableCoordinate;
diff --git a/src/test/java/org/apache/maven/shared/project/deploy/internal/DefaultProjectDeployerTest.java b/src/test/java/org/apache/maven/shared/project/deploy/internal/DefaultProjectDeployerTest.java
new file mode 100644
index 0000000..2d54a24
--- /dev/null
+++ b/src/test/java/org/apache/maven/shared/project/deploy/internal/DefaultProjectDeployerTest.java
@@ -0,0 +1,82 @@
+package org.apache.maven.shared.project.deploy.internal;
+
+/*
+ * 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 static org.mockito.Mockito.mock;
+
+import org.apache.maven.project.ProjectBuildingRequest;
+import org.apache.maven.shared.artifact.deploy.ArtifactDeployerException;
+import org.apache.maven.shared.project.NoFileAssignedException;
+import org.apache.maven.shared.project.deploy.ProjectDeployer;
+import org.apache.maven.shared.project.deploy.ProjectDeployerRequest;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+/**
+ * Check the parameter contracts which have been made based on the interface {@link ProjectDeployer}.
+ *
+ * @author Karl Heinz Marbaise <a href="mailto:khmarbaise@apache.org">khmabaise@apache.org</a>
+ */
+public class DefaultProjectDeployerTest
+{
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ @Test
+ public void deployShouldFailWithIAEWhileBuildingRequestIsNull()
+ throws IllegalArgumentException, NoFileAssignedException, ArtifactDeployerException
+ {
+ ProjectDeployer dpi = new DefaultProjectDeployer();
+
+ expectedException.expect( IllegalArgumentException.class );
+ expectedException.expectMessage( "The parameter buildingRequest is not allowed to be null." );
+
+ dpi.deploy( null, null, null );
+ }
+
+ @Test
+ public void deployShouldFailWithIAEWhileProjectDeployerRequestIsNull()
+ throws IllegalArgumentException, NoFileAssignedException, ArtifactDeployerException
+ {
+ ProjectDeployer dpi = new DefaultProjectDeployer();
+
+ expectedException.expect( IllegalArgumentException.class );
+ expectedException.expectMessage( "The parameter projectDeployerRequest is not allowed to be null." );
+
+ ProjectBuildingRequest pbr = mock( ProjectBuildingRequest.class );
+ dpi.deploy( pbr, null, null );
+ }
+
+ @Test
+ public void deployShouldFailWithIAEWhileArtifactRepositoryIsNull()
+ throws IllegalArgumentException, NoFileAssignedException, ArtifactDeployerException
+ {
+ ProjectDeployer dpi = new DefaultProjectDeployer();
+
+ expectedException.expect( IllegalArgumentException.class );
+ expectedException.expectMessage( "The parameter artifactRepository is not allowed to be null." );
+
+ ProjectBuildingRequest pbr = mock( ProjectBuildingRequest.class );
+ ProjectDeployerRequest pdr = mock( ProjectDeployerRequest.class );
+ dpi.deploy( pbr, pdr, null );
+ }
+
+}
diff --git a/src/test/java/org/apache/maven/shared/project/install/internal/DefaultProjectInstallerTest.java b/src/test/java/org/apache/maven/shared/project/install/internal/DefaultProjectInstallerTest.java
index 7d1cc8e..8c74d71 100644
--- a/src/test/java/org/apache/maven/shared/project/install/internal/DefaultProjectInstallerTest.java
+++ b/src/test/java/org/apache/maven/shared/project/install/internal/DefaultProjectInstallerTest.java
@@ -38,32 +38,33 @@ import org.junit.rules.ExpectedException;
*/
public class DefaultProjectInstallerTest
{
+
@Rule
- public ExpectedException thrown = ExpectedException.none();
+ public ExpectedException expectedException = ExpectedException.none();
@Test
- public void installShouldReturnIllegalArgumentExceptionWhereBuildingRequestIsNull()
+ public void installShouldFailWithIAEWhileBuildingRequestIsNull()
throws IOException, ArtifactInstallerException, NoFileAssignedException
{
- DefaultProjectInstaller dai = new DefaultProjectInstaller();
+ ProjectInstaller dpi = new DefaultProjectInstaller();
+
+ expectedException.expect( IllegalArgumentException.class );
+ expectedException.expectMessage( "The parameter buildingRequest is not allowed to be null." );
- thrown.expect( IllegalArgumentException.class );
- thrown.expectMessage( "The parameter buildingRequest is not allowed to be null." );
- dai.install( null, null );
+ dpi.install( null, null );
}
@Test
- public void installShouldReturnIllegalArgumentExceptionWhereInstallerRequestIsNull()
+ public void installShouldFailWithIAEWhileProjectInstallerRequestIsNull()
throws IOException, ArtifactInstallerException, NoFileAssignedException
{
- DefaultProjectInstaller dai = new DefaultProjectInstaller();
+ ProjectInstaller dpi = new DefaultProjectInstaller();
- thrown.expect( IllegalArgumentException.class );
- thrown.expectMessage( "The parameter installerRequest is not allowed to be null." );
+ expectedException.expect( IllegalArgumentException.class );
+ expectedException.expectMessage( "The parameter request is not allowed to be null." );
ProjectBuildingRequest pbr = mock( ProjectBuildingRequest.class );
- dai.install( pbr, null );
- }
-
+ dpi.install( pbr, null );
+ }
}
--
To stop receiving notification emails like this one, please contact
khmarbaise@apache.org.