karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject [1/2] karaf git commit: [KARAF-4830] Karaf does not start with staged features in etc/org.apache.karaf.features.cfg
Date Wed, 23 Nov 2016 09:33:20 GMT
Repository: karaf
Updated Branches:
  refs/heads/karaf-4.0.x 814ff4975 -> 0bb989aa1


[KARAF-4830] Karaf does not start with staged features in etc/org.apache.karaf.features.cfg

Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/95c0dfe5
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/95c0dfe5
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/95c0dfe5

Branch: refs/heads/karaf-4.0.x
Commit: 95c0dfe54d0529e603e1a9163f02485016dd85f7
Parents: 814ff49
Author: Guillaume Nodet <gnodet@apache.org>
Authored: Wed Nov 23 10:23:52 2016 +0100
Committer: Guillaume Nodet <gnodet@apache.org>
Committed: Wed Nov 23 10:24:36 2016 +0100

----------------------------------------------------------------------
 .../internal/service/BootFeaturesInstaller.java | 53 ++++++++++++--------
 .../internal/service/FeaturesServiceImpl.java   |  4 +-
 .../service/BootFeaturesInstallerTest.java      | 23 +++++++++
 3 files changed, 59 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/95c0dfe5/features/core/src/main/java/org/apache/karaf/features/internal/service/BootFeaturesInstaller.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/BootFeaturesInstaller.java
b/features/core/src/main/java/org/apache/karaf/features/internal/service/BootFeaturesInstaller.java
index d45cfc6..bb93361 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/BootFeaturesInstaller.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/BootFeaturesInstaller.java
@@ -19,15 +19,12 @@ package org.apache.karaf.features.internal.service;
 import java.io.File;
 import java.net.URI;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.EnumSet;
 import java.util.HashSet;
 import java.util.Hashtable;
-import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+import java.util.StringTokenizer;
 
 import org.apache.karaf.features.BootFinished;
 import org.apache.karaf.features.FeaturesService;
@@ -131,24 +128,40 @@ public class BootFeaturesInstaller {
     }
 
     protected List<Set<String>> parseBootFeatures(String bootFeatures) {
-        Pattern pattern = Pattern.compile("(\\s*\\(([^)]+))\\s*\\)\\s*,\\s*|.+");
-        Matcher matcher = pattern.matcher(bootFeatures);
-        List<Set<String>> result = new ArrayList<>();
-        while (matcher.find()) {
-            String group = matcher.group(2) != null ? matcher.group(2) : matcher.group();
-            result.add(parseFeatureList(group));
-        }
-        return result;
-    }
-
-    protected Set<String> parseFeatureList(String group) {
-        HashSet<String> features = new LinkedHashSet<>();
-        for (String feature : Arrays.asList(group.trim().split("\\s*,\\s*"))) {
-            if (feature.length() > 0) {
-                features.add(feature);
+        List<Set<String>> stages = new ArrayList<>();
+        StringTokenizer tokenizer = new StringTokenizer(bootFeatures, " \t\r\n,()", true);
+        int paren = 0;
+        Set<String> stage = new HashSet<>();
+        while (tokenizer.hasMoreTokens()) {
+            String token = tokenizer.nextToken();
+            if (token.equals("(")) {
+                if (paren == 0) {
+                    if (!stage.isEmpty()) {
+                        stages.add(stage);
+                        stage = new HashSet<>();
+                    }
+                    paren++;
+                } else {
+                    throw new IllegalArgumentException("Bad syntax in boot features: '" +
bootFeatures + "'");
+                }
+            } else if (token.equals(")")) {
+                if (paren == 1) {
+                    if (!stage.isEmpty()) {
+                        stages.add(stage);
+                        stage = new HashSet<>();
+                    }
+                    paren--;
+                } else {
+                    throw new IllegalArgumentException("Bad syntax in boot features: '" +
bootFeatures + "'");
+                }
+            } else if (!token.matches("[ \t\r\n]+|,")) { // ignore spaces and commas
+                stage.add(token);
             }
         }
-        return features;
+        if (!stage.isEmpty()) {
+            stages.add(stage);
+        }
+        return stages;
     }
 
     private void publishBootFinished() {

http://git-wip-us.apache.org/repos/asf/karaf/blob/95c0dfe5/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
index fac03d3..113d318 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
@@ -1283,7 +1283,9 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
 
     @Override
     public void startBundle(Bundle bundle) throws BundleException {
-        bundle.start();
+        if (bundle != this.bundle || bundle.getState() != Bundle.STARTING) {
+            bundle.start();
+        }
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/karaf/blob/95c0dfe5/features/core/src/test/java/org/apache/karaf/features/internal/service/BootFeaturesInstallerTest.java
----------------------------------------------------------------------
diff --git a/features/core/src/test/java/org/apache/karaf/features/internal/service/BootFeaturesInstallerTest.java
b/features/core/src/test/java/org/apache/karaf/features/internal/service/BootFeaturesInstallerTest.java
index 1c6b0d5..01553d3 100644
--- a/features/core/src/test/java/org/apache/karaf/features/internal/service/BootFeaturesInstallerTest.java
+++ b/features/core/src/test/java/org/apache/karaf/features/internal/service/BootFeaturesInstallerTest.java
@@ -18,6 +18,7 @@ package org.apache.karaf.features.internal.service;
 
 import java.net.URI;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.EnumSet;
 import java.util.List;
 import java.util.Set;
@@ -104,4 +105,26 @@ public class BootFeaturesInstallerTest extends TestBase {
         verify(impl);
     }
 
+    @Test
+    public void testParseBootFeatures() throws Exception {
+        String features = "foo, jim, (ssh, shell, jaas, feature, framework), (system, bundle,
management, service), (instance, package, log, deployer, diagnostic, config, kar), bar, zad";
+        BootFeaturesInstaller bootFeatures = new BootFeaturesInstaller(null, null, null,
null, false);
+        List<Set<String>> stages = bootFeatures.parseBootFeatures(features);
+        Assert.assertEquals(5, stages.size());
+        for (String f : Arrays.asList("foo", "jim")) {
+            Assert.assertTrue("Should contain '" + f + "'", stages.get(0).contains(f));
+        }
+        for (String f : Arrays.asList("ssh", "shell", "jaas", "feature", "framework")) {
+            Assert.assertTrue("Should contain '" + f + "'", stages.get(1).contains(f));
+        }
+        for (String f : Arrays.asList("system", "bundle", "management", "service")) {
+            Assert.assertTrue("Should contain '" + f + "'", stages.get(2).contains(f));
+        }
+        for (String f : Arrays.asList("instance", "package", "log", "deployer", "diagnostic",
"config", "kar")) {
+            Assert.assertTrue("Should contain '" + f + "'", stages.get(3).contains(f));
+        }
+        for (String f : Arrays.asList("bar", "zad")) {
+            Assert.assertTrue("Should contain '" + f + "'", stages.get(4).contains(f));
+        }
+    }
 }


Mime
View raw message