This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch refactor-test
in repository https://gitbox.apache.org/repos/asf/maven-help-plugin.git

commit 72c53136542f72ad1bf0998e535511a289708cff
Author: Sylwester Lachiewicz <slachiew...@apache.org>
AuthorDate: Mon Jan 11 23:52:16 2021 +0100

    Sonar: fix reported issues
    
    
    s
---
 .../maven/plugins/help/AbstractEffectiveMojo.java  |  25 +----
 .../maven/plugins/help/AbstractHelpMojo.java       |  16 +--
 .../maven/plugins/help/ActiveProfilesMojo.java     |   2 +-
 .../apache/maven/plugins/help/AllProfilesMojo.java |   6 +-
 .../apache/maven/plugins/help/DescribeMojo.java    |  26 ++---
 .../maven/plugins/help/EffectivePomMojo.java       |  39 ++------
 .../maven/plugins/help/EffectiveSettingsMojo.java  |  19 ++--
 .../apache/maven/plugins/help/EvaluateMojo.java    | 110 +++++----------------
 .../maven/plugins/help/ActiveProfilesMojoTest.java |  14 +--
 .../maven/plugins/help/AllProfilesMojoTest.java    |  18 ++--
 .../maven/plugins/help/DescribeMojoTest.java       |   9 +-
 .../maven/plugins/help/EvaluateMojoTest.java       |  10 +-
 .../help/stubs/DefaultMavenProjectStub.java        |  12 +--
 13 files changed, 86 insertions(+), 220 deletions(-)

diff --git 
a/src/main/java/org/apache/maven/plugins/help/AbstractEffectiveMojo.java 
b/src/main/java/org/apache/maven/plugins/help/AbstractEffectiveMojo.java
index 6575224..f1232ac 100644
--- a/src/main/java/org/apache/maven/plugins/help/AbstractEffectiveMojo.java
+++ b/src/main/java/org/apache/maven/plugins/help/AbstractEffectiveMojo.java
@@ -31,7 +31,6 @@ import java.util.List;
 import java.util.Properties;
 import java.util.Set;
 
-import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.WriterFactory;
 import org.codehaus.plexus.util.xml.XMLWriter;
 import org.codehaus.plexus.util.xml.XmlWriterUtil;
@@ -66,21 +65,10 @@ public abstract class AbstractEffectiveMojo
             return;
         }
 
-        Writer out = null;
-        try
+        output.getParentFile().mkdirs();
+        try ( Writer out = WriterFactory.newXmlWriter( output ) )
         {
-            output.getParentFile().mkdirs();
-
-            out = WriterFactory.newXmlWriter( output );
-
             out.write( content );
-
-            out.close();
-            out = null;
-        }
-        finally
-        {
-            IOUtil.close( out );
         }
     }
 
@@ -142,11 +130,7 @@ public abstract class AbstractEffectiveMojo
 
             return w.toString();
         }
-        catch ( JDOMException e )
-        {
-            return effectiveModel;
-        }
-        catch ( IOException e )
+        catch ( JDOMException | IOException e )
         {
             return effectiveModel;
         }
@@ -163,13 +147,14 @@ public abstract class AbstractEffectiveMojo
 
         /** {@inheritDoc} */
         @SuppressWarnings( { "rawtypes", "unchecked" } )
+        @Override
         public Set<Object> keySet()
         {
             Set<Object> keynames = super.keySet();
             List list = new ArrayList( keynames );
             Collections.sort( list );
 
-            return new LinkedHashSet<Object>( list );
+            return new LinkedHashSet<>( list );
         }
     }
 }
diff --git a/src/main/java/org/apache/maven/plugins/help/AbstractHelpMojo.java 
b/src/main/java/org/apache/maven/plugins/help/AbstractHelpMojo.java
index f8dd75c..0f079ff 100644
--- a/src/main/java/org/apache/maven/plugins/help/AbstractHelpMojo.java
+++ b/src/main/java/org/apache/maven/plugins/help/AbstractHelpMojo.java
@@ -32,7 +32,6 @@ import org.apache.maven.project.DefaultProjectBuildingRequest;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.ProjectBuilder;
 import org.apache.maven.project.ProjectBuildingRequest;
