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 9030a62  add getters for all of components mutators
9030a62 is described below

commit 9030a625bb6f583d85d4250e21a4b075dc9ce0b2
Author: Stefan Bodewig <[email protected]>
AuthorDate: Sun Aug 16 14:17:33 2026 +0200

    add getters for all of components mutators
---
 build.xml                                          |   1 +
 src/main/org/apache/ant/cyclonedx/Component.java   | 282 +++++++++++++++++----
 .../org/apache/ant/cyclonedx/ComponentBomTask.java |   4 +-
 .../org/apache/ant/cyclonedx/ComponentType.java    |   2 +-
 .../ant/cyclonedx/IvyModuleComponentResolver.java  |   4 +-
 src/main/org/apache/ant/cyclonedx/License.java     |  21 ++
 6 files changed, 259 insertions(+), 55 deletions(-)

diff --git a/build.xml b/build.xml
index 13c6900..c6fc8b8 100644
--- a/build.xml
+++ b/build.xml
@@ -38,6 +38,7 @@ under the License.
       includeantruntime="true">
       <classpath refid="ivy.lib.path"/>
       <classpath refid="classpath.compile"/>
+      <compilerArg value="-Xlint:all"/>
     </javac>
   </target>
 
diff --git a/src/main/org/apache/ant/cyclonedx/Component.java 
b/src/main/org/apache/ant/cyclonedx/Component.java
index 61a6651..9976de4 100644
--- a/src/main/org/apache/ant/cyclonedx/Component.java
+++ b/src/main/org/apache/ant/cyclonedx/Component.java
@@ -254,6 +254,7 @@ public class Component extends DataType {
      *
      * @param description component description
      */
+    @Override
     public void setDescription(String description) {
         checkAttributesAllowed();
         this.description = description;
@@ -309,7 +310,7 @@ public class Component extends DataType {
      *
      * <p>At most one supplier can be set.</p>
      *
-     * @param supplier compoment supplier
+     * @param supplier component supplier
      */
     public void addSupplier(Organization supplier) {
         checkChildrenAllowed();
@@ -378,7 +379,7 @@ public class Component extends DataType {
     /**
      * Adds a license to this component.
      *
-     * @param l compoment license
+     * @param l component license
      */
     public void addConfiguredLicense(License l) {
         checkChildrenAllowed();
@@ -498,10 +499,38 @@ public class Component extends DataType {
         return ivyModule == null ? (ivyModule = new IvyModule()) : ivyModule;
     }
 
+    /**
+     * Gets the resource the component is about.
+     *
+     * @return the resource holding the component's content - may be null
+     * @since CycloneDX Antlib 0.2
+     */
+    public Resource getComponentFile() {
+        if (isReference()) {
+            return getRef().getComponentFile();
+        }
+        dieOnCircularReference();
+        return resource;
+    }
+
+    /**
+     * Gets the component type.
+     *
+     * @return the component type  - may be null
+     * @since CycloneDX Antlib 0.2
+     */
+    public ComponentType getType() {
+        if (isReference()) {
+            return getRef().getType();
+        }
+        dieOnCircularReference();
+        return type == null ? null : ComponentType.from(type);
+    }
+
     /**
      * Gets the name of the component.
      *
-     * @return component name
+     * @return component name - will not be null on a valid component
      */
     public String getName() {
         if (isReference()) {
@@ -514,7 +543,7 @@ public class Component extends DataType {
     /**
      * Gets the group of the component.
      *
-     * @return component group
+     * @return component group - may be null
      */
     public String getGroup() {
         if (isReference()) {
@@ -527,7 +556,7 @@ public class Component extends DataType {
     /**
      * Gets the version of the component.
      *
-     * @return component version
+     * @return component version - may be null
      * @since CycloneDX Antlib 0.2
      */
     public String getVersion() {
@@ -576,58 +605,169 @@ public class Component extends DataType {
     }
 
     /**
-     * Gets the dependencies of the component.
+     * Gets the decription of the component.
      *
-     * @return component's dependencies
+     * @return component description - may be null
+     * @since CycloneDX Antlib 0.2
      */
-    public Iterable<Dependency> getDependencies() {
+    @Override
+    public String getDescription() {
         if (isReference()) {
-            return getRef().getDependencies();
+            return getRef().getDescription();
         }
         dieOnCircularReference();
-        return 
dependencies.stream().sorted(Dependency.DependencyComparator).collect(Collectors.toList());
+        return description;
     }
 
     /**
-     * Whether dependencies are unknoown.
+     * Gets the publisher of the component.
      *
-     * @return the value set with {@link #setUnknownDependencies}
-     * or {@code false}.
+     * @return component publisher - may be null
+     * @since CycloneDX Antlib 0.2
      */
-    public boolean areDependenciesUnknown() {
+    public String getPublisher() {
         if (isReference()) {
-            return getRef().areDependenciesUnknown();
+            return getRef().getPublisher();
         }
         dieOnCircularReference();
-        return unknownDependencies;
+        return publisher;
     }
 
     /**
-     * Recursively returns the nested components of this component.
+     * Gets the copyright of the component.
      *
-     * @return nested components of this component
+     * @return component copyright - may be null
+     * @since CycloneDX Antlib 0.2
      */
-    public List<Component> getNestedComponents() {
+    public String getCopyright() {
         if (isReference()) {
-            return getRef().getNestedComponents();
+            return getRef().getCopyright();
         }
         dieOnCircularReference();
-        List<Component> result = new ArrayList<>();
-        result.addAll(nestedComponents);
-        result.addAll(nestedComponents
-                      .stream()
-                      .flatMap(c -> c.getNestedComponents().stream())
-                      .collect(Collectors.toList()));
-        return result;
+        return copyright;
     }
 
     /**
-     * Gets the dependencies of the component.
+     * Gets the mime-type of the component.
+     *
+     * @return component mime-type - may be null
+     * @since CycloneDX Antlib 0.2
+     */
+    public String getMimeType() {
+        if (isReference()) {
+            return getRef().getMimeType();
+        }
+        dieOnCircularReference();
+        return mimeType;
+    }
+
+    /**
+     * Gets the manufacturer of the component.
+     *
+     * @return component manufacturer - may be null
+     * @since CycloneDX Antlib 0.2
+     */
+    public Organization getManufacturer() {
+        if (isReference()) {
+            return getRef().getManufacturer();
+        }
+        dieOnCircularReference();
+        return manufacturer;
+    }
+
+    /**
+     * Gets the supplier of the component.
+     *
+     * @return component supplier - may be null
+     * @since CycloneDX Antlib 0.2
+     */
+    public Organization getSupplier() {
+        if (isReference()) {
+            return getRef().getSupplier();
+        }
+        dieOnCircularReference();
+        return supplier;
+    }
+
+    /**
+     * Gets the authors of the component.
+     *
+     * @return component authors - will not be null
+     * @since CycloneDX Antlib 0.2
+     */
+    public Collection<OrganizationalContact> getAuthors() {
+        if (isReference()) {
+            return getRef().getAuthors();
+        }
+        dieOnCircularReference();
+        return authors;
+    }
+
+    /**
+     * Gets the tags of the component.
+     *
+     * @return component tags - will not be null
+     * @since CycloneDX Antlib 0.2
+     */
+    public Collection<Tag> getTags() {
+        if (isReference()) {
+            return getRef().getTags();
+        }
+        dieOnCircularReference();
+        return tags.stream().map(Tag::new).collect(Collectors.toList());
+    }
+
+    /**
+     * Gets merged properties added via {@link #addConfiguredProperty} or 
{@link #addConfiguredPropertySet} to the
+     * component.
+     *
+     * @return component property - will not be null
+     * @since CycloneDX Antlib 0.2
+     */
+    public Collection<Property> getProperties() {
+        if (isReference()) {
+            return getRef().getProperties();
+        }
+        dieOnCircularReference();
+        return properties;
+    }
+
+    /**
+     * Gets whether the supplier shall also be used to provide the 
manufacturer information.
+     *
+     * @return whether to use supplier as manufacturer as well
+     * @since CycloneDX Antlib 0.2
+     */
+    public boolean getSupplierIsManufacturer() {
+        if (isReference()) {
+            return getRef().getSupplierIsManufacturer();
+        }
+        dieOnCircularReference();
+        return supplierIsManufacturer;
+    }
+
+    /**
+     * Gets licenses added to this component.
+     *
+     * @return component licenses - will not be null
+     * @since CycloneDX Antlib 0.2
+     */
+    public Collection<License> getLicenses() {
+        if (isReference()) {
+            return getRef().getLicenses();
+        }
+        dieOnCircularReference();
+        return 
licenses.stream().map(License::from).collect(Collectors.toList());
+    }
+
+    /**
+     * Gets the merged external references added via {@see 
#addConfiguredExternalReference} or {@see
+     * #addConfiguredExternalReferenceSet} to the component.
      *
-     * @return component's dependencies
+     * @return component's external references - will not be null
      * @since CycloneDX Antlib 0.2
      */
-    Collection<org.cyclonedx.model.ExternalReference> getExternalReferences() {
+    public Collection<org.cyclonedx.model.ExternalReference> 
getExternalReferences() {
         if (isReference()) {
             return getRef().getExternalReferences();
         }
@@ -635,13 +775,27 @@ public class Component extends DataType {
         return externalReferences;
     }
 
+    /**
+     * Gets the scope of this component.
+     *
+     * @return component scope - may be null
+     * @since CycloneDX Antlib 0.2
+     */
+    public ComponentScope getScope() {
+        if (isReference()) {
+            return getRef().getScope();
+        }
+        dieOnCircularReference();
+        return scope == null ? null : ComponentScope.from(scope);
+    }
+
     /**
      * Gets whether the isExternal flag is true.
      *
      * @return whether the isExternal flag is true
      * @since CycloneDX Antlib 0.2
      */
-    boolean getIsExternal() {
+    public boolean getIsExternal() {
         if (isReference()) {
             return getRef().getIsExternal();
         }
@@ -650,31 +804,49 @@ public class Component extends DataType {
     }
 
     /**
-     * Gets whether any licenses have been explicitly configured for this 
component.
+     * Recursively returns the nested components of this component.
      *
-     * @return whether any licenses have been explicitly configured
-     * @since CycloneDX Antlib 0.2
+     * @return nested components of this component - will not be null
      */
-    boolean hasLicenses() {
+    public List<Component> getNestedComponents() {
         if (isReference()) {
-            return getRef().hasLicenses();
+            return getRef().getNestedComponents();
         }
         dieOnCircularReference();
-        return !licenses.isEmpty();
+        List<Component> result = new ArrayList<>();
+        result.addAll(nestedComponents);
+        result.addAll(nestedComponents
+                      .stream()
+                      .flatMap(c -> c.getNestedComponents().stream())
+                      .collect(Collectors.toList()));
+        return result;
     }
 
     /**
-     * Gets whether any description been explicitly configured for this 
component.
+     * Gets the dependencies of the component.
      *
-     * @return whether any description has been explicitly configured
-     * @since CycloneDX Antlib 0.2
+     * @return component's dependencies - will not be null
+     */
+    public Collection<Dependency> getDependencies() {
+        if (isReference()) {
+            return getRef().getDependencies();
+        }
+        dieOnCircularReference();
+        return 
dependencies.stream().sorted(Dependency.DependencyComparator).collect(Collectors.toList());
+    }
+
+    /**
+     * Whether dependencies are unknoown.
+     *
+     * @return the value set with {@link #setUnknownDependencies}
+     * or {@code false}.
      */
-    boolean hasDescription() {
+    public boolean areDependenciesUnknown() {
         if (isReference()) {
-            return getRef().hasDescription();
+            return getRef().areDependenciesUnknown();
         }
         dieOnCircularReference();
-        return description != null;
+        return unknownDependencies;
     }
 
     /**
@@ -867,7 +1039,7 @@ public class Component extends DataType {
         return component;
     }
 
-    static Component from(
+    protected static Component from(
         org.cyclonedx.model.Component real,
         List<org.cyclonedx.model.Dependency> dependencies) {
         Component c = new Component();
@@ -875,8 +1047,8 @@ public class Component extends DataType {
         return c;
     }
 
-    void fillFrom(org.cyclonedx.model.Component real,
-                  List<org.cyclonedx.model.Dependency> allDependencies) {
+    protected void fillFrom(org.cyclonedx.model.Component real,
+                            List<org.cyclonedx.model.Dependency> 
allDependencies) {
         if (type == null) {
             setType(ComponentType.from(real.getType()));
         }
@@ -1094,6 +1266,16 @@ public class Component extends DataType {
     public static class Tag {
         private String tag;
 
+        public Tag() {
+        }
+
+        /**
+         * @since CycloneDX Antlib 0.2
+         */
+        public Tag(String tag) {
+            this.tag = tag;
+        }
+
         /**
          * Sets the tag value.
          *
@@ -1150,7 +1332,7 @@ public class Component extends DataType {
 
         /**
          * Whether to create a bom-Type external reference in the
-         * resolved compoment based on the nested resource's URI.
+         * resolved component based on the nested resource's URI.
          *
          * <p>Will not create an external reference of there are
          * already external references om the component or the
@@ -1166,7 +1348,7 @@ public class Component extends DataType {
 
         /**
          * Whether to create a bom-Type external reference in the
-         * resolved compoment based on the nested resource's URI.
+         * resolved component based on the nested resource's URI.
          * @return create whether to create a bom-Type external reference
          */
         public boolean getCreateBomExternalReference() {
@@ -1244,7 +1426,7 @@ public class Component extends DataType {
          * <p>Any module that is included in the SBOM because it is required 
by on of the configurations given in {@link
          * #setConf} and only is included because of configurations listed 
here is marked optional. Including
          * configurations that are not part of {@link #setConf} doesn't have 
any effect. {@code *} is no supported. The
-         * default is to have no optional compoments.</p>
+         * default is to have no optional components.</p>
          *
          * @param comma separated list of the configurations to mark optional.
          */
@@ -1262,7 +1444,7 @@ public class Component extends DataType {
          * <p>Any module that is included in the SBOM because it is required 
by on of the configurations given in {@link
          * #setConf} and only is included because of configurations listed 
here is marked external. Including
          * configurations that are not part of {@link #setConf} doesn't have 
any effect. {@code *} is no supported. The
-         * default is to have no external compoments.</p>
+         * default is to have no external components.</p>
          *
          * @param comma separated list of the configurations to mark external.
          */
diff --git a/src/main/org/apache/ant/cyclonedx/ComponentBomTask.java 
b/src/main/org/apache/ant/cyclonedx/ComponentBomTask.java
index be11c98..df7e1a5 100644
--- a/src/main/org/apache/ant/cyclonedx/ComponentBomTask.java
+++ b/src/main/org/apache/ant/cyclonedx/ComponentBomTask.java
@@ -379,8 +379,8 @@ public class ComponentBomTask extends Task {
         }
         byte[] componentIdHash = new 
DigestUtils(MessageDigestAlgorithms.MD5).digest(componentId);
         long clockseq = ((long)(componentIdHash[0] & 0x3F) << 56) | 
((long)(componentIdHash[1] & 0xFF) << 48);
-        long nodeLow = ((long)(componentIdHash[2] & 0xFFl) << 40) | 
((long)(componentIdHash[3] & 0xFF) << 32);
-        long nodeHigh = ((long)(componentIdHash[4] & 0xFFl) << 24) | 
((componentIdHash[5] & 0xFF) << 16)
+        long nodeLow = ((componentIdHash[2] & 0xFFl) << 40) | 
((long)(componentIdHash[3] & 0xFF) << 32);
+        long nodeHigh = ((componentIdHash[4] & 0xFFl) << 24) | 
((componentIdHash[5] & 0xFF) << 16)
             | ((componentIdHash[6] & 0xFF) << 8) | (componentIdHash[7] & 0xFF);
         long lsb = variant | clockseq | nodeLow | nodeHigh;
 
diff --git a/src/main/org/apache/ant/cyclonedx/ComponentType.java 
b/src/main/org/apache/ant/cyclonedx/ComponentType.java
index afb669d..44ae501 100644
--- a/src/main/org/apache/ant/cyclonedx/ComponentType.java
+++ b/src/main/org/apache/ant/cyclonedx/ComponentType.java
@@ -52,7 +52,7 @@ public class ComponentType extends EnumeratedAttribute {
      * @param type CycloneDX type.
      * @return translated type
      */
-    public  static ComponentType from(Type type) {
+    public static ComponentType from(Type type) {
         ComponentType t = new ComponentType();
         t.setValue(type.name());
         return t;
diff --git a/src/main/org/apache/ant/cyclonedx/IvyModuleComponentResolver.java 
b/src/main/org/apache/ant/cyclonedx/IvyModuleComponentResolver.java
index 275589e..58ba715 100644
--- a/src/main/org/apache/ant/cyclonedx/IvyModuleComponentResolver.java
+++ b/src/main/org/apache/ant/cyclonedx/IvyModuleComponentResolver.java
@@ -209,12 +209,12 @@ class IvyModuleComponentResolver {
         if (component.getVersion() == null) {
             component.setVersion(mrid.getRevision());
         }
-        if (!component.hasDescription() && md.getDescription() != null && 
md.getDescription().length() > 0) {
+        if (component.getDescription() == null && md.getDescription() != null 
&& md.getDescription().length() > 0) {
             component.setDescription(md.getDescription());
         }
 
         String licenseUrl = null;
-        if (!component.hasLicenses()) {
+        if (component.getLicenses().isEmpty()) {
             License[] ivyLicenses = md.getLicenses();
             if (ivyLicenses != null) {
 
diff --git a/src/main/org/apache/ant/cyclonedx/License.java 
b/src/main/org/apache/ant/cyclonedx/License.java
index 7750f36..e4fac3f 100644
--- a/src/main/org/apache/ant/cyclonedx/License.java
+++ b/src/main/org/apache/ant/cyclonedx/License.java
@@ -135,6 +135,27 @@ public class License extends DataType {
         return l;
     }
 
+    /**
+     * @since CycloneDX Antlib 0.2
+     */
+    public static License from(org.cyclonedx.model.License l) {
+        License license = new License();
+        String id = l.getId();
+        if (id != null) {
+            license.setLicenseId(id);
+        } else {
+            String name = l.getName();
+            if (name != null) {
+                license.setName(name);
+            }
+        }
+        String url = l.getName();
+        if (url != null) {
+            license.addConfiguredUrl(new URLResource(url));
+        }
+        return license;
+    }
+
     /**
      * Perform the check for circular references and return the
      * referenced License.

Reply via email to