karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmoulli...@apache.org
Subject svn commit: r960037 - in /karaf/trunk/features: ./ command/src/main/java/org/apache/karaf/features/command/ core/src/main/java/org/apache/karaf/features/ core/src/main/java/org/apache/karaf/features/internal/
Date Fri, 02 Jul 2010 15:51:02 GMT
Author: cmoulliard
Date: Fri Jul  2 15:51:02 2010
New Revision: 960037

URL: http://svn.apache.org/viewvc?rev=960037&view=rev
Log:
KARAF-96 : add attribute to define bundle start level + boolean indicating if the bundle can
start or not. OBR module has been disabled

Added:
    karaf/trunk/features/core/src/main/java/org/apache/karaf/features/BundleInfo.java
    karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/BundleImpl.java
Modified:
    karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/InfoFeatureCommand.java
    karaf/trunk/features/core/src/main/java/org/apache/karaf/features/Feature.java
    karaf/trunk/features/core/src/main/java/org/apache/karaf/features/Resolver.java
    karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/FeatureImpl.java
    karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java
    karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/RepositoryImpl.java
    karaf/trunk/features/pom.xml

Modified: karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/InfoFeatureCommand.java
URL: http://svn.apache.org/viewvc/karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/InfoFeatureCommand.java?rev=960037&r1=960036&r2=960037&view=diff
==============================================================================
--- karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/InfoFeatureCommand.java
(original)
+++ karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/InfoFeatureCommand.java
Fri Jul  2 15:51:02 2010
@@ -22,6 +22,7 @@ import java.util.Map;
 import org.apache.felix.gogo.commands.Argument;
 import org.apache.felix.gogo.commands.Command;
 import org.apache.felix.gogo.commands.Option;
+import org.apache.karaf.features.BundleInfo;
 import org.apache.karaf.features.Feature;
 import org.apache.karaf.features.FeaturesService;
 
