Skip to content

Commit

Permalink
Renam id to value in License Expression
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Alzate <aalzate@sonatype.com>
  • Loading branch information
mr-zepol committed Apr 22, 2024
1 parent 99ec2cf commit 6666ffc
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 18 deletions.
16 changes: 8 additions & 8 deletions src/main/java/org/cyclonedx/model/license/Expression.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(Include.NON_EMPTY)
@JsonPropertyOrder({"id", "acknowledgement", "bom-ref"})
@JsonPropertyOrder({"value", "acknowledgement", "bom-ref"})
@JsonDeserialize(using = ExpressionDeserializer.class)
public class Expression
{
Expand All @@ -25,14 +25,14 @@ public class Expression

@JacksonXmlText
@JsonProperty("expression")
private String id;
private String value;

public Expression() {

}

public Expression(String id) {
this.id = id;
public Expression(String value) {
this.value = value;
}

public String getBomRef() {
Expand All @@ -51,11 +51,11 @@ public void setAcknowledgement(final String acknowledgement) {
this.acknowledgement = acknowledgement;
}

public String getId() {
return id;
public String getValue() {
return value;
}

public void setId(final String id) {
this.id = id;
public void setValue(final String value) {
this.value = value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ public Expression deserialize(

JsonNode textNode = node.get("expression");
if (textNode != null) {
expression.setId(textNode.textValue());
expression.setValue(textNode.textValue());
}
else if (node.has("")) {
expression.setId(node.get("").asText());
expression.setValue(node.get("").asText());
}

return expression;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ private void serializeXml(
{
if (CollectionUtils.isNotEmpty(licenseChoice.getLicenses())) {
serializeLicensesToJsonArray(licenseChoice, gen, provider);
} else if (licenseChoice.getExpression() != null && StringUtils.isNotBlank(licenseChoice.getExpression().getId())) {
}
else if (licenseChoice.getExpression() != null &&
StringUtils.isNotBlank(licenseChoice.getExpression().getValue())) {
final ToXmlGenerator toXmlGenerator = (ToXmlGenerator) gen;
serializeExpressionToXml(licenseChoice, toXmlGenerator);
}
Expand All @@ -76,7 +78,9 @@ private void serializeJson(
{
if (CollectionUtils.isNotEmpty(licenseChoice.getLicenses())) {
serializeLicensesToJsonArray(licenseChoice, gen, provider);
} else if (licenseChoice.getExpression() != null && StringUtils.isNotBlank(licenseChoice.getExpression().getId())) {
}
else if (licenseChoice.getExpression() != null &&
StringUtils.isNotBlank(licenseChoice.getExpression().getValue())) {
serializeExpressionToJson(licenseChoice, gen);
}
}
Expand Down Expand Up @@ -116,7 +120,7 @@ private void serializeExpressionToXml(
}

toXmlGenerator.setNextIsUnwrapped(true);
toXmlGenerator.writeStringField("", expression.getId());
toXmlGenerator.writeStringField("", expression.getValue());
toXmlGenerator.writeEndObject();
toXmlGenerator.writeEndObject();
}
Expand All @@ -126,7 +130,7 @@ private void serializeExpressionToJson(final LicenseChoice licenseChoice, final
Expression expression = licenseChoice.getExpression();
gen.writeStartArray();
gen.writeStartObject();
gen.writeStringField("expression", expression.getId());
gen.writeStringField("expression", expression.getValue());
if (StringUtils.isNotBlank(expression.getAcknowledgement())) {
gen.writeStringField("acknowledgement", expression.getAcknowledgement());
}
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/org/cyclonedx/parsers/JsonParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ public void testParsedObjects12Bom() throws Exception {
assertEquals("org.glassfish.hk2", c3.getGroup());
assertEquals("osgi-resource-locator", c3.getName());
assertEquals("1.0.1", c3.getVersion());
assertEquals("(CDDL-1.0 OR GPL-2.0-with-classpath-exception)", c3.getLicenseChoice().getExpression().getId());
assertEquals("(CDDL-1.0 OR GPL-2.0-with-classpath-exception)",
c3.getLicenseChoice().getExpression().getValue());

assertServices(bom);

Expand Down Expand Up @@ -279,7 +280,7 @@ public void schema16_license_expression_acknowledgement() throws Exception {
assertNotNull(lc.getExpression());

Expression expression = lc.getExpression();
assertEquals("EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0", expression.getId());
assertEquals("EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0", expression.getValue());
assertEquals("my-license", expression.getBomRef());
assertEquals("declared", expression.getAcknowledgement());
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/cyclonedx/parsers/XmlParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public void testParsedObjects11Bom() throws Exception {
assertNotNull(c1.getPedigree().getCommits().get(0).getCommitter().getTimestamp());
assertEquals("Initial commit", c1.getPedigree().getCommits().get(0).getMessage());
assertEquals("Commentary here", c1.getPedigree().getNotes());
assertEquals("EPL-2.0 OR GPL-2.0-with-classpath-exception", c2.getLicenseChoice().getExpression().getId());
assertEquals("EPL-2.0 OR GPL-2.0-with-classpath-exception", c2.getLicenseChoice().getExpression().getValue());
}

@Test
Expand Down Expand Up @@ -432,7 +432,7 @@ public void schema16_license_expression_acknowledgement() throws Exception {
assertNotNull(lc.getExpression());

Expression expression = lc.getExpression();
assertEquals("EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0", expression.getId());
assertEquals("EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0", expression.getValue());
assertEquals("my-license", expression.getBomRef());
assertEquals("declared", expression.getAcknowledgement());
}
Expand Down

0 comments on commit 6666ffc

Please sign in to comment.