diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/GroupRepositoryMetadata.java b/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/GroupRepositoryMetadata.java index 490b47f305..fd88ddcb97 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/GroupRepositoryMetadata.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/GroupRepositoryMetadata.java @@ -75,11 +75,11 @@ public class GroupRepositoryMetadata String artifactId, String name ) { - List plugins = getMetadata().getPlugins(); + List plugins = getMetadata().getPlugins(); boolean found = false; - for ( Iterator i = plugins.iterator(); i.hasNext() && !found; ) + for ( Iterator i = plugins.iterator(); i.hasNext() && !found; ) { - Plugin plugin = (Plugin) i.next(); + Plugin plugin = i.next(); if ( plugin.getPrefix().equals( goalPrefix ) ) { found = true; diff --git a/maven-compat/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java b/maven-compat/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java index 9cbd7c814f..7a9ec09039 100644 --- a/maven-compat/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java +++ b/maven-compat/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java @@ -93,7 +93,7 @@ public class DefaultProfileManager return requestProperties; } - public Map getProfilesById() + public Map getProfilesById() { return profilesById; } @@ -138,13 +138,11 @@ public class DefaultProfileManager /* (non-Javadoc) * @see org.apache.maven.profiles.ProfileManager#explicitlyActivate(java.util.List) */ - public void explicitlyActivate( List profileIds ) + public void explicitlyActivate( List profileIds ) { - for ( Object profileId1 : profileIds ) + for ( String profileId1 : profileIds ) { - String profileId = (String) profileId1; - - explicitlyActivate( profileId ); + explicitlyActivate( profileId1 ); } } @@ -164,13 +162,11 @@ public class DefaultProfileManager /* (non-Javadoc) * @see org.apache.maven.profiles.ProfileManager#explicitlyDeactivate(java.util.List) */ - public void explicitlyDeactivate( List profileIds ) + public void explicitlyDeactivate( List profileIds ) { - for ( Object profileId1 : profileIds ) + for ( String profileId1 : profileIds ) { - String profileId = (String) profileId1; - - explicitlyDeactivate( profileId ); + explicitlyDeactivate( profileId1 ); } } @@ -212,13 +208,11 @@ public class DefaultProfileManager /* (non-Javadoc) * @see org.apache.maven.profiles.ProfileManager#addProfiles(java.util.List) */ - public void addProfiles( List profiles ) + public void addProfiles( List profiles ) { - for ( Object profile1 : profiles ) + for ( Profile profile1 : profiles ) { - Profile profile = (Profile) profile1; - - addProfile( profile ); + addProfile( profile1 ); } } diff --git a/maven-compat/src/main/java/org/apache/maven/profiles/ProfileManager.java b/maven-compat/src/main/java/org/apache/maven/profiles/ProfileManager.java index 603343fd19..98064eff84 100644 --- a/maven-compat/src/main/java/org/apache/maven/profiles/ProfileManager.java +++ b/maven-compat/src/main/java/org/apache/maven/profiles/ProfileManager.java @@ -34,16 +34,16 @@ public interface ProfileManager void explicitlyActivate( String profileId ); - void explicitlyActivate( List profileIds ); + void explicitlyActivate( List profileIds ); void explicitlyDeactivate( String profileId ); - void explicitlyDeactivate( List profileIds ); + void explicitlyDeactivate( List profileIds ); List getActiveProfiles() throws ProfileActivationException; - void addProfiles( List profiles ); + void addProfiles( List profiles ); Map getProfilesById(); diff --git a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/DefaultLegacyArtifactCollector.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/DefaultLegacyArtifactCollector.java index 04d0d6b70f..0d6cea8107 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/DefaultLegacyArtifactCollector.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/DefaultLegacyArtifactCollector.java @@ -342,9 +342,9 @@ public class DefaultLegacyArtifactCollector // Conflict Resolution ResolutionNode resolved = null; - for ( Iterator j = conflictResolvers.iterator(); ( resolved == null ) && j.hasNext(); ) + for ( Iterator j = conflictResolvers.iterator(); ( resolved == null ) && j.hasNext(); ) { - ConflictResolver conflictResolver = (ConflictResolver) j.next(); + ConflictResolver conflictResolver = j.next(); resolved = conflictResolver.resolveConflict( previous, node ); } @@ -424,9 +424,9 @@ public class DefaultLegacyArtifactCollector Artifact parentArtifact = node.getArtifact(); - for ( Iterator i = node.getChildrenIterator(); i.hasNext(); ) + for ( Iterator i = node.getChildrenIterator(); i.hasNext(); ) { - ResolutionNode child = (ResolutionNode) i.next(); + ResolutionNode child = i.next(); try { diff --git a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/ArtifactTransformationManager.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/ArtifactTransformationManager.java index f0ac9c89c8..95f15f98ee 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/ArtifactTransformationManager.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/ArtifactTransformationManager.java @@ -78,5 +78,5 @@ public interface ArtifactTransformationManager ArtifactRepository localRepository ) throws ArtifactDeploymentException; - List getArtifactTransformations(); + List getArtifactTransformations(); } diff --git a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/DefaultArtifactTransformationManager.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/DefaultArtifactTransformationManager.java index e9b1afbce6..024778de9a 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/DefaultArtifactTransformationManager.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/DefaultArtifactTransformationManager.java @@ -79,7 +79,7 @@ public class DefaultArtifactTransformationManager } } - public List getArtifactTransformations() + public List getArtifactTransformations() { return artifactTransformations; } diff --git a/maven-compat/src/main/java/org/apache/maven/usability/plugin/ExpressionDocumenter.java b/maven-compat/src/main/java/org/apache/maven/usability/plugin/ExpressionDocumenter.java index d0aeb31609..65bd9cf620 100644 --- a/maven-compat/src/main/java/org/apache/maven/usability/plugin/ExpressionDocumenter.java +++ b/maven-compat/src/main/java/org/apache/maven/usability/plugin/ExpressionDocumenter.java @@ -44,7 +44,7 @@ public class ExpressionDocumenter private static Map expressionDocumentation; - public static Map load() + public static Map load() throws ExpressionDocumentationException { if ( expressionDocumentation == null ) @@ -117,17 +117,15 @@ public class ExpressionDocumenter ExpressionDocumentation documentation = paramdocReader.read( reader, true ); - List expressions = documentation.getExpressions(); + List expressions = documentation.getExpressions(); Map bySyntax = new HashMap<>(); if ( expressions != null && !expressions.isEmpty() ) { - for ( Object expression : expressions ) + for ( Expression expression : expressions ) { - Expression expr = (Expression) expression; - - bySyntax.put( expr.getSyntax(), expr ); + bySyntax.put( expression.getSyntax(), expression ); } } diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java index df49dbd55a..72a2017f61 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java @@ -241,7 +241,7 @@ public class ArtifactResolverTest printErrors( result ); - Iterator i = result.getArtifacts().iterator(); + Iterator i = result.getArtifacts().iterator(); assertEquals( "n should be first", n, i.next() ); assertEquals( "m should be second", m, i.next() ); diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecyclePhase.java b/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecyclePhase.java index a68a71c00f..e0cc8ddcdf 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecyclePhase.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecyclePhase.java @@ -50,7 +50,7 @@ public class LifecyclePhase public void set( String goals ) { - mojos = new ArrayList(); + mojos = new ArrayList<>(); String[] mojoGoals = StringUtils.split( goals, "," ); diff --git a/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java index 1a3100e911..48b8e5ef83 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java @@ -60,7 +60,7 @@ public interface PluginManager Object getPluginComponent( Plugin plugin, String role, String roleHint ) throws PluginManagerException, ComponentLookupException; - Map getPluginComponents( Plugin plugin, String role ) + Map getPluginComponents( Plugin plugin, String role ) throws ComponentLookupException, PluginManagerException; /** diff --git a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java index edb5cfe231..e7eecb5d18 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java @@ -203,8 +203,7 @@ public class DefaultMavenPluginManager { if ( pluginFile.isFile() ) { - JarFile pluginJar = new JarFile( pluginFile, false ); - try + try ( JarFile pluginJar = new JarFile( pluginFile, false ) ) { ZipEntry pluginDescriptorEntry = pluginJar.getEntry( getPluginDescriptorLocation() ); @@ -215,10 +214,6 @@ public class DefaultMavenPluginManager pluginDescriptor = parsePluginDescriptor( is, plugin, pluginFile.getAbsolutePath() ); } } - finally - { - pluginJar.close(); - } } else { @@ -274,11 +269,7 @@ public class DefaultMavenPluginManager return pluginDescriptor; } - catch ( IOException e ) - { - throw new PluginDescriptorParsingException( plugin, descriptorLocation, e ); - } - catch ( PlexusConfigurationException e ) + catch ( IOException | PlexusConfigurationException e ) { throw new PluginDescriptorParsingException( plugin, descriptorLocation, e ); } @@ -369,7 +360,7 @@ public class DefaultMavenPluginManager if ( cacheRecord != null ) { pluginDescriptor.setClassRealm( cacheRecord.realm ); - pluginDescriptor.setArtifacts( new ArrayList( cacheRecord.artifacts ) ); + pluginDescriptor.setArtifacts( new ArrayList<>( cacheRecord.artifacts ) ); for ( ComponentDescriptor componentDescriptor : pluginDescriptor.getComponents() ) { componentDescriptor.setRealm( cacheRecord.realm ); @@ -450,13 +441,7 @@ public class DefaultMavenPluginManager ( (DefaultPlexusContainer) container ).discoverComponents( pluginRealm, new SessionScopeModule( container ), new MojoExecutionScopeModule( container ) ); } - catch ( ComponentLookupException e ) - { - throw new PluginContainerException( plugin, pluginRealm, - "Error in component graph of plugin " + plugin.getId() + ": " - + e.getMessage(), e ); - } - catch ( CycleDetectedInComponentGraphException e ) + catch ( ComponentLookupException | CycleDetectedInComponentGraphException e ) { throw new PluginContainerException( plugin, pluginRealm, "Error in component graph of plugin " + plugin.getId() + ": " @@ -466,12 +451,12 @@ public class DefaultMavenPluginManager private List toAetherArtifacts( final List pluginArtifacts ) { - return new ArrayList( RepositoryUtils.toArtifacts( pluginArtifacts ) ); + return new ArrayList<>( RepositoryUtils.toArtifacts( pluginArtifacts ) ); } private List toMavenArtifacts( DependencyNode root, PreorderNodeListGenerator nlg ) { - List artifacts = new ArrayList( nlg.getNodes().size() ); + List artifacts = new ArrayList<>( nlg.getNodes().size() ); RepositoryUtils.toArtifacts( artifacts, Collections.singleton( root ), Collections.emptyList(), null ); for ( Iterator it = artifacts.iterator(); it.hasNext(); ) { @@ -486,7 +471,7 @@ public class DefaultMavenPluginManager private Map calcImports( MavenProject project, ClassLoader parent, List imports ) { - Map foreignImports = new HashMap(); + Map foreignImports = new HashMap<>(); ClassLoader projectRealm = project.getClassRealm(); if ( projectRealm != null ) @@ -661,7 +646,7 @@ public class DefaultMavenPluginManager { if ( "basic".equals( configuratorId ) ) { - throw new PluginParameterException( mojoDescriptor, new ArrayList( missingParameters ) ); + throw new PluginParameterException( mojoDescriptor, new ArrayList<>( missingParameters ) ); } else { @@ -736,7 +721,7 @@ public class DefaultMavenPluginManager return; } - List invalidParameters = new ArrayList(); + List invalidParameters = new ArrayList<>(); for ( Parameter parameter : mojoDescriptor.getParameters() ) { @@ -811,7 +796,7 @@ public class DefaultMavenPluginManager (Map) project.getContextValue( KEY_EXTENSIONS_REALMS ); if ( pluginRealms == null ) { - pluginRealms = new HashMap(); + pluginRealms = new HashMap<>(); project.setContextValue( KEY_EXTENSIONS_REALMS, pluginRealms ); } @@ -890,11 +875,7 @@ public class DefaultMavenPluginManager { pluginDescriptor = extractPluginDescriptor( artifacts.get( 0 ), plugin ); } - catch ( PluginDescriptorParsingException e ) - { - // ignore, see above - } - catch ( InvalidPluginDescriptorException e ) + catch ( PluginDescriptorParsingException | InvalidPluginDescriptorException e ) { // ignore, see above } diff --git a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginManager.java index e2f4526cfe..a8ac9ebd03 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginManager.java @@ -19,8 +19,6 @@ package org.apache.maven.plugin.internal; * under the License. */ -import java.util.Map; - import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; @@ -59,6 +57,8 @@ import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; +import java.util.Map; + /** * @author Benjamin Bentmann */ @@ -121,7 +121,7 @@ public class DefaultPluginManager } } - public Map getPluginComponents( Plugin plugin, String role ) + public Map getPluginComponents( Plugin plugin, String role ) throws ComponentLookupException, PluginManagerException { MavenSession session = legacySupport.getSession(); diff --git a/maven-settings-builder/src/main/java/org/apache/maven/settings/validation/DefaultSettingsValidator.java b/maven-settings-builder/src/main/java/org/apache/maven/settings/validation/DefaultSettingsValidator.java index 5c4f10f8f4..1e31f504ff 100644 --- a/maven-settings-builder/src/main/java/org/apache/maven/settings/validation/DefaultSettingsValidator.java +++ b/maven-settings-builder/src/main/java/org/apache/maven/settings/validation/DefaultSettingsValidator.java @@ -147,7 +147,7 @@ public class DefaultSettingsValidator if ( proxies != null ) { - Set proxyIds = new HashSet(); + Set proxyIds = new HashSet<>(); for ( Proxy proxy : proxies ) {