aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-cpd-plugin
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2014-01-26 17:49:05 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2014-01-26 22:28:54 +0100
commit5f79d13360162ec93cc3813915791baacb19d4f6 (patch)
treeb6de26d141ec406634836912bd268c1b8b8fbcdb /plugins/sonar-cpd-plugin
parentd702367da7a46b4179babda8a791827d8aae513a (diff)
downloadsonarqube-5f79d13360162ec93cc3813915791baacb19d4f6.tar.gz
sonarqube-5f79d13360162ec93cc3813915791baacb19d4f6.zip
SONAR-926 remove useless coupling with class Language
Diffstat (limited to 'plugins/sonar-cpd-plugin')
-rw-r--r--plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdEngine.java2
-rw-r--r--plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdSensor.java16
-rw-r--r--plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/SonarBridgeEngine.java10
-rw-r--r--plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/SonarEngine.java4
-rw-r--r--plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/CpdSensorTest.java20
5 files changed, 22 insertions, 30 deletions
diff --git a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdEngine.java b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdEngine.java
index 0c336491884..3e221e1978c 100644
--- a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdEngine.java
+++ b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdEngine.java
@@ -27,7 +27,7 @@ import org.sonar.api.resources.Project;
public abstract class CpdEngine implements BatchExtension {
- abstract boolean isLanguageSupported(Language language);
+ abstract boolean isLanguageSupported(String language);
abstract void analyse(Project project, SensorContext context);
diff --git a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdSensor.java b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdSensor.java
index f9346aaffc3..f55f1215fef 100644
--- a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdSensor.java
+++ b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdSensor.java
@@ -27,7 +27,6 @@ import org.sonar.api.batch.ModuleLanguages;
import org.sonar.api.batch.Sensor;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.config.Settings;
-import org.sonar.api.resources.Language;
import org.sonar.api.resources.Project;
public class CpdSensor implements Sensor {
@@ -51,17 +50,16 @@ public class CpdSensor implements Sensor {
}
@VisibleForTesting
- CpdEngine getEngine(Language language) {
+ CpdEngine getEngine(String language) {
if (sonarEngine.isLanguageSupported(language)) {
return sonarEngine;
- } else {
- return sonarBridgeEngine;
}
+ return sonarBridgeEngine;
}
@VisibleForTesting
- boolean isSkipped(Language language) {
- String key = "sonar.cpd." + language.getKey() + ".skip";
+ boolean isSkipped(String language) {
+ String key = "sonar.cpd." + language + ".skip";
if (settings.hasKey(key)) {
return settings.getBoolean(key);
}
@@ -69,15 +67,15 @@ public class CpdSensor implements Sensor {
}
public void analyse(Project project, SensorContext context) {
- for (Language language : moduleLanguages.getModuleLanguages()) {
+ for (String language : moduleLanguages.keys()) {
if (isSkipped(language)) {
- LOG.info("Detection of duplicated code is skipped for {}.", language);
+ LOG.info("Detection of duplicated code is skipped for {}", language);
continue;
}
CpdEngine engine = getEngine(language);
if (!engine.isLanguageSupported(language)) {
- LOG.debug("Detection of duplicated code is not supported for {}.", language);
+ LOG.debug("Detection of duplicated code is not supported for {}", language);
continue;
}
LOG.info("{} is used for {}", engine, language);
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 aa4bf2b4da6..9750b2fa206 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
@@ -42,6 +42,7 @@ import org.sonar.duplications.internal.pmd.TokenizerBridge;
import org.sonar.plugins.cpd.index.IndexFactory;
import org.sonar.plugins.cpd.index.SonarDuplicationsIndex;
+import javax.annotation.CheckForNull;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.ExecutionException;
@@ -76,7 +77,7 @@ public class SonarBridgeEngine extends CpdEngine {
}
@Override
- public boolean isLanguageSupported(Language language) {
+ public boolean isLanguageSupported(String language) {
return getMapping(language) != null;
}
@@ -90,7 +91,7 @@ public class SonarBridgeEngine extends CpdEngine {
return;
}
- CpdMapping mapping = getMapping(project.getLanguage());
+ CpdMapping mapping = getMapping(project.getLanguage().getKey());
// Create index
SonarDuplicationsIndex index = indexFactory.create(project);
@@ -167,10 +168,11 @@ public class SonarBridgeEngine extends CpdEngine {
return minimumTokens;
}
- private CpdMapping getMapping(Language language) {
+ @CheckForNull
+ private CpdMapping getMapping(String language) {
if (mappings != null) {
for (CpdMapping cpdMapping : mappings) {
- if (cpdMapping.getLanguage().equals(language)) {
+ if (cpdMapping.getLanguage().getKey().equals(language)) {
return cpdMapping;
}
}
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 d82132e8d15..832b4e7ab82 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
@@ -92,8 +92,8 @@ public class SonarEngine extends CpdEngine {
}
@Override
- public boolean isLanguageSupported(Language language) {
- return Java.KEY.equals(language.getKey());
+ public boolean isLanguageSupported(String language) {
+ return Java.KEY.equals(language);
}
@Override
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 185bb6d6013..5fb30de0227 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
@@ -39,7 +39,6 @@ public class CpdSensorTest {
SonarBridgeEngine sonarBridgeEngine;
CpdSensor sensor;
Settings settings;
- private Language phpLanguage;
@Before
public void setUp() {
@@ -47,25 +46,18 @@ public class CpdSensorTest {
sonarEngine = new SonarEngine(indexFactory, null, null);
sonarBridgeEngine = new SonarBridgeEngine(indexFactory, null, null);
settings = new Settings(new PropertyDefinitions(CpdPlugin.class));
- phpLanguage = new AbstractLanguage("php", "PHP") {
-
- @Override
- public String[] getFileSuffixes() {
- return null;
- }
- };
sensor = new CpdSensor(sonarEngine, sonarBridgeEngine, settings, new DefaultModuleLanguages(settings, new Languages()));
}
@Test
public void test_global_skip() {
settings.setProperty("sonar.cpd.skip", true);
- assertThat(sensor.isSkipped(Java.INSTANCE)).isTrue();
+ assertThat(sensor.isSkipped(Java.KEY)).isTrue();
}
@Test
public void should_not_skip_by_default() {
- assertThat(sensor.isSkipped(Java.INSTANCE)).isFalse();
+ assertThat(sensor.isSkipped(Java.KEY)).isFalse();
}
@Test
@@ -73,14 +65,14 @@ public class CpdSensorTest {
settings.setProperty("sonar.cpd.skip", false);
settings.setProperty("sonar.cpd.php.skip", true);
- assertThat(sensor.isSkipped(phpLanguage)).isTrue();
- assertThat(sensor.isSkipped(Java.INSTANCE)).isFalse();
+ assertThat(sensor.isSkipped("php")).isTrue();
+ assertThat(sensor.isSkipped(Java.KEY)).isFalse();
}
@Test
public void test_engine() {
- assertThat(sensor.getEngine(Java.INSTANCE)).isSameAs(sonarEngine);
- assertThat(sensor.getEngine(phpLanguage)).isSameAs(sonarBridgeEngine);
+ assertThat(sensor.getEngine(Java.KEY)).isSameAs(sonarEngine);
+ assertThat(sensor.getEngine("PHP")).isSameAs(sonarBridgeEngine);
}
}