Skip to content

Commit

Permalink
SONAR-11459 Stop publishing modules and folders in the scanner report
Browse files Browse the repository at this point in the history
  • Loading branch information
henryju authored and sonartech committed Jan 16, 2019
1 parent 6a598e7 commit b6f878d
Show file tree
Hide file tree
Showing 49 changed files with 289 additions and 1,389 deletions.
Expand Up @@ -28,7 +28,7 @@
import org.sonar.api.config.Settings; import org.sonar.api.config.Settings;


import static java.util.function.Function.identity; import static java.util.function.Function.identity;
import static org.sonar.core.config.MultivalueProperty.parseAsCsv; import static org.sonar.api.config.internal.MultivalueProperty.parseAsCsv;


public class ConfigurationProvider extends ProviderAdapter { public class ConfigurationProvider extends ProviderAdapter {


Expand Down
Expand Up @@ -21,7 +21,7 @@


import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.sonar.api.batch.fs.InputPath; import org.sonar.api.batch.fs.internal.DefaultInputFile;


import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;


Expand All @@ -46,8 +46,8 @@ private ComponentKeys() {
// only static stuff // only static stuff
} }


public static String createEffectiveKey(String projectKey, InputPath inputPath) { public static String createEffectiveKey(String projectKey, DefaultInputFile inputPath) {
return createEffectiveKey(projectKey, inputPath.relativePath()); return createEffectiveKey(projectKey, inputPath.getProjectRelativePath());
} }


public static String createEffectiveKey(String projectKey, @Nullable String path) { public static String createEffectiveKey(String projectKey, @Nullable String path) {
Expand Down
Expand Up @@ -19,23 +19,23 @@
*/ */
package org.sonar.core.component; package org.sonar.core.component;


import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.DefaultInputFile;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;


public class ComponentKeysTest { public class ComponentKeysTest {
@Rule @Rule
public ExpectedException expectedException = ExpectedException.none(); public ExpectedException expectedException = ExpectedException.none();


@Test @Test
public void create_effective_key() { public void create_effective_key() {
InputFile file = mock(InputFile.class); DefaultInputFile file = mock(DefaultInputFile.class);
when(file.relativePath()).thenReturn("foo/Bar.php"); when(file.getProjectRelativePath()).thenReturn("foo/Bar.php");
assertThat(ComponentKeys.createEffectiveKey("my_project", file)).isEqualTo("my_project:foo/Bar.php"); assertThat(ComponentKeys.createEffectiveKey("my_project", file)).isEqualTo("my_project:foo/Bar.php");
} }


Expand Down
Expand Up @@ -165,9 +165,6 @@ interface Index {
@CheckForNull @CheckForNull
InputFile inputFile(String relativePath); InputFile inputFile(String relativePath);


@CheckForNull
InputDir inputDir(String relativePath);

/** /**
* @since 6.3 * @since 6.3
*/ */
Expand Down
Expand Up @@ -172,19 +172,15 @@ public InputDir inputDir(File dir) {
if (relativePath == null) { if (relativePath == null) {
return 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) { public DefaultFileSystem add(InputFile inputFile) {
cache.add(inputFile); cache.add(inputFile);
return this; return this;
} }


public DefaultFileSystem add(DefaultInputDir inputDir) {
cache.add(inputDir);
return this;
}

@Override @Override
public SortedSet<String> languages() { public SortedSet<String> languages() {
return cache.languages(); return cache.languages();
Expand All @@ -199,16 +195,10 @@ public abstract static class Cache implements Index {


protected abstract void doAdd(InputFile inputFile); protected abstract void doAdd(InputFile inputFile);


protected abstract void doAdd(InputDir inputDir);

final void add(InputFile inputFile) { final void add(InputFile inputFile) {
doAdd(inputFile); doAdd(inputFile);
} }


public void add(InputDir inputDir) {
doAdd(inputDir);
}

protected abstract SortedSet<String> languages(); protected abstract SortedSet<String> languages();
} }


Expand All @@ -217,7 +207,6 @@ public void add(InputDir inputDir) {
*/ */
private static class MapCache extends Cache { private static class MapCache extends Cache {
private final Map<String, InputFile> fileMap = new HashMap<>(); 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> filesByNameCache = LinkedHashMultimap.create();
private final SetMultimap<String, InputFile> filesByExtensionCache = LinkedHashMultimap.create(); private final SetMultimap<String, InputFile> filesByExtensionCache = LinkedHashMultimap.create();
private SortedSet<String> languages = new TreeSet<>(); private SortedSet<String> languages = new TreeSet<>();
Expand All @@ -232,11 +221,6 @@ public InputFile inputFile(String relativePath) {
return fileMap.get(relativePath); return fileMap.get(relativePath);
} }


@Override
public InputDir inputDir(String relativePath) {
return dirMap.get(relativePath);
}

@Override @Override
public Iterable<InputFile> getFilesByName(String filename) { public Iterable<InputFile> getFilesByName(String filename) {
return filesByNameCache.get(filename); return filesByNameCache.get(filename);
Expand All @@ -257,11 +241,6 @@ protected void doAdd(InputFile inputFile) {
filesByExtensionCache.put(FileExtensionPredicate.getExtension(inputFile), inputFile); filesByExtensionCache.put(FileExtensionPredicate.getExtension(inputFile), inputFile);
} }


@Override
protected void doAdd(InputDir inputDir) {
dirMap.put(inputDir.relativePath(), inputDir);
}

@Override @Override
protected SortedSet<String> languages() { protected SortedSet<String> languages() {
return languages; return languages;
Expand Down
Expand Up @@ -39,7 +39,7 @@
public class DefaultIndexedFile extends DefaultInputComponent implements IndexedFile { public class DefaultIndexedFile extends DefaultInputComponent implements IndexedFile {
private final String projectRelativePath; private final String projectRelativePath;
private final String moduleRelativePath; private final String moduleRelativePath;
private final String moduleKey; private final String projectKey;
private final String language; private final String language;
private final Type type; private final Type type;
private final Path absolutePath; private final Path absolutePath;
Expand All @@ -48,15 +48,15 @@ public class DefaultIndexedFile extends DefaultInputComponent implements Indexed
/** /**
* Testing purposes only! * Testing purposes only!
*/ */
public DefaultIndexedFile(String moduleKey, Path baseDir, String relativePath, @Nullable String language) { public DefaultIndexedFile(String projectKey, Path baseDir, String relativePath, @Nullable String language) {
this(baseDir.resolve(relativePath), moduleKey, relativePath, relativePath, Type.MAIN, language, TestInputFileBuilder.nextBatchId(), this(baseDir.resolve(relativePath), projectKey, relativePath, relativePath, Type.MAIN, language, TestInputFileBuilder.nextBatchId(),
new SensorStrategy()); 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) { SensorStrategy sensorStrategy) {
super(batchId); super(batchId);
this.moduleKey = moduleKey; this.projectKey = projectKey;
this.projectRelativePath = PathUtils.sanitize(projectRelativePath); this.projectRelativePath = PathUtils.sanitize(projectRelativePath);
this.moduleRelativePath = PathUtils.sanitize(moduleRelativePath); this.moduleRelativePath = PathUtils.sanitize(moduleRelativePath);
this.type = type; this.type = type;
Expand Down Expand Up @@ -114,11 +114,7 @@ public Type type() {
*/ */
@Override @Override
public String key() { public String key() {
return new StringBuilder().append(moduleKey).append(":").append(moduleRelativePath).toString(); return new StringBuilder().append(projectKey).append(":").append(projectRelativePath).toString();
}

public String moduleKey() {
return moduleKey;
} }


@Override @Override
Expand Down
Expand Up @@ -27,8 +27,8 @@
public abstract class DefaultInputComponent implements InputComponent { public abstract class DefaultInputComponent implements InputComponent {
private int id; private int id;


public DefaultInputComponent(int batchId) { public DefaultInputComponent(int scannerId) {
this.id = batchId; this.id = scannerId;
} }


@Override @Override
Expand Down
Expand Up @@ -36,11 +36,7 @@ public class DefaultInputDir extends DefaultInputComponent implements InputDir {
private Path moduleBaseDir; private Path moduleBaseDir;


public DefaultInputDir(String moduleKey, String relativePath) { public DefaultInputDir(String moduleKey, String relativePath) {
this(moduleKey, relativePath, TestInputFileBuilder.nextBatchId()); super(-1);
}

public DefaultInputDir(String moduleKey, String relativePath, int batchId) {
super(batchId);
this.moduleKey = moduleKey; this.moduleKey = moduleKey;
this.relativePath = PathUtils.sanitize(relativePath); this.relativePath = PathUtils.sanitize(relativePath);
} }
Expand Down
Expand Up @@ -174,10 +174,6 @@ public String key() {
return indexedFile.key(); return indexedFile.key();
} }


public String moduleKey() {
return indexedFile.moduleKey();
}

@Override @Override
public int hashCode() { public int hashCode() {
return indexedFile.hashCode(); return indexedFile.hashCode();
Expand Down

This file was deleted.

Expand Up @@ -36,27 +36,27 @@
/** /**
* Intended to be used in unit tests that need to create {@link InputFile}s. * 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. * 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. * A module base directory is only needed to construct absolute paths.
* * <p>
* Examples of usage of the constructors: * Examples of usage of the constructors:
* *
* <pre> * <pre>
* InputFile file1 = TestInputFileBuilder.create("module1", "myfile.java").build(); * InputFile file1 = TestInputFileBuilder.create("module1", "myfile.java").build();
* InputFile file2 = TestInputFileBuilder.create("", fs.baseDir(), myfile).build(); * InputFile file2 = TestInputFileBuilder.create("", fs.baseDir(), myfile).build();
* </pre> * </pre>
* * <p>
* file1 will have the "module1" as both module key and module base directory. * 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. * 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 * @since 6.3
*/ */
public class TestInputFileBuilder { public class TestInputFileBuilder {
private static int batchId = 1; private static int batchId = 1;


private final int id; private final int id;
private final String relativePath; private final String relativePath;
private final String moduleKey; private final String projectKey;
@CheckForNull @CheckForNull
private Path projectBaseDir; private Path projectBaseDir;
private Path moduleBaseDir; private Path moduleBaseDir;
Expand All @@ -74,29 +74,28 @@ public class TestInputFileBuilder {
private String contents; private String contents;


/** /**
* Create a InputFile identified by the given module key and relative path. * Create a InputFile identified by the given project key and relative path.
* The module key will also be used as the module's base directory.
*/ */
public TestInputFileBuilder(String moduleKey, String relativePath) { public TestInputFileBuilder(String projectKey, String relativePath) {
this(moduleKey, relativePath, batchId++); this(projectKey, relativePath, batchId++);
} }


/** /**
* Create a InputFile with a given module key and module base directory. * 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. * 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(); String relativePath = moduleBaseDir.toPath().relativize(filePath.toPath()).toString();
this.moduleKey = moduleKey; this.projectKey = projectKey;
setModuleBaseDir(moduleBaseDir.toPath()); setModuleBaseDir(moduleBaseDir.toPath());
this.relativePath = PathUtils.sanitize(relativePath); this.relativePath = PathUtils.sanitize(relativePath);
this.id = batchId++; this.id = batchId++;
} }


public TestInputFileBuilder(String moduleKey, String relativePath, int id) { public TestInputFileBuilder(String projectKey, String relativePath, int id) {
this.moduleKey = moduleKey; this.projectKey = projectKey;
setModuleBaseDir(Paths.get(moduleKey)); setModuleBaseDir(Paths.get(projectKey));
this.relativePath = PathUtils.sanitize(relativePath); this.relativePath = PathUtils.sanitize(relativePath);
this.id = id; this.id = id;
} }
Expand Down Expand Up @@ -217,7 +216,7 @@ public DefaultInputFile build() {
projectBaseDir = moduleBaseDir; projectBaseDir = moduleBaseDir;
} }
String projectRelativePath = projectBaseDir.relativize(absolutePath).toString(); 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, DefaultInputFile inputFile = new DefaultInputFile(indexedFile,
f -> f.setMetadata(new Metadata(lines, nonBlankLines, hash, originalLineStartOffsets, originalLineEndOffsets, lastValidOffset)), f -> f.setMetadata(new Metadata(lines, nonBlankLines, hash, originalLineStartOffsets, originalLineEndOffsets, lastValidOffset)),
contents); contents);
Expand Down

0 comments on commit b6f878d

Please sign in to comment.