Skip to content

Commit

Permalink
Fix issue #50 with SurefireAPI. Set a sensible default for the JUnit …
Browse files Browse the repository at this point in the history
…report path, avoiding one more parameter in sonar-project.properties
  • Loading branch information
cyrilpicat committed Feb 21, 2014
1 parent 0d857c8 commit 44bef0b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build-and-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if [ "$?" != 0 ]; then
fi

# Deploy new verion of plugin in Sonar dir
cp target/sonar-objective-c-plugin-0.3.1.jar $SONARQUBE_HOME/extensions/plugins
cp target/sonar-objective-c-plugin-0.3.2-SNAPSHOT.jar $SONARQUBE_HOME/extensions/plugins

# Stop/start Sonar
$SONARQUBE_HOME/bin/macosx-universal-64/sonar.sh stop
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<groupId>org.codehaus.sonar-plugin.objectivec</groupId>
<artifactId>sonar-objective-c-plugin</artifactId>
<version>0.3.1</version>
<version>0.3.2-SNAPSHOT</version>

<packaging>sonar-plugin</packaging>

Expand Down
4 changes: 2 additions & 2 deletions sample/sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ sonar.sourceEncoding=UTF-8

# JUnit report generated by run-sonar.sh is stored in sonar-reports/TEST-report.xml
# Change it only if you generate the file on your own
# The XML files have to be prefixed by TEST- otherwise it is not processed
sonar.junit.reportsPath=sonar-reports/
# The XML files have to be prefixed by TEST- otherwise they are not processed
# sonar.junit.reportsPath=sonar-reports/

# Cobertura report generated by run-sonar.sh is stored in sonar-reports/coverage.xml
# Change it only if you generate the file on your own
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,29 @@
import org.sonar.api.batch.DependsUpon;
import org.sonar.api.batch.Sensor;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.config.Settings;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Resource;
import org.sonar.plugins.objectivec.core.ObjectiveC;
import org.sonar.plugins.surefire.api.AbstractSurefireParser;
import org.sonar.plugins.surefire.api.SurefireUtils;

import java.io.File;

public class SurefireSensor implements Sensor {

private static final Logger LOG = LoggerFactory.getLogger(SurefireSensor.class);
public static final String REPORT_PATH_KEY = "sonar.junit.reportsPath";
public static final String DEFAULT_REPORT_PATH = "sonar-reports/";
private final Settings conf;

public SurefireSensor() {
this(null);
}

public SurefireSensor(final Settings config) {
conf = config;
}

@DependsUpon
public Class<?> dependsUponCoverageSensors() {
Expand All @@ -49,8 +60,24 @@ public boolean shouldExecuteOnProject(Project project) {
}

public void analyse(Project project, SensorContext context) {
File dir = SurefireUtils.getReportsDirectory(project);
collect(project, context, dir);

/*
GitHub Issue #50
Formerly we used SurefireUtils.getReportsDirectory(project). It seems that is this one:
http://grepcode.com/file/repo1.maven.org/maven2/org.codehaus.sonar.plugins/sonar-surefire-plugin/3.3.2/org/sonar/plugins/surefire/api/SurefireUtils.java?av=f#34
However it turns out that the Java plugin contains its own version of SurefireUtils
that is very different (and does not contain a matching method).
That seems to be this one: http://svn.codehaus.org/sonar-plugins/tags/sonar-groovy-plugin-0.5/src/main/java/org/sonar/plugins/groovy/surefire/SurefireSensor.java
The result is as follows:
1. At runtime getReportsDirectory(project) fails if you have the Java plugin installed
2. At build time the new getReportsDirectory(project,settings) because I guess something in the build chain doesn't know about the Java plugin version
So the implementation here reaches into the project properties and pulls the path out by itself.
*/

collect(project, context, new File(reportPath()));
}

protected void collect(Project project, SensorContext context, File reportsDir) {
Expand All @@ -73,4 +100,12 @@ public String toString() {
return "Objective-C SurefireSensor";
}

private String reportPath() {
String reportPath = conf.getString(REPORT_PATH_KEY);
if (reportPath == null) {
reportPath = DEFAULT_REPORT_PATH;
}
return reportPath;
}

}

0 comments on commit 44bef0b

Please sign in to comment.