From 42a2ab5b29536c7b254ef880107094579fa57b83 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Sat, 1 Jul 2023 08:05:59 -0400 Subject: [PATCH 1/3] [MJAVADOC-755] Use java.lang.String instead of StringUtils --- .../maven/plugins/javadoc/JavadocUtil.java | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) 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 ccb13c8e..6514dcdc 100644 --- a/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java +++ b/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java @@ -99,7 +99,6 @@ import org.codehaus.plexus.util.DirectoryScanner; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.IOUtil; -import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.cli.CommandLineException; import org.codehaus.plexus.util.cli.CommandLineUtils; import org.codehaus.plexus.util.cli.Commandline; @@ -212,12 +211,12 @@ protected static String quotedArgument(String value) { if (arg != null && !arg.isEmpty()) { if (arg.contains("'")) { - arg = StringUtils.replace(arg, "'", "\\'"); + arg = arg.replace("'", "\\'"); } arg = "'" + arg + "'"; // To prevent javadoc error - arg = StringUtils.replace(arg, "\n", " "); + arg = arg.replace("\n", " "); } return arg; @@ -285,13 +284,13 @@ protected static void copyJavadocResources(File outputDirectory, File javadocDir } List docFiles = FileUtils.getDirectoryNames( - javadocDir, "resources,**/doc-files", StringUtils.join(excludes.iterator(), ","), false, true); + javadocDir, "resources,**/doc-files", String.join(",", excludes), false, true); for (String docFile : docFiles) { File docFileOutput = new File(outputDirectory, docFile); FileUtils.mkdir(docFileOutput.getAbsolutePath()); FileUtils.copyDirectoryStructure(new File(javadocDir, docFile), docFileOutput); List files = FileUtils.getFileAndDirectoryNames( - docFileOutput, StringUtils.join(excludes.iterator(), ","), null, true, true, true, true); + docFileOutput, String.join(",", excludes), null, true, true, true, true); for (String filename : files) { File file = new File(filename); @@ -457,18 +456,21 @@ protected static JavaVersion getJavadocVersion(File javadocExe) CommandLineUtils.StringStreamConsumer err = new JavadocOutputStreamConsumer(); int exitCode = CommandLineUtils.executeCommandLine(cmd, out, err); - + String errOutput = err.getOutput(); // non-null if (exitCode != 0) { - StringBuilder msg = new StringBuilder("Exit code: " + exitCode + " - " + err.getOutput()); + StringBuilder msg = new StringBuilder("Exit code: " + exitCode + " - " + errOutput); msg.append('\n'); msg.append("Command line was:").append(CommandLineUtils.toString(cmd.getCommandline())); throw new CommandLineException(msg.toString()); } - if (StringUtils.isNotEmpty(err.getOutput())) { - return JavaVersion.parse(extractJavadocVersion(err.getOutput())); - } else if (StringUtils.isNotEmpty(out.getOutput())) { - return JavaVersion.parse(extractJavadocVersion(out.getOutput())); + if (!errOutput.isEmpty()) { + return JavaVersion.parse(extractJavadocVersion(errOutput)); + } else { + String outOutput = out.getOutput(); // non-null + if (!outOutput.isEmpty()) { + return JavaVersion.parse(extractJavadocVersion(outOutput)); + } } throw new IllegalArgumentException("No output found from the command line 'javadoc -J-version'"); @@ -881,7 +883,7 @@ protected static String unifyPathSeparator(final String path) { return null; } - return StringUtils.join(splitPath(path), File.pathSeparator); + return String.join(File.pathSeparator, splitPath(path)); } // ---------------------------------------------------------------------- @@ -1494,14 +1496,19 @@ private static CloseableHttpClient createHttpClient(Settings settings, URL url) ProxyInfo proxyInfo = new ProxyInfo(); proxyInfo.setNonProxyHosts(activeProxy.getNonProxyHosts()); - if (StringUtils.isNotEmpty(activeProxy.getHost()) + String activeProxyHost = activeProxy.getHost(); + if (activeProxyHost != null + && !activeProxyHost.isEmpty() && (url == null || !ProxyUtils.validateNonProxyHosts(proxyInfo, url.getHost()))) { HttpHost proxy = new HttpHost(activeProxy.getHost(), activeProxy.getPort()); builder.setProxy(proxy); - if (StringUtils.isNotEmpty(activeProxy.getUsername()) && activeProxy.getPassword() != null) { + String activeProxyUsername = activeProxy.getUsername(); + if (activeProxyUsername != null + && !activeProxyUsername.isEmpty() + && activeProxy.getPassword() != null) { Credentials credentials = - new UsernamePasswordCredentials(activeProxy.getUsername(), activeProxy.getPassword()); + new UsernamePasswordCredentials(activeProxyUsername, activeProxy.getPassword()); CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, credentials); From e4c6024f059bb9aff66d8664e542b72793eb9a85 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Thu, 6 Jul 2023 08:21:56 -0400 Subject: [PATCH 2/3] improve javadoc --- .../apache/maven/plugins/javadoc/JavadocUtil.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) 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 6514dcdc..16b215f7 100644 --- a/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java +++ b/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java @@ -200,19 +200,17 @@ protected static List getExcludedPackages( /** * Convenience method to wrap an argument value in single quotes (i.e. '). Intended for values which - * may contain whitespaces.
- * To prevent javadoc error, the line separator (i.e. \n) are skipped. + * may contain whitespace.
+ * To prevent javadoc errors, line feeds (i.e. \n) are replaces with spaces. * - * @param value the argument value. - * @return argument with quote + * @param value the argument value + * @return quoted argument */ protected static String quotedArgument(String value) { String arg = value; if (arg != null && !arg.isEmpty()) { - if (arg.contains("'")) { - arg = arg.replace("'", "\\'"); - } + arg = arg.replace("'", "\\'"); arg = "'" + arg + "'"; // To prevent javadoc error From 4bf864ec69fe0be51ee4a16d9d15c98e1d8bb866 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Thu, 6 Jul 2023 08:23:09 -0400 Subject: [PATCH 3/3] typo --- .../org/apache/maven/plugins/javadoc/JavadocUtil.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 16b215f7..3333e108 100644 --- a/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java +++ b/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java @@ -199,12 +199,12 @@ protected static List getExcludedPackages( } /** - * Convenience method to wrap an argument value in single quotes (i.e. '). Intended for values which + * Convenience method to wrap a command line option-argument in single quotes (i.e. '). Intended for values which * may contain whitespace.
- * To prevent javadoc errors, line feeds (i.e. \n) are replaces with spaces. + * Line feeds (i.e. \n) are replaced with spaces, and single quotes are backslash escaped. * - * @param value the argument value - * @return quoted argument + * @param value the option-argument + * @return quoted option-argument */ protected static String quotedArgument(String value) { String arg = value;