From bfd0441db29d8418186b22df15f694594ef71f07 Mon Sep 17 00:00:00 2001 From: Alexey Loubyansky Date: Sun, 12 Mar 2023 22:02:56 +0100 Subject: [PATCH] A test to make sure non-existing modules are ignored during workspace discovery --- .../maven/workspace/WorkspaceLoader.java | 3 +++ .../test/LocalWorkspaceDiscoveryTest.java | 18 ++++++++++++++++++ .../root/module1/pom.xml | 13 +++++++++++++ .../workspace-missing-module/root/pom.xml | 14 ++++++++++++++ 4 files changed, 48 insertions(+) create mode 100644 independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-missing-module/root/module1/pom.xml create mode 100644 independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-missing-module/root/pom.xml diff --git a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/WorkspaceLoader.java b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/WorkspaceLoader.java index ea06a5bfc1f49..0cab46d8b25c3 100644 --- a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/WorkspaceLoader.java +++ b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/WorkspaceLoader.java @@ -194,6 +194,9 @@ private LocalProject loadParentProject(Path projectPom, final Model rawModel) th } private Path getParentPom(Path projectPom, Model rawModel) { + if (rawModel == null) { + return null; + } Path parentPom = null; final Path projectDir = projectPom.getParent(); final Parent parent = rawModel.getParent(); diff --git a/independent-projects/bootstrap/maven-resolver/src/test/java/io/quarkus/bootstrap/workspace/test/LocalWorkspaceDiscoveryTest.java b/independent-projects/bootstrap/maven-resolver/src/test/java/io/quarkus/bootstrap/workspace/test/LocalWorkspaceDiscoveryTest.java index 3f3f7b478e2ea..3a2e018bf0a0d 100644 --- a/independent-projects/bootstrap/maven-resolver/src/test/java/io/quarkus/bootstrap/workspace/test/LocalWorkspaceDiscoveryTest.java +++ b/independent-projects/bootstrap/maven-resolver/src/test/java/io/quarkus/bootstrap/workspace/test/LocalWorkspaceDiscoveryTest.java @@ -266,6 +266,24 @@ public void loadWorkspaceWithDirBreaks() throws Exception { assertEquals(4, ws.getProjects().size()); } + @Test + public void loadWorkspaceWithMissingModule() throws Exception { + final URL projectUrl = Thread.currentThread().getContextClassLoader().getResource("workspace-missing-module/root"); + assertNotNull(projectUrl); + final Path rootProjectDir = Paths.get(projectUrl.toURI()); + assertTrue(Files.exists(rootProjectDir)); + final Path nestedProjectDir = rootProjectDir.resolve("module1"); + assertTrue(Files.exists(nestedProjectDir)); + + final LocalWorkspace ws = new BootstrapMavenContext(BootstrapMavenContext.config() + .setCurrentProject(nestedProjectDir.toString())) + .getWorkspace(); + + assertNotNull(ws.getProject("org.acme", "module1")); + assertNotNull(ws.getProject("org.acme", "root")); + assertEquals(2, ws.getProjects().size()); + } + @Test public void loadWorkspaceRootWithNoModules() throws Exception { final URL projectUrl = Thread.currentThread().getContextClassLoader().getResource("workspace-root-no-module/root"); diff --git a/independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-missing-module/root/module1/pom.xml b/independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-missing-module/root/module1/pom.xml new file mode 100644 index 0000000000000..c2bd1297bbe6c --- /dev/null +++ b/independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-missing-module/root/module1/pom.xml @@ -0,0 +1,13 @@ + + + 4.0.0 + + + org.acme + root + 1.0 + + + module1 + pom + diff --git a/independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-missing-module/root/pom.xml b/independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-missing-module/root/pom.xml new file mode 100644 index 0000000000000..e944292d29d1d --- /dev/null +++ b/independent-projects/bootstrap/maven-resolver/src/test/resources/workspace-missing-module/root/pom.xml @@ -0,0 +1,14 @@ + + + 4.0.0 + + org.acme + root + 1.0 + pom + + + module1 + module2 + +