Skip to content
Permalink
Browse files
This closes #1147
  • Loading branch information
aledsage committed Jan 14, 2016
2 parents e2392c3 + 9c64872 commit a2fde1af6da656e3b81ab31e61e35d445c201f76
Showing 3 changed files with 19 additions and 6 deletions.
@@ -36,7 +36,8 @@ public CatalogXmlSerializer() {
super(DeserializingClassRenamesProvider.loadDeserializingClassRenames());

xstream.addDefaultImplementation(ArrayList.class, Collection.class);


//Doesn't work well for non-standard lists, like Lists.transform results
xstream.aliasType("list", List.class);
xstream.aliasType("map", Map.class);

@@ -19,6 +19,7 @@
package org.apache.brooklyn.core.mgmt;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.codehaus.jackson.annotate.JsonIgnore;
@@ -85,11 +86,17 @@ public int hashCode() {

public static class TraitsTag extends ListTag<String> {
public TraitsTag(List<Class<?>> interfaces) {
super(Lists.transform(interfaces, new Function<Class<?>, String>() {
@Override public String apply(Class<?> input) {
return input.getName();
}
}));
// The transformed list is a view, meaning that it references
// the instances list. This means that it will serialize
// the list of classes along with the anonymous function which
// is not what we want. Force eager evaluation instead, using
// a simple list, supported by {@link CatalogXmlSerializer}.
super(new ArrayList<String>(
Lists.transform(interfaces, new Function<Class<?>, String>() {
@Override public String apply(Class<?> input) {
return input.getName();
}
})));
}

@JsonProperty("traits")
@@ -39,12 +39,14 @@
import org.apache.brooklyn.core.catalog.internal.CatalogXmlSerializer;
import org.apache.brooklyn.core.catalog.internal.CatalogClasspathDo.CatalogScanningModes;
import org.apache.brooklyn.core.entity.Entities;
import org.apache.brooklyn.core.mgmt.BrooklynTags;
import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
import org.apache.brooklyn.core.test.entity.TestApplication;
import org.apache.brooklyn.core.test.entity.TestEntity;
import org.apache.brooklyn.util.core.BrooklynMavenArtifacts;
import org.apache.brooklyn.util.maven.MavenRetriever;
import org.apache.commons.lang3.ClassUtils;

import com.google.common.collect.ImmutableList;

@@ -111,6 +113,9 @@ public CatalogDto buildExampleCatalog() {
testEntitiesJavaCatalog.addEntry(CatalogItemBuilder.newTemplate(TestApplication.class.getCanonicalName(), BasicBrooklynCatalog.NO_VERSION)
.displayName("Test App from JAR")
.javaType(TestApplication.class.getCanonicalName())
.tag(BrooklynTags.newNotesTag("Some notes for catalog testing"))
.tag(BrooklynTags.newYamlSpecTag("This is the spec for a test catalog item"))
.tag(BrooklynTags.newTraitsTag(ClassUtils.getAllInterfaces(TestApplication.class)))
.build());
testEntitiesJavaCatalog.addEntry(CatalogItemBuilder.newEntity(TestEntity.class.getCanonicalName(), BasicBrooklynCatalog.NO_VERSION)
.displayName("Test Entity from JAR")

0 comments on commit a2fde1a

Please sign in to comment.