Skip to content

Commit

Permalink
convert external reference type by value instead of default CONSTANT_…
Browse files Browse the repository at this point in the history
…NAME

fixes #463

Signed-off-by: Hervé Boutemy <hboutemy@apache.org>
  • Loading branch information
hboutemy committed Mar 23, 2024
1 parent 3fd83bf commit eed838e
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
defaultPhase = LifecyclePhase.PACKAGE,
threadSafe = true,
aggregator = true,
requiresOnline = true
requiresOnline = true,
configurator = "cyclonedx-mojo-component-configurator"
)
public class CycloneDxAggregateMojo extends CycloneDxMojo {
@Parameter(property = "reactorProjects", readonly = true, required = true)
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/cyclonedx/maven/CycloneDxMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
name = "makeBom",
defaultPhase = LifecyclePhase.PACKAGE,
threadSafe = true,
requiresOnline = true
requiresOnline = true,
configurator = "cyclonedx-mojo-component-configurator"
)
public class CycloneDxMojo extends BaseCycloneDxMojo {

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/cyclonedx/maven/CycloneDxPackageMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
defaultPhase = LifecyclePhase.PACKAGE,
threadSafe = true,
aggregator = true,
requiresOnline = true
requiresOnline = true,
configurator = "cyclonedx-mojo-component-configurator"
)
public class CycloneDxPackageMojo extends BaseCycloneDxMojo {
@Parameter(property = "reactorProjects", readonly = true, required = true)
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/cyclonedx/maven/ExtendedMojoConfigurator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.cyclonedx.maven;

import org.codehaus.plexus.component.configurator.BasicComponentConfigurator;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;

import javax.inject.Named;

@Named("cyclonedx-mojo-component-configurator")
public class ExtendedMojoConfigurator extends BasicComponentConfigurator implements Initializable {

@Override
public void initialize() throws InitializationException {
converterLookup.registerConverter(new ExternalReferenceTypeConverter());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.cyclonedx.maven;

import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
import org.codehaus.plexus.component.configurator.converters.basic.AbstractBasicConverter;

import org.cyclonedx.model.ExternalReference;

/**
* Custom Plexus BasicConverter to instantiate <code>ExternalReference.Type</code> from a String.
*
* @see ExternalReference.Type
*/
public class ExternalReferenceTypeConverter extends AbstractBasicConverter {

@Override
public boolean canConvert(Class type) {
return ExternalReference.Type.class.isAssignableFrom(type);
}

@Override
public Object fromString(String string) throws ComponentConfigurationException {
Object value = ExternalReference.Type.fromString(string);
if (value == null) {
throw new ComponentConfigurationException("Unsupported ExternalReference type: " + string);
}
return value;
}
}
6 changes: 2 additions & 4 deletions src/site/markdown/external-references.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ You can add more external references the component that the BOM describes by plu
<configuration>
<externalReferences>
<externalReference>
<type>EXTERNAL_REFERENCE_TYPE</type><-- for "external-reference-type"-->
<type>... external-reference-type ...</type>
<url>... value ...</url>
<comment>(optional) comment</comment>
</externalReference>
Expand All @@ -47,11 +47,9 @@ You can add more external references the component that the BOM describes by plu
</plugin>
```

Notice that the type value in the plugin configuration refers to a [CycloneDX Core (Java) library constant name][external-reference-type-constants]
corresponding to [CycloneDX type][external-reference-type].
See valid [CycloneDX external reference types][external-reference-type].

[maven-model]: https://maven.apache.org/ref/current/maven-model/maven.html
[metadata-component]: https://cyclonedx.org/docs/1.5/json/#metadata_component
[components]: https://cyclonedx.org/docs/1.5/json/#components
[external-reference-type]: https://cyclonedx.org/docs/1.5/json/#metadata_component_externalReferences_items_type
[external-reference-type-constants]: https://cyclonedx.github.io/cyclonedx-core-java/org/cyclonedx/model/ExternalReference.Type.html
2 changes: 1 addition & 1 deletion src/test/resources/external-reference/child/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<schemaVersion>1.4</schemaVersion>
<externalReferences combine.children="append">
<externalReference>
<type>CHAT</type>
<type>chat</type>
<url>https://acme.com/child</url>
</externalReference>
</externalReferences>
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/external-reference/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@
<outputFormat>json</outputFormat>
<externalReferences><!-- additional configured external references -->
<externalReference>
<type>CHAT</type><!-- Java ExternalReference.Type constant for "chat" CycloneDX external reference type -->
<type>chat</type>
<url>https://acme.com/parent</url>
<comment>optional comment</comment>
</externalReference>
<externalReference>
<type>RELEASE_NOTES</type><!-- Java ExternalReference.Type constant for "release-notes" CycloneDX external reference type -->
<type>release-notes</type>
<url>https://github.com/CycloneDX/cyclonedx-maven-plugin/releases</url>
</externalReference>
</externalReferences>
Expand Down

0 comments on commit eed838e

Please sign in to comment.