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 d00714cf3..972b57d9b 100644 --- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java +++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java @@ -2472,10 +2472,9 @@ private static List trimValues(List items) { List result = new ArrayList<>(items.size()); for (String item : items) { String trimmed = item.trim(); - if (trimmed == null || trimmed.isEmpty()) { - continue; + if (!trimmed.isEmpty()) { + result.add(trimmed); } - result.add(trimmed); } return result; } @@ -3658,7 +3657,7 @@ private void addArgIfNotEmpty( while (token.hasMoreTokens()) { String current = token.nextToken().trim(); - if (current != null && !current.isEmpty()) { + if (!current.isEmpty()) { arguments.add(current); if (token.hasMoreTokens() && repeatKey) { @@ -3891,9 +3890,6 @@ private synchronized void resolveDependencyBundles() throws IOException { if (dependencyJavadocBundles == null) { dependencyJavadocBundles = resourceResolver.resolveDependencyJavadocBundles(getDependencySourceResolverConfig()); - if (dependencyJavadocBundles == null) { - dependencyJavadocBundles = new ArrayList<>(); - } } } @@ -4930,45 +4926,38 @@ private void addTagletsFromTagletArtifacts(List arguments) throws MavenR tagletsPath = JavadocUtil.pruneFiles(tagletsPath); for (String tagletJar : tagletsPath) { - if (!tagletJar.toLowerCase(Locale.ENGLISH).endsWith(".jar")) { - continue; - } - - List tagletClasses; - try { - tagletClasses = JavadocUtil.getTagletClassNames(new File(tagletJar)); - } catch (IOException e) { - if (getLog().isWarnEnabled()) { - getLog().warn("Unable to auto-detect Taglet class names from '" + tagletJar - + "'. Try to specify them with ."); - } - if (getLog().isDebugEnabled()) { - getLog().debug("IOException: " + e.getMessage(), e); - } - continue; - } catch (ClassNotFoundException e) { - if (getLog().isWarnEnabled()) { - getLog().warn("Unable to auto-detect Taglet class names from '" + tagletJar - + "'. Try to specify them with ."); - } - if (getLog().isDebugEnabled()) { - getLog().debug("ClassNotFoundException: " + e.getMessage(), e); - } - continue; - } catch (NoClassDefFoundError e) { - if (getLog().isWarnEnabled()) { - getLog().warn("Unable to auto-detect Taglet class names from '" + tagletJar - + "'. Try to specify them with ."); - } - if (getLog().isDebugEnabled()) { - getLog().debug("NoClassDefFoundError: " + e.getMessage(), e); - } - continue; - } - - if (tagletClasses != null && !tagletClasses.isEmpty()) { - for (String tagletClass : tagletClasses) { - addArgIfNotEmpty(arguments, "-taglet", JavadocUtil.quotedArgument(tagletClass)); + if (tagletJar.toLowerCase(Locale.ENGLISH).endsWith(".jar")) { + try { + List tagletClasses = JavadocUtil.getTagletClassNames(new File(tagletJar)); + if (!tagletClasses.isEmpty()) { + for (String tagletClass : tagletClasses) { + addArgIfNotEmpty(arguments, "-taglet", JavadocUtil.quotedArgument(tagletClass)); + } + } + } catch (IOException e) { + if (getLog().isWarnEnabled()) { + getLog().warn("Unable to auto-detect Taglet class names from '" + tagletJar + + "'. Try to specify them with ."); + } + if (getLog().isDebugEnabled()) { + getLog().debug("IOException: " + e.getMessage(), e); + } + } catch (ClassNotFoundException e) { + if (getLog().isWarnEnabled()) { + getLog().warn("Unable to auto-detect Taglet class names from '" + tagletJar + + "'. Try to specify them with ."); + } + if (getLog().isDebugEnabled()) { + getLog().debug("ClassNotFoundException: " + e.getMessage(), e); + } + } catch (NoClassDefFoundError e) { + if (getLog().isWarnEnabled()) { + getLog().warn("Unable to auto-detect Taglet class names from '" + tagletJar + + "'. Try to specify them with ."); + } + if (getLog().isDebugEnabled()) { + getLog().debug("NoClassDefFoundError: " + e.getMessage(), e); + } } } } @@ -5072,9 +5061,7 @@ private void doExecuteJavadocCommandLine(Commandline cmd, File javadocOutputDire } writeDebugJavadocScript(cmdLine, javadocOutputDirectory); - if ((output != null && !output.isEmpty()) - && StringUtils.isEmpty(err.getOutput()) - && isJavadocVMInitError(output)) { + if (output != null && StringUtils.isEmpty(err.getOutput()) && isJavadocVMInitError(output)) { throw new MavenReportException(output + '\n' + '\n' + JavadocUtil.ERROR_INIT_VM + '\n' + "Or, try to reduce the Java heap size for the Javadoc goal using " + "-Dminmemory= and -Dmaxmemory=." + '\n' + '\n' + "Command line was: " @@ -5083,7 +5070,7 @@ && isJavadocVMInitError(output)) { + "' dir.\n"); } - if (output != null && !output.isEmpty()) { + if (output != null) { getLog().info(output); } @@ -5114,7 +5101,7 @@ && isJavadocVMInitError(output)) { throw new MavenReportException(msg.toString()); } - if (output != null && !output.isEmpty()) { + if (output != null) { getLog().info(output); } } catch (CommandLineException 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 040e9992e..4871f1a25 100644 --- a/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java +++ b/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java @@ -229,7 +229,7 @@ protected static String quotedArgument(String value) { List list = Arrays.stream(arg.split("\n")).map(String::trim).collect(Collectors.toList()); arg = String.join("", list); - if (arg != null && !arg.isEmpty()) { + if (!arg.isEmpty()) { arg = arg.replace("'", "\\'"); arg = "'" + arg + "'"; } @@ -815,9 +815,7 @@ protected static void invokeMaven( request.setProperties(properties); } File javaHome = getJavaHome(log); - if (javaHome != null) { - request.setJavaHome(javaHome); - } + request.setJavaHome(javaHome); if (log != null && log.isDebugEnabled()) { log.debug("Invoking Maven for the goals: " + goals + " with " @@ -1106,7 +1104,7 @@ private static File getJavaHome(Log log) { javaHome = new File(javaHomeValue); } - if (javaHome == null || !javaHome.exists()) { + if (!javaHome.exists()) { if (log != null && log.isErrorEnabled()) { log.error("Cannot find Java application directory. Either specify 'java.home' system property, or " + "JAVA_HOME environment variable."); @@ -1464,12 +1462,8 @@ private static BufferedReader getReader(URL url, Settings settings) throws IOExc public void close() throws IOException { super.close(); - if (httpMethod != null) { - httpMethod.releaseConnection(); - } - if (httpClient != null) { - httpClient.close(); - } + httpMethod.releaseConnection(); + httpClient.close(); } }; } 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 3218221da..f2be6a73f 100644 --- a/src/test/java/org/apache/maven/plugins/javadoc/JavadocReportTest.java +++ b/src/test/java/org/apache/maven/plugins/javadoc/JavadocReportTest.java @@ -1033,9 +1033,7 @@ public void testProxy() throws Exception { // see comment above (line 829) // assertTrue( optionsContent.contains( "-link 'http://commons.apache.org/logging/apidocs'" ) ); } finally { - if (proxyServer != null) { - proxyServer.stop(); - } + proxyServer.stop(); } }