Repository: jclouds Updated Branches: refs/heads/master 02b2e80b2 -> 773aa30c6
JCLOUDS-1067: Fix cookbook grouping mapping in Chef metadata Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/773aa30c Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/773aa30c Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/773aa30c Branch: refs/heads/master Commit: 773aa30c64108f5dc28a6fefb58d1ca4baa016ae Parents: 02b2e80 Author: Ignasi Barrera <[email protected]> Authored: Mon Jan 25 15:39:06 2016 +0100 Committer: Ignasi Barrera <[email protected]> Committed: Thu Jan 28 15:12:29 2016 +0100 ---------------------------------------------------------------------- .../java/org/jclouds/chef/domain/Grouping.java | 103 +++++++++++++++++++ .../java/org/jclouds/chef/domain/Metadata.java | 12 +-- .../ParseCookbookVersionFromJsonTest.java | 6 +- .../resources/apache-chef-demo-cookbook.json | 11 +- 4 files changed, 124 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jclouds/blob/773aa30c/apis/chef/src/main/java/org/jclouds/chef/domain/Grouping.java ---------------------------------------------------------------------- diff --git a/apis/chef/src/main/java/org/jclouds/chef/domain/Grouping.java b/apis/chef/src/main/java/org/jclouds/chef/domain/Grouping.java new file mode 100644 index 0000000..c9c739e --- /dev/null +++ b/apis/chef/src/main/java/org/jclouds/chef/domain/Grouping.java @@ -0,0 +1,103 @@ +/* + * 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.jclouds.chef.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; + +/** + * Information of a group of attributes in a namespace. + */ +public class Grouping { + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private String title; + private String description; + + public Builder title(String title) { + this.title = checkNotNull(title, "title"); + return this; + } + + public Builder description(String description) { + this.description = description; + return this; + } + + public Grouping build() { + return new Grouping(title, description); + } + } + + private final String title; + private final String description; + + @ConstructorProperties({ "title", "description" }) + protected Grouping(String title, String description) { + this.title = title; + this.description = description; + } + + public String getTitle() { + return title; + } + + public String getDescription() { + return description; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((title == null) ? 0 : title.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Grouping other = (Grouping) obj; + if (description == null) { + if (other.description != null) + return false; + } else if (!description.equals(other.description)) + return false; + if (title == null) { + if (other.title != null) + return false; + } else if (!title.equals(other.title)) + return false; + return true; + } + + @Override + public String toString() { + return "Grouping [title=" + title + ", description=" + description + "]"; + } + +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/773aa30c/apis/chef/src/main/java/org/jclouds/chef/domain/Metadata.java ---------------------------------------------------------------------- diff --git a/apis/chef/src/main/java/org/jclouds/chef/domain/Metadata.java b/apis/chef/src/main/java/org/jclouds/chef/domain/Metadata.java index 33f8dfb..7da6c67 100644 --- a/apis/chef/src/main/java/org/jclouds/chef/domain/Metadata.java +++ b/apis/chef/src/main/java/org/jclouds/chef/domain/Metadata.java @@ -49,7 +49,7 @@ public class Metadata { private ImmutableMap.Builder<String, String> recipes = ImmutableMap.builder(); private ImmutableMap.Builder<String, String> replacing = ImmutableMap.builder(); private String name; - private ImmutableMap.Builder<String, String> groupings = ImmutableMap.builder(); + private ImmutableMap.Builder<String, Grouping> groupings = ImmutableMap.builder(); private String longDescription; private ImmutableMap.Builder<String, Attribute> attributes = ImmutableMap.builder(); private ImmutableMap.Builder<String, String> recommendations = ImmutableMap.builder(); @@ -154,12 +154,12 @@ public class Metadata { return this; } - public Builder grouping(String key, String value) { + public Builder grouping(String key, Grouping value) { this.groupings.put(checkNotNull(key, "key"), checkNotNull(value, "value")); return this; } - public Builder grouping(Map<String, String> groupings) { + public Builder grouping(Map<String, Grouping> groupings) { this.groupings.putAll(checkNotNull(groupings, "groupings")); return this; } @@ -211,7 +211,7 @@ public class Metadata { private final Map<String, String> recipes; private final Map<String, String> replacing; private final String name; - private final Map<String, String> groupings; + private final Map<String, Grouping> groupings; @SerializedName("long_description") private final String longDescription; private final Map<String, Attribute> attributes; @@ -224,7 +224,7 @@ public class Metadata { @Nullable Map<String, String> dependencies, String maintainerEmail, @Nullable Map<String, String> conflicting, String description, @Nullable Map<String, String> providing, @Nullable Map<String, String> platforms, String version, @Nullable Map<String, String> recipes, @Nullable Map<String, String> replacing, String name, - @Nullable Map<String, String> groupings, String longDescription, @Nullable Map<String, Attribute> attributes, + @Nullable Map<String, Grouping> groupings, String longDescription, @Nullable Map<String, Attribute> attributes, @Nullable Map<String, String> recommendations) { this.license = license; this.maintainer = maintainer; @@ -297,7 +297,7 @@ public class Metadata { return name; } - public Map<String, String> getGroupings() { + public Map<String, Grouping> getGroupings() { return groupings; } http://git-wip-us.apache.org/repos/asf/jclouds/blob/773aa30c/apis/chef/src/test/java/org/jclouds/chef/functions/ParseCookbookVersionFromJsonTest.java ---------------------------------------------------------------------- diff --git a/apis/chef/src/test/java/org/jclouds/chef/functions/ParseCookbookVersionFromJsonTest.java b/apis/chef/src/test/java/org/jclouds/chef/functions/ParseCookbookVersionFromJsonTest.java index 7bc19bf..598fbe8 100644 --- a/apis/chef/src/test/java/org/jclouds/chef/functions/ParseCookbookVersionFromJsonTest.java +++ b/apis/chef/src/test/java/org/jclouds/chef/functions/ParseCookbookVersionFromJsonTest.java @@ -25,6 +25,7 @@ import java.net.URI; import org.jclouds.chef.ChefApiMetadata; import org.jclouds.chef.config.ChefParserModule; import org.jclouds.chef.domain.CookbookVersion; +import org.jclouds.chef.domain.Grouping; import org.jclouds.chef.domain.Metadata; import org.jclouds.chef.domain.Resource; import org.jclouds.http.HttpResponse; @@ -101,8 +102,11 @@ public class ParseCookbookVersionFromJsonTest { .maintainer("Your Name") // .maintainerEmail("[email protected]") // .description("A fabulous new cookbook") // - .version("0.0.0").name("apache-chef-demo") // + .version("0.0.0") // + .name("apache-chef-demo") // .longDescription("") // + .grouping("one", Grouping.builder().title("One title").description("One description").build()) // + .grouping("two", Grouping.builder().title("Two title").description("Two description").build()) // .build()) .rootFile( Resource http://git-wip-us.apache.org/repos/asf/jclouds/blob/773aa30c/apis/chef/src/test/resources/apache-chef-demo-cookbook.json ---------------------------------------------------------------------- diff --git a/apis/chef/src/test/resources/apache-chef-demo-cookbook.json b/apis/chef/src/test/resources/apache-chef-demo-cookbook.json index 228a3c0..8df911f 100644 --- a/apis/chef/src/test/resources/apache-chef-demo-cookbook.json +++ b/apis/chef/src/test/resources/apache-chef-demo-cookbook.json @@ -17,7 +17,16 @@ "long_description": "", "recommendations": {}, "version": "0.0.0", - "groupings": {}, + "groupings": { + "one": { + "title": "One title", + "description": "One description" + }, + "two": { + "title": "Two title", + "description": "Two description" + } + }, "recipes": {}, "conflicting": {}, "description": "A fabulous new cookbook",
