Skip to content

Commit

Permalink
Initial changes for evidence
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-zepol committed Aug 24, 2023
1 parent adbba75 commit ee461c5
Show file tree
Hide file tree
Showing 11 changed files with 586 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public BomJsonGenerator15(final Bom bom) {
modifiedBom = injectBomFormatAndSpecVersion(bom);
}
catch (GeneratorException e) {
e.printStackTrace();
}
this.bom = modifiedBom != null ? modifiedBom : bom;
}
Expand Down
106 changes: 83 additions & 23 deletions src/main/java/org/cyclonedx/model/Evidence.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,43 +25,103 @@
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import org.cyclonedx.model.evidence.Frame;
import org.cyclonedx.model.evidence.Identity;
import org.cyclonedx.model.evidence.Occurrence;
import org.cyclonedx.util.deserializer.LicenseDeserializer;

import java.util.ArrayList;
import java.util.List;

@SuppressWarnings("unused")
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonPropertyOrder({"licenses", "copyright"})
public class Evidence extends ExtensibleElement {
@JsonPropertyOrder({"identity", "occurrences", "callstack", "licenses", "copyright"})
public class Evidence
extends ExtensibleElement
{
private LicenseChoice license;

private LicenseChoice license;
private List<Copyright> copyright;
private List<Copyright> copyright;

@JacksonXmlProperty(localName = "licenses")
@JsonProperty("licenses")
@JsonDeserialize(using = LicenseDeserializer.class)
public LicenseChoice getLicenseChoice() {
return license;
}
@VersionFilter(versions = {"1.0", "1.1", "1.2", "1.3", "1.4"})
private Identity identity;

public void setLicenseChoice(LicenseChoice licenseChoice) {
this.license = licenseChoice;
}
@VersionFilter(versions = {"1.0", "1.1", "1.2", "1.3", "1.4"})
private List<Occurrence> occurrences;

@VersionFilter(versions = {"1.0", "1.1", "1.2", "1.3", "1.4"})
private Callstack callstack;

@JacksonXmlProperty(localName = "licenses")
@JsonProperty("licenses")
@JsonDeserialize(using = LicenseDeserializer.class)
public LicenseChoice getLicenseChoice() {
return license;
}

public void setLicenseChoice(LicenseChoice licenseChoice) {
this.license = licenseChoice;
}

@JacksonXmlElementWrapper(useWrapping = false)
public List<Copyright> getCopyright() {
return copyright;
}

public void setCopyright(List<Copyright> copyright) {
this.copyright = copyright;
}

@JacksonXmlElementWrapper(useWrapping = false)
public List<Copyright> getCopyright() {
return copyright;
public void addCopyright(Copyright copyright) {
if (this.copyright == null) {
this.copyright = new ArrayList<>();
}
this.copyright.add(copyright);
}

public Identity getIdentity() {
return identity;
}

public void setIdentity(final Identity identity) {
this.identity = identity;
}

@JsonProperty("occurrences")
@JacksonXmlElementWrapper(localName = "occurrences")
@JacksonXmlProperty(localName = "occurrence")
public List<Occurrence> getOccurrences() {
return occurrences;
}

public void setOccurrences(final List<Occurrence> occurrences) {
this.occurrences = occurrences;
}

public Callstack getCallstack() {
return callstack;
}

public void setCallstack(final Callstack callstack) {
this.callstack = callstack;
}

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public static class Callstack
{
List<Frame> frames;

public void setCopyright(List<Copyright> copyright) {
this.copyright = copyright;
@JacksonXmlElementWrapper(localName = "frames")
@JacksonXmlProperty(localName = "frame")
@JsonProperty("frames")
public List<Frame> getFrames() {
return frames;
}

public void addCopyright(Copyright copyright) {
if (this.copyright == null) {
this.copyright = new ArrayList<>();
}
this.copyright.add(copyright);
public void setFrames(final List<Frame> frames) {
this.frames = frames;
}
}
}
88 changes: 88 additions & 0 deletions src/main/java/org/cyclonedx/model/evidence/Frame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package org.cyclonedx.model.evidence;

import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import org.cyclonedx.model.ExtensibleElement;

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class Frame extends ExtensibleElement
{
private String packageFrame;

private String module;

private String function;

private List<String> parameters;

private Integer line;

private Integer column;

private String fullFilename;

public String getPackageFrame() {
return packageFrame;
}

public void setPackageFrame(final String packageFrame) {
this.packageFrame = packageFrame;
}

public String getModule() {
return module;
}

public void setModule(final String module) {
this.module = module;
}

public String getFunction() {
return function;
}

public void setFunction(final String function) {
this.function = function;
}

@JsonProperty("parameters")
@JacksonXmlElementWrapper(localName = "parameters")
@JacksonXmlProperty(localName = "parameter")
public List<String> getParameters() {
return parameters;
}

public void setParameters(final List<String> parameters) {
this.parameters = parameters;
}

public Integer getLine() {
return line;
}

public void setLine(final Integer line) {
this.line = line;
}

public Integer getColumn() {
return column;
}

public void setColumn(final Integer column) {
this.column = column;
}

public String getFullFilename() {
return fullFilename;
}

public void setFullFilename(final String fullFilename) {
this.fullFilename = fullFilename;
}
}
126 changes: 126 additions & 0 deletions src/main/java/org/cyclonedx/model/evidence/Identity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package org.cyclonedx.model.evidence;

import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import org.cyclonedx.model.ExtensibleElement;

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonPropertyOrder({"field", "confidence", "methods", "tools"})
public class Identity extends ExtensibleElement
{
public Field field;

public Double confidence;

public List<Method> methods;

public List<Tool> tools;

public enum Field {
@JsonProperty("group")
GROUP("group"),
@JsonProperty("name")
NAME("name"),
@JsonProperty("version")
VERSION("version"),
@JsonProperty("purl")
PURL("purl"),
@JsonProperty("cpe")
CPE( "cpe"),
@JsonProperty("swid")
SWID("swid"),
@JsonProperty("hash")
HASH( "hash");

private final String name;

public String getTypeName() {
return this.name;
}

Field(String name) {
this.name = name;
}
}

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public static class Tool {
@JacksonXmlProperty(isAttribute = true, localName = "ref")
@JsonProperty("ref")
private String ref;


private String bomLink;

public Tool() {
}

public Tool(String ref) {
this.ref = ref;
}

public String getRef() {
return ref;
}

public void setRef(final String ref) {
this.ref = ref;
}

@JsonProperty("bomLinkElement")
public String getBomLink() {
return bomLink;
}

public void setBomLink(final String bomLink) {
this.bomLink = bomLink;
}
}

public Field getField() {
return field;
}

public void setField(final Field field) {
this.field = field;
}

public Double getConfidence() {
return confidence;
}

public void setConfidence(final Double confidence) {
this.confidence = confidence;
}

@JsonProperty("methods")
@JacksonXmlElementWrapper(localName = "methods")
@JacksonXmlProperty(localName = "method")
public List<Method> getMethods() {
return methods;
}

public void setMethods(final List<Method> methods) {
this.methods = methods;
}

@JsonProperty("tools")
@JacksonXmlElementWrapper(localName = "tools")
@JacksonXmlProperty(localName = "tool")
public List<Tool> getTools() {
return tools;
}

public void setTools(final List<Tool> tools) {
this.tools = tools;
}
}
Loading

0 comments on commit ee461c5

Please sign in to comment.