Generate an execution report from yang-maven-plugin-it 60/97960/6
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 18 Oct 2021 16:15:18 +0000 (18:15 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 18 Oct 2021 18:27:09 +0000 (20:27 +0200)
Adjust our wiring to pass down failsafe argLine to our individual
maven invocations. This ends up producing correct execution reports.

The second part end up merging these partial reports into a single
execution report.

The third part is to unpack yang-maven-plugin and its dependencies,
which means classes can be looked up and jacoco thinks this is coming
from us. Yeah, not nice, but works.

JIRA: YANGTOOLS-1167
Change-Id: I4179b96d8a0039041160f9143798b785a74fb932
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
plugin/yang-maven-plugin-it/pom.xml
plugin/yang-maven-plugin-it/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/it/YangToSourcesPluginTestIT.java

index 047af806809ff2cdcb21338d1ea91e9961b27b2e..85b35c2e3e7ba1150a9c527d8cd2fe3ebfbca7be 100644 (file)
     <artifactId>yang-maven-plugin-it</artifactId>
     <version>8.0.0-SNAPSHOT</version>
 
+    <properties>
+        <!-- We are doing abhorrent things here unpacking our dependencies, which confuses analysis, just skip it -->
+        <odlparent.dependency.skip>true</odlparent.dependency.skip>
+    </properties>
+
     <dependencies>
         <dependency>
             <groupId>org.apache.maven.shared</groupId>
             <artifactId>guava</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>yang-maven-plugin</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
-      <testResources>
-        <testResource>
-          <directory>${basedir}/src/test/resources</directory>
-          <filtering>true</filtering>
-        </testResource>
-      </testResources>
+        <testResources>
+            <testResource>
+                <directory>${basedir}/src/test/resources</directory>
+                <filtering>true</filtering>
+            </testResource>
+        </testResources>
         <plugins>
-          <plugin>
-            <artifactId>maven-resources-plugin</artifactId>
-            <executions>
-              <execution>
-                <id>default-testResources</id>
-                <phase>process-test-resources</phase>
-                <goals>
-                  <goal>testResources</goal>
-                </goals>
-                <configuration>
-                  <useDefaultDelimiters>false</useDefaultDelimiters>
-                  <delimiters>
-                    <delimiter>@</delimiter>
-                  </delimiters>
-                </configuration>
-              </execution>
-            </executions>
-          </plugin>
             <plugin>
-                <artifactId>maven-failsafe-plugin</artifactId>
+                <artifactId>maven-resources-plugin</artifactId>
                 <executions>
                     <execution>
+                        <id>default-testResources</id>
+                        <phase>process-test-resources</phase>
                         <goals>
-                            <goal>integration-test</goal>
-                            <goal>verify</goal>
+                            <goal>testResources</goal>
                         </goals>
+                        <configuration>
+                            <useDefaultDelimiters>false</useDefaultDelimiters>
+                            <delimiters>
+                                <delimiter>@</delimiter>
+                            </delimiters>
+                        </configuration>
                     </execution>
                 </executions>
             </plugin>
                 </configuration>
                 <executions>
                     <execution>
-                      <phase>pre-integration-test</phase>
-                      <goals>
-                          <goal>effective-settings</goal>
-                      </goals>
+                        <phase>pre-integration-test</phase>
+                        <goals>
+                            <goal>effective-settings</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <artifactId>maven-failsafe-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>integration-test</goal>
+                            <goal>verify</goal>
+                        </goals>
+                        <configuration>
+                            <!-- We want to pass argLine down to maven invocations, not to failsafe -->
+                            <argLine>-DitArgPath='@{argLine}'</argLine>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+
+            <plugin>
+                <groupId>org.jacoco</groupId>
+                <artifactId>jacoco-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>merge-reports</id>
+                        <phase>post-integration-test</phase>
+                        <goals>
+                            <goal>merge</goal>
+                        </goals>
+                        <configuration>
+                            <fileSets>
+                                <fileSet>
+                                    <directory>${project.build.directory}/test-classes/test-parent</directory>
+                                    <includes>
+                                        <include>*.exec</include>
+                                    </includes>
+                                </fileSet>
+                            </fileSets>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+
+            <!-- Okay, this is rather ugly, but is needed to fool JaCoCo to generate an XML report -->
+            <plugin>
+                <artifactId>maven-dependency-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>fake-classes</id>
+                        <phase>post-integration-test</phase>
+                        <goals>
+                            <goal>unpack-dependencies</goal>
+                        </goals>
+                        <configuration>
+                            <includeGroupIds>org.opendaylight.yangtools</includeGroupIds>
+                            <includes>**/*.class</includes>
+                            <outputDirectory>${project.build.directory}/classes</outputDirectory>
+                        </configuration>
                     </execution>
                 </executions>
             </plugin>
         </plugins>
     </build>
-
 </project>
index 99ad946f5b205b682446d10a044e8e75e5e8acef..1ddbe3e8551c54a08382501870f3282d78b8ad7c 100644 (file)
@@ -25,9 +25,36 @@ import java.util.Optional;
 import java.util.Properties;
 import org.apache.maven.it.VerificationException;
 import org.apache.maven.it.Verifier;
+import org.junit.BeforeClass;
 import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class YangToSourcesPluginTestIT {
+    private static final Logger LOG = LoggerFactory.getLogger(YangToSourcesPluginTestIT.class);
+    private static final String MAVEN_OPTS = "MAVEN_OPTS";
+    private static final String DESTFILE = "destfile=";
+
+    private static String ARGLINE_PREFIX;
+    private static String ARGLINE_SUFFIX;
+
+    @BeforeClass
+    public static void beforeClass() {
+        final String argLine = System.getProperty("itArgPath");
+        if (argLine == null || argLine.isBlank()) {
+            return;
+        }
+
+        final int destFileIndex = argLine.indexOf(DESTFILE);
+        if (destFileIndex == -1) {
+            LOG.warn("Cannot find \"{} in \"{}\", disabling integration", DESTFILE, argLine);
+            return;
+        }
+
+        ARGLINE_PREFIX = argLine.substring(0, destFileIndex + DESTFILE.length());
+        final int commaIndex = argLine.indexOf(',', ARGLINE_PREFIX.length());
+        ARGLINE_SUFFIX = commaIndex == -1 ? "" : argLine.substring(commaIndex);
+    }
 
     // TODO Test yang files in transitive dependencies
 
@@ -111,17 +138,29 @@ public class YangToSourcesPluginTestIT {
     static Verifier setUp(final String project, final boolean ignoreF)
             throws VerificationException, URISyntaxException, IOException {
         final URL path = YangToSourcesPluginTestIT.class.getResource("/" + project + "pom.xml");
-        final Verifier verifier = new Verifier(new File(path.toURI()).getParent());
+        final File parent = new File(path.toURI()).getParentFile();
+        final Verifier verifier = new Verifier(parent.toString());
         if (ignoreF) {
             verifier.addCliOption("-fn");
         }
 
-        final Optional<String> maybeSettings = getEffectiveSettingsXML();
-        if (maybeSettings.isPresent()) {
+        getEffectiveSettingsXML().ifPresent(settings -> {
             verifier.addCliOption("-gs");
-            verifier.addCliOption(maybeSettings.get());
-        }
+            verifier.addCliOption(settings);
+        });
+
+        verifier.setForkJvm(true);
         verifier.setMavenDebug(true);
+
+        if (ARGLINE_PREFIX != null) {
+            final String argLine =
+                ARGLINE_PREFIX + parent.getParent() + "/" + parent.getName() + ".exec" + ARGLINE_SUFFIX;
+            final String mavenOpts = System.getenv(MAVEN_OPTS);
+            final String newMavenOpts = mavenOpts == null ? argLine : mavenOpts + " " + argLine;
+            LOG.debug("Adjusted {} to \"{}\"", MAVEN_OPTS, newMavenOpts);
+            verifier.setEnvironmentVariable(MAVEN_OPTS, newMavenOpts);
+        }
+
         verifier.executeGoal("generate-sources");
         return verifier;
     }