You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2018/11/04 17:25:12 UTC

[sling-slingfeature-maven-plugin] branch master updated: SLING-8058 : Make configuration of slingfeature-maven-plugin consistent

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 f635b58  SLING-8058 : Make configuration of slingfeature-maven-plugin consistent
f635b58 is described below

commit f635b5810bd349eebe809fcabb9a23fbc507c1cd
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Sun Nov 4 18:25:01 2018 +0100

    SLING-8058 : Make configuration of slingfeature-maven-plugin consistent
---
 .../maven/mojos/AbstractIncludingFeatureMojo.java  | 158 +++++++++++++++++++++
 .../sling/feature/maven/mojos/AggregateConfig.java |  44 ++++++
 .../maven/mojos/FeatureSelectionConfig.java        |  66 +++++++++
 3 files changed, 268 insertions(+)

diff --git a/src/main/java/org/apache/sling/feature/maven/mojos/AbstractIncludingFeatureMojo.java b/src/main/java/org/apache/sling/feature/maven/mojos/AbstractIncludingFeatureMojo.java
new file mode 100644
index 0000000..d212125
--- /dev/null
+++ b/src/main/java/org/apache/sling/feature/maven/mojos/AbstractIncludingFeatureMojo.java
@@ -0,0 +1,158 @@
+/*
+ * 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;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.sling.feature.ArtifactId;
+import org.apache.sling.feature.Feature;
+import org.apache.sling.feature.maven.ProjectHelper;
+import org.codehaus.plexus.util.AbstractScanner;
+
+public class AbstractIncludingFeatureMojo extends AbstractFeatureMojo {
+
+    protected List<Feature> getSelectedFeatures(final FeatureSelectionConfig config) throws MojoExecutionException {
+        final List<Feature> selection = new ArrayList<>();
+
+        selectFeatureFiles(config, selection);
+
+        // TODO process aggregates
+
+        // TODO process artifacts
+
+        return selection;
+    }
+
+    private void selectFeatureFiles(final FeatureSelectionConfig config, final List<Feature> selection)
+            throws MojoExecutionException {
+        // get map of all project features
+        final Map<String, Feature> projectFeatures = ProjectHelper.getAssembledFeatures(this.project);
+
+        final String prefix = this.features.toPath().normalize().toFile().getAbsolutePath().concat(File.separator);
+        if (config.getIncludes().isEmpty()) {
+            final FeatureScanner scanner = new FeatureScanner(projectFeatures, prefix);
+            if (!config.getExcludes().isEmpty()) {
+                scanner.setExcludes(config.getExcludes().toArray(new String[config.getExcludes().size()]));
+            }
+            scanner.scan();
+            selection.addAll(scanner.getIncluded().values());
+        } else {
+            for (final String include : config.getIncludes()) {
+                final FeatureScanner scanner = new FeatureScanner(projectFeatures, prefix);
+                if (!config.getExcludes().isEmpty()) {
+                    scanner.setExcludes(config.getExcludes().toArray(new String[config.getExcludes().size()]));
+                }
+                scanner.setIncludes(new String[] { include });
+                scanner.scan();
+
+                if (!include.contains("*") && scanner.getIncluded().isEmpty()) {
+                    throw new MojoExecutionException("FeatureInclude " + include + " not found.");
+                }
+                selection.addAll(scanner.getIncluded().values());
+            }
+        }
+        if (!config.getExcludes().isEmpty()) {
+            for (final String exclude : config.getExcludes()) {
+                if (!exclude.contains("*")) {
+                    final FeatureScanner scanner = new FeatureScanner(projectFeatures, prefix);
+                    scanner.setIncludes(new String[] { exclude });
+                    scanner.scan();
+                    if (scanner.getIncluded().isEmpty()) {
+                        throw new MojoExecutionException("FeatureExclude " + exclude + " not found.");
+                    }
+                }
+            }
+        }
+    }
+
+    public static class FeatureScanner extends AbstractScanner {
+
+        private final Map<String, Feature> features;
+
+        private final Map<ArtifactId, Feature> included = new LinkedHashMap<>();
+
+        private final String prefix;
+
+        public FeatureScanner(final Map<String, Feature> features, final String prefix) {
+            this.features = features;
+            this.prefix = prefix;
+        }
+
+        @Override
+        public void scan() {
+            setupDefaultFilters();
+            setupMatchPatterns();
+
+            for (Map.Entry<String, Feature> entry : features.entrySet()) {
+                // skip aggregates
+                if (ProjectHelper.isAggregate(entry.getKey())) {
+                    continue;
+                }
+                final String name = entry.getKey().substring(prefix.length());
+                final String[] tokenizedName = tokenizePathToString(name, File.separator);
+                if (isIncluded(name, tokenizedName)) {
+                    if (!isExcluded(name, tokenizedName)) {
+                        included.put(entry.getValue().getId(), entry.getValue());
+                    }
+                }
+            }
+        }
+
+        static String[] tokenizePathToString(String path, String separator) {
+            List<String> ret = new ArrayList<>();
+            StringTokenizer st = new StringTokenizer(path, separator);
+            while (st.hasMoreTokens()) {
+                ret.add(st.nextToken());
+            }
+            return ret.toArray(new String[ret.size()]);
+        }
+
+        public Map<ArtifactId, Feature> getIncluded() {
+            return this.included;
+        }
+
+        @Override
+        public String[] getIncludedFiles() {
+            return null;
+        }
+
+        @Override
+        public String[] getIncludedDirectories() {
+            return null;
+        }
+
+        @Override
+        public File getBasedir() {
+            return null;
+        }
+    }
+
+    @Override
+    public void execute() throws MojoExecutionException, MojoFailureException {
+        // TODO Auto-generated method stub
+
+    }
+
+
+}
diff --git a/src/main/java/org/apache/sling/feature/maven/mojos/AggregateConfig.java b/src/main/java/org/apache/sling/feature/maven/mojos/AggregateConfig.java
new file mode 100644
index 0000000..ea696c6
--- /dev/null
+++ b/src/main/java/org/apache/sling/feature/maven/mojos/AggregateConfig.java
@@ -0,0 +1,44 @@
+/*
+ * 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;
+
+import org.apache.maven.plugins.annotations.Parameter;
+
+public class AggregateConfig extends FeatureSelectionConfig {
+
+    /**
+     * This is the classifier for the new feature. If not specified the feature is
+     * the main artifact for the project.
+     */
+    @Parameter
+    public String aggregateClassifier;
+    /**
+     * If this is set to {@code true} the feature is marked as final.
+     */
+    @Parameter(defaultValue = "false")
+    public boolean markAsFinal;
+    /**
+     * Optional title for the feature
+     */
+    @Parameter
+    public String featureTitle;
+    /**
+     * Optional description for the feature
+     */
+    @Parameter
+    public String featureDescription;
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/feature/maven/mojos/FeatureSelectionConfig.java b/src/main/java/org/apache/sling/feature/maven/mojos/FeatureSelectionConfig.java
new file mode 100644
index 0000000..7b0a72e
--- /dev/null
+++ b/src/main/java/org/apache/sling/feature/maven/mojos/FeatureSelectionConfig.java
@@ -0,0 +1,66 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.model.Dependency;
+
+public class FeatureSelectionConfig {
+
+    private List<String> includes = new ArrayList<>();
+
+    private List<String> excludes = new ArrayList<>();
+
+    private List<Dependency> artifacts = new ArrayList<>();
+
+    private List<String> aggregatedFeatures = new ArrayList<>();
+
+    public FeatureSelectionConfig() {
+    }
+
+    public void setFeatureInclude(final String val) {
+        includes.add(val);
+    }
+
+    public void setFeatureExclude(final String val) {
+        excludes.add(val);
+    }
+
+    public void setFeatureArtifact(final Dependency a) {
+        artifacts.add(a);
+    }
+
+    public void setAggregatedFeature(final String classifier) {
+        aggregatedFeatures.add(classifier);
+    }
+
+    public List<String> getIncludes() {
+        return this.includes;
+    }
+
+    public List<String> getExcludes() {
+        return this.excludes;
+    }
+
+    @Override
+    public String toString() {
+        return "FeatureSelectionConfig [featureIncludes=" + includes + ", featureExcludes=" + excludes
+                + ", featureArtifacts=" + artifacts + ", aggregatedFeatures=" + aggregatedFeatures + "]";
+    }
+}
\ No newline at end of file