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 783adc7 make cyclonedx-core-java guess SPDX license id when not
specified
783adc7 is described below
commit 783adc7a1eef11930db37020bff915a905722ac7
Author: Stefan Bodewig <[email protected]>
AuthorDate: Sun Aug 16 09:17:03 2026 +0200
make cyclonedx-core-java guess SPDX license id when not specified
---
changes.xml | 4 ++
docs/license.html | 4 ++
example/ant-cyclonedx-0.2alpha.cdx.diff | 97 +++++++++-----------------
example/ant-cyclonedx-0.2alpha.cdx.json | 32 ++++-----
example/ant-cyclonedx-0.2alpha.ivy.cdx.json | 68 +++++++++---------
src/main/org/apache/ant/cyclonedx/License.java | 29 ++++++++
src/tests/antunit/component-ivymodule-test.xml | 4 +-
src/tests/antunit/license-test.xml | 42 +++++++++++
8 files changed, 165 insertions(+), 115 deletions(-)
diff --git a/changes.xml b/changes.xml
index 2003159..d35269d 100644
--- a/changes.xml
+++ b/changes.xml
@@ -105,6 +105,10 @@
This adds Ivy as a new dependency which is only required if you
want to use this feature.
</action>
+ <action type="add">
+ The license element now tries to guess the license's SPDX id
+ if only a name is given.
+ </action>
</release>
<release version="0.1" date="2026-06-03" description="initial release">
diff --git a/docs/license.html b/docs/license.html
index 7ff1760..672e3fc 100644
--- a/docs/license.html
+++ b/docs/license.html
@@ -52,6 +52,10 @@ <h3>Attributes</h3>
</tr>
</table>
+ <p>Since CycloneDX Antlib 0.2 the Antlib will try to guess the
+ SPDX license from its name if the <code>name</code> attribute is
+ used.<code>
+
<h3>Nested elements</h3>
<h4>url</h4>
diff --git a/example/ant-cyclonedx-0.2alpha.cdx.diff
b/example/ant-cyclonedx-0.2alpha.cdx.diff
index da78f27..afb3c22 100644
--- a/example/ant-cyclonedx-0.2alpha.cdx.diff
+++ b/example/ant-cyclonedx-0.2alpha.cdx.diff
@@ -1,5 +1,5 @@
---- ant-cyclonedx-0.2alpha.cdx.json 2026-08-16 08:03:01.398142552 +0200
-+++ ant-cyclonedx-0.2alpha.ivy.cdx.json 2026-08-16 08:02:57.645496553
+0200
+--- ant-cyclonedx-0.2alpha.cdx.json 2026-08-16 09:14:38.469315413 +0200
++++ ant-cyclonedx-0.2alpha.ivy.cdx.json 2026-08-16 09:14:42.941135681
+0200
@@ -253,36 +253,64 @@
"components" : [
{
@@ -54,7 +54,7 @@
"license" : {
- "id" : "MIT",
- "url" : "https://opensource.org/license/mit/"
-+ "name" : "Apache License, Version 2.0",
++ "id" : "Apache-2.0",
+ "url" : "https://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
@@ -85,7 +85,7 @@
{
"license" : {
- "id" : "Apache-2.0"
-+ "name" : "The Apache Software License, Version 2.0",
++ "id" : "Apache-2.0",
+ "url" : "https://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
@@ -126,7 +126,7 @@
{
"license" : {
- "id" : "Apache-2.0"
-+ "name" : "The Apache Software License, Version 2.0",
++ "id" : "Apache-2.0",
+ "url" : "https://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
@@ -167,7 +167,7 @@
{
"license" : {
- "id" : "Apache-2.0"
-+ "name" : "The Apache Software License, Version 2.0",
++ "id" : "Apache-2.0",
+ "url" : "https://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
@@ -208,7 +208,7 @@
{
"license" : {
- "id" : "Apache-2.0"
-+ "name" : "The Apache Software License, Version 2.0",
++ "id" : "Apache-2.0",
+ "url" : "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
@@ -246,18 +246,18 @@
- "url" : "https://github.com/FasterXML/jackson-dataformat-xml"
+ "alg" : "SHA-256",
+ "content" :
"cc3a0e540791a9a1cbcd7584767b84572ffda0b72823856558f47dea69ae8ed1"
- },
- {
-- "type" : "bom",
-- "url" :
"https://repo1.maven.org/maven2/com/fasterxml/jackson/dataformat/jackson-dataformat-xml/2.22.1/jackson-dataformat-xml-2.22.1-sbom-cyclonedx.json"
++ },
++ {
+ "alg" : "SHA-512",
+ "content" :
"12398c493aa3b54716813a6297b72104fa52ab324bae54512e41a1285ac756fcbb800084c088f8e9d3aceae2e698ca164bc547421d5fe2fb62ed2dadf1d3d000"
+ },
+ {
+ "alg" : "SHA3-256",
+ "content" :
"2d33856e0e0aa27571950d57227a66ab78f22c5cecf7c07afc3ad4dbe3b4b4ae"
-+ },
-+ {
+ },
+ {
+- "type" : "bom",
+- "url" :
"https://repo1.maven.org/maven2/com/fasterxml/jackson/dataformat/jackson-dataformat-xml/2.22.1/jackson-dataformat-xml-2.22.1-sbom-cyclonedx.json"
+ "alg" : "SHA3-512",
+ "content" :
"47bdf965089a1949286216aed3b286d8990a3b9169dacb15f0a6f36df07ee397d0ecbcc1294228479068cdbff4b1d8a11718ad5efa744952c34eb092e62cf644"
+ },
@@ -275,7 +275,7 @@
+ "licenses" : [
+ {
+ "license" : {
-+ "name" : "The Apache Software License, Version 2.0",
++ "id" : "Apache-2.0",
+ "url" : "https://www.apache.org/licenses/LICENSE-2.0.txt"
+ }
+ }
@@ -288,13 +288,11 @@
}
]
},
-@@ -615,12 +637,18 @@
- "licenses" : [
+@@ -616,11 +638,17 @@
{
"license" : {
-- "id" : "Apache-2.0",
+ "id" : "Apache-2.0",
- "url" : "https://www.apache.org/licenses/LICENSE-2.0.txt"
-+ "name" : "The Apache License, Version 2.0",
+ "url" : "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
@@ -319,13 +317,7 @@
"hashes" : [
{
"alg" : "MD5",
-@@ -666,102 +694,16 @@
- "licenses" : [
- {
- "license" : {
-- "id" : "MIT",
-+ "name" : "MIT",
- "url" : "https://opensource.org/licenses/MIT"
+@@ -671,97 +699,11 @@
}
}
],
@@ -425,13 +417,11 @@
}
]
},
-@@ -809,17 +751,22 @@
- "licenses" : [
+@@ -810,16 +752,21 @@
{
"license" : {
-- "id" : "Apache-2.0",
+ "id" : "Apache-2.0",
- "url" : "https://www.apache.org/licenses/LICENSE-2.0.txt"
-+ "name" : "Apache License Version 2.0",
+ "url" : "https://www.apache.org/licenses/LICENSE-2.0"
}
}
@@ -452,13 +442,11 @@
"group" : "commons-codec",
"name" : "commons-codec",
"version" : "1.22.1",
-@@ -861,47 +808,22 @@
- "licenses" : [
+@@ -862,46 +809,21 @@
{
"license" : {
-- "id" : "Apache-2.0",
+ "id" : "Apache-2.0",
- "url" : "https://www.apache.org/licenses/LICENSE-2.0"
-+ "name" : "Apache-2.0",
+ "url" : "https://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
@@ -502,13 +490,11 @@
"group" : "commons-io",
"name" : "commons-io",
"version" : "2.22.0",
-@@ -943,40 +865,16 @@
- "licenses" : [
+@@ -944,39 +866,15 @@
{
"license" : {
-- "id" : "Apache-2.0",
+ "id" : "Apache-2.0",
- "url" : "https://www.apache.org/licenses/LICENSE-2.0"
-+ "name" : "Apache-2.0",
+ "url" : "https://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
@@ -652,13 +638,11 @@
"group" : "org.apache.commons",
"name" : "commons-collections4",
"version" : "4.5.0",
-@@ -1187,63 +1136,22 @@
- "licenses" : [
+@@ -1188,62 +1137,21 @@
{
"license" : {
-- "id" : "Apache-2.0",
+ "id" : "Apache-2.0",
- "url" : "https://www.apache.org/licenses/LICENSE-2.0"
-+ "name" : "Apache-2.0",
+ "url" : "https://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
@@ -718,13 +702,11 @@
"group" : "org.apache.commons",
"name" : "commons-lang3",
"version" : "3.20.0",
-@@ -1285,95 +1193,26 @@
- "licenses" : [
+@@ -1286,94 +1194,25 @@
{
"license" : {
-- "id" : "Apache-2.0",
+ "id" : "Apache-2.0",
- "url" : "https://www.apache.org/licenses/LICENSE-2.0"
-+ "name" : "Apache-2.0",
+ "url" : "https://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
@@ -817,13 +799,11 @@
"hashes" : [
{
"alg" : "MD5",
-@@ -1411,93 +1250,21 @@
- "licenses" : [
+@@ -1412,92 +1251,20 @@
{
"license" : {
-- "id" : "Apache-2.0",
+ "id" : "Apache-2.0",
- "url" : "https://www.apache.org/licenses/LICENSE-2.0.txt"
-+ "name" : "The Apache Software License, Version 2.0",
+ "url" : "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
@@ -914,13 +894,7 @@
"bom-ref" : "pkg:maven/org.codehaus.woodstox/[email protected]?type=jar",
"group" : "org.codehaus.woodstox",
"name" : "stax2-api",
-@@ -1540,17 +1307,22 @@
- "licenses" : [
- {
- "license" : {
-- "id" : "BSD-2-Clause",
-+ "name" : "The BSD 2-Clause License",
- "url" : "http://www.opensource.org/licenses/bsd-license.php"
+@@ -1545,12 +1312,17 @@
}
}
],
@@ -940,13 +914,11 @@
"group" : "org.cyclonedx",
"name" : "cyclonedx-core-java",
"version" : "13.1.0",
-@@ -1592,62 +1364,146 @@
- "licenses" : [
+@@ -1593,61 +1365,145 @@
{
"license" : {
-- "id" : "Apache-2.0",
+ "id" : "Apache-2.0",
- "url" : "https://www.apache.org/licenses/LICENSE-2.0.txt"
-+ "name" : "Apache-2.0",
+ "url" : "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
@@ -1013,7 +985,7 @@
+ "licenses" : [
+ {
+ "license" : {
-+ "name" : "MIT",
++ "id" : "MIT",
+ "url" : "https://opensource.org/license/mit"
+ }
+ }
@@ -1074,9 +1046,8 @@
"licenses" : [
{
"license" : {
-- "id" : "Apache-2.0",
+ "id" : "Apache-2.0",
- "url" : "https://www.apache.org/licenses/LICENSE-2.0.txt"
-+ "name" : "Apache License, Version 2.0",
+ "url" : "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
diff --git a/example/ant-cyclonedx-0.2alpha.cdx.json
b/example/ant-cyclonedx-0.2alpha.cdx.json
index fb255e6..58c0668 100644
--- a/example/ant-cyclonedx-0.2alpha.cdx.json
+++ b/example/ant-cyclonedx-0.2alpha.cdx.json
@@ -34,35 +34,35 @@
"hashes" : [
{
"alg" : "MD5",
- "content" : "72e87679cb7b25f3b1849c157a006428"
+ "content" : "768f4a65e486384ef8211bcb1a845a66"
},
{
"alg" : "SHA-1",
- "content" : "bad777295cc811815c2f82cf554978eabd06908c"
+ "content" : "c6ec42e0b9f8e668085d45917c02efc3d5ebfeaa"
},
{
"alg" : "SHA-256",
- "content" :
"6cef1fafc36b884f4be609c20695bf111fc0c4970bb98744f71b6221473026a5"
+ "content" :
"0dec3274326d38a8ac989ecb304710d33dcbb7a2b4445b0bd573af775963972b"
},
{
"alg" : "SHA-512",
- "content" :
"eda3b3c30bc628bfab0421548c2b8a8b37fbc79d02723156344bdf4f0c054594ba8bc7a6d6e8776b70af39c89b523513cac7e562741eebdf2ec2fec19983df3f"
+ "content" :
"961e02a351f61ec04109e1b42088f92697cfb2fa1eccc50a9f27c1bd6bf08242b6b0a175222408a77ad34271d33b8b16b69c38d8c6d1fb7b9f6fbcb2e158690b"
},
{
"alg" : "SHA3-256",
- "content" :
"0fca4ccbb30b9a434a7d862e4338429a0ccee1fb48c83f499bbd55a694e43ac2"
+ "content" :
"5dd9dc9ad4bf54773f0f57595e5738fb33e25c21f9b40e85b64fedc6985e1041"
},
{
"alg" : "SHA3-512",
- "content" :
"e4cecfe5fae3fae96a08417a5999cea4170984c03ac35a720b07eef4ddf53ff64edf84e31d3b01020c46ea0e45cf0ee1870121d0a5935fff5a7edc839f452071"
+ "content" :
"dc2de9b50227a6ccd95dce5bd6195e4124d7a8c99ffec7716c45cd24f715cd7d559c1a1588e0e252af935ba8f8534d157abab1ce8846eb01c92ee4051d7e64b4"
},
{
"alg" : "SHA-384",
- "content" :
"f4e5814675b5dbd572abb5a07de3e52d26a30c70e756039d7276d5ec88aa240d63e93f73e04e94ea2fd26ec33e71396a"
+ "content" :
"678cf2de597f950bb18d3700253cfe36a9bb696eab257cd771a58252ccba80fc76d2736adda5b3e5857aef01b2b3674f"
},
{
"alg" : "SHA3-384",
- "content" :
"4f4f28ff6b84c8b1993d96b985d68bc52993d2e93f6c40dcc2bb33a9bc0b22c2a60fc5f888dcaa0ebf2f6752ead7302f"
+ "content" :
"56fe98f060613c2c7cdfe558a00459e409149a85fc996ca8f50161487c5c9f775c1d7b748ee0991cfc1bc38d8af8f5c7"
}
],
"licenses" : [
@@ -146,35 +146,35 @@
"hashes" : [
{
"alg" : "MD5",
- "content" : "72e87679cb7b25f3b1849c157a006428"
+ "content" : "768f4a65e486384ef8211bcb1a845a66"
},
{
"alg" : "SHA-1",
- "content" : "bad777295cc811815c2f82cf554978eabd06908c"
+ "content" : "c6ec42e0b9f8e668085d45917c02efc3d5ebfeaa"
},
{
"alg" : "SHA-256",
- "content" :
"6cef1fafc36b884f4be609c20695bf111fc0c4970bb98744f71b6221473026a5"
+ "content" :
"0dec3274326d38a8ac989ecb304710d33dcbb7a2b4445b0bd573af775963972b"
},
{
"alg" : "SHA-512",
- "content" :
"eda3b3c30bc628bfab0421548c2b8a8b37fbc79d02723156344bdf4f0c054594ba8bc7a6d6e8776b70af39c89b523513cac7e562741eebdf2ec2fec19983df3f"
+ "content" :
"961e02a351f61ec04109e1b42088f92697cfb2fa1eccc50a9f27c1bd6bf08242b6b0a175222408a77ad34271d33b8b16b69c38d8c6d1fb7b9f6fbcb2e158690b"
},
{
"alg" : "SHA3-256",
- "content" :
"0fca4ccbb30b9a434a7d862e4338429a0ccee1fb48c83f499bbd55a694e43ac2"
+ "content" :
"5dd9dc9ad4bf54773f0f57595e5738fb33e25c21f9b40e85b64fedc6985e1041"
},
{
"alg" : "SHA3-512",
- "content" :
"e4cecfe5fae3fae96a08417a5999cea4170984c03ac35a720b07eef4ddf53ff64edf84e31d3b01020c46ea0e45cf0ee1870121d0a5935fff5a7edc839f452071"
+ "content" :
"dc2de9b50227a6ccd95dce5bd6195e4124d7a8c99ffec7716c45cd24f715cd7d559c1a1588e0e252af935ba8f8534d157abab1ce8846eb01c92ee4051d7e64b4"
},
{
"alg" : "SHA-384",
- "content" :
"f4e5814675b5dbd572abb5a07de3e52d26a30c70e756039d7276d5ec88aa240d63e93f73e04e94ea2fd26ec33e71396a"
+ "content" :
"678cf2de597f950bb18d3700253cfe36a9bb696eab257cd771a58252ccba80fc76d2736adda5b3e5857aef01b2b3674f"
},
{
"alg" : "SHA3-384",
- "content" :
"4f4f28ff6b84c8b1993d96b985d68bc52993d2e93f6c40dcc2bb33a9bc0b22c2a60fc5f888dcaa0ebf2f6752ead7302f"
+ "content" :
"56fe98f060613c2c7cdfe558a00459e409149a85fc996ca8f50161487c5c9f775c1d7b748ee0991cfc1bc38d8af8f5c7"
}
],
"licenses" : [
diff --git a/example/ant-cyclonedx-0.2alpha.ivy.cdx.json
b/example/ant-cyclonedx-0.2alpha.ivy.cdx.json
index 4f33b56..0960a29 100644
--- a/example/ant-cyclonedx-0.2alpha.ivy.cdx.json
+++ b/example/ant-cyclonedx-0.2alpha.ivy.cdx.json
@@ -34,35 +34,35 @@
"hashes" : [
{
"alg" : "MD5",
- "content" : "72e87679cb7b25f3b1849c157a006428"
+ "content" : "768f4a65e486384ef8211bcb1a845a66"
},
{
"alg" : "SHA-1",
- "content" : "bad777295cc811815c2f82cf554978eabd06908c"
+ "content" : "c6ec42e0b9f8e668085d45917c02efc3d5ebfeaa"
},
{
"alg" : "SHA-256",
- "content" :
"6cef1fafc36b884f4be609c20695bf111fc0c4970bb98744f71b6221473026a5"
+ "content" :
"0dec3274326d38a8ac989ecb304710d33dcbb7a2b4445b0bd573af775963972b"
},
{
"alg" : "SHA-512",
- "content" :
"eda3b3c30bc628bfab0421548c2b8a8b37fbc79d02723156344bdf4f0c054594ba8bc7a6d6e8776b70af39c89b523513cac7e562741eebdf2ec2fec19983df3f"
+ "content" :
"961e02a351f61ec04109e1b42088f92697cfb2fa1eccc50a9f27c1bd6bf08242b6b0a175222408a77ad34271d33b8b16b69c38d8c6d1fb7b9f6fbcb2e158690b"
},
{
"alg" : "SHA3-256",
- "content" :
"0fca4ccbb30b9a434a7d862e4338429a0ccee1fb48c83f499bbd55a694e43ac2"
+ "content" :
"5dd9dc9ad4bf54773f0f57595e5738fb33e25c21f9b40e85b64fedc6985e1041"
},
{
"alg" : "SHA3-512",
- "content" :
"e4cecfe5fae3fae96a08417a5999cea4170984c03ac35a720b07eef4ddf53ff64edf84e31d3b01020c46ea0e45cf0ee1870121d0a5935fff5a7edc839f452071"
+ "content" :
"dc2de9b50227a6ccd95dce5bd6195e4124d7a8c99ffec7716c45cd24f715cd7d559c1a1588e0e252af935ba8f8534d157abab1ce8846eb01c92ee4051d7e64b4"
},
{
"alg" : "SHA-384",
- "content" :
"f4e5814675b5dbd572abb5a07de3e52d26a30c70e756039d7276d5ec88aa240d63e93f73e04e94ea2fd26ec33e71396a"
+ "content" :
"678cf2de597f950bb18d3700253cfe36a9bb696eab257cd771a58252ccba80fc76d2736adda5b3e5857aef01b2b3674f"
},
{
"alg" : "SHA3-384",
- "content" :
"4f4f28ff6b84c8b1993d96b985d68bc52993d2e93f6c40dcc2bb33a9bc0b22c2a60fc5f888dcaa0ebf2f6752ead7302f"
+ "content" :
"56fe98f060613c2c7cdfe558a00459e409149a85fc996ca8f50161487c5c9f775c1d7b748ee0991cfc1bc38d8af8f5c7"
}
],
"licenses" : [
@@ -146,35 +146,35 @@
"hashes" : [
{
"alg" : "MD5",
- "content" : "72e87679cb7b25f3b1849c157a006428"
+ "content" : "768f4a65e486384ef8211bcb1a845a66"
},
{
"alg" : "SHA-1",
- "content" : "bad777295cc811815c2f82cf554978eabd06908c"
+ "content" : "c6ec42e0b9f8e668085d45917c02efc3d5ebfeaa"
},
{
"alg" : "SHA-256",
- "content" :
"6cef1fafc36b884f4be609c20695bf111fc0c4970bb98744f71b6221473026a5"
+ "content" :
"0dec3274326d38a8ac989ecb304710d33dcbb7a2b4445b0bd573af775963972b"
},
{
"alg" : "SHA-512",
- "content" :
"eda3b3c30bc628bfab0421548c2b8a8b37fbc79d02723156344bdf4f0c054594ba8bc7a6d6e8776b70af39c89b523513cac7e562741eebdf2ec2fec19983df3f"
+ "content" :
"961e02a351f61ec04109e1b42088f92697cfb2fa1eccc50a9f27c1bd6bf08242b6b0a175222408a77ad34271d33b8b16b69c38d8c6d1fb7b9f6fbcb2e158690b"
},
{
"alg" : "SHA3-256",
- "content" :
"0fca4ccbb30b9a434a7d862e4338429a0ccee1fb48c83f499bbd55a694e43ac2"
+ "content" :
"5dd9dc9ad4bf54773f0f57595e5738fb33e25c21f9b40e85b64fedc6985e1041"
},
{
"alg" : "SHA3-512",
- "content" :
"e4cecfe5fae3fae96a08417a5999cea4170984c03ac35a720b07eef4ddf53ff64edf84e31d3b01020c46ea0e45cf0ee1870121d0a5935fff5a7edc839f452071"
+ "content" :
"dc2de9b50227a6ccd95dce5bd6195e4124d7a8c99ffec7716c45cd24f715cd7d559c1a1588e0e252af935ba8f8534d157abab1ce8846eb01c92ee4051d7e64b4"
},
{
"alg" : "SHA-384",
- "content" :
"f4e5814675b5dbd572abb5a07de3e52d26a30c70e756039d7276d5ec88aa240d63e93f73e04e94ea2fd26ec33e71396a"
+ "content" :
"678cf2de597f950bb18d3700253cfe36a9bb696eab257cd771a58252ccba80fc76d2736adda5b3e5857aef01b2b3674f"
},
{
"alg" : "SHA3-384",
- "content" :
"4f4f28ff6b84c8b1993d96b985d68bc52993d2e93f6c40dcc2bb33a9bc0b22c2a60fc5f888dcaa0ebf2f6752ead7302f"
+ "content" :
"56fe98f060613c2c7cdfe558a00459e409149a85fc996ca8f50161487c5c9f775c1d7b748ee0991cfc1bc38d8af8f5c7"
}
],
"licenses" : [
@@ -295,7 +295,7 @@
"licenses" : [
{
"license" : {
- "name" : "Apache License, Version 2.0",
+ "id" : "Apache-2.0",
"url" : "https://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
@@ -352,7 +352,7 @@
"licenses" : [
{
"license" : {
- "name" : "The Apache Software License, Version 2.0",
+ "id" : "Apache-2.0",
"url" : "https://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
@@ -409,7 +409,7 @@
"licenses" : [
{
"license" : {
- "name" : "The Apache Software License, Version 2.0",
+ "id" : "Apache-2.0",
"url" : "https://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
@@ -466,7 +466,7 @@
"licenses" : [
{
"license" : {
- "name" : "The Apache Software License, Version 2.0",
+ "id" : "Apache-2.0",
"url" : "https://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
@@ -523,7 +523,7 @@
"licenses" : [
{
"license" : {
- "name" : "The Apache Software License, Version 2.0",
+ "id" : "Apache-2.0",
"url" : "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
@@ -580,7 +580,7 @@
"licenses" : [
{
"license" : {
- "name" : "The Apache Software License, Version 2.0",
+ "id" : "Apache-2.0",
"url" : "https://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
@@ -637,7 +637,7 @@
"licenses" : [
{
"license" : {
- "name" : "The Apache License, Version 2.0",
+ "id" : "Apache-2.0",
"url" : "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
@@ -694,7 +694,7 @@
"licenses" : [
{
"license" : {
- "name" : "MIT",
+ "id" : "MIT",
"url" : "https://opensource.org/licenses/MIT"
}
}
@@ -751,7 +751,7 @@
"licenses" : [
{
"license" : {
- "name" : "Apache License Version 2.0",
+ "id" : "Apache-2.0",
"url" : "https://www.apache.org/licenses/LICENSE-2.0"
}
}
@@ -808,7 +808,7 @@
"licenses" : [
{
"license" : {
- "name" : "Apache-2.0",
+ "id" : "Apache-2.0",
"url" : "https://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
@@ -865,7 +865,7 @@
"licenses" : [
{
"license" : {
- "name" : "Apache-2.0",
+ "id" : "Apache-2.0",
"url" : "https://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
@@ -1136,7 +1136,7 @@
"licenses" : [
{
"license" : {
- "name" : "Apache-2.0",
+ "id" : "Apache-2.0",
"url" : "https://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
@@ -1193,7 +1193,7 @@
"licenses" : [
{
"license" : {
- "name" : "Apache-2.0",
+ "id" : "Apache-2.0",
"url" : "https://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
@@ -1250,7 +1250,7 @@
"licenses" : [
{
"license" : {
- "name" : "The Apache Software License, Version 2.0",
+ "id" : "Apache-2.0",
"url" : "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
@@ -1307,7 +1307,7 @@
"licenses" : [
{
"license" : {
- "name" : "The BSD 2-Clause License",
+ "id" : "BSD-2-Clause",
"url" : "http://www.opensource.org/licenses/bsd-license.php"
}
}
@@ -1364,7 +1364,7 @@
"licenses" : [
{
"license" : {
- "name" : "Apache-2.0",
+ "id" : "Apache-2.0",
"url" : "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
@@ -1421,7 +1421,7 @@
"licenses" : [
{
"license" : {
- "name" : "MIT",
+ "id" : "MIT",
"url" : "https://opensource.org/license/mit"
}
}
@@ -1478,7 +1478,7 @@
"licenses" : [
{
"license" : {
- "name" : "Apache License, Version 2.0",
+ "id" : "Apache-2.0",
"url" : "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
diff --git a/src/main/org/apache/ant/cyclonedx/License.java
b/src/main/org/apache/ant/cyclonedx/License.java
index 6d70194..7750f36 100644
--- a/src/main/org/apache/ant/cyclonedx/License.java
+++ b/src/main/org/apache/ant/cyclonedx/License.java
@@ -19,6 +19,9 @@ package org.apache.ant.cyclonedx;
import java.util.Comparator;
+import org.cyclonedx.model.LicenseChoice;
+import org.cyclonedx.util.LicenseResolver;
+
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.types.DataType;
import org.apache.tools.ant.types.resources.URLResource;
@@ -108,6 +111,17 @@ public class License extends DataType {
if (name == null && id == null) {
throw new BuildException("license name or licenseId is required");
}
+
+ if (id == null) {
+ org.cyclonedx.model.License l = guessLicense();
+ if (l != null) {
+ if (url != null) {
+ l.setUrl(url);
+ }
+ return l;
+ }
+ }
+
org.cyclonedx.model.License l = new org.cyclonedx.model.License();
if (name != null) {
l.setName(name);
@@ -129,4 +143,19 @@ public class License extends DataType {
protected License getRef() {
return getCheckedRef(License.class);
}
+
+ /**
+ * Tries to guess the SPDX license identifier from the license's name or
url.
+ */
+ private org.cyclonedx.model.License guessLicense() {
+ LicenseChoice lc = LicenseResolver.resolve(name, false);
+ if ((lc == null || lc.getLicenses() == null ||
lc.getLicenses().isEmpty())
+ && url != null) {
+ lc = LicenseResolver.resolve(url, false);
+ }
+ if (lc != null && lc.getLicenses() != null &&
!lc.getLicenses().isEmpty()) {
+ return lc.getLicenses().get(0);
+ }
+ return null;
+ }
}
diff --git a/src/tests/antunit/component-ivymodule-test.xml
b/src/tests/antunit/component-ivymodule-test.xml
index 653f2f5..1ffad58 100644
--- a/src/tests/antunit/component-ivymodule-test.xml
+++ b/src/tests/antunit/component-ivymodule-test.xml
@@ -88,8 +88,8 @@
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"/>
+ name="bom.metadata.component.licenses.license.id"
+ value="Apache-2.0"/>
<au:assertPropertyEquals
xmlns:au="antlib:org.apache.ant.antunit"
name="bom.metadata.component.licenses.license.url"
diff --git a/src/tests/antunit/license-test.xml
b/src/tests/antunit/license-test.xml
index ffc0063..5aec828 100644
--- a/src/tests/antunit/license-test.xml
+++ b/src/tests/antunit/license-test.xml
@@ -71,6 +71,48 @@
value="https://example.org/"/>
</target>
+ <target name="testLicenseGuessesIdFromLicenseName">
+ <cdx:componentbom
+ outputdirectory="${output}" format="xml"
+ xmlns:cdx="antlib:org.apache.ant.cyclonedx">
+ <component name="testname">
+ <license name="Apache License 2.0">
+ <url url="https://example.org/"/>
+ </license>
+ </component>
+ </cdx:componentbom>
+ <xmlproperty file="${output}/bom.xml"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.metadata.component.licenses.license.id"
+ value="Apache-2.0"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.metadata.component.licenses.license.url"
+ value="https://example.org/"/>
+ </target>
+
+ <target name="testLicenseGuessesIdFromLicenseUrl">
+ <cdx:componentbom
+ outputdirectory="${output}" format="xml"
+ xmlns:cdx="antlib:org.apache.ant.cyclonedx">
+ <component name="testname">
+ <license name="foo">
+ <url url="https://www.apache.org/licenses/LICENSE-2.0"/>
+ </license>
+ </component>
+ </cdx:componentbom>
+ <xmlproperty file="${output}/bom.xml"/>
+ <au:assertPropertyEquals
+ xmlns:au="antlib:org.apache.ant.antunit"
+ name="bom.metadata.component.licenses.license.id"
+ value="Apache-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"/>
+ </target>
+
<target name="testLicenseWorksViaReference">
<cdx:license
licenseId="0BSD" id="test-license"