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-deploy-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new b9c1c8b  [MDEPLOY-314] Include artifactId in DeployMojo#processProject 
messages
b9c1c8b is described below

commit b9c1c8bc486c7defb92171e1ea9169075b76695c
Author: András Péteri <apet...@b2international.com>
AuthorDate: Mon Nov 20 14:27:01 2023 +0100

    [MDEPLOY-314] Include artifactId in DeployMojo#processProject messages
    
    Enhance messages on deployAtEnd
    
    ---
    
    https://issues.apache.org/jira/browse/MDEPLOY-314
---
 .../apache/maven/plugins/deploy/DeployMojo.java    |  14 +-
 .../maven/plugins/deploy/DeployMojoTest.java       | 141 ++++++++++++++++++++-
 2 files changed, 148 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java 
b/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
index c3ea850..79ee1d8 100644
--- a/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
+++ b/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
@@ -308,7 +308,8 @@ public class DeployMojo extends AbstractDeployMojo {
         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"
@@ -319,18 +320,19 @@ public class DeployMojo extends AbstractDeployMojo {
             } 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/deploy/DeployMojoTest.java 
b/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
index 3b0df77..5884ae1 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
@@ -23,6 +23,7 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
+import java.util.Properties;
 import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.maven.execution.MavenSession;
@@ -36,10 +37,12 @@ import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.ProjectBuildingRequest;
 import org.codehaus.plexus.util.FileUtils;
 import org.eclipse.aether.DefaultRepositorySystemSession;
+import org.eclipse.aether.RepositorySystem;
 import org.eclipse.aether.internal.impl.DefaultLocalPathComposer;
 import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
 import org.eclipse.aether.repository.LocalRepository;
 import org.eclipse.aether.repository.RemoteRepository;
+import org.junit.Ignore;
 import org.mockito.InjectMocks;
 import org.mockito.MockitoAnnotations;
 
@@ -470,10 +473,46 @@ public class DeployMojoTest extends AbstractMojoTestCase {
 
         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-deploy-test did 
not assign a file to the build artifact",
+                    e.getMessage());
+        }
+    }
+
+    public void testDeployIfProjectFileIsNull() throws Exception {
+        File testPom = new File(getBasedir(), 
"target/test-classes/unit/basic-deploy-test/plugin-config.xml");
 
+        DeployMojo mojo = (DeployMojo) lookupMojo("deploy", testPom);
+
+        MockitoAnnotations.initMocks(this);
+
+        ProjectBuildingRequest buildingRequest = 
mock(ProjectBuildingRequest.class);
+        when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
+
+        setVariableValueToObject(mojo, "session", session);
+
+        assertNotNull(mojo);
+
+        MavenProject project = (MavenProject) getVariableValueFromObject(mojo, 
"project");
+        project.setGroupId("org.apache.maven.test");
+        project.setArtifactId("maven-deploy-test");
+        project.setVersion("1.0-SNAPSHOT");
+
+        project.setFile(null);
+        assertNull(project.getFile());
+
+        setVariableValueToObject(mojo, "pluginContext", new 
ConcurrentHashMap<>());
+        setVariableValueToObject(mojo, "reactorProjects", 
Collections.singletonList(project));
+
+        try {
+            mojo.execute();
             fail("Did not throw mojo execution exception");
         } catch (MojoExecutionException e) {
-            // expected
+            // expected, message should include artifactId
+            assertEquals("The POM for project maven-deploy-test could not be 
attached", e.getMessage());
         }
     }
 
@@ -568,6 +607,106 @@ public class DeployMojoTest extends AbstractMojoTestCase {
         assertEquals(0, getSizeOfExpectedFiles(fileList, expectedFiles));
     }
 
+    public void testNonPomDeployWithAttachedArtifactsOnly() throws Exception {
+        File testPom = new File(
+                getBasedir(), 
"target/test-classes/unit/basic-deploy-with-attached-artifacts/" + 
"plugin-config.xml");
+
+        mojo = (DeployMojo) lookupMojo("deploy", testPom);
+
+        MockitoAnnotations.initMocks(this);
+
+        assertNotNull(mojo);
+
+        ProjectBuildingRequest buildingRequest = 
mock(ProjectBuildingRequest.class);
+        when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
+
+        MavenProject project = (MavenProject) getVariableValueFromObject(mojo, 
"project");
+        project.setGroupId("org.apache.maven.test");
+        project.setArtifactId("maven-deploy-test");
+        project.setVersion("1.0-SNAPSHOT");
+
+        setVariableValueToObject(mojo, "pluginContext", new 
ConcurrentHashMap<>());
+        setVariableValueToObject(mojo, "reactorProjects", 
Collections.singletonList(project));
+
+        artifact = (DeployArtifactStub) 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-deploy-test did 
not assign a main file to the project "
+                            + "but it has attachments. Change packaging to 
'pom'.",
+                    e.getMessage());
+        }
+    }
+
+    @Ignore("SCP is not part of Maven3 distribution. Aether handles transport 
extensions.")
+    public void _testBasicDeployWithScpAsProtocol() throws Exception {
+        String originalUserHome = System.getProperty("user.home");
+
+        // FIX THE DAMN user.home BEFORE YOU DELETE IT!!!
+        File altHome = new File(getBasedir(), "target/ssh-user-home");
+        altHome.mkdirs();
+
+        System.out.println("Testing user.home value for .ssh dir: " + 
altHome.getCanonicalPath());
+
+        Properties props = System.getProperties();
+        props.setProperty("user.home", altHome.getCanonicalPath());
+
+        System.setProperties(props);
+
+        File testPom = new File(getBasedir(), 
"target/test-classes/unit/basic-deploy-scp/plugin-config.xml");
+
+        mojo = (DeployMojo) lookupMojo("deploy", testPom);
+
+        assertNotNull(mojo);
+
+        RepositorySystem repositorySystem = mock(RepositorySystem.class);
+
+        setVariableValueToObject(mojo, "repositorySystem", repositorySystem);
+
+        File file = new File(
+                getBasedir(),
+                "target/test-classes/unit/basic-deploy-scp/target/" + 
"deploy-test-file-1.0-SNAPSHOT.jar");
+
+        assertTrue(file.exists());
+
+        MavenProject project = (MavenProject) getVariableValueFromObject(mojo, 
"project");
+
+        setVariableValueToObject(mojo, "pluginContext", new 
ConcurrentHashMap<>());
+        setVariableValueToObject(mojo, "reactorProjects", 
Collections.singletonList(project));
+
+        artifact = (DeployArtifactStub) project.getArtifact();
+
+        artifact.setFile(file);
+
+        String altUserHome = System.getProperty("user.home");
+
+        if (altUserHome.equals(originalUserHome)) {
+            // this is *very* bad!
+            throw new IllegalStateException(
+                    "Setting 'user.home' system property to alternate value 
did NOT work. Aborting test.");
+        }
+
+        File sshFile = new File(altUserHome, ".ssh");
+
+        System.out.println("Testing .ssh dir: " + sshFile.getCanonicalPath());
+
+        // delete first the .ssh folder if existing before executing the mojo
+        if (sshFile.exists()) {
+            FileUtils.deleteDirectory(sshFile);
+        }
+
+        mojo.execute();
+
+        assertTrue(sshFile.exists());
+
+        FileUtils.deleteDirectory(sshFile);
+    }
+
     public void testLegacyAltDeploymentRepositoryWithDefaultLayout() throws 
Exception {
         DeployMojo mojo = new DeployMojo();
 

Reply via email to