trautonen / coveralls-maven-plugin

Maven plugin for submitting Java code coverage reports to Coveralls web service.
MIT License
312 stars 123 forks source link

Source not found #57

Open lschuetze opened 9 years ago

lschuetze commented 9 years ago

I am trying to build http://github.com/dresden-ocl/dresdenocl repository. But if I run mvn cobertura:cobertura coveralls:report cobertura runs fine. But coveralls-maven-plugin reports a problem:

[ERROR] Failed to execute goal org.eluder.coveralls:coveralls-maven-plugin:3.0.1:report (default-cli) on project org.dresdenocl: I/O operation failed: No source found for testpackage/Class1_DefAspect_testSortedByIteratorExp01.aj -> [Help 1]

The file in question lies in /tests/org.dresdenocl.tools.codegen.ocl2java.test.aspectj/src/testpackage/constraints so I really ask me why it is not looking into testpackage/constraints/ but in testpackage/.

Tried adding the directory to sourceDirectory but this does not help.

As you can see it is a multi module setup. Maybe you see where the problem comes from.

lschuetze commented 9 years ago

I've run mvnDebug and remote debugged the build process. Appearently, the issue seems to come from cobertura which fails to save the path of the AspectJ files correctly.

The java classes that are weaved rely in the package testpackage while those aspects have the package testpackage.constraints. The package names reflect the physical folder structure.

Somehow, there are several entries in the cobertura.xml regarding the weaved aspect:

  1. <class name="testpackage.Class1$Class1_DefAspect_testSortedByIteratorExp01$1" filename="testpackage/Class1_DefAspect_testSortedByIteratorExp01.aj" line-rate="0.0" branch-rate="0.0" complexity="0.0">
  2. <class name="testpackage.constraints.Class1_DefAspect_testSortedByIteratorExp01" filename="testpackage/constraints/Class1_DefAspect_testSortedByIteratorExp01.aj" line-rate="0.0" branch-rate="0.0" complexity="0.0">

The second one is the right one. Using -XnoInline does not have the desired effect.

Extract from Class1_DefAspect_testSortedByIteratorExp01.aj

public privileged aspect Class1_DefAspect_testSortedByIteratorExp01 {
...
    public java.util.List<Integer> testpackage.Class1.testSortedByIteratorExp01() {
        ...
    }
}

Therefore, I don't see the issue with coveralls-maven-plugin anymore. However, cobertura-maven-plugin has approx. 1100 days on average to fix a reported bug. I don't see this being fixed soon.

trautonen commented 9 years ago

Nice that you found a workaround (saved me the trouble of debugging this). There's not much I can do on the report parsing side to fix such issues. I could add a feature that you can ignore some files in the report, but I think you can do the same in the coverage tools also, so it's not worth the effort to create feature duplication in two different tools.

viniciuspires commented 9 years ago

Tapio, looks like my build is failing because of a similar issue (see the end of the log: https://travis-ci.org/viniciuspires/reqlist/jobs/49405357). It says:

[ERROR] Failed to execute goal org.eluder.coveralls:coveralls-maven-plugin:3.0.1:report (default-cli) on project reqlist: I/O operation failed: No source found for org/reqlist/entity/view/AndamentoProjeto_.java -> [Help 1]

For my open-source project: https://github.com/viniciuspires/reqlist

Any ideas of why this is happening?

pdurbin commented 9 years ago

@viniciuspires I'm getting a similar error for https://github.com/pdurbin/addressbookmvc/tree/master/examples/javaee7 and I'm wondering how you got https://coveralls.io/github/viniciuspires/reqlist working. Like you, I'm seeing an error about a file with an underscore, which is strange because the underscore isn't in the original file name:

[ERROR] Failed to execute goal org.eluder.coveralls:coveralls-maven-plugin:3.0.1:report (default-cli) on project javaee7addressbook: I/O operation failed: No source found for com/greptilian/addressbookmvc/javaee7/Person_.java

Any tips on resolving this error?

viniciuspires commented 9 years ago

@pdurbin I don't remember exactly, but this classes are generated by the JPA to contain the related entity metadata, and the coveralls-maven-plugin was somehow trying to find its source, which doesn't exist. In my case, I think I somehow disabled this behaviour on JPA, and started to use only the entities I made.

Anyway, this serves as a workaround, I don't know how this should be solved, but I think that maybe there's a way to make coveralls-maven-plugin ignore generated classes, and don't fail because of that.

pdurbin commented 9 years ago

@viniciuspires nevermind! I fixed this by changing exclude-unlisted-classes from false to true in src/main/resources/META-INF/persistence.xml in https://github.com/pdurbin/addressbookmvc/commit/4e9f2ed72a80430ba34dd4f7d1229eb25f5bfe65

I just upvoted http://stackoverflow.com/questions/23326456/why-is-there-a-class-with-entity-name-plus-an-underscore-for-jpa-entity-class and added an answer.

trautonen commented 9 years ago

The problem is that this plugin cannot deal with any kind of code generation, because it requires the original source to be available. It is also questionable if you should run your coverage metrics based on generated code, which actually means you are testing a code generator, not your own code.

As a general solution, all generated code should be excluded from coverage tools. JaCoCo: http://www.eclemma.org/jacoco/trunk/doc/prepare-agent-mojo.html#excludes Cobertura (Instrumentation): http://www.mojohaus.org/cobertura-maven-plugin/usage.html

muzir commented 7 years ago

Be aware of there is no duplicate sourceDirectory in your pom build cycle. Because maven default source location is src/main below extra definiton in my pom.xml cause the same error as above.

I/O operation failed: No source found for

    <sourceDirectory>src/main</sourceDirectory>
    <testSourceDirectory>src/test</testSourceDirectory>
    <resources>
        <resource>
            <directory>src/resource</directory>
        </resource>
    </resources>

After I removed these lines my problem is solved.

You can check this link for good explanation

https://github.com/asciidoctor/asciidoctor/wiki/Coveralls.io-configuration-for-maven-projects

and my project too :)

