Skip to content

Commit

Permalink
Quick fixes for problems reported by the IDE
Browse files Browse the repository at this point in the history
  • Loading branch information
slachiewicz committed Sep 23, 2020
1 parent 0e1b878 commit dfb1e61
Show file tree
Hide file tree
Showing 27 changed files with 66 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,11 @@ private void validateParameters( ProjectBuildingRequest request, Collection<Arti
* @return true if the current Maven version is Maven 3.1.
*/
private boolean isMaven31()
{
return canFindCoreClass( "org.eclipse.aether.artifact.Artifact" ); // Maven 3.1 specific
}

private boolean canFindCoreClass( String className )
{
try
{
Thread.currentThread().getContextClassLoader().loadClass( className );

// Maven 3.1 specific
Thread.currentThread().getContextClassLoader().loadClass( "org.eclipse.aether.artifact.Artifact" );
return true;
}
catch ( ClassNotFoundException e )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,11 @@ private void validateParameters( ProjectBuildingRequest request, Collection<Arti
* @return true if the current Maven version is Maven 3.1.
*/
private boolean isMaven31()
{
return canFindCoreClass( "org.eclipse.aether.artifact.Artifact" ); // Maven 3.1 specific
}

private boolean canFindCoreClass( String className )
{
try
{
Thread.currentThread().getContextClassLoader().loadClass( className );

// Maven 3.1 specific
Thread.currentThread().getContextClassLoader().loadClass( "org.eclipse.aether.artifact.Artifact" );
return true;
}
catch ( ClassNotFoundException e )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,11 @@ private void validateParameters( ProjectBuildingRequest buildingRequest, Artifac
* @return true if the current Maven version is Maven 3.1.
*/
private boolean isMaven31()
{
return canFindCoreClass( "org.eclipse.aether.artifact.Artifact" ); // Maven 3.1 specific
}

private boolean canFindCoreClass( String className )
{
try
{
Thread.currentThread().getContextClassLoader().loadClass( className );

// Maven 3.1 specific
Thread.currentThread().getContextClassLoader().loadClass( "org.eclipse.aether.artifact.Artifact" );
return true;
}
catch ( ClassNotFoundException e )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public CollectRequest addDependency( Dependency dependency )
{
if ( this.dependencies.isEmpty() )
{
this.dependencies = new ArrayList<Dependency>();
this.dependencies = new ArrayList<>();
}
this.dependencies.add( dependency );
}
Expand Down Expand Up @@ -243,7 +243,7 @@ public CollectRequest addManagedDependency( Dependency managedDependency )
{
if ( this.managedDependencies.isEmpty() )
{
this.managedDependencies = new ArrayList<Dependency>();
this.managedDependencies = new ArrayList<>();
}
this.managedDependencies.add( managedDependency );
}
Expand Down Expand Up @@ -291,7 +291,7 @@ public CollectRequest addRepository( ArtifactRepository repository )
{
if ( this.repositories.isEmpty() )
{
this.repositories = new ArrayList<ArtifactRepository>();
this.repositories = new ArrayList<>();
}
this.repositories.add( repository );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,23 +133,18 @@ private void validateRoot( Object root )
*/
private boolean isMaven31()
{
return canFindCoreClass( "org.eclipse.aether.artifact.Artifact" ); // Maven 3.1 specific
try
{
// Maven 3.1 specific
Thread.currentThread().getContextClassLoader().loadClass( "org.eclipse.aether.artifact.Artifact" );
return true;
}
catch ( ClassNotFoundException e )
{
return false;
}
}

private boolean canFindCoreClass( String className )
{
try
{
Thread.currentThread().getContextClassLoader().loadClass( className );

return true;
}
catch ( ClassNotFoundException e )
{
return false;
}
}

/**
* Injects the Plexus content.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.lang.reflect.InvocationTargetException;

import org.apache.maven.shared.transfer.collection.DependencyCollectionException;
import org.apache.maven.shared.transfer.dependencies.collect.DependencyCollectorException;

/**
* Invokes method on objects using reflection.
Expand Down Expand Up @@ -72,7 +71,7 @@ public static <T> T invoke( Class<?> objectClazz, String staticMethod, Class<?>
* @param argClasses the classes of the argument, used to select the right static method
* @param args the actual arguments to be passed
* @return the result of the method invocation
* @throws DependencyCollectorException if any checked exception occurs
* @throws DependencyCollectionException if any checked exception occurs
*/
public static <T> T invoke( Class<?> objectClazz, String staticMethod, Class<?>[] argClasses, Object[] args )
throws DependencyCollectionException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public CollectResult collectDependencies( Model root )
.invoke( RepositoryUtils.class, "newArtifactTypeRegistry",
ArtifactHandlerManager.class, artifactHandlerManager );

List<Dependency> aetherDependencies = new ArrayList<Dependency>( root.getDependencies().size() );
List<Dependency> aetherDependencies = new ArrayList<>( root.getDependencies().size() );
for ( org.apache.maven.model.Dependency mavenDependency : root.getDependencies() )
{
aetherDependencies.add( toDependency( mavenDependency, typeRegistry ) );
Expand All @@ -125,8 +125,8 @@ public CollectResult collectDependencies( Model root )

if ( root.getDependencyManagement() != null )
{
List<Dependency> aetherManagerDependencies =
new ArrayList<Dependency>( root.getDependencyManagement().getDependencies().size() );
List<Dependency> aetherManagerDependencies = new ArrayList<>(
root.getDependencyManagement().getDependencies().size() );

for ( org.apache.maven.model.Dependency mavenDependency : root.getDependencyManagement().getDependencies() )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public List<DependencyNode> getChildren()
public List<ArtifactRepository> getRemoteRepositories()
{
List<RemoteRepository> aetherRepositories = dependencyNode.getRepositories();
List<ArtifactRepository> mavenRepositories = new ArrayList<ArtifactRepository>( aetherRepositories.size() );
List<ArtifactRepository> mavenRepositories = new ArrayList<>( aetherRepositories.size() );

for ( RemoteRepository aetherRepository : aetherRepositories )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public CollectResult collectDependencies( Model root )
.invoke( RepositoryUtils.class, "newArtifactTypeRegistry",
ArtifactHandlerManager.class, artifactHandlerManager );

List<Dependency> aetherDependencies = new ArrayList<Dependency>( root.getDependencies().size() );
List<Dependency> aetherDependencies = new ArrayList<>( root.getDependencies().size() );
for ( org.apache.maven.model.Dependency mavenDependency : root.getDependencies() )
{
aetherDependencies.add( toDependency( mavenDependency, typeRegistry ) );
Expand All @@ -125,8 +125,8 @@ public CollectResult collectDependencies( Model root )

if ( root.getDependencyManagement() != null )
{
List<Dependency> aetherManagerDependencies =
new ArrayList<Dependency>( root.getDependencyManagement().getDependencies().size() );
List<Dependency> aetherManagerDependencies = new ArrayList<>(
root.getDependencyManagement().getDependencies().size() );

for ( org.apache.maven.model.Dependency mavenDependency : root.getDependencyManagement().getDependencies() )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public List<DependencyNode> getChildren()
public List<ArtifactRepository> getRemoteRepositories()
{
List<RemoteRepository> aetherRepositories = dependencyNode.getRepositories();
List<ArtifactRepository> mavenRepositories = new ArrayList<ArtifactRepository>( aetherRepositories.size() );
List<ArtifactRepository> mavenRepositories = new ArrayList<>( aetherRepositories.size() );

for ( RemoteRepository aetherRepository : aetherRepositories )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,11 @@ private void validateRoot( Object root )
* @return true if the current Maven version is Maven 3.1.
*/
private boolean isMaven31()
{
return canFindCoreClass( "org.eclipse.aether.artifact.Artifact" ); // Maven 3.1 specific
}

private boolean canFindCoreClass( String className )
{
try
{
Thread.currentThread().getContextClassLoader().loadClass( className );

// Maven 3.1 specific
Thread.currentThread().getContextClassLoader().loadClass( "org.eclipse.aether.artifact.Artifact" );
return true;
}
catch ( ClassNotFoundException e )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
* under the License.
*/

import java.lang.reflect.InvocationTargetException;

import org.apache.maven.shared.transfer.dependencies.collect.DependencyCollectorException;

import java.lang.reflect.InvocationTargetException;

/**
* Invokes method on objects using reflection.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Maven30CollectorResult implements CollectorResult
@Override
public List<ArtifactRepository> getRemoteRepositories()
{
final Set<RemoteRepository> aetherRepositories = new HashSet<RemoteRepository>();
final Set<RemoteRepository> aetherRepositories = new HashSet<>();

DependencyVisitor visitor = new DependencyVisitor()
{
Expand All @@ -72,7 +72,7 @@ public boolean visitLeave( DependencyNode node )

collectResult.getRoot().accept( visitor );

List<ArtifactRepository> mavenRepositories = new ArrayList<ArtifactRepository>( aetherRepositories.size() );
List<ArtifactRepository> mavenRepositories = new ArrayList<>( aetherRepositories.size() );

for ( RemoteRepository aetherRepository : aetherRepositories )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private static Dependency toDependency( org.apache.maven.model.Dependency mavenD

Object[] args = new Object[] {mavenDependency, typeRegistry};

return (Dependency) Invoker.invoke( RepositoryUtils.class, "toDependency", argClasses, args );
return Invoker.invoke( RepositoryUtils.class, "toDependency", argClasses, args );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public List<DependencyNode> getChildren()
public List<ArtifactRepository> getRemoteRepositories()
{
List<RemoteRepository> aetherRepositories = dependencyNode.getRepositories();
List<ArtifactRepository> mavenRepositories = new ArrayList<ArtifactRepository>( aetherRepositories.size() );
List<ArtifactRepository> mavenRepositories = new ArrayList<>( aetherRepositories.size() );

for ( RemoteRepository aetherRepository : aetherRepositories )
{
Expand Down Expand Up @@ -152,7 +152,7 @@ private Artifact getArtifact( org.sonatype.aether.artifact.Artifact aetherArtifa
{
try
{
return (Artifact) Invoker.invoke( RepositoryUtils.class, "toArtifact",
return Invoker.invoke( RepositoryUtils.class, "toArtifact",
org.sonatype.aether.artifact.Artifact.class, aetherArtifact );
}
catch ( DependencyCollectorException e )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Maven31CollectorResult implements CollectorResult
@Override
public List<ArtifactRepository> getRemoteRepositories()
{
final Set<RemoteRepository> aetherRepositories = new HashSet<RemoteRepository>();
final Set<RemoteRepository> aetherRepositories = new HashSet<>();

DependencyVisitor visitor = new DependencyVisitor()
{
Expand All @@ -72,7 +72,7 @@ public boolean visitLeave( DependencyNode node )

collectResult.getRoot().accept( visitor );

List<ArtifactRepository> mavenRepositories = new ArrayList<ArtifactRepository>( aetherRepositories.size() );
List<ArtifactRepository> mavenRepositories = new ArrayList<>( aetherRepositories.size() );

for ( RemoteRepository aetherRepository : aetherRepositories )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private static Dependency toDependency( org.apache.maven.model.Dependency mavenD

Object[] args = new Object[] {mavenDependency, typeRegistry};

return (Dependency) Invoker.invoke( RepositoryUtils.class, "toDependency", argClasses, args );
return Invoker.invoke( RepositoryUtils.class, "toDependency", argClasses, args );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public List<DependencyNode> getChildren()
public List<ArtifactRepository> getRemoteRepositories()
{
List<RemoteRepository> aetherRepositories = dependencyNode.getRepositories();
List<ArtifactRepository> mavenRepositories = new ArrayList<ArtifactRepository>( aetherRepositories.size() );
List<ArtifactRepository> mavenRepositories = new ArrayList<>( aetherRepositories.size() );

for ( RemoteRepository aetherRepository : aetherRepositories )
{
Expand Down Expand Up @@ -152,7 +152,7 @@ private Artifact getArtifact( org.eclipse.aether.artifact.Artifact aetherArtifac
{
try
{
return (Artifact) Invoker.invoke( RepositoryUtils.class, "toArtifact",
return Invoker.invoke( RepositoryUtils.class, "toArtifact",
org.eclipse.aether.artifact.Artifact.class, aetherArtifact );
}
catch ( DependencyCollectorException e )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,11 @@ public Iterable<ArtifactResult> resolveDependencies( ProjectBuildingRequest buil
* @return true if the current Maven version is Maven 3.1.
*/
private boolean isMaven31()
{
return canFindCoreClass( "org.eclipse.aether.artifact.Artifact" ); // Maven 3.1 specific
}

private boolean canFindCoreClass( String className )
{
try
{
Thread.currentThread().getContextClassLoader().loadClass( className );

// Maven 3.1 specific
Thread.currentThread().getContextClassLoader().loadClass( "org.eclipse.aether.artifact.Artifact" );
return true;
}
catch ( ClassNotFoundException e )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,7 @@ private Iterable<org.apache.maven.shared.transfer.artifact.resolve.ArtifactResul
public Iterator<org.apache.maven.shared.transfer.artifact.resolve.ArtifactResult> iterator()
{
// CHECKSTYLE_OFF: LineLength
Collection<org.apache.maven.shared.transfer.artifact.resolve.ArtifactResult> artResults =
new ArrayList<org.apache.maven.shared.transfer.artifact.resolve.ArtifactResult>(
Collection<org.apache.maven.shared.transfer.artifact.resolve.ArtifactResult> artResults = new ArrayList<>(
dependencyResults.getArtifactResults().size() );
// CHECKSTYLE_ON: LineLength

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void deploy( ProjectBuildingRequest buildingRequest, ProjectDeployerReque

int retryFailedDeploymentCount = projectDeployerRequest.getRetryFailedDeploymentCount();

List<Artifact> deployableArtifacts = new ArrayList<Artifact>();
List<Artifact> deployableArtifacts = new ArrayList<>();
if ( isPomArtifact )
{
deployableArtifacts.add( artifact );
Expand All @@ -118,10 +118,7 @@ else if ( !attachedArtifacts.isEmpty() )
}
}

for ( Artifact attached : attachedArtifacts )
{
deployableArtifacts.add( attached );
}
deployableArtifacts.addAll( attachedArtifacts );

deploy( buildingRequest, deployableArtifacts, artifactRepository, retryFailedDeploymentCount );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void install( ProjectBuildingRequest buildingRequest, ProjectInstallerReq

ProjectArtifactMetadata metadata;

Collection<File> metadataFiles = new LinkedHashSet<File>();
Collection<File> metadataFiles = new LinkedHashSet<>();

if ( isPomArtifact )
{
Expand All @@ -108,7 +108,7 @@ public void install( ProjectBuildingRequest buildingRequest, ProjectInstallerReq
// but not package). We are designing in a proper solution for Maven 2.1
if ( file != null && file.isFile() )
{
installer.install( buildingRequest, Collections.<Artifact>singletonList( artifact ) );
installer.install( buildingRequest, Collections.singletonList( artifact ) );
addMetaDataFilesForArtifact( buildingRequest, artifact, metadataFiles );
}
else if ( !attachedArtifacts.isEmpty() )
Expand Down
Loading

0 comments on commit dfb1e61

Please sign in to comment.