aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2017-01-23 11:22:39 +0100
committerDuarte Meneses <duarte.meneses@sonarsource.com>2017-01-27 16:26:30 +0100
commite606937326a6f2c9d83d7d2509d73bb237a94356 (patch)
treefa5c8ca45b490b3d786c914af90881d636c18db2 /sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated
parenteea589c564a924993e8edba9d8fa9691e756bce4 (diff)
downloadsonarqube-e606937326a6f2c9d83d7d2509d73bb237a94356.tar.gz
sonarqube-e606937326a6f2c9d83d7d2509d73bb237a94356.zip
SONAR-8631 Only publish input files used by sensors
Diffstat (limited to 'sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/DeprecatedSensorContext.java12
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/perspectives/ScannerPerspectives.java22
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/TestPlanBuilder.java4
3 files changed, 14 insertions, 24 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/DeprecatedSensorContext.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/DeprecatedSensorContext.java
index 1908cf638b2..cfc2d8cf89e 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/DeprecatedSensorContext.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/DeprecatedSensorContext.java
@@ -68,11 +68,7 @@ public class DeprecatedSensorContext extends DefaultSensorContext implements Sen
return index.getMeasure(module.key(), metric);
}
- private String getEffectiveKey(Resource r) {
- if (r.getEffectiveKey() != null) {
- return r.getEffectiveKey();
- }
-
+ private String getComponentKey(Resource r) {
if (ResourceUtils.isProject(r) || /* For technical projects */ResourceUtils.isRootProject(r)) {
return r.getKey();
} else {
@@ -107,12 +103,12 @@ public class DeprecatedSensorContext extends DefaultSensorContext implements Sen
@Override
public Resource getResource(Resource resource) {
- return index.getResource(getEffectiveKey(resource));
+ return index.getResource(getComponentKey(resource));
}
@Override
public <M> M getMeasures(Resource resource, MeasuresFilter<M> filter) {
- return index.getMeasures(getEffectiveKey(resource), filter);
+ return index.getMeasures(getComponentKey(resource), filter);
}
@Override
@@ -124,7 +120,7 @@ public class DeprecatedSensorContext extends DefaultSensorContext implements Sen
@Override
public Measure saveMeasure(@Nullable Resource resource, Measure measure) {
Resource resourceOrProject = resourceOrProject(resource);
- return index.addMeasure(getEffectiveKey(resourceOrProject), measure);
+ return index.addMeasure(getComponentKey(resourceOrProject), measure);
}
@Override
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/perspectives/ScannerPerspectives.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/perspectives/ScannerPerspectives.java
index f15ba18ea66..ad2b65bf934 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/perspectives/ScannerPerspectives.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/perspectives/ScannerPerspectives.java
@@ -22,6 +22,8 @@ package org.sonar.scanner.deprecated.perspectives;
import com.google.common.collect.Maps;
import java.util.Map;
import javax.annotation.CheckForNull;
+
+import org.sonar.api.batch.fs.InputComponent;
import org.sonar.api.batch.fs.InputPath;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.component.Perspective;
@@ -29,18 +31,15 @@ import org.sonar.api.component.ResourcePerspectives;
import org.sonar.api.resources.Resource;
import org.sonar.api.resources.ResourceUtils;
import org.sonar.core.component.ComponentKeys;
-import org.sonar.scanner.index.DefaultIndex;
import org.sonar.scanner.scan.filesystem.InputComponentStore;
public class ScannerPerspectives implements ResourcePerspectives {
private final Map<Class<?>, PerspectiveBuilder<?>> builders = Maps.newHashMap();
- private final DefaultIndex resourceIndex;
private final InputComponentStore componentStore;
private final DefaultInputModule module;
- public ScannerPerspectives(PerspectiveBuilder[] builders, DefaultInputModule module, DefaultIndex resourceIndex, InputComponentStore componentStore) {
- this.resourceIndex = resourceIndex;
+ public ScannerPerspectives(PerspectiveBuilder[] builders, DefaultInputModule module, InputComponentStore componentStore) {
this.componentStore = componentStore;
this.module = module;
@@ -52,22 +51,15 @@ public class ScannerPerspectives implements ResourcePerspectives {
@Override
@CheckForNull
public <P extends Perspective> P as(Class<P> perspectiveClass, Resource resource) {
- Resource indexedResource = resource;
- if (resource.getEffectiveKey() == null) {
- indexedResource = resourceIndex.getResource(getEffectiveKey(resource));
- }
- if (indexedResource != null) {
+ InputComponent component = componentStore.getByKey(getComponentKey(resource));
+ if (component != null) {
PerspectiveBuilder<P> builder = builderFor(perspectiveClass);
- return builder.loadPerspective(perspectiveClass, componentStore.getByKey(indexedResource.getEffectiveKey()));
+ return builder.loadPerspective(perspectiveClass, component);
}
return null;
}
- private String getEffectiveKey(Resource r) {
- if (r.getEffectiveKey() != null) {
- return r.getEffectiveKey();
- }
-
+ private String getComponentKey(Resource r) {
if (ResourceUtils.isProject(r) || /* For technical projects */ResourceUtils.isRootProject(r)) {
return r.getKey();
} else {
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/TestPlanBuilder.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/TestPlanBuilder.java
index 580b0b10944..5f80f14d6b8 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/TestPlanBuilder.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/TestPlanBuilder.java
@@ -25,6 +25,7 @@ import javax.annotation.CheckForNull;
import org.sonar.api.batch.fs.InputComponent;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.InputFile.Type;
+import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.test.MutableTestPlan;
import org.sonar.scanner.deprecated.perspectives.PerspectiveBuilder;
@@ -40,8 +41,9 @@ public class TestPlanBuilder extends PerspectiveBuilder<MutableTestPlan> {
@Override
public MutableTestPlan loadPerspective(Class<MutableTestPlan> perspectiveClass, InputComponent component) {
if (component.isFile()) {
- InputFile inputFile = (InputFile) component;
+ DefaultInputFile inputFile = (DefaultInputFile) component;
if (inputFile.type() == Type.TEST) {
+ inputFile.setPublish(true);
if (!testPlanByFile.containsKey(inputFile)) {
testPlanByFile.put(inputFile, new DefaultTestPlan());
}