Skip to content
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

Add new showLint compiler configuration #131

Merged
merged 2 commits into from
Apr 29, 2021
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 @@ -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 )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this lack of symmetry between get/set/field disturbing.
Also - other setShow*s seem to accept boolean.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pzygielo ah yes I agree It's confusing I will change that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes good point I agree

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pzygielo @bondolo what about #132
btw this fix the Xlint with no args which is possible

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem was that there was an existing showWarnings() flag. The intention was that the warnings flag would still control whether lint would be shown to avoid the weird corner case where warnings were disabled and lint was configured.
warnings enabled : show errors, warnings and "lint"
warnings disabled : show errors only.

{
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
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