summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorFabrice Bellingard <fabrice.bellingard@sonarsource.com>2013-02-15 13:51:23 +0100
committerFabrice Bellingard <fabrice.bellingard@sonarsource.com>2013-02-15 13:52:12 +0100
commit05c796bc1a858973103f038c9678583afa37aaea (patch)
treea5fa9fed0eda172eaf5020c2275ef59ff8a9a724 /plugins
parentb50c37b61c63eb5e25787f779d261989adf96de5 (diff)
downloadsonarqube-05c796bc1a858973103f038c9678583afa37aaea.tar.gz
sonarqube-05c796bc1a858973103f038c9678583afa37aaea.zip
SONAR-3108 Add new property to exclude files from duplication detection
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdPlugin.java24
-rw-r--r--plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/SonarBridgeEngine.java4
-rw-r--r--plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/SonarEngine.java14
-rw-r--r--plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/CpdSensorTest.java2
-rw-r--r--plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/SonarEngineTest.java2
5 files changed, 32 insertions, 14 deletions
diff --git a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdPlugin.java b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdPlugin.java
index 81ac5d09f36..c6f59261437 100644
--- a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdPlugin.java
+++ b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdPlugin.java
@@ -50,18 +50,28 @@ import java.util.List;
// not displayed in UI
project = false, module = false, global = false,
category = CoreProperties.CATEGORY_DUPLICATIONS,
- type = PropertyType.BOOLEAN)
+ type = PropertyType.BOOLEAN),
+ @Property(
+ key = CoreProperties.CPD_EXCLUSIONS,
+ defaultValue = "",
+ name = "Duplication exclusions",
+ description = "Patterns used to exclude some source files from the duplication detection mechanism.",
+ project = true,
+ module = true,
+ global = true,
+ category = CoreProperties.CATEGORY_DUPLICATIONS,
+ multiValues = true)
})
public final class CpdPlugin extends SonarPlugin {
public List getExtensions() {
return ImmutableList.of(
- CpdSensor.class,
- SumDuplicationsDecorator.class,
- DuplicationDensityDecorator.class,
- IndexFactory.class,
- SonarEngine.class,
- SonarBridgeEngine.class);
+ CpdSensor.class,
+ SumDuplicationsDecorator.class,
+ DuplicationDensityDecorator.class,
+ IndexFactory.class,
+ SonarEngine.class,
+ SonarBridgeEngine.class);
}
}
diff --git a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/SonarBridgeEngine.java b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/SonarBridgeEngine.java
index d62fd253ef2..0b05e83f4ad 100644
--- a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/SonarBridgeEngine.java
+++ b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/SonarBridgeEngine.java
@@ -31,6 +31,7 @@ import org.sonar.api.config.Settings;
import org.sonar.api.resources.Language;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
+import org.sonar.api.scan.filesystem.FileQuery;
import org.sonar.api.scan.filesystem.ModuleFileSystem;
import org.sonar.api.utils.SonarException;
import org.sonar.duplications.DuplicationPredicates;
@@ -81,7 +82,8 @@ public class SonarBridgeEngine extends CpdEngine {
@Override
public void analyse(Project project, SensorContext context) {
- List<File> sourceFiles = fileSystem.sourceFilesOfLang(project.getLanguageKey());
+ String[] cpdExclusions = settings.getStringArray(CoreProperties.CPD_EXCLUSIONS);
+ List<File> sourceFiles = fileSystem.files(FileQuery.onSource().onLanguage(project.getLanguageKey()).withExclusions(cpdExclusions));
if (sourceFiles.isEmpty()) {
return;
}
diff --git a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/SonarEngine.java b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/SonarEngine.java
index a00c906e514..e9e4c589081 100644
--- a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/SonarEngine.java
+++ b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/SonarEngine.java
@@ -19,6 +19,10 @@
*/
package org.sonar.plugins.cpd;
+import org.sonar.api.CoreProperties;
+
+import org.sonar.api.config.Settings;
+
import com.google.common.collect.Iterables;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringEscapeUtils;
@@ -34,6 +38,7 @@ import org.sonar.api.resources.JavaFile;
import org.sonar.api.resources.Language;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
+import org.sonar.api.scan.filesystem.FileQuery;
import org.sonar.api.scan.filesystem.ModuleFileSystem;
import org.sonar.api.scan.filesystem.PathResolver;
import org.sonar.api.utils.SonarException;
@@ -81,15 +86,15 @@ public class SonarEngine extends CpdEngine {
private static final int TIMEOUT = 5 * 60;
private final IndexFactory indexFactory;
-
private final ModuleFileSystem fileSystem;
-
private final PathResolver pathResolver;
+ private final Settings settings;
- public SonarEngine(IndexFactory indexFactory, ModuleFileSystem moduleFileSystem, PathResolver pathResolver) {
+ public SonarEngine(IndexFactory indexFactory, ModuleFileSystem moduleFileSystem, PathResolver pathResolver, Settings settings) {
this.indexFactory = indexFactory;
this.fileSystem = moduleFileSystem;
this.pathResolver = pathResolver;
+ this.settings = settings;
}
@Override
@@ -107,7 +112,8 @@ public class SonarEngine extends CpdEngine {
@Override
public void analyse(Project project, SensorContext context) {
- List<File> sourceFiles = fileSystem.sourceFilesOfLang(project.getLanguageKey());
+ String[] cpdExclusions = settings.getStringArray(CoreProperties.CPD_EXCLUSIONS);
+ List<File> sourceFiles = fileSystem.files(FileQuery.onSource().onLanguage(project.getLanguageKey()).withExclusions(cpdExclusions));
if (sourceFiles.isEmpty()) {
return;
}
diff --git a/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/CpdSensorTest.java b/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/CpdSensorTest.java
index 8d2ab27bb3d..c04dacaa92e 100644
--- a/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/CpdSensorTest.java
+++ b/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/CpdSensorTest.java
@@ -42,7 +42,7 @@ public class CpdSensorTest {
@Before
public void setUp() {
IndexFactory indexFactory = mock(IndexFactory.class);
- sonarEngine = new SonarEngine(indexFactory, null, null);
+ sonarEngine = new SonarEngine(indexFactory, null, null, null);
sonarBridgeEngine = new SonarBridgeEngine(indexFactory, null, null);
settings = new Settings(new PropertyDefinitions(CpdPlugin.class));
sensor = new CpdSensor(sonarEngine, sonarBridgeEngine, settings);
diff --git a/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/SonarEngineTest.java b/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/SonarEngineTest.java
index e3a054324a4..fbb7a0b7d32 100644
--- a/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/SonarEngineTest.java
+++ b/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/SonarEngineTest.java
@@ -67,7 +67,7 @@ public class SonarEngineTest {
when(pathResolver.relativePath(anyCollection(), any(java.io.File.class))).thenReturn(relativePath);
when(relativePath.path()).thenReturn("com/foo/Bar.java");
- SonarEngine engine = new SonarEngine(null, fileSystem, pathResolver);
+ SonarEngine engine = new SonarEngine(null, fileSystem, pathResolver, null);
Resource<?> resource = engine.getResource(new java.io.File(""));
assertThat(resource.getKey()).isEqualTo("com.foo.Bar");