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-3764] NoClassDefFoundError when the features-core bundle is refreshed by itself
Date Thu, 11 Jun 2015 06:31:39 GMT
Repository: karaf
Updated Branches:
  refs/heads/master 947d2eb7c -> 8723b8fd8


[KARAF-3764] NoClassDefFoundError when the features-core bundle is refreshed by itself

Also fix problems with eventadmin and packageadmin causing refreshes of pax-logging-api and
most of bundles at the start phase


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

Branch: refs/heads/master
Commit: 8723b8fd843040e7eed3fd9f887efd53727c0c3a
Parents: 9770185
Author: Guillaume Nodet <gnodet@gmail.com>
Authored: Wed Jun 10 21:08:25 2015 +0200
Committer: Guillaume Nodet <gnodet@gmail.com>
Committed: Wed Jun 10 21:13:35 2015 +0200

----------------------------------------------------------------------
 assemblies/apache-karaf/pom.xml                 |   5 +-
 .../standard/src/main/feature/feature.xml       |   2 +-
 config/pom.xml                                  |   5 +-
 .../karaf/config/command/MetaCommand.java       | 125 ++++++++++---------
 .../features/internal/service/Deployer.java     |  24 ++--
 .../internal/service/EventAdminListener.java    |  93 ++++++++------
 .../karaf/itests/ConditionalFeaturesTest.java   |   3 +-
 .../org/apache/karaf/itests/FeatureTest.java    |   2 +-
 8 files changed, 147 insertions(+), 112 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/8723b8fd/assemblies/apache-karaf/pom.xml
----------------------------------------------------------------------
diff --git a/assemblies/apache-karaf/pom.xml b/assemblies/apache-karaf/pom.xml
index f2b7e7b..ba12881 100644
--- a/assemblies/apache-karaf/pom.xml
+++ b/assemblies/apache-karaf/pom.xml
@@ -48,7 +48,6 @@
             <artifactId>standard</artifactId>
             <classifier>features</classifier>
             <type>xml</type>
-            <scope>runtime</scope>
         </dependency>
         <dependency>
             <groupId>org.apache.karaf.features</groupId>
@@ -159,8 +158,10 @@
                     <installedFeatures>
                         <feature>wrapper</feature>
                     </installedFeatures>
-                    <bootFeatures>
+                    <startupFeatures>
                         <feature>eventadmin</feature>
+                    </startupFeatures>
+                    <bootFeatures>
                         <feature>wrap</feature>
                         <feature>aries-blueprint</feature>
                         <feature>shell</feature>

http://git-wip-us.apache.org/repos/asf/karaf/blob/8723b8fd/assemblies/features/standard/src/main/feature/feature.xml
----------------------------------------------------------------------
diff --git a/assemblies/features/standard/src/main/feature/feature.xml b/assemblies/features/standard/src/main/feature/feature.xml
index 7c66305..c45c828 100644
--- a/assemblies/features/standard/src/main/feature/feature.xml
+++ b/assemblies/features/standard/src/main/feature/feature.xml
@@ -499,7 +499,7 @@
             org.apache.felix.eventadmin.AddTimestamp=true
             org.apache.felix.eventadmin.AddSubject=true
         </config>
-        <bundle start-level="30">mvn:org.apache.karaf.services/org.apache.karaf.services.eventadmin/${project.version}</bundle>
+        <bundle start-level="5">mvn:org.apache.karaf.services/org.apache.karaf.services.eventadmin/${project.version}</bundle>
         <conditional>
             <condition>webconsole</condition>
             <bundle start-level="30">mvn:org.apache.felix/org.apache.felix.webconsole.plugins.event/${felix.eventadmin.webconsole.plugin.version}</bundle>

http://git-wip-us.apache.org/repos/asf/karaf/blob/8723b8fd/config/pom.xml
----------------------------------------------------------------------
diff --git a/config/pom.xml b/config/pom.xml
index a460394..16abc8c 100644
--- a/config/pom.xml
+++ b/config/pom.xml
@@ -102,11 +102,10 @@
                         <Export-Package>
                             org.apache.karaf.config.command*,
                             org.apache.karaf.config.core,
