This is an automated email from the ASF dual-hosted git repository.

cstamas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-install-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new e914367      [MINSTALL-195] Include artifactId in 
InstallMojo#processProject messages
e914367 is described below

commit e9143678bac6980000483693b3b2ed2d58407920
Author: Tamas Cservenak <ta...@cservenak.net>
AuthorDate: Wed Apr 24 15:40:23 2024 +0200

        [MINSTALL-195] Include artifactId in InstallMojo#processProject messages
---
 src/it/no-main-artifact-1/verify.groovy            |  2 +-
 src/it/no-main-artifact-2/verify.groovy            |  2 +-
 .../apache/maven/plugins/install/InstallMojo.java  | 14 +++--
 .../maven/plugins/install/InstallMojoTest.java     | 65 +++++++++++++++++++++-
 4 files changed, 73 insertions(+), 10 deletions(-)

diff --git a/src/it/no-main-artifact-1/verify.groovy 
b/src/it/no-main-artifact-1/verify.groovy
index 9442aa7..7274ba5 100644
--- a/src/it/no-main-artifact-1/verify.groovy
+++ b/src/it/no-main-artifact-1/verify.groovy
@@ -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'." )
\ No newline at end of file
diff --git a/src/it/no-main-artifact-2/verify.groovy 
b/src/it/no-main-artifact-2/verify.groovy
index 9442aa7..7274ba5 100644
--- a/src/it/no-main-artifact-2/verify.groovy
+++ b/src/it/no-main-artifact-2/verify.groovy
@@ -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'." )
\ No newline at end of file
diff --git a/src/main/java/org/apache/maven/plugins/install/InstallMojo.java 
b/src/main/java/org/apache/maven/plugins/install/InstallMojo.java
index a2aaa9a..35eb1c1 100644
--- a/src/main/java/org/apache/maven/plugins/install/InstallMojo.java
+++ b/src/main/java/org/apache/maven/plugins/install/InstallMojo.java
@@ -207,7 +207,8 @@ public class InstallMojo extends AbstractMojo {
         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"
@@ -218,18 +219,19 @@ public class InstallMojo extends AbstractMojo {
             } 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");
             }
         }
 
diff --git 
a/src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java 
b/src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java
index 7939778..8176925 100644
--- a/src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java
@@ -155,6 +155,38 @@ public class InstallMojoTest extends AbstractMojoTestCase {
         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");
 
@@ -210,15 +242,44 @@ public class InstallMojoTest extends AbstractMojoTestCase 
{
 
         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");

Reply via email to