brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [16/27] brooklyn-server git commit: update OsgiBundleWithUrl to act like versioned name, and uses of VersionedName
Date Fri, 30 Jun 2017 14:03:04 GMT
update OsgiBundleWithUrl to act like versioned name, and uses of VersionedName

OSGi versions are taken at the very last moment, allowing us to preserve brooklyn-recommended
syntax throughout nearly all our code; and lookups/matches in OSGi space compare the OSGi-target


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/701a1d7f
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/701a1d7f
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/701a1d7f

Branch: refs/heads/master
Commit: 701a1d7fb70203fd6a0503c369b16674972344ac
Parents: 89fb139
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Thu Jun 22 13:18:28 2017 +0100
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Thu Jun 22 14:12:02 2017 +0100

----------------------------------------------------------------------
 .../brooklyn/api/typereg/OsgiBundleWithUrl.java |  6 ++-
 .../camp/brooklyn/ExternalConfigYamlTest.java   |  2 +-
 .../brooklyn/test/lite/CampYamlLiteTest.java    |  2 +-
 .../catalog/internal/BasicBrooklynCatalog.java  |  4 +-
 .../core/catalog/internal/CatalogBundleDto.java | 10 ++++-
 .../internal/CatalogItemDtoAbstract.java        |  2 -
 .../core/mgmt/ha/OsgiArchiveInstaller.java      | 21 +++++-----
 .../brooklyn/core/mgmt/ha/OsgiManager.java      | 39 ++++++++---------
 .../mgmt/rebind/dto/MementosGenerators.java     |  2 +-
 .../core/typereg/BasicManagedBundle.java        | 14 +++++--
 .../core/typereg/BasicOsgiBundleWithUrl.java    | 12 ++++--
 .../apache/brooklyn/util/core/osgi/Osgis.java   | 44 +++-----------------
 .../rest/resources/CatalogResource.java         |  3 ++
 .../rest/resources/CatalogResourceTest.java     |  4 +-
 .../apache/brooklyn/util/osgi/OsgiUtils.java    | 10 ++++-
 .../brooklyn/util/osgi/VersionedName.java       | 37 +++++++++++++---
 .../util/text/BrooklynVersionSyntax.java        |  6 +++
 .../apache/brooklyn/util/osgi/OsgisTest.java    |  8 ++--
 .../brooklyn/util/osgi/VersionedNameTest.java   | 37 ++++++++++++----
 19 files changed, 156 insertions(+), 107 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/701a1d7f/api/src/main/java/org/apache/brooklyn/api/typereg/OsgiBundleWithUrl.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/brooklyn/api/typereg/OsgiBundleWithUrl.java b/api/src/main/java/org/apache/brooklyn/api/typereg/OsgiBundleWithUrl.java
