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 2014/04/25 14:40:58 UTC
[1/6] git commit: [KARAF-2888] Fix IllegalStateException if a bundle
has been manually installed and is later requested by a feature
Repository: karaf
Updated Branches:
refs/heads/master 2e1dbb7b5 -> 1c63a097e
[KARAF-2888] Fix IllegalStateException if a bundle has been manually installed and is later requested by a feature
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/1f563d5f
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/1f563d5f
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/1f563d5f
Branch: refs/heads/master
Commit: 1f563d5f59659c37fbb14033d8c3fe88bbb0d38b
Parents: 2e1dbb7
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Fri Apr 25 11:43:57 2014 +0200
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Fri Apr 25 11:43:57 2014 +0200
----------------------------------------------------------------------
.../features/internal/region/SubsystemResolveContext.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/1f563d5f/features/core/src/main/java/org/apache/karaf/features/internal/region/SubsystemResolveContext.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/region/SubsystemResolveContext.java b/features/core/src/main/java/org/apache/karaf/features/internal/region/SubsystemResolveContext.java
index 10be228..da435de 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/region/SubsystemResolveContext.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/region/SubsystemResolveContext.java
@@ -35,6 +35,7 @@ import org.eclipse.equinox.region.Region;
import org.eclipse.equinox.region.RegionDigraph;
import org.eclipse.equinox.region.RegionFilter;
import org.osgi.framework.BundleException;
+import org.osgi.framework.wiring.BundleRevision;
import org.osgi.resource.Capability;
import org.osgi.resource.Requirement;
import org.osgi.resource.Resource;
@@ -130,9 +131,8 @@ public class SubsystemResolveContext extends ResolveContext {
String r2 = getRegion(resource).getName();
int c = r1.compareTo(r2);
if (c == 0) {
- // This should never happen because resource have been
- // de-duplicated during the pre-resolution phase.
- throw new IllegalStateException();
+ // One of the resource has to be a bundle, use that one
+ c = (prev instanceof BundleRevision) ? -1 : +1;
}
resource = c < 0 ? prev : resource;
}
[5/6] git commit: [KARAF-2942] Require JDK7 for Karaf 4.x
Posted by gn...@apache.org.
[KARAF-2942] Require JDK7 for Karaf 4.x
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/67c4d86d
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/67c4d86d
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/67c4d86d
Branch: refs/heads/master
Commit: 67c4d86d152d12b60221d704833903854ab2a448
Parents: 09a5e99
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Fri Apr 25 14:28:41 2014 +0200
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Fri Apr 25 14:28:41 2014 +0200
----------------------------------------------------------------------
pom.xml | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/67c4d86d/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index bd74e51..43c3b5c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -2080,8 +2080,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
- <source>1.6</source>
- <target>1.6</target>
+ <source>1.7</source>
+ <target>1.7</target>
<maxmem>256M</maxmem>
<fork>${compiler.fork}</fork>
</configuration>
@@ -2101,7 +2101,7 @@
<version>3.0.2</version>
</requireMavenVersion>
<requireJavaVersion>
- <version>[1.6,1.9)</version>
+ <version>[1.7,1.9)</version>
</requireJavaVersion>
</rules>
</configuration>
[3/6] git commit: Remove service.guard from framework-security
feature, it has its own service-security feature
Posted by gn...@apache.org.
Remove service.guard from framework-security feature, it has its own service-security feature
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/bbaa966c
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/bbaa966c
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/bbaa966c
Branch: refs/heads/master
Commit: bbaa966cf52d361cd825f905d660634fcbb60f37
Parents: 1ea7beb
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Fri Apr 25 11:46:20 2014 +0200
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Fri Apr 25 11:46:20 2014 +0200
----------------------------------------------------------------------
assemblies/features/standard/src/main/feature/feature.xml | 1 -
1 file changed, 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/bbaa966c/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 f7fcb67..1ff2fb0 100644
--- a/assemblies/features/standard/src/main/feature/feature.xml
+++ b/assemblies/features/standard/src/main/feature/feature.xml
@@ -22,7 +22,6 @@
<feature version="${project.version}" description="OSGi Security for Karaf" name="framework-security">
<bundle start="false" start-level="1">mvn:org.apache.felix/org.apache.felix.framework.security/${felix.framework.security.version}</bundle>
- <bundle start="true" start-level="10">mvn:org.apache.karaf.service/org.apache.karaf.service.guard/${project.version}</bundle>
</feature>
<feature version="${project.version}" description="Services Security for Karaf" name="service-security">
[6/6] git commit: [KARAF-2942] Switch features/core to JDK 7
Posted by gn...@apache.org.
[KARAF-2942] Switch features/core to JDK 7
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/1c63a097
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/1c63a097
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/1c63a097
Branch: refs/heads/master
Commit: 1c63a097eda230369e8d9c5ac86b426d9232550f
Parents: 67c4d86
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Fri Apr 25 14:29:15 2014 +0200
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Fri Apr 25 14:29:15 2014 +0200
----------------------------------------------------------------------
.../download/simple/SimpleDownloader.java | 7 +-
.../internal/region/SubsystemResolver.java | 10 +-
.../features/internal/repository/UrlLoader.java | 7 +-
.../service/FeatureConfigInstaller.java | 38 ++---
.../internal/service/FeaturesServiceImpl.java | 137 ++++++++++---------
.../features/internal/service/Overrides.java | 7 +-
.../internal/service/RepositoryImpl.java | 36 ++---
.../features/internal/service/StateStorage.java | 29 ++--
.../features/internal/util/ChecksumUtils.java | 51 ++++---
.../karaf/features/internal/util/MapUtils.java | 18 +--
.../equinox/internal/region/DigraphHelper.java | 28 ++--
11 files changed, 177 insertions(+), 191 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/1c63a097/features/core/src/main/java/org/apache/karaf/features/internal/download/simple/SimpleDownloader.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/download/simple/SimpleDownloader.java b/features/core/src/main/java/org/apache/karaf/features/internal/download/simple/SimpleDownloader.java
index 1255fb6..11b20cd 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/download/simple/SimpleDownloader.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/download/simple/SimpleDownloader.java
@@ -101,8 +101,9 @@ public class SimpleDownloader implements DownloadManager, Downloader {
}
protected Map<String, String> doGetMetadata() throws IOException {
- InputStream is = open();
- try {
+ try (
+ InputStream is = open()
+ ) {
ZipInputStream zis = new ZipInputStream(is);
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
@@ -115,8 +116,6 @@ public class SimpleDownloader implements DownloadManager, Downloader {
return headers;
}
}
- } finally {
- is.close();
}
throw new IllegalArgumentException("Resource " + url + " does not contain a manifest");
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/1c63a097/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 a6355d2..0478125 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
@@ -160,7 +160,7 @@ public class SubsystemResolver {
public Map<String, Map<String, BundleInfo>> getBundleInfos() {
if (bundleInfos == null) {
- bundleInfos = new HashMap<String, Map<String, BundleInfo>>();
+ bundleInfos = new HashMap<>();
addBundleInfos(root);
}
return bundleInfos;
@@ -170,7 +170,7 @@ public class SubsystemResolver {
String region = getFlatSubsystemsMap().get(subsystem.getName());
Map<String, BundleInfo> bis = bundleInfos.get(region);
if (bis == null) {
- bis = new HashMap<String, BundleInfo>();
+ bis = new HashMap<>();
bundleInfos.put(region, bis);
}
bis.putAll(subsystem.getBundleInfos());
@@ -222,7 +222,7 @@ public class SubsystemResolver {
public Map<String, String> getFlatSubsystemsMap() {
if (flatSubsystemsMap == null) {
- flatSubsystemsMap = new HashMap<String, String>();
+ flatSubsystemsMap = new HashMap<>();
findSubsystemsToFlatten(root, flatSubsystemsMap);
}
return flatSubsystemsMap;
@@ -266,7 +266,7 @@ public class SubsystemResolver {
private Map<Resource, String> getResourceMapping(SimpleFilter resourceFilter) {
Map<String, String> flats = getFlatSubsystemsMap();
Map<Resource, List<Wire>> wiring = getWiring();
- Map<Resource, String> resources = new HashMap<Resource, String>();
+ Map<Resource, String> resources = new HashMap<>();
SimpleFilter sf = createFilter(IDENTITY_NAMESPACE, "*",
CAPABILITY_TYPE_ATTRIBUTE, TYPE_SUBSYSTEM);
for (Resource resource : wiring.keySet()) {
@@ -349,7 +349,7 @@ public class SubsystemResolver {
}
private SimpleFilter createFilter(String... s) {
- Map<String, Object> attrs = new HashMap<String, Object>();
+ Map<String, Object> attrs = new HashMap<>();
for (int i = 0; i < s.length - 1; i += 2) {
attrs.put(s[i], s[i+1]);
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/1c63a097/features/core/src/main/java/org/apache/karaf/features/internal/repository/UrlLoader.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/repository/UrlLoader.java b/features/core/src/main/java/org/apache/karaf/features/internal/repository/UrlLoader.java
index 8bed863..77db247 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/repository/UrlLoader.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/repository/UrlLoader.java
@@ -61,8 +61,9 @@ public abstract class UrlLoader {
if (lm <= lastModified) {
return false;
}
- BufferedInputStream bis = new BufferedInputStream(connection.getInputStream());
- try {
+ try (
+ BufferedInputStream bis = new BufferedInputStream(connection.getInputStream())
+ ) {
// Auto-detect gzipped streams
InputStream is = bis;
bis.mark(512);
@@ -75,8 +76,6 @@ public abstract class UrlLoader {
boolean r = doRead(is);
lastModified = lm;
return r;
- } finally {
- bis.close();
}
} catch (IOException e) {
throw new RuntimeException(e);
http://git-wip-us.apache.org/repos/asf/karaf/blob/1c63a097/features/core/src/main/java/org/apache/karaf/features/internal/service/FeatureConfigInstaller.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeatureConfigInstaller.java b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeatureConfigInstaller.java
index 258b44b..a42dab2 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeatureConfigInstaller.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeatureConfigInstaller.java
@@ -128,40 +128,28 @@ public class FeatureConfigInstaller {
LOGGER.info("Creating configuration file {}", finalname);
}
- InputStream is = null;
- FileOutputStream fop = null;
- try {
- is = new BufferedInputStream(new URL(fileLocation).openStream());
-
+ try (
+ InputStream is = new BufferedInputStream(new URL(fileLocation).openStream())
+ ) {
if (!file.exists()) {
File parentFile = file.getParentFile();
if (parentFile != null)
parentFile.mkdirs();
file.createNewFile();
}
+ try (
+ FileOutputStream fop = new FileOutputStream(file)
+ ) {
+ int bytesRead;
+ byte[] buffer = new byte[1024];
- fop = new FileOutputStream(file);
-
- int bytesRead;
- byte[] buffer = new byte[1024];
-
- while ((bytesRead = is.read(buffer)) != -1) {
- fop.write(buffer, 0, bytesRead);
+ while ((bytesRead = is.read(buffer)) != -1) {
+ fop.write(buffer, 0, bytesRead);
+ }
}
- } catch (RuntimeException e) {
+ } catch (RuntimeException | MalformedURLException e) {
LOGGER.error(e.getMessage());
throw e;
- } catch (MalformedURLException e) {
- LOGGER.error(e.getMessage());
- throw e;
- } finally {
- if (is != null)
- is.close();
- if (fop != null) {
- fop.flush();
- fop.close();
- }
- }
-
+ }
}
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/1c63a097/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 eafd08e..054c615 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
@@ -168,7 +168,7 @@ public class FeaturesServiceImpl implements FeaturesService {
// Synchronized on lock
private final Object lock = new Object();
private final State state = new State();
- private final Map<String, Repository> repositoryCache = new HashMap<String, Repository>();
+ private final Map<String, Repository> repositoryCache = new HashMap<>();
private Map<String, Map<String, Feature>> featureCache;
@@ -249,8 +249,8 @@ public class FeaturesServiceImpl implements FeaturesService {
public void registerListener(FeaturesListener listener) {
listeners.add(listener);
try {
- Set<String> repositories = new TreeSet<String>();
- Set<String> installedFeatures = new TreeSet<String>();
+ Set<String> repositories = new TreeSet<>();
+ Set<String> installedFeatures = new TreeSet<>();
synchronized (lock) {
repositories.addAll(state.repositories);
installedFeatures.addAll(state.installedFeatures.keySet());
@@ -362,7 +362,7 @@ public class FeaturesServiceImpl implements FeaturesService {
// Clean cache
featureCache = null;
repo = repositoryCache.get(uri.toString());
- List<String> toRemove = new ArrayList<String>();
+ List<String> toRemove = new ArrayList<>();
toRemove.add(uri.toString());
while (!toRemove.isEmpty()) {
Repository rep = repositoryCache.remove(toRemove.remove(0));
@@ -404,7 +404,7 @@ public class FeaturesServiceImpl implements FeaturesService {
// Make sure the cache is loaded
getFeatures();
synchronized (lock) {
- List<Repository> repos = new ArrayList<Repository>();
+ List<Repository> repos = new ArrayList<>();
for (Map.Entry<String, Repository> entry : repositoryCache.entrySet()) {
if (state.repositories.contains(entry.getKey())) {
repos.add(entry.getValue());
@@ -473,7 +473,7 @@ public class FeaturesServiceImpl implements FeaturesService {
}
public Feature[] listFeatures() throws Exception {
- Set<Feature> features = new HashSet<Feature>();
+ Set<Feature> features = new HashSet<>();
for (Map<String, Feature> featureWithDifferentVersion : getFeatures().values()) {
for (Feature f : featureWithDifferentVersion.values()) {
features.add(f);
@@ -488,13 +488,13 @@ public class FeaturesServiceImpl implements FeaturesService {
if (featureCache != null) {
return featureCache;
}
- uris = new ArrayList<String>(state.repositories);
+ uris = new ArrayList<>(state.repositories);
}
//the outer map's key is feature name, the inner map's key is feature version
- Map<String, Map<String, Feature>> map = new HashMap<String, Map<String, Feature>>();
+ Map<String, Map<String, Feature>> map = new HashMap<>();
// Two phase load:
// * first load dependent repositories
- List<String> toLoad = new ArrayList<String>(uris);
+ List<String> toLoad = new ArrayList<>(uris);
while (!toLoad.isEmpty()) {
String uri = toLoad.remove(0);
Repository repo;
@@ -515,13 +515,13 @@ public class FeaturesServiceImpl implements FeaturesService {
}
List<Repository> repos;
synchronized (lock) {
- repos = new ArrayList<Repository>(repositoryCache.values());
+ repos = new ArrayList<>(repositoryCache.values());
}
// * then load all features
for (Repository repo : repos) {
for (Feature f : repo.getFeatures()) {
if (map.get(f.getName()) == null) {
- Map<String, Feature> versionMap = new HashMap<String, Feature>();
+ Map<String, Feature> versionMap = new HashMap<>();
versionMap.put(f.getVersion(), f);
map.put(f.getName(), versionMap);
} else {
@@ -544,7 +544,7 @@ public class FeaturesServiceImpl implements FeaturesService {
@Override
public Feature[] listInstalledFeatures() throws Exception {
- Set<Feature> features = new HashSet<Feature>();
+ Set<Feature> features = new HashSet<>();
Map<String, Map<String, Feature>> allFeatures = getFeatures();
synchronized (lock) {
for (Map<String, Feature> featureWithDifferentVersion : allFeatures.values()) {
@@ -560,7 +560,7 @@ public class FeaturesServiceImpl implements FeaturesService {
@Override
public Feature[] listRequiredFeatures() throws Exception {
- Set<Feature> features = new HashSet<Feature>();
+ Set<Feature> features = new HashSet<>();
Map<String, Map<String, Feature>> allFeatures = getFeatures();
synchronized (lock) {
for (Map<String, Feature> featureWithDifferentVersion : allFeatures.values()) {
@@ -669,7 +669,7 @@ public class FeaturesServiceImpl implements FeaturesService {
if (region == null || region.isEmpty()) {
region = ROOT_REGION;
}
- List<String> featuresToAdd = new ArrayList<String>();
+ List<String> featuresToAdd = new ArrayList<>();
Map<String, Map<String, Feature>> featuresMap = getFeatures();
for (String feature : features) {
feature = normalize(feature);
@@ -685,7 +685,7 @@ public class FeaturesServiceImpl implements FeaturesService {
featuresToAdd.add(req);
}
}
- featuresToAdd = new ArrayList<String>(new LinkedHashSet<String>(featuresToAdd));
+ featuresToAdd = new ArrayList<>(new LinkedHashSet<>(featuresToAdd));
StringBuilder sb = new StringBuilder();
sb.append("Adding features: ");
for (int i = 0; i < featuresToAdd.size(); i++) {
@@ -697,7 +697,7 @@ public class FeaturesServiceImpl implements FeaturesService {
print(sb.toString(), options.contains(Option.Verbose));
Set<String> fl = required.get(region);
if (fl == null) {
- fl = new HashSet<String>();
+ fl = new HashSet<>();
required.put(region,fl);
}
fl.addAll(featuresToAdd);
@@ -712,12 +712,12 @@ public class FeaturesServiceImpl implements FeaturesService {
}
Set<String> fl = required.get(region);
if (fl == null) {
- fl = new HashSet<String>();
+ fl = new HashSet<>();
required.put(region, fl);
}
- List<String> featuresToRemove = new ArrayList<String>();
- for (String feature : new HashSet<String>(features)) {
- List<String> toRemove = new ArrayList<String>();
+ List<String> featuresToRemove = new ArrayList<>();
+ for (String feature : new HashSet<>(features)) {
+ List<String> toRemove = new ArrayList<>();
feature = normalize(feature);
if (feature.endsWith("/0.0.0")) {
String nameSep = feature.substring(0, feature.indexOf("/") + 1);
@@ -750,7 +750,7 @@ public class FeaturesServiceImpl implements FeaturesService {
}
featuresToRemove.addAll(toRemove);
}
- featuresToRemove = new ArrayList<String>(new LinkedHashSet<String>(featuresToRemove));
+ featuresToRemove = new ArrayList<>(new LinkedHashSet<>(featuresToRemove));
StringBuilder sb = new StringBuilder();
sb.append("Removing features: ");
for (int i = 0; i < featuresToRemove.size(); i++) {
@@ -827,12 +827,12 @@ public class FeaturesServiceImpl implements FeaturesService {
protected DeploymentState getDeploymentState() throws Exception {
DeploymentState state = new DeploymentState();
// Bundles
- state.bundles = new HashMap<Long, Bundle>();
+ state.bundles = new HashMap<>();
for (Bundle bundle : systemBundleContext.getBundles()) {
state.bundles.put(bundle.getBundleId(), bundle);
}
// Features
- state.features = new HashMap<String, Feature>();
+ state.features = new HashMap<>();
for (Map<String, Feature> m : getFeatures().values()) {
for (Feature feature : m.values()) {
String id = feature.getName() + "/" + VersionTable.getVersion(feature.getVersion());
@@ -841,16 +841,16 @@ public class FeaturesServiceImpl implements FeaturesService {
}
// Region -> bundles mapping
// Region -> policy mapping
- state.bundlesPerRegion = new HashMap<String, Set<Long>>();
- state.filtersPerRegion = new HashMap<String, Map<String, Map<String, Set<String>>>>();
+ state.bundlesPerRegion = new HashMap<>();
+ state.filtersPerRegion = new HashMap<>();
RegionDigraph clone = digraph.copy();
for (Region region : clone.getRegions()) {
// Get bundles
- state.bundlesPerRegion.put(region.getName(), new HashSet<Long>(region.getBundleIds()));
+ state.bundlesPerRegion.put(region.getName(), new HashSet<>(region.getBundleIds()));
// Get policies
- Map<String, Map<String, Set<String>>> edges = new HashMap<String, Map<String, Set<String>>>();
+ Map<String, Map<String, Set<String>>> edges = new HashMap<>();
for (RegionDigraph.FilteredRegion fr : clone.getEdges(region)) {
- Map<String, Set<String>> policy = new HashMap<String, Set<String>>();
+ Map<String, Set<String>> policy = new HashMap<>();
Map<String, Collection<String>> current = fr.getFilter().getSharingPolicy();
for (String ns : current.keySet()) {
for (String f : current.get(ns)) {
@@ -910,7 +910,7 @@ public class FeaturesServiceImpl implements FeaturesService {
// Get all resources that will be used to satisfy the old features set
// If noStart is true, we don't want to start the newly installed features
// but we still want old features to be started.
- Set<Resource> resourceLinkedToOldFeatures = new HashSet<Resource>();
+ Set<Resource> resourceLinkedToOldFeatures = new HashSet<>();
if (noStart) {
for (Map.Entry<String, Set<Resource>> entry : featuresPerRegion.entrySet()) {
String region = entry.getKey();
@@ -931,7 +931,7 @@ public class FeaturesServiceImpl implements FeaturesService {
//
// Compute the set of bundles to refresh
//
- Set<Bundle> toRefresh = new TreeSet<Bundle>(new BundleComparator()); // sort is only used for display
+ Set<Bundle> toRefresh = new TreeSet<>(new BundleComparator()); // sort is only used for display
for (RegionDeployment regionDeployment : deployment.regions.values()) {
toRefresh.addAll(regionDeployment.toDelete);
toRefresh.addAll(regionDeployment.toUpdate.keySet());
@@ -946,11 +946,11 @@ public class FeaturesServiceImpl implements FeaturesService {
// Automatically turn unmanaged bundles into managed bundles
// if they are required by a feature and no other unmanaged
// bundles have a requirement on it
- Set<Bundle> toManage = new TreeSet<Bundle>(new BundleComparator()); // sort is only used for display
+ Set<Bundle> toManage = new TreeSet<>(new BundleComparator()); // sort is only used for display
if (!noManageBundles) {
Set<Resource> features = resolver.getFeatures().keySet();
Set<? extends Resource> unmanaged = apply(flatten(unmanagedBundles), adapt(BundleRevision.class));
- Set<Resource> requested = new HashSet<Resource>();
+ Set<Resource> requested = new HashSet<>();
// Gather bundles required by a feature
for (List<Wire> wires : resolver.getWiring().values()) {
for (Wire wire : wires) {
@@ -970,7 +970,7 @@ public class FeaturesServiceImpl implements FeaturesService {
}
}
if (!requested.isEmpty()) {
- Map<Long, String> bundleToRegion = new HashMap<Long, String>();
+ Map<Long, String> bundleToRegion = new HashMap<>();
for (Map.Entry<String, Set<Long>> entry : dstate.bundlesPerRegion.entrySet()) {
for (long id : entry.getValue()) {
bundleToRegion.put(id, entry.getKey());
@@ -1006,9 +1006,9 @@ public class FeaturesServiceImpl implements FeaturesService {
return;
}
- Set<Bundle> toStart = new HashSet<Bundle>();
- Set<Bundle> toResolve = new HashSet<Bundle>();
- Set<Bundle> toStop = new HashSet<Bundle>();
+ Set<Bundle> toStart = new HashSet<>();
+ Set<Bundle> toResolve = new HashSet<>();
+ Set<Bundle> toStop = new HashSet<>();
//
// Execute deployment
@@ -1044,7 +1044,7 @@ public class FeaturesServiceImpl implements FeaturesService {
//
// Find start levels to update
//
- Map<Bundle, Integer> toUpdateStartLevel = new HashMap<Bundle, Integer>();
+ Map<Bundle, Integer> toUpdateStartLevel = new HashMap<>();
{
FrameworkStartLevel fsl = systemBundleContext.getBundle().adapt(FrameworkStartLevel.class);
for (Map.Entry<Resource, String> entry : resolver.getBundles().entrySet()) {
@@ -1142,12 +1142,12 @@ public class FeaturesServiceImpl implements FeaturesService {
String name = computedRegion.getName();
Map<String, Map<String, Set<String>>> policy = policies.get(name);
if (policy == null) {
- policy = new HashMap<String, Map<String, Set<String>>>();
+ policy = new HashMap<>();
policies.put(name, policy);
}
for (RegionDigraph.FilteredRegion fr : computedDigraph.getEdges(computedRegion)) {
String r2 = fr.getRegion().getName();
- Map<String, Set<String>> filters = new HashMap<String, Set<String>>();
+ Map<String, Set<String>> filters = new HashMap<>();
Map<String, Collection<String>> current = fr.getFilter().getSharingPolicy();
for (String ns : current.keySet()) {
for (String f : current.get(ns)) {
@@ -1248,19 +1248,24 @@ public class FeaturesServiceImpl implements FeaturesService {
for (Resource resource : regionDeployment.toInstall) {
String uri = getUri(resource);
print(" " + uri, verbose);
- InputStream is = getBundleInputStream(resource, providers);
Bundle bundle;
- if (ROOT_REGION.equals(name)) {
- bundle = region.installBundleAtLocation(uri, is);
- } else {
- bundle = region.installBundle(uri, is);
+ long crc;
+ try (
+ ChecksumUtils.CRCInputStream is = new ChecksumUtils.CRCInputStream (getBundleInputStream(resource, providers))
+ ) {
+ if (ROOT_REGION.equals(name)) {
+ bundle = region.installBundleAtLocation(uri, is);
+ } else {
+ bundle = region.installBundle(uri, is);
+ }
+ crc = is.getCRC();
}
addToMapSet(managedBundles, name, bundle.getBundleId());
deployment.resToBnd.put(resource, bundle);
// save a checksum of installed snapshot bundle
if (UPDATE_SNAPSHOTS_CRC.equals(updateSnaphots)
&& isUpdateable(resource) && !deployment.bundleChecksums.containsKey(bundle.getBundleId())) {
- deployment.bundleChecksums.put(bundle.getBundleId(), ChecksumUtils.checksum(getBundleInputStream(resource, providers)));
+ deployment.bundleChecksums.put(bundle.getBundleId(), crc);
}
BundleInfo bi = bundleInfos.get(entry.getKey()).get(uri);
if (bi != null && bi.getStartLevel() > 0) {
@@ -1308,7 +1313,7 @@ public class FeaturesServiceImpl implements FeaturesService {
RequirementSort.sort(Collections.<Resource>emptyList());
if (!noRefresh) {
- toStop = new HashSet<Bundle>();
+ toStop = new HashSet<>();
toStop.addAll(toRefresh);
removeFragmentsAndBundlesInState(toStop, UNINSTALLED | RESOLVED | STOPPING);
if (!toStop.isEmpty()) {
@@ -1345,7 +1350,7 @@ public class FeaturesServiceImpl implements FeaturesService {
removeFragmentsAndBundlesInState(toStart, UNINSTALLED | ACTIVE | STARTING);
if (!toStart.isEmpty()) {
// Compute correct start order
- List<Exception> exceptions = new ArrayList<Exception>();
+ List<Exception> exceptions = new ArrayList<>();
print("Starting bundles:", verbose);
while (!toStart.isEmpty()) {
List<Bundle> bs = getBundlesToStart(toStart);
@@ -1484,7 +1489,7 @@ public class FeaturesServiceImpl implements FeaturesService {
Map<String, Set<Resource>> bundlesPerRegions = resolver.getBundlesPerRegions();
// Gather all regions, including old ones and new ones
- Set<String> regions = new HashSet<String>();
+ Set<String> regions = new HashSet<>();
regions.addAll(state.managedBundles.keySet());
regions.addAll(bundlesPerRegions.keySet());
@@ -1501,7 +1506,7 @@ public class FeaturesServiceImpl implements FeaturesService {
// Compute the list of resources to deploy in the region
Set<Resource> bundlesInRegion = bundlesPerRegions.get(region);
List<Resource> toDeploy = bundlesInRegion != null
- ? new ArrayList<Resource>(bundlesInRegion) : new ArrayList<Resource>();
+ ? new ArrayList<>(bundlesInRegion) : new ArrayList<Resource>();
// First pass: go through all installed bundles and mark them
// as either to ignore or delete
@@ -1531,9 +1536,9 @@ public class FeaturesServiceImpl implements FeaturesService {
deployment.toUpdate.put(bundle, resource);
} else if (UPDATE_SNAPSHOTS_CRC.equalsIgnoreCase(updateSnaphots)) {
// if the checksum are different
- InputStream is = null;
- try {
- is = getBundleInputStream(resource, resolver.getProviders());
+ try (
+ InputStream is = getBundleInputStream(resource, resolver.getProviders())
+ ) {
long newCrc = ChecksumUtils.checksum(is);
long oldCrc = state.bundleChecksums.containsKey(bundle.getBundleId()) ? state.bundleChecksums.get(bundle.getBundleId()) : 0l;
if (newCrc != oldCrc) {
@@ -1541,10 +1546,6 @@ public class FeaturesServiceImpl implements FeaturesService {
deployment.toUpdate.put(bundle, resource);
}
result.bundleChecksums.put(bundle.getBundleId(), newCrc);
- } finally {
- if (is != null) {
- is.close();
- }
}
}
}
@@ -1561,7 +1562,7 @@ public class FeaturesServiceImpl implements FeaturesService {
// Second pass on remaining resources
for (Resource resource : toDeploy) {
- TreeMap<Version, Bundle> matching = new TreeMap<Version, Bundle>();
+ TreeMap<Version, Bundle> matching = new TreeMap<>();
VersionRange range = new VersionRange(Macro.transform(bundleUpdateRange, getVersion(resource).toString()));
for (Bundle bundle : deployment.toDelete) {
if (bundle.getSymbolicName().equals(getSymbolicName(resource)) && range.contains(bundle.getVersion())) {
@@ -1621,7 +1622,7 @@ public class FeaturesServiceImpl implements FeaturesService {
// so that we don't end up with the service trying to do stuff before we're done
boolean restart = bundles.remove(bundle);
- SortedMap<Integer, Set<Bundle>> bundlesPerStartLevel = new TreeMap<Integer, Set<Bundle>>();
+ SortedMap<Integer, Set<Bundle>> bundlesPerStartLevel = new TreeMap<>();
for (Bundle bundle : bundles) {
int sl = bundle.adapt(BundleStartLevel.class).getStartLevel();
addToMapSet(bundlesPerStartLevel, sl, bundle);
@@ -1633,11 +1634,11 @@ public class FeaturesServiceImpl implements FeaturesService {
// are given back by the resolution, meaning that all root bundles (i.e. those that were
// not flagged as dependencies in features) are started before the others. This should
// make sure those important bundles are started first and minimize the problem.
- List<BundleRevision> revs = new ArrayList<BundleRevision>();
+ List<BundleRevision> revs = new ArrayList<>();
for (Bundle bundle : bundles) {
revs.add(bundle.adapt(BundleRevision.class));
}
- List<Bundle> sorted = new ArrayList<Bundle>();
+ List<Bundle> sorted = new ArrayList<>();
for (BundleRevision rev : RequirementSort.sort(revs)) {
sorted.add(rev.getBundle());
}
@@ -1648,14 +1649,14 @@ public class FeaturesServiceImpl implements FeaturesService {
}
protected List<Bundle> getBundlesToStop(Collection<Bundle> bundles) {
- SortedMap<Integer, Set<Bundle>> bundlesPerStartLevel = new TreeMap<Integer, Set<Bundle>>();
+ SortedMap<Integer, Set<Bundle>> bundlesPerStartLevel = new TreeMap<>();
for (Bundle bundle : bundles) {
int sl = bundle.adapt(BundleStartLevel.class).getStartLevel();
addToMapSet(bundlesPerStartLevel, sl, bundle);
}
bundles = bundlesPerStartLevel.get(bundlesPerStartLevel.lastKey());
- List<Bundle> bundlesToDestroy = new ArrayList<Bundle>();
+ List<Bundle> bundlesToDestroy = new ArrayList<>();
for (Bundle bundle : bundles) {
ServiceReference[] references = bundle.getRegisteredServices();
int usage = 0;
@@ -1740,15 +1741,15 @@ public class FeaturesServiceImpl implements FeaturesService {
static class Deployment {
- Map<Long, Long> bundleChecksums = new HashMap<Long, Long>();
- Map<Resource, Bundle> resToBnd = new HashMap<Resource, Bundle>();
- Map<String, RegionDeployment> regions = new HashMap<String, RegionDeployment>();
+ Map<Long, Long> bundleChecksums = new HashMap<>();
+ Map<Resource, Bundle> resToBnd = new HashMap<>();
+ Map<String, RegionDeployment> regions = new HashMap<>();
}
static class RegionDeployment {
- List<Resource> toInstall = new ArrayList<Resource>();
- List<Bundle> toDelete = new ArrayList<Bundle>();
- Map<Bundle, Resource> toUpdate = new HashMap<Bundle, Resource>();
+ List<Resource> toInstall = new ArrayList<>();
+ List<Bundle> toDelete = new ArrayList<>();
+ Map<Bundle, Resource> toUpdate = new HashMap<>();
}
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/1c63a097/features/core/src/main/java/org/apache/karaf/features/internal/service/Overrides.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/Overrides.java b/features/core/src/main/java/org/apache/karaf/features/internal/service/Overrides.java
index 238b007..0e02871 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/Overrides.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/Overrides.java
@@ -101,8 +101,9 @@ public class Overrides {
Set<String> overrides = new HashSet<String>();
try {
if (overridesUrl != null) {
- InputStream is = new URL(overridesUrl).openStream();
- try {
+ try (
+ InputStream is = new URL(overridesUrl).openStream()
+ ) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String line;
while ((line = reader.readLine()) != null) {
@@ -111,8 +112,6 @@ public class Overrides {
overrides.add(line);
}
}
- } finally {
- is.close();
}
}
} catch (Exception e) {
http://git-wip-us.apache.org/repos/asf/karaf/blob/1c63a097/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryImpl.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryImpl.java b/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryImpl.java
index 9c2f2b6..2b32161 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryImpl.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryImpl.java
@@ -70,29 +70,29 @@ public class RepositoryImpl implements Repository {
public void load(boolean validate) throws IOException {
if (features == null) {
- try {
- InputStream inputStream = uri.toURL().openStream();
- inputStream = new FilterInputStream(inputStream) {
- @Override
- public int read(byte[] b, int off, int len) throws IOException {
- if (Thread.currentThread().isInterrupted()) {
- throw new InterruptedIOException();
- }
- return super.read(b, off, len);
- }
- };
- try {
- features = JaxbUtil.unmarshal(uri.toASCIIString(), inputStream, validate);
- } finally {
- inputStream.close();
- }
- } catch (IllegalArgumentException e) {
- throw (IOException) new IOException(e.getMessage() + " : " + uri).initCause(e);
+ try (
+ InputStream inputStream = new InterruptibleInputStream(uri.toURL().openStream())
+ ) {
+ features = JaxbUtil.unmarshal(uri.toASCIIString(), inputStream, validate);
} catch (Exception e) {
throw (IOException) new IOException(e.getMessage() + " : " + uri).initCause(e);
}
}
}
+ static class InterruptibleInputStream extends FilterInputStream {
+ InterruptibleInputStream(InputStream in) {
+ super(in);
+ }
+
+ @Override
+ public int read(byte[] b, int off, int len) throws IOException {
+ if (Thread.currentThread().isInterrupted()) {
+ throw new InterruptedIOException();
+ }
+ return super.read(b, off, len);
+ }
+ }
+
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/1c63a097/features/core/src/main/java/org/apache/karaf/features/internal/service/StateStorage.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/StateStorage.java b/features/core/src/main/java/org/apache/karaf/features/internal/service/StateStorage.java
index 1b0a728..a509a9d 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/StateStorage.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/StateStorage.java
@@ -16,7 +16,6 @@
*/
package org.apache.karaf.features.internal.service;
-import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -36,9 +35,10 @@ public abstract class StateStorage {
state.requestedFeatures.clear();
state.installedFeatures.clear();
state.managedBundles.clear();
- InputStream is = getInputStream();
- if (is != null) {
- try {
+ try (
+ InputStream is = getInputStream()
+ ) {
+ if (is != null) {
Map json = (Map) JsonReader.read(is);
state.bootDone.set((Boolean) json.get("bootDone"));
state.repositories.addAll(toStringSet((Collection) json.get("repositories")));
@@ -46,16 +46,15 @@ public abstract class StateStorage {
state.installedFeatures.putAll(toStringStringSetMap((Map) json.get("installed")));
state.managedBundles.putAll(toStringLongSetMap((Map) json.get("managed")));
state.bundleChecksums.putAll(toLongLongMap((Map) json.get("checksums")));
- } finally {
- close(is);
}
}
}
public void save(State state) throws IOException {
- OutputStream os = getOutputStream();
- if (os != null) {
- try {
+ try (
+ OutputStream os = getOutputStream()
+ ) {
+ if (os != null) {
Map<String, Object> json = new HashMap<String, Object>();
json.put("bootDone", state.bootDone.get());
json.put("repositories", state.repositories);
@@ -64,8 +63,6 @@ public abstract class StateStorage {
json.put("managed", state.managedBundles);
json.put("checksums", toStringLongMap(state.bundleChecksums));
JsonWriter.write(os, json);
- } finally {
- close(os);
}
}
}
@@ -129,14 +126,4 @@ public abstract class StateStorage {
}
}
- static void close(Closeable closeable) {
- if (closeable != null) {
- try {
- closeable.close();
- } catch (IOException e) {
- // Ignore
- }
- }
- }
-
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/1c63a097/features/core/src/main/java/org/apache/karaf/features/internal/util/ChecksumUtils.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/util/ChecksumUtils.java b/features/core/src/main/java/org/apache/karaf/features/internal/util/ChecksumUtils.java
index 19fc706..f18f10a 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/util/ChecksumUtils.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/util/ChecksumUtils.java
@@ -16,6 +16,7 @@
*/
package org.apache.karaf.features.internal.util;
+import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.CRC32;
@@ -32,24 +33,42 @@ public class ChecksumUtils {
* @param is the input stream
* @return a checksum identifying any change
*/
- public static long checksum(InputStream is) throws IOException
- {
- try {
- CRC32 crc = new CRC32();
- byte[] buffer = new byte[8192];
- int l;
- while ((l = is.read(buffer)) > 0) {
- crc.update(buffer, 0, l);
- }
+ public static long checksum(InputStream is) throws IOException {
+ CRC32 crc = new CRC32();
+ byte[] buffer = new byte[8192];
+ int l;
+ while ((l = is.read(buffer)) > 0) {
+ crc.update(buffer, 0, l);
+ }
+ return crc.getValue();
+ }
+
+ public static class CRCInputStream extends FilterInputStream {
+
+ private final CRC32 crc = new CRC32();
+
+ public CRCInputStream(InputStream in) {
+ super(in);
+ }
+
+ public long getCRC() {
return crc.getValue();
- } finally {
- if (is != null) {
- try {
- is.close();
- } catch (IOException e) {
- // Ignore
- }
+ }
+
+ @Override
+ public int read() throws IOException {
+ byte[] b = new byte[1];
+ int nb = read(b, 0, 1);
+ return nb == 1 ? b[0] : -1;
+ }
+
+ @Override
+ public int read(byte[] b, int off, int len) throws IOException {
+ int nb = super.read(b, off, len);
+ if (nb > 0) {
+ crc.update(b, off, nb);
}
+ return nb;
}
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/1c63a097/features/core/src/main/java/org/apache/karaf/features/internal/util/MapUtils.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/util/MapUtils.java b/features/core/src/main/java/org/apache/karaf/features/internal/util/MapUtils.java
index d844c22..6437d10 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/util/MapUtils.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/util/MapUtils.java
@@ -32,7 +32,7 @@ public class MapUtils {
}
public static <S, T> Map<S, Set<T>> invert(Map<T, S> map) {
- Map<S, Set<T>> inverted = new HashMap<S, Set<T>>(map.size());
+ Map<S, Set<T>> inverted = new HashMap<>(map.size());
for (Map.Entry<T, S> entry : map.entrySet()) {
addToMapSet(inverted, entry.getValue(), entry.getKey());
}
@@ -40,7 +40,7 @@ public class MapUtils {
}
public static <S, T, U> Map<S, Set<U>> apply(Map<S, Set<T>> mapset, Function<T, U> function) {
- Map<S, Set<U>> result = new HashMap<S, Set<U>>(mapset.size());
+ Map<S, Set<U>> result = new HashMap<>(mapset.size());
for (Map.Entry<S, Set<T>> entry : mapset.entrySet()) {
result.put(entry.getKey(), apply(entry.getValue(), function));
}
@@ -48,7 +48,7 @@ public class MapUtils {
}
public static <U, T> Set<U> apply(Set<T> set, Function<T, U> function) {
- Set<U> result = new HashSet<U>(set.size());
+ Set<U> result = new HashSet<>(set.size());
for (T t : set) {
result.add(function.apply(t));
}
@@ -56,7 +56,7 @@ public class MapUtils {
}
public static <S, T, U> Map<T, U> build(Collection<S> col, Function<S, T> key, Function<S, U> value) {
- Map<T, U> result = new HashMap<T, U>(col.size());
+ Map<T, U> result = new HashMap<>(col.size());
for (S s : col) {
result.put(key.apply(s), value.apply(s));
}
@@ -87,7 +87,7 @@ public class MapUtils {
}
public static <S, T> Set<T> flatten(Map<S, Set<T>> mapset) {
- Set<T> set = new HashSet<T>();
+ Set<T> set = new HashSet<>();
for (Set<T> s : mapset.values()) {
set.addAll(s);
}
@@ -104,7 +104,7 @@ public class MapUtils {
for (Map.Entry<S, Set<T>> entry : toAdd.entrySet()) {
Set<T> s = from.get(entry.getKey());
if (s == null) {
- s = new HashSet<T>();
+ s = new HashSet<>();
from.put(entry.getKey(), s);
}
s.addAll(entry.getValue());
@@ -174,21 +174,21 @@ public class MapUtils {
}
public static <S, T> Map<S, Set<T>> copyMapSet(Map<S, Set<T>> from) {
- Map<S, Set<T>> to = new HashMap<S, Set<T>>();
+ Map<S, Set<T>> to = new HashMap<>();
copyMapSet(from, to);
return to;
}
public static <S, T> void copyMapSet(Map<S, Set<T>> from, Map<S, Set<T>> to) {
for (Map.Entry<S, Set<T>> entry : from.entrySet()) {
- to.put(entry.getKey(), new HashSet<T>(entry.getValue()));
+ to.put(entry.getKey(), new HashSet<>(entry.getValue()));
}
}
public static <S, T> void addToMapSet(Map<S, Set<T>> map, S key, T value) {
Set<T> values = map.get(key);
if (values == null) {
- values = new HashSet<T>();
+ values = new HashSet<>();
map.put(key, values);
}
values.add(value);
http://git-wip-us.apache.org/repos/asf/karaf/blob/1c63a097/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
index cd874b6..a5e96eb 100644
--- 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
@@ -55,7 +55,7 @@ public class DigraphHelper {
public static StandardRegionDigraph loadDigraph(BundleContext bundleContext) throws BundleException, IOException, InvalidSyntaxException {
StandardRegionDigraph digraph;
- ThreadLocal<Region> threadLocal = new ThreadLocal<Region>();
+ ThreadLocal<Region> threadLocal = new ThreadLocal<>();
File digraphFile = bundleContext.getDataFile(DIGRAPH_FILE);
if (digraphFile == null || !digraphFile.exists()) {
digraph = new StandardRegionDigraph(bundleContext, threadLocal);
@@ -64,11 +64,10 @@ public class DigraphHelper {
root.addBundle(bundle);
}
} else {
- InputStream in = new FileInputStream(digraphFile);
- try {
+ try (
+ InputStream in = new FileInputStream(digraphFile)
+ ) {
digraph = readDigraph(new DataInputStream(in), bundleContext, threadLocal);
- } finally {
- in.close();
}
}
return digraph;
@@ -76,17 +75,12 @@ public class DigraphHelper {
public static void saveDigraph(BundleContext bundleContext, RegionDigraph digraph) throws IOException {
File digraphFile = bundleContext.getDataFile(DIGRAPH_FILE);
- FileOutputStream out = new FileOutputStream(digraphFile);
- try {
+ try (
+ FileOutputStream out = new FileOutputStream(digraphFile)
+ ) {
saveDigraph(digraph, out);
} catch (Exception e) {
// Ignore
- } finally {
- try {
- out.close();
- } catch (IOException e) {
- // ignore;
- }
}
}
@@ -125,17 +119,17 @@ public class DigraphHelper {
}
static void saveDigraph(RegionDigraph digraph, OutputStream out) throws IOException {
- Map<String, Object> json = new LinkedHashMap<String, Object>();
- Map<String, Set<Long>> regions = new LinkedHashMap<String, Set<Long>>();
+ 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<Map<String, Object>>();
+ 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<String, Object>();
+ Map<String, Object> edge = new HashMap<>();
edge.put(TAIL, tail.getName());
edge.put(HEAD, fr.getRegion().getName());
edge.put(POLICY, fr.getFilter().getSharingPolicy());
[2/6] git commit: [KARAF-2911] Remove resolver and region services
from subsystems feature (they are provided by features.core bundle)
Posted by gn...@apache.org.
[KARAF-2911] Remove resolver and region services from subsystems feature (they are provided by features.core bundle)
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/1ea7beb0
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/1ea7beb0
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/1ea7beb0
Branch: refs/heads/master
Commit: 1ea7beb071cb13c18bb8d45d86e61918b1002142
Parents: 1f563d5
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Fri Apr 25 11:45:40 2014 +0200
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Fri Apr 25 11:45:40 2014 +0200
----------------------------------------------------------------------
assemblies/features/enterprise/src/main/feature/feature.xml | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/1ea7beb0/assemblies/features/enterprise/src/main/feature/feature.xml
----------------------------------------------------------------------
diff --git a/assemblies/features/enterprise/src/main/feature/feature.xml b/assemblies/features/enterprise/src/main/feature/feature.xml
index fedc19d..ad2ecf6 100644
--- a/assemblies/features/enterprise/src/main/feature/feature.xml
+++ b/assemblies/features/enterprise/src/main/feature/feature.xml
@@ -243,9 +243,7 @@
<feature name="subsystems" description="Support for OSGi subsystems" version="${aries.subsystem.version}">
<details>Support for Aries OSGi subsystems</details>
<bundle dependency="true" start-level="30">mvn:org.apache.aries/org.apache.aries.util/${aries.util.version}</bundle>
- <bundle start-level="30">mvn:org.apache.felix/org.apache.felix.resolver/${felix.resolver.version}</bundle>
- <bundle start-level="30">mvn:org.apache.karaf.services/org.apache.karaf.services.coordinator/${project.version}</bundle>
- <bundle start-level="30">mvn:org.eclipse.equinox/org.eclipse.equinox.region/${equinox.region.version}</bundle>
+ <bundle dependency="true" start-level="30">mvn:org.apache.karaf.services/org.apache.karaf.services.coordinator/${project.version}</bundle>
<bundle start-level="30">mvn:org.apache.aries.subsystem/org.apache.aries.subsystem/${aries.subsystem.version}</bundle>
<bundle start-level="30">mvn:org.apache.karaf.subsystem/org.apache.karaf.subsystem.core/${project.version}</bundle>
</feature>
[4/6] git commit: [KARAF-2923] Make sure bundles part of a
conditional are only used to solve optional dependencies if the conditional
itself is satisfied
Posted by gn...@apache.org.
[KARAF-2923] Make sure bundles part of a conditional are only used to solve optional dependencies if the conditional itself is satisfied
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/09a5e995
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/09a5e995
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/09a5e995
Branch: refs/heads/master
Commit: 09a5e995d9951260060742ef938d7fa6f62dccd8
Parents: bbaa966
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Fri Apr 25 13:15:45 2014 +0200
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Fri Apr 25 13:15:45 2014 +0200
----------------------------------------------------------------------
.../features/internal/region/Subsystem.java | 45 +++++++++++---------
.../features/internal/region/SubsystemTest.java | 42 ++++++++++++++++++
.../karaf/features/internal/region/data4/a.mf | 6 +++
.../karaf/features/internal/region/data4/b.mf | 6 +++
.../features/internal/region/data4/features.xml | 32 ++++++++++++++
5 files changed, 112 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/09a5e995/features/core/src/main/java/org/apache/karaf/features/internal/region/Subsystem.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/region/Subsystem.java b/features/core/src/main/java/org/apache/karaf/features/internal/region/Subsystem.java
index 651c388..8d6277a 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/region/Subsystem.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/region/Subsystem.java
@@ -254,16 +254,16 @@ public class Subsystem extends ResourceImpl {
if (feature != null) {
final Map<String, ResourceImpl> bundles = new ConcurrentHashMap<String, ResourceImpl>();
final Downloader downloader = manager.createDownloader();
- final Map<BundleInfo, Boolean> infos = new HashMap<BundleInfo, Boolean>();
+ final Map<BundleInfo, Conditional> infos = new HashMap<BundleInfo, Conditional>();
for (Conditional cond : feature.getConditional()) {
for (final BundleInfo bi : cond.getBundles()) {
- infos.put(bi, false);
+ infos.put(bi, cond);
}
}
for (BundleInfo bi : feature.getBundles()) {
- infos.put(bi, true);
+ infos.put(bi, null);
}
- for (Map.Entry<BundleInfo, Boolean> entry : infos.entrySet()) {
+ for (Map.Entry<BundleInfo, Conditional> entry : infos.entrySet()) {
final BundleInfo bi = entry.getKey();
final String loc = bi.getLocation();
downloader.download(loc, new DownloadCallback() {
@@ -286,17 +286,6 @@ public class Subsystem extends ResourceImpl {
}
downloader.await();
Overrides.override(bundles, overrides);
- for (Map.Entry<BundleInfo, Boolean> entry : infos.entrySet()) {
- final BundleInfo bi = entry.getKey();
- final String loc = bi.getLocation();
- final boolean mandatory = entry.getValue();
- ResourceImpl res = bundles.get(loc);
- if (bi.isDependency()) {
- addDependency(res, false, bi.isStart(), bi.getStartLevel());
- } else {
- doAddDependency(res, mandatory, bi.isStart(), bi.getStartLevel());
- }
- }
for (Dependency dep : feature.getDependencies()) {
Subsystem ss = this;
while (!ss.isAcceptDependencies()) {
@@ -304,15 +293,33 @@ public class Subsystem extends ResourceImpl {
}
ss.requireFeature(dep.getName(), dep.getVersion());
}
+ // Add conditionals
+ Map<Conditional, Resource> resConds = new HashMap<Conditional, Resource>();
for (Conditional cond : feature.getConditional()) {
FeatureResource resCond = FeatureResource.build(feature, cond, featureResolutionRange, bundles);
addIdentityRequirement(this, resCond, false);
installable.add(resCond);
+ resConds.put(cond, resCond);
+ }
+ // Add features
+ FeatureResource resFeature = FeatureResource.build(feature, featureResolutionRange, bundles);
+ addIdentityRequirement(resFeature, this);
+ installable.add(resFeature);
+ // Add dependencies
+ for (Map.Entry<BundleInfo, Conditional> entry : infos.entrySet()) {
+ final BundleInfo bi = entry.getKey();
+ final String loc = bi.getLocation();
+ final Conditional cond = entry.getValue();
+ ResourceImpl res = bundles.get(loc);
+ if (bi.isDependency()) {
+ addDependency(res, false, bi.isStart(), bi.getStartLevel());
+ } else {
+ doAddDependency(res, cond == null, bi.isStart(), bi.getStartLevel());
+ }
+ if (cond != null) {
+ addIdentityRequirement(res, resConds.get(cond), true);
+ }
}
-
- FeatureResource res = FeatureResource.build(feature, featureResolutionRange, bundles);
- addIdentityRequirement(res, this);
- installable.add(res);
}
// Compute dependencies
for (DependencyInfo info : dependencies.values()) {
http://git-wip-us.apache.org/repos/asf/karaf/blob/09a5e995/features/core/src/test/java/org/apache/karaf/features/internal/region/SubsystemTest.java
----------------------------------------------------------------------
diff --git a/features/core/src/test/java/org/apache/karaf/features/internal/region/SubsystemTest.java b/features/core/src/test/java/org/apache/karaf/features/internal/region/SubsystemTest.java
index 5e8edd5..5aabcb7 100644
--- a/features/core/src/test/java/org/apache/karaf/features/internal/region/SubsystemTest.java
+++ b/features/core/src/test/java/org/apache/karaf/features/internal/region/SubsystemTest.java
@@ -125,6 +125,48 @@ public class SubsystemTest {
verify(resolver, expected);
}
+ @Test
+ public void testConditionalUnsatisfiedWithOptional() throws Exception {
+ RepositoryImpl repo = new RepositoryImpl(getClass().getResource("data4/features.xml").toURI());
+
+ Map<String, Set<String>> features = new HashMap<String, Set<String>>();
+ addToMapSet(features, "root/apps1", "f1");
+ Map<String, Set<String>> expected = new HashMap<String, Set<String>>();
+ addToMapSet(expected, "root/apps1", "a/1.0.0");
+
+ SubsystemResolver resolver = new SubsystemResolver(new TestDownloadManager("data4"));
+ resolver.resolve(Arrays.asList(repo.getFeatures()),
+ features,
+ Collections.<String, Set<BundleRevision>>emptyMap(),
+ Collections.<String>emptySet(),
+ FeaturesServiceImpl.DEFAULT_FEATURE_RESOLUTION_RANGE,
+ null);
+
+ verify(resolver, expected);
+ }
+
+ @Test
+ public void testConditionalSatisfiedWithOptional() throws Exception {
+ RepositoryImpl repo = new RepositoryImpl(getClass().getResource("data4/features.xml").toURI());
+
+ Map<String, Set<String>> features = new HashMap<String, Set<String>>();
+ addToMapSet(features, "root/apps1", "f1");
+ addToMapSet(features, "root/apps1", "f2");
+ Map<String, Set<String>> expected = new HashMap<String, Set<String>>();
+ addToMapSet(expected, "root/apps1", "a/1.0.0");
+ addToMapSet(expected, "root/apps1", "b/1.0.0");
+
+ SubsystemResolver resolver = new SubsystemResolver(new TestDownloadManager("data4"));
+ resolver.resolve(Arrays.asList(repo.getFeatures()),
+ features,
+ Collections.<String, Set<BundleRevision>>emptyMap(),
+ Collections.<String>emptySet(),
+ FeaturesServiceImpl.DEFAULT_FEATURE_RESOLUTION_RANGE,
+ null);
+
+ verify(resolver, expected);
+ }
+
private void verify(SubsystemResolver resolver, Map<String, Set<String>> expected) {
Map<String, Set<String>> mapping = getBundleNamesPerRegions(resolver);
if (!expected.equals(mapping)) {
http://git-wip-us.apache.org/repos/asf/karaf/blob/09a5e995/features/core/src/test/resources/org/apache/karaf/features/internal/region/data4/a.mf
----------------------------------------------------------------------
diff --git a/features/core/src/test/resources/org/apache/karaf/features/internal/region/data4/a.mf b/features/core/src/test/resources/org/apache/karaf/features/internal/region/data4/a.mf
new file mode 100644
index 0000000..34f0569
--- /dev/null
+++ b/features/core/src/test/resources/org/apache/karaf/features/internal/region/data4/a.mf
@@ -0,0 +1,6 @@
+Manifest-Version: 1
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: a
+Bundle-Version: 1.0.0
+Require-Capability: ns;filter:="(ns=b)";resolution:=optional
+
http://git-wip-us.apache.org/repos/asf/karaf/blob/09a5e995/features/core/src/test/resources/org/apache/karaf/features/internal/region/data4/b.mf
----------------------------------------------------------------------
diff --git a/features/core/src/test/resources/org/apache/karaf/features/internal/region/data4/b.mf b/features/core/src/test/resources/org/apache/karaf/features/internal/region/data4/b.mf
new file mode 100644
index 0000000..0cc2cef
--- /dev/null
+++ b/features/core/src/test/resources/org/apache/karaf/features/internal/region/data4/b.mf
@@ -0,0 +1,6 @@
+Manifest-Version: 1
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: b
+Bundle-Version: 1.0.0
+Provide-Capability: ns;ns=b
+
http://git-wip-us.apache.org/repos/asf/karaf/blob/09a5e995/features/core/src/test/resources/org/apache/karaf/features/internal/region/data4/features.xml
----------------------------------------------------------------------
diff --git a/features/core/src/test/resources/org/apache/karaf/features/internal/region/data4/features.xml b/features/core/src/test/resources/org/apache/karaf/features/internal/region/data4/features.xml
new file mode 100644
index 0000000..76cddc7
--- /dev/null
+++ b/features/core/src/test/resources/org/apache/karaf/features/internal/region/data4/features.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+
+-->
+<features name="test" xmlns="http://karaf.apache.org/xmlns/features/v1.3.0">
+
+ <feature name="f1">
+ <conditional>
+ <condition>f2</condition>
+ <bundle>b</bundle>
+ </conditional>
+ <bundle>a</bundle>
+ </feature>
+
+ <feature name="f2">
+ </feature>
+
+</features>
\ No newline at end of file