Skip to content

Commit

Permalink
Fix DeployFileMojo
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Oct 22, 2024
1 parent 82ebf69 commit e36a858
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,9 @@ public void execute() throws MojoException {
artifactManager.setPath(artifact, file);
deployables.add(artifact);

ProducedArtifact pomArtifact = null;
if (!isFilePom) {
ProducedArtifact pomArtifact =
session.createProducedArtifact(groupId, artifactId, version, "", "pom", null);
pomArtifact = session.createProducedArtifact(groupId, artifactId, version, "", "pom", null);
if (deployedPom != null) {
artifactManager.setPath(pomArtifact, deployedPom);
deployables.add(pomArtifact);
Expand Down Expand Up @@ -409,6 +409,9 @@ public void execute() throws MojoException {
} catch (IOException e) {
// ignore
}
if (pomArtifact != null) {
artifactManager.setPath(pomArtifact, null);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,26 +165,27 @@ public void testDeployIfClassifierIsSet(DeployFileMojo mojo) throws Exception {
String version = (String) getVariableValueFromObject(mojo, "version");
String url = (String) getVariableValueFromObject(mojo, "url");

ArtifactDeployerRequest request = execute(mojo);

assertNotNull(request);
List<Artifact> artifacts = new ArrayList<>(request.getArtifacts());
assertEquals(2, artifacts.size());
// first artifact
Artifact a1 = artifacts.get(0);
assertEquals(new ArtifactStub(groupId, artifactId, "bin", version, "jar"), a1);
Path p1 = artifactManager.getPath(a1).orElse(null);
assertNotNull(p1);
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);
Path p2 = artifactManager.getPath(a2).orElse(null);
assertNotNull(p2);
assertTrue(p2.toString().endsWith(".pom"));
// remote repository
assertNotNull(request.getRepository());
assertEquals(url.replace(File.separator, "/"), request.getRepository().getUrl());
execute(mojo, request -> {
assertNotNull(request);
List<Artifact> artifacts = new ArrayList<>(request.getArtifacts());
assertEquals(2, artifacts.size());
// first artifact
Artifact a1 = artifacts.get(0);
assertEquals(new ArtifactStub(groupId, artifactId, "bin", version, "jar"), a1);
Path p1 = artifactManager.getPath(a1).orElse(null);
assertNotNull(p1);
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);
Path p2 = artifactManager.getPath(a2).orElse(null);
assertNotNull(p2);
assertTrue(p2.toString().endsWith(".pom"));
// remote repository
assertNotNull(request.getRepository());
assertEquals(
url.replace(File.separator, "/"), request.getRepository().getUrl());
});
}

@Test
Expand All @@ -206,24 +207,24 @@ public void testDeployIfArtifactIsNotJar(DeployFileMojo mojo) throws Exception {
assertEquals("maven-deploy-file-test", artifactId);
assertEquals("1.0", version);

ArtifactDeployerRequest request = execute(mojo);

assertNotNull(request);
List<Artifact> artifacts = new ArrayList<>(request.getArtifacts());
assertEquals(2, artifacts.size());
Artifact a1 = artifacts.get(0);
Artifact a2 = artifacts.get(1);
Path p1 = artifactManager.getPath(a1).orElse(null);
Path p2 = artifactManager.getPath(a2).orElse(null);
assertNotNull(p1);
assertTrue(p1.toString().endsWith("maven-deploy-test.zip"));
assertNotNull(p2);
assertTrue(p2.toString().endsWith(".pom"));

assertNotNull(request.getRepository());
assertEquals(
"file://" + getBasedir().replace(File.separator, "/") + "/target/remote-repo/deploy-file",
request.getRepository().getUrl());
execute(mojo, request -> {
assertNotNull(request);
List<Artifact> artifacts = new ArrayList<>(request.getArtifacts());
assertEquals(2, artifacts.size());
Artifact a1 = artifacts.get(0);
Artifact a2 = artifacts.get(1);
Path p1 = artifactManager.getPath(a1).orElse(null);
Path p2 = artifactManager.getPath(a2).orElse(null);
assertNotNull(p1);
assertTrue(p1.toString().endsWith("maven-deploy-test.zip"));
assertNotNull(p2);
assertTrue(p2.toString().endsWith(".pom"));

assertNotNull(request.getRepository());
assertEquals(
"file://" + getBasedir().replace(File.separator, "/") + "/target/remote-repo/deploy-file",
request.getRepository().getUrl());
});
}

private ArtifactDeployerRequest execute(DeployFileMojo mojo) {
Expand Down

0 comments on commit e36a858

Please sign in to comment.