You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2021/08/06 09:35:44 UTC
[maven-invoker-plugin] branch MINVOKER-281-java-8 created (now
5df959d)
This is an automated email from the ASF dual-hosted git repository.
olamy pushed a change to branch MINVOKER-281-java-8
in repository https://gitbox.apache.org/repos/asf/maven-invoker-plugin.git.
at 5df959d [MINVOKER-281] java 8 as minimum
This branch includes the following new commits:
new 5df959d [MINVOKER-281] java 8 as minimum
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[maven-invoker-plugin] 01/01: [MINVOKER-281] java 8 as minimum
Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
olamy pushed a commit to branch MINVOKER-281-java-8
in repository https://gitbox.apache.org/repos/asf/maven-invoker-plugin.git
commit 5df959d85ee9b4391317d8bb09954455c96bfa29
Author: Olivier Lamy <ol...@apache.org>
AuthorDate: Fri Aug 6 19:35:10 2021 +1000
[MINVOKER-281] java 8 as minimum
Signed-off-by: Olivier Lamy <ol...@apache.org>
---
pom.xml | 2 +-
.../maven/plugins/invoker/AbstractInvokerMojo.java | 87 ++++++++--------------
.../apache/maven/plugins/invoker/FileLogger.java | 10 +--
.../apache/maven/plugins/invoker/InstallMojo.java | 6 +-
.../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, 57 insertions(+), 100 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..7b4f5cb 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,23 +1384,19 @@ public abstract class AbstractInvokerMojo
ExecutorService executorService = Executors.newFixedThreadPool( runWithParallelThreads );
for ( final BuildJob job : buildJobs )
{
- executorService.execute( new Runnable()
- {
- public void run()
+ executorService.execute(() -> {
+ try
{
- 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 );
- }
+ 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 );
+ }
+ });
}
try
@@ -1623,13 +1604,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 +1784,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 +2013,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 +2402,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 +2435,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 +2464,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 +2538,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 +2578,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..4e63c1e 100644
--- a/src/main/java/org/apache/maven/plugins/invoker/InstallMojo.java
+++ b/src/main/java/org/apache/maven/plugins/invoker/InstallMojo.java
@@ -625,9 +625,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 +637,7 @@ public class InstallMojo
else
{
resolver.resolveDependencies( projectBuildingRequest, coordinate,
- new PatternExclusionsFilter( Collections.<String>emptyList() ) );
+ new PatternExclusionsFilter( Collections.emptyList() ) );
}
}
catch ( DependencyResolverException e )
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..69f9b49 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..f12caee 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