karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject [05/33] git commit: [KARAF-2888] Call listeners when features are installed or uninstalled
Date Fri, 11 Apr 2014 17:20:27 GMT
[KARAF-2888] Call listeners when features are installed or uninstalled


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

Branch: refs/heads/master
Commit: 6a19214e566cec14c821aac849c8718a08eadaac
Parents: 4b6b7af
Author: Guillaume Nodet <gnodet@gmail.com>
Authored: Thu Apr 10 16:27:21 2014 +0200
Committer: Guillaume Nodet <gnodet@gmail.com>
Committed: Fri Apr 11 19:20:02 2014 +0200

----------------------------------------------------------------------
 .../internal/service/FeaturesServiceImpl.java   | 28 +++++++++-----------
 1 file changed, 12 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/6a19214e/features/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
----------------------------------------------------------------------
diff --git a/features/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
b/features/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
index 6c16650..e6dbc32 100644
--- a/features/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
+++ b/features/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
@@ -799,7 +799,10 @@ public class FeaturesServiceImpl implements FeaturesService {
 
         // Install conditionals
         List<String> installedFeatureIds = getFeatureIds(allResources);
-        List<Feature> installedFeatures = getFeatures(repositories, installedFeatureIds);
+        List<String> newFeatures = new ArrayList<String>(installedFeatureIds);
+        newFeatures.removeAll(installed);
+        List<String> delFeatures = new ArrayList<String>(installed);
+        delFeatures.removeAll(installedFeatureIds);
 
         //
         // Compute list of installable resources (those with uris)
@@ -955,25 +958,12 @@ public class FeaturesServiceImpl implements FeaturesService {
         //
         // Update and save state
         //
-        List<String> newFeatures = new ArrayList<String>();
         synchronized (lock) {
-            List<String> allFeatures = new ArrayList<String>();
-            for (Resource resource : allResources) {
-                String name = FeatureNamespace.getName(resource);
-                if (name != null) {
-                    Version version = FeatureNamespace.getVersion(resource);
-                    String id = version != null ? name + "/" + version : name;
-                    allFeatures.add(id);
-                    if (!state.installedFeatures.contains(id)) {
-                        newFeatures.add(id);
-                    }
-                }
-            }
             state.bundleChecksums.putAll(deployment.newCheckums);
             state.features.clear();
             state.features.addAll(features);
             state.installedFeatures.clear();
-            state.installedFeatures.addAll(allFeatures);
+            state.installedFeatures.addAll(installedFeatureIds);
             state.managedBundles.clear();
             state.managedBundles.addAll(managed);
             saveState();
@@ -1061,7 +1051,13 @@ public class FeaturesServiceImpl implements FeaturesService {
             }
         }
 
-        // TODO: call listeners for features added and removed
+        // Call listeners
+        for (Feature feature : getFeatures(repositories, delFeatures)) {
+            callListeners(new FeatureEvent(feature, FeatureEvent.EventType.FeatureUninstalled,
false));
+        }
+        for (Feature feature : getFeatures(repositories, newFeatures)) {
+            callListeners(new FeatureEvent(feature, FeatureEvent.EventType.FeatureInstalled,
false));
+        }
 
         print("Done.", verbose);
     }


Mime
View raw message