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

[MINVOKER-281] java 8 as minimum #57

Merged
merged 4 commits into from Aug 7, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -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>
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -90,26 +89,24 @@
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;
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;
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;

Expand Down Expand Up @@ -886,15 +883,10 @@ private void setupReportsFolder()

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()
Expand All @@ -917,10 +909,7 @@ private void handleScriptRunnerWithScriptClassPath()
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 );
}
Expand Down Expand Up @@ -1057,14 +1046,10 @@ else if ( !pomFile.isFile() )
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 )
{
Expand Down Expand Up @@ -1399,21 +1384,18 @@ private void runBuilds( final File projectsDir, List<BuildJob> 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 );
}
} );
}
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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<String>( props.stringPropertyNames() ) )
for ( String key : new TreeSet<>( props.stringPropertyNames() ) )
{
String value = props.getProperty( key );
getLog().debug( " " + key + " = " + value );
Expand Down Expand Up @@ -2427,7 +2403,7 @@ private List<String> calculateExcludes()
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() );
Expand Down Expand Up @@ -2460,14 +2436,14 @@ private List<BuildJob> getSetupBuildJobsFromFolders()
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() );
}
}

Expand All @@ -2489,7 +2465,7 @@ List<BuildJob> getBuildJobs()
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 );
Expand Down Expand Up @@ -2563,11 +2539,11 @@ private List<BuildJob> scanProjectsDirectory( List<String> includes, List<String
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();
Expand Down Expand Up @@ -2603,7 +2579,7 @@ private List<BuildJob> scanProjectsDirectory( List<String> includes, List<String
buildJob.setOrdinal( invokerProperties.getOrdinal() );
projects.add( buildJob );
}
Collections.sort( projects, OrdinalComparator.INSTANCE );
projects.sort( OrdinalComparator.INSTANCE );
return projects;
}

Expand Down
10 changes: 1 addition & 9 deletions src/main/java/org/apache/maven/plugins/invoker/FileLogger.java
Expand Up @@ -24,7 +24,6 @@

import org.apache.maven.plugin.logging.Log;
import org.apache.maven.shared.invoker.InvocationOutputHandler;
import org.apache.maven.shared.scriptinterpreter.FileLoggerMirrorHandler;

/**
*
Expand Down Expand Up @@ -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 );
}

}
21 changes: 3 additions & 18 deletions src/main/java/org/apache/maven/plugins/invoker/InstallMojo.java
Expand Up @@ -22,14 +22,11 @@

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;
Expand All @@ -49,7 +46,6 @@
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;
Expand Down Expand Up @@ -625,9 +621,9 @@ private void installExtraArtifacts( String[] extraArtifacts )
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
{
Expand All @@ -637,7 +633,7 @@ private void installExtraArtifacts( String[] extraArtifacts )
else
{
resolver.resolveDependencies( projectBuildingRequest, coordinate,
new PatternExclusionsFilter( Collections.<String>emptyList() ) );
new PatternExclusionsFilter( Collections.emptyList() ) );
}
}
catch ( DependencyResolverException e )
Expand All @@ -647,15 +643,4 @@ private void installExtraArtifacts( String[] extraArtifacts )
}
}

// 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;
}

}
Expand Up @@ -82,7 +82,7 @@ public static void createMetadata( File file, Artifact artifact )

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 );

Expand Down Expand Up @@ -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 );
}
}

Expand Down
Expand Up @@ -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;
}
Expand Down
22 changes: 6 additions & 16 deletions src/main/java/org/apache/maven/plugins/invoker/SelectorUtils.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -192,8 +187,8 @@ static boolean isJreVersion( String jreSpec )

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 );
Expand Down Expand Up @@ -249,12 +244,7 @@ static List<Integer> parseVersion( String version )

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;
}
Expand Down