Skip to content

Commit

Permalink
Merge pull request #1 from TimSoethout/update-to-sonar4
Browse files Browse the repository at this point in the history
Added extra option to set custom report path for cobertura coverage f…
  • Loading branch information
johanneszink committed Oct 5, 2015
2 parents 9e91098 + 1237f44 commit 9b38c2e
Showing 1 changed file with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
*/
package org.sonar.plugins.scala.cobertura;

import java.io.File;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.CoverageExtension;
Expand All @@ -32,10 +30,13 @@
import org.sonar.api.scan.filesystem.PathResolver;
import org.sonar.plugins.scala.language.Scala;

import java.io.File;

public class CoberturaSensor implements Sensor, CoverageExtension {

private static final Logger LOG = LoggerFactory.getLogger(CoberturaSensor.class);

public static final String SCALA_COBERTURA_REPORTS_PATH_PROPERTY ="sonar.scala.cobertura.reportPath";
public static final String COBERTURA_REPORTS_PATH_PROPERTY ="sonar.cobertura.reportPath";
private FileSystem fileSystem;;
private PathResolver pathResolver;
Expand All @@ -58,19 +59,23 @@ public boolean shouldExecuteOnProject(Project project) {
}
}

public void analyse(Project project, SensorContext context) {
String path = settings.getString(COBERTURA_REPORTS_PATH_PROPERTY);
if (path == null){
LOG.warn("Cobertura report path property \"sonar.cobertura.reportPath\" not found!");
return;
}
File report = pathResolver.relativeFile(fileSystem.baseDir(), path);
if (!report.isFile()) {
LOG.warn("Cobertura report not found at {}", report);
return;
public void analyse(Project project, SensorContext context) {
String path = settings.getString(SCALA_COBERTURA_REPORTS_PATH_PROPERTY);
if (path == null) {
LOG.warn("Cobertura report path property \"sonar.scala.cobertura.reportPath\" not found!");
path = settings.getString(COBERTURA_REPORTS_PATH_PROPERTY);
}
if (path == null) {
LOG.warn("Cobertura report path property \"sonar.cobertura.reportPath\" not found!");
return;
}
File report = pathResolver.relativeFile(fileSystem.baseDir(), path);
if (!report.isFile()) {
LOG.warn("Cobertura report not found at {}", report);
return;
}
parseReport(report, context);
}
parseReport(report, context);
}

protected void parseReport(File xmlFile, SensorContext context) {
LOG.info("parsing {}", xmlFile);
Expand Down

0 comments on commit 9b38c2e

Please sign in to comment.