Repository: CycloneDX/cyclonedx-maven-plugin (java)

Issue:
externalReference:   Cannot convert 'static-analysis-report' to Enum
plugin v2.7.11 added support for custom External References via #428.

Following the [documentation](https://cyclonedx.github.io/cyclonedx-maven-plugin/external-references.html) I initially added the following to configuration section of pluginManagement entry for plugin:

```
                        <externalReferences>
                            <externalReference>
                                <type>static-analysis-report</type>
                                <url>https://foo.bar.com</url>
                                <comment>SonarQube</comment>
                            </externalReference>
                        </externalReferences>
```

...and got the following error:

```
[2024-01-29T17:15:05.211Z] [ERROR] Failed to execute goal org.cyclonedx:cyclonedx-maven-plugin:2.7.11:makeAggregateBom (default-cli) on project xxx-yyy: Unable to parse configuration of mojo org.cyclonedx:cyclonedx-maven-plugin:2.7.11:makeAggregateBom for parameter externalReference: Cannot convert 'static-analysis-report' to Enum: No enum constant org.cyclonedx.model.ExternalReference.Type.static-analysis-report -> [Help 1]
```

I then noticed line at bottom of documentation:

> Notice that the type value in the plugin configuration refers to a [CycloneDX Core (Java) library constant name](https://cyclonedx.github.io/cyclonedx-core-java/org/cyclonedx/model/ExternalReference.Type.html) corresponding to [CycloneDX type](https://cyclonedx.org/docs/1.5/json/#metadata_component_externalReferences_items_type)

...so I tried `STATIC_ANALYSIS_REPORT` for type, but got the same error.

Aside:  I do think that the value of type should match what is in the CycloneDX documentation (eg the guide) as that makes it easier to expect common behaviour across plugins from different ecosystems (gradle, etc).  This could be important when a Jenkins server is providing type as a variable at build time.

Pull request description:
convert external reference type by value instead of CONSTANT_NAME
it's much easier to understand configuration with external reference type value like
```
<type>release-notes</type>
```

than previously default constant value
```
<type>RELEASE_NOTES</type>
```

fixes #463

Patch:
diff --git a/pom.xml b/pom.xml
index de13987..dbc0785 100644
--- a/pom.xml
+++ b/pom.xml
@@ -332,7 +332,7 @@
                 <plugin>
                     <groupId>org.apache.maven.plugins</groupId>
                     <artifactId>maven-compiler-plugin</artifactId>
-                    <version>3.12.1</version>
+                    <version>3.13.0</version>
                 </plugin>
                 <plugin>
                     <groupId>org.apache.maven.plugins</groupId>
diff --git a/src/main/java/org/cyclonedx/maven/CycloneDxAggregateMojo.java b/src/main/java/org/cyclonedx/maven/CycloneDxAggregateMojo.java
index 92e8f59..416596a 100644
--- a/src/main/java/org/cyclonedx/maven/CycloneDxAggregateMojo.java
+++ b/src/main/java/org/cyclonedx/maven/CycloneDxAggregateMojo.java
@@ -42,7 +42,8 @@ import java.util.Set;
         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)
diff --git a/src/main/java/org/cyclonedx/maven/CycloneDxMojo.java b/src/main/java/org/cyclonedx/maven/CycloneDxMojo.java
index 397dc26..2ca6e15 100644
--- a/src/main/java/org/cyclonedx/maven/CycloneDxMojo.java
+++ b/src/main/java/org/cyclonedx/maven/CycloneDxMojo.java
@@ -43,7 +43,8 @@ import java.util.Set;
         name = "makeBom",
         defaultPhase = LifecyclePhase.PACKAGE,
         threadSafe = true,
-        requiresOnline = true
+        requiresOnline = true,
+        configurator = "cyclonedx-mojo-component-configurator"
 )
 public class CycloneDxMojo extends BaseCycloneDxMojo {
 
diff --git a/src/main/java/org/cyclonedx/maven/CycloneDxPackageMojo.java b/src/main/java/org/cyclonedx/maven/CycloneDxPackageMojo.java
index 656ed22..828d103 100644
--- a/src/main/java/org/cyclonedx/maven/CycloneDxPackageMojo.java
+++ b/src/main/java/org/cyclonedx/maven/CycloneDxPackageMojo.java
@@ -42,7 +42,8 @@ import java.util.Set;
         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)
diff --git a/src/main/java/org/cyclonedx/maven/ExtendedMojoConfigurator.java b/src/main/java/org/cyclonedx/maven/ExtendedMojoConfigurator.java
new file mode 100644
index 0000000..881c814
--- /dev/null
+++ b/src/main/java/org/cyclonedx/maven/ExtendedMojoConfigurator.java
@@ -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());
+    }
+}
diff --git a/src/main/java/org/cyclonedx/maven/ExternalReferenceTypeConverter.java b/src/main/java/org/cyclonedx/maven/ExternalReferenceTypeConverter.java
new file mode 100644
index 0000000..03451f5
--- /dev/null
+++ b/src/main/java/org/cyclonedx/maven/ExternalReferenceTypeConverter.java
@@ -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;
+    }
+}
diff --git a/src/site/markdown/external-references.md b/src/site/markdown/external-references.md
index f02006d..a482c0b 100644
--- a/src/site/markdown/external-references.md
+++ b/src/site/markdown/external-references.md
@@ -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>
@@ -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
\ No newline at end of file


Test patch:
diff --git a/src/test/resources/external-reference/child/pom.xml b/src/test/resources/external-reference/child/pom.xml
index 1f0c7b2..d8fb06b 100644
--- a/src/test/resources/external-reference/child/pom.xml
+++ b/src/test/resources/external-reference/child/pom.xml
@@ -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>
diff --git a/src/test/resources/external-reference/pom.xml b/src/test/resources/external-reference/pom.xml
index faf4ab3..3c170df 100644
--- a/src/test/resources/external-reference/pom.xml
+++ b/src/test/resources/external-reference/pom.xml
@@ -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>