Skip to content

Commit

Permalink
java 1.8 mandatory amd some codebase update (#33)
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Lamy <olamy@apache.org>
  • Loading branch information
olamy committed Aug 14, 2021
1 parent bfaf1ff commit 2d2cc0e
Show file tree
Hide file tree
Showing 32 changed files with 405 additions and 793 deletions.
4 changes: 2 additions & 2 deletions mrm-api/pom.xml
Expand Up @@ -22,12 +22,12 @@
<parent>
<groupId>org.codehaus.mojo</groupId>
<artifactId>mrm</artifactId>
<version>1.2.1-SNAPSHOT</version>
<version>1.3.0-SNAPSHOT</version>
</parent>

<artifactId>mrm-api</artifactId>

<name>Mock Repository Manager: API</name>
<name>Mock Repository Manager :: API</name>

<dependencies>
<dependency>
Expand Down
Expand Up @@ -16,6 +16,7 @@

package org.codehaus.mojo.mrm.api;

import java.util.Objects;
import java.util.Stack;

/**
Expand Down Expand Up @@ -119,12 +120,7 @@ public boolean equals( Object o )
{
return false;
}
if ( parent != null ? !parent.equals( abstractEntry.parent ) : abstractEntry.parent != null )
{
return false;
}

return true;
return Objects.equals(parent, abstractEntry.parent);
}

/**
Expand Down Expand Up @@ -154,7 +150,7 @@ public String toString()
*/
public final String toPath()
{
Stack<String> stack = new Stack<String>();
Stack<String> stack = new Stack<>();
Entry root = getFileSystem().getRoot();
Entry entry = this;
do
Expand All @@ -163,8 +159,8 @@ public final String toPath()
entry = entry.getParent();
}
while ( entry != null && !root.equals( entry ) );
StringBuffer buf = new StringBuffer();

StringBuilder buf = new StringBuilder();
while ( stack.size() > 1 )
{
buf.append( stack.pop() );
Expand Down
Expand Up @@ -89,11 +89,11 @@ protected Entry get( DirectoryEntry parent, String name )
Entry[] entries = listEntries( parent );
if ( entries != null )
{
for ( int i = 0; i < entries.length; i++ )
for (Entry entry : entries)
{
if ( name.equals( entries[i].getName() ) )
if (name.equals(entry.getName()))
{
return entries[i];
return entry;
}
}
}
Expand Down
Expand Up @@ -20,6 +20,7 @@
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;
import java.util.TimeZone;

/**
Expand Down Expand Up @@ -122,14 +123,6 @@ public final class Artifact
private Artifact( String groupId, String artifactId, String version, String classifier, String type, Long timestamp,
Integer buildNumber )
{
groupId.getClass();
artifactId.getClass();
version.getClass();
type.getClass();
if ( timestamp != null )
{
buildNumber.getClass();
}
this.groupId = groupId;
this.artifactId = artifactId;
this.version = version;
Expand All @@ -154,7 +147,7 @@ private Artifact( String groupId, String artifactId, String version, String clas
public Artifact( String groupId, String artifactId, String version, String classifier, String type, long timestamp,
int buildNumber )
{
this( groupId, artifactId, version, classifier, type, new Long( timestamp ), new Integer( buildNumber ) );
this( groupId, artifactId, version, classifier, type, Long.valueOf( timestamp ), Integer.valueOf( buildNumber ) );
}

/**
Expand Down Expand Up @@ -393,15 +386,15 @@ public boolean equals( Object o )
{
return false;
}
if ( classifier != null ? !classifier.equals( artifact.classifier ) : artifact.classifier != null )
if (!Objects.equals(classifier, artifact.classifier))
{
return false;
}
if ( buildNumber != null ? !buildNumber.equals( artifact.buildNumber ) : artifact.buildNumber != null )
if (!Objects.equals(buildNumber, artifact.buildNumber))
{
return false;
}
if ( timestamp != null ? !timestamp.equals( artifact.timestamp ) : artifact.timestamp != null )
if (!Objects.equals(timestamp, artifact.timestamp))
{
return false;
}
Expand Down Expand Up @@ -440,7 +433,7 @@ public boolean equalSnapshots( Artifact artifact )
{
return false;
}
if ( classifier != null ? !classifier.equals( artifact.classifier ) : artifact.classifier != null )
if (!Objects.equals(classifier, artifact.classifier))
{
return false;
}
Expand Down
Expand Up @@ -90,9 +90,9 @@ public interface FactoryHelper
Log getLog();

/**
* Returns the {@ ArchetypeManager}
* Returns the {@link ArchetypeManager}
*
* @return The {@ ArchetypeManager}
* @return The {@link ArchetypeManager}
* @since 1.0
*/
ArchetypeManager getArchetypeManager();
Expand Down
4 changes: 2 additions & 2 deletions mrm-maven-plugin/pom.xml
Expand Up @@ -22,13 +22,13 @@
<parent>
<groupId>org.codehaus.mojo</groupId>
<artifactId>mrm</artifactId>
<version>1.2.1-SNAPSHOT</version>
<version>1.3.0-SNAPSHOT</version>
</parent>

<artifactId>mrm-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>

<name>Mock Repository Manager: Maven Plugin</name>
<name>Mock Repository Manager :: Maven Plugin</name>

<prerequisites>
<maven>${mavenVersion}</maven>
Expand Down
Expand Up @@ -47,10 +47,11 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

/**
* An {@link org.codehaus.mojo.mrm.api.maven.ArtifactStore} that serves content from a running Maven instance.
Expand Down Expand Up @@ -104,7 +105,7 @@ public class ProxyArtifactStore
/**
* A cache of what artifacts are present.
*/
private final Map<String, Map<String, Artifact>> children = new HashMap<String, Map<String, Artifact>>();
private final Map<String, Map<String, Artifact>> children = new HashMap<>();

/**
* Creates a new instance.
Expand All @@ -129,7 +130,7 @@ public ProxyArtifactStore( RepositoryMetadataManager repositoryMetadataManager,
this.artifactResolver = artifactResolver;
this.archetypeManager = archetypeManager;
this.log = log;
remoteRepositories = new ArrayList<ArtifactRepository>();
remoteRepositories = new ArrayList<>();
remoteRepositories.addAll( remoteArtifactRepositories );
remoteRepositories.addAll( remotePluginRepositories );
try
Expand All @@ -139,10 +140,7 @@ public ProxyArtifactStore( RepositoryMetadataManager repositoryMetadataManager,
catch ( InvalidVersionSpecificationException e )
{
// must never happen... so if it does make sure we stop
IllegalStateException ise =
new IllegalStateException( "[0,] should always be a valid version specification" );
ise.initCause( e );
throw ise;
throw new IllegalStateException( "[0,] should always be a valid version specification", e );
}
}

Expand All @@ -155,12 +153,7 @@ private synchronized void addResolved( Artifact artifact )
{
String path =
artifact.getGroupId().replace( '.', '/' ) + '/' + artifact.getArtifactId() + "/" + artifact.getVersion();
Map<String, Artifact> artifactMapper = this.children.get( path );
if ( artifactMapper == null )
{
artifactMapper = new HashMap<String, Artifact>();
this.children.put( path, artifactMapper );
}
Map<String, Artifact> artifactMapper = this.children.computeIfAbsent(path, k -> new HashMap<>());
artifactMapper.put( artifact.getName(), artifact );
addResolved( path );
}
Expand All @@ -176,22 +169,12 @@ private synchronized void addResolved( String path )
{
String name = path.substring( index + 1 );
path = path.substring( 0, index );
Map<String, Artifact> artifactMapper = this.children.get( path );
if ( artifactMapper == null )
{
artifactMapper = new HashMap<String, Artifact>();
this.children.put( path, artifactMapper );
}
Map<String, Artifact> artifactMapper = this.children.computeIfAbsent(path, k -> new HashMap<>());
artifactMapper.put( name, null );
}
if ( !StringUtils.isEmpty( path ) )
{
Map<String, Artifact> artifactMapper = this.children.get( "" );
if ( artifactMapper == null )
{
artifactMapper = new HashMap<String, Artifact>();
this.children.put( "", artifactMapper );
}
Map<String, Artifact> artifactMapper = this.children.computeIfAbsent("", k -> new HashMap<>());
artifactMapper.put( path, null );
}
}
Expand All @@ -207,15 +190,9 @@ public synchronized Set<String> getGroupIds( String parentGroupId )
{
return Collections.emptySet();
}
Set<String> result = new HashSet<String>();
for ( Map.Entry<String, Artifact> e : artifactMapper.entrySet() )
{
if ( e.getValue() == null )
{
result.add( e.getKey() );
}
}
return result;
return artifactMapper.entrySet().stream().filter( entry -> entry.getValue() == null)
.map(Map.Entry::getKey)
.collect(Collectors.toSet());
}

/**
Expand All @@ -229,15 +206,9 @@ public synchronized Set<String> getArtifactIds( String groupId )
{
return Collections.emptySet();
}
Set<String> result = new HashSet<String>();
for ( Map.Entry<String, Artifact> e : artifactMapper.entrySet() )
{
if ( e.getValue() == null )
{
result.add( e.getKey() );
}
}
return result;
return artifactMapper.entrySet().stream().filter(entry -> entry.getValue()==null)
.map(Map.Entry::getKey)
.collect(Collectors.toSet());
}

/**
Expand All @@ -251,15 +222,9 @@ public synchronized Set<String> getVersions( String groupId, String artifactId )
{
return Collections.emptySet();
}
Set<String> result = new HashSet<String>();
for ( Map.Entry<String, Artifact> e : artifactMapper.entrySet() )
{
if ( e.getValue() == null )
{
result.add( e.getKey() );
}
}
return result;
return artifactMapper.entrySet().stream().filter(entry -> entry.getValue()==null)
.map(Map.Entry::getKey)
.collect(Collectors.toSet());
}

/**
Expand All @@ -273,15 +238,9 @@ public synchronized Set<Artifact> getArtifacts( String groupId, String artifactI
{
return Collections.emptySet();
}
Set<Artifact> result = new HashSet<Artifact>();
for ( Artifact a : artifactMapper.values() )
{
if ( a != null )
{
result.add( a );
}
}
return result;
return artifactMapper.values().stream().filter(Objects::nonNull)
.collect( Collectors.toSet() );

}

/**
Expand All @@ -307,15 +266,11 @@ public long getLastModified( Artifact artifact )
}
catch ( org.apache.maven.artifact.resolver.ArtifactNotFoundException e )
{
ArtifactNotFoundException anfe = new ArtifactNotFoundException( artifact );
anfe.initCause( e );
throw anfe;
throw new ArtifactNotFoundException( artifact , e );
}
catch ( ArtifactResolutionException e )
{
IOException ioe = new IOException( e.getMessage() );
ioe.initCause( e );
throw ioe;
throw new IOException( e.getMessage(), e );
}
}

Expand Down Expand Up @@ -346,9 +301,7 @@ public long getSize( Artifact artifact )
}
catch ( ArtifactResolutionException e )
{
IOException ioe = new IOException( e.getMessage() );
ioe.initCause( e );
throw ioe;
throw new IOException( e.getMessage(), e );
}
}

Expand Down Expand Up @@ -376,15 +329,11 @@ public InputStream get( Artifact artifact )
catch ( org.apache.maven.artifact.resolver.ArtifactNotFoundException e )
{
ArtifactNotFoundException anfe = new ArtifactNotFoundException( artifact, e );
// Causes a java.lang.IllegalStateException: Can't overwrite cause
// anfe.initCause( e );
throw anfe;
}
catch ( ArtifactResolutionException e )
{
IOException ioe = new IOException( e.getMessage() );
ioe.initCause( e );
throw ioe;
throw new IOException( e.getMessage(), e );
}
}

Expand Down Expand Up @@ -419,17 +368,16 @@ public Metadata getMetadata( String path )
if ( version != null && version.endsWith( "-SNAPSHOT" ) && !StringUtils.isEmpty( artifactId )
&& !StringUtils.isEmpty( groupId ) )
{
final org.apache.maven.artifact.Artifact artifact =
org.apache.maven.artifact.Artifact artifact =
artifactFactory.createDependencyArtifact( groupId, artifactId,
VersionRange.createFromVersion( version ), "pom", null,
"compile" );
final SnapshotArtifactRepositoryMetadata artifactRepositoryMetadata =
new SnapshotArtifactRepositoryMetadata( artifact );
SnapshotArtifactRepositoryMetadata artifactRepositoryMetadata = new SnapshotArtifactRepositoryMetadata( artifact );
try
{
repositoryMetadataManager.resolve( artifactRepositoryMetadata, remoteRepositories, localRepository );

final Metadata artifactMetadata = artifactRepositoryMetadata.getMetadata();
Metadata artifactMetadata = artifactRepositoryMetadata.getMetadata();
if ( artifactMetadata.getVersioning() != null
&& artifactMetadata.getVersioning().getSnapshot() != null )
{
Expand Down Expand Up @@ -472,9 +420,9 @@ public Metadata getMetadata( String path )
groupId = index == -1 ? null : path.substring( 0, index ).replace( '/', '.' );
if ( !StringUtils.isEmpty( artifactId ) && !StringUtils.isEmpty( groupId ) )
{
final org.apache.maven.artifact.Artifact artifact =
org.apache.maven.artifact.Artifact artifact =
artifactFactory.createDependencyArtifact( groupId, artifactId, anyVersion, "pom", null, "compile" );
final ArtifactRepositoryMetadata artifactRepositoryMetadata = new ArtifactRepositoryMetadata( artifact );
ArtifactRepositoryMetadata artifactRepositoryMetadata = new ArtifactRepositoryMetadata( artifact );
try
{
repositoryMetadataManager.resolve( artifactRepositoryMetadata, remoteRepositories, localRepository );
Expand Down

0 comments on commit 2d2cc0e

Please sign in to comment.