// 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);
}
}
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;
@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;
}
*/
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;
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;
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
@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;
}
@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);
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");
*/
boolean CPD_CROSS_RPOJECT_DEFAULT_VALUE = false;
+ /**
+ * @since 3.5
+ */
+ String CPD_EXCLUSIONS = "sonar.cpd.exclusions";
+
/* Design */
/**