Uploaded image for project: 'Clover'
  1. Clover
  2. CLOV-1471

Maven clover2:setup triggers duplicate class exception

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Medium Medium
    • 3.3.1, 4.0.0
    • None
    • Maven plugin
    • None

      We have several maven projects that have more than one source directory. The non-default directories are added using the build-helper plugin. The clover2:setup goal instruments all source folders, but then sets all non-generated directories as source folders on the maven project. That results in compile errors, since source files are both present in the clover instrumented sources and original location.

      Example:
      java/src << 1. default source folder
      java/src-build << 2. additional source folder
      target/generate-sources/jaxb << 3. generated source folder

      Case (2) is causing problems.

            [CLOV-1471] Maven clover2:setup triggers duplicate class exception

            Aditya Parikh added a comment - - edited

            Hey Mark,

            Yes it does work in initialize phase as follows:

            <execution>
                                    <phase>initialize</phase>
                                    <goals>
                                        <goal>instrument-test</goal>
                                        <goal>check</goal>
                                        <goal>clover</goal>
                                    </goals>
                                </execution>
            
            

            Thanks

            Aditya Parikh added a comment - - edited Hey Mark, Yes it does work in initialize phase as follows: <execution> <phase> initialize </phase> <goals> <goal> instrument-test </goal> <goal> check </goal> <goal> clover </goal> </goals> </execution> Thanks

            Hi Aditya,

            I think that this is caused by a fact that you're using the clover2:instrument instead of the clover2:setup goal. The clover2:instrument forks a custom build life cycle and in this build cycle it performs instrumentation in the 'validate' phase. Due to a fact that your 'add-source' goal is bound to the generate-sources phase, the build-helper-maven-plugin runs after Clover instead of before.

            I suggest to use clover2:setup bounded to the validate or initialize phase (i.e. before the generate-sources one).

            Cheers
            Marek

            Marek Parfianowicz added a comment - Hi Aditya, I think that this is caused by a fact that you're using the clover2:instrument instead of the clover2:setup goal. The clover2:instrument forks a custom build life cycle and in this build cycle it performs instrumentation in the 'validate' phase. Due to a fact that your 'add-source' goal is bound to the generate-sources phase, the build-helper-maven-plugin runs after Clover instead of before. I suggest to use clover2:setup bounded to the validate or initialize phase (i.e. before the generate-sources one). Cheers Marek

            Aditya Parikh added a comment - - edited

            I am facing similar issue for maven-clover2-plugin version 4.0.0. Here's how we are using the build-helper-maven-plugin

            <plugin>
                            <groupId>org.codehaus.mojo</groupId>
                            <artifactId>build-helper-maven-plugin</artifactId>
                            <version>1.9.1</version>
                            <executions>
                                <execution>
                                    <id>add-shared-source</id>
                                    <phase>generate-sources</phase>
                                    <goals>
                                        <goal>add-source</goal>
                                    </goals>
                                    <configuration>
                                        <sources>
                                            <source>../SomeOtherModule1/src/main/java/com</source>
                                            <source>../SomeOtherModule2/src/main/java/com</source>
                                            <source>../SomeOtherModule3/src/main/java/com</source>
                                        </sources>
                                    </configuration>
                                </execution>
                            </executions>
                        </plugin>
            

            and this is how we are using the clover2 plugin in a build profile:

                                <plugin>
                                    <groupId>com.atlassian.maven.plugins</groupId>
                                    <artifactId>maven-clover2-plugin</artifactId>
                                    <version>4.0.0</version>
                                    <configuration combine.self="override">
                                        <targetPercentage>${code_coverage_target}</targetPercentage>
                                        <licenseLocation>${clover_license_location}</licenseLocation>
                                    </configuration>
                                    <executions>
                                        <execution>
                                            <phase>verify</phase>
                                            <goals>
                                                <goal>instrument-test</goal>
                                                <goal>check</goal>
                                                <goal>clover</goal>
                                            </goals>
                                        </execution>
                                    </executions>
                                </plugin>
            

            without the clover plugin, the build compiles fine. but after adding the clover plugin, we get several errors saying duplicate classes found.

            Am I missing something here ?

            Aditya Parikh added a comment - - edited I am facing similar issue for maven-clover2-plugin version 4.0.0. Here's how we are using the build-helper-maven-plugin <plugin> <groupId> org.codehaus.mojo </groupId> <artifactId> build-helper-maven-plugin </artifactId> <version> 1.9.1 </version> <executions> <execution> <id> add-shared-source </id> <phase> generate-sources </phase> <goals> <goal> add-source </goal> </goals> <configuration> <sources> <source> ../SomeOtherModule1/src/main/java/com </source> <source> ../SomeOtherModule2/src/main/java/com </source> <source> ../SomeOtherModule3/src/main/java/com </source> </sources> </configuration> </execution> </executions> </plugin> and this is how we are using the clover2 plugin in a build profile: <plugin> <groupId> com.atlassian.maven.plugins </groupId> <artifactId> maven-clover2-plugin </artifactId> <version> 4.0.0 </version> <configuration combine.self= "override" > <targetPercentage> ${code_coverage_target} </targetPercentage> <licenseLocation> ${clover_license_location} </licenseLocation> </configuration> <executions> <execution> <phase> verify </phase> <goals> <goal> instrument-test </goal> <goal> check </goal> <goal> clover </goal> </goals> </execution> </executions> </plugin> without the clover plugin, the build compiles fine. but after adding the clover plugin, we get several errors saying duplicate classes found. Am I missing something here ?

            Hi bbusjaeger, I intend to release Clover 4.0.1 at the end of next week, so in case I would have to code some fixes for this bug, I need to get a feedback from you on the Tuesday (26.08) the latest. I'd be very grateful if you could have a look at my questions posted in previous comments. Cheers!

            Marek Parfianowicz added a comment - Hi bbusjaeger , I intend to release Clover 4.0.1 at the end of next week, so in case I would have to code some fixes for this bug, I need to get a feedback from you on the Tuesday (26.08) the latest. I'd be very grateful if you could have a look at my questions posted in previous comments. Cheers!

            One more thing: can you tell whether you're using a parallel compilation in Maven?

            I'm asking because Clover does not support parallel builds - it fails when multiple processes are trying to write to the same clover.db file at the same time.

            Marek Parfianowicz added a comment - One more thing: can you tell whether you're using a parallel compilation in Maven? I'm asking because Clover does not support parallel builds - it fails when multiple processes are trying to write to the same clover.db file at the same time.

            In case running 'mvn -X' will not reveal more details, then I suggest running the CloverInstr tool manually on your sources generated by Avro. Thanks to this we will check whether there is a problem with running an instrumentation (for instance, some code construct which Clover cannot correctly parse). In case it succeeds, then we'll know that it's a problem with the maven-clover2-plugin.

            How to use CloverInstr:

            https://confluence.atlassian.com/display/CLOVER/CloverInstr

            Marek Parfianowicz added a comment - In case running 'mvn -X' will not reveal more details, then I suggest running the CloverInstr tool manually on your sources generated by Avro. Thanks to this we will check whether there is a problem with running an instrumentation (for instance, some code construct which Clover cannot correctly parse). In case it succeeds, then we'll know that it's a problem with the maven-clover2-plugin. How to use CloverInstr: https://confluence.atlassian.com/display/CLOVER/CloverInstr

            Regarding the stack trace:

            Caused by: org.apache.maven.plugin.MojoExecutionException: Clover has failed to instrument the source files in the [/home/bbusjaeger/dev/app/main/core/apex-lang/target/clover/src-instrumented] directory
            at com.atlassian.maven.plugin.clover.internal.instrumentation.AbstractInstrumenter.instrumentSources(AbstractInstrumenter.java:198)
            

            This is caused by a non-zero return code from CloverInstr:

            // from maven-clover2-plugin code:
            
            int result = CloverInstr.mainImpl(createCliArgs(filesToInstrument, outputDir));
                    if (result != 0) {
                        throw new MojoExecutionException("Clover has failed to instrument the source files "
                                + "in the [" + outputDir + "] directory");
                    }
            

            Could you please run your build with a debug logging (mvn -X) and check if there are more log messages? I expect to see one of these:

              *** ERROR: <error message>
              USAGE: com.atlassian.clover.CloverInstr [OPTIONS] PARAMS [FILES...]
            
             ... more lines with command line options ...
            

            This can indicate an error in passing arguments between the clover2:instrument/clover2:setup and the CloverInstr program.

            Could not initialise Clover: <error message>
            

            Problem with running instrumentation. There may be various reasons, for example "Unable to create or load clover registry located at: ...".

            Invalid or missing License. Please visit .... to obtain a valid license.
            

            Problem with a license. Rather unlikely as you're successfully instrumenting other files.

            Marek Parfianowicz added a comment - Regarding the stack trace: Caused by: org.apache.maven.plugin.MojoExecutionException: Clover has failed to instrument the source files in the [/home/bbusjaeger/dev/app/main/core/apex-lang/target/clover/src-instrumented] directory at com.atlassian.maven.plugin.clover.internal.instrumentation.AbstractInstrumenter.instrumentSources(AbstractInstrumenter.java:198) This is caused by a non-zero return code from CloverInstr: // from maven-clover2-plugin code: int result = CloverInstr.mainImpl(createCliArgs(filesToInstrument, outputDir)); if (result != 0) { throw new MojoExecutionException( "Clover has failed to instrument the source files " + "in the [" + outputDir + "] directory" ); } Could you please run your build with a debug logging (mvn -X) and check if there are more log messages? I expect to see one of these: *** ERROR: <error message> USAGE: com.atlassian.clover.CloverInstr [OPTIONS] PARAMS [FILES...] ... more lines with command line options ... This can indicate an error in passing arguments between the clover2:instrument/clover2:setup and the CloverInstr program. Could not initialise Clover: <error message> Problem with running instrumentation. There may be various reasons, for example "Unable to create or load clover registry located at: ...". Invalid or missing License. Please visit .... to obtain a valid license. Problem with a license. Rather unlikely as you're successfully instrumenting other files.

            Yes.

            Yes.

            The exception trace is pasted above. I can send a build log, but it didn't have more information. I am happy to run with an instrumented version that reports why "Clover has failed to instrument the source files".

            Benjamin Busjaeger added a comment - Yes. Yes. The exception trace is pasted above. I can send a build log, but it didn't have more information. I am happy to run with an instrumented version that reports why "Clover has failed to instrument the source files".

            We're using excludes + copyExcludedFiles to work-around the issue,

            You have copyExcludedFiles=false, am I correct?

            but it's quite brittle, as devs have to update the excludes whenever they add files in the source folder

            Does it mean that it's impossible to define (general enough) exclusion pattern?

            Anyone looking at the 'Clover has failed to instrument the source files' error in 4.0.0?

            Please have a look at my previous comments. I'd love to investigate it further but I haven't received any POMs or build logs for analysis. So at the moment I assume/guess that it's a problem with order in which goals are called.

            Marek Parfianowicz added a comment - We're using excludes + copyExcludedFiles to work-around the issue, You have copyExcludedFiles=false, am I correct? but it's quite brittle, as devs have to update the excludes whenever they add files in the source folder Does it mean that it's impossible to define (general enough) exclusion pattern? Anyone looking at the 'Clover has failed to instrument the source files' error in 4.0.0? Please have a look at my previous comments. I'd love to investigate it further but I haven't received any POMs or build logs for analysis. So at the moment I assume/guess that it's a problem with order in which goals are called.

            We're using excludes + copyExcludedFiles to work-around the issue, but it's quite brittle, as devs have to update the excludes whenever they add files in the source folder.

            Anyone looking at the 'Clover has failed to instrument the source files' error in 4.0.0?

            Benjamin Busjaeger added a comment - We're using excludes + copyExcludedFiles to work-around the issue, but it's quite brittle, as devs have to update the excludes whenever they add files in the source folder. Anyone looking at the 'Clover has failed to instrument the source files' error in 4.0.0?

              mparfianowicz Marek Parfianowicz
              62751354167d Benjamin Busjaeger
              Affected customers:
              0 This affects my team
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: