You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by an...@apache.org on 2019/06/06 22:13:03 UTC

[sling-org-apache-sling-feature-modelconverter] branch standalone-app updated: Added flags to drop unwanted bundles and limit runmodes

This is an automated email from the ASF dual-hosted git repository.

andysch pushed a commit to branch standalone-app
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-modelconverter.git


The following commit(s) were added to refs/heads/standalone-app by this push:
     new ef06bc0  Added flags to drop unwanted bundles and limit runmodes
ef06bc0 is described below

commit ef06bc0017d85aca2d569eeb0c06e84887f95788
Author: Andreas Schaefer <sc...@iMac.local>
AuthorDate: Thu Jun 6 15:01:17 2019 -0700

    Added flags to drop unwanted bundles and limit runmodes
---
 .../apache/sling/feature/modelconverter/Main.java  | 13 +++++++
 .../modelconverter/ProvisioningToFeature.java      | 43 +++++++++++++++++++---
 2 files changed, 51 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/modelconverter/Main.java b/src/main/java/org/apache/sling/feature/modelconverter/Main.java
index 91158ad..052bfc1 100644
--- a/src/main/java/org/apache/sling/feature/modelconverter/Main.java
+++ b/src/main/java/org/apache/sling/feature/modelconverter/Main.java
@@ -17,6 +17,7 @@
 package org.apache.sling.feature.modelconverter;
 
 import java.io.File;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
@@ -70,6 +71,12 @@ public class Main implements Runnable {
     @Option(names = { "-D", "--noProvisioningModelName" }, description = "If flagged then the Provisioning Model Name is not added'")
     private boolean noProvisioningModelName;
 
+    @Option(names = { "-e", "--excludeBundles" }, description = "List of Bundles and Bundle Configurations to be excluded'")
+    private List<String> excludeBundles;
+
+    @Option(names = { "-r", "--runModes" }, description = "List of Runmodes of the Feature Model. If set only configuration with that runmodes are used w/o a .runmdoes. suffix")
+    private List<String> runModes;
+
     private Pattern pattern = Pattern.compile("^(.*?):(.*?)=(.*?)$");
 
     @Override
@@ -114,6 +121,12 @@ public class Main implements Runnable {
                 }
             }
             options.put("addFrameworkProperties", frameworkPropertiesMap);
+            options.put("excludeBundles", excludeBundles);
+            LOGGER.info("Excluded Bundles: '{}'", excludeBundles);
+            options.put("runModes", runModes == null ? new ArrayList<>() : runModes);
+            LOGGER.info("Runmodes: '{}'", runModes);
+
+            // Start the Conversion
             for(File file: provisioningFiles) {
                 LOGGER.info("Handle File: '{}'", file.getAbsolutePath());
                 ProvisioningToFeature.convert(file, featureModelsOutputDirectory, options);
diff --git a/src/main/java/org/apache/sling/feature/modelconverter/ProvisioningToFeature.java b/src/main/java/org/apache/sling/feature/modelconverter/ProvisioningToFeature.java
index 35b0750..62917cc 100644
--- a/src/main/java/org/apache/sling/feature/modelconverter/ProvisioningToFeature.java
+++ b/src/main/java/org/apache/sling/feature/modelconverter/ProvisioningToFeature.java
@@ -303,7 +303,9 @@ public class ProvisioningToFeature {
             final Map<String,String> variables,
             final List<String> dropVariables,
             final Bundles bundles,
+            final List<String> excludeBundles,
             final Configurations configurations,
+            final List<String> currentRunModes,
             final Extensions extensions,
             final Map<String,String> properties) {
         for (Iterator<Map.Entry<String, String>> it = feature.getVariables().iterator(); it.hasNext(); ) {
@@ -322,9 +324,34 @@ public class ProvisioningToFeature {
 
         Extension cpExtension = extensions.getByName(Extension.EXTENSION_NAME_CONTENT_PACKAGES);
         for(final RunMode runMode : feature.getRunModes() ) {
+            int runModelFilteringMode = 0; // Default behavior with no filtering
+            String[] runModeNames = runMode.getNames();
+            if(!currentRunModes.isEmpty()) {
+                if(runModeNames == null || runModeNames.length == 0) {
+                    runModelFilteringMode = 1; // No Runmode configured -> write as usual
+                } else {
+                    for(String runModeName: runModeNames) {
+                        if(currentRunModes.contains(runModeName)) {
+                            runModelFilteringMode = 2; // Matching Runmode -> write out w/o run mode suffix
+                        }
+                    }
+                    if(runModelFilteringMode != 2) {
+                        runModelFilteringMode = -1; // Ignore this runmode as it does not have a match
+                    }
+                }
+            }
+            if(runModelFilteringMode < 0) {
+                continue;
+            }
             for(final ArtifactGroup group : runMode.getArtifactGroups()) {
                 for(final Artifact artifact : group) {
                     ArtifactId id = ArtifactId.fromMvnUrl(artifact.toMvnUrl());
+                    String artifactId = id.getArtifactId();
+                    LOGGER.info("Check Artitfact Id: '{}' if excluded by: '{}'", artifactId, excludeBundles);
+                    if(excludeBundles.contains(artifactId)) {
+                        // If bundle is excluded then go to the next one
+                        continue;
+                    }
                     String version = id.getVersion();
                     if(version.startsWith("${") && version.endsWith("}")) {
                         // Replace Variable with value if found
@@ -369,8 +396,13 @@ public class ProvisioningToFeature {
                     pid = ".." + pid.substring(1);
                 }
 
-                final String[] runModeNames = runMode.getNames();
-                if (runModeNames != null) {
+                LOGGER.info("Check Configuration Id: '{}' if excluded by: '{}'", pid, excludeBundles);
+                if(excludeBundles.contains(pid)) {
+                    // If configuration is excluded then go to the next one
+                    continue;
+                }
+
+                if (runModeNames != null && runModelFilteringMode != 2) {
                     pid = pid + ".runmodes." + String.join(".", runModeNames);
                     pid = pid.replaceAll("[:]", "..");
                 }
@@ -396,8 +428,7 @@ public class ProvisioningToFeature {
             }
 
             for(final Map.Entry<String, String> prop : runMode.getSettings()) {
-                String[] runModeNames = runMode.getNames();
-                if (runModeNames == null) {
+                if (runModeNames == null && runModelFilteringMode != 2) {
                     properties.put(prop.getKey(), prop.getValue());
                 } else {
                     properties.put(prop.getKey() + ".runmodes:" + String.join(",", runModeNames),
@@ -457,7 +488,9 @@ public class ProvisioningToFeature {
         String nameOption = getOption(options, "name", "");
         boolean useProvidedVersion = getOption(options, "useProvidedVersion", false);
         List<String> dropVariables = getOption(options, "dropVariables", new ArrayList<>());
+        List<String> excludeBundles = getOption(options, "excludeBundles", new ArrayList<>());
         Map<String,Map<String,String>> addFrameworkProperties = getOption(options, "addFrameworkProperties", new HashMap<String,Map<String, String>>());
+        List<String> runModes = getOption(options, "runModes", new ArrayList<>());
 
         for(final Feature feature : model.getFeatures() ) {
             final String idString;
@@ -502,7 +535,7 @@ public class ProvisioningToFeature {
                     }
                 }
             }
-            buildFromFeature(feature, variables, dropVariables, f.getBundles(), f.getConfigurations(), f.getExtensions(), frameworkProperties);
+            buildFromFeature(feature, variables, dropVariables, f.getBundles(), excludeBundles, f.getConfigurations(), runModes, f.getExtensions(), frameworkProperties);
 
             if (!f.getId().getArtifactId().equals(feature.getName())) {
                 f.getVariables().put(FeatureToProvisioning.PROVISIONING_MODEL_NAME_VARIABLE, feature.getName());