From e606937326a6f2c9d83d7d2509d73bb237a94356 Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Mon, 23 Jan 2017 11:22:39 +0100 Subject: SONAR-8631 Only publish input files used by sensors --- .../deprecated/DeprecatedSensorContext.java | 12 ++++-------- .../perspectives/ScannerPerspectives.java | 22 +++++++--------------- .../scanner/deprecated/test/TestPlanBuilder.java | 4 +++- 3 files changed, 14 insertions(+), 24 deletions(-) (limited to 'sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated') 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 getMeasures(Resource resource, MeasuresFilter 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, 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 as(Class

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

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 { @Override public MutableTestPlan loadPerspective(Class 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()); } -- cgit v1.2.3