From ec68e769aef8675eb3f5a748d853741461c5d9c6 Mon Sep 17 00:00:00 2001 From: Drew Crawford Date: Sat, 1 Feb 2014 22:54:54 -0600 Subject: [PATCH 1/3] This fixes https://github.com/octo-technology/sonar-objective-c/issues/50. I'm not entirely convinced it's the right solution, but it works. --- .../objectivec/tests/SurefireSensor.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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) { From 803b8d6bb55544a2ef0ae311c10a3ad6c8d0b248 Mon Sep 17 00:00:00 2001 From: Drew Crawford Date: Sat, 1 Feb 2014 23:05:41 -0600 Subject: [PATCH 2/3] This fixes the OCLint portion of https://github.com/octo-technology/sonar-objective-c/issues/52 --- .../plugins/objectivec/violations/OCLintXMLStreamHandler.java | 3 +++ 1 file changed, 3 insertions(+) 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; } From 4705c7a50281ec23f0604eddf88c199c335eb420 Mon Sep 17 00:00:00 2001 From: Drew Crawford Date: Sun, 2 Feb 2014 00:36:58 -0600 Subject: [PATCH 3/3] This fixes the coverage part of https://github.com/octo-technology/sonar-objective-c/issues/52 --- .../objectivec/coverage/CoverageMeasuresPersistor.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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; } }