Repository: CycloneDX/cyclonedx-maven-plugin
Pull request #121 (2021-08-17 16:28:41)

a unit test to validate BOMInputStream object fixes the issue in all cases
Hi @stevespringett  
Does this help? It's in reference to issue-117.
Best regards
Gregory


Patch:
diff --git a/pom.xml b/pom.xml
index 8333ccd..ed4aee2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -140,6 +140,21 @@
             <version>3.6.1</version>
             <scope>provided</scope>
         </dependency>
+        
+        <dependency>
+            <groupId>io.takari.maven.plugins</groupId>
+            <artifactId>takari-plugin-integration-testing</artifactId>
+            <type>pom</type>
+            <scope>test</scope>
+            <version>2.9.2</version>
+        </dependency>
+
+        <dependency>
+            <groupId>io.takari.maven.plugins</groupId>
+            <artifactId>takari-plugin-testing</artifactId>
+            <scope>test</scope>
+            <version>2.9.2</version>
+        </dependency>
     </dependencies>
 
     <prerequisites>
@@ -148,6 +163,21 @@
 
     <build>
         <plugins>
+            <plugin>
+                <groupId>io.takari.maven.plugins</groupId>
+                <artifactId>takari-lifecycle-plugin</artifactId>
+                <version>1.13.9</version>
+                <extensions>true</extensions>
+                <executions>
+                    <execution>
+                        <id>testProperties</id>
+                        <phase>process-test-resources</phase>
+                        <goals>
+                            <goal>testProperties</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-plugin-plugin</artifactId>
diff --git a/src/main/java/org/cyclonedx/maven/BaseCycloneDxMojo.java b/src/main/java/org/cyclonedx/maven/BaseCycloneDxMojo.java
index a314685..4e652bb 100644
--- a/src/main/java/org/cyclonedx/maven/BaseCycloneDxMojo.java
+++ b/src/main/java/org/cyclonedx/maven/BaseCycloneDxMojo.java
@@ -95,6 +95,7 @@ import java.util.TreeMap;
 import java.util.UUID;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
+import org.apache.commons.io.input.BOMInputStream;
 
 import static org.apache.maven.artifact.Artifact.SCOPE_COMPILE;
 
@@ -727,10 +728,18 @@ public abstract class BaseCycloneDxMojo extends AbstractMojo implements Contextu
     private MavenProject readPom(InputStream in) {
         try {
             final MavenXpp3Reader mavenreader = new MavenXpp3Reader();
-            try (final InputStreamReader reader = new InputStreamReader(in)) {
+            try (final InputStreamReader reader = new InputStreamReader(new BOMInputStream(in))) { 
                 final Model model = mavenreader.read(reader);
                 return new MavenProject(model);
-            }
+            } 
+            //if you don't like BOMInputStream you can also escape the error this way:
+//            catch (XmlPullParserException xppe){
+//               if (! xppe.getMessage().startsWith("only whitespace content allowed before start tag")){
+//                   throw xppe;
+//               } else {
+//                   getLog().debug("The pom.xml starts with a Byte Order Marker and MavenXpp3Reader doesn't like it");
+//               }
+//            }
         } catch (XmlPullParserException | IOException e) {
             getLog().error("An error occurred attempting to read POM", e);
         }


Test patch:
diff --git a/src/test/java/org/cyclonedx/maven/Issue117Test.java b/src/test/java/org/cyclonedx/maven/Issue117Test.java
new file mode 100644
index 0000000..d5a0133
--- /dev/null
+++ b/src/test/java/org/cyclonedx/maven/Issue117Test.java
@@ -0,0 +1,57 @@
+package org.cyclonedx.maven;
+
+import io.takari.maven.testing.TestResources;
+import io.takari.maven.testing.executor.MavenRuntime;
+import io.takari.maven.testing.executor.MavenRuntime.MavenRuntimeBuilder;
+import io.takari.maven.testing.executor.MavenVersions;
+import io.takari.maven.testing.executor.junit.MavenJUnitTestRunner;
+import java.io.File;
+import java.io.IOException;
+import java.util.Properties;
+import org.apache.commons.io.FileUtils;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(MavenJUnitTestRunner.class)
+@MavenVersions({"3.6.3"})
+public class Issue117Test {
+
+    @Rule
+    public final TestResources resources = new TestResources(
+            "target/test-classes",
+            "target/test-classes/transformed-projects"
+    );
+
+    public final MavenRuntime verifier;
+
+    public Issue117Test(MavenRuntimeBuilder runtimeBuilder)
+            throws Exception {
+        this.verifier = runtimeBuilder.build(); //.withCliOptions(opts) // //
+    }
+
+    @Test
+    public void testPluginWithActiviti() throws IOException, Exception {
+        File projectDirTransformed = new File(
+                "target/test-classes/transformed-projects/issue-117"
+        );
+        if (projectDirTransformed.exists()) {
+            FileUtils.cleanDirectory(projectDirTransformed);
+            projectDirTransformed.delete();
+        }
+
+        File projDir = resources.getBasedir("issue-117");
+
+        Properties props = new Properties();
+
+        props.load(Issue117Test.class.getClassLoader().getResourceAsStream("test.properties"));
+        String projectVersion = String.class.cast(props.get("project.version"));
+        verifier
+                .forProject(projDir) //
+                .withCliOption("-Dtest.input.version=" + projectVersion) // debug
+                .withCliOption("-X") // debug
+                .withCliOption("-B")
+                .execute("clean", "package")
+                .assertErrorFreeLog();
+    }
+}
diff --git a/src/test/resources/issue-117/pom.xml b/src/test/resources/issue-117/pom.xml
new file mode 100644
index 0000000..990f054
--- /dev/null
+++ b/src/test/resources/issue-117/pom.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>com.example</groupId>
+    <artifactId>issue-117</artifactId>
+    <packaging>jar</packaging>
+    <version>1.0.0</version>
+
+    <name>Issue-117</name>
+
+    <licenses>
+        <license>
+            <name>Apache-2.0</name>
+            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+        </license>
+    </licenses>
+
+    <properties>
+        <maven.compiler.source>1.8</maven.compiler.source>
+        <maven.compiler.target>1.8</maven.compiler.target>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.activiti</groupId>
+            <artifactId>activiti-engine</artifactId>
+            <version>5.14</version>
+        </dependency>
+    </dependencies>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.cyclonedx</groupId>
+                <artifactId>cyclonedx-maven-plugin</artifactId>
+                <version>${test.input.version}</version>
+                <executions>
+                    <execution>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>makeAggregateBom</goal>
+                        </goals>
+                    </execution>
+                </executions>
+                <configuration>
+                    <projectType>library</projectType>
+                    <schemaVersion>1.3</schemaVersion>
+                    <includeBomSerialNumber>true</includeBomSerialNumber>
+                    <includeCompileScope>true</includeCompileScope>
+                    <includeProvidedScope>true</includeProvidedScope>
+                    <includeRuntimeScope>true</includeRuntimeScope>
+                    <includeSystemScope>true</includeSystemScope>
+                    <includeTestScope>true</includeTestScope>
+                    <includeLicenseText>true</includeLicenseText>
+                    <outputFormat>all</outputFormat>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>