This is an automated email from the ASF dual-hosted git repository. olamy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven-invoker-plugin.git
The following commit(s) were added to refs/heads/master by this push: new 5c050e6 [MINVOKER-281] java 8 as minimum (#57) 5c050e6 is described below commit 5c050e641e54f6b45ff429876f55945f07aface1 Author: Olivier Lamy <ol...@apache.org> AuthorDate: Sat Aug 7 14:42:31 2021 +1000 [MINVOKER-281] java 8 as minimum (#57) Signed-off-by: Olivier Lamy <ol...@apache.org> --- pom.xml | 2 +- .../maven/plugins/invoker/AbstractInvokerMojo.java | 84 ++++++++-------------- .../apache/maven/plugins/invoker/FileLogger.java | 10 +-- .../apache/maven/plugins/invoker/InstallMojo.java | 21 +----- .../maven/plugins/invoker/MetadataUtils.java | 4 +- .../org/apache/maven/plugins/invoker/Selector.java | 2 +- .../maven/plugins/invoker/SelectorUtils.java | 22 ++---- .../maven/plugins/invoker/InterpolationTest.java | 4 +- .../maven/plugins/invoker/InvokerMojoTest.java | 2 +- .../plugins/invoker/InvokerPropertiesTest.java | 8 +-- .../maven/plugins/invoker/SelectorUtilsTest.java | 10 +-- 11 files changed, 56 insertions(+), 113 deletions(-) diff --git a/pom.xml b/pom.xml index 516d77e..4f06293 100644 --- a/pom.xml +++ b/pom.xml @@ -65,7 +65,7 @@ under the License. </distributionManagement> <properties> - <javaVersion>7</javaVersion> + <javaVersion>8</javaVersion> <mavenVersion>3.1.1</mavenVersion> <doxiaVersion>1.9.1</doxiaVersion> <doxiaSitetoolsVersion>1.9.2</doxiaSitetoolsVersion> 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 7ee143e..44d4a7e 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 @@ package org.apache.maven.plugins.invoker; 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.nio.file.Paths; 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.HashMap; 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.TreeSet; 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 @@ public abstract class AbstractInvokerMojo private List<BuildJob> getNonSetupJobs( List<BuildJob> buildJobs ) { - List<BuildJob> 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 @@ public abstract class AbstractInvokerMojo scriptRunner.setGlobalVariable( "localRepositoryPath", localRepositoryPath ); if ( scriptVariables != null ) { - for ( Entry<String, String> entry : scriptVariables.entrySet() ) - { - scriptRunner.setGlobalVariable( entry.getKey(), entry.getValue() ); - } + scriptVariables.forEach( ( key, value ) -> scriptRunner.setGlobalVariable( key, value ) ); } scriptRunner.setClassPath( scriptClassPath ); } @@ -1057,14 +1046,10 @@ public abstract class AbstractInvokerMojo collectProjects( projectsDir, parent, projectPaths, false ); } - Collection<String> modulePaths = new LinkedHashSet<>(); + Collection<String> 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 @@ public abstract class AbstractInvokerMojo 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 @@ public abstract class AbstractInvokerMojo 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 @@ public abstract class AbstractInvokerMojo 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 @@ public abstract class AbstractInvokerMojo { Properties props = invokerProperties.getProperties(); getLog().debug( "Using invoker properties:" ); - for ( String key : new TreeSet<String>( props.stringPropertyNames() ) ) + for ( String key : new TreeSet<>( props.stringPropertyNames() ) ) { String value = props.getProperty( key ); getLog().debug( " " + key + " = " + value ); @@ -2427,7 +2403,7 @@ public abstract class AbstractInvokerMojo throws IOException { List<String> excludes = - ( pomExcludes != null ) ? new ArrayList<>( pomExcludes ) : new ArrayList<String>(); + ( pomExcludes != null ) ? new ArrayList<>( pomExcludes ) : new ArrayList<>(); if ( this.settingsFile != null ) { String exclude = relativizePath( this.settingsFile, projectsDirectory.getCanonicalPath() ); @@ -2460,14 +2436,14 @@ public abstract class AbstractInvokerMojo return setupPoms; } - private static class OrdinalComparator implements Comparator + private static class OrdinalComparator implements Comparator<BuildJob> { 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 @@ public abstract class AbstractInvokerMojo List<BuildJob> 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<BuildJob> normalPoms = scanProjectsDirectory( pomIncludes, excludes, BuildJob.Type.NORMAL ); @@ -2563,11 +2539,11 @@ public abstract class AbstractInvokerMojo scanner.setFollowSymlinks( false ); if ( includes != null ) { - scanner.setIncludes( includes.toArray( new String[includes.size()] ) ); + scanner.setIncludes( includes.toArray( new String[0] ) ); } if ( excludes != null ) { - scanner.setExcludes( excludes.toArray( new String[excludes.size()] ) ); + scanner.setExcludes( excludes.toArray( new String[0] ) ); } scanner.addDefaultExcludes(); scanner.scan(); @@ -2603,7 +2579,7 @@ public abstract class AbstractInvokerMojo buildJob.setOrdinal( invokerProperties.getOrdinal() ); projects.add( buildJob ); } - Collections.sort( projects, OrdinalComparator.INSTANCE ); + projects.sort( OrdinalComparator.INSTANCE ); return projects; } diff --git a/src/main/java/org/apache/maven/plugins/invoker/FileLogger.java b/src/main/java/org/apache/maven/plugins/invoker/FileLogger.java index ef0ebaa..4a7d3cb 100644 --- a/src/main/java/org/apache/maven/plugins/invoker/FileLogger.java +++ b/src/main/java/org/apache/maven/plugins/invoker/FileLogger.java @@ -24,7 +24,6 @@ import java.io.IOException; import org.apache.maven.plugin.logging.Log; import org.apache.maven.shared.invoker.InvocationOutputHandler; -import org.apache.maven.shared.scriptinterpreter.FileLoggerMirrorHandler; /** * @@ -56,14 +55,7 @@ class FileLogger FileLogger( File outputFile, final Log log ) throws IOException { - super( outputFile, new FileLoggerMirrorHandler() - { - @Override - public void consumeOutput( String message ) - { - log.info( message ); - } - } ); + super( outputFile, log::info ); } } diff --git a/src/main/java/org/apache/maven/plugins/invoker/InstallMojo.java b/src/main/java/org/apache/maven/plugins/invoker/InstallMojo.java index 4a10ed4..c00e41b 100644 --- a/src/main/java/org/apache/maven/plugins/invoker/InstallMojo.java +++ b/src/main/java/org/apache/maven/plugins/invoker/InstallMojo.java @@ -22,14 +22,11 @@ package org.apache.maven.plugins.invoker; import java.io.File; import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashSet; -import java.util.List; import java.util.Map; import org.apache.maven.artifact.Artifact; @@ -49,7 +46,6 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.project.ProjectBuildingRequest; import org.apache.maven.shared.artifact.filter.resolve.PatternExclusionsFilter; import org.apache.maven.shared.transfer.artifact.install.ArtifactInstaller; -import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResult; import org.apache.maven.shared.transfer.dependencies.DefaultDependableCoordinate; import org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolver; import org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolverException; @@ -625,9 +621,9 @@ public class InstallMojo ProjectBuildingRequest projectBuildingRequest = repositoryManager .setLocalRepositoryBasedir( session.getProjectBuildingRequest(), localRepositoryPath ); - projectBuildingRequest.setRemoteRepositories( Arrays.asList( localRepository ) ); + projectBuildingRequest.setRemoteRepositories( Collections.singletonList( localRepository ) ); resolver.resolveDependencies( projectBuildingRequest, coordinate, - new PatternExclusionsFilter( Collections.<String>emptyList() ) ); + new PatternExclusionsFilter( Collections.emptyList() ) ); } finally { @@ -637,7 +633,7 @@ public class InstallMojo else { resolver.resolveDependencies( projectBuildingRequest, coordinate, - new PatternExclusionsFilter( Collections.<String>emptyList() ) ); + new PatternExclusionsFilter( Collections.emptyList() ) ); } } catch ( DependencyResolverException e ) @@ -647,15 +643,4 @@ public class InstallMojo } } - // FIXME could be simplify with using lambda... maybe in the next century... :P - private List<Artifact> toArtifactsList( Iterable<ArtifactResult> artifactResults ) - { - List<Artifact> 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 ad816e5..6588b97 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 @@ class MetadataUtils File metadataFile = new File( file.getParentFile().getParentFile(), "maven-metadata-local.xml" ); - Set<String> allVersions = new LinkedHashSet<String>(); + Set<String> allVersions = new LinkedHashSet<>(); Xpp3Dom metadata = readMetadata( metadataFile ); @@ -150,7 +150,7 @@ class MetadataUtils } 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 4fde5df..6f6cfba 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 @@ class Selector 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 db509e0..a144937 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 @@ package org.apache.maven.plugins.invoker; */ 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 @@ class SelectorUtils 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 @@ class SelectorUtils static boolean isJreVersion( String jreSpec, String actualJreVersion ) { - List<String> includes = new ArrayList<String>(); - List<String> excludes = new ArrayList<String>(); + List<String> includes = new ArrayList<>(); + List<String> excludes = new ArrayList<>(); parseList( jreSpec, includes, excludes ); List<Integer> jreVersion = parseVersion( actualJreVersion ); @@ -249,12 +244,7 @@ class SelectorUtils String[] tokens = StringUtils.split( version, "." ); - List<Integer> numbers = new ArrayList<Integer>(); - - for ( String token : tokens ) - { - numbers.add( Integer.valueOf( token ) ); - } + List<Integer> 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 bf11628..cd75a75 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 @@ package org.apache.maven.plugins.invoker; 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 class InterpolationTest { 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 f3dc12f..1c22131 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 class InvokerMojoTest extends AbstractMojoTestCase public void testAlreadyCloned() { - assertFalse( AbstractInvokerMojo.alreadyCloned( "dir", Collections.<String>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 a929032..df72222 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 class InvokerPropertiesTest props.setProperty( "invoker.goals", " " ); facade.configureInvocation( request, 0 ); - verify( request ).setGoals( eq( Collections.<String>emptyList() ) ); + verify( request ).setGoals( eq( Collections.emptyList() ) ); verifyNoMoreInteractions( request ); clearInvocations( request ); props.setProperty( "invoker.goals", "" ); facade.configureInvocation( request, 0 ); - verify( request ).setGoals( eq( Collections.<String>emptyList() ) ); + verify( request ).setGoals( eq( Collections.emptyList() ) ); verifyNoMoreInteractions( request ); clearInvocations( request ); @@ -162,13 +162,13 @@ public class InvokerPropertiesTest props.setProperty( "invoker.profiles", " " ); facade.configureInvocation( request, 0 ); - verify( request ).setProfiles( eq( Collections.<String>emptyList() ) ); + verify( request ).setProfiles( eq( Collections.emptyList() ) ); verifyNoMoreInteractions( request ); clearInvocations( request ); props.setProperty( "invoker.profiles", "" ); facade.configureInvocation( request, 0 ); - verify( request ).setProfiles( eq( Collections.<String>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 95fb116..2a4e823 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<String> includes = new ArrayList<String>(); - List<String> excludes = new ArrayList<String>(); + List<String> includes = new ArrayList<>(); + List<String> 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 class SelectorUtilsTest 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