You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2014/07/04 11:50:53 UTC
[11/45] git commit: Fix infinite recursion in Osgis.getBundle
Fix infinite recursion in Osgis.getBundle
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/b0bd8089
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/b0bd8089
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/b0bd8089
Branch: refs/heads/master
Commit: b0bd80894e1b4cc93821361abeec5d6aaf3e70fd
Parents: b6d2364
Author: Sam Corbett <sa...@cloudsoftcorp.com>
Authored: Mon Jun 30 12:54:44 2014 +0100
Committer: Sam Corbett <sa...@cloudsoftcorp.com>
Committed: Tue Jul 1 13:37:37 2014 +0100
----------------------------------------------------------------------
.../src/main/java/brooklyn/util/osgi/Osgis.java | 31 +++++++++++++-------
1 file changed, 21 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/b0bd8089/core/src/main/java/brooklyn/util/osgi/Osgis.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/util/osgi/Osgis.java b/core/src/main/java/brooklyn/util/osgi/Osgis.java
index 5edca46..e6aff48 100644
--- a/core/src/main/java/brooklyn/util/osgi/Osgis.java
+++ b/core/src/main/java/brooklyn/util/osgi/Osgis.java
@@ -23,6 +23,7 @@ import brooklyn.util.exceptions.Exceptions;
import brooklyn.util.guava.Maybe;
import com.google.common.annotations.Beta;
+import com.google.common.base.Joiner;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
@@ -50,19 +51,24 @@ public class Osgis {
public static List<Bundle> getBundlesByName(Framework framework, String symbolicName) {
return getBundlesByName(framework, symbolicName, Predicates.<Version>alwaysTrue());
}
-
+
+ /**
+ * Tries to find a bundle in the given framework with name matching either `name' or `name:version'.
+ */
public static Maybe<Bundle> getBundle(Framework framework, String symbolicNameOptionallyWithVersion) {
String[] parts = symbolicNameOptionallyWithVersion.split(":");
- List<Bundle> matches;
- if (parts.length==2) {
- return getBundle(framework, symbolicNameOptionallyWithVersion);
- } else if (parts.length==1) {
- matches = getBundlesByName(framework, symbolicNameOptionallyWithVersion);
- if (matches.isEmpty()) return Maybe.absent("no bundles matching "+symbolicNameOptionallyWithVersion);
- return Maybe.of(matches.iterator().next());
+ Maybe<Bundle> result = Maybe.absent("No bundles matching "+symbolicNameOptionallyWithVersion);
+ if (parts.length == 2) {
+ result = getBundle(framework, parts[0], parts[1]);
+ } else if (parts.length == 1) {
+ List<Bundle> matches = getBundlesByName(framework, symbolicNameOptionallyWithVersion);
+ if (!matches.isEmpty()) {
+ result = Maybe.of(matches.iterator().next());
+ }
} else {
throw new IllegalArgumentException("Cannot parse symbolic-name:version string '"+symbolicNameOptionallyWithVersion+"'");
}
+ return result;
}
public static Maybe<Bundle> getBundle(Framework framework, String symbolicName, String version) {
@@ -70,8 +76,13 @@ public class Osgis {
}
public static Maybe<Bundle> getBundle(Framework framework, String symbolicName, Version version) {
- List<Bundle> matches = getBundlesByName(framework, symbolicName, Predicates.<Version>equalTo(version));
- if (matches.isEmpty()) return Maybe.absent("no bundles matching "+symbolicName+":"+version);
+ List<Bundle> matches = getBundlesByName(framework, symbolicName, Predicates.equalTo(version));
+ if (matches.isEmpty()) {
+ return Maybe.absent("No bundles matching name=" + symbolicName + " version=" + version);
+ } else if (matches.size() > 1) {
+ LOG.warn("More than one bundle in framework={} matched name={}, version={}! Returning first of matches={}",
+ new Object[]{framework, symbolicName, version, Joiner.on(", ").join(matches)});
+ }
return Maybe.of(matches.iterator().next());
}