Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ private String getChildPathAdjustment(Model child, Model parent, String childDir
* repository. In other words, modules where artifactId != moduleDirName will see different effective URLs
* depending on how the model was constructed (from filesystem or from repository).
*/
if (child.getProjectDirectory() != null) {
if (child.getProjectDirectory() != null
&& child.getProjectDirectory().getFileName() != null) {
childName = child.getProjectDirectory().getFileName().toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

import org.apache.maven.api.model.Model;
import org.apache.maven.api.services.xml.XmlReaderRequest;
Expand All @@ -31,6 +32,7 @@
import org.xmlunit.builder.DiffBuilder;
import org.xmlunit.diff.Diff;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertFalse;

class DefaultInheritanceAssemblerTest {
Expand Down Expand Up @@ -58,6 +60,76 @@ void testPluginConfiguration() throws Exception {
testInheritance("plugin-configuration");
}

/**
* Check most classical urls inheritance: directory structure where parent POM in parent directory
* and child directory == artifactId
*/
@Test
void testUrls() throws Exception {
testInheritance("urls");
}

/**
* Flat directory structure: parent & child POMs in sibling directories, child directory == artifactId.
*/
@Test
void testFlatUrls() throws Exception {
testInheritance("flat-urls");
}

/**
* MNG-5951 MNG-6059 child.x.y.inherit.append.path="false" test
*/
@Test
void testNoAppendUrls() throws Exception {
testInheritance("no-append-urls");
}

/**
* MNG-5951 special case test: inherit with partial override
*/
@Test
void testNoAppendUrls2() throws Exception {
testInheritance("no-append-urls2");
}

/**
* MNG-5951 special case test: child.x.y.inherit.append.path="true" in child should not reset content
*/
@Test
void testNoAppendUrls3() throws Exception {
testInheritance("no-append-urls3");
}

@Test
void testWithEmptyUrl() throws Exception {
testInheritance("empty-urls", false);
}

@Test
void testModulePathNotArtifactId() throws Exception {
Model parent = getModel("module-path-not-artifactId-parent");
Model child = getModel("module-path-not-artifactId-child");

Model assembled = assembler.assembleModelInheritance(child, parent, null, null);

Path actual = Paths.get("target/test-classes/poms/inheritance/module-path-not-artifactId-actual.xml");
Files.createDirectories(actual.getParent());
xmlFactory.write(XmlWriterRequest.<Model>builder()
.content(assembled)
.path(actual)
.build());

Path expected = getPom("module-path-not-artifactId-expected");

Diff diff = DiffBuilder.compare(expected.toFile())
.withTest(actual.toFile())
.ignoreComments()
.ignoreWhitespace()
.build();
assertFalse(diff.hasDifferences(), "XML files should be identical: " + diff.toString());
}

public void testInheritance(String baseName) throws Exception {
testInheritance(baseName, false);
testInheritance(baseName, true);
Expand Down Expand Up @@ -95,4 +167,62 @@ public void testInheritance(String baseName, boolean fromRepo) throws Exception
.build();
assertFalse(diff.hasDifferences(), "XML files should be identical: " + diff.toString());
}

@Test
void testAssembleWithNullArtifactIdDoesNotThrowNpe() {
Model parent = Model.newBuilder()
.modelVersion("4.0.0")
.groupId("test")
.artifactId("parent")
.version("1.0")
.build();

Model child = Model.newBuilder()
.modelVersion("4.0.0")
.groupId("test")
.version("1.0")
.build();

assertDoesNotThrow(() -> assembler.assembleModelInheritance(child, parent, null, null));
}
Comment on lines +172 to +187

@Test
void testAssembleWithRootProjectDirectoryDoesNotThrowNpe() {
Model parent = Model.newBuilder()
.modelVersion("4.0.0")
.groupId("test")
.artifactId("parent")
.version("1.0")
.build();

Model child = Model.newBuilder()
.modelVersion("4.0.0")
.groupId("test")
.artifactId("child")
.version("1.0")
.pomFile(Paths.get("/pom.xml"))
.build();
Comment on lines +203 to +204

assertDoesNotThrow(() -> assembler.assembleModelInheritance(child, parent, null, null));
}

@Test
void testAssembleWithNullArtifactIdAndRootProjectDirectoryDoesNotThrowNpe() {
Model parent = Model.newBuilder()
.modelVersion("4.0.0")
.groupId("test")
.artifactId("parent")
.version("1.0")
.modules(List.of("../child/pom.xml"))
.build();
Comment on lines +216 to +217

Model child = Model.newBuilder()
.modelVersion("4.0.0")
.groupId("test")
.version("1.0")
.pomFile(Paths.get("/pom.xml"))
.build();

assertDoesNotThrow(() -> assembler.assembleModelInheritance(child, parent, null, null));
}
}
Loading