rfscholte closed pull request #8: Cleanup code using java 7 features
URL: https://github.com/apache/maven-javadoc-plugin/pull/8
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/src/main/java/org/apache/maven/plugins/javadoc/AbstractFixJavadocMojo.java 
b/src/main/java/org/apache/maven/plugins/javadoc/AbstractFixJavadocMojo.java
index 1036095..e51eb8b 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractFixJavadocMojo.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractFixJavadocMojo.java
@@ -392,7 +392,7 @@
     /**
      * Split {@link #fixTags} by comma.
      *
-     * @see {@link #init()}
+     * @see #init()
      */
     private String[] fixTagsSplitted;
 
@@ -1145,10 +1145,8 @@ else if ( lineNumber == javaClass.getLineNumber() )
      * @param stringWriter    not null
      * @param originalContent not null
      * @param entity          not null
-     * @param changeDetected
-     * @return the updated changeDetected flag
      * @throws IOException if any
-     * @see #extractOriginalJavadoc(String, AbstractJavaEntity)
+     * @see #extractOriginalJavadoc
      */
     private void takeCareSingleComment( final StringWriter stringWriter, final 
String originalContent,
                                         final JavaAnnotatedElement entity )
@@ -1262,9 +1260,9 @@ private boolean isInLevel( List<String> modifiers )
      * <font color="#000000">DummyClass&nbsp;</font><font 
color="#000000">{}</font></code>
      * </code>
      *
-     * @param buffer    not null
-     * @param javaClass not null
-     * @param indent    not null
+     * @param stringWriter not null
+     * @param javaClass    not null
+     * @param indent       not null
      * @see #getDefaultClassJavadocComment(JavaClass)
      * @see #appendDefaultAuthorTag(StringBuilder, String)
      * @see #appendDefaultSinceTag(StringBuilder, String)
@@ -1417,7 +1415,7 @@ private void addDefaultFieldComment( final StringWriter 
stringWriter, final Java
                 }
                 else
                 {
-                    sb.append( value.toString().substring( 0, 39 ) ).append( 
"\"{trunked}" );
+                    sb.append( value.toString(), 0, 39 ).append( "\"{trunked}" 
);
                 }
                 // CHECKSTYLE_ON: MagicNumber
             }
@@ -1496,11 +1494,11 @@ private boolean fixMethodComment( final StringWriter 
stringWriter, final String
      * <font color="#000000">){}</font>
      * </code>
      *
-     * @param buffer     not null
+     * @param stringWriter   not null
      * @param javaExecutable not null
-     * @param indent     not null
+     * @param indent         not null
      * @throws MojoExecutionException if any