https://github.com/muzir/azorka.api

trautonen commented 7 years ago

@muzir this is interesting. I'm not totally sure how maven's runtime source loading works, but the plugin basically uses MavenProject.getCompileSourceRoots() so it "should" see the same sources as maven itself.

Do you have a broken example where the source loading fails with a custom source directory?

The defaults are actually src/main/java, src/test/java and src/main/resources so if your source files (with package directories) are not straight under the defined directories, they are not found. But if they are, then it's worth checking why they are not found.

muzir commented 7 years ago

@trautonen please clone this repo and add below lines to pom.xml under build tag.

<sourceDirectory>src/main</sourceDirectory>
    <testSourceDirectory>src/test</testSourceDirectory>
    <resources>
        <resource>
            <directory>src/resource</directory>
        </resource>
    </resources>

Then you need to add <configuration><repoToken>yourToken</repoToken></configuration> for coveralls-maven-plugin and run this command mvn coveralls:report when I do this I get below exception

Failed to execute goal org.eluder.coveralls:coveralls-maven-plugin:4.3.0:report (default-cli) on project azorka.api: I/O operation failed: No source found for com/azorka/api/validation/ValidationService.java -> [Help 1]

alessandrolulli commented 7 years ago

Hello, i am encountering the same issue on a Scala project built with Maven and using Travis. Please find following my configuration in the pom.xml:

<plugin>
                <groupId>org.eluder.coveralls</groupId>
                <artifactId>coveralls-maven-plugin</artifactId>
                <version>4.3.0</version>
                <configuration>
                    <repoToken>${env.COVERALLS_TOKEN}</repoToken>
                    <sourceEncoding>UTF-8</sourceEncoding>
                </configuration>
            </plugin>
<plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.7.9</version>
                <executions>
                    <execution>
                        <id>prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

The .travis.yml

sudo: false
language: java
notifications:
  email:
    on_success: change 
    on_failure: always
script:
    - mvn test jacoco:report
after_success:
    - mvn coveralls:report

Could you please help me?

alessandrolulli commented 7 years ago

Hi, i solved the issue adding the source directory to the list of directories where coveralls searches the sources. I do not understand why coveralls plugin is not looking in the default source directory.

However, find below my working configurations:

<plugin>
                <groupId>org.eluder.coveralls</groupId>
                <artifactId>coveralls-maven-plugin</artifactId>
                <version>4.3.0</version>
                <configuration>
                    <repoToken>${env.COVERALLS_TOKEN}</repoToken>
                    <sourceEncoding>UTF-8</sourceEncoding>
                    <sourceDirectories>
                        <sourceDirectory>${basedir}/src/main/scala</sourceDirectory>
                    </sourceDirectories>
                </configuration>
            </plugin>
nfalco79 commented 6 years ago

me too here. Coveralls plugin goes in error on a source file of shaded third party jar (embedded as jar for OSGi).

[ERROR] Failed to execute goal org.eluder.coveralls:coveralls-maven-plugin:4.3.0:report (default-cli) on project junit4osgi-parent: I/O operation failed: No source found for org/codehaus/plexus/util/xml/XmlStreamReader.java -> [Help 1]

As workaround I limit jacoco to tracks only my packages to avoid instruct coveralls on third party code.

JSpiner commented 6 years ago

same here. https://github.com/JSpiner/SafeExecutor https://travis-ci.org/JSpiner/SafeExecutor/builds/380008003?utm_source=github_status&utm_medium=notification any tips to solve it??

JSpiner commented 6 years ago

I resolved it. My wrong package name occurs this error. https://github.com/JSpiner/SafeExecutor/commit/fd4fccb7a55a0954de64a5007075afc7d8718875

victorhsr commented 7 months ago

Hi, i solved the issue adding the source directory to the list of directories where coveralls searches the sources. I do not understand why coveralls plugin is not looking in the default source directory.

However, find below my working configurations:

<plugin>
                <groupId>org.eluder.coveralls</groupId>
                <artifactId>coveralls-maven-plugin</artifactId>
                <version>4.3.0</version>
                <configuration>
                    <repoToken>${env.COVERALLS_TOKEN}</repoToken>
                    <sourceEncoding>UTF-8</sourceEncoding>
                    <sourceDirectories>
                        <sourceDirectory>${basedir}/src/main/scala</sourceDirectory>
                    </sourceDirectories>
                </configuration>
            </plugin>

Yep that also worked for my kotlin project which uses maven:

<plugin>
  <groupId>com.github.hazendaz.maven</groupId>
  <artifactId>coveralls-maven-plugin</artifactId>
  <version>4.5.0-M2</version>
  <configuration>
      <scanForSources>true</scanForSources>
      <sourceDirectories>
          <sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
          <sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
      </sourceDirectories>
  </configuration>
</plugin>