You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gn...@apache.org on 2017/10/20 13:59:08 UTC
karaf git commit: [KARAF-5435] BundleException when installing a
bundle by API when the FeatureService install a feature
Repository: karaf
Updated Branches:
refs/heads/master 5e050de5e -> 45fed9365
[KARAF-5435] BundleException when installing a bundle by API when the FeatureService install a feature
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/45fed936
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/45fed936
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/45fed936
Branch: refs/heads/master
Commit: 45fed936553e464a0575e61d94fe67128c089a31
Parents: 5e050de
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Fri Oct 20 15:52:43 2017 +0200
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Fri Oct 20 15:59:03 2017 +0200
----------------------------------------------------------------------
.../karaf/features/internal/osgi/Activator.java | 1 +
.../internal/service/BundleInstallSupport.java | 2 ++
.../service/BundleInstallSupportImpl.java | 30 ++++++++++++++++----
.../internal/service/FeaturesServiceImpl.java | 2 +-
.../internal/service/StaticInstallSupport.java | 4 +++
5 files changed, 33 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/45fed936/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java b/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java
index 1ac72b6..6881d47 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java
@@ -321,6 +321,7 @@ public class Activator extends BaseActivator {
featuresService = null;
}
if (installSupport != null) {
+ installSupport.unregister();
installSupport.saveDigraph();
}
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/45fed936/features/core/src/main/java/org/apache/karaf/features/internal/service/BundleInstallSupport.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/BundleInstallSupport.java b/features/core/src/main/java/org/apache/karaf/features/internal/service/BundleInstallSupport.java
index 8b0ffc4..5865592 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/BundleInstallSupport.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/BundleInstallSupport.java
@@ -69,6 +69,8 @@ public interface BundleInstallSupport {
File getDataFile(String name);
FrameworkInfo getInfo();
+
+ void unregister();
class FrameworkInfo {
public Bundle ourBundle;
http://git-wip-us.apache.org/repos/asf/karaf/blob/45fed936/features/core/src/main/java/org/apache/karaf/features/internal/service/BundleInstallSupportImpl.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/BundleInstallSupportImpl.java b/features/core/src/main/java/org/apache/karaf/features/internal/service/BundleInstallSupportImpl.java
index 4463465..232c57b 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/BundleInstallSupportImpl.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/BundleInstallSupportImpl.java
@@ -27,6 +27,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import org.apache.karaf.features.Feature;
@@ -73,7 +74,10 @@ public class BundleInstallSupportImpl implements BundleInstallSupport {
* take place.
*/
private final BundleContext systemBundleContext;
-
+
+ private Map<Thread, ResolverHook> hooks = new ConcurrentHashMap<>();
+ private ServiceRegistration<ResolverHookFactory> hookRegistration;
+
public BundleInstallSupportImpl(Bundle ourBundle,
BundleContext ourBundleContext,
BundleContext systemBundleContext,
@@ -84,6 +88,17 @@ public class BundleInstallSupportImpl implements BundleInstallSupport {
this.systemBundleContext = systemBundleContext;
this.configInstaller = configInstaller;
this.digraph = digraph;
+ if (systemBundleContext != null) {
+ hookRegistration = systemBundleContext.registerService(ResolverHookFactory.class,
+ triggers -> hooks.get(Thread.currentThread()), null);
+ }
+
+ }
+
+ public void unregister() {
+ if (hookRegistration != null) {
+ hookRegistration.unregister();
+ }
}
public void print(String message, boolean verbose) {
@@ -176,10 +191,16 @@ public class BundleInstallSupportImpl implements BundleInstallSupport {
}
Bundle sourceBundle = requirement.getRevision().getBundle();
Resource sourceResource = bndToRes.get(sourceBundle);
+ List<Wire> wires = wiring.get(sourceResource);
+ if (sourceBundle == null || wires == null) {
+ // This could be a bundle external to this resolution which
+ // is being resolve at the same time, so do not interfere
+ return;
+ }
Set<Resource> wired = new HashSet<>();
// Get a list of allowed wired resources
wired.add(sourceResource);
- for (Wire wire : wiring.get(sourceResource)) {
+ for (Wire wire : wires) {
wired.add(wire.getProvider());
if (HostNamespace.HOST_NAMESPACE.equals(wire.getRequirement().getNamespace())) {
for (Wire hostWire : wiring.get(wire.getProvider())) {
@@ -205,13 +226,12 @@ public class BundleInstallSupportImpl implements BundleInstallSupport {
public void end() {
}
};
- ResolverHookFactory factory = triggers -> hook;
- ServiceRegistration<ResolverHookFactory> registration = systemBundleContext.registerService(ResolverHookFactory.class, factory, null);
+ hooks.put(Thread.currentThread(), hook);
try {
FrameworkWiring frameworkWiring = systemBundleContext.getBundle().adapt(FrameworkWiring.class);
frameworkWiring.resolveBundles(bundles);
} finally {
- registration.unregister();
+ hooks.remove(Thread.currentThread());
}
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/45fed936/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 cf01a8f..4301448 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
@@ -155,7 +155,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
}
public void stop() {
- this.executor.shutdown();
+ this.executor.shutdown();
}
@SuppressWarnings({"unchecked", "rawtypes"})
http://git-wip-us.apache.org/repos/asf/karaf/blob/45fed936/features/core/src/main/java/org/apache/karaf/features/internal/service/StaticInstallSupport.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/StaticInstallSupport.java b/features/core/src/main/java/org/apache/karaf/features/internal/service/StaticInstallSupport.java
index eaecccb..30471a4 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/StaticInstallSupport.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/StaticInstallSupport.java
@@ -92,4 +92,8 @@ public abstract class StaticInstallSupport implements BundleInstallSupport {
return new FrameworkInfo();
}
+ @Override
+ public void unregister() {
+ }
+
}