Skip to content

Commit

Permalink
[MINSTALL-195] Include artifactId in InstallMojo#processProject mess…
Browse files Browse the repository at this point in the history
…ages
  • Loading branch information
cstamas committed Apr 24, 2024
1 parent 3ebb448 commit e914367
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/it/no-main-artifact-1/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@

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

assert buildLog.text.contains( "The packaging plugin for this project did not assign "
assert buildLog.text.contains( "The packaging plugin for project test did not assign "
+ "a main file to the project but it has attachments. Change packaging to 'pom'." )
2 changes: 1 addition & 1 deletion src/it/no-main-artifact-2/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@

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

assert buildLog.text.contains( "The packaging plugin for this project did not assign "
assert buildLog.text.contains( "The packaging plugin for project test did not assign "
+ "a main file to the project but it has attachments. Change packaging to 'pom'." )
14 changes: 8 additions & 6 deletions src/main/java/org/apache/maven/plugins/install/InstallMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ private void processProject(MavenProject project, InstallRequest request) throws
if (isFile(pomArtifact.getFile())) {
request.addArtifact(pomArtifact);
} else {
throw new MojoExecutionException("The project POM could not be attached");
throw new MojoExecutionException(
"The POM for project " + project.getArtifactId() + " could not be attached");
}

// is not packaged, is "incomplete"
Expand All @@ -218,18 +219,19 @@ private void processProject(MavenProject project, InstallRequest request) throws
} else if (!project.getAttachedArtifacts().isEmpty()) {
if (allowIncompleteProjects) {
getLog().warn("");
getLog().warn("The packaging plugin for this project did not assign");
getLog().warn("The packaging plugin for project " + project.getArtifactId() + " did not assign");
getLog().warn("a main file to the project but it has attachments. Change packaging to 'pom'.");
getLog().warn("");
getLog().warn("Incomplete projects like this will fail in future Maven versions!");
getLog().warn("");
} else {
throw new MojoExecutionException("The packaging plugin for this project did not assign "
+ "a main file to the project but it has attachments. Change packaging to 'pom'.");
throw new MojoExecutionException("The packaging plugin for project " + project.getArtifactId()
+ " did not assign a main file to the project but it has attachments. Change packaging"
+ " to 'pom'.");
}
} else {
throw new MojoExecutionException(
"The packaging for this project did not assign a file to the build artifact");
throw new MojoExecutionException("The packaging plugin for project " + project.getArtifactId()
+ " did not assign a file to the build artifact");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,38 @@ public void testBasicInstallWithAttachedArtifacts() throws Exception {
assertEquals(13, FileUtils.getFiles(new File(LOCAL_REPO), null, null).size());
}

public void testNonPomInstallWithAttachedArtifactsOnly() throws Exception {
File testPom = new File(
getBasedir(),
"target/test-classes/unit/basic-install-test-with-attached-artifacts/" + "plugin-config.xml");

AbstractMojo mojo = (AbstractMojo) lookupMojo("install", testPom);

assertNotNull(mojo);

MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
updateMavenProject(project);

setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
setVariableValueToObject(mojo, "pluginDescriptor", new PluginDescriptor());
setVariableValueToObject(mojo, "session", createMavenSession());

artifact = (InstallArtifactStub) project.getArtifact();

artifact.setFile(null);

try {
mojo.execute();
fail("Did not throw mojo execution exception");
} catch (MojoExecutionException e) {
// expected, message should include artifactId
assertEquals(
"The packaging plugin for project maven-install-test did not assign a main file to the project "
+ "but it has attachments. Change packaging to 'pom'.",
e.getMessage());
}
}

public void testUpdateReleaseParamSetToTrue() throws Exception {
File testPom = new File(getBasedir(), "target/test-classes/unit/configured-install-test/plugin-config.xml");

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

try {
mojo.execute();

fail("Did not throw mojo execution exception");
} catch (MojoExecutionException e) {
// expected
// expected, message should include artifactId
assertEquals(
"The packaging plugin for project maven-install-test did not assign a file to the build artifact",
e.getMessage());
}

assertFalse(new File(LOCAL_REPO).exists());
}

public void testInstallIfProjectFileIsNull() throws Exception {
File testPom = new File(getBasedir(), "target/test-classes/unit/basic-install-test/plugin-config.xml");

AbstractMojo mojo = (AbstractMojo) lookupMojo("install", testPom);

assertNotNull(mojo);

MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
updateMavenProject(project);

setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
setVariableValueToObject(mojo, "pluginDescriptor", new PluginDescriptor());
setVariableValueToObject(mojo, "session", createMavenSession());

project.setFile(null);

assertNull(project.getFile());

try {
mojo.execute();
fail("Did not throw mojo execution exception");
} catch (MojoExecutionException e) {
// expected, message should include artifactId
assertEquals("The POM for project maven-install-test could not be attached", e.getMessage());
}
}

public void testInstallIfPackagingIsPom() throws Exception {
File testPom = new File(
getBasedir(), "target/test-classes/unit/basic-install-test-packaging-pom/" + "plugin-config.xml");
Expand Down

0 comments on commit e914367

Please sign in to comment.