Skip to content

Commit

Permalink
Resort sources to have module-info.java first (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
pzygielo and pzygielo authored Feb 22, 2022
1 parent dd8d76d commit 88562f7
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
5 changes: 5 additions & 0 deletions plexus-compilers/plexus-compiler-eclipse/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ public CompilerResult performCompile( CompilerConfiguration config )
return new CompilerResult( true, messageList );
}

allSources = resortSourcesToPutModuleInfoFirst( allSources );

// Compile
try
{
Expand Down Expand Up @@ -476,6 +478,29 @@ public void worked( int i, int i1 )
}
}

static List<String> resortSourcesToPutModuleInfoFirst( List<String> allSources )
{
ArrayList<String> resorted = new ArrayList<>();

for ( String mi : allSources )
{
if ( mi.endsWith( "module-info.java" ) )
{
resorted.add( mi );
}
}

for ( String nmi : allSources )
{
if ( !nmi.endsWith( "module-info.java") )
{
resorted.add( nmi );
}
}

return resorted;
}

static boolean processCustomArguments( CompilerConfiguration config, List<String> args )
{
boolean result = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.codehaus.plexus.compiler.eclipse;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

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

import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.assertEquals;

class EclipseJavaCompilerTest
{
@ParameterizedTest
@MethodSource( "sources" )
void testReorderedSources( List<String> expected, List<String> inputSources )
{
List<String> resorted = EclipseJavaCompiler.resortSourcesToPutModuleInfoFirst( inputSources );

assertEquals( expected, resorted );
}

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

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

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

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

return Stream.of(
Arguments.arguments( expectedOrder, moduleInfoAlreadyFirst ),
Arguments.arguments( expectedOrder, moduleInfoSomewhereInTheMiddle ),
Arguments.arguments( expectedOrder, moduleInfoAsLast )
);
}
}

0 comments on commit 88562f7

Please sign in to comment.