aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-09-15 16:07:27 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2014-09-17 10:48:31 +0200
commit9513bee576bda233b91e6703bf0e40a6c102752c (patch)
treef602525a6309380464fbe4b6ffc9524d00e1d192 /sonar-plugin-api
parent568d2097670bc3c8fd71f914ea425ec551ec0d5c (diff)
downloadsonarqube-9513bee576bda233b91e6703bf0e40a6c102752c.tar.gz
sonarqube-9513bee576bda233b91e6703bf0e40a6c102752c.zip
SONAR-5389 Update APIs to ease migration of language plugins
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/FileSystem.java8
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFileSystem.java13
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/component/ResourcePerspectives.java3
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/resources/ProjectFileSystem.java2
4 files changed, 26 insertions, 0 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/FileSystem.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/FileSystem.java
index 0c285f686e2..cd8bf7c1a36 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/FileSystem.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/FileSystem.java
@@ -141,4 +141,12 @@ public interface FileSystem extends BatchComponent {
* Languages detected in all files, whatever their type (main or test)
*/
SortedSet<String> languages();
+
+ /**
+ * Utility method mainly used to resolve location of reports.
+ * @return file in canonical form from specified path. Path can be absolute or relative to project basedir.
+ * For example resolvePath("pom.xml") or resolvePath("src/main/java")
+ * @since 5.0
+ */
+ File resolvePath(String path);
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFileSystem.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFileSystem.java
index 55c5303cbae..0e67c3cf9ac 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFileSystem.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFileSystem.java
@@ -32,6 +32,7 @@ import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import java.io.File;
+import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collection;
@@ -281,4 +282,16 @@ public class DefaultFileSystem implements FileSystem {
}
}
+ @Override
+ public File resolvePath(String path) {
+ File file = new File(path);
+ if (!file.isAbsolute()) {
+ try {
+ file = new File(baseDir(), path).getCanonicalFile();
+ } catch (IOException e) {
+ throw new IllegalArgumentException("Unable to resolve path '" + path + "'", e);
+ }
+ }
+ return file;
+ }
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/component/ResourcePerspectives.java b/sonar-plugin-api/src/main/java/org/sonar/api/component/ResourcePerspectives.java
index d992b571001..e3233de0a7f 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/component/ResourcePerspectives.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/component/ResourcePerspectives.java
@@ -19,6 +19,7 @@
*/
package org.sonar.api.component;
+import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.resources.Resource;
import javax.annotation.CheckForNull;
@@ -27,7 +28,9 @@ import javax.annotation.CheckForNull;
* Only on batch-side.
*
* @since 3.5
+ * @deprecated since 5.0 everything you need is available in {@link SensorContext}
*/
+@Deprecated
public interface ResourcePerspectives extends Perspectives {
@CheckForNull
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ProjectFileSystem.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ProjectFileSystem.java
index 944b1278a6a..ea393f5805c 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ProjectFileSystem.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ProjectFileSystem.java
@@ -20,6 +20,7 @@
package org.sonar.api.resources;
import org.sonar.api.BatchComponent;
+import org.sonar.api.batch.fs.FileSystem;
import java.io.File;
import java.io.IOException;
@@ -97,6 +98,7 @@ public interface ProjectFileSystem extends BatchComponent {
/**
* @return file in canonical form from specified path. Path can be absolute or relative to project basedir.
* For example resolvePath("pom.xml") or resolvePath("src/main/java")
+ * @deprecated since 5.0 use {@link FileSystem#resolvePath(String)}
*/
File resolvePath(String path);