Skip to content

Commit

Permalink
add some java8 sugar syntax usage (#148)
Browse files Browse the repository at this point in the history
* add some java8 sugar syntax usage

Signed-off-by: olivier lamy <olamy@apache.org>

* more  java8 sugar syntax usage

Signed-off-by: olivier lamy <olamy@apache.org>
  • Loading branch information
olamy authored Feb 9, 2021
1 parent f767508 commit 2d1efa5
Show file tree
Hide file tree
Showing 15 changed files with 140 additions and 266 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ public class BuildSignaturesTask

private File destfile;

private Vector<Path> paths = new Vector<Path>();
private Vector<Path> paths = new Vector<>();

private Vector<Signature> signatures = new Vector<Signature>();
private Vector<Signature> signatures = new Vector<>();

private Vector<Ignore> includeClasses = new Vector<Ignore>();
private Vector<Ignore> includeClasses = new Vector<>();

private Vector<Ignore> excludeClasses = new Vector<Ignore>();
private Vector<Ignore> excludeClasses = new Vector<>();

public void setDestfile( File dest )
{
Expand Down Expand Up @@ -130,15 +130,15 @@ public void execute()
validate();
try
{
Vector<InputStream> inStreams = new Vector<InputStream>();
Vector<InputStream> inStreams = new Vector<>();
for ( Signature signature : signatures )
{
log( "Importing signatures from " + signature.getSrc() );
inStreams.add( new FileInputStream( signature.getSrc() ) );
}

SignatureBuilder builder =
new SignatureBuilder( inStreams.toArray( new InputStream[inStreams.size()] ),
new SignatureBuilder( inStreams.toArray( new InputStream[0] ),
new FileOutputStream( destfile ), new AntLogger( this ) );
for ( Ignore tmp: includeClasses )
{
Expand All @@ -151,10 +151,10 @@ public void execute()
for ( Path path : paths )
{
final String[] files = path.list();
for ( int j = 0; j < files.length; j++ )
for ( String file : files )
{
log( "Capturing signatures from " + files[j], Project.MSG_INFO );
process( builder, new File( files[j] ) );
log( "Capturing signatures from " + file, Project.MSG_INFO );
process( builder, new File( file ) );
}
}
builder.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.Vector;
Expand Down Expand Up @@ -64,11 +63,11 @@ public class CheckSignatureTask

private boolean failOnError = true;

private Vector<Path> paths = new Vector<Path>();
private Vector<Path> paths = new Vector<>();

private Vector<Ignore> ignores = new Vector<Ignore>();
private Vector<Ignore> ignores = new Vector<>();

private Vector<Annotation> annotations = new Vector<Annotation>();
private Vector<Annotation> annotations = new Vector<>();

public void addPath( Path path )
{
Expand Down Expand Up @@ -185,22 +184,20 @@ public void execute()
final SignatureChecker signatureChecker =
new SignatureChecker( new FileInputStream( signature ), ignoredPackages, new AntLogger( this ) );

final List<File> tmp = new ArrayList<File>();
final List<File> tmp = new ArrayList<>();
if (sourcepath != null) {
Iterator<?> i = sourcepath.iterator();
while ( i.hasNext() )
for ( Object next : sourcepath )
{
Object next = i.next();
if ( next instanceof FileResource )
{
final File file = ( (FileResource) next ).getFile();
tmp.add(file);
tmp.add( file );
}
}
}
signatureChecker.setSourcePath(tmp);

final Collection<String> annotationTypes = new HashSet<String>();
final Collection<String> annotationTypes = new HashSet<>();
for ( Annotation annotation : annotations )
{
if ( annotation != null && annotation.getClassName() != null )
Expand All @@ -213,9 +210,9 @@ public void execute()
for ( Path path : paths )
{
final String[] files = path.list();
for ( int j = 0; j < files.length; j++ )
for ( String file : files )
{
signatureChecker.process( new File( files[j] ) );
signatureChecker.process( new File( file ) );
}
}

Expand Down Expand Up @@ -269,18 +266,16 @@ private void apply( ClassFileVisitor v )
for ( Path path : paths )
{
final String[] files = path.list();
for ( int j = 0; j < files.length; j++ )
for ( String file : files )
{
log( "Ignoring the signatures from file to be checked: " + files[j], Project.MSG_INFO );
v.process( new File( files[j] ) );
log( "Ignoring the signatures from file to be checked: " + file, Project.MSG_INFO );
v.process( new File( file ) );
}
}
if ( classpath != null )
{
Iterator<?> i = classpath.iterator();
while ( i.hasNext() )
for ( Object next : classpath )
{
Object next = i.next();
if ( next instanceof FileResource )
{
final File file = ( (FileResource) next ).getFile();
Expand All @@ -290,4 +285,4 @@ private void apply( ClassFileVisitor v )
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,8 @@ public void execute( EnforcerRuleHelper helper )

if ( ignores != null )
{
for ( int i = 0; i < ignores.length; i++ )
for ( String ignore : ignores )
{
String ignore = ignores[i];
if ( ignore == null )
{
continue;
Expand Down Expand Up @@ -322,48 +321,49 @@ private void apply( ClassFileVisitor v, File outputDirectory, File testOutputDir
}

logger.debug( "Building list of classes from dependencies" );
for ( Iterator i = project.getArtifacts().iterator(); i.hasNext(); )
for ( Object o : project.getArtifacts() )
{

Artifact artifact = (Artifact) i.next();
Artifact artifact = (Artifact) o;

if ( !artifact.getArtifactHandler().isAddedToClasspath() ) {
logger.debug( "Skipping artifact " + artifactId( artifact )
+ " as it is not added to the classpath." );
if ( !artifact.getArtifactHandler().isAddedToClasspath() )
{
logger.debug(
"Skipping artifact " + artifactId( artifact ) + " as it is not added to the classpath." );
continue;
}

if ( !classpathScopes.contains( artifact.getScope() ) )
{
logger.debug( "Skipping artifact " + artifactId( artifact )
+ " as it is not on the "
+ ( checkTestClasses ? "test" : "compile" ) + " classpath." );
logger.debug( "Skipping artifact " + artifactId( artifact ) + " as it is not on the " + (
checkTestClasses
? "test"
: "compile" ) + " classpath." );
continue;
}

if ( includesFilter != null && !includesFilter.include( artifact ) )
{
logger.debug( "Skipping classes in artifact " + artifactId( artifact )
+ " as it does not match include rules." );
+ " as it does not match include rules." );
continue;
}

if ( excludesFilter != null && !excludesFilter.include( artifact ) )
{
logger.debug( "Skipping classes in artifact " + artifactId( artifact )
+ " as it does matches exclude rules." );
+ " as it does matches exclude rules." );
continue;
}

if ( artifact.getFile() == null )
{
logger.warn( "Skipping classes in artifact " + artifactId( artifact )
+ " as there are unresolved dependencies." );
+ " as there are unresolved dependencies." );
continue;
}

logger.debug( "Adding classes in artifact " + artifactId( artifact ) +
" to the ignores" );
logger.debug( "Adding classes in artifact " + artifactId( artifact ) + " to the ignores" );
v.process( artifact.getFile() );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,20 +380,20 @@ else if ( tc == null && jdk != null && jdk.getParameters() != null )
if ( includeClasses != null )
{
getLog().info( "Restricting signatures to include only the following classes:" );
for ( int i = 0; i < includeClasses.length; i++ )
for ( String includeClass : includeClasses )
{
getLog().info( " " + includeClasses[i] );
builder.addInclude( includeClasses[i] );
getLog().info( " " + includeClass );
builder.addInclude( includeClass );
}
}

if ( excludeClasses != null )
{
getLog().info( "Restricting signatures to exclude the following classes:" );
for ( int i = 0; i < excludeClasses.length; i++ )
for ( String excludeClass : excludeClasses )
{
getLog().info( " " + excludeClasses[i] );
builder.addExclude( excludeClasses[i] );
getLog().info( " " + excludeClass );
builder.addExclude( excludeClass );
}
}

Expand Down Expand Up @@ -422,7 +422,7 @@ private boolean detectJavaBootClasspath( String javaExecutable )
Artifact javaBootClasspathDetector = null;
while ( i.hasNext() && javaBootClasspathDetector == null )
{
Artifact candidate = (Artifact) i.next();
Artifact candidate = i.next();

if ( StringUtils.equals( jbcpdGroupId, candidate.getGroupId() )
&& StringUtils.equals( jbcpdArtifactId, candidate.getArtifactId() ) && candidate.getFile() != null
Expand Down Expand Up @@ -528,10 +528,8 @@ private void processModuleDependencies( SignatureBuilder builder )
? null
: new PatternExcludesArtifactFilter( Arrays.asList( excludeDependencies ) );

for ( Iterator<Artifact> i = project.getArtifacts().iterator(); i.hasNext(); )
for ( Artifact artifact : (Iterable<Artifact>) project.getArtifacts() )
{
Artifact artifact = i.next();

if ( includesFilter != null && !includesFilter.include( artifact ) )
{
getLog().debug( "Artifact " + artifactId( artifact ) + " ignored as it does not match include rules." );
Expand Down Expand Up @@ -569,17 +567,17 @@ private void processJavaBootClasspath( SignatureBuilder builder )
if ( includeJavaHome && javaHomeClassPath != null && javaHomeClassPath.length > 0 )
{
getLog().debug( "Parsing signatures java classpath:" );
for ( int i = 0; i < javaHomeClassPath.length; i++ )
for ( File file : javaHomeClassPath )
{
if ( javaHomeClassPath[i].isFile() || javaHomeClassPath[i].isDirectory() )
if ( file.isFile() || file.isDirectory() )
{
getLog().debug( "Processing " + javaHomeClassPath[i] );
builder.process( javaHomeClassPath[i] );
getLog().debug( "Processing " + file );
builder.process( file );
}
else
{
getLog().warn( "Could not add signatures from boot classpath element: " + javaHomeClassPath[i]
+ " as it does not exist." );
getLog().warn(
"Could not add signatures from boot classpath element: " + file + " as it does not exist." );
}
}
}
Expand All @@ -588,19 +586,16 @@ private void processJavaBootClasspath( SignatureBuilder builder )
private InputStream[] getBaseSignatures()
throws FileNotFoundException
{
List<InputStream> baseSignatures = new ArrayList<InputStream>();
for ( Iterator<Artifact> i = project.getArtifacts().iterator(); i.hasNext(); )
List<InputStream> baseSignatures = new ArrayList<>();
for ( Artifact artifact : (Iterable<Artifact>) project.getArtifacts() )
{
Artifact artifact = i.next();
if ( StringUtils.equals( "signature", artifact.getType() ) )
{
getLog().info( "Importing sigantures from " + artifact.getFile() );
baseSignatures.add( new FileInputStream( artifact.getFile() ) );
}
}
final InputStream[] baseSignatureInputStreams =
(InputStream[]) baseSignatures.toArray( new InputStream[baseSignatures.size()] );
return baseSignatureInputStreams;
return baseSignatures.toArray( new InputStream[0] );
}

/**
Expand Down Expand Up @@ -650,12 +645,12 @@ private Toolchain getJdkToolchainFromConfiguration()
try
{
final ToolchainPrivate[] tcp = getToolchains( "jdk" );
for ( int i = 0; i < tcp.length; i++ )
for ( ToolchainPrivate toolchainPrivate : tcp )
{
if ( tcp[i].getType().equals( "jdk" ) /* MNG-5716 */
&& tcp[i].matchesRequirements( jdk.getParameters() ) )
if ( toolchainPrivate.getType().equals( "jdk" ) /* MNG-5716 */
&& toolchainPrivate.matchesRequirements( jdk.getParameters() ) )
{
return tcp[i];
return toolchainPrivate;
}
}
}
Expand Down Expand Up @@ -715,9 +710,9 @@ private ToolchainPrivate[] getToolchains( String type )
buf.append( "\n\nCannot find a suitable 'getToolchainsForType' method. Available methods are:\n" );

Method[] methods = managerClass.getMethods();
for ( int i = 0; i < methods.length; i++ )
for ( Method method : methods )
{
buf.append( " " ).append( methods[i] ).append( '\n' );
buf.append( " " ).append( method ).append( '\n' );
}
throw new MojoExecutionException( buf.toString(), e );
}
Expand Down
Loading

0 comments on commit 2d1efa5

Please sign in to comment.