Skip to content

Commit b9c1c8b

Browse files
apetericstamas
authored andcommitted
[MDEPLOY-314] Include artifactId in DeployMojo#processProject messages
Enhance messages on deployAtEnd --- https://issues.apache.org/jira/browse/MDEPLOY-314
1 parent 74d331b commit b9c1c8b

File tree

2 files changed

+148
-7
lines changed

2 files changed

+148
-7
lines changed

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

+8-6
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,8 @@ private void processProject(final MavenProject project, DeployRequest request) t
308308
if (isFile(pomArtifact.getFile())) {
309309
request.addArtifact(pomArtifact);
310310
} else {
311-
throw new MojoExecutionException("The project POM could not be attached");
311+
throw new MojoExecutionException(
312+
"The POM for project " + project.getArtifactId() + " could not be attached");
312313
}
313314

314315
// is not packaged, is "incomplete"
@@ -319,18 +320,19 @@ private void processProject(final MavenProject project, DeployRequest request) t
319320
} else if (!project.getAttachedArtifacts().isEmpty()) {
320321
if (allowIncompleteProjects) {
321322
getLog().warn("");
322-
getLog().warn("The packaging plugin for this project did not assign");
323+
getLog().warn("The packaging plugin for project " + project.getArtifactId() + " did not assign");
323324
getLog().warn("a main file to the project but it has attachments. Change packaging to 'pom'.");
324325
getLog().warn("");
325326
getLog().warn("Incomplete projects like this will fail in future Maven versions!");
326327
getLog().warn("");
327328
} else {
328-
throw new MojoExecutionException("The packaging plugin for this project did not assign "
329-
+ "a main file to the project but it has attachments. Change packaging to 'pom'.");
329+
throw new MojoExecutionException("The packaging plugin for project " + project.getArtifactId()
330+
+ " did not assign a main file to the project but it has attachments. Change packaging"
331+
+ " to 'pom'.");
330332
}
331333
} else {
332-
throw new MojoExecutionException(
333-
"The packaging for this project did not assign a file to the build artifact");
334+
throw new MojoExecutionException("The packaging plugin for project " + project.getArtifactId()
335+
+ " did not assign a file to the build artifact");
334336
}
335337
}
336338

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

+140-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Collections;
2424
import java.util.List;
2525
import java.util.Objects;
26+
import java.util.Properties;
2627
import java.util.concurrent.ConcurrentHashMap;
2728

2829
import org.apache.maven.execution.MavenSession;
@@ -36,10 +37,12 @@
3637
import org.apache.maven.project.ProjectBuildingRequest;
3738
import org.codehaus.plexus.util.FileUtils;
3839
import org.eclipse.aether.DefaultRepositorySystemSession;
40+
import org.eclipse.aether.RepositorySystem;
3941
import org.eclipse.aether.internal.impl.DefaultLocalPathComposer;
4042
import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
4143
import org.eclipse.aether.repository.LocalRepository;
4244
import org.eclipse.aether.repository.RemoteRepository;
45+
import org.junit.Ignore;
4346
import org.mockito.InjectMocks;
4447
import org.mockito.MockitoAnnotations;
4548

@@ -470,10 +473,46 @@ public void testDeployIfArtifactFileIsNull() throws Exception {
470473

471474
try {
472475
mojo.execute();
476+
fail("Did not throw mojo execution exception");
477+
} catch (MojoExecutionException e) {
478+
// expected, message should include artifactId
479+
assertEquals(
480+
"The packaging plugin for project maven-deploy-test did not assign a file to the build artifact",
481+
e.getMessage());
482+
}
483+
}
484+
485+
public void testDeployIfProjectFileIsNull() throws Exception {
486+
File testPom = new File(getBasedir(), "target/test-classes/unit/basic-deploy-test/plugin-config.xml");
473487

488+
DeployMojo mojo = (DeployMojo) lookupMojo("deploy", testPom);
489+
490+
MockitoAnnotations.initMocks(this);
491+
492+
ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
493+
when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
494+
495+
setVariableValueToObject(mojo, "session", session);
496+
497+
assertNotNull(mojo);
498+
499+
MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
500+
project.setGroupId("org.apache.maven.test");
501+
project.setArtifactId("maven-deploy-test");
502+
project.setVersion("1.0-SNAPSHOT");
503+
504+
project.setFile(null);
505+
assertNull(project.getFile());
506+
507+
setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
508+
setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
509+
510+
try {
511+
mojo.execute();
474512
fail("Did not throw mojo execution exception");
475513
} catch (MojoExecutionException e) {
476-
// expected
514+
// expected, message should include artifactId
515+
assertEquals("The POM for project maven-deploy-test could not be attached", e.getMessage());
477516
}
478517
}
479518

