Skip to content

Commit

Permalink
Merge pull request #18 from blackducksoftware/ek-add-primary-creator
Browse files Browse the repository at this point in the history
adding primary creator
  • Loading branch information
ekerwin authored Jul 2, 2018
2 parents 35e3566 + bdf244c commit 0a9e4c2
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 47 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
12.2.0-SNAPSHOT
15.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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";

Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}

}

0 comments on commit 0a9e4c2

Please sign in to comment.