|
23 | 23 | import java.util.Collections;
|
24 | 24 | import java.util.List;
|
25 | 25 | import java.util.Objects;
|
| 26 | +import java.util.Properties; |
26 | 27 | import java.util.concurrent.ConcurrentHashMap;
|
27 | 28 |
|
28 | 29 | import org.apache.maven.execution.MavenSession;
|
|
36 | 37 | import org.apache.maven.project.ProjectBuildingRequest;
|
37 | 38 | import org.codehaus.plexus.util.FileUtils;
|
38 | 39 | import org.eclipse.aether.DefaultRepositorySystemSession;
|
| 40 | +import org.eclipse.aether.RepositorySystem; |
39 | 41 | import org.eclipse.aether.internal.impl.DefaultLocalPathComposer;
|
40 | 42 | import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
|
41 | 43 | import org.eclipse.aether.repository.LocalRepository;
|
42 | 44 | import org.eclipse.aether.repository.RemoteRepository;
|
| 45 | +import org.junit.Ignore; |
43 | 46 | import org.mockito.InjectMocks;
|
44 | 47 | import org.mockito.MockitoAnnotations;
|
45 | 48 |
|
@@ -470,10 +473,46 @@ public void testDeployIfArtifactFileIsNull() throws Exception {
|
470 | 473 |
|
471 | 474 | try {
|
472 | 475 | 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"); |
473 | 487 |
|
| 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(); |
474 | 512 | fail("Did not throw mojo execution exception");
|
475 | 513 | } 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()); |
477 | 516 | }
|
478 | 517 | }
|
479 | 518 |
|
@@ -568,6 +607,106 @@ public void testDeployWithAttachedArtifacts() throws Exception {
|
568 | 607 | assertEquals(0, getSizeOfExpectedFiles(fileList, expectedFiles));
|
569 | 608 | }
|
570 | 609 |
|
| 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 | + |
571 | 710 | public void testLegacyAltDeploymentRepositoryWithDefaultLayout() throws Exception {
|
572 | 711 | DeployMojo mojo = new DeployMojo();
|
573 | 712 |
|
|
0 commit comments