From a2d5e82501f3ed8d96239845842770515f5087e6 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Mon, 1 Dec 2014 15:36:12 +0100 Subject: SONAR-5864 API cleanup * add a proper way to create perspective on InputFile * add a proper way to convert InputFile to resource * deprecate colorizer --- .../org/sonar/core/component/ScanPerspectives.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'sonar-core') diff --git a/sonar-core/src/main/java/org/sonar/core/component/ScanPerspectives.java b/sonar-core/src/main/java/org/sonar/core/component/ScanPerspectives.java index 142f52a4f7c..a3cfb20cdc5 100644 --- a/sonar-core/src/main/java/org/sonar/core/component/ScanPerspectives.java +++ b/sonar-core/src/main/java/org/sonar/core/component/ScanPerspectives.java @@ -22,12 +22,18 @@ package org.sonar.core.component; import com.google.common.collect.Maps; import org.sonar.api.BatchComponent; import org.sonar.api.batch.SonarIndex; +import org.sonar.api.batch.fs.InputDir; +import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.batch.fs.InputPath; import org.sonar.api.component.Component; import org.sonar.api.component.Perspective; import org.sonar.api.component.ResourcePerspectives; +import org.sonar.api.resources.Directory; +import org.sonar.api.resources.File; import org.sonar.api.resources.Resource; import javax.annotation.CheckForNull; + import java.util.Map; public class ScanPerspectives implements ResourcePerspectives, BatchComponent { @@ -64,6 +70,19 @@ public class ScanPerspectives implements ResourcePerspectives, BatchComponent { return null; } + @Override + public

P as(Class

perspectiveClass, InputPath inputPath) { + Resource r; + if (inputPath instanceof InputDir) { + r = Directory.create(((InputDir) inputPath).relativePath()); + } else if (inputPath instanceof InputFile) { + r = File.create(((InputFile) inputPath).relativePath()); + } else { + throw new IllegalArgumentException("Unknow input path type: " + inputPath); + } + return as(perspectiveClass, r); + } + private PerspectiveBuilder builderFor(Class clazz) { PerspectiveBuilder builder = (PerspectiveBuilder) builders.get(clazz); if (builder == null) { -- cgit v1.2.3