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 9e61bd8 SLING-9416 : Use extension far for feature archives by default
9e61bd8 is described below
commit 9e61bd851a842beb63c4e3a6bc77cb89421928c3
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Fri May 1 14:59:24 2020 +0200
SLING-9416 : Use extension far for feature archives by default
---
.../apache/sling/feature/maven/mojos/Archive.java | 14 +++-
.../maven/mojos/AttachFeatureArchivesMojo.java | 97 +++++++++++-----------
2 files changed, 60 insertions(+), 51 deletions(-)
diff --git a/src/main/java/org/apache/sling/feature/maven/mojos/Archive.java
b/src/main/java/org/apache/sling/feature/maven/mojos/Archive.java
index 277d11d..8761107 100644
--- a/src/main/java/org/apache/sling/feature/maven/mojos/Archive.java
+++ b/src/main/java/org/apache/sling/feature/maven/mojos/Archive.java
@@ -21,8 +21,12 @@ package org.apache.sling.feature.maven.mojos;
*/
public class Archive extends FeatureSelectionConfig {
+ public static final String DEFAULT_EXTENSION = "far";
+
private String classifier;
+ private String type = DEFAULT_EXTENSION;
+
/**
* If this is set to {@code false} the archive is not added to the project
* artifacts.
@@ -37,9 +41,17 @@ public class Archive extends FeatureSelectionConfig {
this.classifier = classifier;
}
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String value) {
+ this.type = value;
+ }
+
@Override
public String toString() {
- return "Archive [classifier=" + classifier + ", getFilesExcludes()=" +
getFilesExcludes() + ", getSelections()="
+ return "Archive [classifier=" + classifier + ", type=" + type + ",
getFilesExcludes()=" + getFilesExcludes() + ", getSelections()="
+ getSelections() + ", attach()=" + attach + "]";
}
}
diff --git
a/src/main/java/org/apache/sling/feature/maven/mojos/AttachFeatureArchivesMojo.java
b/src/main/java/org/apache/sling/feature/maven/mojos/AttachFeatureArchivesMojo.java
index 14850f8..b972a24 100644
---
a/src/main/java/org/apache/sling/feature/maven/mojos/AttachFeatureArchivesMojo.java
+++
b/src/main/java/org/apache/sling/feature/maven/mojos/AttachFeatureArchivesMojo.java
@@ -29,7 +29,6 @@ import java.util.Map;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
-import java.util.zip.Deflater;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
@@ -54,52 +53,7 @@ import org.apache.sling.feature.maven.ProjectHelper;
)
public class AttachFeatureArchivesMojo extends AbstractIncludingFeatureMojo {
- private static final String EXTENSION = "zip";
-
- private static final String CLASSIFIER = "far";
-
- @Parameter
- private List<Archive> archives;
-
- @Override
- public void execute() throws MojoExecutionException, MojoFailureException {
- checkPreconditions();
- if (archives == null || archives.size() == 0) {
- // by default create an archive of each feature individually
- this.attachArchives(ProjectHelper.getFeatures(this.project));
- } else {
- for (final Archive archive : archives) {
- if (archive.getClassifier() == null) {
- throw new MojoExecutionException("Classifier is missing
for archive.");
- }
- final List<Feature> features = new ArrayList<>();
- features.addAll(this.getSelectedFeatures(archive).values());
- this.attachArchives(features, archive.getClassifier(),
archive.attach);
- }
- }
- }
-
- /**
- * Attach archives for all features
- *
- * @throws MojoExecutionException
- */
- void attachArchives(final Map<String, Feature> features) throws
MojoExecutionException {
- for (final Map.Entry<String, Feature> entry : features.entrySet()) {
- final boolean add;
- if (ProjectHelper.isAggregate(entry.getKey())) {
- add = ProjectHelper.isAttachAggregate(entry.getKey());
- } else {
- add = true;
- }
-
- if (add) {
- final String classifier =
entry.getValue().getId().getClassifier() == null ? CLASSIFIER
- :
entry.getValue().getId().getClassifier().concat(CLASSIFIER);
- attachArchives(Collections.singletonList(entry.getValue()),
classifier, true);
- }
- }
- }
+ private static final String DEFAULT_CLASSIFIER = "far";
public static final String ATTR_BUILT_BY = "Built-By";
@@ -121,6 +75,43 @@ public class AttachFeatureArchivesMojo extends
AbstractIncludingFeatureMojo {
public static final String ATTR_SPECIFICATION_VERSION =
"Specification-Version";
+ @Parameter
+ private List<Archive> archives;
+
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ checkPreconditions();
+ if (archives == null || archives.size() == 0) {
+ // by default create an archive of each feature individually
+ for (final Map.Entry<String, Feature> entry :
ProjectHelper.getFeatures(this.project).entrySet()) {
+ final boolean add;
+ if (ProjectHelper.isAggregate(entry.getKey())) {
+ add = ProjectHelper.isAttachAggregate(entry.getKey());
+ } else {
+ add = true;
+ }
+
+ if (add) {
+ final String classifier =
entry.getValue().getId().getClassifier() == null ? DEFAULT_CLASSIFIER
+ :
entry.getValue().getId().getClassifier().concat(DEFAULT_CLASSIFIER);
+ createArchive(Collections.singletonList(entry.getValue()),
classifier, Archive.DEFAULT_EXTENSION, true);
+ }
+ }
+ } else {
+ for (final Archive archive : archives) {
+ if (archive.getClassifier() == null) {
+ throw new MojoExecutionException("Classifier is missing
for archive.");
+ }
+ if (archive.getType() == null) {
+ throw new MojoExecutionException("Type is missing for
archive.");
+ }
+ final List<Feature> features = new ArrayList<>();
+ features.addAll(this.getSelectedFeatures(archive).values());
+ this.createArchive(features, archive.getClassifier(),
archive.getType(), archive.attach);
+ }
+ }
+ }
+
private Manifest createBaseManifest(final Feature feature) {
final Manifest mf = new Manifest();
mf.getMainAttributes().putValue("Implementation-Build",
project.getVersion());
@@ -146,8 +137,15 @@ public class AttachFeatureArchivesMojo extends
AbstractIncludingFeatureMojo {
return mf;
}
- private void attachArchives(final List<Feature> features, final String
classifier, final boolean attach) throws MojoExecutionException {
- final ArtifactId archiveId =
features.get(0).getId().changeClassifier(classifier).changeType(EXTENSION);
+ /**
+ * Create feature archive
+ * @param features The features contained in the archive
+ * @param classifier The classifier to use for the archive
+ * @param type The type to use for the archive
+ * @param attach Whether the archive should be attached to the project
+ */
+ private void createArchive(final List<Feature> features, final String
classifier, final String type, final boolean attach) throws
MojoExecutionException {
+ final ArtifactId archiveId =
features.get(0).getId().changeClassifier(classifier).changeType(type);
// write the feature model archive
final File outputFile = new File(
@@ -171,7 +169,6 @@ public class AttachFeatureArchivesMojo extends
AbstractIncludingFeatureMojo {
, features.toArray(new Feature[features.size()]))) {
// handle license etc.
- jos.setLevel(Deflater.BEST_COMPRESSION);
final File classesDir = new
File(this.project.getBuild().getOutputDirectory());
if ( classesDir.exists() ) {
final File metaInfDir = new File(classesDir, "META-INF");