Skip to content

Commit 56c109a

Browse files
bondoloMike Duigou
and
Mike Duigou
authored
Add new showLint compiler configuration (#131)
* Add new showLint compiler configuration 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. * Update pom.xml remove added whitespace. Co-authored-by: Mike Duigou <bondolo@github.com>
1 parent b719a3b commit 56c109a

File tree

4 files changed

+48
-21
lines changed

4 files changed

+48
-21
lines changed

plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/CompilerConfiguration.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ public class CompilerConfiguration
6868
private String debugLevel;
6969

7070
private boolean showWarnings = true;
71-
71+
72+
private String warnings;
73+
7274
/**
7375
* -Werror argument as supported since Java 1.7
7476
*/
@@ -79,7 +81,7 @@ public class CompilerConfiguration
7981
private String sourceVersion;
8082

8183
private String targetVersion;
82-
84+
8385
/**
8486
* value of -release parameter in java 9+
8587
*/
@@ -354,16 +356,26 @@ public boolean isShowDeprecation()
354356
return showDeprecation;
355357
}
356358

359+
public String getWarnings()
360+
{
361+
return warnings;
362+
}
363+
364+
public void setShowLint( String warnings )
365+
{
366+
this.warnings = warnings;
367+
}
368+
357369
public void setShowDeprecation( boolean showDeprecation )
358370
{
359371
this.showDeprecation = showDeprecation;
360372
}
361-
373+
362374
public boolean isFailOnWarning()
363375
{
364376
return failOnWarning;
365377
}
366-
378+
367379
public void setFailOnWarning( boolean failOnWarnings )
368380
{
369381
this.failOnWarning = failOnWarnings;
@@ -388,7 +400,7 @@ public void setTargetVersion( String targetVersion )
388400
{
389401
this.targetVersion = targetVersion;
390402
}
391-
403+
392404
public String getReleaseVersion()
393405
{
394406
return releaseVersion;
@@ -451,7 +463,7 @@ public void setCustomCompilerArguments( LinkedHashMap<String, String> customComp
451463

452464
/**
453465
* Get all unique argument keys and their value. In case of duplicate keys, last one added wins.
454-
*
466+
*
455467
* @return
456468
* @see CompilerConfiguration#getCustomCompilerArgumentsEntries()
457469
*/
@@ -473,10 +485,10 @@ public void setCustomCompilerArgumentsAsMap( Map<String, String> customCompilerA
473485
this.customCompilerArguments.addAll( customCompilerArguments.entrySet() );
474486
}
475487
}
476-
488+
477489
/**
478490
* In case argument keys are not unique, this will return all entries
479-
*
491+
*
480492
* @return
481493
*/
482494
public Collection<Map.Entry<String,String>> getCustomCompilerArgumentsEntries()

plexus-compiler-its/src/main/it/simple-javac/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@
5555
</compilerArgs>
5656
</configuration>
5757
<dependencies>
58+
<dependency>
59+
<groupId>org.codehaus.plexus</groupId>
60+
<artifactId>plexus-compiler-api</artifactId>
61+
<version>@pom.version@</version>
62+
</dependency>
5863
<dependency>
5964
<groupId>org.codehaus.plexus</groupId>
6065
<artifactId>plexus-compiler-javac</artifactId>

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,10 @@ public CompilerResult performCompile( CompilerConfiguration config )
129129
}
130130
else
131131
{
132-
StringBuilder warns = new StringBuilder();
132+
String warnings = config.getWarnings();
133+
StringBuilder warns = StringUtils.isEmpty(warnings)
134+
? new StringBuilder()
135+
: new StringBuilder(warnings).append(',');
133136

134137
if ( config.isShowDeprecation() )
135138
{

plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public static String[] buildCompilerArguments( CompilerConfiguration config, Str
235235

236236
args.add( getPathString( classpathEntries ) );
237237
}
238-
238+
239239
List<String> modulepathEntries = config.getModulepathEntries();
240240
if ( modulepathEntries != null && !modulepathEntries.isEmpty() )
241241
{
@@ -343,8 +343,15 @@ public static String[] buildCompilerArguments( CompilerConfiguration config, Str
343343
if ( !config.isShowWarnings() )
344344
{
345345
args.add( "-nowarn" );
346+
} else
347+
{
348+
String warnings = config.getWarnings();
349+
if (StringUtils.isNotEmpty(warnings))
350+
{
351+
args.add("-Xlint:" + warnings);
352+
}
346353
}
347-
354+
348355
if ( config.isFailOnWarning() )
349356
{
350357
args.add( "-Werror" );
@@ -380,7 +387,7 @@ else if ( !suppressSource( config ) )
380387
{
381388
args.add( "-source" );
382389
args.add( config.getSourceVersion() );
383-
}
390+
}
384391
}
385392

386393

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

712719
StringBuilder buffer = new StringBuilder();
713-
720+
714721
boolean hasPointer = false;
715722

716723
while ( true )
717724
{
718725
line = input.readLine();
719-
726+
720727
if ( line == null )
721728
{
722729
// javac output not detected by other parsing
@@ -760,10 +767,10 @@ else if ( hasPointer )
760767
{
761768
// add the error bean
762769
errors.add( parseModernError( exitCode, buffer.toString() ) );
763-
770+
764771
// reset for next error block
765772
buffer = new StringBuilder(); // this is quicker than clearing it
766-
773+
767774
hasPointer = false;
768775
}
769776

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

792799
buffer.append( EOL );
793800
}
794-
801+
795802
if ( line.endsWith( "^" ) )
796803
{
797804
hasPointer = true;
798805
}
799806
}
800807
}
801-
808+
802809
private static boolean isMisc( String line )
803810
{
804811
return startsWithPrefix( line, MISC_PREFIXES );
@@ -808,7 +815,7 @@ private static boolean isNote( String line )
808815
{
809816
return startsWithPrefix( line, NOTE_PREFIXES );
810817
}
811-
818+
812819
private static boolean startsWithPrefix( String line, String[] prefixes )
813820
{
814821
for ( int i = 0; i < prefixes.length; i++ )
@@ -909,9 +916,9 @@ static CompilerMessage parseModernError( int exitCode, String error )
909916
msgBuffer.append( EOL );
910917

911918
String context = tokens.nextToken( EOL );
912-
919+
913920
String pointer = null;
914-
921+
915922
do
916923
{
917924
final String msgLine = tokens.nextToken( EOL );

0 commit comments

Comments
 (0)