Skip to content

Commit 76826c8

Browse files
authored
[MJAVADOC-822] skippedModules should be more scalable and support regex (#336)
Signed-off-by: Olivier Lamy <[email protected]>
1 parent 6cec134 commit 76826c8

File tree

6 files changed

+83
-5
lines changed

6 files changed

+83
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one
4+
~ or more contributor license agreements. See the NOTICE file
5+
~ distributed with this work for additional information
6+
~ regarding copyright ownership. The ASF licenses this file
7+
~ to you under the Apache License, Version 2.0 (the
8+
~ "License"); you may not use this file except in compliance
9+
~ with the License. You may obtain a copy of the License at
10+
~
11+
~ http://www.apache.org/licenses/LICENSE-2.0
12+
~
13+
~ Unless required by applicable law or agreed to in writing,
14+
~ software distributed under the License is distributed on an
15+
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
~ KIND, either express or implied. See the License for the
17+
~ specific language governing permissions and limitations
18+
~ under the License.
19+
-->
20+
21+
<project xmlns="http://maven.apache.org/POM/4.0.0"
22+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
23+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
24+
<modelVersion>4.0.0</modelVersion>
25+
26+
<parent>
27+
<groupId>org.apache.maven.plugins.javadoc.it</groupId>
28+
<artifactId>mjavadoc636b</artifactId>
29+
<version>1.0-SNAPSHOT</version>
30+
</parent>
31+
<artifactId>mjavadoc636e1</artifactId>
32+
33+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package a.b.e;
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
public interface E1
23+
{
24+
25+
}

src/it/projects/MJAVADOC-636-aggregate_module_skipped/b/pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<modules>
3535
<module>c</module>
3636
<module>e</module>
37+
<module>e1</module>
3738
</modules>
3839

3940
</project>

src/it/projects/MJAVADOC-636-aggregate_module_skipped/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
<artifactId>maven-javadoc-plugin</artifactId>
5555
<version>@project.version@</version>
5656
<configuration>
57-
<skippedModules>mjavadoc636e,mjavadoc636d1</skippedModules>
57+
<skippedModules>mjavadoc636e.*,mjavadoc636d1</skippedModules>
5858
</configuration>
5959
</plugin>
6060
</plugins>

src/it/projects/MJAVADOC-636-aggregate_module_skipped/verify.groovy

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ for (JarEntry file in jar.entries()){
3232
}
3333

3434
assert !files.contains("a/b/e/E.html")
35+
assert !files.contains("a/b/e/E1.html")
3536
assert !files.contains("a/b/c/d/D1.html")
3637
assert files.contains("a/b/c/d/D2.html")
3738
assert files.contains("a/f/F.html")

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

+22-4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import java.util.Properties;
5353
import java.util.Set;
5454
import java.util.StringTokenizer;
55+
import java.util.regex.Pattern;
5556
import java.util.stream.Collectors;
5657

5758
import org.apache.commons.lang3.BooleanUtils;
@@ -1210,7 +1211,7 @@ public abstract class AbstractJavadocMojo extends AbstractMojo {
12101211
* <br/>
12111212
* <b>Note</b>: if {@link #detectOfflineLinks} is defined, the offline links between the project modules are
12121213
* automatically added if the goal is calling in a non-aggregator way.
1213-
* @see OfflineLink.
1214+
* @see OfflineLink
12141215
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#additional-options-provided-by-the-standard-doclet">Doclet option linkoffline</a>
12151216
*/
12161217
@Parameter(property = "offlineLinks")
@@ -1642,14 +1643,19 @@ public abstract class AbstractJavadocMojo extends AbstractMojo {
16421643

16431644
/**
16441645
* <p>
1645-
* Comma separated list of modules (artifactId) to not add in aggregated javadoc
1646+
* Comma separated list of modules (can be regular expression) in the format ([group:]artifactId) to not add in aggregated javadoc
16461647
* </p>
16471648
*
16481649
* @since 3.2.0
16491650
*/
16501651
@Parameter(property = "maven.javadoc.skippedModules")
16511652
private String skippedModules;
16521653

1654+
/**
1655+
* List built once from the parameter {@link #skippedModules}
1656+
*/
1657+
private List<Pattern> patternsToSkip;
1658+
16531659
/**
16541660
* Timestamp for reproducible output archive entries, either formatted as ISO 8601
16551661
* <code>yyyy-MM-dd'T'HH:mm:ssXXX</code> or as an int representing seconds since the epoch (like
@@ -6043,8 +6049,20 @@ protected boolean isSkippedModule(MavenProject mavenProject) {
60436049
if (this.skippedModules == null || this.skippedModules.isEmpty()) {
60446050
return false;
60456051
}
6046-
List<String> modulesToSkip = Arrays.asList(StringUtils.split(this.skippedModules, ','));
6047-
return modulesToSkip.contains(mavenProject.getArtifactId());
6052+
if (this.patternsToSkip == null) {
6053+
this.patternsToSkip = Arrays.stream(StringUtils.split(this.skippedModules, ','))
6054+
.map(String::trim)
6055+
// we are expecting something such [groupdId:]artifactId so if no groupId we want to match any
6056+
// groupId
6057+
.map(s -> !s.contains(":") ? ".*:" + s : s)
6058+
.map(Pattern::compile)
6059+
.collect(Collectors.toList());
6060+
}
6061+
Optional<Pattern> found = this.patternsToSkip.stream()
6062+
.filter(pattern -> pattern.matcher(mavenProject.getGroupId() + ":" + mavenProject.getArtifactId())
6063+
.matches())
6064+
.findAny();
6065+
return found.isPresent() || isSkippedJavadoc(mavenProject);
60486066
}
60496067

60506068
/**

0 commit comments

Comments
 (0)