diff --git a/pom.xml b/pom.xml index 516d77e1..4f062934 100644 --- a/pom.xml +++ b/pom.xml @@ -65,7 +65,7 @@ under the License. - 7 + 8 3.1.1 1.9.1 1.9.2 diff --git a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java index 7ee143ee..44d4a7e1 100644 --- a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java +++ b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java @@ -22,7 +22,6 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Model; -import org.apache.maven.model.Profile; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecution; import org.apache.maven.plugin.MojoExecutionException; @@ -90,7 +89,6 @@ import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; @@ -98,11 +96,9 @@ import java.util.HashSet; import java.util.LinkedHashMap; import java.util.LinkedHashSet; -import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.Map.Entry; import java.util.Properties; import java.util.Set; import java.util.StringTokenizer; @@ -110,6 +106,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; import static org.apache.maven.shared.utils.logging.MessageUtils.buffer; @@ -886,15 +883,10 @@ private void setupReportsFolder() private List getNonSetupJobs( List buildJobs ) { - List result = new LinkedList<>(); - for ( BuildJob buildJob : buildJobs ) - { - if ( !buildJob.getType().equals( BuildJob.Type.SETUP ) ) - { - result.add( buildJob ); - } - } - return result; + return buildJobs.stream(). + filter( buildJob -> !buildJob.getType().equals( BuildJob.Type.SETUP ) ). + collect( Collectors.toList() ); + } private void handleScriptRunnerWithScriptClassPath() @@ -917,10 +909,7 @@ private void handleScriptRunnerWithScriptClassPath() scriptRunner.setGlobalVariable( "localRepositoryPath", localRepositoryPath ); if ( scriptVariables != null ) { - for ( Entry entry : scriptVariables.entrySet() ) - { - scriptRunner.setGlobalVariable( entry.getKey(), entry.getValue() ); - } + scriptVariables.forEach( ( key, value ) -> scriptRunner.setGlobalVariable( key, value ) ); } scriptRunner.setClassPath( scriptClassPath ); } @@ -1057,14 +1046,10 @@ else if ( !pomFile.isFile() ) collectProjects( projectsDir, parent, projectPaths, false ); } - Collection modulePaths = new LinkedHashSet<>(); + Collection modulePaths = new LinkedHashSet<>( model.getModules() ); - modulePaths.addAll( model.getModules() ); + model.getProfiles().forEach( profile -> modulePaths.addAll( profile.getModules() ) ); - for ( Profile profile : model.getProfiles() ) - { - modulePaths.addAll( profile.getModules() ); - } for ( String modulePath : modulePaths ) { @@ -1399,21 +1384,18 @@ private void runBuilds( final File projectsDir, List buildJobs, int ru ExecutorService executorService = Executors.newFixedThreadPool( runWithParallelThreads ); for ( final BuildJob job : buildJobs ) { - executorService.execute( new Runnable() + executorService.execute( () -> { - public void run() + try + { + Path ancestorFolder = getAncestorFolder( projectsPath.resolve( job.getProject() ) ); + + runBuild( projectsDir, job, mergedSettingsFile, javaHome, actualJreVersion, + globalInvokerProperties.get( ancestorFolder ) ); + } + catch ( MojoExecutionException e ) { - try - { - Path ancestorFolder = getAncestorFolder( projectsPath.resolve( job.getProject() ) ); - - runBuild( projectsDir, job, mergedSettingsFile, javaHome, actualJreVersion, - globalInvokerProperties.get( ancestorFolder ) ); - } - catch ( MojoExecutionException e ) - { - throw new RuntimeException( e.getMessage(), e ); - } + throw new RuntimeException( e.getMessage(), e ); } } ); } @@ -1623,13 +1605,7 @@ private CharSequence resolveExternalJreVersion() commandLine.createArg().setValue( "java.version" ); final StringBuilder actualJreVersion = new StringBuilder(); - StreamConsumer consumer = new StreamConsumer() - { - public void consumeLine( String line ) - { - actualJreVersion.append( line ); - } - }; + StreamConsumer consumer = actualJreVersion::append; try { CommandLineUtils.executeCommandLine( commandLine, consumer, null ); @@ -1809,12 +1785,12 @@ private void runBuild( File projectsDir, BuildJob buildJob, File settingsFile, F if ( !suppressSummaries ) { - getLog().info( pad( buildJob ).warning( "SKIPPED" ) + " due to " + message.toString() ); + getLog().info( pad( buildJob ).warning( "SKIPPED" ) + " due to " + message ); } // Abuse failureMessage, the field in the report which should contain the reason for skipping // Consider skipCode + I18N - buildJob.setFailureMessage( "Skipped due to " + message.toString() ); + buildJob.setFailureMessage( "Skipped due to " + message ); } } catch ( RunFailureException e ) @@ -2038,7 +2014,7 @@ private boolean runBuild( File basedir, File pomFile, File settingsFile, File ac { Properties props = invokerProperties.getProperties(); getLog().debug( "Using invoker properties:" ); - for ( String key : new TreeSet( props.stringPropertyNames() ) ) + for ( String key : new TreeSet<>( props.stringPropertyNames() ) ) { String value = props.getProperty( key ); getLog().debug( " " + key + " = " + value ); @@ -2427,7 +2403,7 @@ private List calculateExcludes() throws IOException { List excludes = - ( pomExcludes != null ) ? new ArrayList<>( pomExcludes ) : new ArrayList(); + ( pomExcludes != null ) ? new ArrayList<>( pomExcludes ) : new ArrayList<>(); if ( this.settingsFile != null ) { String exclude = relativizePath( this.settingsFile, projectsDirectory.getCanonicalPath() ); @@ -2460,14 +2436,14 @@ private List getSetupBuildJobsFromFolders() return setupPoms; } - private static class OrdinalComparator implements Comparator + private static class OrdinalComparator implements Comparator { private static final OrdinalComparator INSTANCE = new OrdinalComparator(); @Override - public int compare( Object o1, Object o2 ) + public int compare( BuildJob o1, BuildJob o2 ) { - return Integer.compare( ( ( BuildJob ) o2 ).getOrdinal(), ( ( BuildJob ) o1 ).getOrdinal() ); + return Integer.compare( o2.getOrdinal(), o1.getOrdinal() ); } } @@ -2489,7 +2465,7 @@ List getBuildJobs() List setupPoms = scanProjectsDirectory( setupIncludes, excludes, BuildJob.Type.SETUP ); if ( getLog().isDebugEnabled() ) { - getLog().debug( "Setup projects: " + Arrays.asList( setupPoms ) ); + getLog().debug( "Setup projects: " + Collections.singletonList( setupPoms ) ); } List normalPoms = scanProjectsDirectory( pomIncludes, excludes, BuildJob.Type.NORMAL ); @@ -2563,11 +2539,11 @@ private List scanProjectsDirectory( List includes, List scanProjectsDirectory( List includes, ListemptyList() ) ); + new PatternExclusionsFilter( Collections.emptyList() ) ); } finally { @@ -637,7 +633,7 @@ private void installExtraArtifacts( String[] extraArtifacts ) else { resolver.resolveDependencies( projectBuildingRequest, coordinate, - new PatternExclusionsFilter( Collections.emptyList() ) ); + new PatternExclusionsFilter( Collections.emptyList() ) ); } } catch ( DependencyResolverException e ) @@ -647,15 +643,4 @@ private void installExtraArtifacts( String[] extraArtifacts ) } } - // FIXME could be simplify with using lambda... maybe in the next century... :P - private List toArtifactsList( Iterable artifactResults ) - { - List artifacts = new ArrayList<>( ); - for ( ArtifactResult artifactResult : artifactResults ) - { - artifacts.add( artifactResult.getArtifact() ); - } - return artifacts; - } - } diff --git a/src/main/java/org/apache/maven/plugins/invoker/MetadataUtils.java b/src/main/java/org/apache/maven/plugins/invoker/MetadataUtils.java index ad816e50..6588b978 100644 --- a/src/main/java/org/apache/maven/plugins/invoker/MetadataUtils.java +++ b/src/main/java/org/apache/maven/plugins/invoker/MetadataUtils.java @@ -82,7 +82,7 @@ public static void createMetadata( File file, Artifact artifact ) File metadataFile = new File( file.getParentFile().getParentFile(), "maven-metadata-local.xml" ); - Set allVersions = new LinkedHashSet(); + Set allVersions = new LinkedHashSet<>(); Xpp3Dom metadata = readMetadata( metadataFile ); @@ -150,7 +150,7 @@ private static Xpp3Dom readMetadata( File metadataFile ) } catch ( XmlPullParserException e ) { - throw (IOException) new IOException( e.getMessage() ).initCause( e ); + throw new IOException( e.getMessage(), e ); } } diff --git a/src/main/java/org/apache/maven/plugins/invoker/Selector.java b/src/main/java/org/apache/maven/plugins/invoker/Selector.java index 4fde5df3..6f6cfbab 100644 --- a/src/main/java/org/apache/maven/plugins/invoker/Selector.java +++ b/src/main/java/org/apache/maven/plugins/invoker/Selector.java @@ -111,7 +111,7 @@ private int getGlobal( InvokerProperties invokerProperties ) selection |= SELECTOR_MAVENVERSION; } - if ( !SelectorUtils.isJreVersion( invokerProperties.getJreVersion(), actualJavaVersion.toString() ) ) + if ( !SelectorUtils.isJreVersion( invokerProperties.getJreVersion(), actualJavaVersion ) ) { selection |= SELECTOR_JREVERSION; } diff --git a/src/main/java/org/apache/maven/plugins/invoker/SelectorUtils.java b/src/main/java/org/apache/maven/plugins/invoker/SelectorUtils.java index db509e09..a1449376 100644 --- a/src/main/java/org/apache/maven/plugins/invoker/SelectorUtils.java +++ b/src/main/java/org/apache/maven/plugins/invoker/SelectorUtils.java @@ -20,15 +20,16 @@ */ import java.io.File; -import java.io.FilenameFilter; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Properties; +import java.util.stream.Collectors; import org.apache.maven.plugins.invoker.AbstractInvokerMojo.ToolchainPrivateManager; import org.apache.maven.project.MavenProject; @@ -121,13 +122,7 @@ static String getMavenVersion() static String getMavenVersion( File mavenHome ) { File mavenLib = new File( mavenHome, "lib" ); - File[] jarFiles = mavenLib.listFiles( new FilenameFilter() - { - public boolean accept( File dir, String name ) - { - return name.endsWith( ".jar" ); - } - } ); + File[] jarFiles = mavenLib.listFiles( ( dir, name ) -> name.endsWith( ".jar" ) ); for ( File file : jarFiles ) { @@ -192,8 +187,8 @@ static boolean isJreVersion( String jreSpec ) static boolean isJreVersion( String jreSpec, String actualJreVersion ) { - List includes = new ArrayList(); - List excludes = new ArrayList(); + List includes = new ArrayList<>(); + List excludes = new ArrayList<>(); parseList( jreSpec, includes, excludes ); List jreVersion = parseVersion( actualJreVersion ); @@ -249,12 +244,7 @@ static List parseVersion( String version ) String[] tokens = StringUtils.split( version, "." ); - List numbers = new ArrayList(); - - for ( String token : tokens ) - { - numbers.add( Integer.valueOf( token ) ); - } + List numbers = Arrays.stream( tokens ).map( Integer::valueOf ).collect( Collectors.toList() ); return numbers; } diff --git a/src/test/java/org/apache/maven/plugins/invoker/InterpolationTest.java b/src/test/java/org/apache/maven/plugins/invoker/InterpolationTest.java index bf11628b..cd75a75e 100644 --- a/src/test/java/org/apache/maven/plugins/invoker/InterpolationTest.java +++ b/src/test/java/org/apache/maven/plugins/invoker/InterpolationTest.java @@ -21,7 +21,7 @@ import java.io.File; import java.io.Reader; -import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Properties; @@ -114,7 +114,7 @@ public void testProfilesWithNoFile() { InvokerMojo invokerMojo = new InvokerMojo(); - setVariableValueToObject( invokerMojo, "profiles", Arrays.asList( "zloug" ) ); + setVariableValueToObject( invokerMojo, "profiles", Collections.singletonList( "zloug" ) ); setVariableValueToObject( invokerMojo, "settings", new Settings() ); String dirPath = getBasedir() + File.separatorChar + "src" + File.separatorChar + "test" + File.separatorChar + "resources" + File.separatorChar + "unit" + File.separatorChar + "profiles-from-file"; diff --git a/src/test/java/org/apache/maven/plugins/invoker/InvokerMojoTest.java b/src/test/java/org/apache/maven/plugins/invoker/InvokerMojoTest.java index f3dc12f9..1c221311 100644 --- a/src/test/java/org/apache/maven/plugins/invoker/InvokerMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/invoker/InvokerMojoTest.java @@ -89,7 +89,7 @@ public void testFullPatternInvokerTest() throws Exception public void testAlreadyCloned() { - assertFalse( AbstractInvokerMojo.alreadyCloned( "dir", Collections.emptyList() ) ); + assertFalse( AbstractInvokerMojo.alreadyCloned( "dir", Collections.emptyList() ) ); assertTrue( AbstractInvokerMojo.alreadyCloned( "dir", Collections.singletonList( "dir" ) ) ); assertTrue( AbstractInvokerMojo.alreadyCloned( "dir" + File.separator + "sub", Collections.singletonList( "dir" ) ) ); diff --git a/src/test/java/org/apache/maven/plugins/invoker/InvokerPropertiesTest.java b/src/test/java/org/apache/maven/plugins/invoker/InvokerPropertiesTest.java index a9290328..df72222a 100644 --- a/src/test/java/org/apache/maven/plugins/invoker/InvokerPropertiesTest.java +++ b/src/test/java/org/apache/maven/plugins/invoker/InvokerPropertiesTest.java @@ -132,13 +132,13 @@ public void testConfigureRequestGoals() props.setProperty( "invoker.goals", " " ); facade.configureInvocation( request, 0 ); - verify( request ).setGoals( eq( Collections.emptyList() ) ); + verify( request ).setGoals( eq( Collections.emptyList() ) ); verifyNoMoreInteractions( request ); clearInvocations( request ); props.setProperty( "invoker.goals", "" ); facade.configureInvocation( request, 0 ); - verify( request ).setGoals( eq( Collections.emptyList() ) ); + verify( request ).setGoals( eq( Collections.emptyList() ) ); verifyNoMoreInteractions( request ); clearInvocations( request ); @@ -162,13 +162,13 @@ public void testConfigureRequestProfiles() props.setProperty( "invoker.profiles", " " ); facade.configureInvocation( request, 0 ); - verify( request ).setProfiles( eq( Collections.emptyList() ) ); + verify( request ).setProfiles( eq( Collections.emptyList() ) ); verifyNoMoreInteractions( request ); clearInvocations( request ); props.setProperty( "invoker.profiles", "" ); facade.configureInvocation( request, 0 ); - verify( request ).setProfiles( eq( Collections.emptyList() ) ); + verify( request ).setProfiles( eq( Collections.emptyList() ) ); verifyNoMoreInteractions( request ); clearInvocations( request ); diff --git a/src/test/java/org/apache/maven/plugins/invoker/SelectorUtilsTest.java b/src/test/java/org/apache/maven/plugins/invoker/SelectorUtilsTest.java index 95fb116c..2a4e823e 100644 --- a/src/test/java/org/apache/maven/plugins/invoker/SelectorUtilsTest.java +++ b/src/test/java/org/apache/maven/plugins/invoker/SelectorUtilsTest.java @@ -47,14 +47,14 @@ public class SelectorUtilsTest @Test public void testParseList() { - List includes = new ArrayList(); - List excludes = new ArrayList(); + List includes = new ArrayList<>(); + List excludes = new ArrayList<>(); SelectorUtils.parseList( null, includes, excludes ); SelectorUtils.parseList( " 1.5, !1.4, 1.6+ ", includes, excludes ); assertEquals( Arrays.asList( "1.5", "1.6+" ), includes ); - assertEquals( Arrays.asList( "1.4" ), excludes ); + assertEquals( Collections.singletonList( "1.4" ), excludes ); } @Test @@ -74,8 +74,8 @@ public void testCompareVersions() assertTrue( SelectorUtils.compareVersions( Arrays.asList( 1, 5 ), Arrays.asList( 1, 6 ) ) < 0 ); assertTrue( SelectorUtils.compareVersions( Arrays.asList( 1, 6 ), Arrays.asList( 1, 5 ) ) > 0 ); - assertTrue( SelectorUtils.compareVersions( Arrays.asList( 1 ), Arrays.asList( 1, 6 ) ) < 0 ); - assertTrue( SelectorUtils.compareVersions( Arrays.asList( 1, 6 ), Arrays.asList( 1 ) ) > 0 ); + assertTrue( SelectorUtils.compareVersions( Collections.singletonList( 1 ), Arrays.asList( 1, 6 ) ) < 0 ); + assertTrue( SelectorUtils.compareVersions( Arrays.asList( 1, 6 ), Collections.singletonList( 1 ) ) > 0 ); } @Test