-import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.WriterFactory;
 import org.eclipse.aether.RepositoryException;
@@ -138,21 +137,10 @@ public abstract class AbstractHelpMojo
             return;
         }
 
-        Writer out = null;
-        try
+        output.getParentFile().mkdirs();
+        try ( Writer out = WriterFactory.newPlatformWriter( output ) )
         {
-            output.getParentFile().mkdirs();
-
-            out = WriterFactory.newPlatformWriter( output );
-
             out.write( content );
-
-            out.close();
-            out = null;
-        }
-        finally
-        {
-            IOUtil.close( out );
         }
     }
     
diff --git 
a/src/main/java/org/apache/maven/plugins/help/ActiveProfilesMojo.java 
b/src/main/java/org/apache/maven/plugins/help/ActiveProfilesMojo.java
index 7ac8e6b..326ee9c 100644
--- a/src/main/java/org/apache/maven/plugins/help/ActiveProfilesMojo.java
+++ b/src/main/java/org/apache/maven/plugins/help/ActiveProfilesMojo.java
@@ -106,7 +106,7 @@ public class ActiveProfilesMojo
         Map<String, List<String>> activeProfileIds = 
project.getInjectedProfileIds();
 
         message.append( LS );
-        message.append( "Active Profiles for Project \'" ).append( 
project.getId() ).append( "\':" );
+        message.append( "Active Profiles for Project '" ).append( 
project.getId() ).append( "':" );
         message.append( LS ).append( LS );
 
         if ( activeProfileIds.isEmpty() )
diff --git a/src/main/java/org/apache/maven/plugins/help/AllProfilesMojo.java 
b/src/main/java/org/apache/maven/plugins/help/AllProfilesMojo.java
index 18c96b8..c5f6c0a 100644
--- a/src/main/java/org/apache/maven/plugins/help/AllProfilesMojo.java
+++ b/src/main/java/org/apache/maven/plugins/help/AllProfilesMojo.java
@@ -76,8 +76,8 @@ public class AllProfilesMojo
         {
             descriptionBuffer.append( "Listing Profiles for Project: " 
).append( project.getId() ).append( LS );
             
-            Map<String, Profile> allProfilesByIds = new HashMap<String, 
Profile>();
-            Map<String, Profile> activeProfilesByIds = new HashMap<String, 
Profile>();
+            Map<String, Profile> allProfilesByIds = new HashMap<>();
+            Map<String, Profile> activeProfilesByIds = new HashMap<>();
             addSettingsProfiles( allProfilesByIds );
             addProjectPomProfiles( project, allProfilesByIds, 
activeProfilesByIds );
 
@@ -124,7 +124,7 @@ public class AllProfilesMojo
         for ( Profile p : profilesByIds.values() )
         {
             sb.append( "  Profile Id: " ).append( p.getId() );
-            sb.append( " (Active: " + active + " , Source: " ).append( 
p.getSource() ).append( ")" );
+            sb.append( " (Active: " ).append( active ).append( " , Source: " 
).append( p.getSource() ).append( ")" );
             sb.append( LS );
         }
     }
diff --git a/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java 
b/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java
index 334ede7..9c58b02 100644
--- a/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java
+++ b/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java
@@ -472,7 +472,7 @@ public class DescribeMojo
             append( buffer, "This plugin has " + mojos.size() + " goal" + ( 
mojos.size() > 1 ? "s" : "" ) + ":", 0 );
             buffer.append( LS );
 
-            mojos = new ArrayList<MojoDescriptor>( mojos );
+            mojos = new ArrayList<>( mojos );
             PluginUtils.sortMojos( mojos );
 
             for ( MojoDescriptor md : mojos )
@@ -610,7 +610,7 @@ public class DescribeMojo
             return;
         }
 
-        params = new ArrayList<Parameter>( params );
+        params = new ArrayList<>( params );
         PluginUtils.sortMojoParameters( params );
 
         append( buffer, "Available parameters:", 1 );
