Skip to content

Commit d03646a

Browse files
committed
Resort sources to have module-info.java first
https://bugs.eclipse.org/bugs/show_bug.cgi?id=569833
1 parent dd8d76d commit d03646a

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

plexus-compilers/plexus-compiler-eclipse/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
<artifactId>junit-jupiter-api</artifactId>
3737
<scope>test</scope>
3838
</dependency>
39+
<dependency>
40+
<groupId>org.junit.jupiter</groupId>
41+
<artifactId>junit-jupiter-params</artifactId>
42+
<scope>test</scope>
43+
</dependency>
3944
<dependency>
4045
<groupId>org.hamcrest</groupId>
4146
<artifactId>hamcrest</artifactId>

plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.java

+25
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ public CompilerResult performCompile( CompilerConfiguration config )
262262
return new CompilerResult( true, messageList );
263263
}
264264

265+
allSources = resortSourcesToPutModuleInfoFirst( allSources );
266+
265267
// Compile
266268
try
267269
{
@@ -476,6 +478,29 @@ public void worked( int i, int i1 )
476478
}
477479
}
478480

481+
static List<String> resortSourcesToPutModuleInfoFirst( List<String> allSources )
482+
{
483+
ArrayList<String> resorted = new ArrayList<>();
484+
485+
for ( String mi : allSources )
486+
{
487+
if ( mi.endsWith( "module-info.java" ) )
488+
{
489+
resorted.add( mi );
490+
}
491+
}
492+
493+
for ( String nmi : allSources )
494+
{
495+
if ( !nmi.endsWith( "module-info.java") )
496+
{
497+
resorted.add( nmi );
498+
}
499+
}
500+
501+
return resorted;
502+
}
503+
479504
static boolean processCustomArguments( CompilerConfiguration config, List<String> args )
480505
{
481506
boolean result = false;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.codehaus.plexus.compiler.eclipse;
2+
3+
import org.junit.jupiter.params.ParameterizedTest;
4+
import org.junit.jupiter.params.provider.Arguments;
5+
import org.junit.jupiter.params.provider.MethodSource;
6+
7+
import java.util.List;
8+
import java.util.stream.Stream;
9+
10+
import static java.util.Arrays.asList;
11+
import static org.junit.jupiter.api.Assertions.assertEquals;
12+
13+
class EclipseJavaCompilerTest
14+
{
15+
@ParameterizedTest
16+
@MethodSource( "sources" )
17+
void testReorderedSources( List<String> expected, List<String> inputSources )
18+
{
19+
List<String> resorted = EclipseJavaCompiler.resortSourcesToPutModuleInfoFirst( inputSources );
20+
21+
assertEquals( expected, resorted );
22+
}
23+
24+
static Stream<Arguments> sources()
25+
{
26+
List<String> expectedOrder = asList(
27+
"module-info.java",
28+
"plexus/A.java",
29+
"plexus/B.java",
30+
"eclipse/A.java"
31+
);
32+
33+
List<String> moduleInfoAlreadyFirst = asList(
34+
"module-info.java",
35+
"plexus/A.java",
36+
"plexus/B.java",
37+
"eclipse/A.java"
38+
);
39+
40+
List<String> moduleInfoSomewhereInTheMiddle = asList(
41+
"plexus/A.java",
42+
"module-info.java",
43+
"plexus/B.java",
44+
"eclipse/A.java"
45+
);
46+
47+
List<String> moduleInfoAsLast = asList(
48+
"plexus/A.java",
49+
"plexus/B.java",
50+
"eclipse/A.java",
51+
"module-info.java"
52+
);
53+
54+
return Stream.of(
55+
Arguments.arguments( expectedOrder, moduleInfoAlreadyFirst ),
56+
Arguments.arguments( expectedOrder, moduleInfoSomewhereInTheMiddle ),
57+
Arguments.arguments( expectedOrder, moduleInfoAsLast )
58+
);
59+
}
60+
}

0 commit comments

Comments
 (0)