Skip to content

Commit

Permalink
[MJAVADOC-822] skippedModules should be more scalable and support reg…
Browse files Browse the repository at this point in the history
…ex (#336)

Signed-off-by: Olivier Lamy <olamy@apache.org>
  • Loading branch information
olamy authored Nov 16, 2024
1 parent 6cec134 commit 76826c8
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 5 deletions.
33 changes: 33 additions & 0 deletions src/it/projects/MJAVADOC-636-aggregate_module_skipped/b/e1/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.apache.maven.plugins.javadoc.it</groupId>
<artifactId>mjavadoc636b</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>mjavadoc636e1</artifactId>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package a.b.e;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

public interface E1
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<modules>
<module>c</module>
<module>e</module>
<module>e1</module>
</modules>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<artifactId>maven-javadoc-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<skippedModules>mjavadoc636e,mjavadoc636d1</skippedModules>
<skippedModules>mjavadoc636e.*,mjavadoc636d1</skippedModules>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ for (JarEntry file in jar.entries()){
}

assert !files.contains("a/b/e/E.html")
assert !files.contains("a/b/e/E1.html")
assert !files.contains("a/b/c/d/D1.html")
assert files.contains("a/b/c/d/D2.html")
assert files.contains("a/f/F.html")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import java.util.Properties;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.apache.commons.lang3.BooleanUtils;
Expand Down Expand Up @@ -1210,7 +1211,7 @@ public abstract class AbstractJavadocMojo extends AbstractMojo {
* <br/>
* <b>Note</b>: if {@link #detectOfflineLinks} is defined, the offline links between the project modules are
* automatically added if the goal is calling in a non-aggregator way.
* @see OfflineLink.
* @see OfflineLink
* @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>
*/
@Parameter(property = "offlineLinks")
Expand Down Expand Up @@ -1642,14 +1643,19 @@ public abstract class AbstractJavadocMojo extends AbstractMojo {

/**
* <p>
* Comma separated list of modules (artifactId) to not add in aggregated javadoc
* Comma separated list of modules (can be regular expression) in the format ([group:]artifactId) to not add in aggregated javadoc
* </p>
*
* @since 3.2.0
*/
@Parameter(property = "maven.javadoc.skippedModules")
private String skippedModules;

/**
* List built once from the parameter {@link #skippedModules}
*/
private List<Pattern> patternsToSkip;

/**
* Timestamp for reproducible output archive entries, either formatted as ISO 8601
* <code>yyyy-MM-dd'T'HH:mm:ssXXX</code> or as an int representing seconds since the epoch (like
Expand Down Expand Up @@ -6043,8 +6049,20 @@ protected boolean isSkippedModule(MavenProject mavenProject) {
if (this.skippedModules == null || this.skippedModules.isEmpty()) {
return false;
}
List<String> modulesToSkip = Arrays.asList(StringUtils.split(this.skippedModules, ','));
return modulesToSkip.contains(mavenProject.getArtifactId());
if (this.patternsToSkip == null) {
this.patternsToSkip = Arrays.stream(StringUtils.split(this.skippedModules, ','))
.map(String::trim)
// we are expecting something such [groupdId:]artifactId so if no groupId we want to match any
// groupId
.map(s -> !s.contains(":") ? ".*:" + s : s)
.map(Pattern::compile)
.collect(Collectors.toList());
}
Optional<Pattern> found = this.patternsToSkip.stream()
.filter(pattern -> pattern.matcher(mavenProject.getGroupId() + ":" + mavenProject.getArtifactId())
.matches())
.findAny();
return found.isPresent() || isSkippedJavadoc(mavenProject);
}

/**
Expand Down

0 comments on commit 76826c8

Please # to comment.