This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ant-antlibs-cyclonedx.git
The following commit(s) were added to refs/heads/main by this push:
new 7c4ac14 support names as defined by the spec for externalReference's
type
7c4ac14 is described below
commit 7c4ac14bc627ebb52b053bacc6ffd14a5a706fa8
Author: Stefan Bodewig <[email protected]>
AuthorDate: Wed May 13 05:41:29 2026 +0200
support names as defined by the spec for externalReference's type
---
.../apache/ant/cyclonedx/ExternalReference.java | 25 +++++++++-----
src/main/org/apache/ant/cyclonedx/ToolData.java | 2 +-
src/tests/antunit/externalreferences-test.xml | 39 ++++++++++++++++++++--
3 files changed, 53 insertions(+), 13 deletions(-)
diff --git a/src/main/org/apache/ant/cyclonedx/ExternalReference.java
b/src/main/org/apache/ant/cyclonedx/ExternalReference.java
index 7e16016..94f3d0d 100644
--- a/src/main/org/apache/ant/cyclonedx/ExternalReference.java
+++ b/src/main/org/apache/ant/cyclonedx/ExternalReference.java
@@ -15,7 +15,7 @@ import org.apache.tools.ant.BuildException;
*/
public class ExternalReference {
private String url;
- private org.cyclonedx.model.ExternalReference.Type type;
+ private String type;
/**
* Set the URL (actually URI) of the external reference.
@@ -32,15 +32,13 @@ public class ExternalReference {
*
* <p>Required.</p>
*
- * <p>To make keep this easy to extend the <a
-
href="https://javadoc.io/static/org.cyclonedx/cyclonedx-core-java/12.2.0/org/cyclonedx/model/ExternalReference.Type.html">type
- enum</a> of the <a
+ * <p>Types defined by the specification or the enum names of <a
href="https://github.com/CycloneDX/cyclonedx-core-java">CycloneDX
- Core (Java)</a> library is used directly. This also means you
- need to specify the type in uppercase rather than the lower case
- type defined by the standard.</p>
+ Core (Java)</a>'s <a
+
href="https://javadoc.io/static/org.cyclonedx/cyclonedx-core-java/12.2.0/org/cyclonedx/model/ExternalReference.Type.html">type
+ enum</a> are accepted.</p>
*/
- public void setType(org.cyclonedx.model.ExternalReference.Type type) {
+ public void setType(String type) {
this.type = type;
}
@@ -51,9 +49,18 @@ public class ExternalReference {
if (type == null) {
throw new BuildException("external references must have a type");
}
+ org.cyclonedx.model.ExternalReference.Type t =
org.cyclonedx.model.ExternalReference.Type.fromString(type);
+ if (t == null) {
+ try {
+ t = org.cyclonedx.model.ExternalReference.Type.valueOf(type);
+ } catch (IllegalArgumentException ex) {
+ throw new BuildException("external references type \"" + type
+ "\" is not supported");
+ }
+ }
+
org.cyclonedx.model.ExternalReference r = new
org.cyclonedx.model.ExternalReference();
r.setUrl(url);
- r.setType(type);
+ r.setType(t);
return r;
}
}
diff --git a/src/main/org/apache/ant/cyclonedx/ToolData.java
b/src/main/org/apache/ant/cyclonedx/ToolData.java
index 486768c..f2a06c2 100644
--- a/src/main/org/apache/ant/cyclonedx/ToolData.java
+++ b/src/main/org/apache/ant/cyclonedx/ToolData.java
@@ -125,7 +125,7 @@ public class ToolData {
createExternalReference(ExternalReference.Type type, String url) {
org.apache.ant.cyclonedx.ExternalReference e = new
org.apache.ant.cyclonedx.ExternalReference();
e.setUrl(url);
- e.setType(type);
+ e.setType(type.name());
return e;
}
}
diff --git a/src/tests/antunit/externalreferences-test.xml
b/src/tests/antunit/externalreferences-test.xml
index bfa2ad4..6bf4790 100644
--- a/src/tests/antunit/externalreferences-test.xml
+++ b/src/tests/antunit/externalreferences-test.xml
@@ -27,7 +27,7 @@
outputdirectory="${output}" format="xml"
xmlns:cdx="antlib:org.apache.ant.cyclonedx">
<component name="testname">
- <externalReference type="WEBSITE"/>
+ <externalReference type="website"/>
</component>
</cdx:componentbom>
</au:expectfailure>
@@ -47,7 +47,40 @@
</au:expectfailure>
</target>
+ <target name="testExternalReferenceFailsForUnsupportedType">
+ <au:expectfailure
+ expectedMessage='external references type "foo" is not supported'
+ xmlns:au="antlib:org.apache.ant.antunit">
+ <cdx:componentbom
+ outputdirectory="${output}" format="xml"
+ xmlns:cdx="antlib:org.apache.ant.cyclonedx">
+ <component name="testname">
+ <externalReference type="foo" url="https://ant.apache.org/"/>
+ </component>
+ </cdx:componentbom>
+ </au:expectfailure>
+ </target>
+
<target name="testExternalReferenceWorksAsDirectChildrenOfComponent">
+ <cdx:componentbom
+ outputdirectory="${output}" format="xml"
+ xmlns:cdx="antlib:org.apache.ant.cyclonedx">
+ <component name="testname">
+ <externalReference type="website" url="https://ant.apache.org/"/>
+ </component>
+ </cdx:componentbom>
+ <xmlproperty file="${output}/bom.xml"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.metadata.component.externalReferences.reference(type)"
+ value="website"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.metadata.component.externalReferences.reference.url"
+ value="https://ant.apache.org/"/>
+ </target>
+
+ <target name="testExternalReferenceSuppportsEnumValuesAsType">
<cdx:componentbom
outputdirectory="${output}" format="xml"
xmlns:cdx="antlib:org.apache.ant.cyclonedx">
@@ -73,7 +106,7 @@
<component name="testname">
<externalReferenceSet>
<externalReference
- type="WEBSITE" url="https://ant.apache.org/"/>
+ type="website" url="https://ant.apache.org/"/>
</externalReferenceSet>
</component>
</cdx:componentbom>
@@ -92,7 +125,7 @@
<cdx:externalreferenceset id="test-set"
xmlns:cdx="antlib:org.apache.ant.cyclonedx">
<externalReference
- type="WEBSITE" url="https://ant.apache.org/"/>
+ type="website" url="https://ant.apache.org/"/>
</cdx:externalreferenceset>
<cdx:componentbom
outputdirectory="${output}" format="xml"