siom79 / japicmp

Comparison of two versions of a jar archive
https://siom79.github.io/japicmp
Apache License 2.0
701 stars 107 forks source link

Run report with different configurations #320

Open davidnewcomb opened 2 years ago

davidnewcomb commented 2 years ago

I have written a groovy script that reduces all the changes down to only report changes across our 'special' annotations given our rules. This is all working. A new requirement has come in to split the report into three: one for the public interfaces, one for the internal interfaces and the original one with everything. These 3 reports will go to different teams.

In the groovy script I have this at the top:

REPORT_PUBLIC = true
REPORT_SEMI = true

I am wondering what options are available to help? The simplest solution would be to make 3 copies of the groovy script one with true/true, one with true/false and one with false/true. Then have 3 separate maven plugin declarations each with a different html-path so they don't overwrite each other.

The docs mentions you can have extra executions so the output base name is based on the execution id, so can I pass parameters into the main script from the execution block to get my 3 different reports.

Or maybe trying to pass -Dblar=semi then read it with System.getenv() inside the script.

I'm just looking for a bit of advice on a cleaner way of doing this?

davidnewcomb commented 2 years ago

I have tried it with 3 different plugin blocks, referencing the 3 copies of the script (with different params hardcoded). I have added to the executions block and that prevents the report output names from clashing within the same target folder. I still have a lot of duplication here that I'd like to clean up if possible.

siom79 commented 2 years ago

You can define different executions with different ids:

<plugin>
        <groupId>com.github.siom79.japicmp</groupId>
        <artifactId>japicmp-maven-plugin</artifactId>
        <version>0.15.6</version>
        <configuration>
          <oldVersion>
            <file>
              <path>${project.build.directory}/${project.artifactId}-${project.version}.${project.packaging}</path>
            </file>
          </oldVersion>
          <newVersion>
            <file>
              <path>${project.build.directory}/${project.artifactId}-${project.version}.${project.packaging}</path>
            </file>
          </newVersion>
          <parameter>
            <!-- see documentation -->
          </parameter>
        </configuration>
        <executions>
          <execution>
            <id>conf1</id>
            <phase>verify</phase>
            <goals>
              <goal>cmp</goal>
            </goals>
            <configuration>
              <postAnalysisScript>${project.basedir}/src/main/groovy/postAnalysisScript.groovy</postAnalysisScript>
            </configuration>
          </execution>
          <execution>
            <id>conf2</id>
            <phase>verify</phase>
            <goals>
              <goal>cmp</goal>
            </goals>
            <configuration>
              <postAnalysisScript>${project.basedir}/src/main/groovy/postAnalysisScript.groovy</postAnalysisScript>
            </configuration>
          </execution>
        </executions>
      </plugin>

In this example I get two different files:

[INFO] --- japicmp-maven-plugin:0.15.6:cmp (conf1) @ test ---
[INFO] Written file '/home/boxuser/dev/kvletl/test/target/japicmp/conf1.diff'.
[INFO] Written file '/home/boxuser/dev/kvletl/test/target/japicmp/conf1.xml'.
[INFO] Written file '/home/boxuser/dev/kvletl/test/target/japicmp/conf1.html'.
[INFO] 
[INFO] --- japicmp-maven-plugin:0.15.6:cmp (conf2) @ test ---
[INFO] Written file '/home/boxuser/dev/kvletl/test/target/japicmp/conf2.diff'.
[INFO] Written file '/home/boxuser/dev/kvletl/test/target/japicmp/conf2.xml'.
[INFO] Written file '/home/boxuser/dev/kvletl/test/target/japicmp/conf2.html'.
davidnewcomb commented 2 years ago

Yes, that kind of thing! That solves half the problem.

If there was something like the following which added "myparam" to the environment or something that would be perfect. I'm just thinking allowed here. Are there any facilities like this?

<configuration>
     <postAnalysisScript>${project.basedir}/src/main/groovy/postAnalysisScript.groovy</postAnalysisScript>
     <postAnalysisScriptParameters>
          <postAnalysisScriptParameter>myparam=semi<postAnalysisScriptParameter>
     </postAnalysisScriptParameters>
</configuration>
davidnewcomb commented 2 years ago

Just for anyone following, those parameters are contained within configuration->parameter block. Like so:

<configuration>
   <parameter>
      <postAnalysisScript>${project.basedir}/src/main/groovy/postAnalysisScript.groovy</postAnalysisScript>
   </parameter>
</configuration>