aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine
diff options
context:
space:
mode:
authorJulien HENRY <henryju@yahoo.fr>2016-07-05 16:40:56 +0200
committerJulien HENRY <henryju@yahoo.fr>2016-07-06 09:32:40 +0200
commit6da2fd6aea26d9d29c3d3f39419e000009be9c14 (patch)
tree030f2b6ca4d9e8b40b9bdcdf0215de157489e32a /sonar-scanner-engine
parent68620e2016ee7663bdab75478ec90220b38ef722 (diff)
downloadsonarqube-6da2fd6aea26d9d29c3d3f39419e000009be9c14.tar.gz
sonarqube-6da2fd6aea26d9d29c3d3f39419e000009be9c14.zip
Fix some quality flaws
Diffstat (limited to 'sonar-scanner-engine')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/deprecated/DeprecatedSensorContext.java4
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/index/DefaultIndex.java21
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/rule/RuleFinderCompatibility.java34
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/sensor/SensorWrapper.java4
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/index/DefaultIndexTest.java3
5 files changed, 15 insertions, 51 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/deprecated/DeprecatedSensorContext.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/deprecated/DeprecatedSensorContext.java
index ca087ffdf93..de68c7fba5e 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/deprecated/DeprecatedSensorContext.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/deprecated/DeprecatedSensorContext.java
@@ -21,8 +21,6 @@ package org.sonar.batch.deprecated;
import java.io.Serializable;
import java.util.Collection;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.SonarQubeVersion;
import org.sonar.api.batch.AnalysisMode;
import org.sonar.api.batch.SensorContext;
@@ -48,8 +46,6 @@ import org.sonar.batch.sensor.coverage.CoverageExclusions;
public class DeprecatedSensorContext extends DefaultSensorContext implements SensorContext {
- private static final Logger LOG = LoggerFactory.getLogger(DeprecatedSensorContext.class);
-
private final DefaultIndex index;
private final Project project;
private final CoverageExclusions coverageFilter;
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/index/DefaultIndex.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/index/DefaultIndex.java
index 2831159d8dd..488f1714b28 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/index/DefaultIndex.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/index/DefaultIndex.java
@@ -41,10 +41,8 @@ import org.sonar.api.design.Dependency;
import org.sonar.api.measures.Measure;
import org.sonar.api.measures.MeasuresFilter;
import org.sonar.api.measures.MeasuresFilters;
-import org.sonar.api.resources.Directory;
import org.sonar.api.resources.File;
import org.sonar.api.resources.Project;
-import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Resource;
import org.sonar.api.resources.ResourceUtils;
import org.sonar.api.scan.filesystem.PathResolver;
@@ -59,18 +57,16 @@ public class DefaultIndex {
private final BatchComponentCache componentCache;
private final MeasureCache measureCache;
- private final PathResolver pathResolver;
private final DefaultProjectTree projectTree;
// caches
private DefaultSensorStorage sensorStorage;
private Project currentProject;
private Map<Resource, Bucket> buckets = Maps.newLinkedHashMap();
- public DefaultIndex(BatchComponentCache componentCache, DefaultProjectTree projectTree, MeasureCache measureCache, PathResolver pathResolver) {
+ public DefaultIndex(BatchComponentCache componentCache, DefaultProjectTree projectTree, MeasureCache measureCache) {
this.componentCache = componentCache;
this.projectTree = projectTree;
this.measureCache = measureCache;
- this.pathResolver = pathResolver;
}
public void start() {
@@ -297,21 +293,6 @@ public class DefaultIndex {
if (StringUtils.isNotBlank(reference.getKey())) {
return buckets.get(reference);
}
- String relativePathFromSourceDir = null;
- boolean isTest = false;
- boolean isDir = false;
- if (reference instanceof File) {
- File referenceFile = (File) reference;
- isTest = Qualifiers.UNIT_TEST_FILE.equals(referenceFile.getQualifier());
- relativePathFromSourceDir = referenceFile.relativePathFromSourceDir();
- } else if (reference instanceof Directory) {
- isDir = true;
- Directory referenceDir = (Directory) reference;
- relativePathFromSourceDir = referenceDir.relativePathFromSourceDir();
- if (Directory.ROOT.equals(relativePathFromSourceDir)) {
- relativePathFromSourceDir = "";
- }
- }
return null;
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/rule/RuleFinderCompatibility.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/rule/RuleFinderCompatibility.java
index fe763f873bd..93b55d7da01 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/rule/RuleFinderCompatibility.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/rule/RuleFinderCompatibility.java
@@ -19,24 +19,20 @@
*/
package org.sonar.batch.rule;
-import org.sonar.api.batch.rule.Rules;
-
-import com.google.common.base.Function;
-import com.google.common.collect.Collections2;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
+import org.sonar.api.batch.rule.Rules;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RuleFinder;
import org.sonar.api.rules.RuleQuery;
-import javax.annotation.CheckForNull;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
+import static org.sonar.core.util.stream.Collectors.toList;
/**
* FIXME Waiting for the list of all server rules on batch side this is implemented by redirecting on ActiveRules. This is not correct
@@ -46,12 +42,6 @@ import java.util.Collections;
public class RuleFinderCompatibility implements RuleFinder {
private final Rules rules;
- private static Function<org.sonar.api.batch.rule.Rule, Rule> ruleTransformer = new Function<org.sonar.api.batch.rule.Rule, Rule>() {
- @Override
- public Rule apply(@Nonnull org.sonar.api.batch.rule.Rule input) {
- return toRule(input);
- }
- };
public RuleFinderCompatibility(Rules rules) {
this.rules = rules;
@@ -101,18 +91,20 @@ public class RuleFinderCompatibility implements RuleFinder {
}
private Collection<Rule> byRepository(RuleQuery query) {
- return Collections2.transform(rules.findByRepository(query.getRepositoryKey()), ruleTransformer);
+ return rules.findByRepository(query.getRepositoryKey()).stream()
+ .map(RuleFinderCompatibility::toRule)
+ .collect(toList());
}
-
-
private Collection<Rule> byKey(RuleQuery query) {
Rule rule = toRule(rules.find(RuleKey.of(query.getRepositoryKey(), query.getKey())));
return rule != null ? Arrays.asList(rule) : Collections.<Rule>emptyList();
}
private Collection<Rule> byInternalKey(RuleQuery query) {
- return Collections2.transform(rules.findByInternalKey(query.getRepositoryKey(), query.getConfigKey()), ruleTransformer);
+ return rules.findByInternalKey(query.getRepositoryKey(), query.getConfigKey()).stream()
+ .map(RuleFinderCompatibility::toRule)
+ .collect(toList());
}
@CheckForNull
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/sensor/SensorWrapper.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/sensor/SensorWrapper.java
index 2fb6d98ecdb..f268a67da27 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/sensor/SensorWrapper.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/sensor/SensorWrapper.java
@@ -19,8 +19,6 @@
*/
package org.sonar.batch.sensor;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.batch.sensor.Sensor;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor;
@@ -28,8 +26,6 @@ import org.sonar.api.resources.Project;
public class SensorWrapper implements org.sonar.api.batch.Sensor {
- private static final Logger LOG = LoggerFactory.getLogger(SensorWrapper.class);
-
private Sensor wrappedSensor;
private SensorContext adaptor;
private DefaultSensorDescriptor descriptor;
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/index/DefaultIndexTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/index/DefaultIndexTest.java
index 71d560b3d70..3c50e057ebe 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/index/DefaultIndexTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/index/DefaultIndexTest.java
@@ -34,7 +34,6 @@ import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RuleFinder;
-import org.sonar.api.scan.filesystem.PathResolver;
import org.sonar.batch.DefaultProjectTree;
import org.sonar.batch.FakeJava;
import org.sonar.batch.scan.measure.MeasureCache;
@@ -65,7 +64,7 @@ public class DefaultIndexTest {
DefaultProjectTree projectTree = mock(DefaultProjectTree.class);
BatchComponentCache resourceCache = new BatchComponentCache();
- index = new DefaultIndex(resourceCache, projectTree, mock(MeasureCache.class), new PathResolver());
+ index = new DefaultIndex(resourceCache, projectTree, mock(MeasureCache.class));
baseDir = temp.newFolder();
project = new Project("project");