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 2017/03/01 08:34:22 UTC

[3/5] brooklyn-server git commit: CatalogBomScanner tidy

CatalogBomScanner tidy

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

Branch: refs/heads/master
Commit: f20cdecd2fef5c7ff2f6ef33ab7731c7acfb6de4
Parents: 7d1d47b
Author: Aled Sage <al...@gmail.com>
Authored: Tue Feb 28 22:26:55 2017 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Tue Feb 28 22:34:47 2017 +0000

----------------------------------------------------------------------
 .../catalog/internal/CatalogBomScanner.java     | 32 +++++++++++---------
 1 file changed, 17 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f20cdecd/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBomScanner.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBomScanner.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBomScanner.java
index 6184b1a..8bbb34d 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBomScanner.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBomScanner.java
@@ -123,9 +123,9 @@ public class CatalogBomScanner {
 
     public class CatalogPopulator extends BundleTracker<Iterable<? extends CatalogItem<?, ?>>> {
 
-        private ServiceReference<ManagementContext> mgmtContextReference = null;
-        private BundleContext bundleContext = null;
-        private ManagementContext managementContext = null;
+        private ServiceReference<ManagementContext> mgmtContextReference;
+        private BundleContext bundleContext;
+        private ManagementContext managementContext;
 
         public CatalogPopulator(ServiceReference<ManagementContext> serviceReference) {
             super(serviceReference.getBundle().getBundleContext(), Bundle.ACTIVE, null);
@@ -142,7 +142,7 @@ public class CatalogBomScanner {
 
         @Override
         public void open() {
-            if (mgmtContextReference!=null) {
+            if (mgmtContextReference != null) {
                 bundleContext = getBundleContext();
                 managementContext = getManagementContext();
             }
@@ -152,7 +152,7 @@ public class CatalogBomScanner {
         @Override
         public void close() {
             super.close();
-            if (mgmtContextReference!=null) {
+            if (mgmtContextReference != null) {
                 managementContext = null;
                 getBundleContext().ungetService(mgmtContextReference);
                 bundleContext = null;
@@ -160,14 +160,14 @@ public class CatalogBomScanner {
         }
 
         public BundleContext getBundleContext() {
-            if (bundleContext!=null) return bundleContext;
-            if (mgmtContextReference!=null) return mgmtContextReference.getBundle().getBundleContext();
+            if (bundleContext != null) return bundleContext;
+            if (mgmtContextReference != null) return mgmtContextReference.getBundle().getBundleContext();
             throw new IllegalStateException("Bundle context or management context reference must be supplied");
         }
         
         public ManagementContext getManagementContext() {
-            if (managementContext!=null) return managementContext;
-            if (mgmtContextReference!=null) return getBundleContext().getService(mgmtContextReference);
+            if (managementContext != null) return managementContext;
+            if (mgmtContextReference != null) return getBundleContext().getService(mgmtContextReference);
             throw new IllegalStateException("Bundle context or management context reference must be supplied");
         }
 
@@ -267,13 +267,14 @@ public class CatalogBomScanner {
         private String addLibraryDetails(Bundle bundle, String bomText) {
             @SuppressWarnings("unchecked")
             final Map<String, Object> bom = (Map<String, Object>)Iterables.getOnlyElement(Yamls.parseAll(bomText));
-            @SuppressWarnings("unchecked")
-            final Map<String, Object> catalog = (Map<String, Object>) bom.get(BROOKLYN_CATALOG);
+            final Object catalog = bom.get(BROOKLYN_CATALOG);
             if (null != catalog) {
                 if (catalog instanceof Map<?, ?>) {
-                    addLibraryDetails(bundle, catalog);
+                    @SuppressWarnings("unchecked")
+                    Map<String, Object> catalogMap = (Map<String, Object>) catalog;
+                    addLibraryDetails(bundle, catalogMap);
                 } else {
-                    LOG.warn("Unexpected syntax for {} (expected Map), ignoring", BROOKLYN_CATALOG);
+                    LOG.warn("Unexpected syntax for {} (expected Map, but got {}), ignoring", BROOKLYN_CATALOG, catalog.getClass().getName());
                 }
             }
             final String updatedBom = backToYaml(bom);
@@ -294,11 +295,12 @@ public class CatalogBomScanner {
             }
             final Object librarySpec = catalog.get(BROOKLYN_LIBRARIES);
             if (!(librarySpec instanceof List)) {
-                throw new RuntimeException("expected " + BROOKLYN_LIBRARIES + " to be a list");
+                throw new RuntimeException("expected " + BROOKLYN_LIBRARIES + " to be a list, but got " 
+                        + (librarySpec == null ? "null" : librarySpec.getClass().getName()));
             }
             @SuppressWarnings("unchecked")
             List<Map<String,String>> libraries = (List<Map<String,String>>)librarySpec;
-            if (bundle.getSymbolicName()==null || bundle.getVersion()==null) {
+            if (bundle.getSymbolicName() == null || bundle.getVersion() == null) {
                 throw new IllegalStateException("Cannot scan "+bundle+" for catalog files: name or version is null");
             }
             libraries.add(ImmutableMap.of(