brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hadr...@apache.org
Subject [28/33] incubator-brooklyn git commit: [BROOKLYN-162] Refactor package in ./core/catalog
Date Sat, 15 Aug 2015 13:33:30 GMT
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6caee589/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemDo.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemDo.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemDo.java
new file mode 100644
index 0000000..3914427
--- /dev/null
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemDo.java
@@ -0,0 +1,193 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.catalog.internal;
+
+import java.util.Collection;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import brooklyn.basic.BrooklynObjectInternal;
+
+import org.apache.brooklyn.api.catalog.CatalogItem;
+import org.apache.brooklyn.api.entity.rebind.RebindSupport;
+import org.apache.brooklyn.api.management.ManagementContext;
+import org.apache.brooklyn.api.mementos.CatalogItemMemento;
+
+import brooklyn.config.ConfigKey;
+
+import com.google.common.base.Preconditions;
+
+public class CatalogItemDo<T,SpecT> implements CatalogItem<T,SpecT>, BrooklynObjectInternal {
+
+    protected final CatalogDo catalog;
+    protected final CatalogItemDtoAbstract<T,SpecT> itemDto;
+
+    protected volatile Class<T> javaClass; 
+    
+    public CatalogItemDo(CatalogDo catalog, CatalogItem<T,SpecT> itemDto) {
+        this.catalog = Preconditions.checkNotNull(catalog, "catalog");
+        this.itemDto = (CatalogItemDtoAbstract<T, SpecT>) Preconditions.checkNotNull(itemDto, "itemDto");
+    }
+
+    public CatalogItem<T,SpecT> getDto() {
+        return itemDto;
+    }
+    
+    /**
+     * Config not supported for catalog item. See {@link #getPlanYaml()}.
+     */
+    @Override
+    public ConfigurationSupportInternal config() {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public <U> U setConfig(ConfigKey<U> key, U val) {
+        return config().set(key, val);
+    }
+
+    @Override
+    public CatalogItemType getCatalogItemType() {
+        return itemDto.getCatalogItemType();
+    }
+
+    @Override
+    public Class<T> getCatalogItemJavaType() {
+        return itemDto.getCatalogItemJavaType();
+    }
+
+    @Override
+    public String getId() {
+        return itemDto.getId();
+    }
+
+    @Override
+    public String getCatalogItemId() {
+        return itemDto.getCatalogItemId();
+    }
+
+    @Override
+    public void setDeprecated(boolean deprecated) {
+        itemDto.setDeprecated(deprecated);
+    }
+
+    @Override
+    public boolean isDeprecated() {
+        return itemDto.isDeprecated();
+    }
+
+    @Override
+    public void setCatalogItemId(String id) {
+        itemDto.setCatalogItemId(id);
+    }
+
+    @Override
+    public String getJavaType() {
+        return itemDto.getJavaType();
+    }
+
+    @Deprecated
+    @Override
+    public String getName() {
+        return getDisplayName();
+    }
+
+    @Deprecated
+    @Override
+    public String getRegisteredTypeName() {
+        return getSymbolicName();
+    }
+
+    @Override
+    public String getDisplayName() {
+        return itemDto.getDisplayName();
+    }
+
+    @Override
+    public TagSupport tags() {
+        return itemDto.tags();
+    }
+
+    @Override
+    public String getDescription() {
+        return itemDto.getDescription();
+    }
+
+    @Override
+    public String getIconUrl() {
+        return itemDto.getIconUrl();
+    }
+    
+    @Override
+    public String getSymbolicName() {
+        return itemDto.getSymbolicName();
+    }
+
+    @Override
+    public String getVersion() {
+        return itemDto.getVersion();
+    }
+
+    @Nonnull  // but it is still null sometimes, see in CatalogDo.loadJavaClass
+    @Override
+    public Collection<CatalogBundle> getLibraries() {
+        return itemDto.getLibraries();
+    }
+
+    /** @deprecated since 0.7.0 this is the legacy mechanism; still needed for policies and apps, but being phased out.
+     * new items should use {@link #getPlanYaml} and {@link #newClassLoadingContext} */
+    @Deprecated
+    public Class<T> getJavaClass() {
+        if (javaClass==null) loadJavaClass(null);
+        return javaClass;
+    }
+    
+    @SuppressWarnings("unchecked")
+    Class<? extends T> loadJavaClass(final ManagementContext mgmt) {
+        if (javaClass!=null) return javaClass;
+        javaClass = (Class<T>)CatalogUtils.newClassLoadingContext(mgmt, getId(), getLibraries(), catalog.getRootClassLoader()).loadClass(getJavaType());
+        return javaClass;
+    }
+
+    @Override
+    public String toString() {
+        return getClass().getCanonicalName()+"["+itemDto+"]";
+    }
+
+    @Override
+    public String toXmlString() {
+        return itemDto.toXmlString();
+    }
+
+    @Override
+    public Class<SpecT> getSpecType() {
+        return itemDto.getSpecType();
+    }
+
+    @Nullable @Override
+    public String getPlanYaml() {
+        return itemDto.getPlanYaml();
+    }
+
+    @Override
+    public RebindSupport<CatalogItemMemento> getRebindSupport() {
+        return itemDto.getRebindSupport();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6caee589/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
new file mode 100644
index 0000000..5aa073b
--- /dev/null
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemDtoAbstract.java
@@ -0,0 +1,404 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.catalog.internal;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.basic.AbstractBrooklynObject;
+
+import org.apache.brooklyn.api.catalog.CatalogItem;
+import org.apache.brooklyn.api.entity.rebind.RebindSupport;
+import org.apache.brooklyn.api.mementos.CatalogItemMemento;
+
+import brooklyn.config.ConfigKey;
+import brooklyn.entity.rebind.BasicCatalogItemRebindSupport;
+import brooklyn.util.collections.MutableList;
+import brooklyn.util.flags.FlagUtils;
+import brooklyn.util.flags.SetFromFlag;
+
+import com.google.common.base.Objects;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Sets;
+
+public abstract class CatalogItemDtoAbstract<T, SpecT> extends AbstractBrooklynObject implements CatalogItem<T, SpecT> {
+
+    private static Logger LOG = LoggerFactory.getLogger(CatalogItemDtoAbstract.class);
+
+    private @SetFromFlag String symbolicName;
+    private @SetFromFlag String version = BasicBrooklynCatalog.NO_VERSION;
+
+    private @SetFromFlag String displayName;
+    private @SetFromFlag String description;
+    private @SetFromFlag String iconUrl;
+
+    private @SetFromFlag String javaType;
+    /**@deprecated since 0.7.0, left for deserialization backwards compatibility */
+    private @Deprecated @SetFromFlag String type;
+    private @SetFromFlag String planYaml;
+
+    private @SetFromFlag Collection<CatalogBundle> libraries;
+    private @SetFromFlag Set<Object> tags = Sets.newLinkedHashSet();
+    private @SetFromFlag boolean deprecated;
+
+    /**
+     * Config not supported for catalog item. See {@link #getPlanYaml()}.
+     */
+    @Override
+    public ConfigurationSupportInternal config() {
+        throw new UnsupportedOperationException();
+    }
+    
+    @Override
+    public <U> U setConfig(ConfigKey<U> key, U val) {
+        return config().set(key, val);
+    }
+    
+    @Override
+    public String getId() {
+        return getCatalogItemId();
+    }
+
+    @Override
+    public String getCatalogItemId() {
+        return CatalogUtils.getVersionedId(getSymbolicName(), getVersion());
+    }
+
+    @Override
+    public String getJavaType() {
+        if (javaType != null) return javaType;
+        return type;
+    }
+
+    @Deprecated
+    public String getName() {
+        return getDisplayName();
+    }
+
+    @Deprecated
+    public String getRegisteredTypeName() {
+        return getSymbolicName();
+    }
+
+    @Override
+    public String getDisplayName() {
+        return displayName;
+    }
+
+    @Override
+    public String getDescription() {
+        return description;
+    }
+
+    @Override
+    public String getIconUrl() {
+        return iconUrl;
+    }
+
+    @Override
+    public String getSymbolicName() {
+        if (symbolicName != null) return symbolicName;
+        return getJavaType();
+    }
+
+    @Override
+    public String getVersion() {
+        // The property is set to NO_VERSION when the object is initialized so it's not supposed to be null ever.
+        // But xstream doesn't call constructors when reading from the catalog.xml file which results in null value
+        // for the version property. That's why we have to fix it in the getter.
+        if (version != null) {
+            return version;
+        } else {
+            return BasicBrooklynCatalog.NO_VERSION;
+        }
+    }
+
+    @Override
+    public boolean isDeprecated() {
+        return deprecated;
+    }
+
+    @Override
+    public void setDeprecated(boolean deprecated) {
+        this.deprecated = deprecated;
+    }
+
+    @Nonnull
+    @Override
+    public Collection<CatalogBundle> getLibraries() {
+        if (libraries != null) {
+            return ImmutableList.copyOf(libraries);
+        } else {
+            return Collections.emptyList();
+        }
+    }
+
+    @Nullable @Override
+    public String getPlanYaml() {
+        return planYaml;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hashCode(symbolicName, planYaml, javaType, nullIfEmpty(libraries), version, getCatalogItemId());
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) return true;
+        if (obj == null) return false;
+        if (getClass() != obj.getClass()) return false;
+        CatalogItemDtoAbstract<?,?> other = (CatalogItemDtoAbstract<?,?>) obj;
+        if (!Objects.equal(symbolicName, other.symbolicName)) return false;
+        if (!Objects.equal(planYaml, other.planYaml)) return false;
+        if (!Objects.equal(javaType, other.javaType)) return false;
+        if (!Objects.equal(nullIfEmpty(libraries), nullIfEmpty(other.libraries))) return false;
+        if (!Objects.equal(getCatalogItemId(), other.getCatalogItemId())) return false;
+        if (!Objects.equal(version, other.version)) return false;
+        if (!Objects.equal(deprecated, other.deprecated)) return false;
+        if (!Objects.equal(description, other.description)) return false;
+        if (!Objects.equal(displayName, other.displayName)) return false;
+        if (!Objects.equal(iconUrl, other.iconUrl)) return false;
+        if (!Objects.equal(tags, other.tags)) return false;
+        // 'type' not checked, because deprecated, 
+        // and in future we might want to allow it to be removed/blanked in some impls without affecting equality
+        // (in most cases it is the same as symbolicName so doesn't matter)
+        return true;
+    }
+
+    private static <T> Collection<T> nullIfEmpty(Collection<T> coll) {
+        if (coll==null || coll.isEmpty()) return null;
+        return coll;
+    }
+
+    @Override
+    public String toString() {
+        return getClass().getSimpleName()+"["+getId()+"/"+getDisplayName()+"]";
+    }
+
+    public abstract Class<SpecT> getSpecType();
+
+    transient CatalogXmlSerializer serializer;
+
+    @Override
+    public String toXmlString() {
+        if (serializer==null) loadSerializer();
+        return serializer.toString(this);
+    }
+
+    private synchronized void loadSerializer() {
+        if (serializer == null) {
+            serializer = new CatalogXmlSerializer();
+        }
+    }
+
+    @Override
+    public RebindSupport<CatalogItemMemento> getRebindSupport() {
+        return new BasicCatalogItemRebindSupport(this);
+    }
+
+    @Override
+    public void setDisplayName(String newName) {
+        this.displayName = newName;
+    }
+
+    @Override
+    protected AbstractBrooklynObject configure(Map<?, ?> flags) {
+        FlagUtils.setFieldsFromFlags(flags, this);
+        return this;
+    }
+
+    @Override
+    public TagSupport tags() {
+        return new BasicTagSupport();
+    }
+
+    /*
+     * Using a custom tag support class rather than the one in AbstractBrooklynObject because
+     * when XStream unmarshals a catalog item with no tags (e.g. from any catalog.xml file)
+     * super.tags will be null, and any call to getTags throws a NullPointerException on the
+     * synchronized (tags) statement. It can't just be initialised here because super.tags is
+     * final.
+     */
+    private class BasicTagSupport implements TagSupport {
+
+        private void setTagsIfNull() {
+            // Possible if the class was unmarshalled by Xstream with no tags
+            synchronized (CatalogItemDtoAbstract.this) {
+                if (tags == null) {
+                    tags = Sets.newLinkedHashSet();
+                }
+            }
+        }
+
+        @Nonnull
+        @Override
+        public Set<Object> getTags() {
+            synchronized (CatalogItemDtoAbstract.this) {
+                setTagsIfNull();
+                return ImmutableSet.copyOf(tags);
+            }
+        }
+
+        @Override
+        public boolean containsTag(Object tag) {
+            synchronized (CatalogItemDtoAbstract.this) {
+                setTagsIfNull();
+                return tags.contains(tag);
+            }
+        }
+
+        @Override
+        public boolean addTag(Object tag) {
+            boolean result;
+            synchronized (CatalogItemDtoAbstract.this) {
+                setTagsIfNull();
+                result = tags.add(tag);
+            }
+            onTagsChanged();
+            return result;
+        }
+
+        @Override
+        public boolean addTags(Iterable<?> newTags) {
+            boolean result;
+            synchronized (CatalogItemDtoAbstract.this) {
+                setTagsIfNull();
+                result = Iterables.addAll(tags, newTags);
+            }
+            onTagsChanged();
+            return result;
+        }
+
+        @Override
+        public boolean removeTag(Object tag) {
+            boolean result;
+            synchronized (CatalogItemDtoAbstract.this) {
+                setTagsIfNull();
+                result = tags.remove(tag);
+            }
+            onTagsChanged();
+            return result;
+        }
+    }
+
+    @Override
+    @Deprecated
+    public void setCatalogItemId(String id) {
+        //no op, should be used by rebind code only
+    }
+
+    protected void setSymbolicName(String symbolicName) {
+        this.symbolicName = symbolicName;
+    }
+
+    protected void setVersion(String version) {
+        this.version = version;
+    }
+
+    protected void setDescription(String description) {
+        this.description = description;
+    }
+
+    protected void setIconUrl(String iconUrl) {
+        this.iconUrl = iconUrl;
+    }
+
+    protected void setJavaType(String javaType) {
+        this.javaType = javaType;
+        this.type = null;
+    }
+
+    protected void setPlanYaml(String planYaml) {
+        this.planYaml = planYaml;
+    }
+
+    protected void setLibraries(Collection<CatalogBundle> libraries) {
+        this.libraries = libraries;
+    }
+
+    protected void setTags(Set<Object> tags) {
+        this.tags = tags;
+    }
+
+    protected void setSerializer(CatalogXmlSerializer serializer) {
+        this.serializer = serializer;
+    }
+
+    /**
+     * Parses an instance of CatalogLibrariesDto from the given List. Expects the list entries
+     * to be either Strings or Maps of String -> String. Will skip items that are not.
+     */
+    public static Collection<CatalogBundle> parseLibraries(Collection<?> possibleLibraries) {
+        Collection<CatalogBundle> dto = MutableList.of();
+        for (Object object : possibleLibraries) {
+            if (object instanceof Map) {
+                Map<?, ?> entry = (Map<?, ?>) object;
+                String name = stringValOrNull(entry, "name");
+                String version = stringValOrNull(entry, "version");
+                String url = stringValOrNull(entry, "url");
+                dto.add(new CatalogBundleDto(name, version, url));
+            } else if (object instanceof String) {
+                String inlineRef = (String) object;
+
+                final String name;
+                final String version;
+                final String url;
+
+                //Infer reference type (heuristically)
+                if (inlineRef.contains("/") || inlineRef.contains("\\")) {
+                    //looks like an url/file path
+                    name = null;
+                    version = null;
+                    url = inlineRef;
+                } else if (CatalogUtils.looksLikeVersionedId(inlineRef)) {
+                    //looks like a name+version ref
+                    name = CatalogUtils.getIdFromVersionedId(inlineRef);
+                    version = CatalogUtils.getVersionFromVersionedId(inlineRef);
+                    url = null;
+                } else {
+                    //assume it to be relative url
+                    name = null;
+                    version = null;
+                    url = inlineRef;
+                }
+
+                dto.add(new CatalogBundleDto(name, version, url));
+            } else {
+                LOG.debug("Unexpected entry in libraries list neither string nor map: " + object);
+            }
+        }
+        return dto;
+    }
+
+    private static String stringValOrNull(Map<?, ?> map, String key) {
+        Object val = map.get(key);
+        return val != null ? String.valueOf(val) : null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6caee589/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogLibrariesDo.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogLibrariesDo.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogLibrariesDo.java
new file mode 100644
index 0000000..99041d2
--- /dev/null
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogLibrariesDo.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.catalog.internal;
+
+import java.util.Collection;
+
+import org.apache.brooklyn.api.catalog.CatalogItem;
+
+import com.google.common.base.Preconditions;
+
+@Deprecated
+public class CatalogLibrariesDo implements CatalogItem.CatalogItemLibraries {
+
+    private final CatalogLibrariesDto librariesDto;
+
+
+    public CatalogLibrariesDo(CatalogLibrariesDto librariesDto) {
+        this.librariesDto = Preconditions.checkNotNull(librariesDto, "librariesDto");
+    }
+
+    @Override
+    public Collection<String> getBundles() {
+        return librariesDto.getBundles();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6caee589/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogLibrariesDto.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogLibrariesDto.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogLibrariesDto.java
new file mode 100644
index 0000000..6f2aba8
--- /dev/null
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogLibrariesDto.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.catalog.internal;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import org.apache.brooklyn.api.catalog.CatalogItem;
+
+import com.google.common.collect.ImmutableList;
+
+@Deprecated
+public class CatalogLibrariesDto implements CatalogItem.CatalogItemLibraries {
+
+    private final Collection<String> bundles;
+
+    public CatalogLibrariesDto() {
+        this.bundles = Collections.emptyList();
+    }
+
+    public CatalogLibrariesDto(Collection<String> bundles) {
+        this.bundles = bundles;
+    }
+
+    /**
+     * @return An immutable copy of the bundle URLs referenced by this object
+     */
+    @Override
+    public Collection<String> getBundles() {
+        if (bundles == null) {
+            // can be null on deserialization
+            return Collections.emptyList();
+        }
+        return ImmutableList.copyOf(bundles);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6caee589/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogLocationItemDto.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogLocationItemDto.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogLocationItemDto.java
new file mode 100644
index 0000000..c8206ce
--- /dev/null
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogLocationItemDto.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.catalog.internal;
+
+import org.apache.brooklyn.api.location.Location;
+import org.apache.brooklyn.api.location.LocationSpec;
+
+
+public class CatalogLocationItemDto extends CatalogItemDtoAbstract<Location,LocationSpec<?>> {
+    
+    @Override
+    public CatalogItemType getCatalogItemType() {
+        return CatalogItemType.LOCATION;
+    }
+
+    @Override
+    public Class<Location> getCatalogItemJavaType() {
+        return Location.class;
+    }
+
+    @SuppressWarnings({ "rawtypes", "unchecked" })
+    @Override
+    public Class<LocationSpec<?>> getSpecType() {
+        return (Class)LocationSpec.class;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6caee589/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogPolicyItemDto.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogPolicyItemDto.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogPolicyItemDto.java
new file mode 100644
index 0000000..1c7e6fe
--- /dev/null
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogPolicyItemDto.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.catalog.internal;
+
+import org.apache.brooklyn.api.policy.Policy;
+import org.apache.brooklyn.api.policy.PolicySpec;
+
+
+public class CatalogPolicyItemDto extends CatalogItemDtoAbstract<Policy,PolicySpec<?>> {
+    
+    @Override
+    public CatalogItemType getCatalogItemType() {
+        return CatalogItemType.POLICY;
+    }
+
+    @Override
+    public Class<Policy> getCatalogItemJavaType() {
+        return Policy.class;
+    }
+
+    @SuppressWarnings({ "rawtypes", "unchecked" })
+    @Override
+    public Class<PolicySpec<?>> getSpecType() {
+        return (Class)PolicySpec.class;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6caee589/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogTemplateItemDto.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogTemplateItemDto.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogTemplateItemDto.java
new file mode 100644
index 0000000..229a39c
--- /dev/null
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogTemplateItemDto.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.catalog.internal;
+
+import org.apache.brooklyn.api.entity.Application;
+import org.apache.brooklyn.api.entity.proxying.EntitySpec;
+
+public class CatalogTemplateItemDto extends CatalogItemDtoAbstract<Application,EntitySpec<? extends Application>> {
+
+    @Override
+    public CatalogItemType getCatalogItemType() {
+        return CatalogItemType.TEMPLATE;
+    }
+
+    @Override
+    public Class<Application> getCatalogItemJavaType() {
+        return Application.class;
+    }
+
+    @SuppressWarnings({ "rawtypes", "unchecked" })
+    @Override
+    public Class<EntitySpec<? extends Application>> getSpecType() {
+        return (Class)EntitySpec.class;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6caee589/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUtils.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUtils.java
new file mode 100644
index 0000000..378e450
--- /dev/null
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUtils.java
@@ -0,0 +1,254 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.catalog.internal;
+
+import java.util.Collection;
+
+import javax.annotation.Nullable;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.basic.BrooklynObjectInternal;
+
+import org.apache.brooklyn.api.basic.BrooklynObject;
+import org.apache.brooklyn.api.catalog.BrooklynCatalog;
+import org.apache.brooklyn.api.catalog.CatalogItem;
+import org.apache.brooklyn.api.catalog.CatalogItem.CatalogBundle;
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.management.ManagementContext;
+import org.apache.brooklyn.api.management.classloading.BrooklynClassLoadingContext;
+import org.apache.brooklyn.core.catalog.internal.BasicBrooklynCatalog.BrooklynLoaderTracker;
+import org.apache.brooklyn.core.management.classloading.BrooklynClassLoadingContextSequential;
+import org.apache.brooklyn.core.management.classloading.JavaBrooklynClassLoadingContext;
+import org.apache.brooklyn.core.management.classloading.OsgiBrooklynClassLoadingContext;
+import org.apache.brooklyn.core.management.ha.OsgiManager;
+import org.apache.brooklyn.core.management.internal.ManagementContextInternal;
+
+import brooklyn.config.BrooklynLogging;
+import brooklyn.entity.basic.EntityInternal;
+import brooklyn.entity.rebind.RebindManagerImpl.RebindTracker;
+import brooklyn.util.guava.Maybe;
+import brooklyn.util.text.Strings;
+import brooklyn.util.time.Time;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Joiner;
+import com.google.common.base.Stopwatch;
+
+public class CatalogUtils {
+    private static final Logger log = LoggerFactory.getLogger(CatalogUtils.class);
+
+    public static final char VERSION_DELIMITER = ':';
+
+    public static BrooklynClassLoadingContext newClassLoadingContext(ManagementContext mgmt, CatalogItem<?, ?> item) {
+        // TODO getLibraries() should never be null but sometimes it is still
+        // e.g. run CatalogResourceTest without the above check
+        if (item.getLibraries() == null) {
+            log.debug("CatalogItemDtoAbstract.getLibraries() is null.", new Exception("Trace for null CatalogItemDtoAbstract.getLibraries()"));
+        }
+        return newClassLoadingContext(mgmt, item.getId(), item.getLibraries());
+    }
+    
+    public static BrooklynClassLoadingContext getClassLoadingContext(Entity entity) {
+        ManagementContext mgmt = ((EntityInternal)entity).getManagementContext();
+        String catId = entity.getCatalogItemId();
+        if (Strings.isBlank(catId)) return JavaBrooklynClassLoadingContext.create(mgmt);
+        CatalogItem<?, ?> cat = getCatalogItemOptionalVersion(mgmt, catId);
+        if (cat==null) {
+            log.warn("Cannot load "+catId+" to get classloader for "+entity+"; will try with standard loader, but might fail subsequently");
+            return JavaBrooklynClassLoadingContext.create(mgmt);
+        }
+        return newClassLoadingContext(mgmt, cat);
+    }
+
+    public static BrooklynClassLoadingContext newClassLoadingContext(@Nullable ManagementContext mgmt, String catalogItemId, Collection<CatalogBundle> libraries) {
+        BrooklynClassLoadingContextSequential result = new BrooklynClassLoadingContextSequential(mgmt);
+
+        if (libraries!=null && !libraries.isEmpty()) {
+            result.add(new OsgiBrooklynClassLoadingContext(mgmt, catalogItemId, libraries));
+        }
+
+        BrooklynClassLoadingContext loader = BrooklynLoaderTracker.getLoader();
+        if (loader != null) {
+            result.add(loader);
+        }
+
+        result.addSecondary(JavaBrooklynClassLoadingContext.create(mgmt));
+        return result;
+    }
+
+    /**
+     * @deprecated since 0.7.0 only for legacy catalog items which provide a non-osgi loader; see {@link #newDefault(ManagementContext)}
+     */ @Deprecated
+    public static BrooklynClassLoadingContext newClassLoadingContext(@Nullable ManagementContext mgmt, String catalogItemId, Collection<CatalogBundle> libraries, ClassLoader customClassLoader) {
+        BrooklynClassLoadingContextSequential result = new BrooklynClassLoadingContextSequential(mgmt);
+
+        if (libraries!=null && !libraries.isEmpty()) {
+            result.add(new OsgiBrooklynClassLoadingContext(mgmt, catalogItemId, libraries));
+        }
+
+        BrooklynClassLoadingContext loader = BrooklynLoaderTracker.getLoader();
+        if (loader != null) {
+            result.add(loader);
+        }
+
+        result.addSecondary(JavaBrooklynClassLoadingContext.create(mgmt, customClassLoader));
+        return result;
+    }
+
+    /**
+     * Registers all bundles with the management context's OSGi framework.
+     */
+    public static void installLibraries(ManagementContext managementContext, @Nullable Collection<CatalogBundle> libraries) {
+        if (libraries == null) return;
+
+        ManagementContextInternal mgmt = (ManagementContextInternal) managementContext;
+        if (!libraries.isEmpty()) {
+            Maybe<OsgiManager> osgi = mgmt.getOsgiManager();
+            if (osgi.isAbsent()) {
+                throw new IllegalStateException("Unable to load bundles "+libraries+" because OSGi is not running.");
+            }
+            if (log.isDebugEnabled()) 
+                logDebugOrTraceIfRebinding(log, 
+                    "Loading bundles in {}: {}", 
+                    new Object[] {managementContext, Joiner.on(", ").join(libraries)});
+            Stopwatch timer = Stopwatch.createStarted();
+            for (CatalogBundle bundleUrl : libraries) {
+                osgi.get().registerBundle(bundleUrl);
+            }
+            if (log.isDebugEnabled()) 
+                logDebugOrTraceIfRebinding(log, 
+                    "Registered {} bundles in {}",
+                    new Object[]{libraries.size(), Time.makeTimeStringRounded(timer)});
+        }
+    }
+
+    /** Scans the given {@link BrooklynClassLoadingContext} to detect what catalog item id is in effect. */
+    public static String getCatalogItemIdFromLoader(BrooklynClassLoadingContext loader) {
+        if (loader instanceof OsgiBrooklynClassLoadingContext) {
+            return ((OsgiBrooklynClassLoadingContext)loader).getCatalogItemId();
+        } else {
+            return null;
+        }
+    }
+
+    public static void setCatalogItemIdOnAddition(Entity entity, BrooklynObject itemBeingAdded) {
+        if (entity.getCatalogItemId()!=null) {
+            if (itemBeingAdded.getCatalogItemId()==null) {
+                if (log.isDebugEnabled())
+                    BrooklynLogging.log(log, BrooklynLogging.levelDebugOrTraceIfReadOnly(entity),
+                        "Catalog item addition: "+entity+" from "+entity.getCatalogItemId()+" applying its catalog item ID to "+itemBeingAdded);
+                ((BrooklynObjectInternal)itemBeingAdded).setCatalogItemId(entity.getCatalogItemId());
+            } else {
+                if (!itemBeingAdded.getCatalogItemId().equals(entity.getCatalogItemId())) {
+                    // not a problem, but something to watch out for
+                    log.debug("Cross-catalog item detected: "+entity+" from "+entity.getCatalogItemId()+" has "+itemBeingAdded+" from "+itemBeingAdded.getCatalogItemId());
+                }
+            }
+        } else if (itemBeingAdded.getCatalogItemId()!=null) {
+            if (log.isDebugEnabled())
+                BrooklynLogging.log(log, BrooklynLogging.levelDebugOrTraceIfReadOnly(entity),
+                    "Catalog item addition: "+entity+" without catalog item ID has "+itemBeingAdded+" from "+itemBeingAdded.getCatalogItemId());
+        }
+    }
+
+    @Beta
+    public static void logDebugOrTraceIfRebinding(Logger log, String message, Object ...args) {
+        if (RebindTracker.isRebinding())
+            log.trace(message, args);
+        else
+            log.debug(message, args);
+    }
+
+    public static boolean looksLikeVersionedId(String versionedId) {
+        if (versionedId==null) return false;
+        int fi = versionedId.indexOf(VERSION_DELIMITER);
+        if (fi<0) return false;
+        int li = versionedId.lastIndexOf(VERSION_DELIMITER);
+        if (li!=fi) {
+            // if multiple colons, we say it isn't a versioned reference; the prefix in that case must understand any embedded versioning scheme
+            // this fixes the case of:  http://localhost:8080
+            return false;
+        }
+        String candidateVersion = versionedId.substring(li+1);
+        if (!candidateVersion.matches("[0-9]+(|(\\.|_).*)")) {
+            // version must start with a number, followed if by anything with full stop or underscore before any other characters
+            // e.g.  foo:1  or foo:1.1  or foo:1_SNAPSHOT all supported, but not e.g. foo:bar (or chef:cookbook or docker:my/image)
+            return false;
+        }
+        return true;
+    }
+
+    public static String getIdFromVersionedId(String versionedId) {
+        if (versionedId == null) return null;
+        int versionDelimiterPos = versionedId.lastIndexOf(VERSION_DELIMITER);
+        if (versionDelimiterPos != -1) {
+            return versionedId.substring(0, versionDelimiterPos);
+        } else {
+            return null;
+        }
+    }
+
+    public static String getVersionFromVersionedId(String versionedId) {
+        if (versionedId == null) return null;
+        int versionDelimiterPos = versionedId.lastIndexOf(VERSION_DELIMITER);
+        if (versionDelimiterPos != -1) {
+            return versionedId.substring(versionDelimiterPos+1);
+        } else {
+            return null;
+        }
+    }
+
+    public static String getVersionedId(String id, String version) {
+        // TODO null checks
+        return id + VERSION_DELIMITER + version;
+    }
+
+    //TODO Don't really like this, but it's better to have it here than on the interface to keep the API's 
+    //surface minimal. Could instead have the interface methods accept VerionedId object and have the helpers
+    //construct it as needed.
+    public static CatalogItem<?, ?> getCatalogItemOptionalVersion(ManagementContext mgmt, String versionedId) {
+        if (versionedId == null) return null;
+        if (looksLikeVersionedId(versionedId)) {
+            String id = getIdFromVersionedId(versionedId);
+            String version = getVersionFromVersionedId(versionedId);
+            return mgmt.getCatalog().getCatalogItem(id, version);
+        } else {
+            return mgmt.getCatalog().getCatalogItem(versionedId, BrooklynCatalog.DEFAULT_VERSION);
+        }
+    }
+
+    public static boolean isBestVersion(ManagementContext mgmt, CatalogItem<?,?> item) {
+        CatalogItem<?, ?> bestVersion = getCatalogItemOptionalVersion(mgmt, item.getSymbolicName());
+        if (bestVersion==null) return false;
+        return (bestVersion.getVersion().equals(item.getVersion()));
+    }
+
+    public static <T,SpecT> CatalogItem<T, SpecT> getCatalogItemOptionalVersion(ManagementContext mgmt, Class<T> type, String versionedId) {
+        if (looksLikeVersionedId(versionedId)) {
+            String id = getIdFromVersionedId(versionedId);
+            String version = getVersionFromVersionedId(versionedId);
+            return mgmt.getCatalog().getCatalogItem(type, id, version);
+        } else {
+            return mgmt.getCatalog().getCatalogItem(type, versionedId, BrooklynCatalog.DEFAULT_VERSION);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6caee589/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogXmlSerializer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogXmlSerializer.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogXmlSerializer.java
new file mode 100644
index 0000000..462e00e
--- /dev/null
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogXmlSerializer.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.catalog.internal;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.brooklyn.core.catalog.internal.CatalogClasspathDo.CatalogScanningModes;
+
+import brooklyn.basic.AbstractBrooklynObject;
+import brooklyn.util.xstream.EnumCaseForgivingSingleValueConverter;
+import brooklyn.util.xstream.XmlSerializer;
+
+public class CatalogXmlSerializer extends XmlSerializer<Object> {
+
+    @SuppressWarnings("deprecation")
+    public CatalogXmlSerializer() {
+        xstream.addDefaultImplementation(ArrayList.class, Collection.class);
+        
+        xstream.aliasType("list", List.class);
+        xstream.aliasType("map", Map.class);
+
+        xstream.useAttributeFor("id", String.class);
+
+        xstream.aliasType("catalog", CatalogDto.class);
+        xstream.useAttributeFor(CatalogDto.class, "url");
+        xstream.addImplicitCollection(CatalogDto.class, "catalogs", CatalogDto.class);
+        xstream.addImplicitCollection(CatalogDto.class, "entries", CatalogTemplateItemDto.class);
+        xstream.addImplicitCollection(CatalogDto.class, "entries", CatalogEntityItemDto.class);
+        xstream.addImplicitCollection(CatalogDto.class, "entries", CatalogPolicyItemDto.class);
+        xstream.addImplicitCollection(CatalogDto.class, "entries", CatalogLocationItemDto.class);
+
+        xstream.aliasType("template", CatalogTemplateItemDto.class);
+        xstream.aliasType("entity", CatalogEntityItemDto.class);
+        xstream.aliasType("policy", CatalogPolicyItemDto.class);
+        xstream.aliasType("location", CatalogPolicyItemDto.class);
+
+        xstream.aliasField("registeredType", CatalogItemDtoAbstract.class, "symbolicName");
+        xstream.aliasAttribute(CatalogItemDtoAbstract.class, "displayName", "name");
+        xstream.useAttributeFor(CatalogItemDtoAbstract.class, "type");
+        xstream.useAttributeFor(CatalogItemDtoAbstract.class, "version");
+        xstream.aliasType("bundle", CatalogBundleDto.class);
+        xstream.registerConverter(new CatalogBundleConverter(xstream.getMapper(), xstream.getReflectionProvider()));
+
+        xstream.useAttributeFor(CatalogClasspathDto.class, "scan");
+        xstream.addImplicitCollection(CatalogClasspathDto.class, "entries", "entry", String.class);
+        xstream.registerConverter(new EnumCaseForgivingSingleValueConverter(CatalogScanningModes.class));
+
+        // Note: the management context is being omitted because it is unnecessary for
+        // representations of catalogues generated with this serializer.
+        xstream.omitField(AbstractBrooklynObject.class, "managementContext");
+        xstream.omitField(AbstractBrooklynObject.class, "_legacyConstruction");
+        xstream.omitField(AbstractBrooklynObject.class, "hasWarnedOfNoManagementContextWhenPersistRequested");
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6caee589/core/src/main/java/org/apache/brooklyn/core/management/classloading/OsgiBrooklynClassLoadingContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/management/classloading/OsgiBrooklynClassLoadingContext.java b/core/src/main/java/org/apache/brooklyn/core/management/classloading/OsgiBrooklynClassLoadingContext.java
index af5920b..84baa20 100644
--- a/core/src/main/java/org/apache/brooklyn/core/management/classloading/OsgiBrooklynClassLoadingContext.java
+++ b/core/src/main/java/org/apache/brooklyn/core/management/classloading/OsgiBrooklynClassLoadingContext.java
@@ -26,11 +26,11 @@ import org.apache.brooklyn.api.catalog.CatalogItem;
 import org.apache.brooklyn.api.catalog.CatalogItem.CatalogBundle;
 import org.apache.brooklyn.api.management.ManagementContext;
 import org.apache.brooklyn.api.management.entitlement.EntitlementClass;
+import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
 import org.apache.brooklyn.core.management.entitlement.Entitlements;
 import org.apache.brooklyn.core.management.ha.OsgiManager;
 import org.apache.brooklyn.core.management.internal.ManagementContextInternal;
 
-import brooklyn.catalog.internal.CatalogUtils;
 import brooklyn.util.guava.Maybe;
 
 import com.google.common.base.Objects;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6caee589/core/src/main/java/org/apache/brooklyn/core/management/ha/HighAvailabilityManagerImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/management/ha/HighAvailabilityManagerImpl.java b/core/src/main/java/org/apache/brooklyn/core/management/ha/HighAvailabilityManagerImpl.java
index 25d8281..bda7f6f 100644
--- a/core/src/main/java/org/apache/brooklyn/core/management/ha/HighAvailabilityManagerImpl.java
+++ b/core/src/main/java/org/apache/brooklyn/core/management/ha/HighAvailabilityManagerImpl.java
@@ -42,6 +42,8 @@ import org.apache.brooklyn.api.management.ha.ManagementPlaneSyncRecord;
 import org.apache.brooklyn.api.management.ha.ManagementPlaneSyncRecordPersister;
 import org.apache.brooklyn.api.management.ha.MementoCopyMode;
 import org.apache.brooklyn.api.management.ha.ManagementPlaneSyncRecordPersister.Delta;
+import org.apache.brooklyn.core.catalog.internal.BasicBrooklynCatalog;
+import org.apache.brooklyn.core.catalog.internal.CatalogDto;
 import org.apache.brooklyn.core.internal.BrooklynFeatureEnablement;
 import org.apache.brooklyn.core.management.ha.BasicMasterChooser.AlphabeticMasterChooser;
 import org.apache.brooklyn.core.management.internal.BrooklynObjectManagementMode;
@@ -53,8 +55,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import brooklyn.BrooklynVersion;
-import brooklyn.catalog.internal.BasicBrooklynCatalog;
-import brooklyn.catalog.internal.CatalogDto;
 import brooklyn.config.BrooklynServerConfig;
 import brooklyn.config.ConfigKey;
 import brooklyn.entity.basic.BrooklynTaskTags;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6caee589/core/src/main/java/org/apache/brooklyn/core/management/internal/AbstractManagementContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/management/internal/AbstractManagementContext.java b/core/src/main/java/org/apache/brooklyn/core/management/internal/AbstractManagementContext.java
index 1758846..58e2f60 100644
--- a/core/src/main/java/org/apache/brooklyn/core/management/internal/AbstractManagementContext.java
+++ b/core/src/main/java/org/apache/brooklyn/core/management/internal/AbstractManagementContext.java
@@ -50,13 +50,13 @@ import org.apache.brooklyn.api.management.Task;
 import org.apache.brooklyn.api.management.classloading.BrooklynClassLoadingContext;
 import org.apache.brooklyn.api.management.entitlement.EntitlementManager;
 import org.apache.brooklyn.api.management.ha.HighAvailabilityManager;
+import org.apache.brooklyn.core.catalog.internal.BasicBrooklynCatalog;
+import org.apache.brooklyn.core.catalog.internal.CatalogInitialization;
+import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
 import org.apache.brooklyn.core.management.classloading.JavaBrooklynClassLoadingContext;
 import org.apache.brooklyn.core.management.entitlement.Entitlements;
 import org.apache.brooklyn.core.management.ha.HighAvailabilityManagerImpl;
 
-import brooklyn.catalog.internal.BasicBrooklynCatalog;
-import brooklyn.catalog.internal.CatalogInitialization;
-import brooklyn.catalog.internal.CatalogUtils;
 import brooklyn.config.BrooklynProperties;
 import brooklyn.config.StringConfigMap;
 import brooklyn.entity.basic.AbstractEntity;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6caee589/core/src/main/java/org/apache/brooklyn/core/management/internal/ManagementContextInternal.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/management/internal/ManagementContextInternal.java b/core/src/main/java/org/apache/brooklyn/core/management/internal/ManagementContextInternal.java
index 97a3d73..6c993d8 100644
--- a/core/src/main/java/org/apache/brooklyn/core/management/internal/ManagementContextInternal.java
+++ b/core/src/main/java/org/apache/brooklyn/core/management/internal/ManagementContextInternal.java
@@ -29,9 +29,9 @@ import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.location.Location;
 import org.apache.brooklyn.api.management.ManagementContext;
 import org.apache.brooklyn.api.management.Task;
+import org.apache.brooklyn.core.catalog.internal.CatalogInitialization;
 import org.apache.brooklyn.core.management.ha.OsgiManager;
 
-import brooklyn.catalog.internal.CatalogInitialization;
 import brooklyn.config.BrooklynProperties;
 import brooklyn.entity.basic.BrooklynTaskTags;
 import brooklyn.entity.proxying.InternalEntityFactory;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6caee589/core/src/main/java/org/apache/brooklyn/core/management/internal/NonDeploymentManagementContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/management/internal/NonDeploymentManagementContext.java b/core/src/main/java/org/apache/brooklyn/core/management/internal/NonDeploymentManagementContext.java
index 9d98792..693e254 100644
--- a/core/src/main/java/org/apache/brooklyn/core/management/internal/NonDeploymentManagementContext.java
+++ b/core/src/main/java/org/apache/brooklyn/core/management/internal/NonDeploymentManagementContext.java
@@ -59,10 +59,10 @@ import org.apache.brooklyn.api.management.ha.ManagementPlaneSyncRecord;
 import org.apache.brooklyn.api.management.ha.ManagementPlaneSyncRecordPersister;
 import org.apache.brooklyn.api.mementos.BrooklynMementoPersister;
 import org.apache.brooklyn.api.mementos.BrooklynMementoRawData;
+import org.apache.brooklyn.core.catalog.internal.CatalogInitialization;
 import org.apache.brooklyn.core.management.entitlement.Entitlements;
 import org.apache.brooklyn.core.management.ha.OsgiManager;
 
-import brooklyn.catalog.internal.CatalogInitialization;
 import brooklyn.config.BrooklynProperties;
 import brooklyn.config.StringConfigMap;
 import brooklyn.entity.basic.AbstractEntity;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6caee589/core/src/main/java/org/apache/brooklyn/location/basic/BasicLocationRegistry.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/location/basic/BasicLocationRegistry.java b/core/src/main/java/org/apache/brooklyn/location/basic/BasicLocationRegistry.java
index 9a6466e..3cb9f14 100644
--- a/core/src/main/java/org/apache/brooklyn/location/basic/BasicLocationRegistry.java
+++ b/core/src/main/java/org/apache/brooklyn/location/basic/BasicLocationRegistry.java
@@ -40,9 +40,9 @@ import org.apache.brooklyn.api.location.LocationRegistry;
 import org.apache.brooklyn.api.location.LocationResolver;
 import org.apache.brooklyn.api.location.LocationSpec;
 import org.apache.brooklyn.api.management.ManagementContext;
+import org.apache.brooklyn.core.catalog.CatalogPredicates;
 import org.apache.brooklyn.core.management.internal.LocalLocationManager;
 
-import brooklyn.catalog.CatalogPredicates;
 import brooklyn.config.ConfigMap;
 import brooklyn.config.ConfigPredicates;
 import brooklyn.config.ConfigUtils;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6caee589/core/src/main/java/org/apache/brooklyn/location/basic/CatalogLocationResolver.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/location/basic/CatalogLocationResolver.java b/core/src/main/java/org/apache/brooklyn/location/basic/CatalogLocationResolver.java
index 0866649..55902ee 100644
--- a/core/src/main/java/org/apache/brooklyn/location/basic/CatalogLocationResolver.java
+++ b/core/src/main/java/org/apache/brooklyn/location/basic/CatalogLocationResolver.java
@@ -30,8 +30,7 @@ import org.apache.brooklyn.api.location.LocationRegistry;
 import org.apache.brooklyn.api.location.LocationResolver;
 import org.apache.brooklyn.api.location.LocationSpec;
 import org.apache.brooklyn.api.management.ManagementContext;
-
-import brooklyn.catalog.internal.CatalogUtils;
+import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
 
 /**
  * Given a location spec in the form {@code brooklyn.catalog:<symbolicName>:<version>}, 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6caee589/core/src/test/java/brooklyn/BrooklynVersionTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/BrooklynVersionTest.java b/core/src/test/java/brooklyn/BrooklynVersionTest.java
index 179e698..ebcfbd9 100644
--- a/core/src/test/java/brooklyn/BrooklynVersionTest.java
+++ b/core/src/test/java/brooklyn/BrooklynVersionTest.java
@@ -34,10 +34,9 @@ import org.testng.annotations.Test;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
 
-import brooklyn.catalog.internal.CatalogEntityItemDto;
-import brooklyn.catalog.internal.CatalogItemBuilder;
-import brooklyn.catalog.internal.CatalogItemDtoAbstract;
-
+import org.apache.brooklyn.core.catalog.internal.CatalogEntityItemDto;
+import org.apache.brooklyn.core.catalog.internal.CatalogItemBuilder;
+import org.apache.brooklyn.core.catalog.internal.CatalogItemDtoAbstract;
 import org.apache.brooklyn.core.management.internal.LocalManagementContext;
 import org.apache.brooklyn.core.management.osgi.OsgiTestResources;
 import org.apache.brooklyn.test.TestResourceUnavailableException;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6caee589/core/src/test/java/brooklyn/camp/lite/CampYamlLiteTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/camp/lite/CampYamlLiteTest.java b/core/src/test/java/brooklyn/camp/lite/CampYamlLiteTest.java
index 73cf5ce..d5590fc 100644
--- a/core/src/test/java/brooklyn/camp/lite/CampYamlLiteTest.java
+++ b/core/src/test/java/brooklyn/camp/lite/CampYamlLiteTest.java
@@ -49,13 +49,13 @@ import org.apache.brooklyn.api.catalog.CatalogItem.CatalogBundle;
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.entity.proxying.EntitySpec;
 import org.apache.brooklyn.api.management.Task;
+import org.apache.brooklyn.core.catalog.CatalogPredicates;
+import org.apache.brooklyn.core.catalog.internal.BasicBrooklynCatalog;
+import org.apache.brooklyn.core.catalog.internal.CatalogDto;
+import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
 import org.apache.brooklyn.core.management.internal.LocalManagementContext;
 import org.apache.brooklyn.core.management.osgi.OsgiStandaloneTest;
 
-import brooklyn.catalog.CatalogPredicates;
-import brooklyn.catalog.internal.BasicBrooklynCatalog;
-import brooklyn.catalog.internal.CatalogDto;
-import brooklyn.catalog.internal.CatalogUtils;
 import brooklyn.entity.basic.ApplicationBuilder;
 import brooklyn.entity.basic.ConfigKeys;
 import brooklyn.entity.basic.Entities;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6caee589/core/src/test/java/brooklyn/catalog/internal/CatalogDtoTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/catalog/internal/CatalogDtoTest.java b/core/src/test/java/brooklyn/catalog/internal/CatalogDtoTest.java
deleted file mode 100644
index 25a050e..0000000
--- a/core/src/test/java/brooklyn/catalog/internal/CatalogDtoTest.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package brooklyn.catalog.internal;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-import org.apache.brooklyn.api.catalog.CatalogItem.CatalogBundle;
-import org.apache.brooklyn.core.management.internal.LocalManagementContext;
-import org.apache.brooklyn.test.entity.LocalManagementContextForTests;
-import org.apache.brooklyn.test.entity.TestApplication;
-import org.apache.brooklyn.test.entity.TestEntity;
-
-import brooklyn.catalog.internal.CatalogClasspathDo.CatalogScanningModes;
-import brooklyn.entity.basic.Entities;
-import brooklyn.util.BrooklynMavenArtifacts;
-import brooklyn.util.maven.MavenRetriever;
-
-import com.google.common.collect.ImmutableList;
-
-public class CatalogDtoTest {
-
-    private static final Logger log = LoggerFactory.getLogger(CatalogDtoTest.class);
-
-    private LocalManagementContext managementContext;
-    
-    @BeforeMethod(alwaysRun = true)
-    public void setUp() throws Exception {
-        managementContext = LocalManagementContextForTests.newInstanceWithOsgi();
-    }
-    
-    @AfterMethod(alwaysRun = true)
-    public void tearDown() throws Exception {
-        if (managementContext != null) Entities.destroyAll(managementContext);
-    }
-
-    @Test(groups="Integration")
-    public void testCatalogLookup() {
-        CatalogDto root = buildExampleCatalog();
-        checkCatalogHealthy(root);
-    }
-    
-    @Test(groups="Integration")
-    public void testCatalogSerializeAndLookup() {
-        CatalogDto root = buildExampleCatalog();
-        CatalogXmlSerializer serializer = new CatalogXmlSerializer();
-        
-        String xml = serializer.toString(root);
-        log.info("Example catalog serialized as:\n"+xml);
-        
-        CatalogDto root2 = (CatalogDto) serializer.fromString(xml);
-        checkCatalogHealthy(root2);
-    }
-
-    protected void checkCatalogHealthy(CatalogDto root) {
-        assertEquals(root.catalogs.size(), 4);
-        CatalogDo loader = new CatalogDo(managementContext, root).load();
-        
-        // test app comes from jar, by default
-        CatalogItemDo<?,?> worker = loader.getIdCache().get(CatalogUtils.getVersionedId(TestApplication.class.getCanonicalName(), BasicBrooklynCatalog.NO_VERSION));
-        assertNotNull(worker);
-        assertEquals(worker.getDisplayName(), "Test App from JAR");
-        
-        // TODO can test scanned elements, links to other catalogs, etc
-    }
-
-    public CatalogDto buildExampleCatalog() {
-        CatalogDo root = new CatalogDo(
-                managementContext,
-                CatalogDto.newNamedInstance("My Local Catalog",
-                        "My favourite local settings, including remote catalogs -- intended partly as a teaching " +
-                        "example for what can be expressed, and how", "contents-built-in-test"));
-        root.setClasspathScanForEntities(CatalogScanningModes.NONE);
-
-        String bundleUrl = MavenRetriever.localUrl(BrooklynMavenArtifacts.artifact("", "brooklyn-core", "jar", "tests"));
-        CatalogDo testEntitiesJavaCatalog = new CatalogDo(
-                managementContext,
-                CatalogDto.newNamedInstance("Test Entities from Java", null, "test-java"));
-        testEntitiesJavaCatalog.setClasspathScanForEntities(CatalogScanningModes.NONE);
-        testEntitiesJavaCatalog.addToClasspath(bundleUrl);
-        testEntitiesJavaCatalog.addEntry(CatalogItemBuilder.newTemplate(TestApplication.class.getCanonicalName(), BasicBrooklynCatalog.NO_VERSION)
-                .displayName("Test App from JAR")
-                .javaType(TestApplication.class.getCanonicalName())
-                .build());
-        testEntitiesJavaCatalog.addEntry(CatalogItemBuilder.newEntity(TestEntity.class.getCanonicalName(), BasicBrooklynCatalog.NO_VERSION)
-                .displayName("Test Entity from JAR")
-                .javaType(TestEntity.class.getCanonicalName())
-                .build());
-        root.addCatalog(testEntitiesJavaCatalog.dto);
-
-        CatalogDo testEntitiesJavaCatalogScanning = new CatalogDo(
-                managementContext,
-                CatalogDto.newNamedInstance("Test Entities from Java Scanning", null, "test-java-scan"));
-        testEntitiesJavaCatalogScanning.addToClasspath(bundleUrl);
-        testEntitiesJavaCatalogScanning.setClasspathScanForEntities(CatalogScanningModes.ANNOTATIONS);
-        root.addCatalog(testEntitiesJavaCatalogScanning.dto);
-
-        CatalogDo osgiCatalog = new CatalogDo(
-                managementContext,
-                CatalogDto.newNamedInstance("Test Entities from OSGi",
-                        "A catalog whose entries define their libraries as a list of OSGi bundles", "test-osgi-defined"));
-        osgiCatalog.setClasspathScanForEntities(CatalogScanningModes.NONE);
-        CatalogEntityItemDto osgiEntity = CatalogItemBuilder.newEntity(TestEntity.class.getCanonicalName(), "Test Entity from OSGi")
-                // NB: this is not actually an OSGi bundle, but it's okay as we don't instantiate the bundles ahead of time (currently)
-                .libraries(ImmutableList.<CatalogBundle>of(new CatalogBundleDto(null, null, bundleUrl)))
-                .build();
-        testEntitiesJavaCatalog.addEntry(osgiEntity);
-        root.addCatalog(osgiCatalog.dto);
-
-        root.addCatalog(CatalogDto.newLinkedInstance("classpath://brooklyn-catalog-empty.xml"));
-        return root.dto;
-    }
-    
-    @Test
-    public void testVersionedIdSplitter() {
-        String id = "simple.id";
-        String version = "0.1.2";
-        String versionedId = CatalogUtils.getVersionedId(id, version);
-        
-        Assert.assertNull(CatalogUtils.getIdFromVersionedId(null));
-        Assert.assertNull(CatalogUtils.getVersionFromVersionedId(null));
-        Assert.assertNull(CatalogUtils.getIdFromVersionedId(id));
-        Assert.assertNull(CatalogUtils.getVersionFromVersionedId(version));
-        Assert.assertEquals(CatalogUtils.getIdFromVersionedId(versionedId), id);
-        Assert.assertEquals(CatalogUtils.getVersionFromVersionedId(versionedId), version);
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6caee589/core/src/test/java/brooklyn/catalog/internal/CatalogItemComparatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/catalog/internal/CatalogItemComparatorTest.java b/core/src/test/java/brooklyn/catalog/internal/CatalogItemComparatorTest.java
deleted file mode 100644
index 3e6fe6b..0000000
--- a/core/src/test/java/brooklyn/catalog/internal/CatalogItemComparatorTest.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package brooklyn.catalog.internal;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
-
-import org.testng.annotations.Test;
-import org.apache.brooklyn.api.catalog.CatalogItem;
-
-public class CatalogItemComparatorTest {
-    private static final String RC2 = "10.5.8-rc2";
-    private static final String STABLE = "10.5.8";
-
-    @Test
-    public void testComparison() {
-        compare("0.0.1", "0.0.2", 1);
-        compare("0.0.2", "0.0.1", -1);
-        compare("0.0.1-qual", "0.0.2", 1);
-        compare("0.0.1.qual", "0.0.2", 1);
-        compare("0.0.1-qual", "0.0.1_qual", 0);
-        compare("0.0.1.qual", "0.0.1.qual", 0);
-        compare("0.0.1", "0.0.2-SNAPSHOT", -1);
-        compare("0.0.1", "0.0.2.SNAPSHOT", -1);
-        compare("0.0.0_SNAPSHOT", "0.0.1-SNAPSHOT-20141111114709760", 1);
-        compare("0.0.0.SNAPSHOT", "0.0.1.SNAPSHOT-20141111114709760", 1);
-        compare("2.0", "2.0.1-BUILD", 1);
-        compare("2.0", "2.0.1.BUILD", 1);
-        compare("2.0.1", "2.0-BUILD", -1);
-        compare("2.0.1", "2.0.0.BUILD", -1);
-        compare("2.0", "2.0-BUILD", -1);
-        // Note not true for .qualifier: compare("2.0", "2.0.0.BUILD", -1);
-        compare("2.1", "2.0-BUILD", -1);
-        compare("2.1", "2.0.0.BUILD", -1);
-        compare("1", "1.3", 1);
-        compare("1-beta", "1-rc2", 1);
-        // Note not true for .qualifier: compare("1.0.0.beta", "1.0.0.rc2", 1);
-        compare("1-beta1", "1-beta10", 1);
-
-        compare(STABLE, "10.5", -1);
-        compare(STABLE, STABLE, 0);
-
-        compare(STABLE, "10.6", 1);
-        compare(STABLE, "10.5.8.1", 1);
-
-        compare("10.5.8-rc2", "10.5.8-rc3", 1) ;
-        compare("10.5.8-rc2", "10.5.8-rc1", -1);
-
-        compare(STABLE, RC2, -1);
-
-        CatalogItemComparator cmp = CatalogItemComparator.INSTANCE;
-        assertTrue(cmp.compare(v(RC2), v("10.5.8-beta1")) == cmp.compare(v(RC2), v("10.5.8-beta3")));
-    }
-    
-    private void compare(String v1, String v2, int expected) {
-        CatalogItemComparator cmp = CatalogItemComparator.INSTANCE;
-        assertEquals(cmp.compare(v(v1), v(v2)), expected);
-        assertEquals(cmp.compare(v(v2), v(v1)), -expected);
-    }
-    
-    private CatalogItem<?, ?> v(String version) {
-        return CatalogItemBuilder.newEntity("xxx", version).build();
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6caee589/core/src/test/java/brooklyn/catalog/internal/CatalogLoadTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/catalog/internal/CatalogLoadTest.java b/core/src/test/java/brooklyn/catalog/internal/CatalogLoadTest.java
deleted file mode 100644
index 2e92897..0000000
--- a/core/src/test/java/brooklyn/catalog/internal/CatalogLoadTest.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package brooklyn.catalog.internal;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertTrue;
-
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-import org.apache.brooklyn.api.catalog.CatalogItem.CatalogBundle;
-
-import brooklyn.util.ResourceUtils;
-
-import com.google.common.base.Joiner;
-import com.google.common.collect.Iterables;
-
-public class CatalogLoadTest {
-
-    CatalogXmlSerializer serializer;
-
-    @BeforeMethod
-    public void setUp() {
-        serializer = new CatalogXmlSerializer();
-    }
-
-    private String loadFile(String file) {
-        return ResourceUtils.create(this).getResourceAsString(file);
-    }
-
-    // CAMP YAML parsing not available in core, so YAML catalog tests are in camp, e.g. CatalogYamlEntitiesTest 
-    
-    @Test
-    public void testLoadXmlCatalog() {
-        CatalogDto catalog = (CatalogDto) serializer.fromString(
-                loadFile("classpath://brooklyn/catalog/internal/osgi-catalog.xml"));
-        assertNotNull(catalog);
-        assertEquals(catalog.name, "OSGi catalogue");
-        assertEquals(Iterables.size(catalog.getUniqueEntries()), 1, "Catalog entries = " + Joiner.on(", ").join(catalog.getUniqueEntries()));
-
-        CatalogItemDtoAbstract<?,?> template = Iterables.getOnlyElement(catalog.getUniqueEntries());
-        assertEquals(template.getDisplayName(), "Entity name");
-        assertEquals(template.getVersion(), "9.1.3");
-        assertEquals(template.getJavaType(), "com.example.ExampleApp");
-        assertEquals(template.getLibraries().size(), 2,
-                "Template bundles=" + Joiner.on(", ").join(template.getLibraries()));
-        
-        boolean foundBundle1 = false, foundBundle2 = false;
-        for (CatalogBundle bundle : template.getLibraries()) {
-            if (bundle.getUrl().equals("file://path/to/bundle.jar")) {
-                foundBundle1 = true;
-            }
-            if (bundle.getUrl().equals("http://www.url.com/for/bundle.jar")) {
-                foundBundle2 = true;
-            }
-        }
-        assertTrue(foundBundle1);
-        assertTrue(foundBundle2);
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6caee589/core/src/test/java/brooklyn/catalog/internal/CatalogScanTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/catalog/internal/CatalogScanTest.java b/core/src/test/java/brooklyn/catalog/internal/CatalogScanTest.java
deleted file mode 100644
index c417421..0000000
--- a/core/src/test/java/brooklyn/catalog/internal/CatalogScanTest.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package brooklyn.catalog.internal;
-
-import java.net.URLEncoder;
-import java.util.List;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.Test;
-import org.apache.brooklyn.api.catalog.BrooklynCatalog;
-import org.apache.brooklyn.api.catalog.CatalogItem;
-import org.apache.brooklyn.api.entity.Application;
-import org.apache.brooklyn.api.entity.proxying.EntitySpec;
-import org.apache.brooklyn.core.management.internal.LocalManagementContext;
-
-import brooklyn.catalog.CatalogPredicates;
-import brooklyn.catalog.internal.MyCatalogItems.MySillyAppTemplate;
-import brooklyn.config.BrooklynProperties;
-import brooklyn.config.BrooklynServerConfig;
-import brooklyn.entity.basic.Entities;
-import brooklyn.util.ResourceUtils;
-import brooklyn.util.net.Urls;
-import brooklyn.util.text.Strings;
-
-import com.google.common.base.Predicates;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-
-public class CatalogScanTest {
-
-    private static final Logger log = LoggerFactory.getLogger(CatalogScanTest.class);
-
-    private BrooklynCatalog defaultCatalog, annotsCatalog, fullCatalog;
-    
-    private List<LocalManagementContext> managementContexts = Lists.newCopyOnWriteArrayList();
-
-    @AfterMethod(alwaysRun = true)
-    public void tearDown(){
-        for (LocalManagementContext managementContext : managementContexts) {
-            Entities.destroyAll(managementContext);
-        }
-        managementContexts.clear();
-    }
-    
-    private LocalManagementContext newManagementContext(BrooklynProperties props) {
-        LocalManagementContext result = new LocalManagementContext(props);
-        managementContexts.add(result);
-        return result;
-    }
-    
-    private synchronized void loadFullCatalog() {
-        if (fullCatalog!=null) return;
-        BrooklynProperties props = BrooklynProperties.Factory.newEmpty();
-        props.put(BrooklynServerConfig.BROOKLYN_CATALOG_URL.getName(), 
-                "data:,"+Urls.encode("<catalog><classpath scan=\"types\"/></catalog>"));
-        fullCatalog = newManagementContext(props).getCatalog();        
-        log.info("ENTITIES loaded for FULL: "+fullCatalog.getCatalogItems(Predicates.alwaysTrue()));
-    }
-    
-    private synchronized void loadTheDefaultCatalog(boolean lookOnDiskForDefaultCatalog) {
-        if (defaultCatalog!=null) return;
-        BrooklynProperties props = BrooklynProperties.Factory.newEmpty();
-        props.put(BrooklynServerConfig.BROOKLYN_CATALOG_URL.getName(),
-            // if default catalog is picked up from the system, we might get random stuff from ~/.brooklyn/ instead of the default;
-            // useful as an integration check that we default correctly, but irritating for people to use if they have such a catalog installed
-            (lookOnDiskForDefaultCatalog ? "" :
-                "data:,"+Urls.encode(new ResourceUtils(this).getResourceAsString("classpath:/brooklyn/default.catalog.bom"))));
-        LocalManagementContext managementContext = newManagementContext(props);
-        defaultCatalog = managementContext.getCatalog();        
-        log.info("ENTITIES loaded for DEFAULT: "+defaultCatalog.getCatalogItems(Predicates.alwaysTrue()));
-    }
-    
-    @SuppressWarnings("deprecation")
-    private synchronized void loadAnnotationsOnlyCatalog() {
-        if (annotsCatalog!=null) return;
-        BrooklynProperties props = BrooklynProperties.Factory.newEmpty();
-        props.put(BrooklynServerConfig.BROOKLYN_CATALOG_URL.getName(),
-                "data:,"+URLEncoder.encode("<catalog><classpath scan=\"annotations\"/></catalog>"));
-        LocalManagementContext managementContext = newManagementContext(props);
-        annotsCatalog = managementContext.getCatalog();
-        log.info("ENTITIES loaded with annotation: "+annotsCatalog.getCatalogItems(Predicates.alwaysTrue()));
-    }
-    
-    @Test
-    public void testLoadAnnotations() {
-        loadAnnotationsOnlyCatalog();
-        BrooklynCatalog c = annotsCatalog;
-        
-        Iterable<CatalogItem<Object,Object>> bases = c.getCatalogItems(CatalogPredicates.displayName(Predicates.containsPattern("MyBaseEntity")));
-        Assert.assertEquals(Iterables.size(bases), 0, "should have been empty: "+bases);
-        
-        Iterable<CatalogItem<Object,Object>> asdfjkls = c.getCatalogItems(CatalogPredicates.displayName(Predicates.containsPattern("__asdfjkls__shouldnotbefound")));
-        Assert.assertEquals(Iterables.size(asdfjkls), 0);
-        
-        Iterable<CatalogItem<Object,Object>> silly1 = c.getCatalogItems(CatalogPredicates.displayName(Predicates.equalTo("MySillyAppTemplate")));
-        Iterable<CatalogItem<Object,Object>> silly2 = c.getCatalogItems(CatalogPredicates.javaType(Predicates.equalTo(MySillyAppTemplate.class.getName())));
-        CatalogItem<Object, Object> silly1El = Iterables.getOnlyElement(silly1);
-        Assert.assertEquals(silly1El, Iterables.getOnlyElement(silly2));
-        
-        CatalogItem<Application,EntitySpec<? extends Application>> s1 = c.getCatalogItem(Application.class, silly1El.getSymbolicName(), silly1El.getVersion());
-        Assert.assertEquals(s1, silly1El);
-        
-        Assert.assertEquals(s1.getDescription(), "Some silly app test");
-        
-        Class<? extends Application> app = c.loadClass(s1);
-        Assert.assertEquals(MySillyAppTemplate.class, app);
-        
-        String xml = ((BasicBrooklynCatalog)c).toXmlString();
-        log.info("Catalog is:\n"+xml);
-        Assert.assertTrue(xml.indexOf("Some silly app test") >= 0);
-    }
-
-    @Test
-    public void testAnnotationLoadsSomeApps() {
-        loadAnnotationsOnlyCatalog();
-        Iterable<CatalogItem<Object,Object>> silly1 = annotsCatalog.getCatalogItems(CatalogPredicates.displayName(Predicates.equalTo("MySillyAppTemplate")));
-        Assert.assertEquals(Iterables.getOnlyElement(silly1).getDescription(), "Some silly app test");
-    }
-    
-    @Test
-    public void testAnnotationLoadsSomeAppBuilders() {
-        loadAnnotationsOnlyCatalog();
-        Iterable<CatalogItem<Object,Object>> silly1 = annotsCatalog.getCatalogItems(CatalogPredicates.displayName(Predicates.equalTo("MySillyAppBuilderTemplate")));
-        Assert.assertEquals(Iterables.getOnlyElement(silly1).getDescription(), "Some silly app builder test");
-    }
-    
-    @Test
-    public void testMoreTypesThanAnnotations() {
-        loadAnnotationsOnlyCatalog();
-        loadFullCatalog();
-        
-        int numFromAnnots = Iterables.size(annotsCatalog.getCatalogItems(Predicates.alwaysTrue()));
-        int numFromTypes = Iterables.size(fullCatalog.getCatalogItems(Predicates.alwaysTrue()));
-        
-        Assert.assertTrue(numFromAnnots < numFromTypes, "full="+numFromTypes+" annots="+numFromAnnots);
-    }
-    
-    @Test
-    public void testMoreTypesThanAnnotationsForApps() {
-        loadAnnotationsOnlyCatalog();
-        loadFullCatalog();
-        
-        int numFromAnnots = Iterables.size(annotsCatalog.getCatalogItems(CatalogPredicates.IS_TEMPLATE));
-        int numFromTypes = Iterables.size(fullCatalog.getCatalogItems(CatalogPredicates.IS_TEMPLATE));
-        
-        Assert.assertTrue(numFromAnnots < numFromTypes, "full="+numFromTypes+" annots="+numFromAnnots);
-    }
-    
-    @Test
-    public void testAnnotationIsDefault() {
-        doTestAnnotationIsDefault(false);
-    }
-    
-    // see comment in load method; likely fails if a custom catalog is installed in ~/.brooklyn/
-    @Test(groups="Integration", enabled=false)
-    public void testAnnotationIsDefaultOnDisk() {
-        doTestAnnotationIsDefault(true);
-    }
-
-    private void doTestAnnotationIsDefault(boolean lookOnDiskForDefaultCatalog) {
-        loadTheDefaultCatalog(false);
-        int numInDefault = Iterables.size(defaultCatalog.getCatalogItems(Predicates.alwaysTrue()));
-        
-        loadAnnotationsOnlyCatalog();
-        int numFromAnnots = Iterables.size(annotsCatalog.getCatalogItems(Predicates.alwaysTrue()));
-        
-        Assert.assertEquals(numInDefault, numFromAnnots);
-        Assert.assertTrue(numInDefault>0, "Expected more than 0 entries");
-    }
-
-    // a simple test asserting no errors when listing the real catalog, and listing them for reference
-    // also useful to test variants in a stored catalog to assert they all load
-    // TODO integration tests which build up catalogs assuming other things are installed
-    @Test
-    public void testListCurrentCatalogItems() {
-        LocalManagementContext mgmt = newManagementContext(BrooklynProperties.Factory.newDefault());
-        log.info("ITEMS\n"+Strings.join(mgmt.getCatalog().getCatalogItems(), "\n"));
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6caee589/core/src/test/java/brooklyn/catalog/internal/CatalogTestUtils.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/catalog/internal/CatalogTestUtils.java b/core/src/test/java/brooklyn/catalog/internal/CatalogTestUtils.java
deleted file mode 100644
index b420860..0000000
--- a/core/src/test/java/brooklyn/catalog/internal/CatalogTestUtils.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package brooklyn.catalog.internal;
-
-import org.apache.brooklyn.api.catalog.CatalogItem;
-import org.apache.brooklyn.api.entity.proxying.EntitySpec;
-import org.apache.brooklyn.api.management.ManagementContext;
-import org.apache.brooklyn.api.management.classloading.BrooklynClassLoadingContext;
-
-import com.google.common.annotations.Beta;
-
-public class CatalogTestUtils {
-
-    /** creates entity spec with the java type of a catalog item;
-     * would be nice to have this in {@link CatalogUtils},
-     * but the logic for parsing the yaml is buried in camp code,
-     * so it's a little bit hard to make this a first class method.
-     * <p>
-     * (this impl ignores many things, including config and location.)
-     */
-    @Beta
-    public static EntitySpec<?> createEssentialEntitySpec(ManagementContext mgmt, CatalogItem<?, ?> catalogItem) {
-        BrooklynClassLoadingContext loader = CatalogUtils.newClassLoadingContext(mgmt, catalogItem);
-        @SuppressWarnings({ "unchecked", "rawtypes" })
-        EntitySpec<?> spec = EntitySpec.create( (Class)loader.loadClass(catalogItem.getJavaType()) );
-        spec.catalogItemId(catalogItem.getId());
-        return spec;
-    }
-
-}


Mime
View raw message