Skip to content

Ensure that EclipseJavaCompiler doesn't pass duplicate source files to ECJ #230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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