Skip to content

Commit

Permalink
Add new showLint compiler configuration
Browse files Browse the repository at this point in the history
Adds the ability to configure additional non-default compiler warnings and lint. To be
used for the javac -Xlint or similar features of the ECJ compiler.
  • Loading branch information
Mike Duigou committed Apr 27, 2021
1 parent b719a3b commit c0e5b7d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ public class CompilerConfiguration
private String debugLevel;

private boolean showWarnings = true;


private String warnings;

/**
* -Werror argument as supported since Java 1.7
*/
Expand All @@ -79,7 +81,7 @@ public class CompilerConfiguration
private String sourceVersion;

private String targetVersion;

/**
* value of -release parameter in java 9+
*/
Expand Down Expand Up @@ -354,16 +356,26 @@ public boolean isShowDeprecation()
return showDeprecation;
}

public String getWarnings()
{
return warnings;
}

public void setShowLint( String warnings )
{
this.warnings = warnings;
}

public void setShowDeprecation( boolean showDeprecation )
{
this.showDeprecation = showDeprecation;
}

public boolean isFailOnWarning()
{
return failOnWarning;
}

public void setFailOnWarning( boolean failOnWarnings )
{
this.failOnWarning = failOnWarnings;
Expand All @@ -388,7 +400,7 @@ public void setTargetVersion( String targetVersion )
{
this.targetVersion = targetVersion;
}

public String getReleaseVersion()
{
return releaseVersion;
Expand Down Expand Up @@ -451,7 +463,7 @@ public void setCustomCompilerArguments( LinkedHashMap<String, String> customComp

/**
* Get all unique argument keys and their value. In case of duplicate keys, last one added wins.
*
*
* @return
* @see CompilerConfiguration#getCustomCompilerArgumentsEntries()
*/
Expand All @@ -473,10 +485,10 @@ public void setCustomCompilerArgumentsAsMap( Map<String, String> customCompilerA
this.customCompilerArguments.addAll( customCompilerArguments.entrySet() );
}
}

/**
* In case argument keys are not unique, this will return all entries
*
*
* @return
*/
public Collection<Map.Entry<String,String>> getCustomCompilerArgumentsEntries()
Expand Down
6 changes: 3 additions & 3 deletions plexus-compiler-its/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler</artifactId>
<version>2.8.9-SNAPSHOT</version>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler</artifactId>
<version>2.8.9-SNAPSHOT</version>
</parent>

<artifactId>plexus-compiler-its</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions plexus-compiler-its/src/main/it/simple-javac/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
</compilerArgs>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-api</artifactId>
<version>@pom.version@</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-javac</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ public CompilerResult performCompile( CompilerConfiguration config )
}
else
{
StringBuilder warns = new StringBuilder();
String warnings = config.getWarnings();
StringBuilder warns = StringUtils.isEmpty(warnings)
? new StringBuilder()
: new StringBuilder(warnings).append(',');

if ( config.isShowDeprecation() )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public static String[] buildCompilerArguments( CompilerConfiguration config, Str

args.add( getPathString( classpathEntries ) );
}

List<String> modulepathEntries = config.getModulepathEntries();
if ( modulepathEntries != null && !modulepathEntries.isEmpty() )
{
Expand Down Expand Up @@ -343,8 +343,15 @@ public static String[] buildCompilerArguments( CompilerConfiguration config, Str
if ( !config.isShowWarnings() )
{
args.add( "-nowarn" );
} else
{
String warnings = config.getWarnings();
if (StringUtils.isNotEmpty(warnings))
{
args.add("-Xlint:" + warnings);
}
}

if ( config.isFailOnWarning() )
{
args.add( "-Werror" );
Expand Down Expand Up @@ -380,7 +387,7 @@ else if ( !suppressSource( config ) )
{
args.add( "-source" );
args.add( config.getSourceVersion() );
}
}
}


Expand Down Expand Up @@ -710,13 +717,13 @@ static List<CompilerMessage> parseModernStream( int exitCode, BufferedReader inp
String line;

StringBuilder buffer = new StringBuilder();

boolean hasPointer = false;

while ( true )
{
line = input.readLine();

if ( line == null )
{
// javac output not detected by other parsing
Expand Down Expand Up @@ -760,10 +767,10 @@ else if ( hasPointer )
{
// add the error bean
errors.add( parseModernError( exitCode, buffer.toString() ) );

// reset for next error block
buffer = new StringBuilder(); // this is quicker than clearing it

hasPointer = false;
}

Expand Down Expand Up @@ -791,14 +798,14 @@ else if ( ( buffer.length() == 0 ) && isMisc( line ) )

buffer.append( EOL );
}

if ( line.endsWith( "^" ) )
{
hasPointer = true;
}
}
}

private static boolean isMisc( String line )
{
return startsWithPrefix( line, MISC_PREFIXES );
Expand All @@ -808,7 +815,7 @@ private static boolean isNote( String line )
{
return startsWithPrefix( line, NOTE_PREFIXES );
}

private static boolean startsWithPrefix( String line, String[] prefixes )
{
for ( int i = 0; i < prefixes.length; i++ )
Expand Down Expand Up @@ -909,9 +916,9 @@ static CompilerMessage parseModernError( int exitCode, String error )
msgBuffer.append( EOL );

String context = tokens.nextToken( EOL );

String pointer = null;

do
{
final String msgLine = tokens.nextToken( EOL );
Expand Down

0 comments on commit c0e5b7d

Please sign in to comment.