aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2018-11-16 15:19:14 +0100
committersonartech <sonartech@sonarsource.com>2019-01-16 09:43:02 +0100
commitb6f878d8d48c55c03bcbf2ba8010526f1fa12f49 (patch)
tree01f2d3038a65ea2d7f79978d17a77f4d33f69522 /sonar-plugin-api
parent6a598e7d7973171e04d78483085ede97a4e21dcb (diff)
downloadsonarqube-b6f878d8d48c55c03bcbf2ba8010526f1fa12f49.tar.gz
sonarqube-b6f878d8d48c55c03bcbf2ba8010526f1fa12f49.zip
SONAR-11459 Stop publishing modules and folders in the scanner report
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/FileSystem.java3
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFileSystem.java25
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultIndexedFile.java16
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputComponent.java4
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputDir.java6
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java4
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/InputComponentTree.java30
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/TestInputFileBuilder.java33
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/PathPatternTest.java24
9 files changed, 39 insertions, 106 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 705934458b4..433c87c57bb 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
@@ -165,9 +165,6 @@ public interface FileSystem {
@CheckForNull
InputFile inputFile(String relativePath);
- @CheckForNull
- InputDir inputDir(String relativePath);
-
/**
* @since 6.3
*/
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 096d0eb5d03..ee90497714d 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
@@ -172,7 +172,8 @@ public class DefaultFileSystem implements FileSystem {
if (relativePath == null) {
return null;
}
- return cache.inputDir(relativePath);
+ // Issues on InputDir are moved to the project, so we just return a fake InputDir for backward compatibility
+ return new DefaultInputDir("unused", relativePath).setModuleBaseDir(baseDir);
}
public DefaultFileSystem add(InputFile inputFile) {
@@ -180,11 +181,6 @@ public class DefaultFileSystem implements FileSystem {
return this;
}
- public DefaultFileSystem add(DefaultInputDir inputDir) {
- cache.add(inputDir);
- return this;
- }
-
@Override
public SortedSet<String> languages() {
return cache.languages();
@@ -199,16 +195,10 @@ public class DefaultFileSystem implements FileSystem {
protected abstract void doAdd(InputFile inputFile);
- protected abstract void doAdd(InputDir inputDir);
-
final void add(InputFile inputFile) {
doAdd(inputFile);
}
- public void add(InputDir inputDir) {
- doAdd(inputDir);
- }
-
protected abstract SortedSet<String> languages();
}
@@ -217,7 +207,6 @@ public class DefaultFileSystem implements FileSystem {
*/
private static class MapCache extends Cache {
private final Map<String, InputFile> fileMap = new HashMap<>();
- private final Map<String, InputDir> dirMap = new HashMap<>();
private final SetMultimap<String, InputFile> filesByNameCache = LinkedHashMultimap.create();
private final SetMultimap<String, InputFile> filesByExtensionCache = LinkedHashMultimap.create();
private SortedSet<String> languages = new TreeSet<>();
@@ -233,11 +222,6 @@ public class DefaultFileSystem implements FileSystem {
}
@Override
- public InputDir inputDir(String relativePath) {
- return dirMap.get(relativePath);
- }
-
- @Override
public Iterable<InputFile> getFilesByName(String filename) {
return filesByNameCache.get(filename);
}
@@ -258,11 +242,6 @@ public class DefaultFileSystem implements FileSystem {
}
@Override
- protected void doAdd(InputDir inputDir) {
- dirMap.put(inputDir.relativePath(), inputDir);
- }
-
- @Override
protected SortedSet<String> languages() {
return languages;
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultIndexedFile.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultIndexedFile.java
index 5b3bdf7a671..1488121129c 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultIndexedFile.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultIndexedFile.java
@@ -39,7 +39,7 @@ import org.sonar.api.utils.PathUtils;
public class DefaultIndexedFile extends DefaultInputComponent implements IndexedFile {
private final String projectRelativePath;
private final String moduleRelativePath;
- private final String moduleKey;
+ private final String projectKey;
private final String language;
private final Type type;
private final Path absolutePath;
@@ -48,15 +48,15 @@ public class DefaultIndexedFile extends DefaultInputComponent implements Indexed
/**
* Testing purposes only!
*/
- public DefaultIndexedFile(String moduleKey, Path baseDir, String relativePath, @Nullable String language) {
- this(baseDir.resolve(relativePath), moduleKey, relativePath, relativePath, Type.MAIN, language, TestInputFileBuilder.nextBatchId(),
+ public DefaultIndexedFile(String projectKey, Path baseDir, String relativePath, @Nullable String language) {
+ this(baseDir.resolve(relativePath), projectKey, relativePath, relativePath, Type.MAIN, language, TestInputFileBuilder.nextBatchId(),
new SensorStrategy());
}
- public DefaultIndexedFile(Path absolutePath, String moduleKey, String projectRelativePath, String moduleRelativePath, Type type, @Nullable String language, int batchId,
+ public DefaultIndexedFile(Path absolutePath, String projectKey, String projectRelativePath, String moduleRelativePath, Type type, @Nullable String language, int batchId,
SensorStrategy sensorStrategy) {
super(batchId);
- this.moduleKey = moduleKey;
+ this.projectKey = projectKey;
this.projectRelativePath = PathUtils.sanitize(projectRelativePath);
this.moduleRelativePath = PathUtils.sanitize(moduleRelativePath);
this.type = type;
@@ -114,11 +114,7 @@ public class DefaultIndexedFile extends DefaultInputComponent implements Indexed
*/
@Override
public String key() {
- return new StringBuilder().append(moduleKey).append(":").append(moduleRelativePath).toString();
- }
-
- public String moduleKey() {
- return moduleKey;
+ return new StringBuilder().append(projectKey).append(":").append(projectRelativePath).toString();
}
@Override
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 7138f95adcc..9908523fc9a 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
@@ -27,8 +27,8 @@ import org.sonar.api.batch.fs.InputComponent;
public abstract class DefaultInputComponent implements InputComponent {
private int id;
- public DefaultInputComponent(int batchId) {
- this.id = batchId;
+ public DefaultInputComponent(int scannerId) {
+ this.id = scannerId;
}
@Override
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputDir.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputDir.java
index 32b8ad6cb23..14a39ee1b32 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputDir.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputDir.java
@@ -36,11 +36,7 @@ public class DefaultInputDir extends DefaultInputComponent implements InputDir {
private Path moduleBaseDir;
public DefaultInputDir(String moduleKey, String relativePath) {
- this(moduleKey, relativePath, TestInputFileBuilder.nextBatchId());
- }
-
- public DefaultInputDir(String moduleKey, String relativePath, int batchId) {
- super(batchId);
+ super(-1);
this.moduleKey = moduleKey;
this.relativePath = PathUtils.sanitize(relativePath);
}
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 efa7804d512..01316b2ad30 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
@@ -174,10 +174,6 @@ public class DefaultInputFile extends DefaultInputComponent implements InputFile
return indexedFile.key();
}
- public String moduleKey() {
- return indexedFile.moduleKey();
- }
-
@Override
public int hashCode() {
return indexedFile.hashCode();
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/InputComponentTree.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/InputComponentTree.java
deleted file mode 100644
index ddb76b83624..00000000000
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/InputComponentTree.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2019 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.util.Collection;
-
-import org.sonar.api.batch.fs.InputComponent;
-
-public interface InputComponentTree {
- Collection<InputComponent> getChildren(InputComponent module);
-
- InputComponent getParent(InputComponent 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 d84961b76c5..00f9319c2d4 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
@@ -36,19 +36,19 @@ import org.sonar.api.utils.PathUtils;
/**
* Intended to be used in unit tests that need to create {@link InputFile}s.
* An InputFile is unambiguously identified by a <b>module key</b> and a <b>relative path</b>, so these parameters are mandatory.
- *
+ * <p>
* A module base directory is only needed to construct absolute paths.
- *
+ * <p>
* Examples of usage of the constructors:
- *
+ *
* <pre>
* InputFile file1 = TestInputFileBuilder.create("module1", "myfile.java").build();
* InputFile file2 = TestInputFileBuilder.create("", fs.baseDir(), myfile).build();
* </pre>
- *
+ * <p>
* file1 will have the "module1" as both module key and module base directory.
* file2 has an empty string as module key, and a relative path which is the path from the filesystem base directory to myfile.
- *
+ *
* @since 6.3
*/
public class TestInputFileBuilder {
@@ -56,7 +56,7 @@ public class TestInputFileBuilder {
private final int id;
private final String relativePath;
- private final String moduleKey;
+ private final String projectKey;
@CheckForNull
private Path projectBaseDir;
private Path moduleBaseDir;
@@ -74,29 +74,28 @@ public class TestInputFileBuilder {
private String contents;
/**
- * Create a InputFile identified by the given module key and relative path.
- * The module key will also be used as the module's base directory.
+ * Create a InputFile identified by the given project key and relative path.
*/
- public TestInputFileBuilder(String moduleKey, String relativePath) {
- this(moduleKey, relativePath, batchId++);
+ public TestInputFileBuilder(String projectKey, String relativePath) {
+ this(projectKey, relativePath, batchId++);
}
/**
* Create a InputFile with a given module key and module base directory.
- * The relative path is generated comparing the file path to the module base directory.
+ * The relative path is generated comparing the file path to the module base directory.
* filePath must point to a file that is within the module base directory.
*/
- public TestInputFileBuilder(String moduleKey, File moduleBaseDir, File filePath) {
+ public TestInputFileBuilder(String projectKey, File moduleBaseDir, File filePath) {
String relativePath = moduleBaseDir.toPath().relativize(filePath.toPath()).toString();
- this.moduleKey = moduleKey;
+ this.projectKey = projectKey;
setModuleBaseDir(moduleBaseDir.toPath());
this.relativePath = PathUtils.sanitize(relativePath);
this.id = batchId++;
}
- public TestInputFileBuilder(String moduleKey, String relativePath, int id) {
- this.moduleKey = moduleKey;
- setModuleBaseDir(Paths.get(moduleKey));
+ public TestInputFileBuilder(String projectKey, String relativePath, int id) {
+ this.projectKey = projectKey;
+ setModuleBaseDir(Paths.get(projectKey));
this.relativePath = PathUtils.sanitize(relativePath);
this.id = id;
}
@@ -217,7 +216,7 @@ public class TestInputFileBuilder {
projectBaseDir = moduleBaseDir;
}
String projectRelativePath = projectBaseDir.relativize(absolutePath).toString();
- DefaultIndexedFile indexedFile = new DefaultIndexedFile(absolutePath, moduleKey, projectRelativePath, relativePath, type, language, id, new SensorStrategy());
+ DefaultIndexedFile indexedFile = new DefaultIndexedFile(absolutePath, projectKey, projectRelativePath, relativePath, type, language, id, new SensorStrategy());
DefaultInputFile inputFile = new DefaultInputFile(indexedFile,
f -> f.setMetadata(new Metadata(lines, nonBlankLines, hash, originalLineStartOffsets, originalLineEndOffsets, lastValidOffset)),
contents);
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/PathPatternTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/PathPatternTest.java
index aa6ed4c7d97..cc2d186da44 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/PathPatternTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/PathPatternTest.java
@@ -33,11 +33,11 @@ import static org.assertj.core.api.Assertions.assertThat;
public class PathPatternTest {
@Rule
public TemporaryFolder temp = new TemporaryFolder();
- private Path moduleBasePath;
+ private Path baseDir;
@Before
public void setUp() throws IOException {
- moduleBasePath = temp.newFolder().toPath();
+ baseDir = temp.newFolder().toPath();
}
@Test
@@ -45,14 +45,14 @@ public class PathPatternTest {
PathPattern pattern = PathPattern.create("**/*Foo.java");
assertThat(pattern.toString()).isEqualTo("**/*Foo.java");
- IndexedFile indexedFile = new DefaultIndexedFile("ABCDE", moduleBasePath, "src/main/java/org/MyFoo.java", null);
+ IndexedFile indexedFile = new DefaultIndexedFile("ABCDE", baseDir, "src/main/java/org/MyFoo.java", null);
assertThat(pattern.match(indexedFile.path(), Paths.get(indexedFile.relativePath()))).isTrue();
// case sensitive by default
- indexedFile = new DefaultIndexedFile("ABCDE", moduleBasePath, "src/main/java/org/MyFoo.JAVA", null);
+ indexedFile = new DefaultIndexedFile("ABCDE", baseDir, "src/main/java/org/MyFoo.JAVA", null);
assertThat(pattern.match(indexedFile.path(), Paths.get(indexedFile.relativePath()))).isFalse();
- indexedFile = new DefaultIndexedFile("ABCDE", moduleBasePath, "src/main/java/org/Other.java", null);
+ indexedFile = new DefaultIndexedFile("ABCDE", baseDir, "src/main/java/org/Other.java", null);
assertThat(pattern.match(indexedFile.path(), Paths.get(indexedFile.relativePath()))).isFalse();
}
@@ -60,10 +60,10 @@ public class PathPatternTest {
public void match_relative_path_and_insensitive_file_extension() throws Exception {
PathPattern pattern = PathPattern.create("**/*Foo.java");
- IndexedFile indexedFile = new DefaultIndexedFile("ABCDE", moduleBasePath, "src/main/java/org/MyFoo.JAVA", null);
+ IndexedFile indexedFile = new DefaultIndexedFile("ABCDE", baseDir, "src/main/java/org/MyFoo.JAVA", null);
assertThat(pattern.match(indexedFile.path(), Paths.get(indexedFile.relativePath()), false)).isTrue();
- indexedFile = new DefaultIndexedFile("ABCDE", moduleBasePath, "src/main/java/org/Other.java", null);
+ indexedFile = new DefaultIndexedFile("ABCDE", baseDir, "src/main/java/org/Other.java", null);
assertThat(pattern.match(indexedFile.path(), Paths.get(indexedFile.relativePath()), false)).isFalse();
}
@@ -72,14 +72,14 @@ public class PathPatternTest {
PathPattern pattern = PathPattern.create("file:**/src/main/**Foo.java");
assertThat(pattern.toString()).isEqualTo("file:**/src/main/**Foo.java");
- IndexedFile indexedFile = new DefaultIndexedFile("ABCDE", moduleBasePath, "src/main/java/org/MyFoo.java", null);
+ IndexedFile indexedFile = new DefaultIndexedFile("ABCDE", baseDir, "src/main/java/org/MyFoo.java", null);
assertThat(pattern.match(indexedFile.path(), Paths.get(indexedFile.relativePath()))).isTrue();
// case sensitive by default
- indexedFile = new DefaultIndexedFile("ABCDE", moduleBasePath, "src/main/java/org/MyFoo.JAVA", null);
+ indexedFile = new DefaultIndexedFile("ABCDE", baseDir, "src/main/java/org/MyFoo.JAVA", null);
assertThat(pattern.match(indexedFile.path(), Paths.get(indexedFile.relativePath()))).isFalse();
- indexedFile = new DefaultIndexedFile("ABCDE", moduleBasePath, "src/main/java/org/Other.java", null);
+ indexedFile = new DefaultIndexedFile("ABCDE", baseDir, "src/main/java/org/Other.java", null);
assertThat(pattern.match(indexedFile.path(), Paths.get(indexedFile.relativePath()))).isFalse();
}
@@ -88,10 +88,10 @@ public class PathPatternTest {
PathPattern pattern = PathPattern.create("file:**/src/main/**Foo.java");
assertThat(pattern.toString()).isEqualTo("file:**/src/main/**Foo.java");
- IndexedFile indexedFile = new DefaultIndexedFile("ABCDE", moduleBasePath, "src/main/java/org/MyFoo.JAVA", null);
+ IndexedFile indexedFile = new DefaultIndexedFile("ABCDE", baseDir, "src/main/java/org/MyFoo.JAVA", null);
assertThat(pattern.match(indexedFile.path(), Paths.get(indexedFile.relativePath()), false)).isTrue();
- indexedFile = new DefaultIndexedFile("ABCDE", moduleBasePath, "src/main/java/org/Other.JAVA", null);
+ indexedFile = new DefaultIndexedFile("ABCDE", baseDir, "src/main/java/org/Other.JAVA", null);
assertThat(pattern.match(indexedFile.path(), Paths.get(indexedFile.relativePath()), false)).isFalse();
}