Skip to content

Commit eed838e

Browse files
committed
convert external reference type by value instead of default CONSTANT_NAME
fixes #463 Signed-off-by: Hervé Boutemy <[email protected]>
1 parent 3fd83bf commit eed838e

File tree

8 files changed

+55
-10
lines changed

8 files changed

+55
-10
lines changed

src/main/java/org/cyclonedx/maven/CycloneDxAggregateMojo.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
defaultPhase = LifecyclePhase.PACKAGE,
4343
threadSafe = true,
4444
aggregator = true,
45-
requiresOnline = true
45+
requiresOnline = true,
46+
configurator = "cyclonedx-mojo-component-configurator"
4647
)
4748
public class CycloneDxAggregateMojo extends CycloneDxMojo {
4849
@Parameter(property = "reactorProjects", readonly = true, required = true)

src/main/java/org/cyclonedx/maven/CycloneDxMojo.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
name = "makeBom",
4444
defaultPhase = LifecyclePhase.PACKAGE,
4545
threadSafe = true,
46-
requiresOnline = true
46+
requiresOnline = true,
47+
configurator = "cyclonedx-mojo-component-configurator"
4748
)
4849
public class CycloneDxMojo extends BaseCycloneDxMojo {
4950

src/main/java/org/cyclonedx/maven/CycloneDxPackageMojo.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
defaultPhase = LifecyclePhase.PACKAGE,
4343
threadSafe = true,
4444
aggregator = true,
45-
requiresOnline = true
45+
requiresOnline = true,
46+
configurator = "cyclonedx-mojo-component-configurator"
4647
)
4748
public class CycloneDxPackageMojo extends BaseCycloneDxMojo {
4849
@Parameter(property = "reactorProjects", readonly = true, required = true)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.cyclonedx.maven;
2+
3+
import org.codehaus.plexus.component.configurator.BasicComponentConfigurator;
4+
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
5+
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
6+
7+
import javax.inject.Named;
8+
9+
@Named("cyclonedx-mojo-component-configurator")
10+
public class ExtendedMojoConfigurator extends BasicComponentConfigurator implements Initializable {
11+
12+
@Override
13+
public void initialize() throws InitializationException {
14+
converterLookup.registerConverter(new ExternalReferenceTypeConverter());
15+
}
16+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.cyclonedx.maven;
2+
3+
import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
4+
import org.codehaus.plexus.component.configurator.converters.basic.AbstractBasicConverter;
5+
6+
import org.cyclonedx.model.ExternalReference;
7+
8+
/**
9+
* Custom Plexus BasicConverter to instantiate <code>ExternalReference.Type</code> from a String.
10+
*
11+
* @see ExternalReference.Type
12+
*/
13+
public class ExternalReferenceTypeConverter extends AbstractBasicConverter {
14+
15+
@Override
16+
public boolean canConvert(Class type) {
17+
return ExternalReference.Type.class.isAssignableFrom(type);
18+
}
19+
20+
@Override
21+
public Object fromString(String string) throws ComponentConfigurationException {
22+
Object value = ExternalReference.Type.fromString(string);
23+
if (value == null) {
24+
throw new ComponentConfigurationException("Unsupported ExternalReference type: " + string);
25+
}
26+
return value;
27+
}
28+
}

src/site/markdown/external-references.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ You can add more external references the component that the BOM describes by plu
3838
<configuration>
3939
<externalReferences>
4040
<externalReference>
41-
<type>EXTERNAL_REFERENCE_TYPE</type><-- for "external-reference-type"-->
41+
<type>... external-reference-type ...</type>
4242
<url>... value ...</url>
4343
<comment>(optional) comment</comment>
4444
</externalReference>
@@ -47,11 +47,9 @@ You can add more external references the component that the BOM describes by plu
4747
</plugin>
4848
```
4949

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

5352
[maven-model]: https://maven.apache.org/ref/current/maven-model/maven.html
5453
[metadata-component]: https://cyclonedx.org/docs/1.5/json/#metadata_component
5554
[components]: https://cyclonedx.org/docs/1.5/json/#components
5655
[external-reference-type]: https://cyclonedx.org/docs/1.5/json/#metadata_component_externalReferences_items_type
57-
[external-reference-type-constants]: https://cyclonedx.github.io/cyclonedx-core-java/org/cyclonedx/model/ExternalReference.Type.html

src/test/resources/external-reference/child/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<schemaVersion>1.4</schemaVersion>
3232
<externalReferences combine.children="append">
3333
<externalReference>
34-
<type>CHAT</type>
34+
<type>chat</type>
3535
<url>https://acme.com/child</url>
3636
</externalReference>
3737
</externalReferences>

src/test/resources/external-reference/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@
9090
<outputFormat>json</outputFormat>
9191
<externalReferences><!-- additional configured external references -->
9292
<externalReference>
93-
<type>CHAT</type><!-- Java ExternalReference.Type constant for "chat" CycloneDX external reference type -->
93+
<type>chat</type>
9494
<url>https://acme.com/parent</url>
9595
<comment>optional comment</comment>
9696
</externalReference>
9797
<externalReference>
98-
<type>RELEASE_NOTES</type><!-- Java ExternalReference.Type constant for "release-notes" CycloneDX external reference type -->
98+
<type>release-notes</type>
9999
<url>https://github.com/CycloneDX/cyclonedx-maven-plugin/releases</url>
100100
</externalReference>
101101
</externalReferences>

0 commit comments

Comments
 (0)