diff --git a/build.gradle b/build.gradle index 27911d1..2fc95e8 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { dependencies { classpath "com.blackducksoftware.integration:common-gradle-plugin:0.0.+" } } -version = '14.0.1-SNAPSHOT' +version = '15.0.0' apply plugin: 'com.blackducksoftware.integration.library' @@ -17,7 +17,7 @@ versionFile.delete() versionFile << version dependencies { - compile 'com.blackducksoftware.integration:integration-common:11.0.0' + compile 'com.blackducksoftware.integration:integration-common:11.1.1' testCompile 'org.mockito:mockito-core:2.18.3' testCompile 'org.skyscreamer:jsonassert:1.5.0' diff --git a/src/main/java/com/blackducksoftware/integration/hub/bdio/BdioNodeFactory.java b/src/main/java/com/blackducksoftware/integration/hub/bdio/BdioNodeFactory.java index e488f25..e3ff0d2 100644 --- a/src/main/java/com/blackducksoftware/integration/hub/bdio/BdioNodeFactory.java +++ b/src/main/java/com/blackducksoftware/integration/hub/bdio/BdioNodeFactory.java @@ -39,7 +39,7 @@ import com.blackducksoftware.integration.hub.bdio.model.BdioCreationInfo; import com.blackducksoftware.integration.hub.bdio.model.BdioExternalIdentifier; import com.blackducksoftware.integration.hub.bdio.model.BdioProject; -import com.blackducksoftware.integration.hub.bdio.model.ToolSpdxCreator; +import com.blackducksoftware.integration.hub.bdio.model.SpdxCreator; import com.blackducksoftware.integration.hub.bdio.model.externalid.ExternalId; public class BdioNodeFactory { @@ -66,7 +66,7 @@ public BdioBillOfMaterials createBillOfMaterials(final String codeLocationName, version = IOUtils.toString(inputStream, StandardCharsets.UTF_8); } catch (final IOException e) { } - billOfMaterials.creationInfo.addSpdxCreator(new ToolSpdxCreator("IntegrationBdio", version)); + billOfMaterials.creationInfo.addSpdxCreator(SpdxCreator.createToolSpdxCreator("IntegrationBdio", version)); return billOfMaterials; } diff --git a/src/main/java/com/blackducksoftware/integration/hub/bdio/model/BdioCreationInfo.java b/src/main/java/com/blackducksoftware/integration/hub/bdio/model/BdioCreationInfo.java index 739d19b..bd97c6a 100644 --- a/src/main/java/com/blackducksoftware/integration/hub/bdio/model/BdioCreationInfo.java +++ b/src/main/java/com/blackducksoftware/integration/hub/bdio/model/BdioCreationInfo.java @@ -36,6 +36,12 @@ public class BdioCreationInfo { @SerializedName("spdx:created") public String created; + // ekerwin 2018-06-11 + // The Hub only supports a single creator and if there are multiple creators, the Hub will use only the first one. + public void setPrimarySpdxCreator(final SpdxCreator spdxCreator) { + creator.add(0, spdxCreator.getData()); + } + public void addSpdxCreator(final SpdxCreator spdxCreator) { creator.add(spdxCreator.getData()); } diff --git a/src/main/java/com/blackducksoftware/integration/hub/bdio/model/SpdxCreator.java b/src/main/java/com/blackducksoftware/integration/hub/bdio/model/SpdxCreator.java index a34226c..87309e6 100644 --- a/src/main/java/com/blackducksoftware/integration/hub/bdio/model/SpdxCreator.java +++ b/src/main/java/com/blackducksoftware/integration/hub/bdio/model/SpdxCreator.java @@ -27,8 +27,19 @@ public class SpdxCreator { public String type; public String identifier; + public SpdxCreator(final String type, final String identifier) { + this.type = type; + this.identifier = identifier; + } + public String getData() { return String.format("%s: %s", type, identifier); } + public static SpdxCreator createToolSpdxCreator(final String name, final String version) { + final String identifier = String.format("%s-%s", name, version); + final SpdxCreator spdxCreator = new SpdxCreator("Tool", identifier); + return spdxCreator; + } + } diff --git a/src/main/java/com/blackducksoftware/integration/hub/bdio/model/ToolSpdxCreator.java b/src/main/java/com/blackducksoftware/integration/hub/bdio/model/ToolSpdxCreator.java deleted file mode 100644 index b27b193..0000000 --- a/src/main/java/com/blackducksoftware/integration/hub/bdio/model/ToolSpdxCreator.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * integration-bdio - * - * Copyright (C) 2018 Black Duck Software, Inc. - * http://www.blackducksoftware.com/ - * - * 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 com.blackducksoftware.integration.hub.bdio.model; - -public class ToolSpdxCreator extends SpdxCreator { - public ToolSpdxCreator(final String name, final String version) { - this.type = "Tool"; - this.identifier = String.format("%s-%s", name, version); - } - -} diff --git a/src/main/resources/com/blackducksoftware/integration/hub/bdio/version.txt b/src/main/resources/com/blackducksoftware/integration/hub/bdio/version.txt index 4703655..791fc94 100644 --- a/src/main/resources/com/blackducksoftware/integration/hub/bdio/version.txt +++ b/src/main/resources/com/blackducksoftware/integration/hub/bdio/version.txt @@ -1 +1 @@ -12.2.0-SNAPSHOT \ No newline at end of file +15.0.0 \ No newline at end of file diff --git a/src/test/java/com/blackducksoftware/integration/hub/bdio/BdioNodeFactoryTest.java b/src/test/java/com/blackducksoftware/integration/hub/bdio/BdioNodeFactoryTest.java index 0d2b04e..2a9ea4a 100644 --- a/src/test/java/com/blackducksoftware/integration/hub/bdio/BdioNodeFactoryTest.java +++ b/src/test/java/com/blackducksoftware/integration/hub/bdio/BdioNodeFactoryTest.java @@ -23,22 +23,32 @@ */ package com.blackducksoftware.integration.hub.bdio; -import com.blackducksoftware.integration.hub.bdio.model.*; -import com.blackducksoftware.integration.hub.bdio.model.externalid.ExternalId; -import com.blackducksoftware.integration.hub.bdio.model.externalid.ExternalIdFactory; -import com.blackducksoftware.integration.hub.bdio.utility.JsonTestUtils; -import com.google.gson.Gson; -import org.json.JSONException; -import org.junit.Test; +import static org.junit.Assert.assertEquals; -import java.io.*; +import java.io.ByteArrayOutputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static org.junit.Assert.assertEquals; +import org.json.JSONException; +import org.junit.Test; + +import com.blackducksoftware.integration.hub.bdio.model.BdioBillOfMaterials; +import com.blackducksoftware.integration.hub.bdio.model.BdioComponent; +import com.blackducksoftware.integration.hub.bdio.model.BdioCreationInfo; +import com.blackducksoftware.integration.hub.bdio.model.BdioProject; +import com.blackducksoftware.integration.hub.bdio.model.SimpleBdioDocument; +import com.blackducksoftware.integration.hub.bdio.model.SpdxCreator; +import com.blackducksoftware.integration.hub.bdio.model.externalid.ExternalId; +import com.blackducksoftware.integration.hub.bdio.model.externalid.ExternalIdFactory; +import com.blackducksoftware.integration.hub.bdio.utility.JsonTestUtils; +import com.google.gson.Gson; public class BdioNodeFactoryTest { private final JsonTestUtils jsonTestUtils = new JsonTestUtils(); @@ -100,7 +110,7 @@ private SimpleBdioDocument getSimpleBdioDocument() { final BdioBillOfMaterials bdioBillOfMaterials = bdioNodeFactory.createBillOfMaterials("", projectName, projectVersion); // we are overriding the default value of a new creation info just to pass the json comparison bdioBillOfMaterials.creationInfo = new BdioCreationInfo(); - bdioBillOfMaterials.creationInfo.addSpdxCreator(new ToolSpdxCreator("integration-bdio-test", "0.0.1-SNAPSHOT")); + bdioBillOfMaterials.creationInfo.addSpdxCreator(SpdxCreator.createToolSpdxCreator("integration-bdio-test", "0.0.1-SNAPSHOT")); // we are overriding the default value of a new uuid just to pass the json comparison bdioBillOfMaterials.id = "uuid:45772d33-5353-44f1-8681-3d8a15540646"; diff --git a/src/test/java/com/blackducksoftware/integration/hub/bdio/model/BdioCreationInfoTest.java b/src/test/java/com/blackducksoftware/integration/hub/bdio/model/BdioCreationInfoTest.java new file mode 100644 index 0000000..e025a4a --- /dev/null +++ b/src/test/java/com/blackducksoftware/integration/hub/bdio/model/BdioCreationInfoTest.java @@ -0,0 +1,28 @@ +package com.blackducksoftware.integration.hub.bdio.model; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class BdioCreationInfoTest { + @Test + public void testAddingMultipleCreators() { + final BdioCreationInfo bdioCreationInfo = new BdioCreationInfo(); + bdioCreationInfo.addSpdxCreator(SpdxCreator.createToolSpdxCreator("a simple tool", "2.0")); + bdioCreationInfo.addSpdxCreator(SpdxCreator.createToolSpdxCreator("another simple tool", "1.0")); + + assertEquals(2, bdioCreationInfo.getCreator().size()); + assertEquals("Tool: a simple tool-2.0", bdioCreationInfo.getCreator().get(0)); + } + + @Test + public void testSettingPrimaryCreator() { + final BdioCreationInfo bdioCreationInfo = new BdioCreationInfo(); + bdioCreationInfo.addSpdxCreator(SpdxCreator.createToolSpdxCreator("a simple tool", "2.0")); + bdioCreationInfo.setPrimarySpdxCreator(SpdxCreator.createToolSpdxCreator("another simple tool", "1.0")); + + assertEquals(2, bdioCreationInfo.getCreator().size()); + assertEquals("Tool: another simple tool-1.0", bdioCreationInfo.getCreator().get(0)); + } + +}