index b17b993..970fc68 100644
--- a/api/src/main/java/org/apache/brooklyn/api/typereg/OsgiBundleWithUrl.java
+++ b/api/src/main/java/org/apache/brooklyn/api/typereg/OsgiBundleWithUrl.java
@@ -24,7 +24,11 @@ import com.google.common.annotations.Beta;
 public interface OsgiBundleWithUrl {
     
     public String getSymbolicName();
-    public String getVersion();
+    /** guaranteed to be in OSGi syntax, or null if name+version not available */
+    public String getOsgiVersionString();
+    
+    /** string as defined by caller; not necessarily in OSGi syntax */
+    public String getSuppliedVersionString();
     
     /** where this bundle can be downloaded; typically required unless we are guaranteed
the bundle will be manually installed or handled by persistence */
     public String getUrl();

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/701a1d7f/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ExternalConfigYamlTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ExternalConfigYamlTest.java
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ExternalConfigYamlTest.java
index 7b71840..abef044 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ExternalConfigYamlTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ExternalConfigYamlTest.java
@@ -193,7 +193,7 @@ public class ExternalConfigYamlTest extends AbstractYamlTest {
         CatalogBundle bundle = Iterables.getOnlyElement(item.getLibraries());
         assertEquals(bundle.getUrl(), LIBRARY_URL);
         assertEquals(bundle.getSymbolicName(), LIBRARY_SYMBOLIC_NAME);
-        assertEquals(bundle.getVersion(), LIBRARY_VERSION);
+        assertEquals(bundle.getSuppliedVersionString(), LIBRARY_VERSION);
     }
 
     // Will download the given catalog library jar

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/701a1d7f/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/CampYamlLiteTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/CampYamlLiteTest.java
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/CampYamlLiteTest.java
index 506e838..12abc50 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/CampYamlLiteTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/CampYamlLiteTest.java
@@ -169,7 +169,7 @@ public class CampYamlLiteTest {
         Assert.assertEquals(bundles.size(), 1);
         CatalogBundle bundle = Iterables.getOnlyElement(bundles);
         Assert.assertEquals(bundle.getUrl(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL);
-        Assert.assertEquals(bundle.getVersion(), "0.1.0");
+        Assert.assertEquals(bundle.getSuppliedVersionString(), "0.1.0");
 
         EntitySpec<?> spec1 = (EntitySpec<?>) mgmt.getCatalog().peekSpec(retrievedItem);
         assertNotNull(spec1);

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/701a1d7f/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
index b0d028f..a787789 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
@@ -60,13 +60,11 @@ import org.apache.brooklyn.util.javalang.AggregateClassLoader;
 import org.apache.brooklyn.util.javalang.JavaClassNames;
 import org.apache.brooklyn.util.javalang.LoadedClassLoader;
 import org.apache.brooklyn.util.osgi.VersionedName;
-import org.apache.brooklyn.util.text.BrooklynVersionSyntax;
 import org.apache.brooklyn.util.text.Strings;
 import org.apache.brooklyn.util.time.Duration;
 import org.apache.brooklyn.util.time.Time;
 import org.apache.brooklyn.util.yaml.Yamls;
 import org.apache.brooklyn.util.yaml.Yamls.YamlExtract;
-import org.osgi.framework.Version;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.yaml.snakeyaml.Yaml;
@@ -448,7 +446,7 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
         if (Strings.isBlank(version)) {
             throw new IllegalStateException("Catalog BOM must define version if bundle is
defined");
         }
-        return new VersionedName(bundle, Version.valueOf(BrooklynVersionSyntax.toValidOsgiVersion(version)));
+        return new VersionedName(bundle, version);
     }
 
     private void collectCatalogItems(String yaml, List<CatalogItemDtoAbstract<?, ?>>
result, Map<?, ?> parentMeta) {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/701a1d7f/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBundleDto.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBundleDto.java
b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBundleDto.java
index 1be4e18..dbbfc76 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBundleDto.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBundleDto.java
@@ -23,6 +23,7 @@ import com.google.common.base.Objects;
 import com.google.common.base.Preconditions;
 
 import org.apache.brooklyn.api.catalog.CatalogItem.CatalogBundle;
+import org.apache.brooklyn.util.text.BrooklynVersionSyntax;
 
 public class CatalogBundleDto implements CatalogBundle {
     private String symbolicName;
@@ -40,7 +41,7 @@ public class CatalogBundleDto implements CatalogBundle {
         }
 
         this.symbolicName = name;
-        this.version = version;
+        this.version = version==null ? null : BrooklynVersionSyntax.toValidOsgiVersion(version);
         this.url = url;
     }
 
@@ -58,9 +59,14 @@ public class CatalogBundleDto implements CatalogBundle {
     }
 
     @Override
-    public String getVersion() {
+    public String getSuppliedVersionString() {
         return version;
     }
+    
+    @Override
+    public String getOsgiVersionString() {
+        return version==null ? version : BrooklynVersionSyntax.toValidOsgiVersion(version);
+    }
 
     @Override
     public String getUrl() {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/701a1d7f/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemDtoAbstract.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemDtoAbstract.java
b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemDtoAbstract.java
index d098cdd..9047fcb 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemDtoAbstract.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemDtoAbstract.java
@@ -444,8 +444,6 @@ public abstract class CatalogItemDtoAbstract<T, SpecT> extends AbstractBrooklynO
                     url = inlineRef;
                 }
 
-                // TODO
-//                version = RegisteredTypeNaming.toOsgiVersion(version, "library reference
"+name+":"+version);
                 dto.add(new CatalogBundleDto(name, version, url));
             } else {
                 LOG.debug("Unexpected entry in libraries list neither string nor map: " +
object);

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/701a1d7f/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstaller.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstaller.java
b/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstaller.java
index 7d2267a..e4ffb54 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstaller.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstaller.java
@@ -43,6 +43,7 @@ import org.apache.brooklyn.util.guava.Maybe;
 import org.apache.brooklyn.util.os.Os;
 import org.apache.brooklyn.util.osgi.VersionedName;
 import org.apache.brooklyn.util.stream.Streams;
+import org.apache.brooklyn.util.text.BrooklynVersionSyntax;
 import org.apache.brooklyn.util.text.Strings;
 import org.apache.brooklyn.util.text.VersionComparator;
 import org.osgi.framework.Bundle;
@@ -126,7 +127,7 @@ class OsgiArchiveInstaller {
                         // user supplied just a URL (eg brooklyn.libraries), but we recognise
it,
                         // so don't try to reload it, just record the info we know about
it to retrieve the bundle
                         ((BasicManagedBundle)suppliedKnownBundleMetadata).setSymbolicName(mbFromUrl.getSymbolicName());
-                        ((BasicManagedBundle)suppliedKnownBundleMetadata).setVersion(mbFromUrl.getVersion());
+                        ((BasicManagedBundle)suppliedKnownBundleMetadata).setVersion(mbFromUrl.getSuppliedVersionString());
                     }
                 }
                 if (installedBundle.isAbsent() && suppliedKnownBundleMetadata.getOsgiUniqueUrl()!=null)
{
@@ -136,7 +137,7 @@ class OsgiArchiveInstaller {
                     installedBundle = Osgis.bundleFinder(osgiManager.framework).requiringFromUrl(suppliedKnownBundleMetadata.getUrl()).find();
                 }
                 if (installedBundle.isAbsent() && suppliedKnownBundleMetadata.isNameResolved())
{
-                    installedBundle = Osgis.bundleFinder(osgiManager.framework).symbolicName(suppliedKnownBundleMetadata.getSymbolicName()).version(suppliedKnownBundleMetadata.getVersion()).find();
+                    installedBundle = Osgis.bundleFinder(osgiManager.framework).symbolicName(suppliedKnownBundleMetadata.getSymbolicName()).version(suppliedKnownBundleMetadata.getSuppliedVersionString()).find();
                 }
                 if (suppliedKnownBundleMetadata.getUrl()!=null) {
                     if (installedBundle.isAbsent() || force) {
@@ -209,7 +210,7 @@ class OsgiArchiveInstaller {
     
     private void updateManifestFromAllSourceInformation() {
         if (discoveredBomVersionedName!=null) {
-            matchSetOrFail("catalog.bom in archive", discoveredBomVersionedName.getSymbolicName(),
discoveredBomVersionedName.getVersion().toString());
+            matchSetOrFail("catalog.bom in archive", discoveredBomVersionedName.getSymbolicName(),
discoveredBomVersionedName.getVersionString());
         }
         
         boolean manifestNeedsUpdating = false;
@@ -221,12 +222,12 @@ class OsgiArchiveInstaller {
                 discoveredManifest.getMainAttributes().getValue(Constants.BUNDLE_VERSION)
)) {
             manifestNeedsUpdating = true;                
             discoveredManifest.getMainAttributes().putValue(Constants.BUNDLE_SYMBOLICNAME,
inferredMetadata.getSymbolicName());
-            discoveredManifest.getMainAttributes().putValue(Constants.BUNDLE_VERSION, inferredMetadata.getVersion());
+            discoveredManifest.getMainAttributes().putValue(Constants.BUNDLE_VERSION, inferredMetadata.getOsgiVersionString()
);
         }
         if (Strings.isBlank(inferredMetadata.getSymbolicName())) {
             throw new IllegalArgumentException("Missing bundle symbolic name in BOM or MANIFEST");
         }
-        if (Strings.isBlank(inferredMetadata.getVersion())) {
+        if (Strings.isBlank(inferredMetadata.getSuppliedVersionString())) {
             throw new IllegalArgumentException("Missing bundle version in BOM or MANIFEST");
         }
         if (discoveredManifest.getMainAttributes().getValue(Attributes.Name.MANIFEST_VERSION)==null)
{
@@ -305,7 +306,7 @@ class OsgiArchiveInstaller {
             } else {
                 result.metadata = inferredMetadata;
                 // no such managed bundle
-                Maybe<Bundle> b = Osgis.bundleFinder(osgiManager.framework).symbolicName(result.getMetadata().getSymbolicName()).version(result.getMetadata().getVersion()).find();
+                Maybe<Bundle> b = Osgis.bundleFinder(osgiManager.framework).symbolicName(result.getMetadata().getSymbolicName()).version(result.getMetadata().getSuppliedVersionString()).find();
                 if (b.isPresent()) {
                     // if it's non-brooklyn installed then fail
                     // (e.g. someone trying to install brooklyn or guice through this mechanism!)
@@ -398,7 +399,7 @@ class OsgiArchiveInstaller {
     private boolean canUpdate() {
         // only update if forced, or it's a snapshot for which a byte stream is supplied
         // (IE don't update a snapshot verison every time its URL is referenced in a 'libraries'
section)
-        return force || (VersionComparator.isSnapshot(inferredMetadata.getVersion()) &&
inputStreamSupplied);
+        return force || (VersionComparator.isSnapshot(inferredMetadata.getSuppliedVersionString())
&& inputStreamSupplied);
     }
 
     /** true if the supplied name and version are complete; updates if the known data is
incomplete;
@@ -415,10 +416,10 @@ class OsgiArchiveInstaller {
         
         if (Strings.isBlank(version)) {
             suppliedIsComplete = false;
-        } else if (Strings.isBlank(inferredMetadata.getVersion())) {
+        } else if (Strings.isBlank(inferredMetadata.getSuppliedVersionString())) {
             ((BasicManagedBundle)inferredMetadata).setVersion(version);
-        } else if (!Objects.equal(inferredMetadata.getVersion(), version)){
-            throw new IllegalArgumentException("Bundle version mismatch '"+version+"' from
"+source+" (expected '"+inferredMetadata.getVersion()+"')");
+        } else if (!BrooklynVersionSyntax.equalAsOsgiVersions(inferredMetadata.getSuppliedVersionString(),
version)) {
+            throw new IllegalArgumentException("Bundle version mismatch '"+version+"' from
"+source+" (expected '"+inferredMetadata.getSuppliedVersionString()+"')");
         }
         
         return suppliedIsComplete;

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/701a1d7f/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java
index c3fa58d..dcabe00 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java
@@ -105,41 +105,42 @@ public class OsgiManager {
     final ManagedBundlesRecord managedBundlesRecord = new ManagedBundlesRecord();
     
     static class ManagedBundlesRecord {
-        private Map<String, ManagedBundle> managedBundles = MutableMap.of();
-        private Map<VersionedName, String> managedBundlesByName = MutableMap.of();
-        private Map<String, String> managedBundlesByUrl = MutableMap.of();
+        private Map<String, ManagedBundle> managedBundlesByUid = MutableMap.of();
+        private Map<VersionedName, String> managedBundlesUidByVersionedName = MutableMap.of();
+        private Map<String, String> managedBundlesUidByUrl = MutableMap.of();
         
         synchronized Map<String, ManagedBundle> getManagedBundles() {
-            return ImmutableMap.copyOf(managedBundles);
+            return ImmutableMap.copyOf(managedBundlesByUid);
         }
 
         synchronized String getManagedBundleId(VersionedName vn) {
-            return managedBundlesByName.get(vn);
+            return managedBundlesUidByVersionedName.get(VersionedName.toOsgiVersionedName(vn));
         }
 
         synchronized ManagedBundle getManagedBundle(VersionedName vn) {
-            return managedBundles.get(managedBundlesByName.get(vn));
+            return managedBundlesByUid.get(managedBundlesUidByVersionedName.get(VersionedName.toOsgiVersionedName(vn)));
         }
         
         synchronized String getManagedBundleIdFromUrl(String url) {
-            return managedBundlesByUrl.get(url);
+            return managedBundlesUidByUrl.get(url);
         }
         
         synchronized ManagedBundle getManagedBundleFromUrl(String url) {
             String id = getManagedBundleIdFromUrl(url);
             if (id==null) return null;
-            return managedBundles.get(id);
+            return managedBundlesByUid.get(id);
         }
 
         synchronized void setManagedBundleUrl(String url, String id) {
-            managedBundlesByUrl.put(url, id);    
+            managedBundlesUidByUrl.put(url, id);    
         }
         
         synchronized void addManagedBundle(OsgiBundleInstallationResult result) {
-            managedBundles.put(result.getMetadata().getId(), result.getMetadata());
-            managedBundlesByName.put(result.getMetadata().getVersionedName(), result.getMetadata().getId());
+            managedBundlesByUid.put(result.getMetadata().getId(), result.getMetadata());
+            managedBundlesUidByVersionedName.put(VersionedName.toOsgiVersionedName(result.getMetadata().getVersionedName()),

+                result.getMetadata().getId());
             if (Strings.isNonBlank(result.getMetadata().getUrl())) {
-                managedBundlesByUrl.put(result.getMetadata().getUrl(), result.getMetadata().getId());
+                managedBundlesUidByUrl.put(result.getMetadata().getUrl(), result.getMetadata().getId());
             }
         }
     }
@@ -306,12 +307,12 @@ public class OsgiManager {
      */
     public void uninstallUploadedBundle(ManagedBundle bundleMetadata) {
         synchronized (managedBundlesRecord) {
-            ManagedBundle metadata = managedBundlesRecord.managedBundles.remove(bundleMetadata.getId());
+            ManagedBundle metadata = managedBundlesRecord.managedBundlesByUid.remove(bundleMetadata.getId());
             if (metadata==null) {
                 throw new IllegalStateException("No such bundle registered: "+bundleMetadata);
             }
-            managedBundlesRecord.managedBundlesByName.remove(bundleMetadata.getVersionedName());
-            managedBundlesRecord.managedBundlesByUrl.remove(bundleMetadata.getUrl());
+            managedBundlesRecord.managedBundlesUidByVersionedName.remove(bundleMetadata.getVersionedName());
+            managedBundlesRecord.managedBundlesUidByUrl.remove(bundleMetadata.getUrl());
         }
         mgmt.getRebindManager().getChangeListener().onUnmanaged(bundleMetadata);
 
@@ -440,7 +441,7 @@ public class OsgiManager {
         } else {
             Maybe<Bundle> installedBundle;
             if (bundleMetadata.isNameResolved()) {
-                installedBundle = Osgis.bundleFinder(framework).symbolicName(bundleMetadata.getSymbolicName()).version(bundleMetadata.getVersion()).find();
+                installedBundle = Osgis.bundleFinder(framework).symbolicName(bundleMetadata.getSymbolicName()).version(bundleMetadata.getSuppliedVersionString()).find();
             } else {
                 installedBundle = Maybe.absent("Bundle metadata does not have URL nor does
it have both name and version");
             }
@@ -460,7 +461,7 @@ public class OsgiManager {
     public static boolean isBundleNameEqualOrAbsent(OsgiBundleWithUrl bundle, Bundle b) {
         return !bundle.isNameResolved() ||
                 (bundle.getSymbolicName().equals(b.getSymbolicName()) &&
-                bundle.getVersion().equals(b.getVersion().toString()));
+                bundle.getOsgiVersionString().equals(b.getVersion().toString()));
     }
 
     public <T> Maybe<Class<T>> tryResolveClass(String type, OsgiBundleWithUrl...
osgiBundles) {
@@ -537,7 +538,7 @@ public class OsgiManager {
             ManagedBundle mb = getManagedBundleFromUrl(catalogBundle.getUrl());
             if (mb!=null) {
                 bundleFinder.requiringFromUrl(null);
-                bundleFinder.symbolicName(mb.getSymbolicName()).version(mb.getVersion());
+                bundleFinder.symbolicName(mb.getSymbolicName()).version(mb.getSuppliedVersionString());
                 result = bundleFinder.find();
                 if (result.isPresent()) {
                     return result;
@@ -547,7 +548,7 @@ public class OsgiManager {
 
         if (catalogBundle.getSymbolicName()!=null) {
             BundleFinder bundleFinder = Osgis.bundleFinder(framework);
-            bundleFinder.symbolicName(catalogBundle.getSymbolicName()).version(catalogBundle.getVersion());
+            bundleFinder.symbolicName(catalogBundle.getSymbolicName()).version(catalogBundle.getSuppliedVersionString());
             return bundleFinder.find();
         }
         if (result!=null) {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/701a1d7f/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/dto/MementosGenerators.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/dto/MementosGenerators.java
b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/dto/MementosGenerators.java
index e19c63d..20179bc 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/dto/MementosGenerators.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/dto/MementosGenerators.java
@@ -349,7 +349,7 @@ public class MementosGenerators {
         populateBrooklynObjectMementoBuilder(bundle, builder);
         builder.url(bundle.getUrl())
             .symbolicName(bundle.getSymbolicName())
-            .version(bundle.getVersion());
+            .version(bundle.getSuppliedVersionString());
         return builder.build();
     }
     

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/701a1d7f/core/src/main/java/org/apache/brooklyn/core/typereg/BasicManagedBundle.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicManagedBundle.java b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicManagedBundle.java
index 6c0fa35..350507c 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicManagedBundle.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicManagedBundle.java
@@ -30,6 +30,7 @@ import org.apache.brooklyn.core.mgmt.rebind.BasicManagedBundleRebindSupport;
 import org.apache.brooklyn.core.objs.AbstractBrooklynObject;
 import org.apache.brooklyn.core.objs.BrooklynObjectInternal;
 import org.apache.brooklyn.util.osgi.VersionedName;
+import org.apache.brooklyn.util.text.BrooklynVersionSyntax;
 import org.osgi.framework.Version;
 
 import com.google.common.annotations.Beta;
@@ -76,10 +77,15 @@ public class BasicManagedBundle extends AbstractBrooklynObject implements
Manage
     }
     
     @Override
-    public String getVersion() {
+    public String getSuppliedVersionString() {
         return version;
     }
 
+    @Override
+    public String getOsgiVersionString() {
+        return version==null ? version : BrooklynVersionSyntax.toValidOsgiVersion(version);
+    }
+
     public void setVersion(String version) {
         this.version = version;
     }
@@ -87,7 +93,7 @@ public class BasicManagedBundle extends AbstractBrooklynObject implements
Manage
     @Override
     public VersionedName getVersionedName() {
         if (symbolicName==null) return null;
-        return new VersionedName(symbolicName, Version.parseVersion(version));
+        return new VersionedName(symbolicName, version);
     }
     
     @Override
@@ -135,7 +141,7 @@ public class BasicManagedBundle extends AbstractBrooklynObject implements
Manage
         if (getClass() != obj.getClass()) return false;
         OsgiBundleWithUrl other = (OsgiBundleWithUrl) obj;
         if (!Objects.equal(symbolicName, other.getSymbolicName())) return false;
-        if (!Objects.equal(version, other.getVersion())) return false;
+        if (!Objects.equal(getOsgiVersionString(), other.getOsgiVersionString())) return
false;
         if (!Objects.equal(url, other.getUrl())) return false;
         return true;
     }
@@ -183,6 +189,6 @@ public class BasicManagedBundle extends AbstractBrooklynObject implements
Manage
     }
 
     public static ManagedBundle of(CatalogBundle bundleUrl) {
-        return new BasicManagedBundle(bundleUrl.getSymbolicName(), bundleUrl.getVersion(),
bundleUrl.getUrl());
+        return new BasicManagedBundle(bundleUrl.getSymbolicName(), bundleUrl.getSuppliedVersionString(),
bundleUrl.getUrl());
     }
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/701a1d7f/core/src/main/java/org/apache/brooklyn/core/typereg/BasicOsgiBundleWithUrl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicOsgiBundleWithUrl.java
b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicOsgiBundleWithUrl.java
index 5db9820..264b96c 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicOsgiBundleWithUrl.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicOsgiBundleWithUrl.java
@@ -20,6 +20,7 @@ package org.apache.brooklyn.core.typereg;
 
 import org.apache.brooklyn.api.catalog.CatalogItem.CatalogBundle;
 import org.apache.brooklyn.api.typereg.OsgiBundleWithUrl;
+import org.apache.brooklyn.util.text.BrooklynVersionSyntax;
 
 import com.google.common.base.MoreObjects;
 import com.google.common.base.Objects;
@@ -48,7 +49,7 @@ public class BasicOsgiBundleWithUrl implements CatalogBundle, OsgiBundleWithUrl
     }
     
     public BasicOsgiBundleWithUrl(OsgiBundleWithUrl b) {
-        this(b.getSymbolicName(), b.getVersion(), b.getUrl());
+        this(b.getSymbolicName(), b.getSuppliedVersionString(), b.getUrl());
     }
 
     @Override
@@ -68,9 +69,14 @@ public class BasicOsgiBundleWithUrl implements CatalogBundle, OsgiBundleWithUrl
     }
 
     @Override
-    public String getVersion() {
+    public String getSuppliedVersionString() {
         return version;
     }
+    
+    @Override
+    public String getOsgiVersionString() {
+        return version==null ? version : BrooklynVersionSyntax.toValidOsgiVersion(version);
+    }
 
     @Override
     public String getUrl() {
@@ -98,7 +104,7 @@ public class BasicOsgiBundleWithUrl implements CatalogBundle, OsgiBundleWithUrl
         if (getClass() != obj.getClass()) return false;
         OsgiBundleWithUrl other = (OsgiBundleWithUrl) obj;
         if (!Objects.equal(symbolicName, other.getSymbolicName())) return false;
-        if (!Objects.equal(version, other.getVersion())) return false;
+        if (!Objects.equal(getOsgiVersionString(), other.getOsgiVersionString())) return
false;
         if (!Objects.equal(url, other.getUrl())) return false;
         return true;
     }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/701a1d7f/core/src/main/java/org/apache/brooklyn/util/core/osgi/Osgis.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/util/core/osgi/Osgis.java b/core/src/main/java/org/apache/brooklyn/util/core/osgi/Osgis.java
index d46f098..c1a40f8 100644
--- a/core/src/main/java/org/apache/brooklyn/util/core/osgi/Osgis.java
+++ b/core/src/main/java/org/apache/brooklyn/util/core/osgi/Osgis.java
@@ -38,6 +38,7 @@ import org.apache.brooklyn.util.guava.Maybe;
 import org.apache.brooklyn.util.net.Urls;
 import org.apache.brooklyn.util.os.Os;
 import org.apache.brooklyn.util.osgi.OsgiUtils;
+import org.apache.brooklyn.util.osgi.VersionedName;
 import org.apache.brooklyn.util.stream.Streams;
 import org.apache.brooklyn.util.text.BrooklynVersionSyntax;
 import org.apache.brooklyn.util.text.Strings;
@@ -49,7 +50,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.common.annotations.Beta;
-import com.google.common.base.Function;
 import com.google.common.base.Joiner;
 import com.google.common.base.Optional;
 import com.google.common.base.Predicate;
@@ -65,23 +65,6 @@ import com.google.common.base.Predicates;
 public class Osgis {
     private static final Logger LOG = LoggerFactory.getLogger(Osgis.class);
 
-    /** @deprecated since 0.9.0, replaced with {@link org.apache.brooklyn.util.osgi.VersionedName}
*/
-    @Deprecated
-    public static class VersionedName extends org.apache.brooklyn.util.osgi.VersionedName
{
-
-        private VersionedName(org.apache.brooklyn.util.osgi.VersionedName src) {
-            super(src.getSymbolicName(), src.getVersion());
-        }
-
-        public VersionedName(Bundle b) {
-            super(b);
-        }
-
-        public VersionedName(String symbolicName, Version version) {
-            super(symbolicName, version);
-        }
-    }
-
     public static class BundleFinder {
         protected final Framework framework;
         protected String symbolicName;
@@ -109,17 +92,14 @@ public class Osgis {
             if (Strings.isBlank(symbolicNameOptionallyWithVersion))
                 return this;
             
-            Maybe<org.apache.brooklyn.util.osgi.VersionedName> nv = OsgiUtils.parseOsgiIdentifier(symbolicNameOptionallyWithVersion);
-            if (nv.isAbsent())
-                throw new IllegalArgumentException("Cannot parse symbolic-name:version string
'"+symbolicNameOptionallyWithVersion+"'");
-
+            Maybe<VersionedName> nv = VersionedName.parseMaybe(symbolicNameOptionallyWithVersion,
false);
             return id(nv.get());
         }
 
-        private BundleFinder id(org.apache.brooklyn.util.osgi.VersionedName nv) {
+        private BundleFinder id(VersionedName nv) {
             symbolicName(nv.getSymbolicName());
-            if (nv.getVersion() != null) {
-                version(nv.getVersion().toString());
+            if (nv.getVersionString() != null) {
+                version(nv.getVersionString());
             }
             return this;
         }
@@ -127,7 +107,7 @@ public class Osgis {
         public BundleFinder bundle(CatalogBundle bundle) {
             if (bundle.isNameResolved()) {
                 symbolicName(bundle.getSymbolicName());
-                version(bundle.getVersion());
+                version(bundle.getSuppliedVersionString());
             }
             if (bundle.getUrl() != null) {
                 requiringFromUrl(bundle.getUrl());
@@ -443,18 +423,6 @@ public class Osgis {
         return SystemFrameworkLoader.get().isSystemBundle(bundle);
     }
 
-    /** @deprecated since 0.9.0, replaced with {@link OsgiUtils#parseOsgiIdentifier(java.lang.String)
} */
-    @Deprecated
-    public static Maybe<VersionedName> parseOsgiIdentifier(String symbolicNameOptionalWithVersion)
{
-        final Maybe<org.apache.brooklyn.util.osgi.VersionedName> original = OsgiUtils.parseOsgiIdentifier(symbolicNameOptionalWithVersion);
-        return original.transform(new Function<org.apache.brooklyn.util.osgi.VersionedName,
VersionedName>() {
-            @Override
-            public VersionedName apply(org.apache.brooklyn.util.osgi.VersionedName input)
{
-                return new VersionedName(input);
-            }
-        });
-    }
-
     @Beta
     public static Optional<Bundle> getBundleOf(Class<?> clazz) {
         Bundle bundle = org.osgi.framework.FrameworkUtil.getBundle(clazz);

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/701a1d7f/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java
----------------------------------------------------------------------
diff --git a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java
b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java
index 2d7487d..9c6272b 100644
--- a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java
+++ b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java
@@ -200,6 +200,9 @@ public class CatalogResource extends AbstractBrooklynRestResource implements
Cat
             .install(new ByteArrayInputStream(zipInput));
         
         if (result.hasError()) {
+            if (log.isTraceEnabled()) {
+                log.trace("Unable to create from archive, returning 400: "+result.getError().getMessage(),
result.getError());
+            }
             return ApiError.builder().errorCode(Status.BAD_REQUEST).message(result.getWithoutError().getMessage())
                 .data(BundleInstallationRestResult.of(result.getWithoutError(), mgmt(), brooklyn(),
ui)).build().asJsonResponse();
         }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/701a1d7f/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/CatalogResourceTest.java
----------------------------------------------------------------------
diff --git a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/CatalogResourceTest.java
b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/CatalogResourceTest.java
index 46d1c9c..759ba03 100644
--- a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/CatalogResourceTest.java
+++ b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/CatalogResourceTest.java
@@ -776,7 +776,7 @@ public class CatalogResourceTest extends BrooklynRestResourceTest {
         Assert.assertNull(lib.getUrl());
 
         assertEquals(lib.getSymbolicName(), "org.apache.brooklyn.test.resources.osgi.brooklyn-test-osgi-entities");
-        assertEquals(lib.getVersion(), version);
+        assertEquals(lib.getSuppliedVersionString(), version);
 
         // now let's check other things on the item
         URI expectedIconUrl = URI.create(getEndpointAddress() + "/catalog/icon/" + symbolicName
+ "/" + entityItem.getVersion()).normalize();
@@ -852,7 +852,7 @@ public class CatalogResourceTest extends BrooklynRestResourceTest {
         Assert.assertNull(lib.getUrl());
 
         assertEquals(lib.getSymbolicName(), symbolicName);
-        assertEquals(lib.getVersion(), version);
+        assertEquals(lib.getSuppliedVersionString(), version);
 
         // now let's check other things on the item
         URI expectedIconUrl = URI.create(getEndpointAddress() + "/catalog/icon/" + symbolicName
+ "/" + entityItem.getVersion()).normalize();

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/701a1d7f/utils/common/src/main/java/org/apache/brooklyn/util/osgi/OsgiUtils.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/osgi/OsgiUtils.java b/utils/common/src/main/java/org/apache/brooklyn/util/osgi/OsgiUtils.java
index 1fe07f5..0645f55 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/util/osgi/OsgiUtils.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/util/osgi/OsgiUtils.java
@@ -80,10 +80,16 @@ public class OsgiUtils {
         return b.getSymbolicName() + ":" + b.getVersion();
     }
 
-    /** Takes a string which might be of the form "symbolic-name" or "symbolic-name:version"
(or something else entirely)
+    /** Like {@link VersionedName#parseMaybe(String, boolean)} but enforces OSGi syntax for
the input version.
+     * <p> 
+     * Takes a string which might be of the form "symbolic-name" or "symbolic-name:version"
(or something else entirely)
      * and returns a VersionedName. The versionedName.getVersion() will be null if if there
was no version in the input
-     * (or returning {@link Maybe#absent()} if not valid, with a suitable error message).
*/
+     * (or returning {@link Maybe#absent()} if not valid, with a suitable error message).

+     * @deprecated since 0.12.0 use {@link VersionedName#parseMaybe(String, boolean)}; check
OSGi version compatibility manually if needed 
+     * (but usually not wanted, we let it convert to OSGi syntax as needed) */
+    @Deprecated // all usages except for tests removed
     public static Maybe<VersionedName> parseOsgiIdentifier(String symbolicNameOptionalWithVersion)
{
+        // TODO deprecate?
         if (Strings.isBlank(symbolicNameOptionalWithVersion)) {
             return Maybe.absent("OSGi identifier is blank");
         }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/701a1d7f/utils/common/src/main/java/org/apache/brooklyn/util/osgi/VersionedName.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/osgi/VersionedName.java b/utils/common/src/main/java/org/apache/brooklyn/util/osgi/VersionedName.java
index e466d82..9ae70df 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/util/osgi/VersionedName.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/util/osgi/VersionedName.java
@@ -19,7 +19,9 @@ import static com.google.common.base.Preconditions.checkNotNull;
 
 import javax.annotation.Nullable;
 
+import org.apache.brooklyn.util.guava.Maybe;
 import org.apache.brooklyn.util.text.BrooklynVersionSyntax;
+import org.apache.brooklyn.util.text.Strings;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.Version;
 
@@ -126,11 +128,36 @@ public class VersionedName {
         return Objects.equal(name, o.name) && Objects.equal(getOsgiVersion(), o.getOsgiVersion());
       
     }
 
-    public static VersionedName fromString(String nameOptionalColonVersion) {
-        if (nameOptionalColonVersion==null) return null;
-        int colon = nameOptionalColonVersion.indexOf(':');
-        if (colon<0) throw new IllegalArgumentException("Versioned name '"+nameOptionalColonVersion+"'
must be of form 'name:version'");
-        return new VersionedName(nameOptionalColonVersion.substring(0, colon), nameOptionalColonVersion.substring(colon+1));
+    /** Returns a {@link VersionedName} instance where {@link #getVersionString()} complies
with OSGi syntax (or is null), 
+     * even if the input does not. 
+     * Typically used to convert from Brooklyn-recommended <code>1.0-SNAPSHOT</code>
syntax to 
+     * OSGi-mandated <code>1.0.0.SNAPSHOT</code> syntax. */
+    public static VersionedName toOsgiVersionedName(VersionedName vn) {
+        if (vn==null) return null;
+        return new VersionedName(vn.getSymbolicName(), vn.getOsgiVersion());
+    }
+
+    /** As {@link #parseMaybe(String)} but throwing if invalid; allows null version */
+    public static VersionedName fromString(String vn) {
+        return parseMaybe(vn, false).get();
+    }
+    
+    /** Takes a string which might be of the form "symbolic-name" or "symbolic-name:version"
(or something else entirely)
+     * and returns a VersionedName. The versionedName.getVersion() will be null if if there
was no version in the input
+     * and the second argument is false, versions not required.
+     * Returns a {@link Maybe#absent()} with a suitable message if not valid. */
+    public static Maybe<VersionedName> parseMaybe(String symbolicNameWithVersion, boolean
versionRequired) {
+        if (Strings.isBlank(symbolicNameWithVersion)) {
+            return Maybe.absent("Identifier is blank");
+        }
+        String[] parts = symbolicNameWithVersion.split(":");
+        if (versionRequired && parts.length!=2) {
+            return Maybe.absent("Identifier '"+symbolicNameWithVersion+"' must be of 'name:version'
syntax");
+        }
+        if (parts.length > 2) {
+            return Maybe.absent("Identifier '"+symbolicNameWithVersion+"' has too many parts;
max one ':' symbol");
+        }
+        return Maybe.of(new VersionedName(parts[0], parts.length == 2 ? parts[1] : null));
     }
 
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/701a1d7f/utils/common/src/main/java/org/apache/brooklyn/util/text/BrooklynVersionSyntax.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/text/BrooklynVersionSyntax.java
b/utils/common/src/main/java/org/apache/brooklyn/util/text/BrooklynVersionSyntax.java
index 63c69e1..b8aa580 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/util/text/BrooklynVersionSyntax.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/util/text/BrooklynVersionSyntax.java
@@ -185,4 +185,10 @@ public class BrooklynVersionSyntax {
         return result.toString();
     }
 
+    /** Returns true if the given strings are equal when mapped according to {@link #toValidOsgiVersion(String)}
*/
+    public static boolean equalAsOsgiVersions(String v1, String v2) {
+        if (v1==null || v2==null) return (v1==null && v2==null);
+        return toValidOsgiVersion(v1).equals(toValidOsgiVersion(v2));
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/701a1d7f/utils/common/src/test/java/org/apache/brooklyn/util/osgi/OsgisTest.java
----------------------------------------------------------------------
diff --git a/utils/common/src/test/java/org/apache/brooklyn/util/osgi/OsgisTest.java b/utils/common/src/test/java/org/apache/brooklyn/util/osgi/OsgisTest.java
index c86670a..a56264a 100644
--- a/utils/common/src/test/java/org/apache/brooklyn/util/osgi/OsgisTest.java
+++ b/utils/common/src/test/java/org/apache/brooklyn/util/osgi/OsgisTest.java
@@ -21,16 +21,16 @@ package org.apache.brooklyn.util.osgi;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertFalse;
 
-import org.osgi.framework.Version;
 import org.testng.annotations.Test;
 
 public class OsgisTest {
 
+    @SuppressWarnings("deprecation")
     @Test
     public void testParseOsgiIdentifier() throws Exception {
-        assertEquals(OsgiUtils.parseOsgiIdentifier("a.b").get(), new VersionedName("a.b",
null));
-        assertEquals(OsgiUtils.parseOsgiIdentifier("a.b:0.1.2").get(), new VersionedName("a.b",
Version.parseVersion("0.1.2")));
-        assertEquals(OsgiUtils.parseOsgiIdentifier("a.b:0.0.0.SNAPSHOT").get(), new VersionedName("a.b",
Version.parseVersion("0.0.0.SNAPSHOT")));
+        assertEquals(OsgiUtils.parseOsgiIdentifier("a.b").get(), new VersionedName("a.b",
(String)null));
+        assertEquals(OsgiUtils.parseOsgiIdentifier("a.b:0.1.2").get(), new VersionedName("a.b",
"0.1.2"));
+        assertEquals(OsgiUtils.parseOsgiIdentifier("a.b:0.0.0.SNAPSHOT").get(), new VersionedName("a.b",
"0.0.0.SNAPSHOT"));
         assertFalse(OsgiUtils.parseOsgiIdentifier("a.b:0.notanumber.2").isPresent()); //
invalid version
         assertFalse(OsgiUtils.parseOsgiIdentifier("a.b:0.1.2:3.4.5").isPresent());    //
too many colons
         assertFalse(OsgiUtils.parseOsgiIdentifier("a.b:0.0.0_SNAPSHOT").isPresent()); //
invalid version

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/701a1d7f/utils/common/src/test/java/org/apache/brooklyn/util/osgi/VersionedNameTest.java
----------------------------------------------------------------------
diff --git a/utils/common/src/test/java/org/apache/brooklyn/util/osgi/VersionedNameTest.java
b/utils/common/src/test/java/org/apache/brooklyn/util/osgi/VersionedNameTest.java
index f162673..e3fe95c 100644
--- a/utils/common/src/test/java/org/apache/brooklyn/util/osgi/VersionedNameTest.java
+++ b/utils/common/src/test/java/org/apache/brooklyn/util/osgi/VersionedNameTest.java
@@ -15,8 +15,11 @@
  */
 package org.apache.brooklyn.util.osgi;
 
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+
+import org.apache.brooklyn.test.Asserts;
 import org.apache.brooklyn.util.javalang.coerce.TypeCoercerExtensible;
-import org.apache.brooklyn.util.text.BrooklynVersionSyntax;
 import org.osgi.framework.Version;
 import org.testng.Assert;
 import org.testng.annotations.Test;
@@ -25,20 +28,36 @@ public class VersionedNameTest {
     
     @Test
     public void testVersionedNameFromString() {
-        VersionedName foo1 = new VersionedName("foo", new Version("1.0"));
+        VersionedName foo1 = new VersionedName("foo", "1.0");
         Assert.assertEquals(foo1, VersionedName.fromString("foo:1.0"));
         Assert.assertEquals(foo1, TypeCoercerExtensible.newDefault().coerce("foo:1.0", VersionedName.class));
     }
+    @Test
+    public void testVersionedNameFromVersion() {
+        VersionedName foo1 = new VersionedName("foo", new Version("1"));
+        Assert.assertEquals(foo1, VersionedName.fromString("foo:1.0.0"));
+    }
     
-    @Test(expectedExceptions=IllegalArgumentException.class)
-    public void testDoesNotAcceptInvalidVersions() {
-        Assert.assertEquals(new VersionedName("foo", new Version("1.0.0.alpha")), VersionedName.fromString("foo:1.0-alpha"));
+    @Test
+    public void testAcceptsAndConvertsNonOsgiVersions() {
+        Assert.assertEquals(new VersionedName("foo", new Version("1.0.0.alpha")), 
+            VersionedName.toOsgiVersionedName(VersionedName.fromString("foo:1.0-alpha")));
     }
     
     @Test
-    public void testManuallyCorrectingVersion() {
-        Assert.assertEquals(new VersionedName("foo", new Version("1.0.0.alpha")), VersionedName.fromString("foo:"+
-            BrooklynVersionSyntax.toValidOsgiVersion("1.0-alpha")));
+    public void testParse() throws Exception {
+        assertEquals(VersionedName.parseMaybe("a.b", false).get(), new VersionedName("a.b",
(String)null));
+        try {
+            assertEquals(VersionedName.parseMaybe("a.b", true).get(), new VersionedName("a.b",
(String)null));
+            Asserts.shouldHaveFailedPreviously();
+        } catch (Exception e) {
+            Asserts.expectedFailureContains(e, "a.b", "version");
+        }
+        assertEquals(VersionedName.fromString("a.b:0.1.2"), new VersionedName("a.b", "0.1.2"));
+        assertEquals(VersionedName.fromString("a.b:0.0.0.SNAPSHOT"), new VersionedName("a.b",
"0.0.0.SNAPSHOT"));
+        assertEquals(VersionedName.fromString("a.b:0.0.0_SNAPSHOT"), new VersionedName("a.b",
"0.0.0_SNAPSHOT"));
+        assertFalse(VersionedName.parseMaybe("a.b:0.1.2:3.4.5", false).isPresent());
+        assertFalse(VersionedName.parseMaybe("", false).isPresent());
     }
-
+    
 }


Mime
View raw message