-                            org.osgi.service.metatype
                         </Export-Package>
                         <Import-Package>
-                            *,
-                            org.osgi.service.metatype
+                            org.osgi.service.metatype;resolution:=optional,
+                            *
                         </Import-Package>
                         <Private-Package>
                             org.apache.karaf.config.core.impl,

http://git-wip-us.apache.org/repos/asf/karaf/blob/8723b8fd/config/src/main/java/org/apache/karaf/config/command/MetaCommand.java
----------------------------------------------------------------------
diff --git a/config/src/main/java/org/apache/karaf/config/command/MetaCommand.java b/config/src/main/java/org/apache/karaf/config/command/MetaCommand.java
index 83a1e7d..b7554ae 100644
--- a/config/src/main/java/org/apache/karaf/config/command/MetaCommand.java
+++ b/config/src/main/java/org/apache/karaf/config/command/MetaCommand.java
@@ -61,74 +61,87 @@ public class MetaCommand extends ConfigCommandSupport {
     }
 
     @Override
-    protected Object doExecute() throws Exception {
-
-        ServiceReference<MetaTypeService> ref = context.getServiceReference(MetaTypeService.class);
-        if (ref == null) {
+    public Object doExecute() throws Exception {
+        try {
+            new InnerCommand().doExecute();
+        } catch (NoClassDefFoundError e) {
             System.out
-                .println("No MetaTypeService present. You need to install an implementation
to use this command.");
-        }
-        MetaTypeService metaTypeService = context.getService(ref);
-        ObjectClassDefinition def = getMetatype(metaTypeService, pid);
-        context.ungetService(ref);
-
-        if (def == null) {
-            System.out.println("No meta type definition found for pid: " + pid);
-            return null;
+                    .println("No MetaTypeService present. You need to install an implementation
to use this command.");
         }
-        System.out.println("Meta type informations for pid: " + pid);
-        ShellTable table = new ShellTable();
-        table.column("key");
-        table.column("name");
-        table.column("type");
-        table.column("default");
-        table.column("description");
-        AttributeDefinition[] attrs = def.getAttributeDefinitions(ObjectClassDefinition.ALL);
-        if (attrs != null) {
-            for (AttributeDefinition attr : attrs) {
-                table.addRow().addContent(attr.getID(), attr.getName(), getType(attr.getType()),
-                                          getDefaultValueStr(attr.getDefaultValue()), attr.getDescription());
-            }
-        }
-        table.print(System.out);
         return null;
     }
 
-    private String getType(int type) {
-        return typeMap.get(type);
-    }
+    class InnerCommand {
 
-    private String getDefaultValueStr(String[] defaultValues) {
-        if (defaultValues == null) {
-            return "";
-        }
-        StringBuilder result = new StringBuilder();
-        boolean first = true;
-        for (String defaultValue : defaultValues) {
-            if (first) {
-                first = false;
-            } else {
-                result.append(",");
+        protected Object doExecute() throws Exception {
+
+            ServiceReference<MetaTypeService> ref = context.getServiceReference(MetaTypeService.class);
+            if (ref == null) {
+                System.out
+                        .println("No MetaTypeService present. You need to install an implementation
to use this command.");
+            }
+            MetaTypeService metaTypeService = context.getService(ref);
+            ObjectClassDefinition def = getMetatype(metaTypeService, pid);
+            context.ungetService(ref);
+
+            if (def == null) {
+                System.out.println("No meta type definition found for pid: " + pid);
+                return null;
+            }
+            System.out.println("Meta type informations for pid: " + pid);
+            ShellTable table = new ShellTable();
+            table.column("key");
+            table.column("name");
+            table.column("type");
+            table.column("default");
+            table.column("description");
+            AttributeDefinition[] attrs = def.getAttributeDefinitions(ObjectClassDefinition.ALL);
+            if (attrs != null) {
+                for (AttributeDefinition attr : attrs) {
+                    table.addRow().addContent(attr.getID(), attr.getName(), getType(attr.getType()),
+                            getDefaultValueStr(attr.getDefaultValue()), attr.getDescription());
+                }
             }
-            result.append(defaultValue);
+            table.print(System.out);
+            return null;
+        }
+
+        private String getType(int type) {
+            return typeMap.get(type);
         }
-        return result.toString();
-    }
 
-    public ObjectClassDefinition getMetatype(MetaTypeService metaTypeService, String pid)
{
-        for (Bundle bundle : context.getBundles()) {
-            MetaTypeInformation info = metaTypeService.getMetaTypeInformation(bundle);
-            if (info == null) {
-                continue;
+        private String getDefaultValueStr(String[] defaultValues) {
+            if (defaultValues == null) {
+                return "";
             }
-            String[] pids = info.getPids();
-            for (String cPid : pids) {
-                if (cPid.equals(pid)) {
-                    return info.getObjectClassDefinition(cPid, null);
+            StringBuilder result = new StringBuilder();
+            boolean first = true;
+            for (String defaultValue : defaultValues) {
+                if (first) {
+                    first = false;
+                } else {
+                    result.append(",");
                 }
+                result.append(defaultValue);
             }
+            return result.toString();
         }
-        return null;
-    }
 
+        public ObjectClassDefinition getMetatype(MetaTypeService metaTypeService, String
pid) {
+            for (Bundle bundle : context.getBundles()) {
+                MetaTypeInformation info = metaTypeService.getMetaTypeInformation(bundle);
+                if (info == null) {
+                    continue;
+                }
+                String[] pids = info.getPids();
+                for (String cPid : pids) {
+                    if (cPid.equals(pid)) {
+                        return info.getObjectClassDefinition(cPid, null);
+                    }
+                }
+            }
+            return null;
+        }
+
+    }
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/8723b8fd/features/core/src/main/java/org/apache/karaf/features/internal/service/Deployer.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/Deployer.java
b/features/core/src/main/java/org/apache/karaf/features/internal/service/Deployer.java
index e6bc258..f3f767b 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/Deployer.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/Deployer.java
@@ -775,10 +775,6 @@ public class Deployer {
             }
         }
 
-        // TODO: remove this hack, but it avoids loading the class after the bundle is refreshed
-        new CopyOnWriteArrayIdentityList().iterator();
-        RequirementSort.sort(Collections.<Resource>emptyList());
-
         if (!noRefresh) {
             toStop = new HashSet<>();
             toStop.addAll(toRefresh.keySet());
@@ -802,9 +798,12 @@ public class Deployer {
                     Bundle bundle = entry.getKey();
                     print("    " + bundle.getSymbolicName() + " / " + bundle.getVersion()
+ " (" + entry.getValue() + ")", verbose);
                 }
-                if (!toRefresh.isEmpty()) {
-                    callback.refreshPackages(toRefresh.keySet());
+                // Ensure all classes are loaded in case the bundle will be refreshed
+                if (dstate.serviceBundle != null && toRefresh.containsKey(dstate.serviceBundle))
{
+                    ensureAllClassesLoaded(dstate.serviceBundle);
                 }
+                callback.refreshPackages(toRefresh.keySet());
+
             }
         }
 
@@ -935,7 +934,7 @@ public class Deployer {
                 Resource resource = bndToRes.get(bundle);
                 // This bundle is not managed
                 if (resource == null) {
-                    continue;
+                    resource = bundle.adapt(BundleRevision.class);
                 }
                 // Continue if we already know about this bundle
                 if (toRefresh.containsKey(bundle)) {
@@ -1370,4 +1369,15 @@ public class Deployer {
         return provider.open();
     }
 
+    public static void ensureAllClassesLoaded(Bundle bundle) throws ClassNotFoundException
{
+        BundleWiring wiring = bundle.adapt(BundleWiring.class);
+        if (wiring != null) {
+            for (String path : wiring.listResources("/", "*.class", BundleWiring.LISTRESOURCES_RECURSE))
{
+                String className = path.substring(0, path.length() - ".class".length());
+                className = className.replace('/', '.');
+                bundle.loadClass(className);
+            }
+        }
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/8723b8fd/features/core/src/main/java/org/apache/karaf/features/internal/service/EventAdminListener.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/EventAdminListener.java
b/features/core/src/main/java/org/apache/karaf/features/internal/service/EventAdminListener.java
index c16613d..bd5c0d5 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/EventAdminListener.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/EventAdminListener.java
@@ -27,12 +27,15 @@ import org.osgi.framework.BundleContext;
 import org.osgi.service.event.Event;
 import org.osgi.service.event.EventAdmin;
 import org.osgi.util.tracker.ServiceTracker;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * A listener to publish events to EventAdmin
  */
 public class EventAdminListener implements FeaturesListener {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(EventAdminListener.class);
     private final ServiceTracker<EventAdmin, EventAdmin> tracker;
 
     public EventAdminListener(BundleContext context) {
@@ -41,51 +44,59 @@ public class EventAdminListener implements FeaturesListener {
     }
 
     public void featureEvent(FeatureEvent event) {
-        EventAdmin eventAdmin = tracker.getService();
-        if (eventAdmin == null) {
-            return;
+        try {
+            EventAdmin eventAdmin = tracker.getService();
+            if (eventAdmin == null) {
+                return;
+            }
+            Dictionary<String, Object> props = new Hashtable<String, Object>();
+            props.put(EventConstants.TYPE, event.getType());
+            props.put(EventConstants.EVENT, event);
+            props.put(EventConstants.TIMESTAMP, System.currentTimeMillis());
+            props.put(EventConstants.FEATURE_NAME, event.getFeature().getName());
+            props.put(EventConstants.FEATURE_VERSION, event.getFeature().getVersion());
+            String topic;
+            switch (event.getType()) {
+            case FeatureInstalled:
+                topic = EventConstants.TOPIC_FEATURES_INSTALLED;
+                break;
+            case FeatureUninstalled:
+                topic = EventConstants.TOPIC_FEATURES_UNINSTALLED;
+                break;
+            default:
+                throw new IllegalStateException("Unknown features event type: " + event.getType());
+            }
+            eventAdmin.postEvent(new Event(topic, props));
+        } catch (IllegalStateException e) {
+            LOGGER.warn("Unable to post event to EventAdmin", e);
         }
-        Dictionary<String, Object> props = new Hashtable<String, Object>();
-        props.put(EventConstants.TYPE, event.getType());
-        props.put(EventConstants.EVENT, event);
-        props.put(EventConstants.TIMESTAMP, System.currentTimeMillis());
-        props.put(EventConstants.FEATURE_NAME, event.getFeature().getName());
-        props.put(EventConstants.FEATURE_VERSION, event.getFeature().getVersion());
-        String topic;
-        switch (event.getType()) {
-        case FeatureInstalled:
-            topic = EventConstants.TOPIC_FEATURES_INSTALLED;
-            break;
-        case FeatureUninstalled:
-            topic = EventConstants.TOPIC_FEATURES_UNINSTALLED;
-            break;
-        default:
-            throw new IllegalStateException("Unknown features event type: " + event.getType());
-        }
-        eventAdmin.postEvent(new Event(topic, props));
     }
 
     public void repositoryEvent(RepositoryEvent event) {
-        EventAdmin eventAdmin = tracker.getService();
-        if (eventAdmin == null) {
-            return;
-        }
-        Dictionary<String, Object> props = new Hashtable<String, Object>();
-        props.put(EventConstants.TYPE, event.getType());
-        props.put(EventConstants.EVENT, event);
-        props.put(EventConstants.TIMESTAMP, System.currentTimeMillis());
-        props.put(EventConstants.REPOSITORY_URI, event.getRepository().getURI().toString());
-        String topic;
-        switch (event.getType()) {
-        case RepositoryAdded:
-            topic = EventConstants.TOPIC_REPOSITORY_ADDED;
-            break;
-        case RepositoryRemoved:
-            topic = EventConstants.TOPIC_REPOSITORY_REMOVED;
-            break;
-        default:
-            throw new IllegalStateException("Unknown repository event type: " + event.getType());
+        try {
+            EventAdmin eventAdmin = tracker.getService();
+            if (eventAdmin == null) {
+                return;
+            }
+            Dictionary<String, Object> props = new Hashtable<String, Object>();
+            props.put(EventConstants.TYPE, event.getType());
+            props.put(EventConstants.EVENT, event);
+            props.put(EventConstants.TIMESTAMP, System.currentTimeMillis());
+            props.put(EventConstants.REPOSITORY_URI, event.getRepository().getURI().toString());
+            String topic;
+            switch (event.getType()) {
+            case RepositoryAdded:
+                topic = EventConstants.TOPIC_REPOSITORY_ADDED;
+                break;
+            case RepositoryRemoved:
+                topic = EventConstants.TOPIC_REPOSITORY_REMOVED;
+                break;
+            default:
+                throw new IllegalStateException("Unknown repository event type: " + event.getType());
+            }
+            eventAdmin.postEvent(new Event(topic, props));
+        } catch (IllegalStateException e) {
+            LOGGER.warn("Unable to post event to EventAdmin", e);
         }
-        eventAdmin.postEvent(new Event(topic, props));
     }
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/8723b8fd/itests/src/test/java/org/apache/karaf/itests/ConditionalFeaturesTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/ConditionalFeaturesTest.java b/itests/src/test/java/org/apache/karaf/itests/ConditionalFeaturesTest.java
index f64dc02..18ef2d0 100644
--- a/itests/src/test/java/org/apache/karaf/itests/ConditionalFeaturesTest.java
+++ b/itests/src/test/java/org/apache/karaf/itests/ConditionalFeaturesTest.java
@@ -76,6 +76,7 @@ public class ConditionalFeaturesTest extends KarafTestSupport {
             featureService.uninstallFeature("scr", EnumSet.of(FeaturesService.Option.NoAutoRefreshBundles));
         } catch (Exception e) {
         }
+        featureService.installFeature("eventadmin", EnumSet.of(FeaturesService.Option.NoAutoRefreshBundles));
         featureService.installFeature("webconsole", EnumSet.of(FeaturesService.Option.NoAutoRefreshBundles));
 
         assertBundleInstalled("org.apache.karaf.webconsole.features");
@@ -84,7 +85,7 @@ public class ConditionalFeaturesTest extends KarafTestSupport {
         assertBundleInstalled("org.apache.karaf.webconsole.http");
         assertBundleInstalled("org.apache.felix.webconsole.plugins.event");
 
-        // remove eventadmin
+        // add eventadmin
         featureService.uninstallFeature("eventadmin", EnumSet.of(FeaturesService.Option.NoAutoRefreshBundles));
         assertBundleNotInstalled("org.apache.felix.webconsole.plugins.event");
     }

http://git-wip-us.apache.org/repos/asf/karaf/blob/8723b8fd/itests/src/test/java/org/apache/karaf/itests/FeatureTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/FeatureTest.java b/itests/src/test/java/org/apache/karaf/itests/FeatureTest.java
index 9aa4112..e87b111 100644
--- a/itests/src/test/java/org/apache/karaf/itests/FeatureTest.java
+++ b/itests/src/test/java/org/apache/karaf/itests/FeatureTest.java
@@ -34,7 +34,7 @@ public class FeatureTest extends KarafTestSupport {
 
     @Test
     public void bootFeatures() throws Exception {
-        assertFeaturesInstalled("eventadmin","jaas", "ssh", "management", "bundle", "config",
"deployer", "diagnostic",
+        assertFeaturesInstalled("jaas", "ssh", "management", "bundle", "config", "deployer",
"diagnostic",
                                 "instance", "kar", "log", "package", "service", "system");
     }
 


Mime
View raw message