This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch support-ivy-as-component-source
in repository https://gitbox.apache.org/repos/asf/ant-antlibs-cyclonedx.git
The following commit(s) were added to
refs/heads/support-ivy-as-component-source by this push:
new c782eb2 incomplete set of tests
c782eb2 is described below
commit c782eb29465eed20dd92d6080eb65e810de77c13
Author: Stefan Bodewig <[email protected]>
AuthorDate: Sun Aug 9 22:15:51 2026 +0200
incomplete set of tests
---
build.xml | 38 +++
src/main/org/apache/ant/cyclonedx/Component.java | 14 +
.../ant/cyclonedx/IvyModuleComponentResolver.java | 2 +-
src/tests/antunit/component-ivymodule-test.xml | 323 +++++++++++++++++++++
src/tests/antunit/resources/another.ivy.xml | 32 ++
src/tests/antunit/resources/foo-bar.ivy.xml | 36 +++
6 files changed, 444 insertions(+), 1 deletion(-)
diff --git a/build.xml b/build.xml
index df2595a..f2041a0 100644
--- a/build.xml
+++ b/build.xml
@@ -63,6 +63,44 @@ under the License.
<ivy:resolve file="ivy.xml" xmlns:ivy="antlib:org.apache.ivy.ant"/>
</target>
+ <target name="antunit-test" depends="ready-to-test-with-antunit,resolve"
+ unless="skip-antunit">
+ <condition property="antunit.includes" value="${antunit.testcase}"
+ else="**/test.xml,**/*-test.xml">
+ <isset property="antunit.testcase" />
+ </condition>
+
+ <property name="antunit.excludes" value="" />
+
+ <mkdir dir="${antunit.report.dir}" />
+
+ <path id="ivy-plus-cdx">
+ <fileset dir="${ivy.jar.dir}" includes="*.jar" id="ivy.lib"/>
+ <path refid="classpath.test"/>
+ <pathelement location="${build.classes}"/>
+ </path>
+ <au:antunit xmlns:au="antlib:org.apache.ant.antunit"
+ failOnError="false"
+ errorProperty="antunit.tests.failed"
+ >
+ <classpath>
+ <path refid="ivy-plus-cdx"/>
+ </classpath>
+ <fileset dir="${src.antunit}" includes="${antunit.includes}"
+ excludes="${antunit.excludes}" />
+
+ <au:xmllistener todir="${antunit.report.dir}" />
+ <au:plainlistener/>
+ <referenceset>
+ <reference refid="classpath.test"/>
+ <reference refid="ivy-plus-cdx"/>
+ </referenceset>
+ <propertyset>
+ <propertyref name="antlib.location"/>
+ </propertyset>
+ </au:antunit>
+ </target>
+
<target name="define-cyclonedx-components"
depends="define-core-ant-components"
if="can.use.cyclonedx">
diff --git a/src/main/org/apache/ant/cyclonedx/Component.java
b/src/main/org/apache/ant/cyclonedx/Component.java
index 4b51d7a..7990690 100644
--- a/src/main/org/apache/ant/cyclonedx/Component.java
+++ b/src/main/org/apache/ant/cyclonedx/Component.java
@@ -601,6 +601,20 @@ public class Component extends DataType {
return !licenses.isEmpty();
}
+ /**
+ * Gets whether any description been explicitly configured for this
component.
+ *
+ * @return whether any description has been explicitly configured
+ * @since CycloneDX Antlib 0.2
+ */
+ boolean hasDescription() {
+ if (isReference()) {
+ return getRef().hasDescription();
+ }
+ dieOnCircularReference();
+ return description != null;
+ }
+
/**
* Read the linked SBOM (if any) and merge its content with the
* one already defined for this component.
diff --git a/src/main/org/apache/ant/cyclonedx/IvyModuleComponentResolver.java
b/src/main/org/apache/ant/cyclonedx/IvyModuleComponentResolver.java
index d1802f3..d31b297 100644
--- a/src/main/org/apache/ant/cyclonedx/IvyModuleComponentResolver.java
+++ b/src/main/org/apache/ant/cyclonedx/IvyModuleComponentResolver.java
@@ -206,7 +206,7 @@ class IvyModuleComponentResolver {
if (component.getVersion() == null) {
component.setVersion(mrid.getRevision());
}
- if (component.getDescription() == null && md.getDescription() != null
&& md.getDescription().length() > 0) {
+ if (!component.hasDescription() && md.getDescription() != null &&
md.getDescription().length() > 0) {
component.setDescription(md.getDescription());
}
diff --git a/src/tests/antunit/component-ivymodule-test.xml
b/src/tests/antunit/component-ivymodule-test.xml
new file mode 100644
index 0000000..67f315f
--- /dev/null
+++ b/src/tests/antunit/component-ivymodule-test.xml
@@ -0,0 +1,323 @@
+<?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="component-ivymodule-test" default="antunit">
+
+ <import file="shared.xml" />
+
+ <target name="setUp" depends="shared.setUp">
+ <mkdir dir="${output}"/>
+ <typedef uri="antlib:org.apache.ant.cyclonedx"
+ resource="org/apache/ant/cyclonedx/antlib.xml"
+ loaderRef="cdx.loader">
+ <classpath>
+ <path refid="ivy-plus-cdx"/>
+ </classpath>
+ </typedef>
+ <taskdef resource="org/apache/ivy/ant/antlib.xml"
+ uri="antlib:org.apache.ivy.ant"
+ loaderRef="cdx.loader"/>
+ </target>
+
+ <target name="testCantUseIvyModuleWithoutRunningResolveFirst">
+ <au:expectfailure expectedMessage="no conf provided, you need to call to
<resolve/> before using this task"
+ xmlns:au="antlib:org.apache.ant.antunit">
+ <cdx:componentbom outputdirectory="${output}" format="xml"
+ xmlns:cdx="antlib:org.apache.ant.cyclonedx">
+ <component>
+ <ivymodule/>
+ </component>
+ </cdx:componentbom>
+ </au:expectfailure>
+ </target>
+
+ <target name="testResolvesAllConfigurationsByDefault">
+ <ivy:resolve file="resources/foo-bar.ivy.xml"
+ xmlns:ivy="antlib:org.apache.ivy.ant"/>
+ <cdx:componentbom outputdirectory="${output}" format="xml"
+ xmlns:cdx="antlib:org.apache.ant.cyclonedx">
+ <component>
+ <ivymodule/>
+ </component>
+ </cdx:componentbom>
+ <xmlproperty file="${output}/bom.xml"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.metadata.component.name"
+ value="bar"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.metadata.component(type)"
+ value="library"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.metadata.component.group"
+ value="foo"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.metadata.component.version"
+ value="1.0"/>
+ <au:assertPropertyNotSet
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.metadata.component.publisher"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.metadata.component.purl"
+ value="pkg:maven/foo/[email protected]?type=jar"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.metadata.component(bom-ref)"
+ value="pkg:maven/foo/[email protected]?type=jar"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.metadata.component.description"
+ value="Foo Bar Test-Project"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.metadata.component.licenses.license.name"
+ value="Apache Software License 2.0"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.metadata.component.licenses.license.url"
+ value="https://www.apache.org/licenses/LICENSE-2.0"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.components.component.name"
+ value="ant-launcher,ant"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.components.component(type)"
+ value="library,library"/>
+ <au:assertPropertyNotSet
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.components.component.scope"/>
+ <au:assertPropertyNotSet
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.components.component(isExternal)"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.components.component.group"
+ value="org.apache.ant,org.apache.ant"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.components.component.version"
+ value="1.10.17,1.10.17"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.components.component.purl"
+
value="pkg:maven/org.apache.ant/[email protected]?type=jar,pkg:maven/org.apache.ant/[email protected]?type=jar"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.components.component(bom-ref)"
+
value="pkg:maven/org.apache.ant/[email protected]?type=jar,pkg:maven/org.apache.ant/[email protected]?type=jar"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.dependencies.dependency(ref)"
+
value="pkg:maven/foo/[email protected]?type=jar,pkg:maven/org.apache.ant/[email protected]?type=jar,pkg:maven/org.apache.ant/[email protected]?type=jar"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.dependencies.dependency.dependency(ref)"
+
value="pkg:maven/org.apache.ant/[email protected]?type=jar,pkg:maven/org.apache.ant/[email protected]?type=jar"/>
+ <!-- SHA1 of ant.jar, see
+
https://repo1.maven.org/maven2/org/apache/ant/ant/1.10.17/ant-1.10.17.jar.sha1
-->
+ <au:assertResourceContains
+ xmlns:au="antlib:org.apache.ant.antunit"
+ resource="${output}/bom.xml"
+ value='<hash
alg="SHA-1">fa8a13422ac460563171d10a37c3f28340a953f6</hash>'/>
+ </target>
+
+ <target name="testCanRestrictConfs">
+ <ivy:resolve file="resources/foo-bar.ivy.xml"
+ xmlns:ivy="antlib:org.apache.ivy.ant"/>
+ <cdx:componentbom outputdirectory="${output}" format="xml"
+ xmlns:cdx="antlib:org.apache.ant.cyclonedx">
+ <component>
+ <ivymodule conf="default"/>
+ </component>
+ </cdx:componentbom>
+ <xmlproperty file="${output}/bom.xml"/>
+ <au:assertPropertyNotSet
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.components.component.name"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.dependencies.dependency(ref)"
+ value="pkg:maven/foo/[email protected]?type=jar"/>
+ <au:assertPropertyNotSet
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.dependencies.dependency.dependency(ref)"/>
+ </target>
+
+ <target name="testCanMarkConfsAsOptional">
+ <ivy:resolve file="resources/foo-bar.ivy.xml"
+ xmlns:ivy="antlib:org.apache.ivy.ant"/>
+ <cdx:componentbom outputdirectory="${output}" format="xml"
+ xmlns:cdx="antlib:org.apache.ant.cyclonedx">
+ <component>
+ <ivymodule optionalconf="ant"/>
+ </component>
+ </cdx:componentbom>
+ <xmlproperty file="${output}/bom.xml"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.components.component.name"
+ value="ant-launcher,ant"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.components.component.scope"
+ value="optional,optional"/>
+ </target>
+
+ <target name="testCanMarkConfsAsExternal">
+ <ivy:resolve file="resources/foo-bar.ivy.xml"
+ xmlns:ivy="antlib:org.apache.ivy.ant"/>
+ <cdx:componentbom outputdirectory="${output}" format="xml"
+ xmlns:cdx="antlib:org.apache.ant.cyclonedx">
+ <component>
+ <ivymodule externalconf="ant"/>
+ </component>
+ </cdx:componentbom>
+ <xmlproperty file="${output}/bom.xml"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.components.component.name"
+ value="ant-launcher,ant"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.components.component(isExternal)"
+ value="true,true"/>
+ </target>
+
+ <target name="testUsesResolveId">
+ <ivy:resolve file="resources/foo-bar.ivy.xml"
+ resolveId="foo-bar-id"
+ xmlns:ivy="antlib:org.apache.ivy.ant"/>
+ <ivy:resolve file="resources/another.ivy.xml"
+ xmlns:ivy="antlib:org.apache.ivy.ant"/>
+ <cdx:componentbom outputdirectory="${output}" format="xml"
+ xmlns:cdx="antlib:org.apache.ant.cyclonedx">
+ <component>
+ <ivymodule resolveId="foo-bar-id"/>
+ </component>
+ </cdx:componentbom>
+ <xmlproperty file="${output}/bom.xml"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.metadata.component.name"
+ value="bar"/>
+ </target>
+
+ <target name="testComponentDataFromIvyXmlCanBeOverwrittenOrMerged">
+ <ivy:resolve file="resources/foo-bar.ivy.xml"
+ xmlns:ivy="antlib:org.apache.ivy.ant"/>
+ <cdx:componentbom outputdirectory="${output}" format="xml"
+ xmlns:cdx="antlib:org.apache.ant.cyclonedx">
+ <component description="my description">
+ <ivymodule/>
+ <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.name"
+ value="bar"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.metadata.component.description"
+ value="my description"/>
+ <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="XtestComponentDataFromDependencyCanBeOverwrittenOrMerged">
+ <ivy:resolve file="resources/foo-bar.ivy.xml"
+ xmlns:ivy="antlib:org.apache.ivy.ant"/>
+ <cdx:componentbom outputdirectory="${output}" format="xml"
+ xmlns:cdx="antlib:org.apache.ant.cyclonedx">
+ <component>
+ <ivymodule/>
+ </component>
+ <additionalComponent
+ name="ant"
+ group="org.apache.ant"
+ version="1.10.17"
+ isExternal="true"
+ description="Apache Ant Core"
+ id="ant"/>
+ </cdx:componentbom>
+ <copy todir="/tmp" file="${output}/bom.xml"/>
+ <xmlproperty file="${output}/bom.xml"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.components.component.name"
+ value="ant-launcher,ant"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.components.component(type)"
+ value="library,library"/>
+ <au:assertPropertyNotSet
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.components.component.scope"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.components.component(isExternal)"
+ value="true"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.components.component.description"
+ value="Apache Ant Core"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.components.component.group"
+ value="org.apache.ant,org.apache.ant"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.components.component.version"
+ value="1.10.17,1.10.17"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.components.component.purl"
+
value="pkg:maven/org.apache.ant/[email protected]?type=jar,pkg:maven/org.apache.ant/[email protected]?type=jar"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.components.component(bom-ref)"
+
value="pkg:maven/org.apache.ant/[email protected]?type=jar,pkg:maven/org.apache.ant/[email protected]?type=jar"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.dependencies.dependency(ref)"
+
value="pkg:maven/foo/[email protected]?type=jar,pkg:maven/org.apache.ant/[email protected]?type=jar,pkg:maven/org.apache.ant/[email protected]?type=jar"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.dependencies.dependency.dependency(ref)"
+
value="pkg:maven/org.apache.ant/[email protected]?type=jar,pkg:maven/org.apache.ant/[email protected]?type=jar"/>
+ <!-- SHA1 of ant.jar, see
+
https://repo1.maven.org/maven2/org/apache/ant/ant/1.10.17/ant-1.10.17.jar.sha1
-->
+ <au:assertResourceContains
+ xmlns:au="antlib:org.apache.ant.antunit"
+ resource="${output}/bom.xml"
+ value='<hash
alg="SHA-1">fa8a13422ac460563171d10a37c3f28340a953f6</hash>'/>
+ </target>
+</project>
diff --git a/src/tests/antunit/resources/another.ivy.xml
b/src/tests/antunit/resources/another.ivy.xml
new file mode 100644
index 0000000..e9bdde0
--- /dev/null
+++ b/src/tests/antunit/resources/another.ivy.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+
+-->
+<ivy-module version="2.0">
+ <info organisation="foo" module="baz" revision="1.0">
+ <license name="Apache Software License 2.0"
+ url="https://www.apache.org/licenses/LICENSE-2.0"/>
+ <ivyauthor name="Apache Ant Development Team"
+ url="https://ant.apache.org/"/>
+ <description homepage="https://ant.apache.org/antlibs/cyclonedx/">
+ Foo Baz Test-Project
+ </description>
+ </info>
+ <configurations>
+ <conf name="default" description="default dependencies"/>
+ </configurations>
+</ivy-module>
diff --git a/src/tests/antunit/resources/foo-bar.ivy.xml
b/src/tests/antunit/resources/foo-bar.ivy.xml
new file mode 100644
index 0000000..6d2cf5c
--- /dev/null
+++ b/src/tests/antunit/resources/foo-bar.ivy.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+
+-->
+<ivy-module version="2.0">
+ <info organisation="foo" module="bar" revision="1.0">
+ <license name="Apache Software License 2.0"
+ url="https://www.apache.org/licenses/LICENSE-2.0"/>
+ <ivyauthor name="Apache Ant Development Team"
+ url="https://ant.apache.org/"/>
+ <description homepage="https://ant.apache.org/antlibs/cyclonedx/">
+ Foo Bar Test-Project
+ </description>
+ </info>
+ <configurations>
+ <conf name="default" description="default dependencies"/>
+ <conf name="ant" description="dependency on Ant"/>
+ </configurations>
+ <dependencies>
+ <dependency org="org.apache.ant" name="ant" rev="1.10.17"
conf="ant->default"/>
+ </dependencies>
+</ivy-module>