Skip to content

Commit

Permalink
Ensure that EclipseJavaCompiler doesn't pass duplicate source files t…
Browse files Browse the repository at this point in the history
…o ECJ (#230)
  • Loading branch information
famod authored Jul 6, 2022
1 parent d09514d commit e136e4c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
import java.nio.charset.IllegalCharsetNameException;
import java.nio.charset.UnsupportedCharsetException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map.Entry;
Expand Down Expand Up @@ -245,7 +247,7 @@ public CompilerResult performCompile( CompilerConfiguration config )
}

// Collect sources
List<String> allSources = new ArrayList<>();
Set<String> allSources = new HashSet<>();
for ( String source : config.getSourceLocations() )
{
File srcFile = new File( source );
Expand Down Expand Up @@ -502,9 +504,9 @@ static boolean isReplaceProcessorPath( CompilerConfiguration config )
return false;
}

static List<String> resortSourcesToPutModuleInfoFirst( List<String> allSources )
static Set<String> resortSourcesToPutModuleInfoFirst( Set<String> allSources )
{
ArrayList<String> resorted = new ArrayList<>();
Set<String> resorted = new LinkedHashSet<>( allSources.size() );

for ( String mi : allSources )
{
Expand Down Expand Up @@ -652,7 +654,7 @@ private JavaCompiler getEcj()
return null;
}

private void addExtraSources( File dir, List<String> allSources )
private void addExtraSources( File dir, Set<String> allSources )
{
DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir( dir.getAbsolutePath() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import java.util.List;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.stream.Stream;

import static java.util.Arrays.asList;
Expand All @@ -14,42 +15,42 @@ class EclipseJavaCompilerTest
{
@ParameterizedTest
@MethodSource( "sources" )
void testReorderedSources( List<String> expected, List<String> inputSources )
void testReorderedSources( Set<String> expected, Set<String> inputSources )
{
List<String> resorted = EclipseJavaCompiler.resortSourcesToPutModuleInfoFirst( inputSources );
Set<String> resorted = EclipseJavaCompiler.resortSourcesToPutModuleInfoFirst( inputSources );

assertEquals( expected, resorted );
}

static Stream<Arguments> sources()
{
List<String> expectedOrder = asList(
Set<String> expectedOrder = new LinkedHashSet<>( asList(
"module-info.java",
"plexus/A.java",
"plexus/B.java",
"eclipse/A.java"
);
) );

List<String> moduleInfoAlreadyFirst = asList(
Set<String> moduleInfoAlreadyFirst = new LinkedHashSet<>( asList(
"module-info.java",
"plexus/A.java",
"plexus/B.java",
"eclipse/A.java"
);
) );

List<String> moduleInfoSomewhereInTheMiddle = asList(
Set<String> moduleInfoSomewhereInTheMiddle = new LinkedHashSet<>( asList(
"plexus/A.java",
"module-info.java",
"plexus/B.java",
"eclipse/A.java"
);
) );

List<String> moduleInfoAsLast = asList(
Set<String> moduleInfoAsLast = new LinkedHashSet<>( asList(
"plexus/A.java",
"plexus/B.java",
"eclipse/A.java",
"module-info.java"
);
) );

return Stream.of(
Arguments.arguments( expectedOrder, moduleInfoAlreadyFirst ),
Expand Down

0 comments on commit e136e4c

Please sign in to comment.