You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by cs...@apache.org on 2015/04/13 10:00:20 UTC
[2/2] karaf git commit: Avoid dependency cycle
Avoid dependency cycle
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/6ebd5cc9
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/6ebd5cc9
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/6ebd5cc9
Branch: refs/heads/master
Commit: 6ebd5cc941a4b80b4b7987d9932ee22370c83dff
Parents: 0b713e6
Author: Christian Schneider <ch...@die-schneider.net>
Authored: Mon Apr 13 09:59:52 2015 +0200
Committer: Christian Schneider <ch...@die-schneider.net>
Committed: Mon Apr 13 09:59:52 2015 +0200
----------------------------------------------------------------------
.../karaf/features/internal/osgi/Activator.java | 5 +-
.../features/internal/region/DigraphHelper.java | 141 ++++++++++++++++++
.../internal/region/SubsystemResolver.java | 14 ++
.../internal/region/CollisionHookHelper.java | 29 ++++
.../equinox/internal/region/DigraphHelper.java | 146 -------------------
5 files changed, 187 insertions(+), 148 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/6ebd5cc9/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 2b29bf8..e9fd1b8 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
@@ -33,6 +33,7 @@ import org.apache.felix.utils.properties.Properties;
import org.apache.karaf.features.FeaturesListener;
import org.apache.karaf.features.FeaturesService;
import org.apache.karaf.features.internal.management.FeaturesServiceMBeanImpl;
+import org.apache.karaf.features.internal.region.DigraphHelper;
import org.apache.karaf.features.internal.repository.AggregateRepository;
import org.apache.karaf.features.internal.repository.JsonRepository;
import org.apache.karaf.features.internal.repository.XmlRepository;
@@ -45,7 +46,7 @@ import org.apache.karaf.util.tracker.BaseActivator;
import org.apache.karaf.util.tracker.annotation.ProvideService;
import org.apache.karaf.util.tracker.annotation.RequireService;
import org.apache.karaf.util.tracker.annotation.Services;
-import org.eclipse.equinox.internal.region.DigraphHelper;
+import org.eclipse.equinox.internal.region.CollisionHookHelper;
import org.eclipse.equinox.internal.region.StandardRegionDigraph;
import org.eclipse.equinox.internal.region.management.StandardManageableRegionDigraph;
import org.eclipse.equinox.region.RegionDigraph;
@@ -125,7 +126,7 @@ public class Activator extends BaseActivator {
// RegionDigraph
digraph = DigraphHelper.loadDigraph(bundleContext);
register(ResolverHookFactory.class, digraph.getResolverHookFactory());
- register(CollisionHook.class, DigraphHelper.getCollisionHook(digraph));
+ register(CollisionHook.class, CollisionHookHelper.getCollisionHook(digraph));
register(org.osgi.framework.hooks.bundle.FindHook.class, digraph.getBundleFindHook());
register(org.osgi.framework.hooks.bundle.EventHook.class, digraph.getBundleEventHook());
register(org.osgi.framework.hooks.service.FindHook.class, digraph.getServiceFindHook());
http://git-wip-us.apache.org/repos/asf/karaf/blob/6ebd5cc9/features/core/src/main/java/org/apache/karaf/features/internal/region/DigraphHelper.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/region/DigraphHelper.java b/features/core/src/main/java/org/apache/karaf/features/internal/region/DigraphHelper.java
new file mode 100644
index 0000000..3c71df6
--- /dev/null
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/region/DigraphHelper.java
@@ -0,0 +1,141 @@
+/*
+ * 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.region;
+
+import java.io.DataInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.karaf.features.internal.service.FeaturesServiceImpl;
+import org.apache.karaf.features.internal.util.JsonReader;
+import org.apache.karaf.features.internal.util.JsonWriter;
+import org.eclipse.equinox.internal.region.StandardRegionDigraph;
+import org.eclipse.equinox.region.Region;
+import org.eclipse.equinox.region.RegionDigraph;
+import org.eclipse.equinox.region.RegionFilterBuilder;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.InvalidSyntaxException;
+
+public final class DigraphHelper {
+
+ private static final String DIGRAPH_FILE = "digraph.json";
+
+ private static final String REGIONS = "regions";
+ private static final String EDGES = "edges";
+ private static final String TAIL = "tail";
+ private static final String HEAD = "head";
+ private static final String POLICY = "policy";
+
+ private DigraphHelper() {
+ }
+
+ public static StandardRegionDigraph loadDigraph(BundleContext bundleContext) throws BundleException, IOException, InvalidSyntaxException {
+ StandardRegionDigraph digraph;
+ ThreadLocal<Region> threadLocal = new ThreadLocal<>();
+ File digraphFile = bundleContext.getDataFile(DIGRAPH_FILE);
+ if (digraphFile == null || !digraphFile.exists()) {
+ digraph = new StandardRegionDigraph(bundleContext, threadLocal);
+ Region root = digraph.createRegion(FeaturesServiceImpl.ROOT_REGION);
+ for (Bundle bundle : bundleContext.getBundles()) {
+ root.addBundle(bundle);
+ }
+ } else {
+ try (
+ InputStream in = new FileInputStream(digraphFile)
+ ) {
+ digraph = readDigraph(new DataInputStream(in), bundleContext, threadLocal);
+ }
+ }
+ return digraph;
+ }
+
+ public static void saveDigraph(BundleContext bundleContext, RegionDigraph digraph) throws IOException {
+ File digraphFile = bundleContext.getDataFile(DIGRAPH_FILE);
+ try (
+ FileOutputStream out = new FileOutputStream(digraphFile)
+ ) {
+ saveDigraph(digraph, out);
+ } catch (Exception e) {
+ // Ignore
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ static StandardRegionDigraph readDigraph(InputStream in, BundleContext bundleContext, ThreadLocal<Region> threadLocal) throws IOException, BundleException, InvalidSyntaxException {
+ StandardRegionDigraph digraph = new StandardRegionDigraph(bundleContext, threadLocal);
+ Map json = (Map) JsonReader.read(in);
+ Map<String, Collection<Number>> regions = (Map<String, Collection<Number>>) json.get(REGIONS);
+ for (Map.Entry<String, Collection<Number>> rmap : regions.entrySet()) {
+ String name = rmap.getKey();
+ Region region = digraph.createRegion(name);
+ for (Number b : rmap.getValue()) {
+ region.addBundle(b.longValue());
+ }
+ }
+ List<Map<String, Object>> edges = (List<Map<String, Object>>) json.get(EDGES);
+ for (Map<String, Object> e : edges) {
+ String tail = (String) e.get(TAIL);
+ String head = (String) e.get(HEAD);
+ Map<String, Collection<String>> policy = (Map<String, Collection<String>>) e.get(POLICY);
+ RegionFilterBuilder builder = digraph.createRegionFilterBuilder();
+ for (Map.Entry<String, Collection<String>> rf : policy.entrySet()) {
+ String ns = rf.getKey();
+ for (String f : rf.getValue()) {
+ builder.allow(ns, f);
+ }
+ }
+ digraph.connect(digraph.getRegion(tail), builder.build(), digraph.getRegion(head));
+ }
+ return digraph;
+ }
+
+ static void saveDigraph(RegionDigraph digraph, OutputStream out) throws IOException {
+ Map<String, Object> json = new LinkedHashMap<>();
+ Map<String, Set<Long>> regions = new LinkedHashMap<>();
+ json.put(REGIONS, regions);
+ for (Region region : digraph.getRegions()) {
+ regions.put(region.getName(), region.getBundleIds());
+ }
+ List<Map<String, Object>> edges = new ArrayList<>();
+ json.put(EDGES, edges);
+ for (Region tail : digraph.getRegions()) {
+ for (RegionDigraph.FilteredRegion fr : digraph.getEdges(tail)) {
+ Map<String, Object> edge = new HashMap<>();
+ edge.put(TAIL, tail.getName());
+ edge.put(HEAD, fr.getRegion().getName());
+ edge.put(POLICY, fr.getFilter().getSharingPolicy());
+ edges.add(edge);
+
+ }
+ }
+ JsonWriter.write(out, json);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6ebd5cc9/features/core/src/main/java/org/apache/karaf/features/internal/region/SubsystemResolver.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/region/SubsystemResolver.java b/features/core/src/main/java/org/apache/karaf/features/internal/region/SubsystemResolver.java
index 78b1833..67d0adb 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/region/SubsystemResolver.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/region/SubsystemResolver.java
@@ -16,6 +16,8 @@
*/
package org.apache.karaf.features.internal.region;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -55,6 +57,7 @@ import org.slf4j.LoggerFactory;
import static org.apache.karaf.features.internal.resolver.ResourceUtils.TYPE_FEATURE;
import static org.apache.karaf.features.internal.resolver.ResourceUtils.TYPE_SUBSYSTEM;
+import static org.apache.karaf.features.internal.resolver.ResourceUtils.getUri;
import static org.apache.karaf.features.internal.util.MapUtils.invert;
import static org.osgi.framework.Constants.PROVIDE_CAPABILITY;
import static org.osgi.framework.namespace.ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE;
@@ -444,4 +447,15 @@ public class SubsystemResolver {
return result;
}
+ public InputStream getBundleInputStream(Resource resource) throws IOException {
+ String uri = getUri(resource);
+ if (uri == null) {
+ throw new IllegalStateException("Resource has no uri");
+ }
+ StreamProvider provider = manager.getProviders().get(uri);
+ if (provider == null) {
+ throw new IllegalStateException("Resource " + uri + " has no StreamProvider");
+ }
+ return provider.open();
+ }
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6ebd5cc9/features/core/src/main/java/org/eclipse/equinox/internal/region/CollisionHookHelper.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/eclipse/equinox/internal/region/CollisionHookHelper.java b/features/core/src/main/java/org/eclipse/equinox/internal/region/CollisionHookHelper.java
new file mode 100644
index 0000000..de8e13f
--- /dev/null
+++ b/features/core/src/main/java/org/eclipse/equinox/internal/region/CollisionHookHelper.java
@@ -0,0 +1,29 @@
+/*
+ * 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.eclipse.equinox.internal.region;
+
+import org.osgi.framework.hooks.bundle.CollisionHook;
+
+/**
+ * Hack to access CollisionHook as StandardRegionDigraph.getBundleCollisionHook() is
+ * not public
+ */
+public class CollisionHookHelper {
+ public static CollisionHook getCollisionHook(StandardRegionDigraph digraph) {
+ return (CollisionHook) digraph.getBundleCollisionHook();
+ }
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/6ebd5cc9/features/core/src/main/java/org/eclipse/equinox/internal/region/DigraphHelper.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/eclipse/equinox/internal/region/DigraphHelper.java b/features/core/src/main/java/org/eclipse/equinox/internal/region/DigraphHelper.java
deleted file mode 100644
index 76714c7..0000000
--- a/features/core/src/main/java/org/eclipse/equinox/internal/region/DigraphHelper.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * 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.eclipse.equinox.internal.region;
-
-import java.io.DataInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.karaf.features.internal.service.FeaturesServiceImpl;
-import org.apache.karaf.features.internal.util.JsonReader;
-import org.apache.karaf.features.internal.util.JsonWriter;
-import org.eclipse.equinox.region.Region;
-import org.eclipse.equinox.region.RegionDigraph;
-import org.eclipse.equinox.region.RegionFilterBuilder;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleException;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.hooks.bundle.CollisionHook;
-
-public final class DigraphHelper {
-
- private static final String DIGRAPH_FILE = "digraph.json";
-
- private static final String REGIONS = "regions";
- private static final String EDGES = "edges";
- private static final String TAIL = "tail";
- private static final String HEAD = "head";
- private static final String POLICY = "policy";
-
- private DigraphHelper() {
- }
-
- public static StandardRegionDigraph loadDigraph(BundleContext bundleContext) throws BundleException, IOException, InvalidSyntaxException {
- StandardRegionDigraph digraph;
- ThreadLocal<Region> threadLocal = new ThreadLocal<>();
- File digraphFile = bundleContext.getDataFile(DIGRAPH_FILE);
- if (digraphFile == null || !digraphFile.exists()) {
- digraph = new StandardRegionDigraph(bundleContext, threadLocal);
- Region root = digraph.createRegion(FeaturesServiceImpl.ROOT_REGION);
- for (Bundle bundle : bundleContext.getBundles()) {
- root.addBundle(bundle);
- }
- } else {
- try (
- InputStream in = new FileInputStream(digraphFile)
- ) {
- digraph = readDigraph(new DataInputStream(in), bundleContext, threadLocal);
- }
- }
- return digraph;
- }
-
- public static void saveDigraph(BundleContext bundleContext, RegionDigraph digraph) throws IOException {
- File digraphFile = bundleContext.getDataFile(DIGRAPH_FILE);
- try (
- FileOutputStream out = new FileOutputStream(digraphFile)
- ) {
- saveDigraph(digraph, out);
- } catch (Exception e) {
- // Ignore
- }
- }
-
- public static CollisionHook getCollisionHook(StandardRegionDigraph digraph) {
- return (CollisionHook) digraph.getBundleCollisionHook();
- }
-
-
- @SuppressWarnings("unchecked")
- static StandardRegionDigraph readDigraph(InputStream in, BundleContext bundleContext, ThreadLocal<Region> threadLocal) throws IOException, BundleException, InvalidSyntaxException {
- StandardRegionDigraph digraph = new StandardRegionDigraph(bundleContext, threadLocal);
- Map json = (Map) JsonReader.read(in);
- Map<String, Collection<Number>> regions = (Map<String, Collection<Number>>) json.get(REGIONS);
- for (Map.Entry<String, Collection<Number>> rmap : regions.entrySet()) {
- String name = rmap.getKey();
- Region region = digraph.createRegion(name);
- for (Number b : rmap.getValue()) {
- region.addBundle(b.longValue());
- }
- }
- List<Map<String, Object>> edges = (List<Map<String, Object>>) json.get(EDGES);
- for (Map<String, Object> e : edges) {
- String tail = (String) e.get(TAIL);
- String head = (String) e.get(HEAD);
- Map<String, Collection<String>> policy = (Map<String, Collection<String>>) e.get(POLICY);
- RegionFilterBuilder builder = digraph.createRegionFilterBuilder();
- for (Map.Entry<String, Collection<String>> rf : policy.entrySet()) {
- String ns = rf.getKey();
- for (String f : rf.getValue()) {
- builder.allow(ns, f);
- }
- }
- digraph.connect(digraph.getRegion(tail), builder.build(), digraph.getRegion(head));
- }
- return digraph;
- }
-
- static void saveDigraph(RegionDigraph digraph, OutputStream out) throws IOException {
- Map<String, Object> json = new LinkedHashMap<>();
- Map<String, Set<Long>> regions = new LinkedHashMap<>();
- json.put(REGIONS, regions);
- for (Region region : digraph.getRegions()) {
- regions.put(region.getName(), region.getBundleIds());
- }
- List<Map<String, Object>> edges = new ArrayList<>();
- json.put(EDGES, edges);
- for (Region tail : digraph.getRegions()) {
- for (RegionDigraph.FilteredRegion fr : digraph.getEdges(tail)) {
- Map<String, Object> edge = new HashMap<>();
- edge.put(TAIL, tail.getName());
- edge.put(HEAD, fr.getRegion().getName());
- edge.put(POLICY, fr.getFilter().getSharingPolicy());
- edges.add(edge);
-
- }
- }
- JsonWriter.write(out, json);
- }
-
-}