Skip to content

Commit

Permalink
Merge pull request #31803 from aloubyansky/fix-npe-loading-workspace-…
Browse files Browse the repository at this point in the history
…modules

A test to make sure non-existing modules are ignored during workspace discovery
  • Loading branch information
gsmet authored Mar 14, 2023
2 parents 8b8c57b + e40820e commit 110fc5f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,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");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.acme</groupId>
<artifactId>root</artifactId>
<version>1.0</version>
</parent>

<artifactId>module1</artifactId>
<packaging>pom</packaging>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>

<groupId>org.acme</groupId>
<artifactId>root</artifactId>
<version>1.0</version>
<packaging>pom</packaging>

<modules>
<module>module1</module>
<module>module2</module>
</modules>
</project>

0 comments on commit 110fc5f

Please sign in to comment.