Skip to content

Commit 314203a

Browse files
authored
[MJAVADOC-814] handle parameters such packages with multi lines (#337)
* [MJAVADOC-814] handle parameters such packages with multi lines * manage other parameters with multi lines --------- Signed-off-by: Olivier Lamy <olamy@apache.org>
1 parent 3bb982d commit 314203a

File tree

3 files changed

+43
-16
lines changed

3 files changed

+43
-16
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -5955,7 +5955,7 @@ protected final JavadocOptions buildJavadocOptions() throws IOException {
59555955
options.setBootclasspathArtifacts(toList(bootclasspathArtifacts));
59565956
options.setDocfilesSubdirsUsed(docfilessubdirs);
59575957
options.setDocletArtifacts(toList(docletArtifact, docletArtifacts));
5958-
options.setExcludedDocfilesSubdirs(excludedocfilessubdir);
5958+
options.setExcludedDocfilesSubdirs(excludedocfilessubdir == null ? null : excludedocfilessubdir.trim());
59595959
options.setExcludePackageNames(toList(excludePackageNames));
59605960
options.setGroups(toList(groups));
59615961
options.setLinks(links);

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

+18-15
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import java.io.BufferedReader;
2222
import java.io.File;
23-
import java.io.FileInputStream;
2423
import java.io.FileNotFoundException;
2524
import java.io.FileOutputStream;
2625
import java.io.IOException;
@@ -57,6 +56,7 @@
5756
import java.util.regex.Matcher;
5857
import java.util.regex.Pattern;
5958
import java.util.regex.PatternSyntaxException;
59+
import java.util.stream.Collectors;
6060

6161
import org.apache.http.HttpHeaders;
6262
import org.apache.http.HttpHost;
@@ -221,14 +221,17 @@ protected static List<String> getExcludedPackages(
221221
* @return quoted option-argument
222222
*/
223223
protected static String quotedArgument(String value) {
224+
if (value == null) {
225+
return null;
226+
}
224227
String arg = value;
225228

229+
List<String> list = Arrays.stream(arg.split("\n")).map(String::trim).collect(Collectors.toList());
230+
arg = String.join("", list);
231+
226232
if (arg != null && !arg.isEmpty()) {
227233
arg = arg.replace("'", "\\'");
228234
arg = "'" + arg + "'";
229-
230-
// To prevent javadoc error
231-
arg = arg.replace("\n", " ");
232235
}
233236

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

254257
for (int i = 0; i < split.length; i++) {
255258
if (i != split.length - 1) {
256-
pathBuilder.append(split[i]).append("\\'");
259+
pathBuilder.append(split[i].trim()).append("\\'");
257260
} else {
258261
pathBuilder.append(split[i]);
259262
}
@@ -291,7 +294,7 @@ protected static void copyJavadocResources(File outputDirectory, File javadocDir
291294
String current;
292295
while (st.hasMoreTokens()) {
293296
current = st.nextToken();
294-
excludes.add("**/" + current + "/**");
297+
excludes.add("**/" + current.trim() + "/**");
295298
}
296299
}
297300

@@ -422,9 +425,9 @@ protected static List<String> getFilesFromSource(
422425
if (sourceFileIncludes == null) {
423426
sourceFileIncludes = Collections.singletonList("**/*.java");
424427
}
425-
ds.setIncludes(sourceFileIncludes.toArray(new String[sourceFileIncludes.size()]));
426-
if (sourceFileExcludes != null && sourceFileExcludes.size() > 0) {
427-
ds.setExcludes(sourceFileExcludes.toArray(new String[sourceFileExcludes.size()]));
428+
ds.setIncludes(sourceFileIncludes.toArray(new String[0]));
429+
if (sourceFileExcludes != null && !sourceFileExcludes.isEmpty()) {
430+
ds.setExcludes(sourceFileExcludes.toArray(new String[0]));
428431
}
429432
ds.setBasedir(sourceDirectory);
430433
ds.scan();
@@ -753,7 +756,7 @@ protected static void invokeMaven(
753756
if (!projectFile.isFile()) {
754757
throw new IllegalArgumentException(projectFile.getAbsolutePath() + " is not a file.");
755758
}
756-
if (goals == null || goals.size() == 0) {
759+
if (goals == null || goals.isEmpty()) {
757760
throw new IllegalArgumentException("goals should be not empty.");
758761
}
759762
if (localRepositoryDir == null || !localRepositoryDir.isDirectory()) {
@@ -889,7 +892,7 @@ protected static String[] splitPath(final String path) {
889892
subpaths.add(pathTokenizer.nextToken());
890893
}
891894

892-
return subpaths.toArray(new String[subpaths.size()]);
895+
return subpaths.toArray(new String[0]);
893896
}
894897

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

933936
List<String> classes = new ArrayList<>();
934937
Pattern pattern = Pattern.compile("(?i)^(META-INF/versions/(?<v>[0-9]+)/)?(?<n>.+)[.]class$");
935-
try (JarInputStream jarStream = new JarInputStream(new FileInputStream(jarFile))) {
938+
try (JarInputStream jarStream = new JarInputStream(Files.newInputStream(jarFile.toPath()))) {
936939
for (JarEntry jarEntry = jarStream.getNextJarEntry();
937940
jarEntry != null;
938941
jarEntry = jarStream.getNextJarEntry()) {
@@ -1179,7 +1182,7 @@ public String nextToken() throws NoSuchElementException {
11791182
lookahead = nextToken;
11801183
}
11811184
}
1182-
return token;
1185+
return token.trim();
11831186
}
11841187
}
11851188

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

1226-
result.add(sb.toString());
1229+
result.add(sb.toString().trim());
12271230
}
12281231

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

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

15181521
if (settings != null && settings.getActiveProxy() != null) {
15191522
Proxy activeProxy = settings.getActiveProxy();

src/test/java/org/apache/maven/plugins/javadoc/JavadocUtilTest.java

+24
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,11 @@ public void testUnifyPathSeparator() {
654654
assertEquals(
655655
path1 + ps + path2 + ps + path1 + ps + path2,
656656
JavadocUtil.unifyPathSeparator(path1 + ";" + path2 + ":" + path1 + ":" + path2));
657+
658+
path1 = "/tmp/maven-javadoc-plugin/src/main/java;\n" + "/tmp/maven-javadoc-plugin/src/main/javadoc\n";
659+
assertEquals(
660+
"/tmp/maven-javadoc-plugin/src/main/java" + ps + "/tmp/maven-javadoc-plugin/src/main/javadoc",
661+
JavadocUtil.unifyPathSeparator(path1));
657662
}
658663

659664
public void testGetIncludedFiles() {
@@ -675,4 +680,23 @@ private void stopSilently(Server server) {
675680
// ignored
676681
}
677682
}
683+
684+
public void testQuotedArgument() throws Exception {
685+
686+
String value = " org.apache.uima.analysis_component:\n org.apache.uima.analysis_engine\n";
687+
688+
String arg = JavadocUtil.quotedArgument(value);
689+
assertEquals("'org.apache.uima.analysis_component:org.apache.uima.analysis_engine'", arg);
690+
691+
value = "org.apache.uima.analysis_component:org.apache.uima.analysis_engine";
692+
693+
arg = JavadocUtil.quotedArgument(value);
694+
assertEquals("'org.apache.uima.analysis_component:org.apache.uima.analysis_engine'", arg);
695+
}
696+
697+
public void testToList() throws Exception {
698+
String value = " *.internal:org.acme.exclude1.*:\n org.acme.exclude2\n ";
699+
List<String> values = JavadocUtil.toList(value);
700+
assertThat(values).containsExactly("*.internal", "org.acme.exclude1.*", "org.acme.exclude2");
701+
}
678702
}

0 commit comments

Comments
 (0)