-     * @see #getDefaultMethodJavadocComment(JavaMethod)
+     * @see #getDefaultMethodJavadocComment
      * @see #appendDefaultSinceTag(StringBuilder, String)
      */
     private void addDefaultMethodComment( final StringWriter stringWriter, 
final JavaExecutable javaExecutable,
@@ -1576,7 +1574,6 @@ private void addDefaultMethodComment( final StringWriter 
stringWriter, final Jav
      * @param originalContent not null
      * @param entity          not null
      * @param indent          not null
-     * @param changeDetected
      * @return the updated changeDetected flag
      * @throws MojoExecutionException if any
      * @throws IOException            if any
@@ -1805,7 +1802,7 @@ static String replaceLinkTags( String comment, 
JavaAnnotatedElement entity )
         while ( linktagMatcher.find() )
         {
             int startName = linktagMatcher.end();
-            resolvedComment.append( comment.substring( startIndex, startName ) 
);
+            resolvedComment.append( comment, startIndex, startName );
             int endName = comment.indexOf( "}", startName );
             if ( endName >= 0 )
             {
@@ -1949,21 +1946,19 @@ JavaEntityTags parseJavadocTags( final String 
originalContent, final JavaAnnotat
                 }
 
                 String paramName = params.get( 0 );
-                if ( docletTag.getName().equals( PARAM_TAG ) )
-                {
-                    javaEntityTags.putJavadocParamTag( paramName, 
originalJavadocTag );
-                }
-                else if ( docletTag.getName().equals( RETURN_TAG ) )
-                {
-                    javaEntityTags.setJavadocReturnTag( originalJavadocTag );
-                }
-                else if ( docletTag.getName().equals( THROWS_TAG ) )
-                {
-                    javaEntityTags.putJavadocThrowsTag( paramName, 
originalJavadocTag );
-                }
-                else
-                {
-                    javaEntityTags.getUnknownTags().add( originalJavadocTag );
+                switch ( docletTag.getName() ) {
+                    case PARAM_TAG:
+                        javaEntityTags.putJavadocParamTag( paramName, 
originalJavadocTag );
+                        break;
+                    case RETURN_TAG:
+                        javaEntityTags.setJavadocReturnTag( originalJavadocTag 
);
+                        break;
+                    case THROWS_TAG:
+                        javaEntityTags.putJavadocThrowsTag( paramName, 
originalJavadocTag );
+                        break;
+                    default:
+                        javaEntityTags.getUnknownTags().add( 
originalJavadocTag );
+                        break;
                 }
             }
             else
@@ -2789,7 +2784,7 @@ private boolean isInherited( JavaExecutable javaMethod )
      * @param javaMethod the QDox JavaMethod object not null
      * @return <code>true</code> if <code>javaMethod</code> exists in the 
given <code>clazz</code>,
      *         <code>false</code> otherwise.
-     * @see #isInherited(JavaMethod)
+     * @see #isInherited(JavaExecutable)
      */
     private boolean isInherited( Class<?> clazz, JavaExecutable javaMethod )
     {
@@ -2945,8 +2940,8 @@ private boolean isNewMethodFromLastRevision( 
JavaExecutable javaExecutable )
      * @param className not null
      * @return the Class corresponding to the given class name using the 
project classloader.
      * @throws MojoExecutionException if class not found
-     * @see {@link ClassUtils#getClass(ClassLoader, String, boolean)}
-     * @see {@link #getProjectClassLoader()}
+     * @see ClassUtils#getClass(ClassLoader, String, boolean)
+     * @see #getProjectClassLoader()
      */
     private Class<?> getClass( String className )
         throws MojoExecutionException
@@ -3036,18 +3031,8 @@ private boolean sinceClassesContains( JavaClass 
javaClass )
     private static void writeFile( final File javaFile, final String encoding, 
final String content )
         throws IOException
     {
-        Writer writer = null;
-        try
-        {
-            writer = WriterFactory.newWriter( javaFile, encoding );
-            writer.write( StringUtils.unifyLineSeparators( content ) );
-            writer.close();
-            writer = null;
-        }
-        finally
-        {
-            IOUtil.close( writer );
-        }
+        String unified = StringUtils.unifyLineSeparators( content );
+        FileUtils.fileWrite( javaFile, encoding, unified );
     }
 
     /**
@@ -3625,7 +3610,7 @@ private static String trimLeft( final String text )
         }
 
         String textTrimmed = text.trim();
-        return text.substring( text.indexOf( textTrimmed ), text.length() );
+        return text.substring( text.indexOf( textTrimmed ) );
     }
 
     /**
diff --git 
a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java 
b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
index e19b68f..5cade56 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
@@ -1916,11 +1916,9 @@ public void execute()
 
     protected final void verifyRemovedParameter( String paramName )
     {
-        Object pluginConfiguration = mojo.getConfiguration();
-        if ( pluginConfiguration instanceof Xpp3Dom )
+        Xpp3Dom configDom = mojo.getConfiguration();
+        if (configDom != null)
         {
-            Xpp3Dom configDom = (Xpp3Dom) pluginConfiguration;
-
             if ( configDom.getChild( paramName ) != null )
             {
                 throw new IllegalArgumentException( "parameter '" + paramName
@@ -1931,11 +1929,9 @@ protected final void verifyRemovedParameter( String 
paramName )
 
     private void verifyReplacedParameter( String oldParamName, String 
newParamNew )
     {
-        Object pluginConfiguration = mojo.getConfiguration();
-        if ( pluginConfiguration instanceof Xpp3Dom )
+        Xpp3Dom configDom = mojo.getConfiguration();
+        if (configDom != null)
         {
-            Xpp3Dom configDom = (Xpp3Dom) pluginConfiguration;
-
             if ( configDom.getChild( oldParamName ) != null )
             {
                 throw new IllegalArgumentException( "parameter '" + 
oldParamName
@@ -2391,12 +2387,7 @@ protected SourceResolverConfig 
configureDependencySourceResolution( final Source
         {
             return resourceResolver.resolveDependencySourcePaths( config );
         }
-        catch ( final ArtifactResolutionException e )
-        {
-            throw new MavenReportException(
-                "Failed to resolve one or more javadoc source/resource 
artifacts:\n\n" + e.getMessage(), e );
-        }
-        catch ( final ArtifactNotFoundException e )
+        catch ( final ArtifactResolutionException | ArtifactNotFoundException 
e )
         {
             throw new MavenReportException(
                 "Failed to resolve one or more javadoc source/resource 
artifacts:\n\n" + e.getMessage(), e );
@@ -2476,7 +2467,7 @@ private String getExcludedPackages( Collection<String> 
sourcePaths )
             String[] excludedPackages = getExcludedPackages();
             String[] subpackagesList = subpackages.split( "[:]" );
 
-            excludedNames = JavadocUtil.getExcludedNames( sourcePaths, 
subpackagesList, excludedPackages );
+            excludedNames = JavadocUtil.getExcludedNames( sourcePaths, 
excludedPackages );
         }
 
         String excludeArg = "";
@@ -2736,23 +2727,7 @@ protected final Toolchain getToolchain()
                     tc = tcs.get( 0 );
                 }
             }
-            catch ( NoSuchMethodException e )
-            {
-                // ignore
-            }
-            catch ( SecurityException e )
-            {
-                // ignore
-            }
-            catch ( IllegalAccessException e )
-            {
-                // ignore
-            }
-            catch ( IllegalArgumentException e )
-            {
-                // ignore
-            }
-            catch ( InvocationTargetException e )
+            catch ( SecurityException | ReflectiveOperationException e )
             {
                 // ignore
             }
@@ -3739,25 +3714,7 @@ private void setFJavadocVersion( File jExecutable )
         {
             jVersion = JavadocUtil.getJavadocVersion( jExecutable );
         }
-        catch ( IOException e )
-        {
-            if ( getLog().isWarnEnabled() )
-            {
-                getLog().warn( "Unable to find the javadoc version: " + 
e.getMessage() );
-                getLog().warn( "Using the Java version instead of, i.e. " + 
JAVA_VERSION );
-            }
-            jVersion = JAVA_VERSION;
-        }
-        catch ( CommandLineException e )
-        {
-            if ( getLog().isWarnEnabled() )
-            {
-                getLog().warn( "Unable to find the javadoc version: " + 
e.getMessage() );
-                getLog().warn( "Using the Java version instead of, i.e. " + 
JAVA_VERSION );
-            }
-            jVersion = JAVA_VERSION;
-        }
-        catch ( IllegalArgumentException e )
+        catch ( IOException | CommandLineException | IllegalArgumentException 
e )
         {
             if ( getLog().isWarnEnabled() )
             {
@@ -3825,8 +3782,8 @@ private void addArgIf( List<String> arguments, boolean b, 
String value )
      * @param b                   the flag which controls if the argument is 
added or not.
      * @param value               the argument value to be added.
      * @param requiredJavaVersion the required Java version, for example 1.31f 
or 1.4f
-     * @see #addArgIf(java.util.List, boolean, String)
-     * @see #isJavaDocVersionAtLeast(float)
+     * @see #addArgIf(List, boolean, String)
+     * @see #isJavaDocVersionAtLeast(JavaVersion)
      */
     private void addArgIf( List<String> arguments, boolean b, String value, 
JavaVersion requiredJavaVersion )
     {
@@ -3856,7 +3813,7 @@ private void addArgIf( List<String> arguments, boolean b, 
String value, JavaVers
      * @param arguments a list of arguments, not null
      * @param key       the argument name.
      * @param value     the argument value to be added.
-     * @see #addArgIfNotEmpty(java.util.List, String, String, boolean)
+     * @see #addArgIfNotEmpty(List, String, String, boolean)
      */
     private void addArgIfNotEmpty( List<String> arguments, String key, String 
value )
     {
@@ -3876,7 +3833,7 @@ private void addArgIfNotEmpty( List<String> arguments, 
String key, String value
      * @param splitValue          if <code>true</code> given value will be 
tokenized by comma
      * @param requiredJavaVersion the required Java version, for example 1.31f 
or 1.4f
      * @see #addArgIfNotEmpty(List, String, String, boolean, boolean)
-     * @see #isJavaDocVersionAtLeast(float)
+     * @see #isJavaDocVersionAtLeast(JavaVersion)
      */
     private void addArgIfNotEmpty( List<String> arguments, String key, String 
value, boolean repeatKey,
                                    boolean splitValue, JavaVersion 
requiredJavaVersion )
@@ -3969,7 +3926,7 @@ private void addArgIfNotEmpty( List<String> arguments, 
String key, String value,
      * @param key                 the argument name.
      * @param value               the argument value to be added.
      * @param requiredJavaVersion the required Java version, for example 1.31f 
or 1.4f
-     * @see #addArgIfNotEmpty(java.util.List, String, String, float, boolean)
+     * @see #addArgIfNotEmpty(List, String, String, JavaVersion, boolean)
      */
     private void addArgIfNotEmpty( List<String> arguments, String key, String 
value,
                                    JavaVersion requiredJavaVersion )
@@ -3986,8 +3943,8 @@ private void addArgIfNotEmpty( List<String> arguments, 
String key, String value,
      * @param value               the argument value to be added.
      * @param requiredJavaVersion the required Java version, for example 1.31f 
or 1.4f
      * @param repeatKey           repeat or not the key in the command line
-     * @see #addArgIfNotEmpty(java.util.List, String, String)
-     * @see #isJavaDocVersionAtLeast(float)
+     * @see #addArgIfNotEmpty(List, String, String)
+     * @see #isJavaDocVersionAtLeast
      */
     private void addArgIfNotEmpty( List<String> arguments, String key, String 
value, JavaVersion requiredJavaVersion,
                                    boolean repeatKey )
@@ -4315,7 +4272,7 @@ private void copyAdditionalJavadocResources( File 
anOutputDirectory )
     /**
      * @param sourcePaths could be null
      * @param files       not null
-     * @return a list files with unnamed package names for files in the 
sourecPaths
+     * @return a list files with unnamed package names for files in the 
sourcePaths
      */
     private List<String> getFilesWithUnnamedPackages( Collection<String> 
sourcePaths, List<String> files )
     {
@@ -4327,7 +4284,7 @@ private void copyAdditionalJavadocResources( File 
anOutputDirectory )
      * @param files           not null, containing list of quoted files
      * @param onlyPackageName boolean for only package name
      * @return a list of package names or files with unnamed package names, 
depending the value of the unnamed flag
-     * @see #getFiles(List)
+     * @see #getFiles
      * @see #getSourcePaths()
      */
     private List<String> getPackageNamesOrFilesWithUnnamedPackages( 
Collection<String> sourcePaths, List<String> files,
@@ -4405,7 +4362,7 @@ private void addCommandLineOptions( Commandline cmd, 
List<String> arguments, Fil
         File optionsFile = new File( javadocOutputDirectory, OPTIONS_FILE_NAME 
);
 
         StringBuilder options = new StringBuilder();
-        options.append( StringUtils.join( arguments.toArray( new 
String[arguments.size()] ),
+        options.append( StringUtils.join( arguments.iterator(),
                                           SystemUtils.LINE_SEPARATOR ) );
 
         try
@@ -4435,7 +4392,7 @@ private void addCommandLineOptions( Commandline cmd, 
List<String> arguments, Fil
      * @see <a 
href="http://docs.oracle.com/javase/7/docs/technotes/guides/javadoc/whatsnew-1.4.html#runningjavadoc";>
      *      What s New in Javadoc 1.4
      *      </a>
-     * @see #isJavaDocVersionAtLeast(float)
+     * @see #isJavaDocVersionAtLeast(JavaVersion)
      * @see #ARGFILE_FILE_NAME
      * @see #FILES_FILE_NAME
      */
@@ -4643,8 +4600,8 @@ private void validateStandardDocletOptions()
      * Standard Javadoc Options wrapped by this Plugin.
      *
      * @param javadocOutputDirectory not null
-     * @param arguments   not null
-     * @param sourcePaths not null
+     * @param arguments              not null
+     * @param allSourcePaths         not null
      * @throws MavenReportException if any
      * @see <a 
href="http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#javadocoptions";>http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#javadocoptions</a>
      */
@@ -4834,10 +4791,7 @@ private void addJavadocOptions( File 
javadocOutputDirectory,
 
         if ( additionalOptions != null && additionalOptions.length > 0 )
         {
-            for ( String option : additionalOptions )
-            {
-                arguments.add( option );
-            }
+            Collections.addAll( arguments, additionalOptions );
         }
     }
 
@@ -5679,7 +5633,7 @@ private String getFullJavadocGoal()
      * @return the detected Javadoc links using the Maven conventions for all 
dependencies defined in the current
      *         project or an empty list.
      * @see #detectLinks
-     * @see #isValidJavadocLink(String)
+     * @see #isValidJavadocLink
      * @since 2.6
      */
     private List<String> getDependenciesLinks()
diff --git a/src/main/java/org/apache/maven/plugins/javadoc/JavadocJar.java 
b/src/main/java/org/apache/maven/plugins/javadoc/JavadocJar.java
index 3060678..c343a58 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/JavadocJar.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/JavadocJar.java
@@ -269,14 +269,13 @@ private File generateArchive( File javadocFiles, String 
jarFileName )
         archiver.setArchiver( jarArchiver );
         archiver.setOutputFile( javadocJar );
 
-        File contentDirectory = javadocFiles;
-        if ( !contentDirectory.exists() )
+        if ( !javadocFiles.exists() )
         {
             getLog().warn( "JAR will be empty - no content was marked for 
inclusion!" );
         }
         else
         {
-            archiver.getArchiver().addDirectory( contentDirectory, 
DEFAULT_INCLUDES, DEFAULT_EXCLUDES );
+            archiver.getArchiver().addDirectory( javadocFiles, 
DEFAULT_INCLUDES, DEFAULT_EXCLUDES );
         }
 
         List<Resource> resources = project.getBuild().getResources();
diff --git a/src/main/java/org/apache/maven/plugins/javadoc/JavadocReport.java 
b/src/main/java/org/apache/maven/plugins/javadoc/JavadocReport.java
index dab71d8..4fba34f 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/JavadocReport.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/JavadocReport.java
@@ -133,15 +133,7 @@ public void generate( Sink sink, Locale locale )
         {
             executeReport( locale );
         }
-        catch ( MavenReportException e )
-        {
-            if ( failOnError )
-            {
-                throw e;
-            }
-            getLog().error( "Error while creating javadoc report: " + 
e.getMessage(), e );
-        }
-        catch ( RuntimeException e )
+        catch ( MavenReportException | RuntimeException e )
         {
             if ( failOnError )
             {
@@ -234,7 +226,7 @@ public boolean canGenerateReport()
     {
         boolean canGenerate = false;
 
-        if ( !this.isAggregator() || ( this.isAggregator() && 
this.project.isExecutionRoot() ) )
+        if ( !this.isAggregator() || this.project.isExecutionRoot() )
         {
             Collection<String> sourcePaths;
             List<String> files;
@@ -289,7 +281,7 @@ public void setReportOutputDirectory( File 
reportOutputDirectory )
     }
 
     /**
-     * @param theDestDir The destiation directory.
+     * @param theDestDir The destination directory.
      */
     public void setDestDir( String theDestDir )
     {
@@ -328,11 +320,7 @@ public void doExecute()
             Locale locale = Locale.getDefault();
             generate( sink, locale );
         }
-        catch ( MavenReportException e )
-        {
-            failOnError( "An error has occurred in " + getName( Locale.ENGLISH 
) + " report generation", e );
-        }
-        catch ( RuntimeException e )
+        catch ( MavenReportException | RuntimeException e )
         {
             failOnError( "An error has occurred in " + getName( Locale.ENGLISH 
) + " report generation", e );
         }
diff --git a/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java 
b/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
index da72cac..beea786 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
@@ -62,16 +62,13 @@
 import org.codehaus.plexus.util.cli.Commandline;
 
 import java.io.BufferedReader;
-import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
-import java.io.OutputStreamWriter;
 import java.io.PrintStream;
 import java.io.UnsupportedEncodingException;
 import java.lang.reflect.Modifier;
@@ -79,6 +76,8 @@
 import java.net.URI;
 import java.net.URL;
 import java.net.URLClassLoader;
+import java.nio.charset.Charset;
+import java.nio.charset.IllegalCharsetNameException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -111,7 +110,7 @@
     /** Error message when VM could not be started using invoker. */
     protected static final String ERROR_INIT_VM =
         "Error occurred during initialization of VM, try to reduce the Java 
heap size for the MAVEN_OPTS "
-            + "environnement variable using -Xms:<size> and -Xmx:<size>.";
+            + "environment variable using -Xms:<size> and -Xmx:<size>.";
 
     /**
      * Method that removes the invalid directories in the specified 
directories. <b>Note</b>: All elements in
@@ -193,21 +192,16 @@ public static boolean shouldPruneFile( String f, 
List<String> pruned )
      * Method that gets all the source files to be excluded from the javadoc 
on the given source paths.
      *
      * @param sourcePaths the path to the source files
-     * @param subpackagesList list of subpackages to be included in the javadoc
      * @param excludedPackages the package names to be excluded in the javadoc
      * @return a List of the source files to be excluded in the generated 
javadoc
      */
-    protected static List<String> getExcludedNames( Collection<String> 
sourcePaths, String[] subpackagesList,
-                                                    String[] excludedPackages )
+    protected static List<String> getExcludedNames( Collection<String> 
sourcePaths, String[] excludedPackages )
     {
         List<String> excludedNames = new ArrayList<>();
         for ( String path : sourcePaths )
         {
-            for ( String aSubpackagesList : subpackagesList )
-            {
-                List<String> excludes = getExcludedPackages( path, 
excludedPackages );
-                excludedNames.addAll( excludes );
-            }
+            List<String> excludes = getExcludedPackages( path, 
excludedPackages );
+            excludedNames.addAll( excludes );
         }
 
         return excludedNames;
@@ -295,8 +289,7 @@ protected static void copyJavadocResources( File 
outputDirectory, File javadocDi
             return;
         }
 
-        List<String> excludes = new ArrayList<>();
-        excludes.addAll( Arrays.asList( FileUtils.getDefaultExcludes() ) );
+        List<String> excludes = new ArrayList<>( Arrays.asList( 
FileUtils.getDefaultExcludes() ) );
 
         if ( StringUtils.isNotEmpty( excludedocfilessubdir ) )
         {
@@ -697,24 +690,14 @@ protected static boolean validateEncoding( String 
charsetName )
             return false;
         }
 
-        OutputStream ost = new ByteArrayOutputStream();
-        OutputStreamWriter osw = null;
         try
         {
-            osw = new OutputStreamWriter( ost, charsetName );
-            osw.close();
-            osw = null;
+            return Charset.isSupported( charsetName );
         }
-        catch ( IOException exc )
+        catch ( IllegalCharsetNameException e )
         {
             return false;
         }
-        finally
-        {
-            IOUtil.close( osw );
-        }
-
-        return true;
     }
 
     /**
@@ -828,36 +811,7 @@ protected static void copyResource( URL url, File file )
             throw new IOException( "The url could not be null." );
         }
 
-        if ( !file.getParentFile().exists() )
-        {
-            file.getParentFile().mkdirs();
-        }
-
-        InputStream in = null;
-        OutputStream out = null;
-        try
-        {
-            in = url.openStream();
-
-            if ( in == null )
-            {
-                throw new IOException( "The resource " + url + " doesn't 
exists." );
-            }
-
-            out = new FileOutputStream( file );
-
-            IOUtil.copy( in, out );
-
-            out.close();
-            out = null;
-            in.close();
-            in = null;
-        }
-        finally
-        {
-            IOUtil.close( in );
-            IOUtil.close( out );
-        }
+        FileUtils.copyURLToFile( url, file );
     }
 
     /**
@@ -1080,12 +1034,8 @@ protected static String unifyPathSeparator( final String 
path )
         }
 
         List<String> classes = new ArrayList<>();
-        JarInputStream jarStream = null;
-
-        try
+        try ( JarInputStream jarStream = new JarInputStream( new 
FileInputStream( jarFile ) ) )
         {
-            jarStream = new JarInputStream( new FileInputStream( jarFile ) );
-
             for ( JarEntry jarEntry = jarStream.getNextJarEntry(); jarEntry != 
null; jarEntry =
                 jarStream.getNextJarEntry() )
             {
@@ -1098,13 +1048,6 @@ protected static String unifyPathSeparator( final String 
path )
 
                 jarStream.closeEntry();
             }
-
-            jarStream.close();
-            jarStream = null;
-        }
-        finally
-        {
-            IOUtil.close( jarStream );
         }
 
         return classes;
diff --git 
a/src/main/java/org/apache/maven/plugins/javadoc/ResourcesBundleMojo.java 
b/src/main/java/org/apache/maven/plugins/javadoc/ResourcesBundleMojo.java
index 2c13cba..89b9e73 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/ResourcesBundleMojo.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/ResourcesBundleMojo.java
@@ -130,12 +130,7 @@ public void doExecute()
             archiver.setDestFile( bundleFile );
             archiver.createArchive();
         }
-        catch ( ArchiverException e )
-        {
-            throw new MojoExecutionException( "Failed to assemble 
javadoc-resources bundle archive. Reason: "
-                + e.getMessage(), e );
-        }
-        catch ( IOException e )
+        catch ( ArchiverException | IOException e )
         {
             throw new MojoExecutionException( "Failed to assemble 
javadoc-resources bundle archive. Reason: "
                 + e.getMessage(), e );
diff --git 
a/src/main/java/org/apache/maven/plugins/javadoc/resolver/ResourceResolver.java 
b/src/main/java/org/apache/maven/plugins/javadoc/resolver/ResourceResolver.java
index b4d331f..f028e24 100644
--- 
a/src/main/java/org/apache/maven/plugins/javadoc/resolver/ResourceResolver.java
+++ 
b/src/main/java/org/apache/maven/plugins/javadoc/resolver/ResourceResolver.java
@@ -227,9 +227,7 @@
             {
                 IOException error =
                     new IOException( "Failed to read javadoc options from: " + 
optionsFile + "\nReason: "
-                        + e.getMessage() );
-                error.initCause( e );
-                
+                        + e.getMessage(), e );
                 throw error;
             }
             finally
@@ -279,21 +277,14 @@
                 dirs.add( entry.getValue() );
             }
         }
-        catch ( ArtifactResolutionException e )
+        catch ( ArtifactResolutionException | ArtifactNotFoundException e )
         {
             if ( getLogger().isDebugEnabled() )
             {
                 getLogger().debug( e.getMessage(), e );
             }
         }
-        catch ( ArtifactNotFoundException e )
-        {
-            if ( getLogger().isDebugEnabled() )
-            {
-                getLogger().debug( e.getMessage(), e );
-            }
-        }
-        
+
         List<JavadocBundle> result = new ArrayList<>();
 
         for ( String d : dirs )
@@ -311,9 +302,7 @@
                 }
                 catch ( XmlPullParserException e )
                 {
-                    IOException error = new IOException( "Failed to parse 
javadoc options: " + e.getMessage() );
-                    error.initCause( e );
-                    
+                    IOException error = new IOException( "Failed to parse 
javadoc options: " + e.getMessage(), e );
                     throw error;
                 }
             }
@@ -432,8 +421,7 @@ private Artifact createResourceArtifact( final Artifact 
artifact, final String c
 
                 unArchiver.extract();
 
-                result.add( new AbstractMap.SimpleEntry<String, String>( 
a.getDependencyConflictId(),
-                                                                         
d.getAbsolutePath() ) );
+                result.add( new AbstractMap.SimpleEntry<>( 
a.getDependencyConflictId(), d.getAbsolutePath() ) );
             }
             catch ( final NoSuchArchiverException e )
             {
@@ -466,19 +454,13 @@ private Artifact createResourceArtifact( final Artifact 
artifact, final String c
             if ( config.includeCompileSources() )
             {
                 final List<String> srcRoots = 
reactorProject.getCompileSourceRoots();
-                for ( final String root : srcRoots )
-                {
-                    dirs.add( root );
-                }
+                dirs.addAll( srcRoots );
             }
 
             if ( config.includeTestSources() )
             {
                 final List<String> srcRoots = 
reactorProject.getTestCompileSourceRoots();
-                for ( final String root : srcRoots )
-                {
-                    dirs.add( root );
-                }
+                dirs.addAll( srcRoots );
             }
         }
 
diff --git 
a/src/test/java/org/apache/maven/plugins/javadoc/FixJavadocMojoTest.java 
b/src/test/java/org/apache/maven/plugins/javadoc/FixJavadocMojoTest.java
index c530ef2..94ad8f8 100644
--- a/src/test/java/org/apache/maven/plugins/javadoc/FixJavadocMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/javadoc/FixJavadocMojoTest.java
@@ -721,18 +721,7 @@ private static void prepareTestProjects( String 
testProjectDirName )
     private static String readFile( File file )
         throws Exception
     {
-        Reader fileReader = null;
-        try
-        {
-            fileReader = ReaderFactory.newReader( file, "UTF-8" );
-            final String content = IOUtil.toString( fileReader );
-            fileReader.close();
-            fileReader = null;
-            return content;
-        }
-        finally
-        {
-            IOUtil.close( fileReader );
-        }
+        String content = FileUtils.fileRead( file, "UTF-8" );
+        return content;
     }
 }
diff --git 
a/src/test/java/org/apache/maven/plugins/javadoc/JavadocReportTest.java 
b/src/test/java/org/apache/maven/plugins/javadoc/JavadocReportTest.java
index f21e063..af45c90 100644
--- a/src/test/java/org/apache/maven/plugins/javadoc/JavadocReportTest.java
+++ b/src/test/java/org/apache/maven/plugins/javadoc/JavadocReportTest.java
@@ -26,7 +26,6 @@
 import java.io.File;
 import java.io.FileReader;
 import java.io.IOException;
-import java.io.Reader;
 import java.net.HttpURLConnection;
 import java.net.URL;
 import java.util.HashMap;
@@ -48,8 +47,6 @@
 import org.apache.maven.settings.Settings;
 import org.codehaus.plexus.languages.java.version.JavaVersion;
 import org.codehaus.plexus.util.FileUtils;
-import org.codehaus.plexus.util.IOUtil;
-import org.codehaus.plexus.util.ReaderFactory;
 import org.codehaus.plexus.util.StringUtils;
 import org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager;
 
@@ -393,21 +390,10 @@ public void testCustomConfiguration()
 
         File options = new File( apidocs, "options" );
         assertTrue( options.isFile() );
-        String contentOptions = null;
-        Reader reader = null;
-        try
-        {
-            reader = ReaderFactory.newPlatformReader( options );
-            contentOptions = IOUtil.toString( reader );
-            reader.close();
-            reader = null;
-        }
-        finally
-        {
-            IOUtil.close( reader );
-        }
 
-        assertTrue( contentOptions != null );
+        String contentOptions = FileUtils.fileRead( options );
+
+        assertNotNull( contentOptions );
         assertTrue( contentOptions.contains( "-link" ) );
         assertTrue( contentOptions.contains( "http://java.sun.com/j2se/"; ) );
     }
@@ -734,7 +720,7 @@ public void testHeaderFooter()
         }
         catch ( MojoExecutionException e )
         {
-            assertTrue( "Doesnt handle correctly newline for header or footer 
parameter", false );
+            fail( "Doesnt handle correctly newline for header or footer 
parameter" );
         }
 
         assertTrue( true );
@@ -952,7 +938,7 @@ public void testValidateOptions()
         try
         {
             mojo.execute();
-            assertTrue( "No wrong encoding catch", false );
+            fail( "No wrong encoding catch" );
         }
         catch ( MojoExecutionException e )
         {
@@ -963,7 +949,7 @@ public void testValidateOptions()
         try
         {
             mojo.execute();
-            assertTrue( "No wrong docencoding catch", false );
+            fail( "No wrong docencoding catch" );
         }
         catch ( MojoExecutionException e )
         {
@@ -974,7 +960,7 @@ public void testValidateOptions()
         try
         {
             mojo.execute();
-            assertTrue( "No wrong charset catch", false );
+            fail( "No wrong charset catch" );
         }
         catch ( MojoExecutionException e )
         {
@@ -987,7 +973,7 @@ public void testValidateOptions()
         try
         {
             mojo.execute();
-            assertTrue( "No wrong locale catch", false );
+            fail( "No wrong locale catch" );
         }
         catch ( MojoExecutionException e )
         {
@@ -1004,7 +990,7 @@ public void testValidateOptions()
         try
         {
             mojo.execute();
-            assertTrue( "No conflict catch", false );
+            fail( "No conflict catch" );
         }
         catch ( MojoExecutionException e )
         {
@@ -1100,7 +1086,7 @@ public void testStylesheetfile()
         try
         {
             mojo.execute();
-            assertTrue( false );
+            fail();
         }
         catch ( Exception e )
         {
diff --git 
a/src/test/java/org/apache/maven/plugins/javadoc/JavadocUtilTest.java 
b/src/test/java/org/apache/maven/plugins/javadoc/JavadocUtilTest.java
index fa5bfaa..825c2a0 100644
--- a/src/test/java/org/apache/maven/plugins/javadoc/JavadocUtilTest.java
+++ b/src/test/java/org/apache/maven/plugins/javadoc/JavadocUtilTest.java
@@ -39,7 +39,6 @@
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.maven.plugins.javadoc.JavadocUtil;
 import org.apache.maven.plugins.javadoc.ProxyServer.AuthAsyncProxyServlet;
 import org.apache.maven.settings.Proxy;
 import org.apache.maven.settings.Settings;
@@ -69,7 +68,7 @@ public void testParseJavadocVersion()
         try
         {
             JavadocUtil.extractJavadocVersion( version );
-            assertTrue( "Not catch null", false );
+            fail( "Not catch null" );
         }
         catch ( IllegalArgumentException e )
         {
@@ -179,7 +178,7 @@ public void testParseJavadocMemory()
         try
         {
             JavadocUtil.parseJavadocMemory( memory );
-            assertTrue( "Not catch null", false );
+            fail( "Not catch null" );
         }
         catch ( IllegalArgumentException e )
         {
@@ -223,7 +222,7 @@ public void testParseJavadocMemory()
         try
         {
             JavadocUtil.parseJavadocMemory( memory );
-            assertTrue( "Not catch wrong pattern", false );
+            fail( "Not catch wrong pattern" );
         }
         catch ( IllegalArgumentException e )
         {
@@ -233,7 +232,7 @@ public void testParseJavadocMemory()
         try
         {
             JavadocUtil.parseJavadocMemory( memory );
-            assertTrue( "Not catch wrong pattern", false );
+            fail( "Not catch wrong pattern" );
         }
         catch ( IllegalArgumentException e )
         {
@@ -751,7 +750,7 @@ public void testPruneDirs()
     public void testUnifyPathSeparator()
         throws Exception
     {
-        assertEquals( null, JavadocUtil.unifyPathSeparator( null ) );
+        assertNull( JavadocUtil.unifyPathSeparator( null ) );
 
         final String ps = File.pathSeparator;
 
diff --git 
a/src/test/java/org/apache/maven/plugins/javadoc/JavadocVersionTest.java 
b/src/test/java/org/apache/maven/plugins/javadoc/JavadocVersionTest.java
index 0a4f1eb..0f0bc23 100644
--- a/src/test/java/org/apache/maven/plugins/javadoc/JavadocVersionTest.java
+++ b/src/test/java/org/apache/maven/plugins/javadoc/JavadocVersionTest.java
@@ -19,13 +19,12 @@
  * under the License.
  */
 
-import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.apache.maven.plugins.javadoc.JavadocVersion;
 import org.junit.Test;
 
 public class JavadocVersionTest
@@ -42,9 +41,9 @@ public void testParse() throws Exception
         assertTrue( JavadocVersion.parse( "1.4" ).compareTo( 
JavadocVersion.parse( "1.5" ) ) < 0 );
         assertTrue( JavadocVersion.parse( "1.8" ).compareTo( 
JavadocVersion.parse( "9" ) ) < 0 );
 
-        assertTrue( JavadocVersion.parse( "1.4" ).compareTo( 
JavadocVersion.parse( "1.4" ) ) == 0 );
-        assertTrue( JavadocVersion.parse( "1.4.2" ).compareTo( 
JavadocVersion.parse( "1.4.2" ) ) == 0 );
-        assertTrue( JavadocVersion.parse( "9" ).compareTo( 
JavadocVersion.parse( "9" ) ) == 0 );
+        assertEquals( 0, JavadocVersion.parse( "1.4" ).compareTo( 
JavadocVersion.parse( "1.4" ) ) );
+        assertEquals( 0, JavadocVersion.parse( "1.4.2" ).compareTo( 
JavadocVersion.parse( "1.4.2" ) ) );
+        assertEquals( 0, JavadocVersion.parse( "9" ).compareTo( 
JavadocVersion.parse( "9" ) ) );
 
         assertTrue( JavadocVersion.parse( "1.4.2" ).compareTo( 
JavadocVersion.parse( "1.4" ) ) > 0 );
         assertTrue( JavadocVersion.parse( "1.5" ).compareTo( 
JavadocVersion.parse( "1.4" ) ) > 0 );


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to