Merge pull request #7287 from aloubyansky/7195

Bootstrap/workspace discovery: check parent dir for pom.xml
This commit is contained in:
Georgios Andrianakis
2020-02-20 17:58:17 +02:00
committed by GitHub
2 changed files with 11 additions and 16 deletions

View File

@@ -80,25 +80,20 @@ public class LocalProject {
private static Model loadRootModel(Path currentProjectDir) throws BootstrapException {
Path pomXml = currentProjectDir.resolve(POM_XML);
Model model = readModel(pomXml);
Parent parent = model.getParent();
while (parent != null) {
if (parent.getRelativePath() != null && !parent.getRelativePath().isEmpty()) {
Model model = null;
while (Files.exists(pomXml)) {
model = readModel(pomXml);
final Parent parent = model.getParent();
if (parent != null
&& parent.getRelativePath() != null
&& !parent.getRelativePath().isEmpty()) {
pomXml = pomXml.getParent().resolve(parent.getRelativePath()).normalize();
if (!Files.exists(pomXml)) {
return model;
}
if (Files.isDirectory(pomXml)) {
pomXml = pomXml.resolve(POM_XML);
}
} else {
pomXml = pomXml.getParent().getParent().resolve(POM_XML);
if (!Files.exists(pomXml)) {
return model;
}
}
model = readModel(pomXml);
parent = model.getParent();
}
return model;
}

View File

@@ -107,10 +107,10 @@ public class LocalWorkspaceDiscoveryTest {
assertEquals("independent", project.getArtifactId());
assertEquals(MvnProjectBuilder.DEFAULT_VERSION, project.getVersion());
final Map<AppArtifactKey, LocalProject> projects = project.getWorkspace().getProjects();
assertEquals(1, projects.size());
assertEquals(6, projects.size());
assertTrue(projects.containsKey(new AppArtifactKey(MvnProjectBuilder.DEFAULT_GROUP_ID, "independent")));
assertLocalDeps(project);
assertLocalDeps(project, "root-module-not-direct-child", "root-no-parent-module", "root-module-with-parent");
}
@Test
@@ -135,9 +135,9 @@ public class LocalWorkspaceDiscoveryTest {
assertEquals(MvnProjectBuilder.DEFAULT_VERSION, project.getVersion());
assertNotNull(project.getWorkspace());
final Map<AppArtifactKey, LocalProject> projects = project.getWorkspace().getProjects();
assertEquals(1, projects.size());
assertEquals(5, projects.size());
assertTrue(projects.containsKey(new AppArtifactKey(MvnProjectBuilder.DEFAULT_GROUP_ID, "root-no-parent-module")));
assertLocalDeps(project);
assertLocalDeps(project, "root-module-not-direct-child");
}
@Test