Skip to content

Commit e36a858

Browse files
committed
Fix DeployFileMojo
1 parent 82ebf69 commit e36a858

File tree

2 files changed

+44
-40
lines changed

2 files changed

+44
-40
lines changed

src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,9 @@ public void execute() throws MojoException {
289289
artifactManager.setPath(artifact, file);
290290
deployables.add(artifact);
291291

292+
ProducedArtifact pomArtifact = null;
292293
if (!isFilePom) {
293-
ProducedArtifact pomArtifact =
294-
session.createProducedArtifact(groupId, artifactId, version, "", "pom", null);
294+
pomArtifact = session.createProducedArtifact(groupId, artifactId, version, "", "pom", null);
295295
if (deployedPom != null) {
296296
artifactManager.setPath(pomArtifact, deployedPom);
297297
deployables.add(pomArtifact);
@@ -409,6 +409,9 @@ public void execute() throws MojoException {
409409
} catch (IOException e) {
410410
// ignore
411411
}
412+
if (pomArtifact != null) {
413+
artifactManager.setPath(pomArtifact, null);
414+
}
412415
}
413416
}
414417
}

src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -165,26 +165,27 @@ public void testDeployIfClassifierIsSet(DeployFileMojo mojo) throws Exception {
165165
String version = (String) getVariableValueFromObject(mojo, "version");
166166
String url = (String) getVariableValueFromObject(mojo, "url");
167167

168-
ArtifactDeployerRequest request = execute(mojo);
169-
170-
assertNotNull(request);
171-
List<Artifact> artifacts = new ArrayList<>(request.getArtifacts());
172-
assertEquals(2, artifacts.size());
173-
// first artifact
174-
Artifact a1 = artifacts.get(0);
175-
assertEquals(new ArtifactStub(groupId, artifactId, "bin", version, "jar"), a1);
176-
Path p1 = artifactManager.getPath(a1).orElse(null);
177-
assertNotNull(p1);
178-
assertTrue(p1.toString().endsWith("maven-deploy-test-1.0-SNAPSHOT.jar"));
179-
// second artifact
180-
Artifact a2 = artifacts.get(1);
181-
assertEquals(new ArtifactStub(groupId, artifactId, "", version, "pom"), a2);
182-
Path p2 = artifactManager.getPath(a2).orElse(null);
183-
assertNotNull(p2);
184-
assertTrue(p2.toString().endsWith(".pom"));
185-
// remote repository
186-
assertNotNull(request.getRepository());
187-
assertEquals(url.replace(File.separator, "/"), request.getRepository().getUrl());
168+
execute(mojo, request -> {
169+
assertNotNull(request);
170+
List<Artifact> artifacts = new ArrayList<>(request.getArtifacts());
171+
assertEquals(2, artifacts.size());
172+
// first artifact
173+
Artifact a1 = artifacts.get(0);
174+
assertEquals(new ArtifactStub(groupId, artifactId, "bin", version, "jar"), a1);
175+
Path p1 = artifactManager.getPath(a1).orElse(null);
176+
assertNotNull(p1);
177+
assertTrue(p1.toString().endsWith("maven-deploy-test-1.0-SNAPSHOT.jar"));
178+
// second artifact
179+
Artifact a2 = artifacts.get(1);
180+
assertEquals(new ArtifactStub(groupId, artifactId, "", version, "pom"), a2);
181+
Path p2 = artifactManager.getPath(a2).orElse(null);
182+
assertNotNull(p2);
183+
assertTrue(p2.toString().endsWith(".pom"));
184+
// remote repository
185+
assertNotNull(request.getRepository());
186+
assertEquals(
187+
url.replace(File.separator, "/"), request.getRepository().getUrl());
188+
});
188189
}
189190

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

209-
ArtifactDeployerRequest request = execute(mojo);
210-
211-
assertNotNull(request);
212-
List<Artifact> artifacts = new ArrayList<>(request.getArtifacts());
213-
assertEquals(2, artifacts.size());
214-
Artifact a1 = artifacts.get(0);
215-
Artifact a2 = artifacts.get(1);
216-
Path p1 = artifactManager.getPath(a1).orElse(null);
217-
Path p2 = artifactManager.getPath(a2).orElse(null);
218-
assertNotNull(p1);
219-
assertTrue(p1.toString().endsWith("maven-deploy-test.zip"));
220-
assertNotNull(p2);
221-
assertTrue(p2.toString().endsWith(".pom"));
222-
223-
assertNotNull(request.getRepository());
224-
assertEquals(
225-
"file://" + getBasedir().replace(File.separator, "/") + "/target/remote-repo/deploy-file",
226-
request.getRepository().getUrl());
210+
execute(mojo, request -> {
211+
assertNotNull(request);
212+
List<Artifact> artifacts = new ArrayList<>(request.getArtifacts());
213+
assertEquals(2, artifacts.size());
214+
Artifact a1 = artifacts.get(0);
215+
Artifact a2 = artifacts.get(1);
216+
Path p1 = artifactManager.getPath(a1).orElse(null);
217+
Path p2 = artifactManager.getPath(a2).orElse(null);
218+
assertNotNull(p1);
219+
assertTrue(p1.toString().endsWith("maven-deploy-test.zip"));
220+
assertNotNull(p2);
221+
assertTrue(p2.toString().endsWith(".pom"));
222+
223+
assertNotNull(request.getRepository());
224+
assertEquals(
225+
"file://" + getBasedir().replace(File.separator, "/") + "/target/remote-repo/deploy-file",
226+
request.getRepository().getUrl());
227+
});
227228
}
228229

229230
private ArtifactDeployerRequest execute(DeployFileMojo mojo) {

0 commit comments

Comments
 (0)