aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src/main/java/org/sonar/api/batch
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2018-11-14 22:47:35 +0100
committersonartech <sonartech@sonarsource.com>2019-01-16 09:43:01 +0100
commitf594bf7568192dbfc9b9a8cf4f7c243ea4ad046b (patch)
treeb4d6818199beebf97e5d4d6a10dfcebde10e7ba8 /sonar-plugin-api/src/main/java/org/sonar/api/batch
parenta0acec09a79485117ab9c8e3c67a8446224d5de9 (diff)
downloadsonarqube-f594bf7568192dbfc9b9a8cf4f7c243ea4ad046b.tar.gz
sonarqube-f594bf7568192dbfc9b9a8cf4f7c243ea4ad046b.zip
SONAR-11465 Deprecate InputModule and introduce InputProject
Diffstat (limited to 'sonar-plugin-api/src/main/java/org/sonar/api/batch')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectKey.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectReactor.java3
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputComponent.java1
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputModule.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AbstractProjectOrModule.java148
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputComponent.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputModule.java124
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputProject.java36
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/InputModuleHierarchy.java11
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/TestInputFileBuilder.java23
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java9
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java30
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/AbstractDefaultIssue.java19
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssue.java10
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java10
17 files changed, 271 insertions, 163 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java
index 7307876e0e3..a846b206bc1 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java
@@ -39,7 +39,9 @@ import org.sonar.api.CoreProperties;
* Since 6.5, plugins should no longer manipulate the project's structure.
*
* @since 2.9
+ * @deprecated since 7.6 use {@link org.sonar.api.scanner.fs.InputProject}
*/
+@Deprecated
public class ProjectDefinition {
public static final String SOURCES_PROPERTY = "sonar.sources";
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectKey.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectKey.java
index 9c382dd719e..a1e4f2661c0 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectKey.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectKey.java
@@ -21,7 +21,9 @@ package org.sonar.api.batch.bootstrap;
/**
* Provides root project key with branch
+ * @deprecated since 7.6
*/
+@Deprecated
@FunctionalInterface
public interface ProjectKey {
String get();
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectReactor.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectReactor.java
index 8bceff01749..4f7393cb073 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectReactor.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectReactor.java
@@ -32,7 +32,7 @@ import java.util.List;
*/
@Deprecated
@ScannerSide
-public class ProjectReactor implements ProjectKey {
+public class ProjectReactor {
private ProjectDefinition root;
@@ -71,7 +71,6 @@ public class ProjectReactor implements ProjectKey {
return null;
}
- @Override
public String get() {
if (root != null) {
return root.getKeyWithBranch();
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputComponent.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputComponent.java
index d2bf32edd88..b6672651a81 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputComponent.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputComponent.java
@@ -26,6 +26,7 @@ package org.sonar.api.batch.fs;
* @see InputFile
* @see InputDir
* @see InputModule
+ * @see org.sonar.api.scanner.fs.InputProject
*/
public interface InputComponent {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputModule.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputModule.java
index 27bf4f2d180..3ce89d90f45 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputModule.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputModule.java
@@ -28,7 +28,9 @@ import org.sonar.api.batch.sensor.SensorContext;
* Used to create issues and measures on modules. You can access InputModule using {@link SensorContext#module()}
*
* @since 5.2
+ * @deprecated since 7.6 modules are deprecated. Use {@link org.sonar.api.scanner.fs.InputProject} instead.
*/
+@Deprecated
@Immutable
public interface InputModule extends InputComponent {
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AbstractProjectOrModule.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AbstractProjectOrModule.java
new file mode 100644
index 00000000000..d9d59a0932b
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AbstractProjectOrModule.java
@@ -0,0 +1,148 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.api.batch.fs.internal;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.LinkOption;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.CheckForNull;
+import javax.annotation.concurrent.Immutable;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
+
+@Immutable
+public abstract class AbstractProjectOrModule extends DefaultInputComponent {
+ private final Path baseDir;
+ private final Path workDir;
+ private final String name;
+ private final String version;
+ private final String originalName;
+ private final String originalVersion;
+ private final String description;
+ private final String keyWithBranch;
+ private final String branch;
+ private final Map<String, String> properties;
+
+ private final String key;
+ private final ProjectDefinition definition;
+
+ /**
+ * For testing only!
+ */
+ public AbstractProjectOrModule(ProjectDefinition definition) {
+ this(definition, TestInputFileBuilder.nextBatchId());
+ }
+
+ public AbstractProjectOrModule(ProjectDefinition definition, int scannerComponentId) {
+ super(scannerComponentId);
+ this.baseDir = initBaseDir(definition);
+ this.workDir = initWorkingDir(definition);
+ this.name = definition.getName();
+ this.originalName = definition.getOriginalName();
+ this.version = definition.getVersion();
+ this.originalVersion = definition.getOriginalVersion();
+ this.description = definition.getDescription();
+ this.keyWithBranch = definition.getKeyWithBranch();
+ this.branch = definition.getBranch();
+ this.properties = Collections.unmodifiableMap(new HashMap<>(definition.properties()));
+
+ this.definition = definition;
+ this.key = definition.getKey();
+ }
+
+ private static Path initBaseDir(ProjectDefinition module) {
+ Path result;
+ try {
+ result = module.getBaseDir().toPath().toRealPath(LinkOption.NOFOLLOW_LINKS);
+ } catch (IOException e) {
+ throw new IllegalStateException("Unable to resolve module baseDir", e);
+ }
+ return result;
+ }
+
+ private static Path initWorkingDir(ProjectDefinition module) {
+ File workingDirAsFile = module.getWorkDir();
+ return workingDirAsFile.getAbsoluteFile().toPath().normalize();
+ }
+
+ /**
+ * Module key without branch
+ */
+ @Override
+ public String key() {
+ return key;
+ }
+
+ @Override
+ public boolean isFile() {
+ return false;
+ }
+
+ public ProjectDefinition definition() {
+ return definition;
+ }
+
+ public Path getBaseDir() {
+ return baseDir;
+ }
+
+ public Path getWorkDir() {
+ return workDir;
+ }
+
+ public String getKeyWithBranch() {
+ return keyWithBranch;
+ }
+
+ @CheckForNull
+ public String getBranch() {
+ return branch;
+ }
+
+ public Map<String, String> properties() {
+ return properties;
+ }
+
+ @CheckForNull
+ public String getOriginalVersion() {
+ return originalVersion;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ @CheckForNull
+ public String getOriginalName() {
+ return originalName;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputComponent.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputComponent.java
index d29d84b6d2d..7138f95adcc 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputComponent.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputComponent.java
@@ -44,7 +44,7 @@ public abstract class DefaultInputComponent implements InputComponent {
return key().equals(that.key());
}
- public int batchId() {
+ public int scannerId() {
return id;
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java
index f7d640a4dbb..efa7804d512 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java
@@ -66,7 +66,7 @@ public class DefaultInputFile extends DefaultInputComponent implements InputFile
// For testing
public DefaultInputFile(DefaultIndexedFile indexedFile, Consumer<DefaultInputFile> metadataGenerator, @Nullable String contents) {
- super(indexedFile.batchId());
+ super(indexedFile.scannerId());
this.indexedFile = indexedFile;
this.metadataGenerator = metadataGenerator;
this.metadata = null;
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputModule.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputModule.java
index 4b7dd814488..157e5a1e25d 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputModule.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputModule.java
@@ -19,134 +19,18 @@
*/
package org.sonar.api.batch.fs.internal;
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.LinkOption;
-import java.nio.file.Path;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import javax.annotation.CheckForNull;
import javax.annotation.concurrent.Immutable;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.fs.InputModule;
-/**
- * @since 5.2
- */
@Immutable
-public class DefaultInputModule extends DefaultInputComponent implements InputModule {
- private final Path baseDir;
- private final Path workDir;
- private final String name;
- private final String version;
- private final String originalName;
- private final String originalVersion;
- private final String description;
- private final String keyWithBranch;
- private final String branch;
- private final Map<String, String> properties;
-
- private final String moduleKey;
- private final ProjectDefinition definition;
+public class DefaultInputModule extends AbstractProjectOrModule implements InputModule {
- /**
- * For testing only!
- */
public DefaultInputModule(ProjectDefinition definition) {
- this(definition, TestInputFileBuilder.nextBatchId());
- }
-
- public DefaultInputModule(ProjectDefinition definition, int batchId) {
- super(batchId);
- this.baseDir = initBaseDir(definition);
- this.workDir = initWorkingDir(definition);
- this.name = definition.getName();
- this.originalName = definition.getOriginalName();
- this.version = definition.getVersion();
- this.originalVersion = definition.getOriginalVersion();
- this.description = definition.getDescription();
- this.keyWithBranch = definition.getKeyWithBranch();
- this.branch = definition.getBranch();
- this.properties = Collections.unmodifiableMap(new HashMap<>(definition.properties()));
-
- this.definition = definition;
- this.moduleKey = definition.getKey();
- }
-
- private static Path initBaseDir(ProjectDefinition module) {
- Path result;
- try {
- result = module.getBaseDir().toPath().toRealPath(LinkOption.NOFOLLOW_LINKS);
- } catch (IOException e) {
- throw new IllegalStateException("Unable to resolve module baseDir", e);
- }
- return result;
- }
-
- private static Path initWorkingDir(ProjectDefinition module) {
- File workingDirAsFile = module.getWorkDir();
- return workingDirAsFile.getAbsoluteFile().toPath().normalize();
- }
-
- /**
- * Module key without branch
- */
- @Override
- public String key() {
- return moduleKey;
- }
-
- @Override
- public boolean isFile() {
- return false;
- }
-
- public ProjectDefinition definition() {
- return definition;
- }
-
- public Path getBaseDir() {
- return baseDir;
+ super(definition);
}
- public Path getWorkDir() {
- return workDir;
+ public DefaultInputModule(ProjectDefinition definition, int scannerComponentId) {
+ super(definition, scannerComponentId);
}
-
- public String getKeyWithBranch() {
- return keyWithBranch;
- }
-
- @CheckForNull
- public String getBranch() {
- return branch;
- }
-
- public Map<String, String> properties() {
- return properties;
- }
-
- @CheckForNull
- public String getOriginalVersion() {
- return originalVersion;
- }
-
- public String getVersion() {
- return version;
- }
-
- @CheckForNull
- public String getOriginalName() {
- return originalName;
- }
-
- public String getName() {
- return name;
- }
-
- public String getDescription() {
- return description;
- }
-
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputProject.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputProject.java
new file mode 100644
index 00000000000..b89a8846534
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputProject.java
@@ -0,0 +1,36 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.api.batch.fs.internal;
+
+import javax.annotation.concurrent.Immutable;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.api.scanner.fs.InputProject;
+
+@Immutable
+public class DefaultInputProject extends AbstractProjectOrModule implements InputProject {
+
+ public DefaultInputProject(ProjectDefinition definition) {
+ super(definition);
+ }
+
+ public DefaultInputProject(ProjectDefinition definition, int scannerComponentId) {
+ super(definition, scannerComponentId);
+ }
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/InputModuleHierarchy.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/InputModuleHierarchy.java
index 5482e59ea78..8fe58bde9dc 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/InputModuleHierarchy.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/InputModuleHierarchy.java
@@ -20,23 +20,20 @@
package org.sonar.api.batch.fs.internal;
import java.util.Collection;
-
import javax.annotation.CheckForNull;
import javax.annotation.concurrent.Immutable;
-import org.sonar.api.batch.fs.InputModule;
-
@Immutable
public interface InputModuleHierarchy {
DefaultInputModule root();
- boolean isRoot(InputModule module);
+ boolean isRoot(DefaultInputModule module);
- Collection<DefaultInputModule> children(InputModule module);
+ Collection<DefaultInputModule> children(DefaultInputModule module);
@CheckForNull
- DefaultInputModule parent(InputModule module);
+ DefaultInputModule parent(DefaultInputModule module);
@CheckForNull
- String relativePath(InputModule module);
+ String relativePath(DefaultInputModule module);
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/TestInputFileBuilder.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/TestInputFileBuilder.java
index b8188f0edce..d84961b76c5 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/TestInputFileBuilder.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/TestInputFileBuilder.java
@@ -239,20 +239,37 @@ public class TestInputFileBuilder {
return new DefaultInputModule(projectDefinition, TestInputFileBuilder.nextBatchId());
}
- public static DefaultInputModule newDefaultInputModule(DefaultInputModule parent, String key) throws IOException {
+ public static DefaultInputModule newDefaultInputModule(AbstractProjectOrModule parent, String key) throws IOException {
Path basedir = parent.getBaseDir().resolve(key);
Files.createDirectory(basedir);
return newDefaultInputModule(key, basedir.toFile());
}
- public static DefaultInputDir newDefaultInputDir(DefaultInputModule module, String relativePath) throws IOException {
+ public static DefaultInputProject newDefaultInputProject(String projectKey, File baseDir) {
+ ProjectDefinition definition = ProjectDefinition.create()
+ .setKey(projectKey)
+ .setBaseDir(baseDir)
+ .setWorkDir(new File(baseDir, ".sonar"));
+ return newDefaultInputProject(definition);
+ }
+
+ public static DefaultInputProject newDefaultInputProject(ProjectDefinition projectDefinition) {
+ return new DefaultInputProject(projectDefinition, TestInputFileBuilder.nextBatchId());
+ }
+
+ public static DefaultInputProject newDefaultInputProject(String key, Path baseDir) throws IOException {
+ Files.createDirectory(baseDir);
+ return newDefaultInputProject(key, baseDir.toFile());
+ }
+
+ public static DefaultInputDir newDefaultInputDir(AbstractProjectOrModule module, String relativePath) throws IOException {
Path basedir = module.getBaseDir().resolve(relativePath);
Files.createDirectory(basedir);
return new DefaultInputDir(module.key(), relativePath)
.setModuleBaseDir(module.getBaseDir());
}
- public static DefaultInputFile newDefaultInputFile(Path projectBaseDir, DefaultInputModule module, String relativePath) {
+ public static DefaultInputFile newDefaultInputFile(Path projectBaseDir, AbstractProjectOrModule module, String relativePath) {
return new TestInputFileBuilder(module.key(), relativePath)
.setStatus(InputFile.Status.SAME)
.setProjectBaseDir(projectBaseDir)
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java
index 806cc24277d..f207b2680c9 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java
@@ -42,6 +42,7 @@ import org.sonar.api.batch.sensor.rule.NewAdHocRule;
import org.sonar.api.batch.sensor.symbol.NewSymbolTable;
import org.sonar.api.config.Configuration;
import org.sonar.api.config.Settings;
+import org.sonar.api.scanner.fs.InputProject;
import org.sonar.api.utils.Version;
/**
@@ -75,10 +76,18 @@ public interface SensorContext {
/**
* @since 5.5
+ * @deprecated since 7.6 modules are deprecated. Use {@link #project()} instead.
*/
+ @Deprecated
InputModule module();
/**
+ * The current project.
+ * @since 7.6
+ */
+ InputProject project();
+
+ /**
* Version of API at runtime, not at compilation time. It's a shortcut on
* {@code runtime().getApiVersion()} since 6.0.
* @since 5.5
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java
index 58286e136e7..e8cc9f81b8f 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java
@@ -42,6 +42,7 @@ import org.sonar.api.batch.fs.TextRange;
import org.sonar.api.batch.fs.internal.DefaultFileSystem;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
import org.sonar.api.batch.fs.internal.DefaultTextPointer;
import org.sonar.api.batch.rule.ActiveRules;
import org.sonar.api.batch.rule.internal.ActiveRulesBuilder;
@@ -82,6 +83,7 @@ import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.internal.ApiVersion;
import org.sonar.api.internal.SonarRuntimeImpl;
import org.sonar.api.measures.Metric;
+import org.sonar.api.scanner.fs.InputProject;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.Version;
@@ -89,18 +91,17 @@ import static java.util.Collections.unmodifiableMap;
/**
* Utility class to help testing {@link Sensor}. This is not an API and method signature may evolve.
- *
+ * <p>
* Usage: call {@link #create(File)} to create an "in memory" implementation of {@link SensorContext} with a filesystem initialized with provided baseDir.
* <p>
* You have to manually register inputFiles using:
* <pre>
* sensorContextTester.fileSystem().add(new DefaultInputFile("myProjectKey", "src/Foo.java")
- .setLanguage("java")
- .initMetadata("public class Foo {\n}"));
+ * .setLanguage("java")
+ * .initMetadata("public class Foo {\n}"));
* </pre>
* <p>
* Then pass it to your {@link Sensor}. You can then query elements provided by your sensor using methods {@link #allIssues()}, ...
- *
*/
public class SensorContextTester implements SensorContext {
@@ -108,6 +109,7 @@ public class SensorContextTester implements SensorContext {
private DefaultFileSystem fs;
private ActiveRules activeRules;
private InMemorySensorStorage sensorStorage;
+ private DefaultInputProject project;
private DefaultInputModule module;
private SonarRuntime runtime;
private boolean cancelled;
@@ -117,6 +119,7 @@ public class SensorContextTester implements SensorContext {
this.fs = new DefaultFileSystem(moduleBaseDir).setEncoding(Charset.defaultCharset());
this.activeRules = new ActiveRulesBuilder().build();
this.sensorStorage = new InMemorySensorStorage();
+ this.project = new DefaultInputProject(ProjectDefinition.create().setKey("projectKey").setBaseDir(moduleBaseDir.toFile()).setWorkDir(moduleBaseDir.resolve(".sonar").toFile()));
this.module = new DefaultInputModule(ProjectDefinition.create().setKey("projectKey").setBaseDir(moduleBaseDir.toFile()).setWorkDir(moduleBaseDir.resolve(".sonar").toFile()));
this.runtime = SonarRuntimeImpl.forSonarQube(ApiVersion.load(System2.INSTANCE), SonarQubeSide.SCANNER);
}
@@ -202,6 +205,11 @@ public class SensorContextTester implements SensorContext {
}
@Override
+ public InputProject project() {
+ return project;
+ }
+
+ @Override
public <G extends Serializable> NewMeasure<G> newMeasure() {
return new DefaultMeasure<>(sensorStorage);
}
@@ -220,7 +228,7 @@ public class SensorContextTester implements SensorContext {
@Override
public NewIssue newIssue() {
- return new DefaultIssue(module, sensorStorage);
+ return new DefaultIssue(project, sensorStorage);
}
public Collection<Issue> allIssues() {
@@ -229,7 +237,7 @@ public class SensorContextTester implements SensorContext {
@Override
public NewExternalIssue newExternalIssue() {
- return new DefaultExternalIssue(module, sensorStorage);
+ return new DefaultExternalIssue(project, sensorStorage);
}
@Override
@@ -331,9 +339,10 @@ public class SensorContextTester implements SensorContext {
/**
* Return list of syntax highlighting applied for a given position in a file. The result is a list because in theory you
* can apply several styles to the same range.
+ *
* @param componentKey Key of the file like 'myProjectKey:src/foo.php'
- * @param line Line you want to query
- * @param lineOffset Offset you want to query.
+ * @param line Line you want to query
+ * @param lineOffset Offset you want to query.
* @return List of styles applied to this position or empty list if there is no highlighting at this position.
*/
public List<TypeOfText> highlightingTypeAt(String componentKey, int line, int lineOffset) {
@@ -353,9 +362,10 @@ public class SensorContextTester implements SensorContext {
/**
* Return list of symbol references ranges for the symbol at a given position in a file.
+ *
* @param componentKey Key of the file like 'myProjectKey:src/foo.php'
- * @param line Line you want to query
- * @param lineOffset Offset you want to query.
+ * @param line Line you want to query
+ * @param lineOffset Offset you want to query.
* @return List of references for the symbol (potentially empty) or null if there is no symbol at this position.
*/
@CheckForNull
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/AbstractDefaultIssue.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/AbstractDefaultIssue.java
index c993ee62d07..39f01a319fc 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/AbstractDefaultIssue.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/AbstractDefaultIssue.java
@@ -30,6 +30,7 @@ import javax.annotation.Nullable;
import org.sonar.api.batch.fs.InputComponent;
import org.sonar.api.batch.fs.internal.DefaultInputDir;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
import org.sonar.api.batch.sensor.internal.DefaultStorable;
import org.sonar.api.batch.sensor.internal.SensorStorage;
import org.sonar.api.batch.sensor.issue.Issue.Flow;
@@ -45,15 +46,15 @@ import static java.util.stream.Collectors.toList;
public abstract class AbstractDefaultIssue<T extends AbstractDefaultIssue> extends DefaultStorable {
protected IssueLocation primaryLocation;
protected List<List<IssueLocation>> flows = new ArrayList<>();
- protected DefaultInputModule projectRoot;
+ protected DefaultInputProject project;
- protected AbstractDefaultIssue(DefaultInputModule projectRoot) {
- this(projectRoot, null);
+ protected AbstractDefaultIssue(DefaultInputProject project) {
+ this(project, null);
}
- public AbstractDefaultIssue(DefaultInputModule projectRoot, @Nullable SensorStorage storage) {
+ public AbstractDefaultIssue(DefaultInputProject project, @Nullable SensorStorage storage) {
super(storage);
- this.projectRoot = projectRoot;
+ this.project = project;
}
public IssueLocation primaryLocation() {
@@ -98,16 +99,16 @@ public abstract class AbstractDefaultIssue<T extends AbstractDefaultIssue> exten
if (component instanceof DefaultInputDir) {
DefaultInputDir dirComponent = (DefaultInputDir) component;
- dirOrModulePath = Optional.of(projectRoot.getBaseDir().relativize(dirComponent.path()));
- } else if (component instanceof DefaultInputModule && !Objects.equals(projectRoot.key(), component.key())) {
+ dirOrModulePath = Optional.of(project.getBaseDir().relativize(dirComponent.path()));
+ } else if (component instanceof DefaultInputModule && !Objects.equals(project.key(), component.key())) {
DefaultInputModule moduleComponent = (DefaultInputModule) component;
- dirOrModulePath = Optional.of(projectRoot.getBaseDir().relativize(moduleComponent.getBaseDir()));
+ dirOrModulePath = Optional.of(project.getBaseDir().relativize(moduleComponent.getBaseDir()));
}
if (dirOrModulePath.isPresent()) {
String path = PathUtils.sanitize(dirOrModulePath.get().toString());
DefaultIssueLocation fixedLocation = new DefaultIssueLocation();
- fixedLocation.on(projectRoot);
+ fixedLocation.on(project);
StringBuilder fullMessage = new StringBuilder();
if (!isNullOrEmpty(path)) {
fullMessage.append("[").append(path).append("] ");
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssue.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssue.java
index a9b9cc1051d..db1f22102eb 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssue.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssue.java
@@ -21,7 +21,7 @@ package org.sonar.api.batch.sensor.issue.internal;
import com.google.common.base.Preconditions;
import javax.annotation.Nullable;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
import org.sonar.api.batch.rule.Severity;
import org.sonar.api.batch.sensor.internal.SensorStorage;
import org.sonar.api.batch.sensor.issue.ExternalIssue;
@@ -40,12 +40,12 @@ public class DefaultExternalIssue extends AbstractDefaultIssue<DefaultExternalIs
private String engineId;
private String ruleId;
- public DefaultExternalIssue(DefaultInputModule projectRoot) {
- this(projectRoot, null);
+ public DefaultExternalIssue(DefaultInputProject project) {
+ this(project, null);
}
- public DefaultExternalIssue(DefaultInputModule projectRoot, @Nullable SensorStorage storage) {
- super(projectRoot, storage);
+ public DefaultExternalIssue(DefaultInputProject project, @Nullable SensorStorage storage) {
+ super(project, storage);
}
@Override
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java
index 1b7de9d9ab0..770562eb1d2 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java
@@ -21,7 +21,7 @@ package org.sonar.api.batch.sensor.issue.internal;
import com.google.common.base.Preconditions;
import javax.annotation.Nullable;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
import org.sonar.api.batch.rule.Severity;
import org.sonar.api.batch.sensor.internal.SensorStorage;
import org.sonar.api.batch.sensor.issue.Issue;
@@ -38,12 +38,12 @@ public class DefaultIssue extends AbstractDefaultIssue<DefaultIssue> implements
private Double gap;
private Severity overriddenSeverity;
- public DefaultIssue(DefaultInputModule projectRoot) {
- this(projectRoot, null);
+ public DefaultIssue(DefaultInputProject project) {
+ this(project, null);
}
- public DefaultIssue(DefaultInputModule projectRoot, @Nullable SensorStorage storage) {
- super(projectRoot, storage);
+ public DefaultIssue(DefaultInputProject project, @Nullable SensorStorage storage) {
+ super(project, storage);
}
public DefaultIssue forRule(RuleKey ruleKey) {