|
19 | 19 | package org.apache.maven.doxia.tools;
|
20 | 20 |
|
21 | 21 | import javax.inject.Inject;
|
22 |
| -import javax.inject.Named; |
23 | 22 |
|
24 | 23 | import java.io.File;
|
25 | 24 | import java.io.StringReader;
|
|
32 | 31 | import java.util.List;
|
33 | 32 | import java.util.Locale;
|
34 | 33 |
|
35 |
| -import org.apache.maven.artifact.repository.ArtifactRepository; |
36 |
| -import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; |
37 |
| -import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; |
38 |
| -import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; |
39 | 34 | import org.apache.maven.doxia.site.LinkItem;
|
40 | 35 | import org.apache.maven.doxia.site.SiteModel;
|
41 | 36 | import org.apache.maven.doxia.site.Skin;
|
42 | 37 | import org.apache.maven.doxia.site.io.xpp3.SiteXpp3Reader;
|
43 | 38 | import org.apache.maven.doxia.site.io.xpp3.SiteXpp3Writer;
|
| 39 | +import org.apache.maven.doxia.tools.stubs.MavenProjectStub; |
44 | 40 | import org.apache.maven.doxia.tools.stubs.SiteToolMavenProjectStub;
|
45 | 41 | import org.apache.maven.project.MavenProject;
|
46 | 42 | import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
|
47 |
| -import org.codehaus.plexus.PlexusContainer; |
48 | 43 | import org.codehaus.plexus.testing.PlexusTest;
|
49 | 44 | import org.codehaus.plexus.util.FileUtils;
|
50 | 45 | import org.codehaus.plexus.util.IOUtil;
|
|
61 | 56 | import static org.junit.jupiter.api.Assertions.assertNotNull;
|
62 | 57 | import static org.junit.jupiter.api.Assertions.assertNotSame;
|
63 | 58 | import static org.junit.jupiter.api.Assertions.assertNull;
|
| 59 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
64 | 60 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
65 | 61 |
|
66 | 62 | /**
|
|
70 | 66 | @PlexusTest
|
71 | 67 | public class SiteToolTest {
|
72 | 68 |
|
73 |
| - @Inject |
74 |
| - private PlexusContainer container; |
75 |
| - |
76 |
| - @Inject |
77 |
| - private ArtifactRepositoryFactory artifactRepositoryFactory; |
78 |
| - |
79 |
| - @Inject |
80 |
| - @Named("default") |
81 |
| - private ArtifactRepositoryLayout defaultArtifactRepositoryLayout; |
82 |
| - |
83 | 69 | @Inject
|
84 | 70 | private DefaultSiteTool tool;
|
85 | 71 |
|
86 |
| - /** |
87 |
| - * @return the repo. |
88 |
| - * |
89 |
| - * @throws Exception |
90 |
| - */ |
91 |
| - protected ArtifactRepository getLocalRepo() throws Exception { |
92 |
| - String updatePolicyFlag = ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS; |
93 |
| - String checksumPolicyFlag = ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN; |
94 |
| - ArtifactRepositoryPolicy snapshotsPolicy = |
95 |
| - new ArtifactRepositoryPolicy(true, updatePolicyFlag, checksumPolicyFlag); |
96 |
| - ArtifactRepositoryPolicy releasesPolicy = |
97 |
| - new ArtifactRepositoryPolicy(true, updatePolicyFlag, checksumPolicyFlag); |
98 |
| - return artifactRepositoryFactory.createArtifactRepository( |
99 |
| - "local", |
100 |
| - getTestFile("target/local-repo").toURI().toURL().toString(), |
101 |
| - defaultArtifactRepositoryLayout, |
102 |
| - snapshotsPolicy, |
103 |
| - releasesPolicy); |
104 |
| - } |
105 |
| - |
106 | 72 | /**
|
107 | 73 | * @return the local repo directory.
|
108 | 74 | *
|
109 | 75 | * @throws Exception
|
110 | 76 | */
|
111 | 77 | protected File getLocalRepoDir() throws Exception {
|
112 |
| - return new File(getLocalRepo().getBasedir()); |
| 78 | + return getTestFile("target/local-repo"); |
113 | 79 | }
|
114 | 80 |
|
115 | 81 | protected RepositorySystemSession newRepoSession() throws Exception {
|
@@ -567,6 +533,59 @@ public void testConvertOldToNewSiteModel() throws Exception {
|
567 | 533 | assertEquals(newModel, model);
|
568 | 534 | }
|
569 | 535 |
|
| 536 | + @Test |
| 537 | + public void testRequireParent() throws SiteToolException, Exception { |
| 538 | + assertNotNull(tool); |
| 539 | + |
| 540 | + SiteToolMavenProjectStub project = new SiteToolMavenProjectStub("require-parent-test"); |
| 541 | + MavenProjectStub parentProject = new MavenProjectStub() { |
| 542 | + @Override |
| 543 | + public File getBasedir() { |
| 544 | + return null; // this should be a non reactor/local project |
| 545 | + } |
| 546 | + }; |
| 547 | + parentProject.setGroupId("org.apache.maven.shared.its"); |
| 548 | + parentProject.setArtifactId("mshared-217-parent"); |
| 549 | + parentProject.setVersion("1.0-SNAPSHOT"); |
| 550 | + project.setParent(parentProject); |
| 551 | + List<MavenProject> reactorProjects = new ArrayList<MavenProject>(); |
| 552 | + |
| 553 | + RepositorySystemSession repoSession = newRepoSession(); |
| 554 | + // coordinates for site descriptor: <groupId>:<artifactId>:xml:site:<version> |
| 555 | + new SiteToolMavenProjectStub("require-parent-test"); |
| 556 | + org.eclipse.aether.artifact.Artifact parentArtifact = new org.eclipse.aether.artifact.DefaultArtifact( |
| 557 | + "org.apache.maven.shared.its:mshared-217-parent:xml:site:1.0-SNAPSHOT"); |
| 558 | + File parentArtifactInRepoFile = new File( |
| 559 | + repoSession.getLocalRepository().getBasedir(), |
| 560 | + repoSession.getLocalRepositoryManager().getPathForLocalArtifact(parentArtifact)); |
| 561 | + |
| 562 | + // model from current local build |
| 563 | + assertThrows( |
| 564 | + SiteToolException.class, |
| 565 | + () -> tool.getSiteModel( |
| 566 | + new File(project.getBasedir(), "src/site"), |
| 567 | + SiteTool.DEFAULT_LOCALE, |
| 568 | + project, |
| 569 | + reactorProjects, |
| 570 | + repoSession, |
| 571 | + project.getRemoteProjectRepositories())); |
| 572 | + |
| 573 | + // now copy parent site descriptor to repo |
| 574 | + FileUtils.copyFile( |
| 575 | + getTestFile("src/test/resources/unit/require-parent-test/parent-site.xml"), parentArtifactInRepoFile); |
| 576 | + try { |
| 577 | + tool.getSiteModel( |
| 578 | + new File(project.getBasedir(), "src/site"), |
| 579 | + SiteTool.DEFAULT_LOCALE, |
| 580 | + project, |
| 581 | + reactorProjects, |
| 582 | + repoSession, |
| 583 | + project.getRemoteProjectRepositories()); |
| 584 | + } finally { |
| 585 | + parentArtifactInRepoFile.delete(); |
| 586 | + } |
| 587 | + } |
| 588 | + |
570 | 589 | private void writeModel(SiteModel model, String to) throws Exception {
|
571 | 590 | Writer writer = WriterFactory.newXmlWriter(getTestFile("target/test-classes/" + to));
|
572 | 591 | try {
|
|
0 commit comments