@@ -568,6 +607,106 @@ public void testDeployWithAttachedArtifacts() throws Exception {
568607
assertEquals(0, getSizeOfExpectedFiles(fileList, expectedFiles));
569608
}
570609

610+
public void testNonPomDeployWithAttachedArtifactsOnly() throws Exception {
611+
File testPom = new File(
612+
getBasedir(), "target/test-classes/unit/basic-deploy-with-attached-artifacts/" + "plugin-config.xml");
613+
614+
mojo = (DeployMojo) lookupMojo("deploy", testPom);
615+
616+
MockitoAnnotations.initMocks(this);
617+
618+
assertNotNull(mojo);
619+
620+
ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
621+
when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
622+
623+
MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
624+
project.setGroupId("org.apache.maven.test");
625+
project.setArtifactId("maven-deploy-test");
626+
project.setVersion("1.0-SNAPSHOT");
627+
628+
setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
629+
setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
630+
631+
artifact = (DeployArtifactStub) project.getArtifact();
632+
artifact.setFile(null);
633+
634+
try {
635+
mojo.execute();
636+
fail("Did not throw mojo execution exception");
637+
} catch (MojoExecutionException e) {
638+
// expected, message should include artifactId
639+
assertEquals(
640+
"The packaging plugin for project maven-deploy-test did not assign a main file to the project "
641+
+ "but it has attachments. Change packaging to 'pom'.",
642+
e.getMessage());
643+
}
644+
}
645+
646+
@Ignore("SCP is not part of Maven3 distribution. Aether handles transport extensions.")
647+
public void _testBasicDeployWithScpAsProtocol() throws Exception {
648+
String originalUserHome = System.getProperty("user.home");
649+
650+
// FIX THE DAMN user.home BEFORE YOU DELETE IT!!!
651+
File altHome = new File(getBasedir(), "target/ssh-user-home");
652+
altHome.mkdirs();
653+
654+
System.out.println("Testing user.home value for .ssh dir: " + altHome.getCanonicalPath());
655+
656+
Properties props = System.getProperties();
657+
props.setProperty("user.home", altHome.getCanonicalPath());
658+
659+
System.setProperties(props);
660+
661+
File testPom = new File(getBasedir(), "target/test-classes/unit/basic-deploy-scp/plugin-config.xml");
662+
663+
mojo = (DeployMojo) lookupMojo("deploy", testPom);
664+
665+
assertNotNull(mojo);
666+
667+
RepositorySystem repositorySystem = mock(RepositorySystem.class);
668+
669+
setVariableValueToObject(mojo, "repositorySystem", repositorySystem);
670+
671+
File file = new File(
672+
getBasedir(),
673+
"target/test-classes/unit/basic-deploy-scp/target/" + "deploy-test-file-1.0-SNAPSHOT.jar");
674+
675+
assertTrue(file.exists());
676+
677+
MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
678+
679+
setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
680+
setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));
681+
682+
artifact = (DeployArtifactStub) project.getArtifact();
683+
684+
artifact.setFile(file);
685+
686+
String altUserHome = System.getProperty("user.home");
687+
688+
if (altUserHome.equals(originalUserHome)) {
689+
// this is *very* bad!
690+
throw new IllegalStateException(
691+
"Setting 'user.home' system property to alternate value did NOT work. Aborting test.");
692+
}
693+
694+
File sshFile = new File(altUserHome, ".ssh");
695+
696+
System.out.println("Testing .ssh dir: " + sshFile.getCanonicalPath());
697+
698+
// delete first the .ssh folder if existing before executing the mojo
699+
if (sshFile.exists()) {
700+
FileUtils.deleteDirectory(sshFile);
701+
}
702+
703+
mojo.execute();
704+
705+
assertTrue(sshFile.exists());
706+
707+
FileUtils.deleteDirectory(sshFile);
708+
}
709+
571710
public void testLegacyAltDeploymentRepositoryWithDefaultLayout() throws Exception {
572711
DeployMojo mojo = new DeployMojo();
573712

0 commit comments

Comments
 (0)