in src/main/java/org/apache/sling/feature/maven/mojos/apis/ApisUtil.java [219:322]
public static Collection<String> getJavadocClassPath(
final Log log,
final RepositorySystem repositorySystem,
final MavenSession mavenSession,
final ApisJarContext ctx,
final String regionName)
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(regionName, false)) {
final String ids = info.getArtifact().getMetadata().get(ApisUtil.JAVADOC_CLASSPATH);
if (ids != null) {
for (final String s : ids.split(",")) {
try {
final ArtifactId cpId = ArtifactId.parse(s.trim());
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 (!ctx.getConfig().getJavadocClasspathRemovals().isEmpty()) {
log.debug("Using javadoc classpath removal: "
.concat(ctx.getConfig().getJavadocClasspathRemovals().toString()));
final IncludeExcludeMatcher matcher =
new IncludeExcludeMatcher(ctx.getConfig().getJavadocClasspathRemovals(), 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 (!ctx.getConfig().getJavadocClasspathHighestVersions().isEmpty()) {
log.debug("Using javadoc classpath highest versions: "
.concat(ctx.getConfig().getJavadocClasspathHighestVersions().toString()));
final IncludeExcludeMatcher matcher =
new IncludeExcludeMatcher(ctx.getConfig().getJavadocClasspathHighestVersions(), 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 (!ctx.getConfig().getJavadocClasspathTops().isEmpty()) {
log.debug("Using javadoc classpath tops: "
.concat(ctx.getConfig().getJavadocClasspathTops().toString()));
final IncludeExcludeMatcher matcher =
new IncludeExcludeMatcher(ctx.getConfig().getJavadocClasspathTops(), 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.debug("------------------------------------------------------------------");
log.debug("Javadoc classpath: ");
for (final String cp : classpath) {
log.debug("- " + cp);
}
log.debug("------------------------------------------------------------------");
}
return classpath;
}