summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-03-02 13:56:16 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2012-03-02 13:56:16 +0100
commit2ec8150bf7b1f1808791b211e8cb99b6ea7a974f (patch)
tree6dd2054742ea63678ac99fe73eaa86e40ca3c000
parent82676715b14d656659e57ceca464f19843b1e689 (diff)
parentfccfe2fab5ff9c8c0886e05dd0c7f4c8aabb27c8 (diff)
downloadsonarqube-2ec8150bf7b1f1808791b211e8cb99b6ea7a974f.tar.gz
sonarqube-2ec8150bf7b1f1808791b211e8cb99b6ea7a974f.zip
Merge branch 'release-2.14' of github.com:SonarSource/sonar into release-2.14
-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
-rw-r--r--sonar-duplications/src/main/java/org/sonar/duplications/internal/pmd/TokenizerBridge.java6
-rw-r--r--sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/PmdBridgeTest.java2
-rw-r--r--sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/TokenizerBridgeTest.java2
5 files changed, 60 insertions, 7 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));
+ }
+
+}
diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/internal/pmd/TokenizerBridge.java b/sonar-duplications/src/main/java/org/sonar/duplications/internal/pmd/TokenizerBridge.java
index 57e84688d76..7881ee60cfd 100644
--- a/sonar-duplications/src/main/java/org/sonar/duplications/internal/pmd/TokenizerBridge.java
+++ b/sonar-duplications/src/main/java/org/sonar/duplications/internal/pmd/TokenizerBridge.java
@@ -37,16 +37,14 @@ import java.util.List;
*/
public class TokenizerBridge {
- private static final int BLOCK_SIZE = 10;
-
private final Tokenizer tokenizer;
private final String encoding;
private final PmdBlockChunker blockBuilder;
- public TokenizerBridge(Tokenizer tokenizer, String encoding) {
+ public TokenizerBridge(Tokenizer tokenizer, String encoding, int blockSize) {
this.tokenizer = tokenizer;
this.encoding = encoding;
- this.blockBuilder = new PmdBlockChunker(BLOCK_SIZE);
+ this.blockBuilder = new PmdBlockChunker(blockSize);
}
// TODO remove from here
diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/PmdBridgeTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/PmdBridgeTest.java
index 60c22a51f85..54210b9c237 100644
--- a/sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/PmdBridgeTest.java
+++ b/sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/PmdBridgeTest.java
@@ -44,7 +44,7 @@ public class PmdBridgeTest {
@Before
public void setUp() {
index = new PackedMemoryCloneIndex();
- bridge = new TokenizerBridge(new JavaTokenizer(), "UTF-8");
+ bridge = new TokenizerBridge(new JavaTokenizer(), "UTF-8", 10);
}
@Test
diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/TokenizerBridgeTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/TokenizerBridgeTest.java
index ec2bd5d0d9b..41a78275377 100644
--- a/sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/TokenizerBridgeTest.java
+++ b/sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/TokenizerBridgeTest.java
@@ -49,7 +49,7 @@ public class TokenizerBridgeTest {
tokenEntries.add(TokenEntry.getEOF());
}
};
- bridge = new TokenizerBridge(tokenizer, "UTF-8");
+ bridge = new TokenizerBridge(tokenizer, "UTF-8", 10);
}
@Test