Skip to content

Commit bb0e885

Browse files
authored
[MJAVADOC-755] Use java.lang.String instead of StringUtils (#208)
* [MJAVADOC-755] Use java.lang.String instead of StringUtils
1 parent a8b2fa3 commit bb0e885

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@
9999
import org.codehaus.plexus.util.DirectoryScanner;
100100
import org.codehaus.plexus.util.FileUtils;
101101
import org.codehaus.plexus.util.IOUtil;
102-
import org.codehaus.plexus.util.StringUtils;
103102
import org.codehaus.plexus.util.cli.CommandLineException;
104103
import org.codehaus.plexus.util.cli.CommandLineUtils;
105104
import org.codehaus.plexus.util.cli.Commandline;
@@ -200,24 +199,22 @@ protected static List<String> getExcludedPackages(
200199
}
201200

202201
/**
203-
* Convenience method to wrap an argument value in single quotes (i.e. <code>'</code>). Intended for values which
204-
* may contain whitespaces. <br>
205-
* To prevent javadoc error, the line separator (i.e. <code>\n</code>) are skipped.
202+
* Convenience method to wrap a command line option-argument in single quotes (i.e. <code>'</code>). Intended for values which
203+
* may contain whitespace. <br>
204+
* Line feeds (i.e. <code>\n</code>) are replaced with spaces, and single quotes are backslash escaped.
206205
*
207-
* @param value the argument value.
208-
* @return argument with quote
206+
* @param value the option-argument
207+
* @return quoted option-argument
209208
*/
210209
protected static String quotedArgument(String value) {
211210
String arg = value;
212211

213212
if (arg != null && !arg.isEmpty()) {
214-
if (arg.contains("'")) {
215-
arg = StringUtils.replace(arg, "'", "\\'");
216-
}
213+
arg = arg.replace("'", "\\'");
217214
arg = "'" + arg + "'";
218215

219216
// To prevent javadoc error
220-
arg = StringUtils.replace(arg, "\n", " ");
217+
arg = arg.replace("\n", " ");
221218
}
222219

223220
return arg;
@@ -285,13 +282,13 @@ protected static void copyJavadocResources(File outputDirectory, File javadocDir
285282
}
286283

287284
List<String> docFiles = FileUtils.getDirectoryNames(
288-
javadocDir, "resources,**/doc-files", StringUtils.join(excludes.iterator(), ","), false, true);
285+
javadocDir, "resources,**/doc-files", String.join(",", excludes), false, true);
289286
for (String docFile : docFiles) {
290287
File docFileOutput = new File(outputDirectory, docFile);
291288
FileUtils.mkdir(docFileOutput.getAbsolutePath());
292289
FileUtils.copyDirectoryStructure(new File(javadocDir, docFile), docFileOutput);
293290
List<String> files = FileUtils.getFileAndDirectoryNames(
294-
docFileOutput, StringUtils.join(excludes.iterator(), ","), null, true, true, true, true);
291+
docFileOutput, String.join(",", excludes), null, true, true, true, true);
295292
for (String filename : files) {
296293
File file = new File(filename);
297294

@@ -457,18 +454,21 @@ protected static JavaVersion getJavadocVersion(File javadocExe)
457454
CommandLineUtils.StringStreamConsumer err = new JavadocOutputStreamConsumer();
458455

459456
int exitCode = CommandLineUtils.executeCommandLine(cmd, out, err);
460-
457+
String errOutput = err.getOutput(); // non-null
461458
if (exitCode != 0) {
462-
StringBuilder msg = new StringBuilder("Exit code: " + exitCode + " - " + err.getOutput());
459+
StringBuilder msg = new StringBuilder("Exit code: " + exitCode + " - " + errOutput);
463460
msg.append('\n');
464461
msg.append("Command line was:").append(CommandLineUtils.toString(cmd.getCommandline()));
465462
throw new CommandLineException(msg.toString());
466463
}
467464

468-
if (StringUtils.isNotEmpty(err.getOutput())) {
469-
return JavaVersion.parse(extractJavadocVersion(err.getOutput()));
470-
} else if (StringUtils.isNotEmpty(out.getOutput())) {
471-
return JavaVersion.parse(extractJavadocVersion(out.getOutput()));
465+
if (!errOutput.isEmpty()) {
466+
return JavaVersion.parse(extractJavadocVersion(errOutput));
467+
} else {
468+
String outOutput = out.getOutput(); // non-null
469+
if (!outOutput.isEmpty()) {
470+
return JavaVersion.parse(extractJavadocVersion(outOutput));
471+
}
472472
}
473473

474474
throw new IllegalArgumentException("No output found from the command line 'javadoc -J-version'");
@@ -881,7 +881,7 @@ protected static String unifyPathSeparator(final String path) {
881881
return null;
882882
}
883883

884-
return StringUtils.join(splitPath(path), File.pathSeparator);
884+
return String.join(File.pathSeparator, splitPath(path));
885885
}
886886

887887
// ----------------------------------------------------------------------
@@ -1494,14 +1494,19 @@ private static CloseableHttpClient createHttpClient(Settings settings, URL url)
14941494
ProxyInfo proxyInfo = new ProxyInfo();
14951495
proxyInfo.setNonProxyHosts(activeProxy.getNonProxyHosts());
14961496

1497-
if (StringUtils.isNotEmpty(activeProxy.getHost())
1497+
String activeProxyHost = activeProxy.getHost();
1498+
if (activeProxyHost != null
1499+
&& !activeProxyHost.isEmpty()
14981500
&& (url == null || !ProxyUtils.validateNonProxyHosts(proxyInfo, url.getHost()))) {
14991501
HttpHost proxy = new HttpHost(activeProxy.getHost(), activeProxy.getPort());
15001502
builder.setProxy(proxy);
15011503

1502-
if (StringUtils.isNotEmpty(activeProxy.getUsername()) && activeProxy.getPassword() != null) {
1504+
String activeProxyUsername = activeProxy.getUsername();
1505+
if (activeProxyUsername != null
1506+
&& !activeProxyUsername.isEmpty()
1507+
&& activeProxy.getPassword() != null) {
15031508
Credentials credentials =
1504-
new UsernamePasswordCredentials(activeProxy.getUsername(), activeProxy.getPassword());
1509+
new UsernamePasswordCredentials(activeProxyUsername, activeProxy.getPassword());
15051510

15061511
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
15071512
credentialsProvider.setCredentials(AuthScope.ANY, credentials);

0 commit comments

Comments
 (0)