-
Notifications
You must be signed in to change notification settings - Fork 25
Maven plugin: generating relative paths in reports #88
Comments
+1 ... I believe this is my problem as well. The paths in the dat file that JSTD generate are the path to the file in the workspace and the paths in the dat file that Saga output is the URL at which it was found. My Sonar is reading the dat file properly but is reporting 0% coverage on all my files. Hopefully I'm not missing something here. JSTD:
Saga:
|
You're most welcome to take a stab at it. I'm currently working on #86, but I'm afraid that after that I will stop actively working on tickets since I just can't find the time these days. |
Should now generate paths relative to |
I can try and test it tomorrow. Will let you know. |
So I completely forgot to try this out. I will do so tomorrow at work. I've put it in my calendar. My apologies for the delay. |
So I did a quick test of this and I still don't believe it is quite right. It seems like you're building the path in the LCOV file based on the path relative to the specified baseDir and the URL at which the file is found. This means file located at Given the following project structure: project |- js |- some |- path |- to |- js |- file.js The URL path to this file through jasmine will be http://host:port/src/js/some/path/to/js/file.js However Sonar wants path/to/project/js/some/path/to/js/file.js I am unsure if project relative paths are accepted, e.g. js/some/path/to/js/file.js So if you could remove the |
Thanks for testing this, and sorry it took me so long to come back to you. The thing is, it's impossible for me to know the real filesystem path if the URL is not a file URL. I cannot assume that an HTTP URL points to a local server, so I have to either put the full or a relative URL, and if that doesn't resolve on the filesystem based on the CWD (or whatever Sonar is using to resolve it), then there's not much I can do, is there? Do you have any idea what directory Sonar uses as the base directory when trying to resolve those paths? |
I'm not sure about the gradle or cli but with maven couldn't you calculate the absolute file path like this? file.absolutePath = maven.project.baseDir + ( file.absoluteUrl - ( jasmine.url + "/src" ) ) for example: "/path/to/project/js/path/to/file.js" = "/path/to/project" + ( "http://localhost:8234/src/js/path/to/file.js" - ( "http://localhost:8234" + "/src" ) ) |
I was experiencing similar symptoms using Maven+Jasmine+Saga and trying to push to Sonar for analysis and display. We are using Sonar v.2.1.2 with Sonar Javascript Plugin 0.4-snapshot.
<!--Javascript testing plugins -->
<plugin>
<groupId>com.github.searls</groupId>
<artifactId>jasmine-maven-plugin</artifactId>
<version>1.3.1.2</version>
<executions>
<execution>
<goals>
<goal>test</goal>
</goals>
<configuration>
<keepServerAlive>true</keepServerAlive>
</configuration>
</execution>
</executions>
<configuration>
<keepServerAlive>true</keepServerAlive>
<jsSrcDir>${project.basedir}/web-app/js</jsSrcDir>
<jsTestSrcDir>${project.basedir}/test/javascript</jsTestSrcDir>
<preloadSources>
<source>${project.basedir}/web-app/js/lib/backbone.marionette/jquery.js</source>
<source>${project.basedir}/web-app/js/lib/backbone.marionette/underscore.js</source>
<source>${project.basedir}/web-app/js/lib/backbone.marionette/backbone.js</source>
<source>${project.basedir}/web-app/js/lib/backbone.marionette/backbone.marionette.js</source>
</preloadSources>
<sourceIncludes>
<include>application.js</include>
<include>models/build.model.js</include>
<include>**/*.js</include>
</sourceIncludes>
</configuration>
</plugin>
<plugin>
<groupId>com.github.timurstrekalov</groupId>
<artifactId>saga-maven-plugin</artifactId>
<version>1.4.1</version>
<executions>
<execution>
<goals>
<goal>coverage</goal>
</goals>
</execution>
</executions>
<configuration>
<baseDir>http://localhost:${jasmine.serverPort}</baseDir>
<outputDir>${project.build.directory}/coverage</outputDir>
<noInstrumentPatterns>
<pattern>.*/spec/.*</pattern>
<!-- Don't instrument specs -->
<pattern>.+/web-app\/js\/lib/.*</pattern>
<!-- Don't instrument libs -->
</noInstrumentPatterns>
</configuration>
</plugin>
<plugin>
<groupId>com.github.goldin</groupId>
<artifactId>copy-maven-plugin</artifactId>
<version>0.2.5</version>
<configuration> <!-- use copy:copy to run-->
<failIfNotFound>false</failIfNotFound>
<resource>
<targetPath>${project.build.directory}/jasmine</targetPath>
<file>${project.build.directory}/coverage/total-coverage.dat</file>
<destFileName>jsTestDriver.conf-coverage.dat</destFileName>
<replaces>
<replace>
<from>http.*src/</from>
<!-- Regex to replace localhost:port -->
<to>${project.basedir}/web-app/js/</to>
<!-- Replacement String to my JS src files -->
</replace>
</replaces>
</resource>
</configuration>
</plugin>
<!--End of Javascript testing plugins --> .... <profile>
<id>sonar-js</id>
<properties>
<sonar.language>js</sonar.language>
<sonar.branch>javascript</sonar.branch>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.javascript.jstestdriver.reportsfolder>target/jasmine</sonar.javascript.jstestdriver.reportsfolder>
<sonar.javascript.lslint.predef>Backbone,console,JQuery</sonar.javascript.lslint.predef>
</properties>
</profile>
Done. Postmortem: There were several issues I had to overcome.
Hope this helps someone. |
AFAIK, Sonar requires relative paths in the report for calculating the coverage (see #58). So I think it would be nice if the Saga Maven plugin would somehow enable relative paths in the report.
For now, I am using an ANT task in my Maven POM that transforms absolute paths into relative paths. Not very nice but it does the trick with Sonar.
The text was updated successfully, but these errors were encountered: