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

Quick fix reported by IDE improvements #707

Merged
merged 1 commit into from
Sep 18, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -320,16 +320,8 @@ protected String toString( Dependency d )
*/
protected boolean isProducedByReactor( Dependency dependency )
{
for ( Object reactorProject : reactorProjects )
{
MavenProject project = (MavenProject) reactorProject;
if ( compare( project, dependency ) )
{
return true;
}
}
return false;

return reactorProjects.stream()
.anyMatch( reactorProject -> compare( reactorProject, dependency ) );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ protected void update( ModifiedPomXMLEventReader pom )
throw new MojoExecutionException( "Unable to build remote project " + remoteArtifact, e );
}

Map<String, Dependency> remoteDepsMap = new HashMap<String, Dependency>();
Map<String, Dependency> remoteDepsMap = new HashMap<>();
if ( !ignoreRemoteDependencyManagement )
{
List<Dependency> remoteProjectDepMgmtDeps = ( remoteMavenProject.getDependencyManagement() == null ) ? null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import org.codehaus.mojo.versions.utils.DependencyComparator;
import org.codehaus.plexus.i18n.I18N;

import static java.util.Collections.EMPTY_MAP;
import static java.util.Collections.emptyMap;
import static org.codehaus.mojo.versions.utils.MiscUtils.filter;

/**
Expand Down Expand Up @@ -190,7 +190,7 @@ && getProject().getOriginalModel().getDependencyManagement().getDependencies() !

Map<Dependency, ArtifactVersions> dependencyManagementUpdates =
processDependencyManagement ? getHelper().lookupDependenciesUpdates( dependencyManagement, false )
: EMPTY_MAP;
: emptyMap();

if ( onlyUpgradable )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import javax.xml.stream.XMLStreamException;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -704,10 +703,8 @@ private void logUpdates( Map<Dependency, ArtifactVersions> updates, String secti
{
List<String> withUpdates = new ArrayList<>();
List<String> usingCurrent = new ArrayList<>();
Iterator i = updates.values().iterator();
while ( i.hasNext() )
for ( ArtifactVersions versions : updates.values() )
{
ArtifactVersions versions = (ArtifactVersions) i.next();
String left = " " + ArtifactUtils.versionlessKey( versions.getArtifact() ) + " ";
final String current;
ArtifactVersion latest;
Expand All @@ -719,12 +716,12 @@ private void logUpdates( Map<Dependency, ArtifactVersions> updates, String secti
else
{
ArtifactVersion newestVersion =
versions.getNewestVersion( versions.getArtifact().getVersionRange(), allowSnapshots );
versions.getNewestVersion( versions.getArtifact().getVersionRange(), allowSnapshots );
current = versions.getArtifact().getVersionRange().toString();
latest = newestVersion == null ? null
: versions.getNewestUpdate( newestVersion, calculateUpdateScope(), allowSnapshots );
: versions.getNewestUpdate( newestVersion, calculateUpdateScope(), allowSnapshots );
if ( latest != null
&& ArtifactVersions.isVersionInRange( latest, versions.getArtifact().getVersionRange() ) )
&& ArtifactVersions.isVersionInRange( latest, versions.getArtifact().getVersionRange() ) )
{
latest = null;
}
Expand All @@ -740,7 +737,7 @@ private void logUpdates( Map<Dependency, ArtifactVersions> updates, String secti
else
{
t.add( StringUtils.rightPad( left, INFO_PAD_SIZE + getOutputLineWidthOffset() - right.length(), "." )
+ right );
+ right );
}
}

Expand All @@ -757,10 +754,9 @@ private void logUpdates( Map<Dependency, ArtifactVersions> updates, String secti
else
{
logLine( false, "The following dependencies in " + section + " are using the newest version:" );
i = usingCurrent.iterator();
while ( i.hasNext() )
for ( String s : usingCurrent )
{
logLine( false, (String) i.next() );
logLine( false, s );
}
logLine( false, "" );
}
Expand All @@ -778,10 +774,9 @@ private void logUpdates( Map<Dependency, ArtifactVersions> updates, String secti
else
{
logLine( false, "The following dependencies in " + section + " have newer versions:" );
i = withUpdates.iterator();
while ( i.hasNext() )
for ( String withUpdate : withUpdates )
{
logLine( false, (String) i.next() );
logLine( false, withUpdate );
}
logLine( false, "" );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ private Map<String, String> getSuperPomPluginManagement()
{
Method getPluginsBoundByDefaultToAllLifecycles =
LifecycleExecutor.class.getMethod( "getPluginsBoundByDefaultToAllLifecycles",
new Class[] {String.class} );
String.class );
Set<Plugin> plugins =
(Set<Plugin>) getPluginsBoundByDefaultToAllLifecycles.invoke( lifecycleExecutor, new Object[] {
getProject().getPackaging()} );
Expand Down Expand Up @@ -1102,7 +1102,7 @@ private Set<Plugin> getBoundPlugins( MavenProject project, String thePhases )
{
Method getPluginsBoundByDefaultToAllLifecycles =
LifecycleExecutor.class.getMethod( "getPluginsBoundByDefaultToAllLifecycles",
new Class[] {String.class} );
String.class );
Set<Plugin> plugins =
(Set<Plugin>) getPluginsBoundByDefaultToAllLifecycles.invoke( lifecycleExecutor, new Object[] {
project.getPackaging() == null ? "jar" : project.getPackaging()} );
Expand All @@ -1127,7 +1127,7 @@ private Set<Plugin> getBoundPlugins( MavenProject project, String thePhases )
getLog().debug( "Using Maven 2.0.10+ strategy to determine lifecycle defined plugins" );
try
{
Method getLifecycles = LifecycleExecutor.class.getMethod( "getLifecycles", new Class[0] );
Method getLifecycles = LifecycleExecutor.class.getMethod( "getLifecycles" );
lifecycles = (List) getLifecycles.invoke( lifecycleExecutor, new Object[0] );
}
catch ( NoSuchMethodException | InvocationTargetException | IllegalAccessException e1 )
Expand Down Expand Up @@ -1221,7 +1221,7 @@ private Set<Plugin> getAllPlugins( MavenProject project, Lifecycle lifecycle )
plugins.add( plugin );
}

plugins.addAll( (List<Plugin>) project.getBuildPlugins() );
plugins.addAll( project.getBuildPlugins() );

return plugins;
}
Expand Down Expand Up @@ -1261,8 +1261,8 @@ private Set<Plugin> getAllPlugins( MavenProject project, Lifecycle lifecycle )
{
if ( defaultMappings == null )
{
throw new LifecycleExecutionException( "Cannot find lifecycle mapping for packaging: \'" + packaging
+ "\'.", e );
throw new LifecycleExecutionException( "Cannot find lifecycle mapping for packaging: '" + packaging
+ "'.", e );
}
}
}
Expand All @@ -1271,8 +1271,8 @@ private Set<Plugin> getAllPlugins( MavenProject project, Lifecycle lifecycle )
{
if ( defaultMappings == null )
{
throw new LifecycleExecutionException( "Cannot find lifecycle mapping for packaging: \'" + packaging
+ "\', and there is no default" );
throw new LifecycleExecutionException( "Cannot find lifecycle mapping for packaging: '" + packaging
+ "', and there is no default" );
}
else
{
Expand Down Expand Up @@ -1446,7 +1446,7 @@ public Map<String, Lifecycle> getPhaseToLifecycleMap( List<Lifecycle> lifecycles

for ( Lifecycle lifecycle : lifecycles )
{
for ( String phase : (List<String>) lifecycle.getPhases() )
for ( String phase : lifecycle.getPhases() )
{
if ( phaseToLifecycleMap.containsKey( phase ) )
{
Expand Down Expand Up @@ -1507,7 +1507,7 @@ private Set<Plugin> getProjectPlugins( Map<String, String> superPomPluginManagem
debugVersionMap( "super-pom version map", superPomPluginManagement );
debugVersionMap( "parent version map", parentPluginManagement );

Map<String, String> excludePluginManagement = new HashMap<String, String>( superPomPluginManagement );
Map<String, String> excludePluginManagement = new HashMap<>( superPomPluginManagement );
excludePluginManagement.putAll( parentPluginManagement );

debugVersionMap( "aggregate version map", excludePluginManagement );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ private void renderPluginDetail( Plugin plugin, PluginUpdatesDetails details )
headerAttributes.addAttribute( SinkEventAttributes.WIDTH, "80%" );
sink.section2();
sink.sectionTitle2();
sink.text( MessageFormat.format( getText( "report.plugin" ), new Object[] {
ArtifactUtils.versionlessKey( plugin.getGroupId(), plugin.getArtifactId() )} ) );
sink.text( MessageFormat.format( getText( "report.plugin" ),
ArtifactUtils.versionlessKey( plugin.getGroupId(), plugin.getArtifactId() ) ) );
sink.sectionTitle2_();
sink.table();
sink.tableRows( new int[] {Sink.JUSTIFY_RIGHT, Sink.JUSTIFY_LEFT}, false );
Expand Down Expand Up @@ -510,16 +510,16 @@ else if ( equals( versions[i],
{
sink.section3();
sink.sectionTitle3();
sink.text( MessageFormat.format( getText( "report.pluginDependencies" ), new Object[] {
ArtifactUtils.versionlessKey( plugin.getGroupId(), plugin.getArtifactId() )} ) );
sink.text( MessageFormat.format( getText( "report.pluginDependencies" ),
ArtifactUtils.versionlessKey( plugin.getGroupId(), plugin.getArtifactId() ) ) );
sink.sectionTitle3_();

renderDependencySummaryTable( details.getDependencyVersions(), false, true, true );

sink.section3_();

details.getDependencyVersions().entrySet()
.forEach( entry -> renderDependencyDetail( entry.getKey(), entry.getValue() ) );
details.getDependencyVersions()
.forEach( this::renderDependencyDetail );
}
sink.section2_();
}
Expand All @@ -528,8 +528,8 @@ private void renderDependencyDetail( Dependency dependency, ArtifactVersions det
{
sink.section3();
sink.sectionTitle3();
sink.text( MessageFormat.format( getText( "report.pluginDependency" ), new Object[] {
ArtifactUtils.versionlessKey( dependency.getGroupId(), dependency.getArtifactId() )} ) );
sink.text( MessageFormat.format( getText( "report.pluginDependency" ),
ArtifactUtils.versionlessKey( dependency.getGroupId(), dependency.getArtifactId() ) ) );
sink.sectionTitle3_();
renderDependencyDetailTable( dependency, details, false, true, true );
sink.section3_();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/codehaus/mojo/versions/SetMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,11 @@ public void execute() throws MojoExecutionException, MojoFailureException
getLog().info( "Local aggregation root: " + project.getBasedir() );
Map<String, Model> reactorModels = PomHelper.getReactorModels( project, getLog() );
final SortedMap<String, Model> reactor =
new TreeMap<String, Model>( new ReactorDepthComparator( reactorModels ) );
new TreeMap<>( new ReactorDepthComparator( reactorModels ) );
reactor.putAll( reactorModels );

// set of files to update
final Set<File> files = new LinkedHashSet<File>();
final Set<File> files = new LinkedHashSet<>();

getLog().info(
"Processing change of " + groupId + ":" + artifactId + ":" + oldVersion + " -> " + newVersion );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ protected void update( ModifiedPomXMLEventReader pom )
if ( artifactVersion != null )
{
getLog().info( "Updating parent from " + getProject().getParent().getVersion()
+ " to " + artifactVersion.toString() );
+ " to " + artifactVersion );

if ( PomHelper.setProjectParentVersion( pom, artifactVersion.toString() ) )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,19 +222,18 @@ && isProcessingParent() )
private ArtifactVersion[] filterVersionsWithIncludes( ArtifactVersion[] newer, Artifact artifact )
{
List<ArtifactVersion> filteredNewer = new ArrayList<>( newer.length );
for ( int j = 0; j < newer.length; j++ )
for ( ArtifactVersion artifactVersion : newer )
{
ArtifactVersion artifactVersion = newer[j];
Artifact artefactWithNewVersion =
new DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId(),
VersionRange.createFromVersion( artifactVersion.toString() ), artifact.getScope(),
artifact.getType(), null, new DefaultArtifactHandler(), false );
new DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId(),
VersionRange.createFromVersion( artifactVersion.toString() ), artifact.getScope(),
artifact.getType(), null, new DefaultArtifactHandler(), false );
if ( isIncluded( artefactWithNewVersion ) )
{
filteredNewer.add( artifactVersion );
}
}
return filteredNewer.toArray( new ArtifactVersion[filteredNewer.size()] );
return filteredNewer.toArray( new ArtifactVersion[0] );
}

}
7 changes: 3 additions & 4 deletions src/main/java/org/codehaus/mojo/versions/UseReactorMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ private void useReactor( ModifiedPomXMLEventReader pom, Collection<Dependency> d
continue;
}

for ( Object reactorProject : reactorProjects )
for ( MavenProject reactorProject : reactorProjects )
{
MavenProject project = (MavenProject) reactorProject;
MavenProject project = reactorProject;
if ( StringUtils.equals( project.getGroupId(), dep.getGroupId() )
&& StringUtils.equals( project.getArtifactId(), dep.getArtifactId() )
&& !StringUtils.equals( project.getVersion(), dep.getVersion() ) )
Expand All @@ -127,9 +127,8 @@ private void useReactor( ModifiedPomXMLEventReader pom, Collection<Dependency> d
private void useReactor( ModifiedPomXMLEventReader pom, MavenProject parent )
throws XMLStreamException, ArtifactMetadataRetrievalException
{
for ( Object reactorProject : reactorProjects )
for ( MavenProject project : reactorProjects )
{
MavenProject project = (MavenProject) reactorProject;
if ( StringUtils.equals( project.getGroupId(), parent.getGroupId() )
&& StringUtils.equals( project.getArtifactId(), parent.getArtifactId() )
&& !StringUtils.equals( project.getVersion(), parent.getVersion() ) )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -192,7 +192,7 @@ private static RuleSet getRuleSet( Wagon wagon, String remoteURI )
try
{
wagon.get( remoteURI, tempFile );
try ( InputStream is = new FileInputStream( tempFile ) )
try ( InputStream is = Files.newInputStream( tempFile.toPath() ) )
{
return readRulesFromStream( is );
}
Expand Down Expand Up @@ -356,7 +356,7 @@ private static RuleSet getRulesViaWagon( String rulesUri, Log logger, String ser
{
throw new MojoExecutionException( "Authorization failure trying to load rules from " + rulesUri, e );
}
catch ( ResourceDoesNotExistException e )
catch ( ResourceDoesNotExistException | IOException e )
{
throw new MojoExecutionException( "Could not load specified rules from " + rulesUri, e );
}
Expand All @@ -372,10 +372,6 @@ private static RuleSet getRulesViaWagon( String rulesUri, Log logger, String ser
{
throw new MojoExecutionException( "Could not establish connection to " + rulesUri, e );
}
catch ( IOException e )
{
throw new MojoExecutionException( "Could not load specified rules from " + rulesUri, e );
}

return loadedRules;
}
Expand All @@ -395,7 +391,8 @@ public Log getLog()
public ArtifactVersions lookupArtifactVersions( Artifact artifact, boolean usePluginRepositories )
throws ArtifactMetadataRetrievalException
{
List remoteRepositories = usePluginRepositories ? remotePluginRepositories : remoteArtifactRepositories;
List<ArtifactRepository> remoteRepositories = usePluginRepositories
? remotePluginRepositories : remoteArtifactRepositories;
final List<ArtifactVersion> versions =
artifactMetadataSource.retrieveAvailableVersions( artifact, localRepository, remoteRepositories );
final List<IgnoreVersion> ignoredVersions = getIgnoredVersions( artifact );
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/codehaus/mojo/versions/api/PomHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
Expand Down Expand Up @@ -1300,9 +1299,8 @@ private static void addProperties( VersionsHelper helper, Map<String, PropertyVe
{
return;
}
for ( Enumeration<String> j = (Enumeration<String>) properties.propertyNames(); j.hasMoreElements(); )
for ( String propertyName : properties.stringPropertyNames() )
{
String propertyName = j.nextElement();
if ( !result.containsKey( propertyName ) )
{
result.put( propertyName, new PropertyVersionsBuilder( profileId, propertyName, helper ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public String toString()
}

public ArtifactVersion getNewestVersion( String currentVersion, Property property, boolean allowSnapshots,
List reactorProjects, VersionsHelper helper )
List<MavenProject> reactorProjects, VersionsHelper helper )
throws InvalidVersionSpecificationException, InvalidSegmentException
{
return getNewestVersion( currentVersion, property, allowSnapshots, reactorProjects, helper, false, -1 );
Expand Down
Loading