Skip to content

Commit 9d1909b

Browse files
committed
#54 Duplicate module handled incorrectly
1 parent 020a7f2 commit 9d1909b

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

plexus-java/src/main/java/org/codehaus/plexus/languages/java/jpms/LocationManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,10 @@ public String extract( Path path )
210210
continue;
211211
}
212212

213-
if ( moduleDescriptor != null )
213+
// Consider strategies how to handle duplicate modules by name
214+
// For now, just ignore it
215+
if ( moduleDescriptor != null && moduleNameSources.putIfAbsent( moduleDescriptor.name(), source ) == null )
214216
{
215-
moduleNameSources.put( moduleDescriptor.name(), source );
216-
217217
availableNamedModules.put( moduleDescriptor.name(), moduleDescriptor );
218218

219219
if ( request.isIncludeAllProviders() )

plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/LocationManagerIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import static org.hamcrest.CoreMatchers.is;
2323
import static org.hamcrest.CoreMatchers.not;
2424
import static org.hamcrest.CoreMatchers.startsWith;
25-
import static org.junit.Assert.assertThat;
25+
import static org.hamcrest.MatcherAssert.assertThat;
2626
import static org.junit.Assume.assumeThat;
2727
import static org.mockito.ArgumentMatchers.any;
2828
import static org.mockito.Mockito.when;

plexus-java/src/test/java/org/codehaus/plexus/languages/java/jpms/LocationManagerTest.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import static org.hamcrest.CoreMatchers.is;
2323
import static org.hamcrest.CoreMatchers.nullValue;
24-
import static org.junit.Assert.assertThat;
24+
import static org.hamcrest.MatcherAssert.assertThat;
2525
import static org.mockito.ArgumentMatchers.any;
2626
import static org.mockito.Mockito.when;
2727

@@ -410,5 +410,31 @@ public void testDirectStatic() throws Exception
410410
assertThat( result.getClasspathElements().contains( moduleC ), is( true ) );
411411
assertThat( result.getPathExceptions().size(), is( 0 ) );
412412
}
413+
414+
@Test
415+
public void testDuplicateModule() throws Exception
416+
{
417+
Path moduleA = Paths.get( "src/test/resources/mock/module-info.java" ); // some file called module-info.java
418+
Path moduleB = Paths.get( "src/test/resources/mock/jar0.jar" ); // any existing file
419+
Path moduleC = Paths.get( "src/test/resources/mock/jar1.jar" ); // any existing file
420+
421+
ResolvePathsRequest<Path> request = ResolvePathsRequest.ofPaths( moduleB, moduleC ).setMainModuleDescriptor( moduleA );
422+
423+
when( qdoxParser.fromSourcePath( moduleA ) ).thenReturn( JavaModuleDescriptor.newModule( "moduleA" )
424+
.requires( "anonymous" )
425+
.build() );
426+
when( asmParser.getModuleDescriptor( moduleB ) ).thenReturn( JavaModuleDescriptor.newModule( "anonymous" )
427+
.build() );
428+
when( asmParser.getModuleDescriptor( moduleC ) ).thenReturn( JavaModuleDescriptor.newModule( "anonymous" )
429+
.build() );
430+
431+
ResolvePathsResult<Path> result = locationManager.resolvePaths( request );
432+
assertThat( result.getPathElements().size(), is( 2 ) );
433+
assertThat( result.getModulepathElements().size(), is( 1 ) );
434+
assertThat( result.getModulepathElements().containsKey( moduleB ), is( true ) );
435+
// with current default the duplicate will be ignored
436+
assertThat( result.getClasspathElements().size(), is( 0 ) );
437+
assertThat( result.getPathExceptions().size(), is( 0 ) );
438+
}
413439

414440
}

0 commit comments

Comments
 (0)