aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-cpd-plugin
diff options
context:
space:
mode:
authorEric Hartmann <hartmann.eric@gmail.com>2012-03-05 11:54:14 +0100
committerEric Hartmann <hartmann.eric@gmail.com>2012-03-05 11:54:14 +0100
commit7c6222ae03569c5af98fdbe646edde3f52cd1674 (patch)
tree55ad97286c5c412ac2f9c2ea789e8387637a0dc3 /plugins/sonar-cpd-plugin
parent55def5196301144549383879c9e3e3752573155c (diff)
parent449823bb51378c333f4028d1ff015d5c50e973d9 (diff)
downloadsonarqube-7c6222ae03569c5af98fdbe646edde3f52cd1674.tar.gz
sonarqube-7c6222ae03569c5af98fdbe646edde3f52cd1674.zip
Merge branch 'release-2.14'
Diffstat (limited to 'plugins/sonar-cpd-plugin')
-rw-r--r--plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/SonarBridgeEngine.java20
-rw-r--r--plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/SonarBridgeEngineTest.java37
2 files changed, 56 insertions, 1 deletions
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 afdd56837d0..7aee8b8ed4a 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
@@ -19,6 +19,7 @@
*/
package org.sonar.plugins.cpd;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import org.sonar.api.batch.CpdMapping;
@@ -68,7 +69,7 @@ public class SonarBridgeEngine extends CpdEngine {
// Create index
SonarDuplicationsIndex index = indexFactory.create(project);
- TokenizerBridge bridge = new TokenizerBridge(mapping.getTokenizer(), fileSystem.getSourceCharset().name());
+ TokenizerBridge bridge = new TokenizerBridge(mapping.getTokenizer(), fileSystem.getSourceCharset().name(), getBlockSize(project));
for (InputFile inputFile : inputFiles) {
Resource resource = mapping.createResource(inputFile.getFile(), fileSystem.getSourceDirs());
String resourceId = SonarEngine.getFullKey(project, resource);
@@ -92,6 +93,23 @@ public class SonarBridgeEngine extends CpdEngine {
}
}
+ private static int getBlockSize(Project project) {
+ String languageKey = project.getLanguageKey();
+ return project.getConfiguration()
+ .getInt("sonar.cpd." + languageKey + ".minimumLines", getDefaultBlockSize(languageKey));
+ }
+
+ @VisibleForTesting
+ static int getDefaultBlockSize(String languageKey) {
+ if ("cobol".equals(languageKey)) {
+ return 30;
+ } else if ("abap".equals(languageKey) || "natur".equals(languageKey)) {
+ return 20;
+ } else {
+ return 10;
+ }
+ }
+
private CpdMapping getMapping(Language language) {
if (mappings != null) {
for (CpdMapping cpdMapping : mappings) {
diff --git a/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/SonarBridgeEngineTest.java b/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/SonarBridgeEngineTest.java
new file mode 100644
index 00000000000..e9ae76e300f
--- /dev/null
+++ b/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/SonarBridgeEngineTest.java
@@ -0,0 +1,37 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.plugins.cpd;
+
+import org.junit.Test;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+public class SonarBridgeEngineTest {
+
+ @Test
+ public void shouldReturnDefaultBlockSize() {
+ assertThat(SonarBridgeEngine.getDefaultBlockSize("cobol"), is(30));
+ assertThat(SonarBridgeEngine.getDefaultBlockSize("natur"), is(20));
+ assertThat(SonarBridgeEngine.getDefaultBlockSize("abap"), is(20));
+ assertThat(SonarBridgeEngine.getDefaultBlockSize("other"), is(10));
+ }
+
+}