Search in sources :

Example 1 with Tag

use of com.amazonaws.services.cloudformation.model.Tag in project pipeline-aws-plugin by jenkinsci.

the class TagsFileParser method parseTags.

public static Collection<Tag> parseTags(InputStream is) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    JsonNode tree = mapper.readTree(is);
    ArrayNode jsonNodes = (ArrayNode) tree;
    return StreamSupport.stream(jsonNodes.spliterator(), false).map(node -> {
        return new Tag().withKey(node.get("Key").asText()).withValue(node.get("Value").asText());
    }).collect(Collectors.toList());
}
Also used : ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Tag(com.amazonaws.services.cloudformation.model.Tag) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) StreamSupport(java.util.stream.StreamSupport) Collectors(java.util.stream.Collectors) InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Tag(com.amazonaws.services.cloudformation.model.Tag) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with Tag

use of com.amazonaws.services.cloudformation.model.Tag in project pipeline-aws-plugin by jenkinsci.

the class TagsFileParserTests method parseJson.

@Test
public void parseJson() throws IOException {
    Collection<Tag> tags = TagsFileParser.parseTags(getClass().getResourceAsStream("tags.json"));
    Assertions.assertThat(tags).containsExactlyInAnyOrder(new Tag().withKey("foo1").withValue("bar1"), new Tag().withKey("foo2").withValue("bar2"));
}
Also used : Tag(com.amazonaws.services.cloudformation.model.Tag) Test(org.junit.Test)

Example 3 with Tag

use of com.amazonaws.services.cloudformation.model.Tag in project pipeline-aws-plugin by jenkinsci.

the class TemplateStepBase method getAwsTags.

protected final Collection<Tag> getAwsTags() {
    Collection<Tag> tagList = new ArrayList<>();
    if (this.tags == null) {
        return tagList;
    }
    for (String tag : this.tags) {
        int i = tag.indexOf('=');
        if (i < 0) {
            throw new IllegalArgumentException("Missing = in tag " + tag);
        }
        String key = tag.substring(0, i);
        String value = tag.substring(i + 1);
        tagList.add(new Tag().withKey(key).withValue(value));
    }
    return tagList;
}
Also used : ArrayList(java.util.ArrayList) Tag(com.amazonaws.services.cloudformation.model.Tag)

Example 4 with Tag

use of com.amazonaws.services.cloudformation.model.Tag in project pipeline-aws-plugin by jenkinsci.

the class TemplateStepBase method getAwsTags.

protected final Collection<Tag> getAwsTags(StepExecution stepExecution) {
    Collection<Tag> tagList = new ArrayList<>();
    if (this.tags != null) {
        for (String tag : this.tags) {
            int i = tag.indexOf('=');
            if (i < 0) {
                throw new IllegalArgumentException("Missing = in tag " + tag);
            }
            String key = tag.substring(0, i);
            String value = tag.substring(i + 1);
            tagList.add(new Tag().withKey(key).withValue(value));
        }
    }
    if (this.tagsFile != null) {
        FilePath tagsFile = loadFileFromWorkspace(stepExecution, this.tagsFile);
        try {
            tagList.addAll(TagsFileParser.parseTags(tagsFile.read()));
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        } catch (InterruptedException e) {
            Thread.interrupted();
            throw new RuntimeException(e);
        }
    }
    return tagList;
}
Also used : FilePath(hudson.FilePath) ArrayList(java.util.ArrayList) UncheckedIOException(java.io.UncheckedIOException) Tag(com.amazonaws.services.cloudformation.model.Tag) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Aggregations

Tag (com.amazonaws.services.cloudformation.model.Tag)4 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 FilePath (hudson.FilePath)1 InputStream (java.io.InputStream)1 UncheckedIOException (java.io.UncheckedIOException)1 Collection (java.util.Collection)1 Collectors (java.util.stream.Collectors)1 StreamSupport (java.util.stream.StreamSupport)1 Test (org.junit.Test)1