aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-squid-java-plugin/src
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2011-04-08 09:13:10 +0200
committersimonbrandhof <simon.brandhof@gmail.com>2011-04-08 09:13:10 +0200
commit7d231a67761c8c5637435d21a7e24364bb00fbe1 (patch)
tree707248a373f86ab868165cd1432eb5bd0f857e86 /plugins/sonar-squid-java-plugin/src
parentaa5de1d8e7f8f6d68f9be98ad9536e4f6db88b6f (diff)
downloadsonarqube-7d231a67761c8c5637435d21a7e24364bb00fbe1.tar.gz
sonarqube-7d231a67761c8c5637435d21a7e24364bb00fbe1.zip
SONAR-2322 Filter unit tests files listed in surefire reports
Diffstat (limited to 'plugins/sonar-squid-java-plugin/src')
-rw-r--r--plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/JavaSourceImporter.java41
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/JavaSourceImporterTest.java9
2 files changed, 25 insertions, 25 deletions
diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/JavaSourceImporter.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/JavaSourceImporter.java
index 9627ba5f9f5..e8c0cf381e3 100644
--- a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/JavaSourceImporter.java
+++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/JavaSourceImporter.java
@@ -19,9 +19,13 @@
*/
package org.sonar.plugins.squid;
+import org.apache.commons.configuration.Configuration;
import org.apache.commons.io.FileUtils;
import org.sonar.api.CoreProperties;
-import org.sonar.api.batch.*;
+import org.sonar.api.batch.DependedUpon;
+import org.sonar.api.batch.Phase;
+import org.sonar.api.batch.Sensor;
+import org.sonar.api.batch.SensorContext;
import org.sonar.api.resources.*;
import org.sonar.api.utils.SonarException;
import org.sonar.java.api.JavaUtils;
@@ -31,15 +35,25 @@ import java.nio.charset.Charset;
import java.util.List;
@Phase(name = Phase.Name.PRE)
-@DependsUpon(classes = SquidSensor.class)
-@DependedUpon(JavaUtils.BARRIER_AFTER_SQUID)
+@DependedUpon(JavaUtils.BARRIER_BEFORE_SQUID)
public final class JavaSourceImporter implements Sensor {
+ private boolean importSources = false;
+
+ public JavaSourceImporter(Configuration conf) {
+ this.importSources = conf.getBoolean(CoreProperties.CORE_IMPORT_SOURCES_PROPERTY,
+ CoreProperties.CORE_IMPORT_SOURCES_DEFAULT_VALUE);
+ }
+
+ JavaSourceImporter(boolean importSources) {
+ this.importSources = importSources;
+ }
+
/**
* {@inheritDoc}
*/
public boolean shouldExecuteOnProject(Project project) {
- return isEnabled(project) && Java.KEY.equals(project.getLanguageKey());
+ return Java.KEY.equals(project.getLanguageKey());
}
/**
@@ -63,14 +77,12 @@ public final class JavaSourceImporter implements Sensor {
void importSource(SensorContext context, JavaFile javaFile, InputFile inputFile, Charset sourcesEncoding) {
try {
- //if (!context.isIndexed(javaFile, true)) {
- // See http://jira.codehaus.org/browse/SONAR-791
- // Squid is the reference plugin to index files. If a file is not indexed,
- // throw new SonarException("Invalid file: " + javaFile + ". Please check that Java source directories match root directories" +
- // " as defined by packages.");
- //}
- String source = FileUtils.readFileToString(inputFile.getFile(), sourcesEncoding.name());
- context.saveSource(javaFile, source);
+ context.index(javaFile);
+
+ if (importSources) {
+ String source = FileUtils.readFileToString(inputFile.getFile(), sourcesEncoding.name());
+ context.saveSource(javaFile, source);
+ }
} catch (IOException e) {
throw new SonarException("Unable to read and import the source file : '" + inputFile.getFile().getAbsolutePath() + "' with the charset : '"
@@ -78,11 +90,6 @@ public final class JavaSourceImporter implements Sensor {
}
}
- boolean isEnabled(Project project) {
- return project.getConfiguration().getBoolean(CoreProperties.CORE_IMPORT_SOURCES_PROPERTY,
- CoreProperties.CORE_IMPORT_SOURCES_DEFAULT_VALUE);
- }
-
@Override
public String toString() {
return getClass().getSimpleName();
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/JavaSourceImporterTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/JavaSourceImporterTest.java
index ec98b96ee15..b6417ce7958 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/JavaSourceImporterTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/JavaSourceImporterTest.java
@@ -48,7 +48,7 @@ public class JavaSourceImporterTest {
when(inputFile.getRelativePath()).thenReturn("UndocumentedApi.java");
when(inputFile.getFile()).thenReturn(fileToImport);
when(inputFile.getFileBaseDir()).thenReturn(fileToImport.getParentFile());
- importer = new JavaSourceImporter();
+ importer = new JavaSourceImporter(true);
context = mock(SensorContext.class);
}
@@ -61,11 +61,4 @@ public class JavaSourceImporterTest {
verify(context).saveSource(eq(javaFile), anyString());
}
- @Test(expected = SonarException.class)
- @Ignore("see SONAR-791")
- public void shouldFailWhenSquidDidNotIndexFile() throws IOException {
- JavaFile javaFile = new JavaFile("Bar");
- when(context.isIndexed(javaFile, true)).thenReturn(false);
- importer.importSource(context, javaFile, inputFile, Charset.defaultCharset());
- }
} \ No newline at end of file