diff --git a/src/main/java/org/sonar/plugins/objectivec/coverage/CoverageMeasuresPersistor.java b/src/main/java/org/sonar/plugins/objectivec/coverage/CoverageMeasuresPersistor.java index 70594815..eb59800d 100644 --- a/src/main/java/org/sonar/plugins/objectivec/coverage/CoverageMeasuresPersistor.java +++ b/src/main/java/org/sonar/plugins/objectivec/coverage/CoverageMeasuresPersistor.java @@ -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); @@ -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; } } diff --git a/src/main/java/org/sonar/plugins/objectivec/tests/SurefireSensor.java b/src/main/java/org/sonar/plugins/objectivec/tests/SurefireSensor.java index 765c61fc..95bdc78d 100644 --- a/src/main/java/org/sonar/plugins/objectivec/tests/SurefireSensor.java +++ b/src/main/java/org/sonar/plugins/objectivec/tests/SurefireSensor.java @@ -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) { diff --git a/src/main/java/org/sonar/plugins/objectivec/violations/OCLintXMLStreamHandler.java b/src/main/java/org/sonar/plugins/objectivec/violations/OCLintXMLStreamHandler.java index 0847046b..82123275 100644 --- a/src/main/java/org/sonar/plugins/objectivec/violations/OCLintXMLStreamHandler.java +++ b/src/main/java/org/sonar/plugins/objectivec/violations/OCLintXMLStreamHandler.java @@ -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; }