Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for #50 and #52 #53

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ private void saveMeasuresForFile(
final CoverageMeasuresBuilder measureBuilder, final String filePath) {
LoggerFactory.getLogger(getClass()).debug("Saving measures for {}",
filePath);
String absFilePath = new File(filePath).getAbsolutePath();
final org.sonar.api.resources.File objcfile = org.sonar.api.resources.File
.fromIOFile(new File(filePath), project);
.fromIOFile(new File(absFilePath), project);
if (fileExists(context, objcfile)) {
LoggerFactory.getLogger(getClass()).debug(
"File {} was found in the project.", filePath);
Expand All @@ -69,6 +70,9 @@ private void saveMeasures(final CoverageMeasuresBuilder measureBuilder,

private boolean fileExists(final SensorContext context,
final org.sonar.api.resources.File file) {
//It's not immediately clear why, but the file is never indexed in the context automatically.
//There's some debate about whether this behavior is changing in version 4.2, see SONAR-5006
context.index(file);
return context.getResource(file) != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,22 @@ public boolean shouldExecuteOnProject(Project project) {
}

public void analyse(Project project, SensorContext context) {
File dir = SurefireUtils.getReportsDirectory(project);
collect(project, context, dir);
/* 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.*/

String path = (String) project.getProperty("sonar.junit.reportsPath");
File pathFile = new File(path);
collect(project, context, new File(path));
}

protected void collect(Project project, SensorContext context, File reportsDir) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ private void recordViolation(final org.sonar.api.resources.File resource,
}

private boolean fileExists(final org.sonar.api.resources.File file) {
//It's not immediately clear why, but the file is never indexed in the context automatically.
//There's some debate about whether this behavior is changing in version 4.2, see SONAR-5006
context.index(file);
return context.getResource(file) != null;
}

Expand Down