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 15e7c6f  document and test external reference
15e7c6f is described below

commit 15e7c6f63891d623769795acbfff60d15000723e
Author: Stefan Bodewig <[email protected]>
AuthorDate: Wed May 13 05:30:05 2026 +0200

    document and test external reference
---
 .../apache/ant/cyclonedx/ExternalReference.java    |  32 +++++-
 src/tests/antunit/externalreferences-test.xml      | 115 +++++++++++++++++++++
 2 files changed, 146 insertions(+), 1 deletion(-)

diff --git a/src/main/org/apache/ant/cyclonedx/ExternalReference.java 
b/src/main/org/apache/ant/cyclonedx/ExternalReference.java
index 6b9866e..7e16016 100644
--- a/src/main/org/apache/ant/cyclonedx/ExternalReference.java
+++ b/src/main/org/apache/ant/cyclonedx/ExternalReference.java
@@ -2,19 +2,49 @@ package org.apache.ant.cyclonedx;
 
 import org.apache.tools.ant.BuildException;
 
+/**
+ * An "external reference", i.e. a notable link for the component or
+ * the SBOM itself.
+ *
+ * <p>External references must have a type and an URL. The
+ * sepcification also supports optional comments and hashes which are
+ * currently not supported. </p>
+ *
+ * <p>External references appear as children of {@link Component} or
+ * {@code ExternalReferenceSet} elements.</p>
+ */
 public class ExternalReference {
     private String url;
     private org.cyclonedx.model.ExternalReference.Type type;
 
+    /**
+     * Set the URL (actually URI) of the external reference.
+     *
+     * <p>Required. This setter does not validate the value actually
+     * follows the URI syntax.</p>
+     */
     public void setUrl(String url) {
         this.url = url;
     }
 
+    /**
+     * Set the type of the external reference.
+     *
+     * <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
+      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>
+     */
     public void setType(org.cyclonedx.model.ExternalReference.Type type) {
         this.type = type;
     }
 
-    public org.cyclonedx.model.ExternalReference 
toCycloneDxExternalReference() {
+    org.cyclonedx.model.ExternalReference toCycloneDxExternalReference() {
         if (url == null) {
             throw new BuildException("external references must have an url");
         }
diff --git a/src/tests/antunit/externalreferences-test.xml 
b/src/tests/antunit/externalreferences-test.xml
new file mode 100644
index 0000000..bfa2ad4
--- /dev/null
+++ b/src/tests/antunit/externalreferences-test.xml
@@ -0,0 +1,115 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      https://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<project name="componentbom-test" default="antunit">
+
+  <import file="shared.xml" />
+
+  <target name="testExternalReferenceRequiresUrl">
+    <au:expectfailure
+        expectedMessage="external references must have an url"
+        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="WEBSITE"/>
+        </component>
+      </cdx:componentbom>
+    </au:expectfailure>
+  </target>
+
+  <target name="testExternalReferenceRequiresType">
+    <au:expectfailure
+        expectedMessage="external references must have a type"
+        xmlns:au="antlib:org.apache.ant.antunit">
+      <cdx:componentbom
+          outputdirectory="${output}" format="xml"
+          xmlns:cdx="antlib:org.apache.ant.cyclonedx">
+        <component name="testname">
+          <externalReference 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="testExternalReferenceWorksNestedIntoAsSet">
+    <cdx:componentbom
+        outputdirectory="${output}" format="xml"
+        xmlns:cdx="antlib:org.apache.ant.cyclonedx">
+      <component name="testname">
+        <externalReferenceSet>
+          <externalReference
+              type="WEBSITE" url="https://ant.apache.org/"/>
+        </externalReferenceSet>
+      </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="testExternalReferenceWorksViaReferenceToASet">
+    <cdx:externalreferenceset id="test-set"
+        xmlns:cdx="antlib:org.apache.ant.cyclonedx">
+      <externalReference
+          type="WEBSITE" url="https://ant.apache.org/"/>
+    </cdx:externalreferenceset>
+    <cdx:componentbom
+        outputdirectory="${output}" format="xml"
+        xmlns:cdx="antlib:org.apache.ant.cyclonedx">
+      <component name="testname">
+        <externalReferenceSet refid="test-set"/>
+      </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>
+
+</project>

Reply via email to