Skip to content

Commit

Permalink
Java 8 code style update and bump some maven dependencies (#463)
Browse files Browse the repository at this point in the history
* some cleanup

Signed-off-by: olivier lamy <olamy@apache.org>

* some cleanup

Signed-off-by: olivier lamy <olamy@apache.org>

* Update src/main/java/org/codehaus/mojo/versions/AbstractVersionsDependencyUpdaterMojo.java

Co-authored-by: Benjamin Marwell <bmarwell@apache.org>

* Update src/main/java/org/codehaus/mojo/versions/AbstractVersionsDependencyUpdaterMojo.java

Co-authored-by: Benjamin Marwell <bmarwell@apache.org>

* Update src/main/java/org/codehaus/mojo/versions/AbstractVersionsDependencyUpdaterMojo.java

Co-authored-by: Benjamin Marwell <bmarwell@apache.org>

* Update src/main/java/org/codehaus/mojo/versions/DisplayDependencyUpdatesMojo.java

Co-authored-by: Benjamin Marwell <bmarwell@apache.org>

* fix casting and renamed variable.

* rework dependency matching

* rework dependency management dependency matches and loop.

* more cleanup java8, upgrade some maven dependencies but this might need more changes

Signed-off-by: olivier lamy <olamy@apache.org>

* Update src/main/java/org/codehaus/mojo/versions/api/PomHelper.java

Co-authored-by: Benjamin Marwell <bmarwell@apache.org>

* sugar syntax

Signed-off-by: olivier lamy <olamy@apache.org>

Co-authored-by: Benjamin Marwell <bmarwell@apache.org>
Co-authored-by: Benjamin Marwell <bmarwell@gmail.com>
  • Loading branch information
3 people committed Jun 29, 2021
1 parent d94fe01 commit efca2ce
Show file tree
Hide file tree
Showing 36 changed files with 243 additions and 372 deletions.
22 changes: 3 additions & 19 deletions pom.xml
Expand Up @@ -25,17 +25,6 @@
</license>
</licenses>

<distributionManagement>
<repository>
<id>ossrh-staging</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
</repository>
<snapshotRepository>
<id>ossrh-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>

<developers>
<developer>
<name>Stephen Connolly</name>
Expand Down Expand Up @@ -110,7 +99,7 @@
<mojo.java.target>1.8</mojo.java.target>
<maven.compiler.source>${mojo.java.target}</maven.compiler.source>

<mavenVersion>2.2.1</mavenVersion>
<mavenVersion>3.0.5</mavenVersion>
<wagonVersion>3.4.0</wagonVersion>
<doxiaVersion>1.9.1</doxiaVersion>
<doxia-sitetoolsVersion>1.7</doxia-sitetoolsVersion>
Expand All @@ -134,12 +123,12 @@
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact-manager</artifactId>
<artifactId>maven-core</artifactId>
<version>${mavenVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<artifactId>maven-compat</artifactId>
<version>${mavenVersion}</version>
</dependency>
<dependency>
Expand All @@ -157,11 +146,6 @@
<artifactId>maven-settings</artifactId>
<version>${mavenVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>${mavenVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-api</artifactId>
Expand Down
Expand Up @@ -22,7 +22,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -207,10 +206,8 @@ protected Artifact findArtifact( Dependency dependency )
{
return null;
}
Iterator<?> iter = getProject().getDependencyArtifacts().iterator();
while ( iter.hasNext() )
for ( Artifact artifact : getProject().getDependencyArtifacts() )
{
Artifact artifact = (Artifact) iter.next();
if ( compare( artifact, dependency ) )
{
return artifact;
Expand Down Expand Up @@ -334,11 +331,7 @@ private boolean compare( MavenProject project, Dependency dep )
{
return false;
}
if ( !StringUtils.equals( project.getArtifactId(), dep.getArtifactId() ) )
{
return false;
}
return true;
return project.getArtifactId().equals( dep.getArtifactId() );
}

/**
Expand All @@ -363,11 +356,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 +484,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 @@ -125,13 +125,13 @@ public abstract class AbstractVersionsReport
* @since 1.0-alpha-3
*/
@Parameter( defaultValue = "${project.remoteArtifactRepositories}", readonly = true )
protected List remoteArtifactRepositories;
protected List<ArtifactRepository> remoteArtifactRepositories;

/**
* @since 1.0-alpha-3
*/
@Parameter( defaultValue = "${project.pluginArtifactRepositories}", readonly = true )
protected List remotePluginRepositories;
protected List<ArtifactRepository> remotePluginRepositories;

/**
* @since 1.0-alpha-1
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 @@ -112,13 +112,13 @@ public abstract class AbstractVersionsUpdaterMojo
* @since 1.0-alpha-3
*/
@Parameter( defaultValue = "${project.remoteArtifactRepositories}", readonly = true )
protected List remoteArtifactRepositories;
protected List<ArtifactRepository> remoteArtifactRepositories;

/**
* @since 1.0-alpha-3
*/
@Parameter( defaultValue = "${project.pluginArtifactRepositories}", readonly = true )
protected List remotePluginRepositories;
protected List<ArtifactRepository> remotePluginRepositories;

/**
* @since 1.0-alpha-1
Expand Down Expand Up @@ -336,11 +336,7 @@ protected void process( File outFile )
writeFile( outFile, input );
}
}
catch ( IOException e )
{
getLog().error( e );
}
catch ( XMLStreamException e )
catch ( IOException | XMLStreamException e )
{
getLog().error( e );
}
Expand Down Expand Up @@ -434,18 +430,18 @@ protected boolean shouldApplyUpdate( Artifact artifact, String currentVersion, A
}
catch ( ArtifactResolutionException e )
{
getLog().warn( "Not updating version: could not resolve " + artifact.toString(), e );
getLog().warn( "Not updating version: could not resolve " + artifact, e );
return false;
}
catch ( ArtifactNotFoundException e )
{
getLog().warn( "Not updating version: could not find " + artifact.toString(), e );
getLog().warn( "Not updating version: could not find " + artifact, e );
return false;
}

if ( currentVersion.equals( updateVersion.toString() ) )
{
getLog().info( "Current version of " + artifact.toString() + " is the latest." );
getLog().info( "Current version of " + artifact + " is the latest." );
return false;
}
return true;
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 @@ -40,6 +40,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;

Expand Down Expand Up @@ -159,10 +160,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 +174,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,33 +193,55 @@ 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 dependency : dependencies )
{
Dependency c = i.next();
boolean matched = false;
Iterator<Dependency> j = dependencyManagement.iterator();
while ( !matched && j.hasNext() )
for ( Dependency managedDependency : dependencyManagement )
{
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() ) ) )
if ( dependenciesMatch( dependency, managedDependency ) )
{
matched = true;
break;
}
}
if ( !matched )
{
result.add( c );
result.add( dependency );
}
}
return result;
}

// open for tests
protected static boolean dependenciesMatch( Dependency dependency, Dependency managedDependency )
{
if ( ! managedDependency.getGroupId().equals( dependency.getGroupId() ) )
{
return false;
}

if ( ! managedDependency.getArtifactId().equals( dependency.getArtifactId() ) )
{
return false;
}

if ( managedDependency.getScope() == null
|| Objects.equals( managedDependency.getScope(), dependency.getScope() ) )
{
return false;
}

if ( managedDependency.getClassifier() == null
|| Objects.equals( managedDependency.getClassifier(), dependency.getClassifier() ) )
{
return false;
}

return dependency.getVersion() == null
|| managedDependency.getVersion() == null
|| Objects.equals( managedDependency.getVersion(), dependency.getVersion() );
}

public boolean isProcessingDependencyManagement()
{
return processDependencyManagement;
Expand Down Expand Up @@ -355,11 +372,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 )
{
throw new MojoExecutionException( e.getMessage(), e );
}
Expand Down

0 comments on commit efca2ce

Please sign in to comment.