You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2022/03/08 10:48:26 UTC
[maven-install-plugin] branch mvn4 updated: runtime support
This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch mvn4
in repository https://gitbox.apache.org/repos/asf/maven-install-plugin.git
The following commit(s) were added to refs/heads/mvn4 by this push:
new 7039dce runtime support
7039dce is described below
commit 7039dce8cfba87cadeb7380e1582b952009e63cb
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Tue Mar 8 11:48:23 2022 +0100
runtime support
---
pom.xml | 5 +
.../maven/plugins/install/AbstractInstallMojo.java | 6 -
.../maven/plugins/install/InstallFileMojo.java | 84 ++---
.../apache/maven/plugins/install/InstallMojo.java | 69 +++-
.../maven/plugins/install/InstallFileMojoTest.java | 377 +++++++++----------
.../maven/plugins/install/InstallMojoTest.java | 397 +++++++--------------
.../maven/plugins/install/stubs/ArtifactStub.java | 178 +++++++++
.../install/stubs/AttachedArtifactStub0.java | 38 --
.../install/stubs/AttachedArtifactStub1.java | 29 --
.../plugins/install/stubs/InstallArtifactStub.java | 121 -------
.../maven/plugins/install/stubs/ProjectStub.java | 152 ++++++++
.../maven/plugins/install/stubs/SessionStub.java | 217 +++++++++++
.../unit/basic-install-checksum/maven-test-jar.jar | 1 -
.../unit/basic-install-checksum/plugin-config.xml | 35 --
.../plugin-config.xml | 42 ---
.../target/maven-install-test-1.0-SNAPSHOT.jar | Bin 2372 -> 0 bytes
.../unit/basic-install-test/plugin-config.xml | 35 --
.../target/maven-install-test-1.0-SNAPSHOT.jar | Bin 2372 -> 0 bytes
.../attached-artifact-test-1.0-SNAPSHOT.jar | 1 +
.../maven-install-test-1.0-SNAPSHOT.jar | Bin
.../packaging-pom.xml} | 15 +-
.../plugin-config.xml => basic-install/test.xml} | 15 +-
.../target/maven-install-test-1.0-SNAPSHOT.jar | Bin 2372 -> 0 bytes
.../target/maven-install-test-1.0-SNAPSHOT.jar | Bin 2372 -> 0 bytes
.../target/maven-install-test-1.0-SNAPSHOT.jar | Bin 1244 -> 0 bytes
.../install-file-with-checksum/maven-test-jar.jar | 1 -
.../basic-test.xml} | 3 +-
.../file-absent.xml} | 3 +-
.../maven-install-test-1.0-SNAPSHOT.jar | Bin
.../test-generatePom.xml} | 4 +-
.../with-checksum.xml} | 2 +-
.../with-classifier.xml} | 2 +-
.../with-pom-as-packaging.xml} | 2 +-
.../with-pomFile-test.xml} | Bin 2934 -> 2856 bytes
34 files changed, 984 insertions(+), 850 deletions(-)
diff --git a/pom.xml b/pom.xml
index 7d53b80..c47a06c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -163,6 +163,11 @@
<artifactId>maven-invoker-plugin</artifactId>
<version>3.2.2</version>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>3.0.0-M5</version>
+ </plugin>
</plugins>
</pluginManagement>
</build>
diff --git a/src/main/java/org/apache/maven/plugins/install/AbstractInstallMojo.java b/src/main/java/org/apache/maven/plugins/install/AbstractInstallMojo.java
index fdec6ff..5788a42 100644
--- a/src/main/java/org/apache/maven/plugins/install/AbstractInstallMojo.java
+++ b/src/main/java/org/apache/maven/plugins/install/AbstractInstallMojo.java
@@ -25,9 +25,6 @@ import org.apache.maven.api.Artifact;
import org.apache.maven.api.Metadata;
import org.apache.maven.api.Session;
import org.apache.maven.api.plugin.annotations.Component;
-import org.apache.maven.api.plugin.annotations.Mojo;
-import org.apache.maven.api.plugin.annotations.Parameter;
-import org.apache.maven.api.services.LocalRepositoryManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -43,9 +40,6 @@ public abstract class AbstractInstallMojo
protected Logger logger = LoggerFactory.getLogger( getClass() );
@Component
- protected LocalRepositoryManager repositoryManager;
-
- @Parameter( defaultValue = "${session}", required = true, readonly = true )
protected Session session;
/**
diff --git a/src/main/java/org/apache/maven/plugins/install/InstallFileMojo.java b/src/main/java/org/apache/maven/plugins/install/InstallFileMojo.java
index 1a029f2..3ecfee7 100644
--- a/src/main/java/org/apache/maven/plugins/install/InstallFileMojo.java
+++ b/src/main/java/org/apache/maven/plugins/install/InstallFileMojo.java
@@ -26,6 +26,7 @@ import java.io.InputStream;
import java.io.Reader;
import java.io.Writer;
import java.nio.file.Files;
+import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.List;
import java.util.jar.JarEntry;
@@ -38,8 +39,6 @@ import org.apache.maven.api.plugin.MojoException;
import org.apache.maven.api.plugin.annotations.Component;
import org.apache.maven.api.plugin.annotations.Mojo;
import org.apache.maven.api.plugin.annotations.Parameter;
-import org.apache.maven.api.services.ArtifactFactory;
-import org.apache.maven.api.services.ArtifactFactoryRequest;
import org.apache.maven.api.services.ArtifactInstaller;
import org.apache.maven.api.services.ArtifactManager;
import org.apache.maven.model.Model;
@@ -47,7 +46,6 @@ import org.apache.maven.model.Parent;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.shared.utils.WriterFactory;
-import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.xml.XmlStreamReader;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
@@ -95,13 +93,13 @@ public class InstallFileMojo
*
* @since 2.2
*/
- @Parameter( property = "classifier" )
+ @Parameter( property = "classifier" ) @SuppressWarnings( "unused" )
private String classifier;
/**
* The file to be installed in the local repository.
*/
- @Parameter( property = "file", required = true )
+ @Parameter( property = "file", required = true ) @SuppressWarnings( "unused" )
private File file;
/**
@@ -109,7 +107,7 @@ public class InstallFileMojo
*
* @since 2.3
*/
- @Parameter( property = "javadoc" )
+ @Parameter( property = "javadoc" ) @SuppressWarnings( "unused" )
private File javadoc;
/**
@@ -117,7 +115,7 @@ public class InstallFileMojo
*
* @since 2.3
*/
- @Parameter( property = "sources" )
+ @Parameter( property = "sources" ) @SuppressWarnings( "unused" )
private File sources;
/**
@@ -135,7 +133,7 @@ public class InstallFileMojo
*
* @since 2.1
*/
- @Parameter( property = "generatePom" )
+ @Parameter( property = "generatePom" ) @SuppressWarnings( "unused" )
private Boolean generatePom;
/**
@@ -144,16 +142,13 @@ public class InstallFileMojo
*
* @since 2.2
*/
- @Parameter( property = "localRepositoryPath" )
+ @Parameter( property = "localRepositoryPath" ) @SuppressWarnings( "unused" )
private File localRepositoryPath;
- /**
- * Used to install the project created.
- */
- @Component
- private ArtifactInstaller installer;
+ @Component @SuppressWarnings( "unused" )
+ private ArtifactInstaller artifactInstaller;
- @Component
+ @Component @SuppressWarnings( "unused" )
private ArtifactManager artifactManager;
/**
@@ -199,16 +194,7 @@ public class InstallFileMojo
// We need to set a new ArtifactHandler otherwise
// the extension will be set to the packaging type
// which is sometimes wrong.
- Artifact artifact = session.getService( ArtifactFactory.class )
- .create( ArtifactFactoryRequest.builder()
- .session( session )
- .groupId( groupId )
- .artifactId( artifactId )
- .classifier( classifier )
- .version( version )
- .extension( FileUtils.getExtension( file.getName() ) )
- .type( packaging )
- .build() );
+ Artifact artifact = session.createArtifact( groupId, artifactId, classifier, version, packaging );
if ( file.equals( getLocalRepoFile( artifact ) ) )
{
@@ -221,19 +207,11 @@ public class InstallFileMojo
if ( !"pom".equals( packaging ) )
{
- Artifact pomArtifact = session.getService( ArtifactFactory.class )
- .create( ArtifactFactoryRequest.builder()
- .session( session )
- .groupId( groupId )
- .artifactId( artifactId )
- .classifier( classifier )
- .version( version )
- .type( "pom" )
- .build() );
+ Artifact pomArtifact = session.createArtifact( groupId, artifactId, "", version, "pom" );
if ( pomFile != null )
{
artifactManager.setPath( pomArtifact, pomFile.toPath() );
- installableArtifacts.add( artifact );
+ installableArtifacts.add( pomArtifact );
}
else
{
@@ -243,7 +221,7 @@ public class InstallFileMojo
|| ( generatePom == null && !getLocalRepoFile( pomArtifact ).exists() ) )
{
logger.debug( "Installing generated POM" );
- installableArtifacts.add( artifact );
+ installableArtifacts.add( pomArtifact );
}
else if ( generatePom == null )
{
@@ -254,37 +232,21 @@ public class InstallFileMojo
if ( sources != null )
{
- Artifact sourcesArtifact = session.getService( ArtifactFactory.class )
- .create( ArtifactFactoryRequest.builder()
- .session( session )
- .groupId( groupId )
- .artifactId( artifactId )
- .classifier( "sources" )
- .version( version )
- .type( "jar" )
- .build() );
+ Artifact sourcesArtifact = session.createArtifact( groupId, artifactId, "sources", version, "jar" );
artifactManager.setPath( sourcesArtifact, sources.toPath() );
- installableArtifacts.add( artifact );
+ installableArtifacts.add( sourcesArtifact );
}
if ( javadoc != null )
{
- Artifact sourcesArtifact = session.getService( ArtifactFactory.class )
- .create( ArtifactFactoryRequest.builder()
- .session( session )
- .groupId( groupId )
- .artifactId( artifactId )
- .classifier( "javadoc" )
- .version( version )
- .type( "jar" )
- .build() );
- artifactManager.setPath( sourcesArtifact, javadoc.toPath() );
- installableArtifacts.add( artifact );
+ Artifact javadocArtifact = session.createArtifact( groupId, artifactId, "javadoc", version, "jar" );
+ artifactManager.setPath( javadocArtifact, javadoc.toPath() );
+ installableArtifacts.add( javadocArtifact );
}
try
{
- installer.install( session, installableArtifacts );
+ artifactInstaller.install( session, installableArtifacts );
}
catch ( Exception e )
{
@@ -328,7 +290,7 @@ public class InstallFileMojo
try ( InputStream pomInputStream = jarFile.getInputStream( entry ) )
{
- Files.copy( pomInputStream, pomFile.toPath() );
+ Files.copy( pomInputStream, pomFile.toPath(), StandardCopyOption.REPLACE_EXISTING );
}
processModel( readModel( pomFile ) );
@@ -342,6 +304,7 @@ public class InstallFileMojo
catch ( IOException e )
{
// ignore, artifact not packaged by Maven
+ logger.trace( "Error reading pom from jar", e );
}
return pomFile;
}
@@ -358,8 +321,7 @@ public class InstallFileMojo
{
try ( Reader reader = new XmlStreamReader( pomFile ) )
{
- final Model model = new MavenXpp3Reader().read( reader );
- return model;
+ return new MavenXpp3Reader().read( reader );
}
catch ( FileNotFoundException e )
{
diff --git a/src/main/java/org/apache/maven/plugins/install/InstallMojo.java b/src/main/java/org/apache/maven/plugins/install/InstallMojo.java
index 03ed848..66a8706 100644
--- a/src/main/java/org/apache/maven/plugins/install/InstallMojo.java
+++ b/src/main/java/org/apache/maven/plugins/install/InstallMojo.java
@@ -19,20 +19,24 @@ package org.apache.maven.plugins.install;
* under the License.
*/
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.maven.api.Artifact;
import org.apache.maven.api.Project;
import org.apache.maven.api.plugin.MojoException;
import org.apache.maven.api.plugin.annotations.Component;
import org.apache.maven.api.plugin.annotations.LifecyclePhase;
import org.apache.maven.api.plugin.annotations.Mojo;
import org.apache.maven.api.plugin.annotations.Parameter;
-import org.apache.maven.api.services.ProjectInstaller;
-import org.apache.maven.api.services.ProjectInstallerException;
-import org.apache.maven.api.services.ProjectInstallerRequest;
+import org.apache.maven.api.services.ArtifactInstaller;
+import org.apache.maven.api.services.ArtifactInstallerException;
+import org.apache.maven.api.services.ArtifactInstallerRequest;
+import org.apache.maven.api.services.ArtifactManager;
+import org.apache.maven.api.services.ProjectManager;
/**
* Installs the project's main artifact, and any other artifacts attached by other plugins in the lifecycle, to the
@@ -51,15 +55,16 @@ public class InstallMojo
*/
private static final AtomicInteger READYPROJECTSCOUNTER = new AtomicInteger();
- private static final List<ProjectInstallerRequest> INSTALLREQUESTS =
- Collections.synchronizedList( new ArrayList<ProjectInstallerRequest>() );
+ private static final List<ArtifactInstallerRequest> INSTALLREQUESTS =
+ Collections.synchronizedList( new ArrayList<>() );
/**
*/
- @Parameter( defaultValue = "${project}", readonly = true, required = true )
+ @Parameter( defaultValue = "${project}", readonly = true, required = true ) @SuppressWarnings( "unused" )
private Project project;
@Parameter( defaultValue = "${reactorProjects}", required = true, readonly = true )
+ @SuppressWarnings( { "unused", "MismatchedQueryAndUpdateOfCollection" } )
private List<Project> reactorProjects;
/**
@@ -69,7 +74,7 @@ public class InstallMojo
*
* @since 2.5
*/
- @Parameter( defaultValue = "false", property = "installAtEnd" )
+ @Parameter( defaultValue = "false", property = "installAtEnd" ) @SuppressWarnings( "unused" )
private boolean installAtEnd;
/**
@@ -81,8 +86,11 @@ public class InstallMojo
@Parameter( property = "maven.install.skip", defaultValue = "false" )
private boolean skip;
- @Component
- private ProjectInstaller installer;
+ @Component @SuppressWarnings( "unused" )
+ private ArtifactInstaller installer;
+
+ @Component @SuppressWarnings( "unused" )
+ private ArtifactManager artifactManager;
public void execute()
throws MojoException
@@ -94,19 +102,44 @@ public class InstallMojo
}
else
{
- // CHECKSTYLE_OFF: LineLength
- ProjectInstallerRequest projectInstallerRequest =
- ProjectInstallerRequest.builder().project( project )
+ List<Artifact> installables = new ArrayList<>();
+
+ installables.add( project.getArtifact() );
+
+ if ( !"pom".equals( project.getPackaging() ) )
+ {
+ Artifact pomArtifact = session.createArtifact(
+ project.getGroupId(), project.getArtifactId(), "",
+ project.getVersion(), "pom" );
+ artifactManager.setPath( pomArtifact, project.getPomPath() );
+ installables.add( pomArtifact );
+ }
+
+ ProjectManager projectManager = session.getService( ProjectManager.class );
+ installables.addAll( projectManager.getAttachedArtifacts( project ) );
+
+ for ( Artifact artifact : installables )
+ {
+ Path path = artifactManager.getPath( artifact ).orElse( null );
+ if ( path == null )
+ {
+ throw new MojoException( "The packaging for this project did not assign "
+ + "a file to the build artifact" );
+ }
+ }
+
+ ArtifactInstallerRequest artifactInstallerRequest = ArtifactInstallerRequest.builder()
+ .session( session )
+ .artifacts( installables )
.build();
- // CHECKSTYLE_ON: LineLength
if ( !installAtEnd )
{
- installProject( projectInstallerRequest );
+ installProject( artifactInstallerRequest );
}
else
{
- INSTALLREQUESTS.add( projectInstallerRequest );
+ INSTALLREQUESTS.add( artifactInstallerRequest );
addedInstallRequest = true;
}
}
@@ -129,16 +162,16 @@ public class InstallMojo
}
}
- private void installProject( ProjectInstallerRequest pir )
+ private void installProject( ArtifactInstallerRequest pir )
throws MojoException
{
try
{
installer.install( pir );
}
- catch ( ProjectInstallerException e )
+ catch ( ArtifactInstallerException e )
{
- throw new MojoException( "ProjectInstallerException", e );
+ throw new MojoException( "ArtifactInstallerRequest", e );
}
}
diff --git a/src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java b/src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java
index bf040b1..1d31c67 100644
--- a/src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java
@@ -20,280 +20,297 @@ package org.apache.maven.plugins.install;
*/
import java.io.File;
-import java.io.Reader;
-
-import org.apache.maven.execution.MavenSession;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Consumer;
+
+import com.google.inject.Inject;
+import com.google.inject.Provides;
+import com.google.inject.Singleton;
+import org.apache.maven.api.Artifact;
+import org.apache.maven.api.Session;
+import org.apache.maven.api.plugin.MojoException;
+import org.apache.maven.api.services.ArtifactInstaller;
+import org.apache.maven.api.services.ArtifactInstallerRequest;
+import org.apache.maven.api.services.ArtifactManager;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
-import org.apache.maven.plugin.testing.AbstractMojoTestCase;
-import org.apache.maven.project.DefaultProjectBuildingRequest;
-import org.apache.maven.project.ProjectBuildingRequest;
-import org.apache.maven.shared.utils.ReaderFactory;
+import org.apache.maven.api.plugin.testing.InjectMojo;
+import org.apache.maven.api.plugin.testing.MojoTest;
+import org.apache.maven.plugins.install.stubs.ArtifactStub;
+import org.apache.maven.plugins.install.stubs.SessionStub;
import org.apache.maven.shared.utils.io.FileUtils;
-import org.eclipse.aether.DefaultRepositorySystemSession;
-import org.eclipse.aether.internal.impl.EnhancedLocalRepositoryManagerFactory;
-import org.eclipse.aether.repository.LocalRepository;
-import org.eclipse.aether.repository.NoLocalRepositoryManagerException;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.apache.maven.api.plugin.testing.MojoExtension.getVariableValueFromObject;
+import static org.codehaus.plexus.testing.PlexusExtension.getBasedir;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doAnswer;
/**
* @author <a href="mailto:aramirez@apache.org">Allan Ramirez</a>
*/
+@MojoTest
public class InstallFileMojoTest
- extends AbstractMojoTestCase
{
- private String groupId;
+ private static final String LOCAL_REPO = "target/local-repo";
+ private String groupId;
private String artifactId;
-
private String version;
-
private String packaging;
-
private String classifier;
-
private File file;
- private final String LOCAL_REPO = "target/local-repo/";
+ @Inject
+ Session session;
+
+ @Inject
+ ArtifactManager artifactManager;
+ @Inject
+ ArtifactInstaller artifactInstaller;
+
+ @BeforeEach
public void setUp()
throws Exception
{
- super.setUp();
-
FileUtils.deleteDirectory( new File( getBasedir() + "/" + LOCAL_REPO ) );
}
- public void testInstallFileTestEnvironment()
- throws Exception
+ @Test
+ @InjectMojo( goal = "install-file", pom = "classpath:/unit/install-file/basic-test.xml")
+ public void testInstallFileTestEnvironment( InstallFileMojo mojo )
{
- File testPom = new File( getBasedir(), "target/test-classes/unit/install-file-basic-test/plugin-config.xml" );
-
- InstallFileMojo mojo = (InstallFileMojo) lookupMojo( "install-file", testPom );
-
- setVariableValueToObject( mojo, "session", createMavenSession() );
-
assertNotNull( mojo );
}
- public void testBasicInstallFile()
- throws Exception
+ @Test
+ @InjectMojo( goal = "install-file", pom = "classpath:/unit/install-file/basic-test.xml")
+ public void testBasicInstallFile( InstallFileMojo mojo )
+ throws Exception
{
- File testPom = new File( getBasedir(), "target/test-classes/unit/install-file-basic-test/plugin-config.xml" );
-
- InstallFileMojo mojo = (InstallFileMojo) lookupMojo( "install-file", testPom );
-
assertNotNull( mojo );
-
- setVariableValueToObject( mojo, "session", createMavenSession() );
-
assignValuesForParameter( mojo );
-
- mojo.execute();
-
File pomFile = (File) getVariableValueFromObject( mojo, "pomFile" );
- org.codehaus.plexus.util.FileUtils.forceDelete( pomFile );
- File installedArtifact = new File( getBasedir(), LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" +
- artifactId + "-" + version + "." + packaging );
+ ArtifactInstallerRequest request = execute( mojo );
- assertTrue( installedArtifact.exists() );
-
- assertEquals( 5, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() );
+ assertNotNull( request );
+ Set<Artifact> artifacts = new HashSet<>( request.getArtifacts() );
+ Artifact pom = getArtifact( null, "pom" );
+ Artifact jar = getArtifact( null, "jar" );
+ assertEquals( new HashSet<>( Arrays.asList( pom, jar ) ), artifacts );
+ assertFileExists( artifactManager.getPath( jar ).orElse( null ) );
+ assertFileExists( artifactManager.getPath( jar ).orElse( null ) );
+ assertEquals( LOCAL_REPO, request.getSession().getLocalRepository().getPath().toString() );
}
- public void testInstallFileWithClassifier()
- throws Exception
+ @Test
+ @InjectMojo( goal = "install-file", pom = "classpath:/unit/install-file/file-absent.xml")
+ public void testFileDoesNotExists( InstallFileMojo mojo )
+ throws Exception
{
- File testPom =
- new File( getBasedir(), "target/test-classes/unit/install-file-with-classifier/plugin-config.xml" );
+ assertNotNull( mojo );
+ assignValuesForParameter( mojo );
- InstallFileMojo mojo = (InstallFileMojo) lookupMojo( "install-file", testPom );
+ assertThrows( MojoException.class, mojo::execute );
+ }
+ @Test
+ @InjectMojo( goal = "install-file", pom = "classpath:/unit/install-file/with-classifier.xml")
+ public void testInstallFileWithClassifier( InstallFileMojo mojo )
+ throws Exception
+ {
assertNotNull( mojo );
-
- setVariableValueToObject( mojo, "session", createMavenSession() );
-
assignValuesForParameter( mojo );
-
assertNotNull( classifier );
- mojo.execute();
-
- File pomFile = (File) getVariableValueFromObject( mojo, "pomFile" );
- org.codehaus.plexus.util.FileUtils.forceDelete( pomFile );
-
- File installedArtifact = new File( getBasedir(), LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" +
- artifactId + "-" + version + "-" + classifier + "." + packaging );
-
- assertTrue( installedArtifact.exists() );
-
- assertEquals( 5, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() );
+ ArtifactInstallerRequest request = execute( mojo );
+
+ assertNotNull( request );
+ Set<Artifact> artifacts = new HashSet<>( request.getArtifacts() );
+ Artifact pom = getArtifact( null, "pom" );
+ Artifact sources = getArtifact( "sources", "jar" );
+ assertEquals( new HashSet<>( Arrays.asList( pom, sources ) ), artifacts );
+ // pom file does not exists, as it should have been deleted after the installation
+ assertFileNotExists( artifactManager.getPath( pom ).get() );
+ assertFileExists( artifactManager.getPath( sources ).get() );
+ assertEquals( LOCAL_REPO, request.getSession().getLocalRepository().getPath().toString() );
}
- public void testInstallFileWithGeneratePom()
+ @Test
+ @InjectMojo( goal = "install-file", pom = "classpath:/unit/install-file/test-generatePom.xml")
+ public void testInstallFileWithGeneratePom( InstallFileMojo mojo )
throws Exception
{
- File testPom =
- new File( getBasedir(), "target/test-classes/unit/install-file-test-generatePom/plugin-config.xml" );
-
- InstallFileMojo mojo = (InstallFileMojo) lookupMojo( "install-file", testPom );
-
assertNotNull( mojo );
-
- setVariableValueToObject( mojo, "session", createMavenSession() );
-
assignValuesForParameter( mojo );
-
- mojo.execute();
-
- File installedArtifact = new File( getBasedir(), LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" +
- artifactId + "-" + version + "." + packaging );
-
assertTrue( (Boolean) getVariableValueFromObject( mojo, "generatePom" ) );
- assertTrue( installedArtifact.exists() );
-
- File installedPom = new File( getBasedir(), LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" +
- artifactId + "-" + version + "." + "pom" );
-
- try ( Reader reader = ReaderFactory.newXmlReader( installedPom ) ) {
- Model model = new MavenXpp3Reader().read( reader );
+ AtomicReference<Model> model = new AtomicReference<>();
+ ArtifactInstallerRequest request = execute( mojo, air -> model.set( readModel( getArtifact( null, "pom" ) ) ) );
+
+ assertNotNull( request );
+ Set<Artifact> artifacts = new HashSet<>( request.getArtifacts() );
+ Artifact pom = getArtifact( null, "pom" );
+ Artifact jar = getArtifact( null, "jar" );
+ assertEquals( new HashSet<>( Arrays.asList( pom, jar ) ), artifacts );
+ assertEquals( "4.0.0", model.get().getModelVersion() );
+ assertEquals( getVariableValueFromObject( mojo, "groupId" ), model.get().getGroupId() );
+ assertEquals( artifactId, model.get().getArtifactId() );
+ assertEquals( version, model.get().getVersion() );
+ assertNotNull( artifactManager.getPath( jar ).orElse( null ) );
+ assertEquals( LOCAL_REPO, request.getSession().getLocalRepository().getPath().toString() );
+ }
- assertEquals( "4.0.0", model.getModelVersion() );
-
- assertEquals( (String) getVariableValueFromObject( mojo, "groupId" ), model.getGroupId() );
-
- assertEquals( artifactId, model.getArtifactId() );
-
- assertEquals( version, model.getVersion() );
+ private Model readModel( Artifact pom )
+ {
+ try
+ {
+ Path pomPath = artifactManager.getPath( pom ).orElse( null );
+ assertNotNull( pomPath );
+ try ( InputStream is = Files.newInputStream( pomPath ) )
+ {
+ return new MavenXpp3Reader().read( is );
+ }
+ }
+ catch ( Exception e )
+ {
+ throw new IllegalStateException( e );
}
-
- assertEquals( 5, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() );
}
- public void testInstallFileWithPomFile()
+ @Test
+ @InjectMojo( goal = "install-file", pom = "classpath:/unit/install-file/with-pomFile-test.xml")
+ public void testInstallFileWithPomFile( InstallFileMojo mojo )
throws Exception
{
- File testPom =
- new File( getBasedir(), "target/test-classes/unit/install-file-with-pomFile-test/plugin-config.xml" );
-
- InstallFileMojo mojo = (InstallFileMojo) lookupMojo( "install-file", testPom );
-
assertNotNull( mojo );
-
- setVariableValueToObject( mojo, "session", createMavenSession() );
-
assignValuesForParameter( mojo );
-
- mojo.execute();
-
File pomFile = (File) getVariableValueFromObject( mojo, "pomFile" );
- assertTrue( pomFile.exists() );
+ ArtifactInstallerRequest request = execute( mojo );
- File installedArtifact = new File( getBasedir(), LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" +
- artifactId + "-" + version + "." + packaging );
-
- assertTrue( installedArtifact.exists() );
-
- File installedPom = new File( getBasedir(), LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" +
- artifactId + "-" + version + "." + "pom" );
-
- assertTrue( installedPom.exists() );
-
- assertEquals( 5, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() );
+ assertNotNull( request );
+ Set<Artifact> artifacts = new HashSet<>( request.getArtifacts() );
+ Artifact pom = getArtifact( null, "pom" );
+ Artifact jar = getArtifact( null, "jar" );
+ assertEquals( new HashSet<>( Arrays.asList( pom, jar ) ), artifacts );
+ assertEquals( pomFile.toPath(), artifactManager.getPath( pom ).orElse( null ) );
+ assertNotNull( artifactManager.getPath( jar ).orElse( null ) );
+ assertEquals( LOCAL_REPO, request.getSession().getLocalRepository().getPath().toString() );
}
- public void testInstallFileWithPomAsPackaging()
+ @Test
+ @InjectMojo( goal = "install-file", pom = "classpath:/unit/install-file/with-pom-as-packaging.xml")
+ public void testInstallFileWithPomAsPackaging( InstallFileMojo mojo )
throws Exception
{
- File testPom = new File( getBasedir(),
- "target/test-classes/unit/install-file-with-pom-as-packaging/" + "plugin-config.xml" );
-
- InstallFileMojo mojo = (InstallFileMojo) lookupMojo( "install-file", testPom );
-
assertNotNull( mojo );
-
- setVariableValueToObject( mojo, "session", createMavenSession() );
-
assignValuesForParameter( mojo );
-
assertTrue( file.exists() );
-
assertEquals( "pom", packaging );
- mojo.execute();
-
- File installedPom = new File( getBasedir(), LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" +
- artifactId + "-" + version + "." + "pom" );
-
- assertTrue( installedPom.exists() );
+ ArtifactInstallerRequest request = execute( mojo );
- assertEquals( 4, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() );
+ assertNotNull( request );
+ Set<Artifact> artifacts = new HashSet<>( request.getArtifacts() );
+ Artifact pom = getArtifact( null, "pom" );
+ assertEquals( new HashSet<>( Arrays.asList( pom ) ), artifacts );
}
- public void testInstallFile()
+ @Test
+ @InjectMojo( goal = "install-file", pom = "classpath:/unit/install-file/with-checksum.xml")
+ public void testInstallFile( InstallFileMojo mojo )
throws Exception
{
- File testPom =
- new File( getBasedir(), "target/test-classes/unit/install-file-with-checksum/" + "plugin-config.xml" );
-
- InstallFileMojo mojo = (InstallFileMojo) lookupMojo( "install-file", testPom );
-
assertNotNull( mojo );
-
- setVariableValueToObject( mojo, "session", createMavenSession() );
-
assignValuesForParameter( mojo );
- mojo.execute();
+ ArtifactInstallerRequest request = execute( mojo );
- String localPath = getBasedir() + "/" + LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" +
- artifactId + "-" + version;
-
- File installedArtifact = new File( localPath + "." + "jar" );
-
- assertTrue( installedArtifact.exists() );
-
- assertEquals( 5, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() );
+ assertNotNull( request );
+ Set<Artifact> artifacts = new HashSet<>( request.getArtifacts() );
+ Artifact pom = getArtifact( null, "pom" );
+ Artifact jar = getArtifact( null, "jar" );
+ assertEquals( new HashSet<>( Arrays.asList( pom, jar ) ), artifacts );
+ assertEquals( LOCAL_REPO, request.getSession().getLocalRepository().getPath().toString() );
}
private void assignValuesForParameter( Object obj )
throws Exception
{
- this.groupId = dotToSlashReplacer( (String) getVariableValueFromObject( obj, "groupId" ) );
-
+ this.groupId = (String) getVariableValueFromObject( obj, "groupId" );
this.artifactId = (String) getVariableValueFromObject( obj, "artifactId" );
-
this.version = (String) getVariableValueFromObject( obj, "version" );
-
this.packaging = (String) getVariableValueFromObject( obj, "packaging" );
-
this.classifier = (String) getVariableValueFromObject( obj, "classifier" );
-
this.file = (File) getVariableValueFromObject( obj, "file" );
}
- private String dotToSlashReplacer( String parameter )
+ private ArtifactStub getArtifact( String classifier, String extension )
+ {
+ return new ArtifactStub( groupId, artifactId, classifier != null ? classifier : "", version, extension );
+ }
+
+ private ArtifactInstallerRequest execute( InstallFileMojo mojo )
+ {
+ return execute( mojo, null );
+ }
+
+ private ArtifactInstallerRequest execute( InstallFileMojo mojo, Consumer<ArtifactInstallerRequest> consumer )
+ {
+ AtomicReference<ArtifactInstallerRequest> request = new AtomicReference<>();
+ doAnswer( iom -> {
+ ArtifactInstallerRequest req = iom.getArgument( 0, ArtifactInstallerRequest.class );
+ request.set( req );
+ if ( consumer != null )
+ {
+ consumer.accept( req );
+ }
+ return null;
+ } ).when( artifactInstaller ).install( any( ArtifactInstallerRequest.class) );
+ mojo.execute();
+ return request.get();
+ }
+
+ private void assertFileExists( Path path )
+ {
+ assertTrue( path != null && Files.exists( path ), () -> path + " should exists" );
+ }
+
+ private void assertFileNotExists( Path path )
+ {
+ assertFalse( path != null && Files.exists( path ), () -> path + " should not exists" );
+ }
+
+ @Provides @Singleton @SuppressWarnings( "unused" )
+ private Session createMavenSession()
+ {
+ return SessionStub.getMockSession( LOCAL_REPO );
+ }
+
+ @Provides
+ private ArtifactInstaller createArtifactInstaller( Session session )
{
- return parameter.replace( '.', '/' );
+ return session.getService( ArtifactInstaller.class );
}
- private MavenSession createMavenSession() throws NoLocalRepositoryManagerException
+ @Provides
+ private ArtifactManager createArtifactManager( Session session )
{
- MavenSession session = mock( MavenSession.class );
- DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
- repositorySession.setLocalRepositoryManager(
- new EnhancedLocalRepositoryManagerFactory().newInstance(
- repositorySession, new LocalRepository( LOCAL_REPO )
- )
- );
- ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest();
- buildingRequest.setRepositorySession( repositorySession );
- when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
- return session;
+ return session.getService( ArtifactManager.class );
}
}
diff --git a/src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java b/src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java
index 4be8436..f8bf850 100644
--- a/src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java
@@ -19,350 +19,215 @@ package org.apache.maven.plugins.install;
* under the License.
*/
+import static org.apache.maven.api.plugin.testing.MojoExtension.getVariableValueFromObject;
+import static org.apache.maven.api.plugin.testing.MojoExtension.setVariableValueToObject;
+import static org.codehaus.plexus.testing.PlexusExtension.getBasedir;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
import java.io.File;
+import java.nio.file.Paths;
+import java.util.Arrays;
import java.util.Collections;
-import java.util.List;
-
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Consumer;
+
+import com.google.inject.Inject;
+import com.google.inject.Provides;
+import com.google.inject.Singleton;
+import org.apache.maven.api.Artifact;
import org.apache.maven.api.Project;
import org.apache.maven.api.Session;
+import org.apache.maven.api.plugin.Mojo;
import org.apache.maven.api.plugin.MojoException;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.metadata.ArtifactMetadata;
-import org.apache.maven.plugin.testing.AbstractMojoTestCase;
-import org.apache.maven.plugins.install.stubs.AttachedArtifactStub0;
-import org.apache.maven.plugins.install.stubs.InstallArtifactStub;
-import org.apache.maven.project.DefaultProjectBuildingRequest;
-import org.apache.maven.project.ProjectBuildingRequest;
-import org.apache.maven.shared.utils.io.FileUtils;
-import org.eclipse.aether.DefaultRepositorySystemSession;
-import org.eclipse.aether.internal.impl.EnhancedLocalRepositoryManagerFactory;
-import org.eclipse.aether.repository.LocalRepository;
-import org.eclipse.aether.repository.NoLocalRepositoryManagerException;
+import org.apache.maven.api.services.ArtifactInstaller;
+import org.apache.maven.api.services.ArtifactInstallerRequest;
+import org.apache.maven.api.services.ArtifactManager;
+import org.apache.maven.api.services.ProjectManager;
+import org.apache.maven.api.plugin.testing.InjectMojo;
+import org.apache.maven.api.plugin.testing.MojoTest;
+import org.apache.maven.plugins.install.stubs.ArtifactStub;
+import org.apache.maven.plugins.install.stubs.SessionStub;
+import org.codehaus.plexus.util.FileUtils;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* @author <a href="mailto:aramirez@apache.org">Allan Ramirez</a>
*/
-
+@MojoTest
public class InstallMojoTest
- extends AbstractMojoTestCase
{
- InstallArtifactStub artifact;
+ private static final String LOCAL_REPO = "target/local-repo/";
- private final String LOCAL_REPO = "target/local-repo/";
+ @Inject
+ ArtifactInstaller artifactInstaller;
- public void setUp()
- throws Exception
- {
- super.setUp();
+ @Inject
+ ArtifactManager artifactManager;
- FileUtils.deleteDirectory( new File( getBasedir() + "/" + LOCAL_REPO ) );
- }
+ @Inject
+ ProjectManager projectManager;
- public void testInstallTestEnvironment()
+ @BeforeEach
+ public void setUp()
throws Exception
{
- File testPom = new File( getBasedir(), "target/test-classes/unit/basic-install-test/plugin-config.xml" );
-
- AbstractInstallMojo mojo = (AbstractInstallMojo) lookupMojo( "install", testPom );
-
- assertNotNull( mojo );
+ FileUtils.deleteDirectory( new File( getBasedir() + "/" + LOCAL_REPO ) );
}
- public void testBasicInstall()
- throws Exception
+ @Test
+ @InjectMojo( goal = "install", pom = "classpath:/unit/basic-install/test.xml" )
+ public void testInstallTestEnvironment( InstallMojo mojo )
{
- File testPom = new File( getBasedir(), "target/test-classes/unit/basic-install-test/plugin-config.xml" );
-
- AbstractInstallMojo mojo = (AbstractInstallMojo) lookupMojo( "install", testPom );
-
assertNotNull( mojo );
-
- File file = new File( getBasedir(), "target/test-classes/unit/basic-install-test/target/"
- + "maven-install-test-1.0-SNAPSHOT.jar" );
-
- Project project = (Project) getVariableValueFromObject( mojo, "project" );
- updateMavenProject( project );
-
- setVariableValueToObject( mojo, "reactorProjects", Collections.singletonList( project ) );
- setVariableValueToObject( mojo, "session", createMavenSession() );
-
- artifact = (InstallArtifactStub) project.getArtifact();
-
- artifact.setFile( file );
-
- mojo.execute();
-
- String groupId = dotToSlashReplacer( artifact.getGroupId() );
-
- File installedArtifact = new File( getBasedir(), LOCAL_REPO + groupId + "/" + artifact.getArtifactId() + "/" +
- artifact.getVersion() + "/" + artifact.getArtifactId() + "-" + artifact.getVersion() + "." + artifact.getArtifactHandler().getExtension() );
-
- assertTrue( installedArtifact.exists() );
-
- assertEquals( 5, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() );
}
- public void testBasicInstallWithAttachedArtifacts()
+ @Test
+ @InjectMojo( goal = "install", pom = "classpath:/unit/basic-install/test.xml" )
+ public void testBasicInstall( InstallMojo mojo )
throws Exception
{
- File testPom = new File( getBasedir(), "target/test-classes/unit/basic-install-test-with-attached-artifacts/"
- + "plugin-config.xml" );
-
- AbstractInstallMojo mojo = (AbstractInstallMojo) lookupMojo( "install", testPom );
-
assertNotNull( mojo );
-
Project project = (Project) getVariableValueFromObject( mojo, "project" );
- updateMavenProject( project );
-
setVariableValueToObject( mojo, "reactorProjects", Collections.singletonList( project ) );
- setVariableValueToObject( mojo, "session", createMavenSession() );
-
- List<Artifact> attachedArtifacts = project.getAttachedArtifacts();
-
- mojo.execute();
+ artifactManager.setPath( project.getArtifact(), Paths.get( getBasedir(), "target/test-classes/unit/basic-install/maven-install-test-1.0-SNAPSHOT.jar" ) );
- String packaging = project.getPackaging();
-
- String groupId;
-
- for ( Object attachedArtifact1 : attachedArtifacts )
- {
- AttachedArtifactStub0 attachedArtifact = (AttachedArtifactStub0) attachedArtifact1;
+ ArtifactInstallerRequest request = execute( mojo );
- groupId = dotToSlashReplacer( attachedArtifact.getGroupId() );
-
- File installedArtifact = new File( getBasedir(), LOCAL_REPO + groupId + "/" +
- attachedArtifact.getArtifactId() + "/" + attachedArtifact.getVersion() + "/" +
- attachedArtifact.getArtifactId() + "-" + attachedArtifact.getVersion() + "." + packaging );
-
- assertTrue( installedArtifact.getPath() + " does not exist", installedArtifact.exists() );
- }
-
- assertEquals( 13, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() );
+ assertNotNull( request );
+ Set<Artifact> artifacts = new HashSet<>( request.getArtifacts() );
+ assertEquals( new HashSet<>( Arrays.asList(
+ new ArtifactStub( "org.apache.maven.test", "maven-install-test", "", "1.0-SNAPSHOT", "jar"),
+ new ArtifactStub( "org.apache.maven.test", "maven-install-test", "", "1.0-SNAPSHOT", "pom")
+ ) ), artifacts );
}
- public void testUpdateReleaseParamSetToTrue()
+ @Test
+ @InjectMojo( goal = "install", pom = "classpath:/unit/basic-install/test.xml" )
+ public void testBasicInstallWithAttachedArtifacts( InstallMojo mojo )
throws Exception
{
- File testPom = new File( getBasedir(), "target/test-classes/unit/configured-install-test/plugin-config.xml" );
-
- AbstractInstallMojo mojo = (AbstractInstallMojo) lookupMojo( "install", testPom );
-
assertNotNull( mojo );
-
- File file = new File( getBasedir(), "target/test-classes/unit/configured-install-test/target/"
- + "maven-install-test-1.0-SNAPSHOT.jar" );
-
Project project = (Project) getVariableValueFromObject( mojo, "project" );
- updateMavenProject( project );
-
setVariableValueToObject( mojo, "reactorProjects", Collections.singletonList( project ) );
- setVariableValueToObject( mojo, "session", createMavenSession() );
-
- artifact = (InstallArtifactStub) project.getArtifact();
-
- artifact.setFile( file );
-
- mojo.execute();
-
-// assertTrue( artifact.isRelease() );
-
- assertEquals( 5, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() );
+ projectManager.attachArtifact( project,
+ new ArtifactStub( "org.apache.maven.test", "attached-artifact-test", "", "1.0-SNAPSHOT", "jar" ),
+ Paths.get( getBasedir(), "target/test-classes/unit/basic-install/attached-artifact-test-1.0-SNAPASHOT.jar" ) );
+ artifactManager.setPath( project.getArtifact(), Paths.get( getBasedir(), "target/test-classes/unit/basic-install/maven-install-test-1.0-SNAPSHOT.jar" ) );
+
+ ArtifactInstallerRequest request = execute( mojo );
+
+ assertNotNull( request );
+ Set<Artifact> artifacts = new HashSet<>( request.getArtifacts() );
+ assertEquals( new HashSet<>( Arrays.asList(
+ new ArtifactStub( "org.apache.maven.test", "maven-install-test", "", "1.0-SNAPSHOT", "jar"),
+ new ArtifactStub( "org.apache.maven.test", "maven-install-test", "", "1.0-SNAPSHOT", "pom"),
+ new ArtifactStub( "org.apache.maven.test", "attached-artifact-test", "", "1.0-SNAPSHOT", "jar")
+ ) ), artifacts );
}
- public void testInstallIfArtifactFileIsNull()
+ @Test
+ @InjectMojo( goal = "install", pom = "classpath:/unit/basic-install/test.xml" )
+ public void testInstallIfArtifactFileIsNull( InstallMojo mojo )
throws Exception
{
- File testPom = new File( getBasedir(), "target/test-classes/unit/basic-install-test/plugin-config.xml" );
-
- AbstractInstallMojo mojo = (AbstractInstallMojo) lookupMojo( "install", testPom );
-
assertNotNull( mojo );
-
Project project = (Project) getVariableValueFromObject( mojo, "project" );
- updateMavenProject( project );
-
setVariableValueToObject( mojo, "reactorProjects", Collections.singletonList( project ) );
- setVariableValueToObject( mojo, "session", createMavenSession() );
-
- artifact = (InstallArtifactStub) project.getArtifact();
-
- artifact.setFile( null );
-
- assertNull( artifact.getFile() );
+ assertFalse( artifactManager.getPath( project.getArtifact() ).isPresent() );
- try
- {
- mojo.execute();
-
- fail( "Did not throw mojo execution exception" );
- }
- catch ( MojoException e )
- {
- //expected
- }
-
- assertFalse( new File( LOCAL_REPO ).exists() );
+ assertThrows( MojoException.class, mojo::execute, "Did not throw mojo execution exception" );
}
- public void testInstallIfPackagingIsPom()
+ @Test
+ @InjectMojo( goal = "install", pom = "classpath:/unit/basic-install/packaging-pom.xml" )
+ public void testInstallIfPackagingIsPom( InstallMojo mojo )
throws Exception
{
- File testPom = new File( getBasedir(),
- "target/test-classes/unit/basic-install-test-packaging-pom/" + "plugin-config.xml" );
-
- AbstractInstallMojo mojo = (AbstractInstallMojo) lookupMojo( "install", testPom );
-
assertNotNull( mojo );
-
Project project = (Project) getVariableValueFromObject( mojo, "project" );
- updateMavenProject( project );
-
setVariableValueToObject( mojo, "reactorProjects", Collections.singletonList( project ) );
- setVariableValueToObject( mojo, "session", createMavenSession() );
-
String packaging = project.getPackaging();
-
assertEquals( "pom", packaging );
+ artifactManager.setPath( project.getArtifact(), project.getPomPath() );
- artifact = (InstallArtifactStub) project.getArtifact();
-
- mojo.execute();
+ ArtifactInstallerRequest request = execute( mojo );
- String groupId = dotToSlashReplacer( artifact.getGroupId() );
-
- File installedArtifact = new File( getBasedir(), LOCAL_REPO + groupId + "/" + artifact.getArtifactId() + "/" +
- artifact.getVersion() + "/" + artifact.getArtifactId() + "-" + artifact.getVersion() + "." + "pom" );
-
- assertTrue( installedArtifact.exists() );
-
- assertEquals( 4, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() );
+ assertNotNull( request );
+ Set<Artifact> artifacts = new HashSet<>( request.getArtifacts() );
+ assertEquals( new HashSet<>( Arrays.asList(
+ new ArtifactStub( "org.apache.maven.test", "maven-install-test", "", "1.0-SNAPSHOT", "pom")
+ ) ), artifacts );
}
- public void testBasicInstallAndCreate()
- throws Exception
+ @Test
+ @InjectMojo( goal = "install", pom = "classpath:/unit/basic-install/test.xml" )
+ public void testSkip( InstallMojo mojo ) throws Exception
{
- File testPom = new File( getBasedir(), "target/test-classes/unit/basic-install-checksum/plugin-config.xml" );
-
- AbstractInstallMojo mojo = (AbstractInstallMojo) lookupMojo( "install", testPom );
-
assertNotNull( mojo );
-
- File file = new File( getBasedir(), "target/test-classes/unit/basic-install-checksum/" + "maven-test-jar.jar" );
-
Project project = (Project) getVariableValueFromObject( mojo, "project" );
- Session mavenSession = createMavenSession();
- updateMavenProject( project );
-
setVariableValueToObject( mojo, "reactorProjects", Collections.singletonList( project ) );
- setVariableValueToObject( mojo, "session", mavenSession );
-
- artifact = (InstallArtifactStub) project.getArtifact();
-
- artifact.setFile( file );
-
- mojo.execute();
-
- ArtifactMetadata metadata = null;
- for ( Object o : artifact.getMetadataList() )
- {
- metadata = (ArtifactMetadata) o;
- if ( metadata.getRemoteFilename().endsWith( "pom" ) )
- {
- break;
- }
- }
-
- RepositoryManager repoManager = (RepositoryManager) getVariableValueFromObject( mojo, "repositoryManager" );
-
- ProjectBuildingRequest pbr = mavenSession.getProjectBuildingRequest();
-
- File pom = new File( repoManager.getLocalRepositoryBasedir( pbr ),
- repoManager.getPathForLocalMetadata( pbr, metadata ) );
-
- assertTrue( pom.exists() );
+ mojo.setSkip( true );
- String groupId = dotToSlashReplacer( artifact.getGroupId() );
- String packaging = project.getPackaging();
- String localPath = getBasedir() + "/" + LOCAL_REPO + groupId + "/" + artifact.getArtifactId() + "/" +
- artifact.getVersion() + "/" + artifact.getArtifactId() + "-" + artifact.getVersion();
-
+ assertNull( execute( mojo ) );
+ }
- File installedArtifact = new File( localPath + "." + packaging );
- assertTrue( installedArtifact.exists() );
-
- assertEquals( 5, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() );
+ @Provides @Singleton @SuppressWarnings( "unused" )
+ private Session createSession()
+ {
+ return SessionStub.getMockSession( LOCAL_REPO );
}
- public void testSkip()
- throws Exception
+ @Provides @SuppressWarnings( "unused" )
+ private ArtifactInstaller createArtifactInstaller( Session session )
{
- File testPom = new File( getBasedir(), "target/test-classes/unit/basic-install-test/plugin-config.xml" );
-
- InstallMojo mojo = (InstallMojo) lookupMojo( "install", testPom );
-
- assertNotNull( mojo );
-
- File file = new File( getBasedir(), "target/test-classes/unit/basic-install-test/target/"
- + "maven-install-test-1.0-SNAPSHOT.jar" );
-
- Project project = (Project) getVariableValueFromObject( mojo, "project" );
- updateMavenProject( project );
-
- setVariableValueToObject( mojo, "reactorProjects", Collections.singletonList( project ) );
- setVariableValueToObject( mojo, "session", createMavenSession() );
-
- artifact = (InstallArtifactStub) project.getArtifact();
-
- artifact.setFile( file );
-
- mojo.setSkip( true );
-
- mojo.execute();
-
- String groupId = dotToSlashReplacer( artifact.getGroupId() );
-
- String packaging = project.getPackaging();
-
- File installedArtifact = new File( getBasedir(), LOCAL_REPO + groupId + "/" + artifact.getArtifactId() + "/" +
- artifact.getVersion() + "/" + artifact.getArtifactId() + "-" + artifact.getVersion() + "." + packaging );
-
- assertFalse( installedArtifact.exists() );
-
- assertFalse( new File( LOCAL_REPO ).exists() );
+ return session.getService( ArtifactInstaller.class );
}
+ @Provides @SuppressWarnings( "unused" )
+ private ArtifactManager createArtifactManager( Session session )
+ {
+ return session.getService( ArtifactManager.class );
+ }
- private String dotToSlashReplacer( String parameter )
+ @Provides @SuppressWarnings( "unused" )
+ private ProjectManager createProjectManager( Session session )
{
- return parameter.replace( '.', '/' );
+ return session.getService( ProjectManager.class );
}
-
- private Session createMavenSession() throws NoLocalRepositoryManagerException
+
+ private <T> ArtifactInstallerRequest execute( Mojo mojo )
{
- Session session = mock( Session.class );
- DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
- repositorySession.setLocalRepositoryManager(
- new EnhancedLocalRepositoryManagerFactory().newInstance(
- repositorySession, new LocalRepository( LOCAL_REPO )
- )
- );
- ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest();
- buildingRequest.setRepositorySession( repositorySession );
- when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
- return session;
+ return execute( mojo, null );
}
-
- private void updateMavenProject( Project project )
+
+ private ArtifactInstallerRequest execute( Mojo mojo, Consumer<ArtifactInstallerRequest> consumer )
{
- project.setGroupId( project.getArtifact().getGroupId() );
- project.setArtifactId( project.getArtifact().getArtifactId() );
- project.setVersion( project.getArtifact().getVersion() );
+ AtomicReference<ArtifactInstallerRequest> request = new AtomicReference<>();
+ doAnswer( iom ->
+ {
+ ArtifactInstallerRequest req = iom.getArgument( 0, ArtifactInstallerRequest.class );
+ request.set( req );
+ if ( consumer != null )
+ {
+ consumer.accept( req );
+ }
+ return null;
+ } ).when( artifactInstaller ).install( any( ArtifactInstallerRequest.class) );
+ mojo.execute();
+ return request.get();
}
+
}
diff --git a/src/test/java/org/apache/maven/plugins/install/stubs/ArtifactStub.java b/src/test/java/org/apache/maven/plugins/install/stubs/ArtifactStub.java
new file mode 100644
index 0000000..33cad59
--- /dev/null
+++ b/src/test/java/org/apache/maven/plugins/install/stubs/ArtifactStub.java
@@ -0,0 +1,178 @@
+package org.apache.maven.plugins.install.stubs;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import javax.annotation.Nonnull;
+
+import java.nio.file.Path;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.regex.Pattern;
+
+import org.apache.maven.api.Artifact;
+
+public class ArtifactStub implements Artifact
+{
+ private static final String SNAPSHOT = "SNAPSHOT";
+
+ private static final Pattern SNAPSHOT_TIMESTAMP = Pattern.compile( "^(.*-)?([0-9]{8}\\.[0-9]{6}-[0-9]+)$" );
+
+ private String groupId;
+ private String artifactId;
+ private String classifier = "";
+ private String version;
+ private String extension;
+ private Path path;
+
+ public ArtifactStub()
+ {
+ }
+
+ public ArtifactStub( String groupId, String artifactId, String classifier, String version, String extension )
+ {
+ this.groupId = groupId;
+ this.artifactId = artifactId;
+ this.classifier = classifier;
+ this.version = version;
+ this.extension = extension;
+ }
+
+ @Nonnull
+ @Override
+ public String getGroupId()
+ {
+ return groupId;
+ }
+
+ public void setGroupId( String groupId )
+ {
+ this.groupId = groupId;
+ }
+
+ @Nonnull
+ @Override
+ public String getArtifactId()
+ {
+ return artifactId;
+ }
+
+ public void setArtifactId( String artifactId )
+ {
+ this.artifactId = artifactId;
+ }
+
+ @Nonnull
+ @Override
+ public String getClassifier()
+ {
+ return classifier;
+ }
+
+ public void setClassifier( String classifier )
+ {
+ this.classifier = classifier;
+ }
+
+ @Nonnull
+ @Override
+ public String getVersion()
+ {
+ return version;
+ }
+
+ public void setVersion( String version )
+ {
+ this.version = version;
+ }
+
+ @Nonnull
+ @Override
+ public String getExtension()
+ {
+ return extension;
+ }
+
+ public void setExtension( String extension )
+ {
+ this.extension = extension;
+ }
+
+ @Nonnull
+ @Override
+ public String getBaseVersion()
+ {
+ return version;
+ }
+
+ @Nonnull
+ @Override
+ public Optional<Path> getPath()
+ {
+ return Optional.ofNullable( path );
+ }
+
+ public void setPath( Path path )
+ {
+ this.path = path;
+ }
+
+ @Override
+ public boolean isSnapshot()
+ {
+ return version.endsWith( SNAPSHOT ) || SNAPSHOT_TIMESTAMP.matcher( version ).matches();
+ }
+
+ @Override
+ public boolean equals( Object o )
+ {
+ if ( this == o )
+ {
+ return true;
+ }
+ if ( o == null || getClass() != o.getClass() )
+ {
+ return false;
+ }
+ ArtifactStub that = (ArtifactStub) o;
+ return Objects.equals( groupId, that.groupId ) && Objects.equals( artifactId, that.artifactId )
+ && Objects.equals( classifier, that.classifier ) && Objects.equals( version,
+ that.version ) && Objects.equals( extension, that.extension ) &&
+ Objects.equals( path, that.path );
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return Objects.hash( groupId, artifactId, classifier, version, extension, path );
+ }
+
+ @Override
+ public String toString()
+ {
+ return "ArtifactStub{" +
+ "groupId='" + groupId + '\'' +
+ ", artifactId='" + artifactId + '\'' +
+ ", classifier='" + classifier + '\'' +
+ ", version='" + version + '\'' +
+ ", extension='" + extension + '\'' +
+ ", path=" + path +
+ '}';
+ }
+}
diff --git a/src/test/java/org/apache/maven/plugins/install/stubs/AttachedArtifactStub0.java b/src/test/java/org/apache/maven/plugins/install/stubs/AttachedArtifactStub0.java
deleted file mode 100644
index 05a6c92..0000000
--- a/src/test/java/org/apache/maven/plugins/install/stubs/AttachedArtifactStub0.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package org.apache.maven.plugins.install.stubs;
-
-import java.io.File;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-public class AttachedArtifactStub0
- extends InstallArtifactStub
-{
- public String getArtifactId()
- {
- return "attached-artifact-test-0";
- }
-
- public File getFile()
- {
- return new File( System.getProperty( "basedir" ),
- "target/test-classes/unit/basic-install-test-with-attached-artifacts/"
- + "target/maven-install-test-1.0-SNAPSHOT.jar" );
- }
-}
diff --git a/src/test/java/org/apache/maven/plugins/install/stubs/AttachedArtifactStub1.java b/src/test/java/org/apache/maven/plugins/install/stubs/AttachedArtifactStub1.java
deleted file mode 100644
index 5a84353..0000000
--- a/src/test/java/org/apache/maven/plugins/install/stubs/AttachedArtifactStub1.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package org.apache.maven.plugins.install.stubs;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-public class AttachedArtifactStub1
- extends AttachedArtifactStub0
-{
- public String getArtifactId()
- {
- return "attached-artifact-test-1";
- }
-}
diff --git a/src/test/java/org/apache/maven/plugins/install/stubs/InstallArtifactStub.java b/src/test/java/org/apache/maven/plugins/install/stubs/InstallArtifactStub.java
deleted file mode 100644
index 0e252da..0000000
--- a/src/test/java/org/apache/maven/plugins/install/stubs/InstallArtifactStub.java
+++ /dev/null
@@ -1,121 +0,0 @@
-package org.apache.maven.plugins.install.stubs;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.maven.artifact.handler.ArtifactHandler;
-import org.apache.maven.artifact.handler.DefaultArtifactHandler;
-import org.apache.maven.artifact.metadata.ArtifactMetadata;
-import org.apache.maven.plugin.testing.stubs.ArtifactStub;
-
-import java.io.File;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-
-public class InstallArtifactStub
- extends ArtifactStub
-{
- private Map<Object, ArtifactMetadata> metadataMap;
-
- private File file;
-
- private boolean release;
-
- public String getArtifactId()
- {
- return "maven-install-test";
- }
-
- public String getGroupId()
- {
- return "org.apache.maven.test";
- }
-
- public String getVersion()
- {
- return "1.0-SNAPSHOT";
- }
-
- public String getBaseVersion()
- {
- return getVersion();
- }
-
- public void setFile( File file )
- {
- this.file = file;
- }
-
- public File getFile()
- {
- return file;
- }
-
- public String getType()
- {
- return "jar";
- }
-
- public ArtifactHandler getArtifactHandler()
- {
- return new DefaultArtifactHandler()
- {
- public String getExtension()
- {
- return "jar";
- }
- };
- }
-
- public void addMetadata( ArtifactMetadata metadata )
- {
- if ( metadataMap == null )
- {
- metadataMap = new HashMap<Object, ArtifactMetadata>();
- }
-
- ArtifactMetadata m = metadataMap.get( metadata.getKey() );
- if ( m != null )
- {
- m.merge( metadata );
- }
- else
- {
- metadataMap.put( metadata.getKey(), metadata );
- }
- }
-
- public Collection getMetadataList()
- {
- return metadataMap == null ? Collections.EMPTY_LIST : metadataMap.values();
- }
-
- public boolean isRelease()
- {
- return release;
- }
-
- public void setRelease( boolean release )
- {
- this.release = release;
- }
-}
diff --git a/src/test/java/org/apache/maven/plugins/install/stubs/ProjectStub.java b/src/test/java/org/apache/maven/plugins/install/stubs/ProjectStub.java
new file mode 100644
index 0000000..ab9fa21
--- /dev/null
+++ b/src/test/java/org/apache/maven/plugins/install/stubs/ProjectStub.java
@@ -0,0 +1,152 @@
+package org.apache.maven.plugins.install.stubs;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import javax.annotation.Nonnull;
+
+import java.io.File;
+import java.nio.file.Path;
+import java.util.List;
+
+import org.apache.maven.api.Artifact;
+import org.apache.maven.api.Dependency;
+import org.apache.maven.api.Project;
+import org.apache.maven.model.Model;
+
+public class ProjectStub implements Project
+{
+ private String groupId;
+ private String artifactId;
+ private String version;
+ private String packaging;
+ private Artifact artifact;
+ private Model model;
+ private File pomPath;
+ private boolean executionRoot;
+
+ @Nonnull
+ @Override
+ public String getGroupId()
+ {
+ return groupId;
+ }
+
+ @Nonnull
+ @Override
+ public String getArtifactId()
+ {
+ return artifactId;
+ }
+
+ @Nonnull
+ @Override
+ public String getVersion()
+ {
+ return version;
+ }
+
+ @Nonnull
+ @Override
+ public String getPackaging()
+ {
+ return packaging;
+ }
+
+ @Nonnull
+ @Override
+ public Artifact getArtifact()
+ {
+ return artifact;
+ }
+
+ @Nonnull
+ @Override
+ public Model getModel()
+ {
+ return model;
+ }
+
+ @Nonnull
+ @Override
+ public Path getPomPath()
+ {
+ return pomPath.toPath();
+ }
+
+ @Nonnull
+ @Override
+ public List<Dependency> getDependencies()
+ {
+ return null;
+ }
+
+ @Nonnull
+ @Override
+ public List<Dependency> getManagedDependencies()
+ {
+ return null;
+ }
+
+ @Override
+ public boolean isExecutionRoot()
+ {
+ return executionRoot;
+ }
+
+ public void setGroupId( String groupId )
+ {
+ this.groupId = groupId;
+ }
+
+ public void setArtifactId( String artifactId )
+ {
+ this.artifactId = artifactId;
+ }
+
+ public void setVersion( String version )
+ {
+ this.version = version;
+ }
+
+ public void setPackaging( String packaging )
+ {
+ this.packaging = packaging;
+ }
+
+ public void setArtifact( Artifact artifact )
+ {
+ this.artifact = artifact;
+ }
+
+ public void setModel( Model model )
+ {
+ this.model = model;
+ }
+
+ public void setPomPath( File pomPath )
+ {
+ this.pomPath = pomPath;
+ }
+
+ public void setExecutionRoot( boolean executionRoot )
+ {
+ this.executionRoot = executionRoot;
+ }
+}
diff --git a/src/test/java/org/apache/maven/plugins/install/stubs/SessionStub.java b/src/test/java/org/apache/maven/plugins/install/stubs/SessionStub.java
new file mode 100644
index 0000000..08245d5
--- /dev/null
+++ b/src/test/java/org/apache/maven/plugins/install/stubs/SessionStub.java
@@ -0,0 +1,217 @@
+package org.apache.maven.plugins.install.stubs;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.net.URI;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+import org.apache.maven.api.Artifact;
+import org.apache.maven.api.LocalRepository;
+import org.apache.maven.api.Project;
+import org.apache.maven.api.RemoteRepository;
+import org.apache.maven.api.Session;
+import org.apache.maven.api.services.ArtifactDeployer;
+import org.apache.maven.api.services.ArtifactDeployerRequest;
+import org.apache.maven.api.services.ArtifactFactory;
+import org.apache.maven.api.services.ArtifactFactoryRequest;
+import org.apache.maven.api.services.ArtifactInstaller;
+import org.apache.maven.api.services.ArtifactInstallerRequest;
+import org.apache.maven.api.services.ArtifactManager;
+import org.apache.maven.api.services.LocalRepositoryManager;
+import org.apache.maven.api.services.ProjectBuilder;
+import org.apache.maven.api.services.ProjectBuilderRequest;
+import org.apache.maven.api.services.ProjectBuilderResult;
+import org.apache.maven.api.services.ProjectManager;
+import org.apache.maven.api.services.RepositoryFactory;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Repository;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.mockito.ArgumentMatchers;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.same;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.withSettings;
+
+public class SessionStub
+{
+
+ public static Session getMockSession( String localRepo )
+ {
+ Session session = mock( Session.class );
+
+ RepositoryFactory repositoryFactory = mock( RepositoryFactory.class );
+ when( repositoryFactory.createRemote( any( Repository.class ) ) )
+ .thenAnswer( iom -> {
+ Repository repository = iom.getArgument( 0, Repository.class );
+ return repositoryFactory.createRemote( repository.getId(), repository.getUrl() );
+ } );
+ when( repositoryFactory.createRemote( anyString(), anyString() ) )
+ .thenAnswer( iom -> {
+ String id = iom.getArgument( 0, String.class );
+ String url = iom.getArgument( 1, String.class );
+ RemoteRepository remoteRepository = mock( RemoteRepository.class, withSettings().lenient() );
+ when( remoteRepository.getId() ).thenReturn( id );
+ when( remoteRepository.getUrl() ).thenReturn( url );
+ when( remoteRepository.getProtocol() ).thenReturn( URI.create( url ).getScheme() );
+ return remoteRepository;
+ } );
+
+ LocalRepositoryManager localRepositoryManager = mock( LocalRepositoryManager.class );
+ when( localRepositoryManager.getPathForLocalArtifact( any(), any(), any() ) )
+ .thenAnswer( iom -> {
+ LocalRepository localRepository = iom.getArgument( 1, LocalRepository.class );
+ Artifact artifact = iom.getArgument( 2, Artifact.class );
+ return localRepository.getPath().resolve( getPathForArtifact( artifact, true ) );
+ } );
+
+ ArtifactInstaller artifactInstaller = mock( ArtifactInstaller.class );
+ doAnswer( iom -> {
+ artifactInstaller.install( ArtifactInstallerRequest.build(
+ iom.getArgument( 0, Session.class ),
+ iom.getArgument( 1, Collection.class ) ) );
+ return null;
+ } ).when( artifactInstaller ).install( any( Session.class ), ArgumentMatchers.<Collection<Artifact>>any() );
+
+ ArtifactDeployer artifactDeployer = mock( ArtifactDeployer.class );
+ doAnswer( iom -> {
+ artifactDeployer.deploy( ArtifactDeployerRequest.build(
+ iom.getArgument( 0, Session.class ),
+ iom.getArgument( 1, RemoteRepository.class ),
+ iom.getArgument( 2, Collection.class ) ) );
+ return null;
+ } ).when( artifactDeployer ).deploy( any(), any(), any() );
+
+ ArtifactManager artifactManager = mock( ArtifactManager.class );
+ Map<Artifact, Path> paths = new HashMap<>();
+ doAnswer( iom -> { paths.put( iom.getArgument( 0 ), iom.getArgument( 1 ) ); return null; } )
+ .when( artifactManager ).setPath( any(), any() );
+ doAnswer( iom -> Optional.ofNullable( paths.get( iom.getArgument( 0, Artifact.class ) ) ) )
+ .when( artifactManager ).getPath( any() );
+
+ LocalRepository localRepository = mock( LocalRepository.class );
+ when( localRepository.getId() ).thenReturn( "local" );
+ when( localRepository.getPath() ).thenReturn( Paths.get( localRepo ) );
+
+ ProjectManager projectManager = mock( ProjectManager.class );
+ Map<Project, Collection<Artifact>> attachedArtifacts = new HashMap<>();
+ doAnswer( iom -> {
+ Project project = iom.getArgument( 1, Project.class );
+ String type = iom.getArgument( 2, String.class );
+ String classifier = iom.getArgument( 3, String.class );
+ Path path = iom.getArgument( 4, Path.class );
+ Artifact artifact = session.createArtifact( project.getGroupId(), project.getArtifactId(), classifier, project.getVersion(), type );
+ artifactManager.setPath( artifact, path );
+ attachedArtifacts.computeIfAbsent( project, p -> new ArrayList<>() )
+ .add( artifact );
+ return null;
+ } ).when( projectManager ).attachArtifact( same( session ), any( Project.class ), any(), any(), any() );
+ doAnswer( iom -> {
+ Project project = iom.getArgument( 0, Project.class );
+ Artifact artifact = iom.getArgument( 1, Artifact.class );
+ Path path = iom.getArgument( 2, Path.class );
+ artifactManager.setPath( artifact, path );
+ attachedArtifacts.computeIfAbsent( project, p -> new ArrayList<>() )
+ .add( artifact );
+ return null;
+ } ).when( projectManager ).attachArtifact( any( Project.class ), any( Artifact.class ), any( Path.class ) );
+ when( projectManager.getAttachedArtifacts( any() ) )
+ .then( iom -> attachedArtifacts.computeIfAbsent( iom.getArgument( 0, Project.class ), p -> new ArrayList<>() ) );
+
+ ArtifactFactory artifactFactory = mock( ArtifactFactory.class );
+ when( artifactFactory.create( any() ) )
+ .then( iom -> {
+ ArtifactFactoryRequest request = iom.getArgument( 0, ArtifactFactoryRequest.class );
+ return new ArtifactStub( request.getGroupId(), request.getArtifactId(),
+ request.getClassifier() != null ? request.getClassifier() : "",
+ request.getVersion(), request.getType() );
+ } );
+
+ ProjectBuilder projectBuilder = mock( ProjectBuilder.class );
+ when( projectBuilder.build( any( ProjectBuilderRequest.class ) ) ).then( iom -> {
+ ProjectBuilderRequest request = iom.getArgument( 0, ProjectBuilderRequest.class );
+ ProjectBuilderResult result = mock( ProjectBuilderResult.class );
+ Model model = new MavenXpp3Reader().read( request.getSource().get().getInputStream() );
+ ProjectStub projectStub = new ProjectStub();
+ projectStub.setModel( model );
+ projectStub.setGroupId( model.getGroupId() );
+ projectStub.setArtifactId( model.getArtifactId() );
+ projectStub.setVersion( model.getVersion() );
+ projectStub.setPackaging( model.getPackaging() );
+ ArtifactStub artifactStub = new ArtifactStub( model.getGroupId(), model.getArtifactId(), "", model.getVersion(), model.getPackaging() );
+ projectStub.setArtifact( artifactStub );
+ when( result.getProject() ).thenReturn( Optional.of( projectStub ) );
+ return result;
+ } );
+
+ when( session.getLocalRepository() ).thenReturn( localRepository );
+ when( session.getService( RepositoryFactory.class ) ).thenReturn( repositoryFactory );
+ when( session.getService( ProjectBuilder.class ) ).thenReturn( projectBuilder );
+ when( session.getService( LocalRepositoryManager.class ) ).thenReturn( localRepositoryManager );
+ when( session.getService( ProjectManager.class ) ).thenReturn( projectManager );
+ when( session.getService( ArtifactManager.class ) ).thenReturn( artifactManager );
+ when( session.getService( ArtifactInstaller.class ) ).thenReturn( artifactInstaller );
+ when( session.getService( ArtifactDeployer.class ) ).thenReturn( artifactDeployer );
+ when( session.getService( ArtifactFactory.class ) ).thenReturn( artifactFactory );
+
+ when( session.getPathForLocalArtifact( any( Artifact.class ) ) )
+ .then( iom -> localRepositoryManager.getPathForLocalArtifact( session, session.getLocalRepository(), iom.getArgument( 0, Artifact.class ) ) );
+ when( session.createArtifact( any(), any(), any(), any(), any() ) )
+ .thenAnswer( iom ->
+ session.getService( ArtifactFactory.class ).create( ArtifactFactoryRequest.builder()
+ .session( session )
+ .groupId( iom.getArgument( 0, String.class ) )
+ .artifactId( iom.getArgument( 1, String.class ) )
+ .classifier( iom.getArgument( 2, String.class ) )
+ .version( iom.getArgument( 3, String.class ) )
+ .type( iom.getArgument( 4, String.class ) )
+ .build() ) );
+ return session;
+ }
+
+ static String getPathForArtifact( Artifact artifact, boolean local )
+ {
+ StringBuilder path = new StringBuilder( 128 );
+ path.append( artifact.getGroupId().replace( '.', '/' ) ).append( '/' );
+ path.append( artifact.getArtifactId() ).append( '/' );
+ path.append( artifact.getBaseVersion() ).append( '/' );
+ path.append( artifact.getArtifactId() ).append( '-' );
+ path.append( local ? artifact.getBaseVersion() : artifact.getVersion() );
+ if ( artifact.getClassifier().length() > 0 )
+ {
+ path.append( '-' ).append( artifact.getClassifier() );
+ }
+ if ( artifact.getExtension().length() > 0 )
+ {
+ path.append( '.' ).append( artifact.getExtension() );
+ }
+ return path.toString();
+ }
+
+}
diff --git a/src/test/resources/unit/basic-install-checksum/maven-test-jar.jar b/src/test/resources/unit/basic-install-checksum/maven-test-jar.jar
deleted file mode 100644
index 5be5453..0000000
--- a/src/test/resources/unit/basic-install-checksum/maven-test-jar.jar
+++ /dev/null
@@ -1 +0,0 @@
-this is just a test jar
\ No newline at end of file
diff --git a/src/test/resources/unit/basic-install-checksum/plugin-config.xml b/src/test/resources/unit/basic-install-checksum/plugin-config.xml
deleted file mode 100644
index 6b4b56c..0000000
--- a/src/test/resources/unit/basic-install-checksum/plugin-config.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-<!--
-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>
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-install-plugin</artifactId>
- <configuration>
- <project implementation="org.apache.maven.plugin.testing.stubs.MavenProjectStub">
- <file>${basedir}/src/test/resources/unit/basic-install-checksum/plugin-config.xml</file>
- <packaging>jar</packaging>
- <artifact implementation="org.apache.maven.plugins.install.stubs.InstallArtifactStub"/>
- <attachedArtifacts/>
- </project>
- </configuration>
- </plugin>
- </plugins>
- </build>
-</project>
diff --git a/src/test/resources/unit/basic-install-test-with-attached-artifacts/plugin-config.xml b/src/test/resources/unit/basic-install-test-with-attached-artifacts/plugin-config.xml
deleted file mode 100644
index 30113ec..0000000
--- a/src/test/resources/unit/basic-install-test-with-attached-artifacts/plugin-config.xml
+++ /dev/null
@@ -1,42 +0,0 @@
-<!--
-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>
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-install-plugin</artifactId>
- <configuration>
- <project implementation="org.apache.maven.plugin.testing.stubs.MavenProjectStub">
- <file>${basedir}/src/test/resources/unit/basic-install-test-with-attached-artifacts/plugin-config.xml</file>
- <packaging>jar</packaging>
- <artifact implementation="org.apache.maven.plugins.install.stubs.InstallArtifactStub">
- <file>${basedir}/src/test/resources/unit/basic-install-test-with-attached-artifacts/plugin-config.xml</file>
- </artifact>
- <attachedArtifacts>
- <attachedArtifact
- implementation="org.apache.maven.plugins.install.stubs.AttachedArtifactStub0"/>
- <attachedArtifact
- implementation="org.apache.maven.plugins.install.stubs.AttachedArtifactStub1"/>
- </attachedArtifacts>
- </project>
- </configuration>
- </plugin>
- </plugins>
- </build>
-</project>
diff --git a/src/test/resources/unit/basic-install-test-with-attached-artifacts/target/maven-install-test-1.0-SNAPSHOT.jar b/src/test/resources/unit/basic-install-test-with-attached-artifacts/target/maven-install-test-1.0-SNAPSHOT.jar
deleted file mode 100644
index 4a0e834..0000000
Binary files a/src/test/resources/unit/basic-install-test-with-attached-artifacts/target/maven-install-test-1.0-SNAPSHOT.jar and /dev/null differ
diff --git a/src/test/resources/unit/basic-install-test/plugin-config.xml b/src/test/resources/unit/basic-install-test/plugin-config.xml
deleted file mode 100644
index c95dccc..0000000
--- a/src/test/resources/unit/basic-install-test/plugin-config.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-<!--
-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>
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-install-plugin</artifactId>
- <configuration>
- <project implementation="org.apache.maven.plugin.testing.stubs.MavenProjectStub">
- <file>${basedir}/src/test/resources/unit/basic-install-test/plugin-config.xml</file>
- <packaging>jar</packaging>
- <artifact implementation="org.apache.maven.plugins.install.stubs.InstallArtifactStub"/>
- <attachedArtifacts/>
- </project>
- </configuration>
- </plugin>
- </plugins>
- </build>
-</project>
diff --git a/src/test/resources/unit/basic-install-test/target/maven-install-test-1.0-SNAPSHOT.jar b/src/test/resources/unit/basic-install-test/target/maven-install-test-1.0-SNAPSHOT.jar
deleted file mode 100644
index 4a0e834..0000000
Binary files a/src/test/resources/unit/basic-install-test/target/maven-install-test-1.0-SNAPSHOT.jar and /dev/null differ
diff --git a/src/test/resources/unit/basic-install/attached-artifact-test-1.0-SNAPSHOT.jar b/src/test/resources/unit/basic-install/attached-artifact-test-1.0-SNAPSHOT.jar
new file mode 100644
index 0000000..6f5f2f8
--- /dev/null
+++ b/src/test/resources/unit/basic-install/attached-artifact-test-1.0-SNAPSHOT.jar
@@ -0,0 +1 @@
+This is not an actual jar
\ No newline at end of file
diff --git a/src/test/resources/unit/install-file-with-pomFile-test/target/maven-install-test-1.0-SNAPSHOT.jar b/src/test/resources/unit/basic-install/maven-install-test-1.0-SNAPSHOT.jar
similarity index 100%
rename from src/test/resources/unit/install-file-with-pomFile-test/target/maven-install-test-1.0-SNAPSHOT.jar
rename to src/test/resources/unit/basic-install/maven-install-test-1.0-SNAPSHOT.jar
diff --git a/src/test/resources/unit/basic-install-test-packaging-pom/plugin-config.xml b/src/test/resources/unit/basic-install/packaging-pom.xml
similarity index 64%
rename from src/test/resources/unit/basic-install-test-packaging-pom/plugin-config.xml
rename to src/test/resources/unit/basic-install/packaging-pom.xml
index baf37e5..eafd324 100644
--- a/src/test/resources/unit/basic-install-test-packaging-pom/plugin-config.xml
+++ b/src/test/resources/unit/basic-install/packaging-pom.xml
@@ -22,11 +22,18 @@ under the License.
<plugin>
<artifactId>maven-install-plugin</artifactId>
<configuration>
- <project implementation="org.apache.maven.plugin.testing.stubs.MavenProjectStub">
- <file>${basedir}/src/test/resources/unit/basic-install-test-packaging-pom/plugin-config.xml</file>
+ <project implementation="org.apache.maven.plugins.install.stubs.ProjectStub">
+ <pomPath>${basedir}/src/test/resources/unit/basic-install/packaging-pom.xml</pomPath>
+ <groupId>org.apache.maven.test</groupId>
+ <artifactId>maven-install-test</artifactId>
+ <version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
- <artifact implementation="org.apache.maven.plugins.install.stubs.InstallArtifactStub"/>
- <attachedArtifacts/>
+ <artifact implementation="org.apache.maven.plugins.install.stubs.ArtifactStub">
+ <groupId>org.apache.maven.test</groupId>
+ <artifactId>maven-install-test</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <extension>pom</extension>
+ </artifact>
</project>
</configuration>
</plugin>
diff --git a/src/test/resources/unit/configured-install-test/plugin-config.xml b/src/test/resources/unit/basic-install/test.xml
similarity index 65%
rename from src/test/resources/unit/configured-install-test/plugin-config.xml
rename to src/test/resources/unit/basic-install/test.xml
index 2cc19ac..1744624 100644
--- a/src/test/resources/unit/configured-install-test/plugin-config.xml
+++ b/src/test/resources/unit/basic-install/test.xml
@@ -22,11 +22,18 @@ under the License.
<plugin>
<artifactId>maven-install-plugin</artifactId>
<configuration>
- <project implementation="org.apache.maven.plugin.testing.stubs.MavenProjectStub">
- <file>${basedir}/src/test/resources/unit/configured-install-test/plugin-config.xml</file>
+ <project implementation="org.apache.maven.plugins.install.stubs.ProjectStub">
+ <pomPath>${basedir}/src/test/resources/unit/basic-install/test.xml</pomPath>
+ <groupId>org.apache.maven.test</groupId>
+ <artifactId>maven-install-test</artifactId>
+ <version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
- <artifact implementation="org.apache.maven.plugins.install.stubs.InstallArtifactStub"/>
- <attachedArtifacts/>
+ <artifact implementation="org.apache.maven.plugins.install.stubs.ArtifactStub">
+ <groupId>org.apache.maven.test</groupId>
+ <artifactId>maven-install-test</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <extension>jar</extension>
+ </artifact>
</project>
</configuration>
</plugin>
diff --git a/src/test/resources/unit/configured-install-test/target/maven-install-test-1.0-SNAPSHOT.jar b/src/test/resources/unit/configured-install-test/target/maven-install-test-1.0-SNAPSHOT.jar
deleted file mode 100644
index 4a0e834..0000000
Binary files a/src/test/resources/unit/configured-install-test/target/maven-install-test-1.0-SNAPSHOT.jar and /dev/null differ
diff --git a/src/test/resources/unit/install-file-basic-test/target/maven-install-test-1.0-SNAPSHOT.jar b/src/test/resources/unit/install-file-basic-test/target/maven-install-test-1.0-SNAPSHOT.jar
deleted file mode 100644
index 4a0e834..0000000
Binary files a/src/test/resources/unit/install-file-basic-test/target/maven-install-test-1.0-SNAPSHOT.jar and /dev/null differ
diff --git a/src/test/resources/unit/install-file-test-generatePom/target/maven-install-test-1.0-SNAPSHOT.jar b/src/test/resources/unit/install-file-test-generatePom/target/maven-install-test-1.0-SNAPSHOT.jar
deleted file mode 100644
index 9c1e111..0000000
Binary files a/src/test/resources/unit/install-file-test-generatePom/target/maven-install-test-1.0-SNAPSHOT.jar and /dev/null differ
diff --git a/src/test/resources/unit/install-file-with-checksum/maven-test-jar.jar b/src/test/resources/unit/install-file-with-checksum/maven-test-jar.jar
deleted file mode 100644
index 5be5453..0000000
--- a/src/test/resources/unit/install-file-with-checksum/maven-test-jar.jar
+++ /dev/null
@@ -1 +0,0 @@
-this is just a test jar
\ No newline at end of file
diff --git a/src/test/resources/unit/install-file-basic-test/plugin-config.xml b/src/test/resources/unit/install-file/basic-test.xml
similarity index 94%
copy from src/test/resources/unit/install-file-basic-test/plugin-config.xml
copy to src/test/resources/unit/install-file/basic-test.xml
index 4052343..ac19871 100644
--- a/src/test/resources/unit/install-file-basic-test/plugin-config.xml
+++ b/src/test/resources/unit/install-file/basic-test.xml
@@ -26,8 +26,7 @@ under the License.
<artifactId>maven-install-file-test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
- <file>${basedir}/target/test-classes/unit/install-file-basic-test/target/maven-install-test-1.0-SNAPSHOT.jar
- </file>
+ <file>${basedir}/target/test-classes/unit/install-file/maven-install-test-1.0-SNAPSHOT.jar</file>
</configuration>
</plugin>
</plugins>
diff --git a/src/test/resources/unit/install-file-basic-test/plugin-config.xml b/src/test/resources/unit/install-file/file-absent.xml
similarity index 94%
rename from src/test/resources/unit/install-file-basic-test/plugin-config.xml
rename to src/test/resources/unit/install-file/file-absent.xml
index 4052343..3f8d4eb 100644
--- a/src/test/resources/unit/install-file-basic-test/plugin-config.xml
+++ b/src/test/resources/unit/install-file/file-absent.xml
@@ -26,8 +26,7 @@ under the License.
<artifactId>maven-install-file-test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
- <file>${basedir}/target/test-classes/unit/install-file-basic-test/target/maven-install-test-1.0-SNAPSHOT.jar
- </file>
+ <file>${basedir}/target/test-classes/unit/install-file/files-does-not-exists.jar</file>
</configuration>
</plugin>
</plugins>
diff --git a/src/test/resources/unit/install-file-with-classifier/target/maven-install-test-1.0-SNAPSHOT.jar b/src/test/resources/unit/install-file/maven-install-test-1.0-SNAPSHOT.jar
similarity index 100%
rename from src/test/resources/unit/install-file-with-classifier/target/maven-install-test-1.0-SNAPSHOT.jar
rename to src/test/resources/unit/install-file/maven-install-test-1.0-SNAPSHOT.jar
diff --git a/src/test/resources/unit/install-file-test-generatePom/plugin-config.xml b/src/test/resources/unit/install-file/test-generatePom.xml
similarity index 86%
rename from src/test/resources/unit/install-file-test-generatePom/plugin-config.xml
rename to src/test/resources/unit/install-file/test-generatePom.xml
index f6624f6..267fc74 100644
--- a/src/test/resources/unit/install-file-test-generatePom/plugin-config.xml
+++ b/src/test/resources/unit/install-file/test-generatePom.xml
@@ -23,11 +23,11 @@ under the License.
<artifactId>maven-install-plugin</artifactId>
<configuration>
<groupId>org.apache.maven.test</groupId>
- <artifactId>maven-install-file-test</artifactId>
+ <artifactId>maven-install-test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<file>
- ${basedir}/src/test/resources/unit/install-file-test-generatePom/target/maven-install-test-1.0-SNAPSHOT.jar
+ ${basedir}/src/test/resources/unit/install-file/maven-install-test-1.0-SNAPSHOT.jar
</file>
<generatePom>true</generatePom>
</configuration>
diff --git a/src/test/resources/unit/install-file-with-checksum/plugin-config.xml b/src/test/resources/unit/install-file/with-checksum.xml
similarity index 91%
rename from src/test/resources/unit/install-file-with-checksum/plugin-config.xml
rename to src/test/resources/unit/install-file/with-checksum.xml
index 91655ef..fa4147d 100644
--- a/src/test/resources/unit/install-file-with-checksum/plugin-config.xml
+++ b/src/test/resources/unit/install-file/with-checksum.xml
@@ -26,7 +26,7 @@ under the License.
<artifactId>maven-install-file-test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
- <file>${basedir}/src/test/resources/unit/install-file-with-checksum/maven-test-jar.jar</file>
+ <file>${basedir}/src/test/resources/unit/install-file/maven-install-test-1.0-SNAPSHOT.jar</file>
<generatePom>true</generatePom>
</configuration>
</plugin>
diff --git a/src/test/resources/unit/install-file-with-classifier/plugin-config.xml b/src/test/resources/unit/install-file/with-classifier.xml
similarity index 95%
rename from src/test/resources/unit/install-file-with-classifier/plugin-config.xml
rename to src/test/resources/unit/install-file/with-classifier.xml
index 8d6a18e..da2240d 100644
--- a/src/test/resources/unit/install-file-with-classifier/plugin-config.xml
+++ b/src/test/resources/unit/install-file/with-classifier.xml
@@ -27,7 +27,7 @@ under the License.
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<classifier>sources</classifier>
- <file>${basedir}/target/test-classes/unit/install-file-with-classifier/target/maven-install-test-1.0-SNAPSHOT.jar
+ <file>${basedir}/target/test-classes/unit/install-file/maven-install-test-1.0-SNAPSHOT.jar
</file>
</configuration>
</plugin>
diff --git a/src/test/resources/unit/install-file-with-pom-as-packaging/plugin-config.xml b/src/test/resources/unit/install-file/with-pom-as-packaging.xml
similarity index 91%
rename from src/test/resources/unit/install-file-with-pom-as-packaging/plugin-config.xml
rename to src/test/resources/unit/install-file/with-pom-as-packaging.xml
index 4ec759d..daa30e0 100644
--- a/src/test/resources/unit/install-file-with-pom-as-packaging/plugin-config.xml
+++ b/src/test/resources/unit/install-file/with-pom-as-packaging.xml
@@ -26,7 +26,7 @@ under the License.
<artifactId>maven-install-file-test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
- <file>${basedir}/src/test/resources/unit/install-file-with-pomFile-test/plugin-config.xml</file>
+ <file>${basedir}/src/test/resources/unit/install-file/with-pomFile-test.xml</file>
</configuration>
</plugin>
</plugins>
diff --git a/src/test/resources/unit/install-file-with-pomFile-test/plugin-config.xml b/src/test/resources/unit/install-file/with-pomFile-test.xml
similarity index 89%
rename from src/test/resources/unit/install-file-with-pomFile-test/plugin-config.xml
rename to src/test/resources/unit/install-file/with-pomFile-test.xml
index fc7c108..6ce977b 100644
Binary files a/src/test/resources/unit/install-file-with-pomFile-test/plugin-config.xml and b/src/test/resources/unit/install-file/with-pomFile-test.xml differ