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
commit 57a2261dda2654a045735385891cbaf8951fbbd7 Author: Stefan Bodewig <[email protected]> AuthorDate: Thu May 14 15:23:28 2026 +0200 document and test organization type --- docs/index.html | 3 +- docs/organization.html | 73 +++++++++++++ .../org/apache/ant/cyclonedx/Organization.java | 27 ++++- src/tests/antunit/organization-test.xml | 118 +++++++++++++++++++++ 4 files changed, 217 insertions(+), 4 deletions(-) diff --git a/docs/index.html b/docs/index.html index ee7c3d2..b1f58fc 100644 --- a/docs/index.html +++ b/docs/index.html @@ -61,6 +61,7 @@ <h2>Tasks and Types provided by this Ant Library</h2> <ul> <li><a href="externalreferenceset.html">externalreferenceset</a></li> <li><a href="license.html">license</a></li> + <li><a href="organization.html">organization</a></li> </ul> <h2>Requirements and Dependencies of this Ant Library</h2> @@ -83,6 +84,6 @@ <h2>Requirements and Dependencies of this Ant Library</h2> and <a href="https://github.com/FasterXML/woodstox/">woodstox</a> when writing the BOM. It may be possible to avoid the woodstox dependency if you only create the JSON format of the SBOM.</p> - + </body> </html> diff --git a/docs/organization.html b/docs/organization.html new file mode 100644 index 0000000..2355747 --- /dev/null +++ b/docs/organization.html @@ -0,0 +1,73 @@ +<!-- + 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. +--> +<html> + <head> + <meta http-equiv="Content-Language" content="en-us"></meta> + <link rel="stylesheet" type="text/css" href="style.css"> + <title>Apache CycloneDX Ant Library - organization</title> + </head> + + <body> + <h2 id="organization">organization</h2> + + <p>Organizations can be attached to components as well as the SBOM + itself using several roles (manufacturer, supplier, publisher) + in CycloneDX SBOMs.</p> + + <p>The organization elements can be used as top-level elements and + be given an id so they can be later referred to via + the <code>refid</code> attribute - + see <a href="https://ant.apache.org/manual/using.html#references">the + Ant manual</a>.</p> + + <h3>Attributes</h3> + + <table class="attr"> + <tr> + <th scope="col">Attribute</th> + <th scope="col">Description</th> + <th scope="col">Required</th> + </tr> + <tr> + <td>name</td> + <td>The name of the organization.</td> + <td>No</td> + </tr> + </table> + + <h3>Nested elements</h3> + + <h4>url</h4> + + <p>Nested <a href="https://ant.apache.org/manual/Types/resources.html#url">url-resource</a>s + named <code>url</code> can be used to specify the URL(s) of the + organization.</p> + + <h3>Examples</h3> + + <p>Below is an organization that would describe the Ant dev team.</p> + + <pre> + <cdx:organization + name="Apache Ant Development Team" + id="ant-team" + xmlns:cdx="antlib:org.apache.ant.cyclonedx"> + <url url="https://ant.apache.org/"/> + </cdx:organization> + </pre> + + </body> diff --git a/src/main/org/apache/ant/cyclonedx/Organization.java b/src/main/org/apache/ant/cyclonedx/Organization.java index 7981495..2ab4e4e 100644 --- a/src/main/org/apache/ant/cyclonedx/Organization.java +++ b/src/main/org/apache/ant/cyclonedx/Organization.java @@ -8,21 +8,39 @@ import org.apache.tools.ant.types.resources.URLResource; import org.cyclonedx.model.OrganizationalEntity; +/** + * Organization appears as "manufacturer", "publisher" or "supplier" + * of components or the SBOM itself. + * + * <p>The CycloneDX specification supports more information for an + * organization than this type currently exposes.</p> + * + * <p>This class is a type exposed by this Ant Library. When using the + * inherited {@code refid} attribute it can reference an instance + * defined previously - in which case no child elements or other + * attributes are allowed.</p> + */ public class Organization extends DataType { private String name; private List<String> urls = new ArrayList<>(); + /** + * Sets the name of the organization. + */ public void setName(String name) { checkAttributesAllowed(); this.name = name; } + /** + * Adds an url of the organization. + */ public void addConfiguredUrl(URLResource url) { - checkAttributesAllowed(); + checkChildrenAllowed(); urls.add(url.getURL().toExternalForm()); } - public OrganizationalEntity toOrganizationalEntity() { + OrganizationalEntity toOrganizationalEntity() { if (isReference()) { return getRef().toOrganizationalEntity(); } @@ -37,7 +55,10 @@ public class Organization extends DataType { return oe; } - public static Organization from(OrganizationalEntity oe) { + /** + * Creates a new instance from the CycloneDX counterpart. + */ + static Organization from(OrganizationalEntity oe) { Organization o = new Organization(); o.setName(oe.getName()); List<String> urls = oe.getUrls(); diff --git a/src/tests/antunit/organization-test.xml b/src/tests/antunit/organization-test.xml new file mode 100644 index 0000000..26d394e --- /dev/null +++ b/src/tests/antunit/organization-test.xml @@ -0,0 +1,118 @@ +<?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="organization-test" default="antunit"> + + <import file="shared.xml" /> + + <target name="testOrganizationAsDirectChildOfComponent"> + <cdx:componentbom + outputdirectory="${output}" format="xml" + xmlns:cdx="antlib:org.apache.ant.cyclonedx"> + <component name="testname"> + <manufacturer name="Example"> + <url url="https://example.org/"/> + </manufacturer> + </component> + </cdx:componentbom> + <xmlproperty file="${output}/bom.xml"/> + <au:assertPropertyEquals + xmlns:au="antlib:org.apache.ant.antunit" + name="bom.metadata.component.manufacturer.name" + value="Example"/> + <au:assertPropertyEquals + xmlns:au="antlib:org.apache.ant.antunit" + name="bom.metadata.component.manufacturer.url" + value="https://example.org/"/> + </target> + + <target name="testOrganizationAllowsMultipleUrlChildren"> + <cdx:componentbom + outputdirectory="${output}" format="xml" + xmlns:cdx="antlib:org.apache.ant.cyclonedx"> + <component name="testname"> + <manufacturer name="Example"> + <url url="https://example.org/"/> + <url url="https://example.com/"/> + </manufacturer> + </component> + </cdx:componentbom> + <xmlproperty file="${output}/bom.xml"/> + <au:assertPropertyEquals + xmlns:au="antlib:org.apache.ant.antunit" + name="bom.metadata.component.manufacturer.name" + value="Example"/> + <au:assertPropertyEquals + xmlns:au="antlib:org.apache.ant.antunit" + name="bom.metadata.component.manufacturer.url" + value="https://example.org/,https://example.com/"/> + </target> + + <target name="testOrganizationWorksViaReference"> + <cdx:organization name="Example" id="test-org" + xmlns:cdx="antlib:org.apache.ant.cyclonedx"> + <url url="https://example.org/"/> + </cdx:organization> + <cdx:componentbom + outputdirectory="${output}" format="xml" + xmlns:cdx="antlib:org.apache.ant.cyclonedx"> + <component name="testname"> + <manufacturer refid="test-org"/> + </component> + </cdx:componentbom> + <xmlproperty file="${output}/bom.xml"/> + <au:assertPropertyEquals + xmlns:au="antlib:org.apache.ant.antunit" + name="bom.metadata.component.manufacturer.name" + value="Example"/> + <au:assertPropertyEquals + xmlns:au="antlib:org.apache.ant.antunit" + name="bom.metadata.component.manufacturer.url" + value="https://example.org/"/> + </target> + + <target + name="testOrganizationWithRefIdDoesntAllowNestedChildren"> + <cdx:organization name="Example" id="test-org" + xmlns:cdx="antlib:org.apache.ant.cyclonedx"> + <url url="https://example.org/"/> + </cdx:organization> + <au:expectfailure + expectedMessage='You must not specify nested elements when using refid' + xmlns:au="antlib:org.apache.ant.antunit"> + <cdx:organization refid="test-org" + xmlns:cdx="antlib:org.apache.ant.cyclonedx"> + <url url="https://example.org/"/> + </cdx:organization> + </au:expectfailure> + </target> + + <target + name="testLicenseWithRefIdDoesntAllowOtherAttributes"> + <cdx:organization name="Example" id="test-org" + xmlns:cdx="antlib:org.apache.ant.cyclonedx"> + <url url="https://example.org/"/> + </cdx:organization> + <au:expectfailure + expectedMessage='You must not specify more than one attribute when using refid' + xmlns:au="antlib:org.apache.ant.antunit"> + <cdx:organization refid="test-org" + name="foo" + xmlns:cdx="antlib:org.apache.ant.cyclonedx"/> + </au:expectfailure> + </target> +</project>
