This is an automated email from the ASF dual-hosted git repository.
cziegeler pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/sling-slingfeature-maven-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new 9b6339b SLING-9615 : Provide options to manipulate the javadoc
classpath
9b6339b is described below
commit 9b6339b1d4dce6541fad754e9d2c0702b077f369
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Tue Jul 28 15:27:58 2020 +0200
SLING-9615 : Provide options to manipulate the javadoc classpath
---
pom.xml | 4 +-
.../sling/feature/maven/mojos/ApisJarMojo.java | 31 ++++++-
.../feature/maven/mojos/apis/ApisJarContext.java | 8 +-
.../sling/feature/maven/mojos/apis/ApisUtil.java | 101 +++++++++++++++++++--
4 files changed, 128 insertions(+), 16 deletions(-)
diff --git a/pom.xml b/pom.xml
index 06506cf..f63d2f3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -170,12 +170,12 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.feature</artifactId>
- <version>1.2.4</version>
+ <version>1.2.5-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.feature.analyser</artifactId>
- <version>1.3.4</version>
+ <version>1.3.5-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
diff --git
a/src/main/java/org/apache/sling/feature/maven/mojos/ApisJarMojo.java
b/src/main/java/org/apache/sling/feature/maven/mojos/ApisJarMojo.java
index 2b7f3d5..301a4f4 100644
--- a/src/main/java/org/apache/sling/feature/maven/mojos/ApisJarMojo.java
+++ b/src/main/java/org/apache/sling/feature/maven/mojos/ApisJarMojo.java
@@ -351,6 +351,34 @@ public class ApisJarMojo extends
AbstractIncludingFeatureMojo {
@Parameter(defaultValue = "true")
private boolean javadocTree;
+ /**
+ * A artifact patterns to match artifacts put on the javadoc classpath.
Follows the pattern
+ * "groupId:artifactId:type:classifier:version". Any matching artifact is
removed from the
+ * classpath. Removals are processed first.
+ * @since 1.3.14
+ */
+ @Parameter
+ private List<String> javadocClasspathRemovals;
+
+ /**
+ * A artifact patterns to match artifacts put on the javadoc classpath.
Follows the pattern
+ * "groupId:artifactId:type:classifier:version". From the matching
artifacts, only
+ * the highest version is kept per artifact. This rule is applied after
the removals.
+ * @since 1.3.14
+ */
+ @Parameter
+ private List<String> javadocClasspathHighestVersions;
+
+ /**
+ * A artifact patterns to match artifacts put on the javadoc classpath.
Follows the pattern
+ * "groupId:artifactId:type:classifier:version". Any matching artifact is
put at the top of
+ * the classpath. This rule is applied last.
+ * @since 1.3.14
+ */
+ @Parameter
+ private List<String> javadocClasspathTops;
+
+
@Parameter(defaultValue = "${project.build.directory}/apis-jars", readonly
= true)
private File mainOutputDir;
@@ -1724,7 +1752,8 @@ public class ApisJarMojo extends
AbstractIncludingFeatureMojo {
}
// classpath
- final Set<String> classpath = ApisUtil.getJavadocClassPath(getLog(),
repositorySystem, mavenSession, ctx, region);
+ final Collection<String> classpath =
ApisUtil.getJavadocClassPath(getLog(), repositorySystem, mavenSession,
+ ctx, region, this.javadocClasspathRemovals,
this.javadocClasspathHighestVersions, this.javadocClasspathTops);
if (!classpath.isEmpty()) {
javadocExecutor.addArgument("-classpath", false)
.addArgument(classpath, File.pathSeparator);
diff --git
a/src/main/java/org/apache/sling/feature/maven/mojos/apis/ApisJarContext.java
b/src/main/java/org/apache/sling/feature/maven/mojos/apis/ApisJarContext.java
index 14fa195..f0865a8 100644
---
a/src/main/java/org/apache/sling/feature/maven/mojos/apis/ApisJarContext.java
+++
b/src/main/java/org/apache/sling/feature/maven/mojos/apis/ApisJarContext.java
@@ -209,7 +209,7 @@ public class ApisJarContext {
}
}
- private final Set<String> javadocClasspath = new HashSet<>();
+ private final Map<ArtifactId, String> javadocClasspath = new HashMap<>();
private final Set<String> packagesWithoutJavaClasses = new HashSet<>();
@@ -266,11 +266,11 @@ public class ApisJarContext {
return checkedOutSourcesDir;
}
- public boolean addJavadocClasspath(final String classpathItem) {
- return javadocClasspath.add(classpathItem);
+ public void addJavadocClasspath(final ArtifactId artifactId, final String
classpath) {
+ javadocClasspath.put(artifactId, classpath);
}
- public Set<String> getJavadocClasspath() {
+ public Map<ArtifactId, String> getJavadocClasspath() {
return javadocClasspath;
}
diff --git
a/src/main/java/org/apache/sling/feature/maven/mojos/apis/ApisUtil.java
b/src/main/java/org/apache/sling/feature/maven/mojos/apis/ApisUtil.java
index 182cfda..a839167 100644
--- a/src/main/java/org/apache/sling/feature/maven/mojos/apis/ApisUtil.java
+++ b/src/main/java/org/apache/sling/feature/maven/mojos/apis/ApisUtil.java
@@ -23,11 +23,15 @@ import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.TreeSet;
+import java.util.TreeMap;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
@@ -41,6 +45,7 @@ import org.apache.sling.feature.Artifact;
import org.apache.sling.feature.ArtifactId;
import org.apache.sling.feature.extension.apiregions.api.ApiRegion;
import org.apache.sling.feature.maven.mojos.apis.ApisJarContext.ArtifactInfo;
+import org.apache.sling.feature.maven.mojos.selection.IncludeExcludeMatcher;
/**
* Context for creating the api jars
@@ -184,11 +189,18 @@ public class ApisUtil {
* Build the classpath for javadoc
* @throws MojoExecutionException
*/
- public static Set<String> getJavadocClassPath(final Log log, final
RepositorySystem repositorySystem,
+ public static Collection<String> getJavadocClassPath(final Log log,
+ final RepositorySystem repositorySystem,
final MavenSession mavenSession,
- final ApisJarContext ctx, final ApiRegion region) throws
MojoExecutionException {
- // classpath
- final Set<String> classpath = new TreeSet<>(ctx.getJavadocClasspath());
+ final ApisJarContext ctx,
+ final ApiRegion region,
+ final List<String> javadocClasspathRemovals,
+ final List<String> javadocClasspathHighestVersions,
+ final List<String> javadocClasspathTops) throws
MojoExecutionException {
+ // classpath - reverse order to have highest versions first
+ final Map<ArtifactId, String> classpathMapping = new
TreeMap<>(Comparator.reverseOrder());
+ classpathMapping.putAll(ctx.getJavadocClasspath());
+
for(final ArtifactInfo info : ctx.getArtifactInfos(region, false)) {
final String ids =
info.getArtifact().getMetadata().get(ApisUtil.JAVADOC_CLASSPATH);
if ( ids != null ) {
@@ -196,21 +208,91 @@ public class ApisUtil {
try {
final ArtifactId cpId = ArtifactId.parse(s.trim());
- classpath.addAll(buildJavadocClasspath(log,
repositorySystem, mavenSession, cpId));
+ classpathMapping.putAll(buildJavadocClasspath(log,
repositorySystem, mavenSession, cpId));
} catch ( final IllegalArgumentException iae) {
throw new MojoExecutionException("Invalid javadoc
classpath artifact id " + s);
}
}
}
}
+
+ // filter classpath using rules
+ // remove
+ if ( javadocClasspathRemovals != null &&
!javadocClasspathRemovals.isEmpty()) {
+ log.debug("Using javadoc classpath removal:
".concat(javadocClasspathRemovals.toString()));
+ final IncludeExcludeMatcher matcher = new
IncludeExcludeMatcher(javadocClasspathRemovals, null, null, false);
+ final Iterator<ArtifactId> iter =
classpathMapping.keySet().iterator();
+ while ( iter.hasNext() ) {
+ final ArtifactId id = iter.next();
+ if ( matcher.matches(id) != null ) {
+ log.debug("Removing from javadoc classpath: " +
id.toMvnId());
+ iter.remove();
+ }
+ }
+ }
+
+ // highest
+ if ( javadocClasspathHighestVersions != null &&
!javadocClasspathHighestVersions.isEmpty() ) {
+ log.debug("Using javadoc classpath highest versions:
".concat(javadocClasspathHighestVersions.toString()));
+ final IncludeExcludeMatcher matcher = new
IncludeExcludeMatcher(javadocClasspathHighestVersions, null, null, false);
+ final Map<ArtifactId, List<ArtifactId>> highest = new HashMap<>();
+ for(final Map.Entry<ArtifactId, String> entry :
classpathMapping.entrySet()) {
+ if ( matcher.matches(entry.getKey()) != null ) {
+ final ArtifactId key = entry.getKey().changeVersion("0");
+ highest.computeIfAbsent(key, k -> new
ArrayList<>()).add(entry.getKey());
+ }
+ }
+
+ for(final List<ArtifactId> versions : highest.values()) {
+ Collections.sort(versions, Comparator.reverseOrder());
+ for(int i=1; i<versions.size();i++) {
+ final ArtifactId id = versions.get(i);
+ classpathMapping.remove(id);
+ log.debug("Removing from javadoc classpath: " +
id.toMvnId());
+ }
+ }
+ }
+
+ // top
+ final List<String> classpath;
+ if ( javadocClasspathTops != null && !javadocClasspathTops.isEmpty()) {
+ log.debug("Using javadoc classpath tops:
".concat(javadocClasspathTops.toString()));
+ final IncludeExcludeMatcher matcher = new
IncludeExcludeMatcher(javadocClasspathTops, null, null, false);
+ final List<String> tops = new ArrayList<>();
+
+ final Iterator<Map.Entry<ArtifactId, String>> iter =
classpathMapping.entrySet().iterator();
+ while ( iter.hasNext() ) {
+ final Map.Entry<ArtifactId, String> entry = iter.next();
+ if ( matcher.matches(entry.getKey()) != null ) {
+ tops.add(0, entry.getValue());
+ iter.remove();
+ }
+ }
+ classpath = new ArrayList<>(classpathMapping.values());
+ for(final String path : tops) {
+ classpath.add(0, path);
+ }
+ } else {
+ classpath = new ArrayList<>(classpathMapping.values());
+ }
+
+// if ( log.isDebugEnabled() ) {
+
log.info("------------------------------------------------------------------");
+ log.info("Javadoc classpath: ");
+ for(final String cp : classpath) {
+ log.info("- " + cp);
+ }
+
log.info("------------------------------------------------------------------");
+ // }
+
return classpath;
}
- public static Set<String> buildJavadocClasspath(final Log log, final
RepositorySystem repositorySystem,
+ public static Map<ArtifactId, String> buildJavadocClasspath(final Log log,
final RepositorySystem repositorySystem,
final MavenSession mavenSession,
final ArtifactId artifactId)
throws MojoExecutionException {
- final Set<String> javadocClasspath = new HashSet<>();
+ final Map<ArtifactId, String> javadocClasspath = new HashMap<>();
log.debug("Retrieving " + artifactId + " and related dependencies...");
org.apache.maven.artifact.Artifact toBeResolvedArtifact =
repositorySystem.createArtifactWithClassifier(artifactId.getGroupId(),
@@ -275,7 +357,8 @@ public class ApisUtil {
for (org.apache.maven.artifact.Artifact resolvedArtifact :
result.getArtifacts()) {
if (resolvedArtifact.getFile() != null) {
log.debug("Adding to javadoc classpath " + resolvedArtifact);
-
javadocClasspath.add(resolvedArtifact.getFile().getAbsolutePath());
+ javadocClasspath.put(new
ArtifactId(resolvedArtifact.getGroupId(), resolvedArtifact.getArtifactId(),
resolvedArtifact.getVersion(), resolvedArtifact.getClassifier(),
resolvedArtifact.getType()),
+ resolvedArtifact.getFile().getAbsolutePath());
} else {
log.debug("Ignoring for javadoc classpath " +
resolvedArtifact);
}