karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ldywi...@apache.org
Subject svn commit: r1059004 - in /karaf/branches/karaf-2.1.x/features/core/src: main/java/org/apache/karaf/features/internal/ test/java/org/apache/karaf/features/internal/
Date Fri, 14 Jan 2011 13:32:14 GMT
Author: ldywicki
Date: Fri Jan 14 13:32:14 2011
New Revision: 1059004

URL: http://svn.apache.org/viewvc?rev=1059004&view=rev
Log:
KARAF-388. Allow specifying a version for boot feature. Patch provided by Lars Heinemann.

Modified:
    karaf/branches/karaf-2.1.x/features/core/src/main/java/org/apache/karaf/features/internal/FeatureImpl.java
    karaf/branches/karaf-2.1.x/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java
    karaf/branches/karaf-2.1.x/features/core/src/test/java/org/apache/karaf/features/internal/FeaturesServiceImplTest.java

Modified: karaf/branches/karaf-2.1.x/features/core/src/main/java/org/apache/karaf/features/internal/FeatureImpl.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.1.x/features/core/src/main/java/org/apache/karaf/features/internal/FeatureImpl.java?rev=1059004&r1=1059003&r2=1059004&view=diff
==============================================================================
--- karaf/branches/karaf-2.1.x/features/core/src/main/java/org/apache/karaf/features/internal/FeatureImpl.java
(original)
+++ karaf/branches/karaf-2.1.x/features/core/src/main/java/org/apache/karaf/features/internal/FeatureImpl.java
Fri Jan 14 13:32:14 2011
@@ -40,6 +40,7 @@ public class FeatureImpl implements Feat
     private Map<String, Map<String,String>> configs = new HashMap<String,
Map<String,String>>();
     public static String SPLIT_FOR_NAME_AND_VERSION = "_split_for_name_and_version_";
     public static String DEFAULT_VERSION = "0.0.0";
+    public static String VERSION_PREFIX = "version=";
 
     public FeatureImpl() {
     }

Modified: karaf/branches/karaf-2.1.x/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.1.x/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java?rev=1059004&r1=1059003&r2=1059004&view=diff
==============================================================================
--- karaf/branches/karaf-2.1.x/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java
(original)
+++ karaf/branches/karaf-2.1.x/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java
Fri Jan 14 13:32:14 2011
@@ -772,12 +772,32 @@ public class FeaturesServiceImpl impleme
         if (boot != null && !bootFeaturesInstalled) {
             new Thread() {
                 public void run() {
+                    // splitting the features
                     String[] list = boot.split(",");
                     Set<Feature> features = new LinkedHashSet<Feature>();
                     for (String f : list) {
                         if (f.length() > 0) {
+                            String featureVersion = null;
+
+                            // first we split the parts of the feature string to gain access
to the version info
+                            // if specified
+                            String[] parts = f.split(";");
+                            String featureName = parts[0];
+                            for (String part : parts) {
+                                // if the part starts with "version=" it contains the version
info
+                                if (part.startsWith(FeatureImpl.VERSION_PREFIX)) {
+                                    featureVersion = part.substring(FeatureImpl.VERSION_PREFIX.length());
+                                }
+                            }
+
+                            if (featureVersion == null) {
+                                // no version specified - use default version
+                                featureVersion = FeatureImpl.DEFAULT_VERSION;
+                            }
+
                             try {
-                                Feature feature = getFeature(f, FeatureImpl.DEFAULT_VERSION);
+                                // try to grab specific feature version
+                                Feature feature = getFeature(featureName, featureVersion);
                                 if (feature != null) {
                                     features.add(feature);
                                 } else {

Modified: karaf/branches/karaf-2.1.x/features/core/src/test/java/org/apache/karaf/features/internal/FeaturesServiceImplTest.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.1.x/features/core/src/test/java/org/apache/karaf/features/internal/FeaturesServiceImplTest.java?rev=1059004&r1=1059003&r2=1059004&view=diff
==============================================================================
--- karaf/branches/karaf-2.1.x/features/core/src/test/java/org/apache/karaf/features/internal/FeaturesServiceImplTest.java
(original)
+++ karaf/branches/karaf-2.1.x/features/core/src/test/java/org/apache/karaf/features/internal/FeaturesServiceImplTest.java
Fri Jan 14 13:32:14 2011
@@ -16,14 +16,19 @@
  */
 package org.apache.karaf.features.internal;
 
+import static org.easymock.EasyMock.*;
+
 import java.io.File;
 import java.io.IOException;
+import java.net.URL;
+import java.net.URLClassLoader;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 import junit.framework.TestCase;
 import org.apache.karaf.features.Feature;
+
 import org.apache.felix.utils.manifest.Clause;
 import org.easymock.EasyMock;
 import org.osgi.framework.BundleContext;
@@ -116,6 +121,51 @@ public class FeaturesServiceImplTest ext
         }
     }
 
+    /**
+     * This test checks KARAF-388 which allows you to specify version of boot feature.
+     */
+    public void testStartDoesNotFailWithNonExistentVersion()  {
+        BundleContext bundleContext = createMock(BundleContext.class);
+
+        final Map<String, Map<String, Feature>> features = new HashMap<String,
Map<String,Feature>>();
+        Map<String, Feature> versions = new HashMap<String, Feature>();
+        versions.put("1.0.0", new FeatureImpl("transaction", "1.0.0"));
+        versions.put("2.0.0", new FeatureImpl("transaction", "2.0.0"));
+        features.put("transaction", versions);
+
+        Map<String, Feature> versions2 = new HashMap<String, Feature>();
+        versions2.put("1.0.0", new FeatureImpl("ssh", "1.0.0"));
+        features.put("ssh", versions2);
+
+        final FeaturesServiceImpl impl = new FeaturesServiceImpl() {
+            protected Map<String,Map<String,Feature>> getFeatures() throws Exception
{
+                return features;
+            };
+
+            // override methods which refers to bundle context to avoid mocking everything
+            @Override
+            protected boolean loadState() {
+                return true;
+            }
+            @Override
+            protected void saveState() {
+            }
+        };
+        impl.setBundleContext(bundleContext);
+
+        try {
+            Thread.currentThread().setContextClassLoader(new URLClassLoader(new URL[0]));
+            impl.setBoot("transaction;version=1.2,ssh;version=1.0.0");
+            impl.start();
+
+            assertFalse("Feature transaction 1.0.0 should not be installed", impl.isInstalled(impl.getFeature("transaction",
"1.0.0")));
+            assertFalse("Feature transaction 2.0.0 should not be installed", impl.isInstalled(impl.getFeature("transaction",
"2.0.0")));
+            assertFalse("Feature ssh should be installed", impl.isInstalled(impl.getFeature("ssh",
"1.0.0")));
+        } catch (Exception e) {
+            fail(String.format("Service should not throw start-up exception but log the error
instead: %s", e));
+        }
+    }
+
     public void testGetOptionalImportsOnly() {
         FeaturesServiceImpl service = new FeaturesServiceImpl();
 



Mime
View raw message