Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update data model for 1.6 #381

Merged
merged 1 commit into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/main/java/org/cyclonedx/model/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
import java.util.List;
import java.util.Objects;

import com.fasterxml.jackson.annotation.JsonUnwrapped;
import org.cyclonedx.Version;
import org.cyclonedx.model.component.ModelCard;
import org.cyclonedx.model.component.crypto.CryptoProperties;
import org.cyclonedx.model.component.Tags;
import org.cyclonedx.model.component.modelCard.ComponentData;
import org.cyclonedx.util.deserializer.ExternalReferencesDeserializer;
import org.cyclonedx.util.deserializer.HashesDeserializer;
Expand Down Expand Up @@ -142,6 +144,7 @@ public String getScopeName() {
private String mimeType;
@VersionFilter(Version.VERSION_12)
private OrganizationalEntity supplier;
@Deprecated
@VersionFilter(Version.VERSION_12)
private String author;
@VersionFilter(Version.VERSION_11)
Expand Down Expand Up @@ -193,6 +196,18 @@ public String getScopeName() {
@JsonProperty("provides")
private List<String> provides;

@VersionFilter(Version.VERSION_16)
@JsonUnwrapped
private Tags tags;

@VersionFilter(Version.VERSION_16)
@JsonProperty("authors")
private List<OrganizationalContact> authors;

@VersionFilter(Version.VERSION_16)
@JsonProperty("manufacturer")
private OrganizationalEntity manufacturer;

@JsonOnly
@VersionFilter(Version.VERSION_14)
private Signature signature;
Expand Down Expand Up @@ -493,6 +508,30 @@ public void setProvides(final List<String> provides) {
this.provides = provides;
}

public Tags getTags() {
return tags;
}

public void setTags(final Tags tags) {
this.tags = tags;
}

public List<OrganizationalContact> getAuthors() {
return authors;
}

public void setAuthors(final List<OrganizationalContact> authors) {
this.authors = authors;
}

public OrganizationalEntity getManufacturer() {
return manufacturer;
}

public void setManufacturer(final OrganizationalEntity manufacturer) {
this.manufacturer = manufacturer;
}

@Override
public int hashCode() {
return Objects.hash(author, publisher, group, name, version, description, scope, hashes, license, copyright,
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/org/cyclonedx/model/Metadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ public class Metadata
@VersionFilter(Version.VERSION_12)
private Component component;

@VersionFilter(Version.VERSION_16)
@JsonProperty("manufacturer")
private OrganizationalEntity manufacturer;

@Deprecated
@VersionFilter(Version.VERSION_12)
private OrganizationalEntity manufacture;

Expand Down Expand Up @@ -197,6 +202,14 @@ public void setToolChoice(final ToolInformation toolInformation) {
this.toolInformation = toolInformation;
}

public OrganizationalEntity getManufacturer() {
return manufacturer;
}

public void setManufacturer(final OrganizationalEntity manufacturer) {
this.manufacturer = manufacturer;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/cyclonedx/model/ReleaseNotes.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import org.cyclonedx.Version;
import org.cyclonedx.model.component.Tags;
import org.cyclonedx.util.deserializer.NotesDeserializer;
import org.cyclonedx.util.deserializer.PropertiesDeserializer;
import org.cyclonedx.util.deserializer.ResolvesDeserializer;
Expand Down Expand Up @@ -67,7 +69,8 @@ public ReleaseNotes() {}
@VersionFilter(Version.VERSION_14)
private Date timestamp;
private List<String> aliases;
private List<String> tags;
@JsonUnwrapped
private Tags tags;
private List<Resolves> resolves;
private List<Notes> notes;
private List<Property> properties;
Expand Down Expand Up @@ -131,14 +134,11 @@ public void setAliases(final List<String> aliases) {
this.aliases = aliases;
}

@JacksonXmlElementWrapper(localName = "tags")
@JacksonXmlProperty(localName = "tag")
@JsonDeserialize(using = StringListDeserializer.class)
public List<String> getTags() {
public Tags getTags() {
return tags;
}

public void setTags(final List<String> tags) {
public void setTags(final Tags tags) {
this.tags = tags;
}

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/cyclonedx/model/Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
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.Version;
import org.cyclonedx.model.component.Tags;
import org.cyclonedx.util.deserializer.ExternalReferencesDeserializer;
import org.cyclonedx.util.deserializer.StringListDeserializer;

Expand All @@ -48,6 +50,7 @@
"licenses",
"externalReferences",
"properties",
"tags",
"services",
"releaseNotes",
"signature"
Expand All @@ -72,6 +75,9 @@ public class Service extends ExtensibleElement {
private List<ExternalReference> externalReferences;
@VersionFilter(Version.VERSION_13)
private List<Property> properties;
@VersionFilter(value = Version.VERSION_16)
@JsonUnwrapped
private Tags tags;
private List<Service> services;
private ReleaseNotes releaseNotes;
@JsonOnly
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/org/cyclonedx/model/component/Tags.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.cyclonedx.model.component;

import java.util.List;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
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.util.deserializer.TagsDeserializer;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonDeserialize(using = TagsDeserializer.class)
public class Tags
{
private List<String> tags;

public Tags() {
}

public Tags(List<String> tags){
this.tags = tags;
}

@JacksonXmlElementWrapper(localName = "tags")
@JacksonXmlProperty(localName = "tag")
@JsonProperty("tags")
public List<String> getTags() {
return tags;
}

public void setTags(final List<String> tags) {
this.tags = tags;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.cyclonedx.util.deserializer;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import org.cyclonedx.model.component.Tags;

public class TagsDeserializer
extends JsonDeserializer<Tags>
{

private final ObjectMapper mapper = new ObjectMapper();
@Override
public Tags deserialize(JsonParser parser, DeserializationContext context) throws IOException {
JsonNode node = parser.getCodec().readTree(parser);

if(node.has("tag")) {
return parseNode(node.get("tag"));
} else {
return parseNode(node);
}
}

private Tags parseNode(JsonNode node) {
List<String> list = new ArrayList<>();

ArrayNode nodes = (node.isArray() ? (ArrayNode) node : new ArrayNode(null).add(node));
for (JsonNode tagNode : nodes) {
list.add(tagNode.asText());
}

if(!list.isEmpty()) {
return new Tags(list);
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ void assertMetadata(final Metadata metadata, final Version version) {
assertNotNull(releaseNotes.getSocialImage());
assertNotNull(releaseNotes.getTimestamp());
assertEquals(1, releaseNotes.getAliases().size());
assertEquals(1, releaseNotes.getTags().size());
assertEquals(1, releaseNotes.getTags().getTags().size());

//Resolves
assertEquals(1, releaseNotes.getResolves().size());
Expand Down
Loading