Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[MJAVADOC-814] handle parameters such packages with multi lines #337

Merged
merged 3 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
olamy marked this conversation as resolved.
Show resolved Hide resolved
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);
olamy marked this conversation as resolved.
Show resolved Hide resolved

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);
assertThat(arg).isEqualTo("'org.apache.uima.analysis_component:org.apache.uima.analysis_engine'");
olamy marked this conversation as resolved.
Show resolved Hide resolved

value = "org.apache.uima.analysis_component:org.apache.uima.analysis_engine";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be two test methods so they don't interfere with eech other


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

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");
}
}