-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
358 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,7 +52,7 @@ | |
* | ||
* @author <a href="mailto:[email protected]">Allan Ramirez</a> | ||
*/ | ||
@Mojo(name = "deploy-file", requiresProject = false) | ||
@Mojo(name = "deploy-file", projectRequired = false) | ||
@SuppressWarnings("unused") | ||
public class DeployFileMojo extends AbstractDeployMojo { | ||
private static final String TAR = "tar."; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
import java.io.File; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
@@ -33,6 +34,9 @@ | |
import org.apache.maven.api.Session; | ||
import org.apache.maven.api.model.Model; | ||
import org.apache.maven.api.plugin.testing.InjectMojo; | ||
import org.apache.maven.api.plugin.testing.MojoExtension; | ||
import org.apache.maven.api.plugin.testing.MojoParameter; | ||
import org.apache.maven.api.plugin.testing.MojoParameters; | ||
import org.apache.maven.api.plugin.testing.MojoTest; | ||
import org.apache.maven.api.plugin.testing.stubs.ArtifactStub; | ||
import org.apache.maven.api.plugin.testing.stubs.SessionStub; | ||
|
@@ -41,6 +45,7 @@ | |
import org.apache.maven.api.services.ArtifactManager; | ||
import org.apache.maven.api.services.ProjectBuilder; | ||
import org.apache.maven.api.services.ProjectManager; | ||
import org.apache.maven.internal.impl.InternalSession; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.apache.maven.api.plugin.testing.MojoExtension.getVariableValueFromObject; | ||
|
@@ -50,6 +55,7 @@ | |
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.when; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Allan Ramirez</a> | ||
|
@@ -71,13 +77,27 @@ public class DeployFileMojoTest { | |
private ArtifactManager artifactManager; | ||
|
||
@Test | ||
@InjectMojo(goal = "deploy-file", pom = "classpath:/unit/deploy-file/plugin-config-test.xml") | ||
@InjectMojo(goal = "deploy-file") | ||
public void testDeployTestEnvironment(DeployFileMojo mojo) { | ||
assertNotNull(mojo); | ||
} | ||
|
||
@Test | ||
@InjectMojo(goal = "deploy-file", pom = "classpath:/unit/deploy-file/plugin-config-test.xml") | ||
@InjectMojo(goal = "deploy-file") | ||
@MojoParameters({ | ||
@MojoParameter(name = "groupId", value = "org.apache.maven.test"), | ||
@MojoParameter(name = "artifactId", value = "maven-deploy-file-test"), | ||
@MojoParameter(name = "version", value = "1.0"), | ||
@MojoParameter(name = "packaging", value = "jar"), | ||
@MojoParameter( | ||
name = "file", | ||
value = "${session.topDirectory}/src/test/resources/unit/maven-deploy-test-1.0-SNAPSHOT.jar"), | ||
@MojoParameter(name = "repositoryId", value = "deploy-test"), | ||
@MojoParameter(name = "url", value = "file://${session.topDirectory}/target/remote-repo/deploy-file"), | ||
@MojoParameter(name = "description", value = "POM was created from deploy:deploy-file"), | ||
@MojoParameter(name = "generatePom", value = "true"), | ||
@MojoParameter(name = "skip", value = "snapshots") | ||
}) | ||
public void testBasicDeployFile(DeployFileMojo mojo) throws Exception { | ||
assertNotNull(mojo); | ||
|
||
|
@@ -93,9 +113,9 @@ public void testBasicDeployFile(DeployFileMojo mojo) throws Exception { | |
assertEquals("maven-deploy-file-test", artifactId); | ||
assertEquals("1.0", version); | ||
assertEquals("jar", packaging); | ||
assertTrue(Files.exists(file)); | ||
assertTrue(Files.exists(file), file.toString()); | ||
assertEquals("deploy-test", repositoryId); | ||
assertEquals("file://" + getBasedir() + "/target/remote-repo/deploy-file-test", url); | ||
assertEquals("file://" + getBasedir() + "/target/remote-repo/deploy-file", url); | ||
|
||
execute(mojo, request -> { | ||
assertNotNull(request); | ||
|
@@ -128,7 +148,20 @@ public void testBasicDeployFile(DeployFileMojo mojo) throws Exception { | |
} | ||
|
||
@Test | ||
@InjectMojo(goal = "deploy-file", pom = "classpath:/unit/deploy-file/plugin-config-classifier.xml") | ||
@InjectMojo(goal = "deploy-file") | ||
@MojoParameters({ | ||
@MojoParameter(name = "groupId", value = "org.apache.maven.test"), | ||
@MojoParameter(name = "artifactId", value = "maven-deploy-file-test"), | ||
@MojoParameter(name = "version", value = "1.0"), | ||
@MojoParameter(name = "packaging", value = "jar"), | ||
@MojoParameter( | ||
name = "file", | ||
value = "${session.topDirectory}/src/test/resources/unit/maven-deploy-test-1.0-SNAPSHOT.jar"), | ||
@MojoParameter(name = "repositoryId", value = "deploy-test"), | ||
@MojoParameter(name = "url", value = "file://${session.topDirectory}/target/remote-repo/deploy-file"), | ||
@MojoParameter(name = "classifier", value = "bin"), | ||
@MojoParameter(name = "generatePom", value = "true") | ||
}) | ||
public void testDeployIfClassifierIsSet(DeployFileMojo mojo) throws Exception { | ||
assertNotNull(mojo); | ||
|
||
|
@@ -149,7 +182,7 @@ public void testDeployIfClassifierIsSet(DeployFileMojo mojo) throws Exception { | |
assertEquals(new ArtifactStub(groupId, artifactId, "bin", version, "jar"), a1); | ||
Path p1 = artifactManager.getPath(a1).orElse(null); | ||
assertNotNull(p1); | ||
assertTrue(p1.toString().endsWith("deploy-test-file-1.0-SNAPSHOT.jar")); | ||
assertTrue(p1.toString().endsWith("maven-deploy-test-1.0-SNAPSHOT.jar")); | ||
// second artifact | ||
Artifact a2 = artifacts.get(1); | ||
assertEquals(new ArtifactStub(groupId, artifactId, "", version, "pom"), a2); | ||
|
@@ -162,7 +195,16 @@ public void testDeployIfClassifierIsSet(DeployFileMojo mojo) throws Exception { | |
} | ||
|
||
@Test | ||
@InjectMojo(goal = "deploy-file", pom = "classpath:/unit/deploy-file/plugin-config-artifact-not-jar.xml") | ||
@InjectMojo(goal = "deploy-file") | ||
@MojoParameters({ | ||
@MojoParameter(name = "groupId", value = "org.apache.maven.test"), | ||
@MojoParameter(name = "artifactId", value = "maven-deploy-file-test"), | ||
@MojoParameter(name = "version", value = "1.0"), | ||
@MojoParameter(name = "file", value = "${session.topDirectory}/src/test/resources/unit/maven-deploy-test.zip"), | ||
@MojoParameter(name = "repositoryId", value = "deploy-test"), | ||
@MojoParameter(name = "url", value = "file://${session.topDirectory}/target/remote-repo/deploy-file"), | ||
@MojoParameter(name = "generatePom", value = "true") | ||
}) | ||
public void testDeployIfArtifactIsNotJar(DeployFileMojo mojo) throws Exception { | ||
assertNotNull(mojo); | ||
|
||
|
@@ -183,7 +225,7 @@ public void testDeployIfArtifactIsNotJar(DeployFileMojo mojo) throws Exception { | |
Path p1 = artifactManager.getPath(a1).orElse(null); | ||
Path p2 = artifactManager.getPath(a2).orElse(null); | ||
assertNotNull(p1); | ||
assertTrue(p1.toString().endsWith("deploy-test-file.zip")); | ||
assertTrue(p1.toString().endsWith("maven-deploy-test.zip")); | ||
assertNotNull(p2); | ||
assertTrue(p2.toString().endsWith(".pom")); | ||
|
||
|
@@ -213,31 +255,33 @@ private void execute(DeployFileMojo mojo, Consumer<ArtifactDeployerRequest> cons | |
@Provides | ||
@Singleton | ||
@SuppressWarnings("unused") | ||
private Session getMockSession() { | ||
return SessionStub.getMockSession(LOCAL_REPO); | ||
private InternalSession createSession() { | ||
InternalSession session = SessionStub.getMockSession(LOCAL_REPO); | ||
when(session.getTopDirectory()).thenReturn(Paths.get(MojoExtension.getBasedir())); | ||
return session; | ||
} | ||
|
||
@Provides | ||
@SuppressWarnings("unused") | ||
private ArtifactDeployer getMockArtifactDeployer(Session session) { | ||
private ArtifactDeployer createArtifactDeployer(Session session) { | ||
return session.getService(ArtifactDeployer.class); | ||
} | ||
|
||
@Provides | ||
@SuppressWarnings("unused") | ||
private ArtifactManager getMockArtifactManager(Session session) { | ||
private ArtifactManager createArtifactManager(Session session) { | ||
return session.getService(ArtifactManager.class); | ||
} | ||
|
||
@Provides | ||
@SuppressWarnings("unused") | ||
private ProjectManager getMockProjectManager(Session session) { | ||
private ProjectManager createProjectManager(Session session) { | ||
return session.getService(ProjectManager.class); | ||
} | ||
|
||
@Provides | ||
@SuppressWarnings("unused") | ||
private ProjectBuilder getMockProjectBuilder(Session session) { | ||
private ProjectBuilder createProjectBuilder(Session session) { | ||
return session.getService(ProjectBuilder.class); | ||
} | ||
} |
Oops, something went wrong.