Skip to content

Commit e914367

Browse files
committed
[MINSTALL-195] Include artifactId in InstallMojo#processProject messages
1 parent 3ebb448 commit e914367

File tree

4 files changed

+73
-10
lines changed

4 files changed

+73
-10
lines changed

src/it/no-main-artifact-1/verify.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919

2020
def buildLog = new File ( basedir, "build.log")
2121

22-
assert buildLog.text.contains( "The packaging plugin for this project did not assign "
22+
assert buildLog.text.contains( "The packaging plugin for project test did not assign "
2323
+ "a main file to the project but it has attachments. Change packaging to 'pom'." )

src/it/no-main-artifact-2/verify.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919

2020
def buildLog = new File ( basedir, "build.log")
2121

22-
assert buildLog.text.contains( "The packaging plugin for this project did not assign "
22+
assert buildLog.text.contains( "The packaging plugin for project test did not assign "
2323
+ "a main file to the project but it has attachments. Change packaging to 'pom'." )

src/main/java/org/apache/maven/plugins/install/InstallMojo.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ private void processProject(MavenProject project, InstallRequest request) throws
207207
if (isFile(pomArtifact.getFile())) {
208208
request.addArtifact(pomArtifact);
209209
} else {
210-
throw new MojoExecutionException("The project POM could not be attached");
210+
throw new MojoExecutionException(
211+
"The POM for project " + project.getArtifactId() + " could not be attached");
211212
}
212213

213214
// is not packaged, is "incomplete"
@@ -218,18 +219,19 @@ private void processProject(MavenProject project, InstallRequest request) throws
218219
} else if (!project.getAttachedArtifacts().isEmpty()) {
219220
if (allowIncompleteProjects) {
220221
getLog().warn("");
221-
getLog().warn("The packaging plugin for this project did not assign");
222+
getLog().warn("The packaging plugin for project " + project.getArtifactId() + " did not assign");
222223
getLog().warn("a main file to the project but it has attachments. Change packaging to 'pom'.");
223224
getLog().warn("");
224225
getLog().warn("Incomplete projects like this will fail in future Maven versions!");
225226
getLog().warn("");
226227
} else {
227-
throw new MojoExecutionException("The packaging plugin for this project did not assign "
228-
+ "a main file to the project but it has attachments. Change packaging to 'pom'.");
228+
throw new MojoExecutionException("The packaging plugin for project " + project.getArtifactId()
229+
+ " did not assign a main file to the project but it has attachments. Change packaging"
230+
+ " to 'pom'.");
229231
}
230232
} else {
231-
throw new MojoExecutionException(
232-
"The packaging for this project did not assign a file to the build artifact");
233+
throw new MojoExecutionException("The packaging plugin for project " + project.getArtifactId()
234+
+ " did not assign a file to the build artifact");
233235
}
234236
}
235237

src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,38 @@ public void testBasicInstallWithAttachedArtifacts() throws Exception {
155155
assertEquals(13, FileUtils.getFiles(new File(LOCAL_REPO), null, null).size());
156156
}
157157

158+
public void testNonPomInstallWithAttachedArtifactsOnly() throws Exception {
159+
File testPom = new File(
160+
getBasedir(),
161+
"target/test-classes/unit/basic-install-test-with-attached-artifacts/" + "plugin-config.xml");
162+
163+
AbstractMojo mojo = (AbstractMojo) lookupMojo("install", testPom);
164+
165+
assertNotNull(mojo);
166+
167+
MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
168+
updateMavenProject(project);
169+
170+
setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
171+
setVariableValueToObject(mojo, "pluginDescriptor", new PluginDescriptor());
172+
setVariableValueToObject(mojo, "session", createMavenSession());
173+
174+
artifact = (InstallArtifactStub) project.getArtifact();
175+
176+
artifact.setFile(null);
177+
178+
try {
179+
mojo.execute();
180+
fail("Did not throw mojo execution exception");
181+
} catch (MojoExecutionException e) {
182+
// expected, message should include artifactId
183+
assertEquals(
184+
"The packaging plugin for project maven-install-test did not assign a main file to the project "
185+
+ "but it has attachments. Change packaging to 'pom'.",
186+
e.getMessage());
187+
}
188+
}
189+
158190
public void testUpdateReleaseParamSetToTrue() throws Exception {
159191
File testPom = new File(getBasedir(), "target/test-classes/unit/configured-install-test/plugin-config.xml");
160192

@@ -210,15 +242,44 @@ public void testInstallIfArtifactFileIsNull() throws Exception {
210242

211243
try {
212244
mojo.execute();
213-
214245
fail("Did not throw mojo execution exception");
215246
} catch (MojoExecutionException e) {
216-
// expected
247+
// expected, message should include artifactId
248+
assertEquals(
249+
"The packaging plugin for project maven-install-test did not assign a file to the build artifact",
250+
e.getMessage());
217251
}
218252

219253
assertFalse(new File(LOCAL_REPO).exists());
220254
}
221255

256+
public void testInstallIfProjectFileIsNull() throws Exception {
257+
File testPom = new File(getBasedir(), "target/test-classes/unit/basic-install-test/plugin-config.xml");
258+
259+
AbstractMojo mojo = (AbstractMojo) lookupMojo("install", testPom);
260+
261+
assertNotNull(mojo);
262+
263+
MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
264+
updateMavenProject(project);
265+
266+
setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
267+
setVariableValueToObject(mojo, "pluginDescriptor", new PluginDescriptor());
268+
setVariableValueToObject(mojo, "session", createMavenSession());
269+
270+
project.setFile(null);
271+
272+
assertNull(project.getFile());
273+
274+
try {
275+
mojo.execute();
276+
fail("Did not throw mojo execution exception");
277+
} catch (MojoExecutionException e) {
278+
// expected, message should include artifactId
279+
assertEquals("The POM for project maven-install-test could not be attached", e.getMessage());
280+
}
281+
}
282+
222283
public void testInstallIfPackagingIsPom() throws Exception {
223284
File testPom = new File(
224285
getBasedir(), "target/test-classes/unit/basic-install-test-packaging-pom/" + "plugin-config.xml");

0 commit comments

Comments
 (0)