Skip to content

Commit

Permalink
[MJAVADOC-814] handle parameters such packages with multi lines (#337)
Browse files Browse the repository at this point in the history
* [MJAVADOC-814] handle parameters such packages with multi lines

* manage other parameters with multi lines

---------

Signed-off-by: Olivier Lamy <olamy@apache.org>
  • Loading branch information
olamy authored Nov 18, 2024
1 parent 3bb982d commit 314203a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5955,7 +5955,7 @@ protected final JavadocOptions buildJavadocOptions() throws IOException {
options.setBootclasspathArtifacts(toList(bootclasspathArtifacts));
options.setDocfilesSubdirsUsed(docfilessubdirs);
options.setDocletArtifacts(toList(docletArtifact, docletArtifacts));
options.setExcludedDocfilesSubdirs(excludedocfilessubdir);
options.setExcludedDocfilesSubdirs(excludedocfilessubdir == null ? null : excludedocfilessubdir.trim());
options.setExcludePackageNames(toList(excludePackageNames));
options.setGroups(toList(groups));
options.setLinks(links);
Expand Down
33 changes: 18 additions & 15 deletions src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -57,6 +56,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import java.util.stream.Collectors;

import org.apache.http.HttpHeaders;
import org.apache.http.HttpHost;
Expand Down Expand Up @@ -221,14 +221,17 @@ protected static List<String> getExcludedPackages(
* @return quoted option-argument
*/
protected static String quotedArgument(String value) {
if (value == null) {
return null;
}
String arg = value;

List<String> list = Arrays.stream(arg.split("\n")).map(String::trim).collect(Collectors.toList());
arg = String.join("", list);

if (arg != null && !arg.isEmpty()) {
arg = arg.replace("'", "\\'");
arg = "'" + arg + "'";

// To prevent javadoc error
arg = arg.replace("\n", " ");
}

return arg;
Expand All @@ -253,7 +256,7 @@ protected static String quotedPathArgument(String value) {

for (int i = 0; i < split.length; i++) {
if (i != split.length - 1) {
pathBuilder.append(split[i]).append("\\'");
pathBuilder.append(split[i].trim()).append("\\'");
} else {
pathBuilder.append(split[i]);
}
Expand Down Expand Up @@ -291,7 +294,7 @@ protected static void copyJavadocResources(File outputDirectory, File javadocDir
String current;
while (st.hasMoreTokens()) {
current = st.nextToken();
excludes.add("**/" + current + "/**");
excludes.add("**/" + current.trim() + "/**");
}
}

Expand Down Expand Up @@ -422,9 +425,9 @@ protected static List<String> getFilesFromSource(
if (sourceFileIncludes == null) {
sourceFileIncludes = Collections.singletonList("**/*.java");
}
ds.setIncludes(sourceFileIncludes.toArray(new String[sourceFileIncludes.size()]));
if (sourceFileExcludes != null && sourceFileExcludes.size() > 0) {
ds.setExcludes(sourceFileExcludes.toArray(new String[sourceFileExcludes.size()]));
ds.setIncludes(sourceFileIncludes.toArray(new String[0]));
if (sourceFileExcludes != null && !sourceFileExcludes.isEmpty()) {
ds.setExcludes(sourceFileExcludes.toArray(new String[0]));
}
ds.setBasedir(sourceDirectory);
ds.scan();
Expand Down Expand Up @@ -753,7 +756,7 @@ protected static void invokeMaven(
if (!projectFile.isFile()) {
throw new IllegalArgumentException(projectFile.getAbsolutePath() + " is not a file.");
}
if (goals == null || goals.size() == 0) {
if (goals == null || goals.isEmpty()) {
throw new IllegalArgumentException("goals should be not empty.");
}
if (localRepositoryDir == null || !localRepositoryDir.isDirectory()) {
Expand Down Expand Up @@ -889,7 +892,7 @@ protected static String[] splitPath(final String path) {
subpaths.add(pathTokenizer.nextToken());
}

return subpaths.toArray(new String[subpaths.size()]);
return subpaths.toArray(new String[0]);
}

/**
Expand Down Expand Up @@ -932,7 +935,7 @@ private static List<String> getClassNamesFromJar(File jarFile) throws IOExceptio

List<String> classes = new ArrayList<>();
Pattern pattern = Pattern.compile("(?i)^(META-INF/versions/(?<v>[0-9]+)/)?(?<n>.+)[.]class$");
try (JarInputStream jarStream = new JarInputStream(new FileInputStream(jarFile))) {
try (JarInputStream jarStream = new JarInputStream(Files.newInputStream(jarFile.toPath()))) {
for (JarEntry jarEntry = jarStream.getNextJarEntry();
jarEntry != null;
jarEntry = jarStream.getNextJarEntry()) {
Expand Down Expand Up @@ -1179,7 +1182,7 @@ public String nextToken() throws NoSuchElementException {
lookahead = nextToken;
}
}
return token;
return token.trim();
}
}

Expand Down Expand Up @@ -1223,7 +1226,7 @@ static List<String> toList(String src, String elementPrefix, String elementSuffi
sb.append(elementSuffix);
}

result.add(sb.toString());
result.add(sb.toString().trim());
}

return result;
Expand Down Expand Up @@ -1513,7 +1516,7 @@ private static CloseableHttpClient createHttpClient(Settings settings, URL url)
builder.setUserAgent("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");

// Some server reject requests that do not have an Accept header
builder.setDefaultHeaders(Arrays.asList(new BasicHeader(HttpHeaders.ACCEPT, "*/*")));
builder.setDefaultHeaders(Collections.singletonList(new BasicHeader(HttpHeaders.ACCEPT, "*/*")));

if (settings != null && settings.getActiveProxy() != null) {
Proxy activeProxy = settings.getActiveProxy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,11 @@ public void testUnifyPathSeparator() {
assertEquals(
path1 + ps + path2 + ps + path1 + ps + path2,
JavadocUtil.unifyPathSeparator(path1 + ";" + path2 + ":" + path1 + ":" + path2));

path1 = "/tmp/maven-javadoc-plugin/src/main/java;\n" + "/tmp/maven-javadoc-plugin/src/main/javadoc\n";
assertEquals(
"/tmp/maven-javadoc-plugin/src/main/java" + ps + "/tmp/maven-javadoc-plugin/src/main/javadoc",
JavadocUtil.unifyPathSeparator(path1));
}

public void testGetIncludedFiles() {
Expand All @@ -675,4 +680,23 @@ private void stopSilently(Server server) {
// ignored
}
}

public void testQuotedArgument() throws Exception {

String value = " org.apache.uima.analysis_component:\n org.apache.uima.analysis_engine\n";

String arg = JavadocUtil.quotedArgument(value);
assertEquals("'org.apache.uima.analysis_component:org.apache.uima.analysis_engine'", arg);

value = "org.apache.uima.analysis_component:org.apache.uima.analysis_engine";

arg = JavadocUtil.quotedArgument(value);
assertEquals("'org.apache.uima.analysis_component:org.apache.uima.analysis_engine'", arg);
}

public void testToList() throws Exception {
String value = " *.internal:org.acme.exclude1.*:\n org.acme.exclude2\n ";
List<String> values = JavadocUtil.toList(value);
assertThat(values).containsExactly("*.internal", "org.acme.exclude1.*", "org.acme.exclude2");
}
}

0 comments on commit 314203a

Please sign in to comment.