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 8acf654 SLING-9617 : Allow to specify api generation parameters
through feature extension
8acf654 is described below
commit 8acf654eeb9eaff831ddfca5b1787beaab768163
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Wed Jul 29 13:54:35 2020 +0200
SLING-9617 : Allow to specify api generation parameters through feature
extension
---
.../sling/feature/maven/mojos/ApisJarMojo.java | 95 +++--
.../maven/mojos/apis/ApisConfiguration.java | 404 +++++++++++++++++++++
.../feature/maven/mojos/apis/ApisJarContext.java | 24 +-
.../sling/feature/maven/mojos/apis/ApisUtil.java | 23 +-
.../feature/maven/mojos/apis/JavadocLinks.java | 10 +-
5 files changed, 470 insertions(+), 86 deletions(-)
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 301a4f4..4383db3 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
@@ -84,7 +84,6 @@ import
org.apache.sling.feature.extension.apiregions.api.ApiExport;
import org.apache.sling.feature.extension.apiregions.api.ApiRegion;
import org.apache.sling.feature.extension.apiregions.api.ApiRegions;
import org.apache.sling.feature.io.IOUtils;
-import org.apache.sling.feature.maven.ProjectHelper;
import org.apache.sling.feature.maven.mojos.apis.ApisJarContext;
import org.apache.sling.feature.maven.mojos.apis.ApisJarContext.ArtifactInfo;
import org.apache.sling.feature.maven.mojos.apis.ApisUtil;
@@ -419,32 +418,6 @@ public class ApisJarMojo extends
AbstractIncludingFeatureMojo {
}
/**
- * Apply region name mapping if configured
- *
- * @param regionName The region name
- * @return The mapped name or the original name
- */
- private String mapApiRegionName(final String regionName) {
- if (this.apiRegionNameMappings != null &&
this.apiRegionNameMappings.containsKey(regionName)) {
- return this.apiRegionNameMappings.get(regionName);
- }
- return regionName;
- }
-
- /**
- * Apply classifier mapping if configured
- *
- * @param classifier The classifier
- * @return The mapped classifier or the original classifier
- */
- private String mapApiClassifier(final String classifier) {
- if (this.apiClassifierMappings != null &&
this.apiClassifierMappings.containsKey(classifier)) {
- return this.apiClassifierMappings.get(classifier);
- }
- return classifier;
- }
-
- /**
* Check if the region is included
*
* @param name The region name
@@ -554,8 +527,24 @@ public class ApisJarMojo extends
AbstractIncludingFeatureMojo {
// create an output directory per feature
final File featureDir = new File(mainOutputDir,
feature.getId().getArtifactId());
- final ApisJarContext ctx = new ApisJarContext(this.mainOutputDir,
feature.getId(), regions);
- ctx.setLicenseDefaults(licenseDefaults);
+ final ApisJarContext ctx = new ApisJarContext(this.mainOutputDir,
feature, regions);
+ ctx.getConfig().setLicenseDefaults(this.licenseDefaults);
+ ctx.getConfig().setLicenseReport(this.licenseReport);
+ ctx.getConfig().setLicenseReportHeader(this.licenseReportHeader);
+ ctx.getConfig().setLicenseReportFooter(this.licenseReportFooter);
+ ctx.getConfig().setJavadocLinks(this.javadocLinks);
+
ctx.getConfig().setJavadocClasspathRemovals(this.javadocClasspathRemovals);
+
ctx.getConfig().setJavadocClasspathHighestVersions(this.javadocClasspathHighestVersions);
+ ctx.getConfig().setJavadocClasspathTops(this.javadocClasspathTops);
+ ctx.getConfig().setApiVersion(this.apiVersion);
+ ctx.getConfig().setJavadocSourceLevel(this.javadocSourceLevel);
+ ctx.getConfig().setBundleResourceFolders(this.resourceFolders);
+ ctx.getConfig().setBundleResources(this.includeResources);
+ ctx.getConfig().setClassifierMappings(apiClassifierMappings);
+ ctx.getConfig().setRegionMappings(apiRegionNameMappings);
+ ctx.getConfig().setManifestEntries(manifestProperties);
+ ctx.getConfig().logConfiguration(getLog());
+
ctx.setDependencyRepositories(this.apiRepositoryUrls);
// for each bundle included in the feature file and record directories
@@ -604,7 +593,7 @@ public class ApisJarMojo extends
AbstractIncludingFeatureMojo {
final File javadocsDir = new File(regionDir,
ArtifactType.JAVADOC.getId());
final ExecutionEnvironmentExtension ext =
ExecutionEnvironmentExtension.getExecutionEnvironmentExtension(feature);
final JavadocLinks links = new JavadocLinks();
- links.calculateLinks(this.javadocLinks,
ctx.getArtifactInfos(apiRegion, false), ext != null ? ext.getFramework() :
null);
+ links.calculateLinks(ctx.getConfig().getJavadocLinks(),
ctx.getArtifactInfos(apiRegion, false), ext != null ? ext.getFramework() :
null);
final Collection<ArtifactInfo> infos = generateJavadoc(ctx,
apiRegion, links, javadocsDir);
if ( infos != null ) {
@@ -650,7 +639,7 @@ public class ApisJarMojo extends
AbstractIncludingFeatureMojo {
final List<String> report,
final JavadocLinks links)
throws MojoExecutionException {
- final Map.Entry<Set<String>, Set<String>> packageResult =
getPackages(jarFile, artifactType.getContentExtension());
+ final Map.Entry<Set<String>, Set<String>> packageResult =
getPackages(ctx, jarFile, artifactType.getContentExtension());
final Set<String> apiPackages = packageResult.getKey();
final Set<String> otherPackages = packageResult.getValue();
if ( omitDependencyArtifacts ) {
@@ -966,16 +955,15 @@ public class ApisJarMojo extends
AbstractIncludingFeatureMojo {
private List<String> getIncludeResourcePatterns(final ApisJarContext ctx,
final ArtifactId id) {
final List<String> pattern = new ArrayList<>();
- if ( includeResources != null ) {
- for(final String folder : this.resourceFolders.split(",")) {
- for(final String inc : this.includeResources) {
- pattern.add(folder.trim().concat("/").concat(inc));
- }
+ for(final String folder : ctx.getConfig().getBundleResourceFolders()) {
+ for(final String inc : ctx.getConfig().getBundleResources()) {
+ pattern.add(folder.concat("/").concat(inc));
}
}
+
// add NOTICE and LICENSE for license report
- if ( this.licenseReport != null ) {
- final String licenseDefault = ctx.getLicenseDefault(id);
+ if ( ctx.getConfig().getLicenseReport() != null ) {
+ final String licenseDefault =
ctx.getConfig().getLicenseDefault(id);
if ( licenseDefault == null || !licenseDefault.isEmpty() ) {
pattern.add("META-INF/NOTICE");
pattern.add("META-INF/LICENSE");
@@ -1548,9 +1536,9 @@ public class ApisJarMojo extends
AbstractIncludingFeatureMojo {
}
// check for license report
- if ( this.licenseReport != null ) {
+ if ( ctx.getConfig().getLicenseReport() != null ) {
final File out = this.createLicenseReport(ctx, apiRegion, infos,
report);
- jarArchiver.addFile(out, this.licenseReport);
+ jarArchiver.addFile(out, ctx.getConfig().getLicenseReport());
}
final ArtifactId targetId = this.buildArtifactId(ctx, apiRegion,
archiveType);
@@ -1594,7 +1582,7 @@ public class ApisJarMojo extends
AbstractIncludingFeatureMojo {
}
// replace/add manifest entries with the one provided in
manifestProperties configuration
-
archiveConfiguration.addManifestEntries(ProjectHelper.propertiesToMap(manifestProperties));
+
archiveConfiguration.addManifestEntries(ctx.getConfig().getManifestEntries());
final File target = new File(mainOutputDir, targetId.toMvnName());
MavenArchiver archiver = new MavenArchiver();
@@ -1618,17 +1606,17 @@ public class ApisJarMojo extends
AbstractIncludingFeatureMojo {
private ArtifactId buildArtifactId(final ApisJarContext ctx, final
ApiRegion apiRegion, final ArtifactType artifactType) {
final StringBuilder classifierBuilder = new StringBuilder();
if (ctx.getFeatureId().getClassifier() != null) {
-
classifierBuilder.append(mapApiClassifier(ctx.getFeatureId().getClassifier()))
+
classifierBuilder.append(ctx.getConfig().mapApiClassifier(ctx.getFeatureId().getClassifier()))
.append('-');
}
- final String finalClassifier =
classifierBuilder.append(mapApiRegionName(apiRegion.getName()))
+ final String finalClassifier =
classifierBuilder.append(ctx.getConfig().mapApiRegionName(apiRegion.getName()))
.append('-')
.append(artifactType.getId())
.toString();
return new ArtifactId(this.project.getGroupId(),
this.project.getArtifactId(),
- this.apiVersion != null ? this.apiVersion :
this.project.getVersion(),
+ ctx.getConfig().getApiVersion() != null ?
ctx.getConfig().getApiVersion() : this.project.getVersion(),
finalClassifier,
artifactType.getExtension());
}
@@ -1723,9 +1711,9 @@ public class ApisJarMojo extends
AbstractIncludingFeatureMojo {
.addArgument(String.join(File.pathSeparator, sourceDirectories));
javadocExecutor.addArgument("-source", false)
- .addArgument(javadocSourceLevel);
+ .addArgument(ctx.getConfig().getJavadocSourceLevel());
- final String versionSuffix = this.apiVersion != null ? this.apiVersion
: ctx.getFeatureId().getVersion();
+ final String versionSuffix = ctx.getConfig().getApiVersion() != null ?
ctx.getConfig().getApiVersion() : ctx.getFeatureId().getVersion();
if (!StringUtils.isBlank(project.getName())) {
javadocExecutor.addArgument("-doctitle", false)
@@ -1753,7 +1741,7 @@ public class ApisJarMojo extends
AbstractIncludingFeatureMojo {
// classpath
final Collection<String> classpath =
ApisUtil.getJavadocClassPath(getLog(), repositorySystem, mavenSession,
- ctx, region, this.javadocClasspathRemovals,
this.javadocClasspathHighestVersions, this.javadocClasspathTops);
+ ctx, region);
if (!classpath.isEmpty()) {
javadocExecutor.addArgument("-classpath", false)
.addArgument(classpath, File.pathSeparator);
@@ -1786,12 +1774,12 @@ public class ApisJarMojo extends
AbstractIncludingFeatureMojo {
* @return A tuple of packages containing files with the extension and
packages with files not having the extension
* @throws MojoExecutionException
*/
- private Map.Entry<Set<String>, Set<String>> getPackages(final File file,
final String extension) throws MojoExecutionException {
+ private Map.Entry<Set<String>, Set<String>> getPackages(final
ApisJarContext ctx, final File file, final String extension) throws
MojoExecutionException {
final Set<String> packages = new TreeSet<>();
final Set<String> otherPackages = new TreeSet<>();
final Set<String> excludes = new HashSet<>();
- for(final String v : resourceFolders.split(",")) {
+ for(final String v : ctx.getConfig().getBundleResourceFolders()) {
excludes.add(v.concat("/"));
}
@@ -1838,10 +1826,11 @@ public class ApisJarMojo extends
AbstractIncludingFeatureMojo {
if ( !out.exists() ) {
final List<String> output = new ArrayList<>();
- output.add(licenseReportHeader);
+
+ output.add(ctx.getConfig().getLicenseReportHeader());
output.add("");
for(final ArtifactInfo info : infos) {
- final String licenseDefault =
ctx.getLicenseDefault(info.getId());
+ final String licenseDefault =
ctx.getConfig().getLicenseDefault(info.getId());
final StringBuilder sb = new
StringBuilder(info.getId().toMvnId());
boolean exclude = false;
@@ -1870,9 +1859,9 @@ public class ApisJarMojo extends
AbstractIncludingFeatureMojo {
output.add(sb.toString());
}
}
- if ( this.licenseReportFooter != null ) {
+ if ( ctx.getConfig().getLicenseReportFooter() != null ) {
output.add("");
- output.add(this.licenseReportFooter);
+ output.add(ctx.getConfig().getLicenseReportFooter());
}
try {
Files.write(out.toPath(), output);
diff --git
a/src/main/java/org/apache/sling/feature/maven/mojos/apis/ApisConfiguration.java
b/src/main/java/org/apache/sling/feature/maven/mojos/apis/ApisConfiguration.java
new file mode 100644
index 0000000..4a0a5e6
--- /dev/null
+++
b/src/main/java/org/apache/sling/feature/maven/mojos/apis/ApisConfiguration.java
@@ -0,0 +1,404 @@
+/*
+ * 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.
+ */
+package org.apache.sling.feature.maven.mojos.apis;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.json.JsonArray;
+import javax.json.JsonObject;
+import javax.json.JsonString;
+import javax.json.JsonValue;
+import javax.json.JsonValue.ValueType;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.sling.feature.ArtifactId;
+import org.apache.sling.feature.Extension;
+import org.apache.sling.feature.ExtensionType;
+import org.apache.sling.feature.Feature;
+import org.apache.sling.feature.maven.ProjectHelper;
+import org.apache.sling.feature.maven.mojos.selection.IncludeExcludeMatcher;
+
+/**
+ * Configuration for creating the api jars.
+ *
+ * The configuration can be controlled by a JSON extension:
+ * <pre>
+ * {
+ * "license-report" : "PATH",
+ * "license-header" : "STRING or STRING ARRAY",
+ * "license-footer" : "STRING or STRING ARRAY",
+ * "license-defaults" : ["PATTERN", "PATTERN"],
+ * "javadoc-links" : ["LINK", "LINK"],
+ * "javadoc-classpath-removals" : ["LINK", "LINK"],
+ * "javadoc-classpath-highest-versions" : ["LINK", "LINK"],
+ * "javadoc-classpath-tops" : ["LINK", "LINK"],
+ * "javadoc-source-level" : "STRING",
+ * "api-version" : "STRING",
+ * "bundle-resource-folders" : ["STRING", "STRING"],
+ * "bundle-resources" : ["STRING", "STRING"],
+ * "region-mapping" : {
+ * "REGION" : "MAPPED_NAME"
+ * },
+ * "classifier-mapping" : {
+ * "CLASSIFIER" : "MAPPED_NAME"
+ * },
+ * "manifest-entries" : {
+ * "key" : "value"
+ * }
+ * }
+ * </pre>
+ */
+public class ApisConfiguration {
+
+ private static final String EXTENSION_NAME = "apis-jar-config";
+
+ private static final String PROP_LICENSE_REPORT = "license-report";
+
+ private static final String PROP_MANIFEST_ENTRIES = "manifest-entries";
+
+ private static final String PROP_CLASSIFIER_MAPPINGS =
"classifier-mappings";
+
+ private static final String PROP_REGION_MAPPINGS = "region-mappings";
+
+ private static final String PROP_BUNDLE_RESOURCES = "bundle-resources";
+
+ private static final String PROP_BUNDLE_RESOURCE_FOLDERS =
"bundle-resource-folders";
+
+ private static final String PROP_API_VERSION = "api-version";
+
+ private static final String PROP_JAVADOC_SOURCE_LEVEL =
"javadoc-source-level";
+
+ private static final String PROP_JAVADOC_CLASSPATH_TOPS =
"javadoc-classpath-tops";
+
+ private static final String PROP_JAVADOC_CLASSPATH_HIGHEST_VERSIONS =
"javadoc-classpath-highest-versions";
+
+ private static final String PROP_JAVADOC_CLASSPATH_REMOVALS =
"javadoc-classpath-removals";
+
+ private static final String PROP_JAVADOC_LINKS = "javadoc-links";
+
+ private static final String PROP_LICENSE_DEFAULTS = "license-defaults";
+
+ private static final String PROP_LICENSE_FOOTER = "license-footer";
+
+ private static final String PROP_LICENSE_HEADER = "license-header";
+
+
+
+ private String licenseReport;
+
+ private final List<String> licenseDefaults = new ArrayList<>();
+
+ private String licenseReportHeader;
+
+ private String licenseReportFooter;
+
+ private final List<String> javadocLinks = new ArrayList<>();
+
+ private final List<String> javadocClasspathRemovals = new ArrayList<>();
+
+ private final List<String> javadocClasspathHighestVersions = new
ArrayList<>();
+
+ private final List<String> javadocClasspathTops = new ArrayList<>();
+
+ private String javadocSourceLevel;
+
+ private String apiVersion;
+
+ private final List<String> bundleResourceFolders = new ArrayList<>();
+
+ private final List<String> bundleResources = new ArrayList<>();
+
+ private final Map<String, String> regionMappings = new HashMap<>();
+
+ private final Map<String, String> classifierMappings = new HashMap<>();
+
+ private final Map<String, String> manifestEntries = new HashMap<>();
+
+ public ApisConfiguration(final Feature feature) throws
MojoExecutionException {
+ // check for extension
+ final Extension ext =
feature.getExtensions().getByName(EXTENSION_NAME);
+ if ( ext != null ) {
+ if ( ext.getType() != ExtensionType.JSON) {
+ throw new MojoExecutionException("Invalid extension type for "
+ ext.getName() + " : " + ext.getType());
+ }
+ final JsonObject json = ext.getJSONStructure().asJsonObject();
+ this.licenseReport = json.getString(PROP_LICENSE_REPORT, null);
+ this.licenseReportHeader = getStringOrArray(json,
PROP_LICENSE_HEADER);
+ this.licenseReportFooter = getStringOrArray(json,
PROP_LICENSE_FOOTER);
+ add(this.licenseDefaults, json, PROP_LICENSE_DEFAULTS);
+
+ add(this.javadocLinks, json, PROP_JAVADOC_LINKS);
+
+ add(this.javadocClasspathRemovals, json,
PROP_JAVADOC_CLASSPATH_REMOVALS);
+ add(this.javadocClasspathHighestVersions, json,
PROP_JAVADOC_CLASSPATH_HIGHEST_VERSIONS);
+ add(this.javadocClasspathTops, json, PROP_JAVADOC_CLASSPATH_TOPS);
+
+ this.javadocSourceLevel =
json.getString(PROP_JAVADOC_SOURCE_LEVEL, null);
+ this.apiVersion = json.getString(PROP_API_VERSION, null);
+
+ add(this.bundleResourceFolders, json,
PROP_BUNDLE_RESOURCE_FOLDERS);
+ add(this.bundleResources, json, PROP_BUNDLE_RESOURCES);
+
+ add(this.regionMappings, json, PROP_REGION_MAPPINGS);
+ add(this.classifierMappings, json, PROP_CLASSIFIER_MAPPINGS);
+ add(this.manifestEntries, json, PROP_MANIFEST_ENTRIES);
+ }
+ }
+
+ public void logConfiguration(final Log log) {
+ if ( log.isInfoEnabled() ) {
+ log.info("Using configuration:");
+ log.info("- " + PROP_JAVADOC_SOURCE_LEVEL + " : " +
this.javadocSourceLevel);
+ log.info("- " + PROP_JAVADOC_LINKS + " : " + this.javadocLinks);
+ log.info("- " + PROP_API_VERSION + " : " + this.apiVersion);
+ log.info("- " + PROP_BUNDLE_RESOURCE_FOLDERS + " : " +
this.bundleResourceFolders);
+ log.info("- " + PROP_BUNDLE_RESOURCES + " : " +
this.bundleResources);
+ log.info("- " + PROP_REGION_MAPPINGS + " : " +
this.regionMappings);
+ log.info("- " + PROP_CLASSIFIER_MAPPINGS + " : " +
this.classifierMappings);
+ log.info("- " + PROP_JAVADOC_CLASSPATH_REMOVALS + " : " +
this.javadocClasspathRemovals);
+ log.info("- " + PROP_JAVADOC_CLASSPATH_HIGHEST_VERSIONS + " : " +
this.javadocClasspathHighestVersions);
+ log.info("- " + PROP_JAVADOC_CLASSPATH_TOPS + " : " +
this.javadocClasspathTops);
+ log.info("- " + PROP_MANIFEST_ENTRIES + " : " +
this.manifestEntries);
+ log.info("- " + PROP_LICENSE_REPORT + " : " + this.licenseReport);
+ log.info("- " + PROP_LICENSE_DEFAULTS + " : " +
this.licenseDefaults);
+ log.info("- " + PROP_LICENSE_HEADER + " : " +
this.licenseReportHeader);
+ log.info("- " + PROP_LICENSE_FOOTER + " : " +
this.licenseReportFooter);
+ }
+ }
+
+ private String getStringOrArray(final JsonObject json, final String
propName) {
+ String result = null;
+ final JsonValue val = json.containsKey(propName) ? json.get(propName)
: null;
+ if ( val != null ) {
+ if ( val.getValueType() == ValueType.ARRAY ) {
+ final StringBuilder sb = new StringBuilder();
+ for(final JsonValue v : val.asJsonArray()) {
+ sb.append(v);
+ sb.append('\n');
+ }
+ result = sb.toString();
+ } else {
+ result = ((JsonString)val).getString();
+ }
+ }
+ return result;
+ }
+
+ private void add(final List<String> list, final JsonObject json, final
String propName) {
+ final JsonArray array = json.containsKey(propName) ?
json.getJsonArray(propName) : null;
+ if ( array != null ) {
+ for(final JsonValue val : array) {
+ list.add(((JsonString)val).getString());
+ }
+ }
+ }
+
+ private void add(final Map<String, String> map, final JsonObject json,
final String propName) {
+ final JsonObject obj = json.containsKey(propName) ?
json.getJsonObject(propName) : null;
+ if ( obj != null ) {
+ for(final Map.Entry<String, JsonValue> entry : obj.entrySet()) {
+ map.put(entry.getKey(),
((JsonString)entry.getValue()).getString());
+ }
+ }
+ }
+
+ public List<String> getBundleResources() {
+ return bundleResources;
+ }
+
+ public List<String> getJavadocLinks() {
+ return javadocLinks;
+ }
+
+ public String getJavadocSourceLevel() {
+ return javadocSourceLevel;
+ }
+
+ public String getApiVersion() {
+ return apiVersion;
+ }
+
+ public List<String> getBundleResourceFolders() {
+ return bundleResourceFolders;
+ }
+
+ public String getLicenseReport() {
+ return licenseReport;
+ }
+
+ public List<String> getLicenseDefaults() {
+ return licenseDefaults;
+ }
+
+ public String getLicenseReportHeader() {
+ return licenseReportHeader;
+ }
+
+ public String getLicenseReportFooter() {
+ return licenseReportFooter;
+ }
+
+ public Map<String, String> getManifestEntries() {
+ return manifestEntries;
+ }
+
+ public List<String> getJavadocClasspathRemovals() {
+ return javadocClasspathRemovals;
+ }
+
+ public List<String> getJavadocClasspathHighestVersions() {
+ return javadocClasspathHighestVersions;
+ }
+
+ public List<String> getJavadocClasspathTops() {
+ return javadocClasspathTops;
+ }
+
+ private IncludeExcludeMatcher licenseDefaultMatcher;
+
+ /**
+ * Apply region name mapping if configured
+ *
+ * @param regionName The region name
+ * @return The mapped name or the original name
+ */
+ public String mapApiRegionName(final String regionName) {
+ if (this.regionMappings.containsKey(regionName)) {
+ return this.regionMappings.get(regionName);
+ }
+ return regionName;
+ }
+
+ /**
+ * Apply classifier mapping if configured
+ *
+ * @param classifier The classifier
+ * @return The mapped classifier or the original classifier
+ */
+ public String mapApiClassifier(final String classifier) {
+ if (this.classifierMappings.containsKey(classifier)) {
+ return this.classifierMappings.get(classifier);
+ }
+ return classifier;
+ }
+
+ public String getLicenseDefault(final ArtifactId id) {
+ return this.licenseDefaultMatcher.matches(id);
+ }
+
+ public void setLicenseDefaults(final List<String>
licenseDefaultsFromProjcect) throws MojoExecutionException {
+ if ( this.licenseDefaults.isEmpty() && licenseDefaultsFromProjcect !=
null ) {
+ this.licenseDefaults.addAll(licenseDefaultsFromProjcect);
+ }
+ this.licenseDefaultMatcher = new
IncludeExcludeMatcher(this.licenseDefaults, null, "=", true);
+ }
+
+ public void setLicenseReport(final String licenseReportFromProjcect) {
+ if ( this.licenseReport == null ) {
+ this.licenseReport = licenseReportFromProjcect;
+ }
+ }
+
+ public void setLicenseReportHeader(final String
licenseReportHeaderFromProjcect) {
+ if ( this.licenseReportHeader == null ) {
+ this.licenseReportHeader = licenseReportHeaderFromProjcect;
+ }
+ }
+
+ public void setLicenseReportFooter(final String
licenseReportFooterFromProjcect) {
+ if ( this.licenseReportFooter == null ) {
+ this.licenseReportFooter = licenseReportFooterFromProjcect;
+ }
+ }
+
+ public void setJavadocLinks(final String[] javadocLinksFromProject) {
+ if ( this.javadocLinks.isEmpty() && javadocLinksFromProject != null ) {
+ for(final String v : javadocLinksFromProject) {
+ this.javadocLinks.add(v);
+ }
+ }
+ }
+
+ public void setJavadocClasspathRemovals(final List<String>
javadocClasspathRemovalsFromProject) {
+ if ( this.javadocClasspathRemovals.isEmpty() &&
javadocClasspathRemovalsFromProject != null ) {
+
this.javadocClasspathRemovals.addAll(javadocClasspathRemovalsFromProject);
+ }
+ }
+
+ public void setJavadocClasspathHighestVersions(final List<String>
javadocClasspathHighestVersionsFromProject) {
+ if ( this.javadocClasspathHighestVersions.isEmpty() &&
javadocClasspathHighestVersionsFromProject != null ) {
+
this.javadocClasspathHighestVersions.addAll(javadocClasspathHighestVersionsFromProject);
+ }
+ }
+
+ public void setJavadocClasspathTops(final List<String>
javadocClasspathTopsFromProject) {
+ if ( this.javadocClasspathTops.isEmpty() &&
javadocClasspathTopsFromProject != null ) {
+ this.javadocClasspathTops.addAll(javadocClasspathTopsFromProject);
+ }
+ }
+
+ public void setJavadocSourceLevel(final String
javadocSourceLevelFromProject) {
+ if ( this.javadocSourceLevel == null ) {
+ this.javadocSourceLevel = javadocSourceLevelFromProject;
+ }
+ }
+
+ public void setApiVersion(final String apiVersionFromProject) {
+ if ( this.apiVersion == null ) {
+ this.apiVersion = apiVersionFromProject;
+ }
+ }
+
+ public void setBundleResources(final String[] includeResourcesFromProject)
{
+ if ( this.bundleResources.isEmpty() && includeResourcesFromProject !=
null ) {
+ for(final String v : includeResourcesFromProject) {
+ this.bundleResources.add(v);
+ }
+ }
+ }
+
+ public void setBundleResourceFolders(final String
resourceFoldersFromProject) {
+ if ( this.bundleResourceFolders.isEmpty() &&
resourceFoldersFromProject != null ) {
+ for(final String v : resourceFoldersFromProject.split(",")) {
+ this.bundleResourceFolders.add(v.trim());
+ }
+ }
+ }
+
+ public void setRegionMappings(final Map<String, String> valuesFromProject)
{
+ if ( this.regionMappings.isEmpty() && valuesFromProject != null ) {
+ this.regionMappings.putAll(valuesFromProject);
+ }
+ }
+
+ public void setClassifierMappings(final Map<String, String>
valuesFromProject) {
+ if ( this.classifierMappings.isEmpty() && valuesFromProject != null ) {
+ this.classifierMappings.putAll(valuesFromProject);
+ }
+ }
+
+ public void setManifestEntries(final Properties valuesFromProject) {
+ if ( this.manifestEntries.isEmpty() && valuesFromProject != null ) {
+
this.manifestEntries.putAll(ProjectHelper.propertiesToMap(valuesFromProject));
+ }
+ }
+}
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 f0865a8..9abe9ae 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
@@ -36,9 +36,9 @@ import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.apache.sling.feature.Artifact;
import org.apache.sling.feature.ArtifactId;
+import org.apache.sling.feature.Feature;
import org.apache.sling.feature.extension.apiregions.api.ApiRegion;
import org.apache.sling.feature.extension.apiregions.api.ApiRegions;
-import org.apache.sling.feature.maven.mojos.selection.IncludeExcludeMatcher;
/**
* Context for creating the api jars
@@ -209,6 +209,8 @@ public class ApisJarContext {
}
}
+ private final ApisConfiguration config;
+
private final Map<ArtifactId, String> javadocClasspath = new HashMap<>();
private final Set<String> packagesWithoutJavaClasses = new HashSet<>();
@@ -231,13 +233,12 @@ public class ApisJarContext {
private final Map<ArtifactId, Model> modelCache = new HashMap<>();
- private IncludeExcludeMatcher licenseDefaultMatcher;
-
/** The set of dependency repositories (URLs) */
private Set<String> dependencyRepositories = new HashSet<>();
- public ApisJarContext(final File mainDir, final ArtifactId featureId,
final ApiRegions regions) {
- this.featureId = featureId;
+ public ApisJarContext(final File mainDir, final Feature feature, final
ApiRegions regions) throws MojoExecutionException {
+ this.config = new ApisConfiguration(feature);
+ this.featureId = feature.getId();
// deflated and source dirs can be shared
this.deflatedBinDir = new File(mainDir, "deflated-bin");
@@ -246,6 +247,10 @@ public class ApisJarContext {
this.apiRegions = regions;
}
+ public ApisConfiguration getConfig() {
+ return this.config;
+ }
+
public ArtifactId getFeatureId() {
return featureId;
}
@@ -317,15 +322,6 @@ public class ApisJarContext {
return result.values();
}
-
- public void setLicenseDefaults(final List<String> licenseDefaults) throws
MojoExecutionException {
- this.licenseDefaultMatcher = new
IncludeExcludeMatcher(licenseDefaults, null, "=", true);
- }
-
- public String getLicenseDefault(final ArtifactId id) {
- return this.licenseDefaultMatcher.matches(id);
- }
-
/**
* Set the dependency repositories
* @param list Comma separated list or {@code null}
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 dbd1340..65b4c86 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
@@ -193,10 +193,7 @@ public class ApisUtil {
final RepositorySystem repositorySystem,
final MavenSession mavenSession,
final ApisJarContext ctx,
- final ApiRegion region,
- final List<String> javadocClasspathRemovals,
- final List<String> javadocClasspathHighestVersions,
- final List<String> javadocClasspathTops) throws
MojoExecutionException {
+ final ApiRegion region) throws MojoExecutionException {
// classpath - reverse order to have highest versions first
final Map<ArtifactId, String> classpathMapping = new
TreeMap<>(Comparator.reverseOrder());
classpathMapping.putAll(ctx.getJavadocClasspath());
@@ -218,9 +215,9 @@ public class ApisUtil {
// 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);
+ 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();
@@ -232,9 +229,9 @@ public class ApisUtil {
}
// 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);
+ 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 ) {
@@ -255,9 +252,9 @@ public class ApisUtil {
// 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);
+ 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();
diff --git
a/src/main/java/org/apache/sling/feature/maven/mojos/apis/JavadocLinks.java
b/src/main/java/org/apache/sling/feature/maven/mojos/apis/JavadocLinks.java
index dca3f53..53fea5e 100644
--- a/src/main/java/org/apache/sling/feature/maven/mojos/apis/JavadocLinks.java
+++ b/src/main/java/org/apache/sling/feature/maven/mojos/apis/JavadocLinks.java
@@ -33,17 +33,15 @@ public class JavadocLinks {
private final Set<String> docLinks = new HashSet<>();
- public void calculateLinks(final String[] globalJavaDocLinks,
+ public void calculateLinks(final List<String> globalJavaDocLinks,
final Collection<ArtifactInfo> infos,
final Artifact framework) throws MojoExecutionException {
final Map<String, Set<String>> linkedPackagesMap = new HashMap<>();
this.docLinks.clear();
this.linkedGlobalPackages.clear();
- if ( globalJavaDocLinks != null ) {
- for(final String val : globalJavaDocLinks) {
- docLinks.add(val);
- ApisUtil.getPackageList(val, linkedGlobalPackages,
linkedPackagesMap);
- }
+ for(final String val : globalJavaDocLinks) {
+ docLinks.add(val);
+ ApisUtil.getPackageList(val, linkedGlobalPackages,
linkedPackagesMap);
}
for(final ArtifactInfo info : infos) {
final List<String> links =
ApisUtil.getJavadocLinks(info.getArtifact());