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

Java 8 code style update and bump some maven dependencies #463

Merged
merged 12 commits into from Jun 29, 2021
Expand Up @@ -207,10 +207,9 @@ protected Artifact findArtifact( Dependency dependency )
{
return null;
}
Iterator<?> iter = getProject().getDependencyArtifacts().iterator();
while ( iter.hasNext() )
for ( Object o : getProject().getDependencyArtifacts() )
olamy marked this conversation as resolved.
Show resolved Hide resolved
{
Artifact artifact = (Artifact) iter.next();
Artifact artifact = (Artifact) o;
olamy marked this conversation as resolved.
Show resolved Hide resolved
if ( compare( artifact, dependency ) )
{
return artifact;
Expand Down Expand Up @@ -334,11 +333,7 @@ private boolean compare( MavenProject project, Dependency dep )
{
return false;
}
if ( !StringUtils.equals( project.getArtifactId(), dep.getArtifactId() ) )
{
return false;
}
return true;
return StringUtils.equals( project.getArtifactId(), dep.getArtifactId() );
olamy marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand All @@ -363,11 +358,7 @@ private boolean compare( Artifact artifact, Dependency dep )
{
return false;
}
if ( !StringUtils.equals( artifact.getClassifier(), dep.getClassifier() ) )
{
return false;
}
return true;
return StringUtils.equals( artifact.getClassifier(), dep.getClassifier() );
}

/**
Expand Down Expand Up @@ -495,9 +486,9 @@ private int findFirstChar( final String includeString, final String chars )
int nextRangeStartDelimiterIndex = -1;

char[] delimiters = chars.toCharArray();
for ( int i = 0; i < delimiters.length; i++ )
for ( char delimiter : delimiters )
{
int index = includeString.indexOf( delimiters[i] );
int index = includeString.indexOf( delimiter );
if ( index >= 0 && nextRangeStartDelimiterIndex >= 0 )
{
nextRangeStartDelimiterIndex = Math.min( index, nextRangeStartDelimiterIndex );
Expand Down
Expand Up @@ -832,9 +832,9 @@ private Set<String> getVersionsInRange( Property property, PropertyVersions vers
{
tmp = artifactVersions;
}
for ( int i = 0; i < tmp.length; i++ )
for ( ArtifactVersion artifactVersion : tmp )
{
rangeVersions.add( tmp[i].toString() );
rangeVersions.add( artifactVersion.toString() );
}
return rangeVersions;
}
Expand Down
Expand Up @@ -176,8 +176,8 @@ protected void update( ModifiedPomXMLEventReader pom )
mapDependencies( remoteDepsMap, remoteProjectDeps );
}

List<String> totalDiffs = new ArrayList<String>();
List<String> propertyDiffs = new ArrayList<String>();
List<String> totalDiffs = new ArrayList<>();
List<String> propertyDiffs = new ArrayList<>();
if ( getProject().getDependencyManagement() != null && isProcessingDependencyManagement() )
{
List<String> depManDiffs =
Expand Down Expand Up @@ -458,4 +458,4 @@ private static String generateId( Artifact artifact )
return sb.toString();
}

}
}
Expand Up @@ -53,8 +53,7 @@ public DependencyUpdatesRenderer( Sink sink, I18N i18n, String bundleName, Local

protected void renderBody()
{
Map<Dependency, ArtifactVersions> allUpdates =
new TreeMap<Dependency, ArtifactVersions>( new DependencyComparator() );
Map<Dependency, ArtifactVersions> allUpdates = new TreeMap<>( new DependencyComparator() );
allUpdates.putAll( dependencyManagementUpdates );
allUpdates.putAll( dependencyUpdates );

Expand Down
Expand Up @@ -159,10 +159,7 @@ private static Set<Dependency> extractPluginDependenciesFromPluginsInPluginManag
{
if ( plugin.getDependencies() != null && !plugin.getDependencies().isEmpty() )
{
for ( Dependency pluginDependency : plugin.getDependencies() )
{
result.add( pluginDependency );
}
result.addAll( plugin.getDependencies() );
}
}
}
Expand All @@ -176,10 +173,7 @@ private static Set<Dependency> extractDependenciesFromPlugins( List<Plugin> plug
{
if ( plugin.getDependencies() != null && !plugin.getDependencies().isEmpty() )
{
for ( Dependency pluginDependency : plugin.getDependencies() )
{
result.add( pluginDependency );
}
result.addAll( plugin.getDependencies() );
}
}
return result;
Expand All @@ -198,20 +192,19 @@ private static Set<Dependency> extractDependenciesFromPlugins( List<Plugin> plug
private static Set<Dependency> removeDependencyManagment( Set<Dependency> dependencies, Set<Dependency> dependencyManagement )
{
Set<Dependency> result = new TreeSet<>( new DependencyComparator() );
for ( Iterator<Dependency> i = dependencies.iterator(); i.hasNext(); )
for ( Dependency c : dependencies )
olamy marked this conversation as resolved.
Show resolved Hide resolved
{
Dependency c = i.next();
boolean matched = false;
Iterator<Dependency> j = dependencyManagement.iterator();
while ( !matched && j.hasNext() )
{
Dependency t =j.next();
if ( StringUtils.equals( t.getGroupId(), c.getGroupId() )
&& StringUtils.equals( t.getArtifactId(), c.getArtifactId() )
&& ( t.getScope() == null || StringUtils.equals( t.getScope(), c.getScope() ) )
&& ( t.getClassifier() == null || StringUtils.equals( t.getClassifier(), c.getClassifier() ) )
&& ( c.getVersion() == null || t.getVersion() == null
|| StringUtils.equals( t.getVersion(), c.getVersion() ) ) )
Dependency t = j.next();
bmarwell marked this conversation as resolved.
Show resolved Hide resolved
if ( StringUtils.equals( t.getGroupId(), c.getGroupId() ) && StringUtils.equals( t.getArtifactId(),
c.getArtifactId() )
&& ( t.getScope() == null || StringUtils.equals( t.getScope(), c.getScope() ) ) && (
t.getClassifier() == null || StringUtils.equals( t.getClassifier(), c.getClassifier() ) ) && (
c.getVersion() == null || t.getVersion() == null || StringUtils.equals( t.getVersion(),
c.getVersion() ) ) )
{
matched = true;
break;
Expand Down Expand Up @@ -355,11 +348,7 @@ public void execute()
logUpdates( getHelper().lookupDependenciesUpdates( pluginDependencies, false ), "Plugin Dependencies" );
}
}
catch ( InvalidVersionSpecificationException e )
{
throw new MojoExecutionException( e.getMessage(), e );
}
catch ( ArtifactMetadataRetrievalException e )
catch ( InvalidVersionSpecificationException | ArtifactMetadataRetrievalException e )
bmarwell marked this conversation as resolved.
Show resolved Hide resolved
{
throw new MojoExecutionException( e.getMessage(), e );
}
Expand Down
Expand Up @@ -179,7 +179,7 @@ private Map<String, String> getSuperPomPluginManagement()
getProject().getPackaging() } );
// we need to provide a copy with the version blanked out so that inferring from super-pom
// works as for 2.x as 3.x fills in the version on us!
Map<String, String> result = new LinkedHashMap<String, String>( plugins.size() );
Map<String, String> result = new LinkedHashMap<>( plugins.size() );
for ( Plugin plugin : plugins )
{
result.put( plugin.getKey(), plugin.getVersion() );
Expand All @@ -196,7 +196,7 @@ private Map<String, String> getSuperPomPluginManagement()

Pattern pathRegex = Pattern.compile( "/project(/profiles/profile)?"
+ "((/build(/pluginManagement)?)|(/reporting))" + "/plugins/plugin" );
Stack<StackState> pathStack = new Stack<StackState>();
Stack<StackState> pathStack = new Stack<>();
StackState curState = null;
while ( pom.hasNext() )
{
Expand Down Expand Up @@ -269,12 +269,12 @@ else if ( event.isEndElement() )
}
}
getLog().debug( "Using Maven 2.x strategy to determine superpom defined plugins" );
Map<String, String> superPomPluginManagement = new HashMap<>();
Map<String, String> superPomPluginManagement;
try
{
MavenProject superProject =
projectBuilder.buildStandaloneSuperProject( new DefaultProjectBuilderConfiguration() );
superPomPluginManagement.putAll( getPluginManagement( superProject.getOriginalModel() ) );
superPomPluginManagement = new HashMap<>( getPluginManagement( superProject.getOriginalModel() ) );
}
catch ( ProjectBuildingException e )
{
Expand Down Expand Up @@ -373,8 +373,8 @@ public void execute()
// renaming parentPluginManagement to parentPlugins)
// NOTICE: getProjectPlugins() takes profiles while getParentPlugins does not
// there is probably a little inconsistency (if plugins configured in profiles of parents)
Map<String, String> parentBuildPlugins = new HashMap<String, String>();
Map<String, String> parentReportPlugins = new HashMap<String, String>();
Map<String, String> parentBuildPlugins = new HashMap<>();
Map<String, String> parentReportPlugins = new HashMap<>();

Set<Plugin> plugins = getProjectPlugins( superPomPluginManagement, parentPlugins, parentBuildPlugins,
parentReportPlugins, pluginsWithVersionsSpecified );
Expand Down Expand Up @@ -454,12 +454,8 @@ public void execute()
// upgrade
if ( minRequires == null || compare( minRequires, pluginRequires ) > 0 )
{
Map<String, String> upgradePlugins = mavenUpgrades.get( pluginRequires );
if ( upgradePlugins == null )
{
mavenUpgrades.put( pluginRequires,
upgradePlugins = new LinkedHashMap<String, String>() );
}
Map<String, String> upgradePlugins =
mavenUpgrades.computeIfAbsent( pluginRequires, k -> new LinkedHashMap<>() );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mavenUpgrades.computeIfAbsent( pluginRequires, k -> new LinkedHashMap<>() );
mavenUpgrades.computeIfAbsent( pluginRequires, key -> new LinkedHashMap<>() );

or

Suggested change
mavenUpgrades.computeIfAbsent( pluginRequires, k -> new LinkedHashMap<>() );
mavenUpgrades.computeIfAbsent( pluginRequires, __ -> new LinkedHashMap<>() );


String upgradePluginKey = compactKey( groupId, artifactId );
if ( !upgradePlugins.containsKey( upgradePluginKey ) )
Expand Down Expand Up @@ -728,7 +724,7 @@ private static String pad( String start, int len, String...ends )
private Map<String, String> getParentsPlugins( List<MavenProject> parents )
throws MojoExecutionException
{
Map<String, String> parentPlugins = new HashMap<String, String>();
Map<String, String> parentPlugins = new HashMap<>();
for ( MavenProject parentProject : parents )
{
getLog().debug( "Processing parent: " + parentProject.getGroupId() + ":" + parentProject.getArtifactId()
Expand Down Expand Up @@ -881,7 +877,7 @@ private Set<String> findPluginsWithVersionsSpecified( StringBuilder pomContents,

Pattern pathRegex = Pattern.compile( "/project(/profiles/profile)?"
+ "((/build(/pluginManagement)?)|(/reporting))" + "/plugins/plugin" );
Stack<StackState> pathStack = new Stack<StackState>();
Stack<StackState> pathStack = new Stack<>();
StackState curState = null;
while ( pom.hasNext() )
{
Expand Down Expand Up @@ -1079,7 +1075,7 @@ private Set<Plugin> getBoundPlugins( MavenProject project, String thePhases )
project.getPackaging() == null ? "jar" : project.getPackaging() } );
// we need to provide a copy with the version blanked out so that inferring from super-pom
// works as for 2.x as 3.x fills in the version on us!
Set<Plugin> result = new LinkedHashSet<Plugin>( plugins.size() );
Set<Plugin> result = new LinkedHashSet<>( plugins.size() );
for ( Plugin plugin : plugins )
{
Plugin dup = new Plugin();
Expand All @@ -1106,7 +1102,7 @@ private Set<Plugin> getBoundPlugins( MavenProject project, String thePhases )
// no much we can do here
}

Set<Plugin> allPlugins = new HashSet<Plugin>();
Set<Plugin> allPlugins = new HashSet<>();

// lookup the bindings for all the passed in phases
for ( String lifecyclePhase : thePhases.split( "," ) )
Expand Down
Expand Up @@ -32,7 +32,6 @@

import javax.xml.stream.XMLStreamException;
import java.util.Collection;
import java.util.Iterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down
Expand Up @@ -23,7 +23,6 @@
import org.codehaus.mojo.versions.api.ArtifactVersions;
import org.codehaus.mojo.versions.api.UpdateScope;

import java.util.Iterator;
import java.util.Map;
import java.util.Objects;

Expand Down Expand Up @@ -64,9 +63,9 @@ public boolean isArtifactUpdateAvailable()

public boolean isDependencyUpdateAvailable()
{
for ( Iterator i = dependencyVersions.values().iterator(); i.hasNext(); )
for ( Object o : dependencyVersions.values() )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for ( Object o : dependencyVersions.values() )
for ( ArtifactVersions versions : (ArtifactVersions) dependencyVersions.values() )

{
ArtifactVersions versions = (ArtifactVersions) i.next();
ArtifactVersions versions = (ArtifactVersions) o;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ArtifactVersions versions = (ArtifactVersions) o;

ArtifactVersion[] dependencyUpdates = versions.getAllUpdates( UpdateScope.ANY, includeSnapshots );
if ( dependencyUpdates != null && dependencyUpdates.length > 0 )
{
Expand Down
Expand Up @@ -505,9 +505,9 @@ else if ( equals( versions[i],

sink.section3_();

for ( Iterator i = details.getDependencyVersions().entrySet().iterator(); i.hasNext(); )
for ( Object o : details.getDependencyVersions().entrySet() )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for ( Object o : details.getDependencyVersions().entrySet() )
for ( Map.Entry entry : (Map.Entry) details.getDependencyVersions().entrySet() )

{
Map.Entry entry = (Map.Entry) i.next();
Map.Entry entry = (Map.Entry) o;
olamy marked this conversation as resolved.
Show resolved Hide resolved
renderDependencyDetail( (Dependency) entry.getKey(), (ArtifactVersions) entry.getValue() );
}
}
Expand Down
Expand Up @@ -83,8 +83,7 @@ public void render()
{
StringBuilder sb = new StringBuilder();
sb.append( "<PluginUpdatesReport>" ).append( NL );
Map<Plugin, PluginUpdatesDetails> allUpdates =
new TreeMap<Plugin, PluginUpdatesDetails>( new PluginComparator() );
Map<Plugin, PluginUpdatesDetails> allUpdates = new TreeMap<>( new PluginComparator() );
allUpdates.putAll( pluginManagementUpdates );
allUpdates.putAll( pluginUpdates );
sb.append( getSummaryBlock( allUpdates ) );
Expand All @@ -106,11 +105,8 @@ public void render()

private static String getSummaryBlock( Map<Plugin, PluginUpdatesDetails> allUpdates )
{
Collection<ArtifactVersions> allVersions = new ArrayList<ArtifactVersions>();
for ( PluginUpdatesDetails details : allUpdates.values() )
{
allVersions.add( details.getArtifactVersions() );
}
Collection<ArtifactVersions> allVersions = new ArrayList<>();
allUpdates.values().forEach( details -> allVersions.add( details.getArtifactVersions() ) );
olamy marked this conversation as resolved.
Show resolved Hide resolved
return DependencyUpdatesXmlRenderer.getSummaryBlock( allVersions );
}

Expand Down
Expand Up @@ -32,8 +32,6 @@
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -79,24 +77,20 @@ public void execute()
{
final Map<String, Model> reactor = PomHelper.getReactorModels( getProject(), getLog() );
List<String> order = new ArrayList<>( reactor.keySet() );
Collections.sort( order, new Comparator<String>()
{
public int compare( String o1, String o2 )
order.sort( ( o1, o2 ) -> {
Model m1 = reactor.get( o1 );
Model m2 = reactor.get( o2 );
int d1 = PomHelper.getReactorParentCount( reactor, m1 );
int d2 = PomHelper.getReactorParentCount( reactor, m2 );
if ( d1 < d2 )
{
Model m1 = reactor.get( o1 );
Model m2 = reactor.get( o2 );
int d1 = PomHelper.getReactorParentCount( reactor, m1 );
int d2 = PomHelper.getReactorParentCount( reactor, m2 );
if ( d1 < d2 )
{
return -1;
}
else if ( d1 > d2 )
{
return 1;
}
return 0;
return -1;
}
else if ( d1 > d2 )
{
return 1;
}
return 0;
} );
olamy marked this conversation as resolved.
Show resolved Hide resolved

for ( String sourcePath : order )
Expand Down
Expand Up @@ -20,7 +20,6 @@
*/

import java.util.Collection;
import java.util.Iterator;

import javax.xml.stream.XMLStreamException;

Expand Down Expand Up @@ -134,4 +133,4 @@ private void useDepVersion( ModifiedPomXMLEventReader pom, Collection<Dependency
}
}
}
}
}
Expand Up @@ -39,7 +39,6 @@
import javax.xml.stream.XMLStreamException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -207,4 +206,4 @@ private ArtifactVersion[] filterVersionsWithIncludes( ArtifactVersion[] newer, A
return filteredNewer.toArray( new ArtifactVersion[filteredNewer.size()] );
}

}
}