@@ -820,9 +820,8 @@ public class DescribeMojo
     {
         try
         {
-            Method m = HelpMojo.class.getDeclaredMethod( "toLines",
-                                                         new Class[]{ 
String.class, Integer.TYPE, Integer.TYPE,
-                                                             Integer.TYPE } );
+            Method m = HelpMojo.class.getDeclaredMethod( "toLines", 
String.class, Integer.TYPE, Integer.TYPE,
+                    Integer.TYPE );
             m.setAccessible( true );
             @SuppressWarnings( "unchecked" )
             List<String> output = (List<String>) m.invoke( HelpMojo.class, 
text, indent, indentSize, lineLength );
@@ -971,7 +970,7 @@ public class DescribeMojo
     private boolean isReportGoal( MojoDescriptor md )
     {
         PluginDescriptor pd = md.getPluginDescriptor();
-        List<URL> urls = new ArrayList<URL>();
+        List<URL> urls = new ArrayList<>();
         ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest( 
session.getProjectBuildingRequest() );
         pbr.setRemoteRepositories( remoteRepositories );
         pbr.setResolveDependencies( true );
@@ -983,15 +982,18 @@ public class DescribeMojo
                     new DefaultArtifact( pd.getGroupId(), pd.getArtifactId(), 
"jar", pd.getVersion() ) ).getArtifact();
             org.eclipse.aether.artifact.Artifact pom = resolveArtifact(
                     new DefaultArtifact( pd.getGroupId(), pd.getArtifactId(), 
"pom", pd.getVersion() ) ).getArtifact();
-            MavenProject project = projectBuilder.build( pom.getFile(), pbr 
).getProject();
+            MavenProject mavenProject = projectBuilder.build( pom.getFile(), 
pbr ).getProject();
             urls.add( jar.getFile().toURI().toURL() );
-            for ( Object artifact : project.getCompileClasspathElements() )
+            for ( String artifact : mavenProject.getCompileClasspathElements() 
)
             {
-                urls.add( new File( (String) artifact ).toURI().toURL() );
+                urls.add( new File( artifact ).toURI().toURL() );
+            }
+            try ( URLClassLoader classLoader = new URLClassLoader( 
urls.toArray( new URL[0] ),
+                    getClass().getClassLoader() ) )
+            {
+                return MavenReport.class.isAssignableFrom(
+                        Class.forName( md.getImplementation(), false, 
classLoader ) );
             }
-            ClassLoader classLoader =
-                new URLClassLoader( urls.toArray( new URL[urls.size()] ), 
getClass().getClassLoader() );
-            return MavenReport.class.isAssignableFrom( Class.forName( 
md.getImplementation(), false, classLoader ) );
         }
         catch ( Exception e )
         {
diff --git a/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java 
b/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
index eb94595..d80e7cd 100644
--- a/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
+++ b/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java
@@ -168,18 +168,11 @@ public class EffectivePomMojo
                 int dotIndex = comment.indexOf( "." );
                 String commentStart = comment.substring( 0, dotIndex );
                 String commentEnd = comment.substring( dotIndex + 1 );
-                effectivePom = effectivePom.replaceAll( "<!--", commentStart 
).replaceAll( "-->", commentEnd );
+                effectivePom = effectivePom.replace( "<!--", commentStart 
).replace( "-->", commentEnd );
             }
 
-            StringBuilder message = new StringBuilder();
-
-            message.append( LS );
-            message.append( "Effective POMs, after inheritance, interpolation, 
and profiles are applied:" );
-            message.append( LS ).append( LS );
-            message.append( effectivePom );
-            message.append( LS );
-
-            getLog().info( message.toString() );
+            getLog().info( LS + "Effective POMs, after inheritance, 
interpolation, and profiles are applied:"
+                    + LS + LS + effectivePom + LS );
         }
     }
 
@@ -194,8 +187,7 @@ public class EffectivePomMojo
     {
         Source source = mojoExecution.getSource();
         // [MNG-5550] For Maven < 3.2.1, the source is null, instead of 
LIFECYCLE: only rely on comparisons with CLI
-        return projects.size() > 1
-            && ( source == Source.CLI || source != Source.CLI && projects.get( 
0 ).equals( project ) );
+        return projects.size() > 1 && ( source == Source.CLI || projects.get( 
0 ).equals( project ) );
     }
 
     // ----------------------------------------------------------------------