@@ -98,13 +99,13 @@ public class InfoFeatureCommand extends 
     }
 
     private void displayBundleInformation(Feature feature) {
-        List<String> bundles = feature.getBundles();
-        if (bundles.isEmpty()) {
+        List<BundleInfo> bundleInfos = feature.getBundles();
+        if (bundleInfos.isEmpty()) {
             System.out.println("Feature has no bundles.");
         } else {
             System.out.println("Feature contains followed bundles:");
-            for (String featureBundle : bundles) {
-                System.out.println("  " + featureBundle);
+            for (BundleInfo featureBundle : bundleInfos) {
+                System.out.println("  " + featureBundle.getLocation());
             }
         }
     }
@@ -147,7 +148,7 @@ public class InfoFeatureCommand extends 
         }
 
         if (bundle) {
-            List<String> bundles = resolved != null ? resolved.getBundles() : feature.getBundles();
+            List<BundleInfo> bundles = resolved != null ? resolved.getBundles() : feature.getBundles();
             for (int i = 0, j = bundles.size(); i < j; i++) {
                 System.out.println(prefix + " " + (i+1 == j ? "\\" : "+") + " " + bundles.get(i));
             }

Added: karaf/trunk/features/core/src/main/java/org/apache/karaf/features/BundleInfo.java
URL: http://svn.apache.org/viewvc/karaf/trunk/features/core/src/main/java/org/apache/karaf/features/BundleInfo.java?rev=960037&view=auto
==============================================================================
--- karaf/trunk/features/core/src/main/java/org/apache/karaf/features/BundleInfo.java (added)
+++ karaf/trunk/features/core/src/main/java/org/apache/karaf/features/BundleInfo.java Fri
Jul  2 15:51:02 2010
@@ -0,0 +1,30 @@
+/*
+ * 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.karaf.features;
+
+/**
+ * A bundle info holds info about a Bundle.
+ */
+public interface BundleInfo {
+
+	String getLocation();
+	
+    int getStartLevel();
+    
+    boolean isStart();
+
+}

Modified: karaf/trunk/features/core/src/main/java/org/apache/karaf/features/Feature.java
URL: http://svn.apache.org/viewvc/karaf/trunk/features/core/src/main/java/org/apache/karaf/features/Feature.java?rev=960037&r1=960036&r2=960037&view=diff
==============================================================================
--- karaf/trunk/features/core/src/main/java/org/apache/karaf/features/Feature.java (original)
+++ karaf/trunk/features/core/src/main/java/org/apache/karaf/features/Feature.java Fri Jul
 2 15:51:02 2010
@@ -34,7 +34,7 @@ public interface Feature {
 
     List<Feature> getDependencies();
 
-    List<String> getBundles();
+    List<BundleInfo> getBundles();
 
     Map<String, Map<String, String>> getConfigurations();
 

Modified: karaf/trunk/features/core/src/main/java/org/apache/karaf/features/Resolver.java
URL: http://svn.apache.org/viewvc/karaf/trunk/features/core/src/main/java/org/apache/karaf/features/Resolver.java?rev=960037&r1=960036&r2=960037&view=diff
==============================================================================
--- karaf/trunk/features/core/src/main/java/org/apache/karaf/features/Resolver.java (original)
+++ karaf/trunk/features/core/src/main/java/org/apache/karaf/features/Resolver.java Fri Jul
 2 15:51:02 2010
@@ -20,6 +20,6 @@ import java.util.List;
 
 public interface Resolver {
 
-    List<String> resolve(Feature feature) throws Exception;
+    List<BundleInfo> resolve(Feature feature) throws Exception;
 
 }

Added: karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/BundleImpl.java
URL: http://svn.apache.org/viewvc/karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/BundleImpl.java?rev=960037&view=auto
==============================================================================
--- karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/BundleImpl.java
(added)
+++ karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/BundleImpl.java
Fri Jul  2 15:51:02 2010
@@ -0,0 +1,77 @@
+/*
+ * 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.karaf.features.internal;
+
+import org.apache.karaf.features.BundleInfo;
+
+/**
+ * A holder of bundle info
+ */
+public class BundleImpl implements BundleInfo {
+
+    private int startLevel;
+    private String location;
+    private boolean start;
+    
+
+    public BundleImpl() {
+    }
+
+    public BundleImpl(String location) {
+    	this.location = location;
+    }
+    
+    
+    public BundleImpl(String location, boolean start) {
+    	this.location = location;
+        this.setStart(start);
+    }
+    
+    public BundleImpl(String location, Integer startLevel) {
+    	this.location = location;
+        this.startLevel = startLevel;
+    }
+    
+    public BundleImpl(String location, Integer startLevel, boolean start) {
+    	this.location = location;
+        this.startLevel = startLevel;
+    }
+    
+    public void setStartLevel(Integer startLevel) {
+    	this.startLevel = startLevel;
+    }
+	
+    public int getStartLevel() {
+		return this.startLevel;
+	}
+	
+	public void setName(String location) {
+		this.location = location;
+	}
+	
+	public String getLocation() {
+		return this.location;
+	}
+
+	public void setStart(boolean start) {
+		this.start = start;
+	}
+
+	public boolean isStart() {
+		return start;
+	}
+}

Modified: karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/FeatureImpl.java
URL: http://svn.apache.org/viewvc/karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/FeatureImpl.java?rev=960037&r1=960036&r2=960037&view=diff
==============================================================================
--- karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/FeatureImpl.java
(original)
+++ karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/FeatureImpl.java
Fri Jul  2 15:51:02 2010
@@ -21,6 +21,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.karaf.features.BundleInfo;
 import org.apache.karaf.features.Feature;
 
 /**
@@ -33,7 +34,9 @@ public class FeatureImpl implements Feat
     private String version;
     private String resolver;
     private List<Feature> dependencies = new ArrayList<Feature>();
-    private List<String> bundles = new ArrayList<String>();
+    // TODO 
+    // private List<String> bundles = new ArrayList<String>();
+    private List<BundleInfo> bundles = new ArrayList<BundleInfo>();
     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";
@@ -79,7 +82,7 @@ public class FeatureImpl implements Feat
         return dependencies;
     }
 
-    public List<String> getBundles() {
+    public List<BundleInfo> getBundles() {
         return bundles;
     }
 
@@ -91,7 +94,7 @@ public class FeatureImpl implements Feat
         dependencies.add(dependency);
     }
 
-    public void addBundle(String bundle) {
+    public void addBundle(BundleInfo bundle) {
         bundles.add(bundle);
     }
 

Modified: karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java
URL: http://svn.apache.org/viewvc/karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java?rev=960037&r1=960036&r2=960037&view=diff
==============================================================================
--- karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java
(original)
+++ karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java
Fri Jul  2 15:51:02 2010
@@ -29,6 +29,7 @@ import java.util.jar.Manifest;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.apache.karaf.features.BundleInfo;
 import org.apache.karaf.features.Feature;
 import org.apache.karaf.features.FeatureEvent;
 import org.apache.karaf.features.FeaturesListener;
@@ -302,6 +303,7 @@ public class FeaturesServiceImpl impleme
                     if (state.installed.contains(b)
                             || (b.getState() != Bundle.STARTING && b.getState() !=
Bundle.ACTIVE
                                     && getStartLevel().isBundlePersistentlyStarted(b)))
{
+                    	// do no start bundles when user request it 
                         try {
                             b.start();
                         } catch (BundleException be) {
@@ -397,18 +399,18 @@ public class FeaturesServiceImpl impleme
             }
         }
         Set<Long> bundles = new TreeSet<Long>();
-        for (String bundleLocation : resolve(feature)) {
-            Bundle b = installBundleIfNeeded(state, bundleLocation);
+        for (BundleInfo bInfo : resolve(feature)) {
+            Bundle b = installBundleIfNeeded(state, bInfo);
             bundles.add(b.getBundleId());
         }
         state.features.put(feature, bundles);
     }
 
-    protected List<String> resolve(Feature feature) throws Exception {
+    protected List<BundleInfo> resolve(Feature feature) throws Exception {
         String resolver = feature.getResolver();
         // If no resolver is specified, we expect a list of uris
         if (resolver == null || resolver.length() == 0) {
-            return feature.getBundles();
+        	return feature.getBundles();
         }
         // Else, find the resolver
         String filter = "(&(" + Constants.OBJECTCLASS + "=" + Resolver.class.getName()
+ ")(name=" + resolver + "))";
@@ -542,9 +544,10 @@ public class FeaturesServiceImpl impleme
         return result;
     }
 
-    protected Bundle installBundleIfNeeded(InstallationState state, String bundleLocation)
throws IOException, BundleException {
-        LOGGER.debug("Checking " + bundleLocation);
+    protected Bundle installBundleIfNeeded(InstallationState state, BundleInfo bundleInfo)
throws IOException, BundleException {
+        LOGGER.debug("Checking " + bundleInfo.getLocation());
         InputStream is;
+        String bundleLocation = bundleInfo.getLocation();
         try {
             is = new BufferedInputStream(new URL(bundleLocation).openStream());
         } catch (RuntimeException e) {
@@ -577,6 +580,15 @@ public class FeaturesServiceImpl impleme
             }
             LOGGER.debug("Installing bundle " + bundleLocation);
             Bundle b = getBundleContext().installBundle(bundleLocation, is);
+            
+            // Define the startLevel for the bundle when defined
+            int ibsl = bundleInfo.getStartLevel();
+            if (ibsl > 0 && ibsl < 100) {
+                StartLevel sl = (StartLevel) bundleContext.getService(
+                		bundleContext.getServiceReference(org.osgi.service.startlevel.StartLevel.class.getName()));
+                sl.setInitialBundleStartLevel(ibsl);           	
+            }
+
             state.bundles.add(b);
             state.installed.add(b);
             return b;

Modified: karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/RepositoryImpl.java?rev=960037&r1=960036&r2=960037&view=diff
==============================================================================
--- karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/RepositoryImpl.java
(original)
+++ karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/RepositoryImpl.java
Fri Jul  2 15:51:02 2010
@@ -160,7 +160,32 @@ public class RepositoryImpl implements R
                     NodeList bundleNodes = e.getElementsByTagName("bundle");
                     for (int j = 0; j < bundleNodes.getLength(); j++) {
                         Element b = (Element) bundleNodes.item(j);
-                        f.addBundle(b.getTextContent());
+                        String bStartLevel = b.getAttribute("start-level");
+                        String bStart = b.getAttribute("start");
+                        boolean bs;
+                        
+                        // Check if the value of the attribute "start"
+                        // is parseable
+                        if (bStart != null && bStart.length() > 0) {
+                        		bs = Boolean.parseBoolean(bStart);
+                        } else {
+                        	// Assign true when the value is not readable
+                        	bs = true;
+                        }
+                       
+                        if (bStartLevel != null && bStartLevel.length() > 0) {
+                        	
+                        	try {
+                        	  int bsl = Integer.parseInt(bStartLevel);
+                          	  f.addBundle(new BundleImpl(b.getTextContent(), bsl, bs));
+                        	} catch (Exception ex) {
+                        		LOGGER.error("The start-level is not an int value for the bundle
: " + b.getTextContent());
+                            }
+ 
+                        } else {
+                        	f.addBundle(new BundleImpl(b.getTextContent(), bs));
+                        }
+                        
                     }
                     features.add(f);
                 }

Modified: karaf/trunk/features/pom.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/features/pom.xml?rev=960037&r1=960036&r2=960037&view=diff
==============================================================================
--- karaf/trunk/features/pom.xml (original)
+++ karaf/trunk/features/pom.xml Fri Jul  2 15:51:02 2010
@@ -36,7 +36,7 @@
         <module>core</module>
         <module>command</module>
         <module>management</module>
-        <module>obr</module>
+        <!-- <module>obr</module> -->
     </modules>
 
 </project>



Mime
View raw message