@@ -240,7 +232,7 @@ public class EffectivePomMojo
         // This removes the XML declaration written by MavenXpp3Writer
         String effectivePom = prettyFormat( sWriter.toString(), null, true );
 
-        writeComment( writer, "Effective POM for project \'" + project.getId() 
+ "\'" );
+        writeComment( writer, "Effective POM for project '" + project.getId() 
+ "'" );
 
         writer.writeMarkup( effectivePom );
     }
@@ -269,7 +261,7 @@ public class EffectivePomMojo
         try
         {
             Class<?> mavenXpp3WriterExClass = Class.forName( 
"org.apache.maven.model.io.xpp3.MavenXpp3WriterEx" );
-            Object mavenXpp3WriterEx = mavenXpp3WriterExClass.newInstance();
+            Object mavenXpp3WriterEx = 
mavenXpp3WriterExClass.getDeclaredConstructor().newInstance();
 
             Method setStringFormatter =
                 mavenXpp3WriterExClass.getMethod( "setStringFormatter", 
InputLocation.StringFormatter.class );
@@ -284,23 +276,8 @@ public class EffectivePomMojo
         {
             // MavenXpp3WriterEx not available in running Maven version
         }
-        catch ( NoSuchMethodException e )
-        {
-            warnWriteMavenXpp3WriterEx( e );
-        }
-        catch ( SecurityException e )
-        {
-            warnWriteMavenXpp3WriterEx( e );
-        }
-        catch ( InstantiationException e )
-        {
-            warnWriteMavenXpp3WriterEx( e );
-        }
-        catch ( IllegalAccessException e )
-        {
-            warnWriteMavenXpp3WriterEx( e );
-        }
-        catch ( IllegalArgumentException e )
+        catch ( NoSuchMethodException | SecurityException | 
IllegalArgumentException | IllegalAccessException
+                | InstantiationException e )
         {
             warnWriteMavenXpp3WriterEx( e );
         }
diff --git 
a/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java 
b/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java
index 90535d0..c8bb052 100644
--- a/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java
+++ b/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java
@@ -86,11 +86,14 @@ public class EffectiveSettingsMojo
         else
         {
             copySettings = copySettings( settings );
-            hidePasswords( copySettings );
+            if ( copySettings != null )
+            {
+                hidePasswords( copySettings );
+            }
         }
 
         StringWriter w = new StringWriter();
-        String encoding = output != null ? copySettings.getModelEncoding()
+        String encoding = output != null && copySettings != null ? 
copySettings.getModelEncoding()
                                 : System.getProperty( "file.encoding" );
         XMLWriter writer =
             new PrettyPrintXMLWriter( w, StringUtils.repeat( " ", 
XmlWriterUtil.DEFAULT_INDENTATION_SIZE ),
@@ -117,13 +120,7 @@ public class EffectiveSettingsMojo
         }
         else
         {
-            StringBuilder message = new StringBuilder();
-
-            message.append( LS ).append( "Effective user-specific 
configuration settings:" ).append( LS ).append( LS );
-            message.append( effectiveSettings );
-            message.append( LS );
-
-            getLog().info( message.toString() );
+            getLog().info( LS + "Effective user-specific configuration 
settings:" + LS + LS + effectiveSettings + LS );
         }
     }
 
@@ -177,7 +174,7 @@ public class EffectiveSettingsMojo
         // Not a deep copy in M2.2.1 !!!
         Settings clone = SettingsUtils.copySettings( settings );
 
-        List<Server> clonedServers = new ArrayList<Server>( 
settings.getServers().size() );
+        List<Server> clonedServers = new ArrayList<>( 
settings.getServers().size() );
         for ( Server server : settings.getServers() )
         {
             Server clonedServer = new Server();
@@ -195,7 +192,7 @@ public class EffectiveSettingsMojo
         }
         clone.setServers( clonedServers );
 
-        List<Proxy> clonedProxies = new ArrayList<Proxy>( 
settings.getProxies().size() );
+        List<Proxy> clonedProxies = new ArrayList<>( 
settings.getProxies().size() );
         for ( Proxy proxy : settings.getProxies() )
         {
             Proxy clonedProxy = new Proxy();
diff --git a/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java 
b/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java
index 4710725..a18a719 100644
--- a/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java
+++ b/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java
@@ -37,7 +37,6 @@ import org.apache.maven.plugins.annotations.Component;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.ProjectBuildingException;
 import org.apache.maven.settings.Settings;
 import org.apache.maven.settings.io.xpp3.SettingsXpp3Writer;
 import 
org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
@@ -231,11 +230,10 @@ public class EvaluateMojo
 
     /**
      * @return a lazy loading evaluator object.
-     * @throws MojoExecutionException if any
      * @throws MojoFailureException if any reflection exceptions occur or 
missing components.
      */
     private PluginParameterExpressionEvaluator getEvaluator()
-        throws MojoExecutionException, MojoFailureException
+        throws MojoFailureException
     {
         if ( evaluator == null )
         {
@@ -421,7 +419,7 @@ public class EvaluateMojo
         if ( obj instanceof List )
         {
             List<?> list = (List<?>) obj;
-            if ( list.size() > 0 )
+            if ( !list.isEmpty() )
             {
                 Object elt = list.iterator().next();
 
@@ -456,16 +454,18 @@ public class EvaluateMojo
             xstream.registerConverter( new PropertiesConverter()
             {
                 /** {@inheritDoc} */
-                public boolean canConvert( @SuppressWarnings( "rawtypes" ) 
Class type )
+                @Override
+                public boolean canConvert( Class type )
                 {
                     return Properties.class == type;
                 }
 
                 /** {@inheritDoc} */
+                @Override
                 public void marshal( Object source, HierarchicalStreamWriter 
writer, MarshallingContext context )
                 {
                     Properties properties = (Properties) source;
-                    Map<?, ?> map = new TreeMap<Object, Object>( properties ); 
// sort
+                    Map<?, ?> map = new TreeMap<>( properties ); // sort
                     for ( Map.Entry<?, ?> entry : map.entrySet() )
                     {
                         writer.startNode( entry.getKey().toString() );
@@ -486,28 +486,14 @@ public class EvaluateMojo
     {
         try
         {
-            addAlias( xstreamObject, getMavenModelJarFile(), 
"org.apache.maven.model" );
-            addAlias( xstreamObject, getMavenSettingsJarFile(), 
"org.apache.maven.settings" );
+            addAlias( xstreamObject, getArtifactFile( "maven-model" ), 
"org.apache.maven.model" );
+            addAlias( xstreamObject, getArtifactFile( "maven-settings" ), 
"org.apache.maven.settings" );
         }
-        catch ( MojoExecutionException e )
+        catch ( MojoExecutionException | RepositoryException e )
         {
             if ( getLog().isDebugEnabled() )
             {
-                getLog().debug( "MojoExecutionException: " + e.getMessage(), e 
);
-            }
-        }
-        catch ( RepositoryException e )
-        {
-            if ( getLog().isDebugEnabled() )
-            {
-                getLog().debug( "RepositoryException: " + e.getMessage(), e );
-            }
-        }
-        catch ( ProjectBuildingException e )
-        {
-            if ( getLog().isDebugEnabled() )
-            {
-                getLog().debug( "ProjectBuildingException: " + e.getMessage(), 
e );
+                getLog().debug( e.getMessage(), e );
             }
         }
 
@@ -521,17 +507,16 @@ public class EvaluateMojo
      */
     private void addAlias( XStream xstreamObject, File jarFile, String 
packageFilter )
     {
-        JarInputStream jarStream = null;
-        try
+        try ( FileInputStream fis = new FileInputStream( jarFile );
+              JarInputStream jarStream = new JarInputStream( fis ) )
         {
-            jarStream = new JarInputStream( new FileInputStream( jarFile ) );
             for ( JarEntry jarEntry = jarStream.getNextJarEntry(); jarEntry != 
null;
                   jarEntry = jarStream.getNextJarEntry() )
             {
                 if ( jarEntry.getName().toLowerCase( Locale.ENGLISH 
).endsWith( ".class" ) )
                 {
                     String name = jarEntry.getName().substring( 0, 
jarEntry.getName().indexOf( "." ) );
-                    name = name.replaceAll( "/", "\\." );
+                    name = name.replace( "/", "\\." );
 
                     if ( name.contains( packageFilter ) && !name.contains( "$" 
) )
                     {
@@ -554,9 +539,6 @@ public class EvaluateMojo
 
                 jarStream.closeEntry();
             }
-
-            jarStream.close();
-            jarStream = null;
         }
         catch ( IOException e )
         {
@@ -565,78 +547,32 @@ public class EvaluateMojo
                 getLog().debug( "IOException: " + e.getMessage(), e );
             }
         }
-        finally
-        {
-            IOUtil.close( jarStream );
-        }
     }
 
     /**
-     * @return the <code>org.apache.maven:maven-model</code> artifact jar file 
in the local repository.
+     * @return the <code>org.apache.maven: artifactId </code> artifact jar 
file for this current HelpPlugin pom.
      * @throws MojoExecutionException if any
-     * @throws ProjectBuildingException if any
-     * @throws RepositoryException if any
      */
-    private File getMavenModelJarFile()
-        throws MojoExecutionException, ProjectBuildingException, 
RepositoryException
-    {
-        return getArtifactFile( true );
-    }
-
-    /**
-     * @return the <code>org.apache.maven:maven-settings</code> artifact jar 
file in the local repository.
-     * @throws MojoExecutionException if any
-     * @throws ProjectBuildingException if any
-     * @throws RepositoryException if any
-     */
-    private File getMavenSettingsJarFile()
-        throws MojoExecutionException, ProjectBuildingException, 
RepositoryException
-    {
-        return getArtifactFile( false );
-    }
-
-    /**
-     * @param isPom <code>true</code> to lookup the <code>maven-model</code> 
artifact jar, <code>false</code> to lookup
-     *            the <code>maven-settings</code> artifact jar.
-     * @return the <code>org.apache.maven:maven-model|maven-settings</code> 
artifact jar file for this current
-     *         HelpPlugin pom.
-     * @throws MojoExecutionException if any
-     */
-    private File getArtifactFile( boolean isPom )
+    private File getArtifactFile( String artifactId )
         throws MojoExecutionException, RepositoryException
     {
         List<Dependency> dependencies = getHelpPluginPom().getDependencies();
         for ( Dependency dependency : dependencies )
         {
-            if ( !( dependency.getGroupId().equals( "org.apache.maven" ) ) )
-            {
-                continue;
-            }
-
-            if ( isPom )
-            {
-                if ( !( dependency.getArtifactId().equals( "maven-model" ) ) )
-                {
-                    continue;
-                }
-            }
-            else
+            if ( ( "org.apache.maven".equals( dependency.getGroupId() ) ) )
             {
-                if ( !( dependency.getArtifactId().equals( "maven-settings" ) 
) )
+                if ( ( artifactId.equals( dependency.getArtifactId() ) ) )
                 {
-                    continue;
-                }
-            }
+                    Artifact mavenArtifact = new DefaultArtifact( 
dependency.getGroupId(), dependency.getArtifactId(),
+                            "jar", dependency.getVersion() );
 
-            Artifact mavenArtifact = new DefaultArtifact(
-                    dependency.getGroupId(), dependency.getArtifactId(), "jar",
-                    dependency.getVersion() );
+                    return resolveArtifact( mavenArtifact 
).getArtifact().getFile();
+                }
 
-            return resolveArtifact( mavenArtifact ).getArtifact().getFile();
+            }
         }
 
-        throw new MojoExecutionException( "Unable to find the 
'org.apache.maven:"
-            + ( isPom ? "maven-model" : "maven-settings" ) + "' artifact" );
+        throw new MojoExecutionException( "Unable to find the 
'org.apache.maven:" + artifactId + "' artifact" );
     }
 
     /**
diff --git 
a/src/test/java/org/apache/maven/plugins/help/ActiveProfilesMojoTest.java 
b/src/test/java/org/apache/maven/plugins/help/ActiveProfilesMojoTest.java
index 9af35fd..6d70fd2 100644
--- a/src/test/java/org/apache/maven/plugins/help/ActiveProfilesMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/help/ActiveProfilesMojoTest.java
@@ -24,7 +24,6 @@ import static org.mockito.Mockito.when;
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.util.Arrays;
 import java.util.Collections;
@@ -93,7 +92,7 @@ public class ActiveProfilesMojoTest
 
     private Map<String, List<String>> getProfiles( List<String> externals, 
List<String> pom )
     {
-        Map<String, List<String>> profiles = new HashMap<String, 
List<String>>();
+        Map<String, List<String>> profiles = new HashMap<>();
         profiles.put( "external", externals ); // from settings
         profiles.put( "org.apache.maven.test:test:1.0", pom ); // from POM
         profiles.put( "", Collections.<String>emptyList() ); // from super POM
@@ -109,18 +108,13 @@ public class ActiveProfilesMojoTest
     }
 
     private String readFile( String path )
-        throws FileNotFoundException, IOException
+        throws IOException
     {
-        FileInputStream fis = null;
-        try
+        try ( FileInputStream fis = new FileInputStream(
+                new File( getBasedir(), 
"target/test-classes/unit/active-profiles/" + path ) ) )
         {
-            fis = new FileInputStream( new File( getBasedir(), 
"target/test-classes/unit/active-profiles/" + path ) );
             return IOUtil.toString( fis );
         }
-        finally
-        {
-            IOUtil.close( fis );
-        }
     }
 
 }
diff --git 
a/src/test/java/org/apache/maven/plugins/help/AllProfilesMojoTest.java 
b/src/test/java/org/apache/maven/plugins/help/AllProfilesMojoTest.java
index fdbe98d..b7f9596 100644
--- a/src/test/java/org/apache/maven/plugins/help/AllProfilesMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/help/AllProfilesMojoTest.java
@@ -21,7 +21,6 @@ package org.apache.maven.plugins.help;
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -146,10 +145,10 @@ public class AllProfilesMojoTest
         MavenProject project = new MavenProjectStub();
         project.setActiveProfiles( Arrays.asList( newPomProfile( "settings-1", 
"settings.xml" ) ) );
         
-        List<org.apache.maven.settings.Profile> settingsProfiles = new 
ArrayList<org.apache.maven.settings.Profile>();
+        List<org.apache.maven.settings.Profile> settingsProfiles = new 
ArrayList<>();
         settingsProfiles.add( newSettingsProfile( "settings-1" ) );
         settingsProfiles.add( newSettingsProfile( "settings-2" ) );
-        setUpMojo( mojo, Arrays.<MavenProject>asList( project ), 
settingsProfiles, "profiles-from-settings.txt" );
+        setUpMojo( mojo, Arrays.asList( project ), settingsProfiles, 
"profiles-from-settings.txt" );
 
         mojo.execute();
 
@@ -185,24 +184,19 @@ public class AllProfilesMojoTest
     }
 
     private String readFile( String path )
-        throws FileNotFoundException, IOException
+        throws IOException
     {
-        FileInputStream fis = null;
-        try
+        try ( FileInputStream fis = new FileInputStream(
+                new File( getBasedir(), 
"target/test-classes/unit/active-profiles/" + path ) ) )
         {
-            fis = new FileInputStream( new File( getBasedir(), 
"target/test-classes/unit/active-profiles/" + path ) );
             return IOUtil.toString( fis );
         }
-        finally
-        {
-            IOUtil.close( fis );
-        }
     }
     
     private static final class InterceptingLog
         extends DefaultLog
     {
-        List<String> warnLogs = new ArrayList<String>();
+        final List<String> warnLogs = new ArrayList<>();
 
         public InterceptingLog( Logger logger )
         {
diff --git a/src/test/java/org/apache/maven/plugins/help/DescribeMojoTest.java 
b/src/test/java/org/apache/maven/plugins/help/DescribeMojoTest.java
index 8cdd49a..0a255ad 100644
--- a/src/test/java/org/apache/maven/plugins/help/DescribeMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/help/DescribeMojoTest.java
@@ -40,8 +40,6 @@ import static 
org.apache.commons.lang3.reflect.FieldUtils.writeDeclaredField;
 import static org.apache.commons.lang3.reflect.FieldUtils.writeField;
 import static org.apache.commons.lang3.reflect.MethodUtils.invokeMethod;
 import static org.junit.Assert.*;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.*;
 
 /**
@@ -60,7 +58,6 @@ public class DescribeMojoTest
         {
             DescribeMojo describeMojo = new DescribeMojo();
             invokeMethod( describeMojo, true, "toLines", "", 2, 2, 80 );
-            assertTrue( true );
         }
         catch ( Throwable e )
         {
@@ -136,9 +133,9 @@ public class DescribeMojoTest
 
         PluginInfo pi = (PluginInfo) invokeMethod( mojo, true, 
"parsePluginLookupInfo" );
 
-        assertEquals( pi.getGroupId(), "org.test" );
-        assertEquals( pi.getArtifactId(), "test" );
-        assertEquals( pi.getVersion(), "1.0" );
+        assertEquals( "org.test", pi.getGroupId() );
+        assertEquals( "test", pi.getArtifactId() );
+        assertEquals( "1.0", pi.getVersion() );
         assertNull( pi.getPrefix() );
     }
     
diff --git a/src/test/java/org/apache/maven/plugins/help/EvaluateMojoTest.java 
b/src/test/java/org/apache/maven/plugins/help/EvaluateMojoTest.java
index bf22790..e2e1926 100644
--- a/src/test/java/org/apache/maven/plugins/help/EvaluateMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/help/EvaluateMojoTest.java
@@ -19,7 +19,7 @@ package org.apache.maven.plugins.help;
  * under the License.
  */
 
-import static org.mockito.Matchers.anyString;
+import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
@@ -154,8 +154,8 @@ public class EvaluateMojoTest
             baos.close();
         }
 
-        String stdResult = new String( baos.toByteArray() );
-        assertTrue( stdResult.equals( "org.apache.maven.its.help" ) );
+        String stdResult = baos.toString();
+        assertEquals( "org.apache.maven.its.help", stdResult );
         assertTrue( interceptingLogger.warnLogs.isEmpty() );
     }
 
@@ -174,9 +174,9 @@ public class EvaluateMojoTest
     {
         private boolean isInfoEnabled;
 
-        List<String> infoLogs = new ArrayList<String>();
+        final List<String> infoLogs = new ArrayList<>();
 
-        List<String> warnLogs = new ArrayList<String>();
+        final List<String> warnLogs = new ArrayList<>();
 
         public InterceptingLog( Logger logger )
         {
diff --git 
a/src/test/java/org/apache/maven/plugins/help/stubs/DefaultMavenProjectStub.java
 
b/src/test/java/org/apache/maven/plugins/help/stubs/DefaultMavenProjectStub.java
index ee37ae6..8841718 100644
--- 
a/src/test/java/org/apache/maven/plugins/help/stubs/DefaultMavenProjectStub.java
+++ 
b/src/test/java/org/apache/maven/plugins/help/stubs/DefaultMavenProjectStub.java
@@ -19,7 +19,6 @@ package org.apache.maven.plugins.help.stubs;
  * under the License.
  */
 
-import java.io.File;
 import java.io.FileReader;
 
 import org.apache.maven.model.Model;
@@ -42,13 +41,10 @@ public class DefaultMavenProjectStub
 
         try
         {
-            final FileReader reader = new FileReader(new File(getBasedir()
-                    + 
"/src/test/resources/unit/default-configuration/default-configuration-plugin-config.xml"));
-            try {
-                model =
-                        pomReader.read(reader);
-            } finally {
-                reader.close();
+            try ( FileReader reader = new FileReader(
+                    getBasedir() + 
"/src/test/resources/unit/default-configuration/default-configuration-plugin-config.xml"
 ) )
+            {
+                model = pomReader.read( reader );
             }
             setModel(model);
         }

Reply via email to