diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2017-08-01 11:37:13 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2017-08-04 14:58:16 +0200 |
commit | ef26b6a20f4a813079538b60f97dba53dc4108c1 (patch) | |
tree | e0e1b5c6a776e55dffbb10d0eca92bc6bbac1830 /sonar-scanner-engine | |
parent | 25aaeb2880043aeb8c219bcc2d178041e76062b1 (diff) | |
download | sonarqube-ef26b6a20f4a813079538b60f97dba53dc4108c1.tar.gz sonarqube-ef26b6a20f4a813079538b60f97dba53dc4108c1.zip |
SONAR-9641 Add URIPredicate
Diffstat (limited to 'sonar-scanner-engine')
12 files changed, 29 insertions, 44 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java index a1734423701..b120e1fd7a8 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java @@ -185,7 +185,7 @@ public class FileIndexer { } String parentRelativePath = getParentRelativePath(inputFile); synchronized (this) { - indexParentDir(inputFile, parentRelativePath); + indexFileAndParentDir(inputFile, parentRelativePath); progress.markAsIndexed(inputFile); } LOG.debug("'{}' indexed {}with language '{}'", relativePathStr, type == Type.TEST ? "as test " : "", inputFile.language()); @@ -202,7 +202,7 @@ public class FileIndexer { return relativePath; } - private void indexParentDir(InputFile inputFile, String parentRelativePath) { + private void indexFileAndParentDir(InputFile inputFile, String parentRelativePath) { DefaultInputDir inputDir = (DefaultInputDir) componentStore.getDir(module.key(), parentRelativePath); if (inputDir == null) { inputDir = new DefaultInputDir(module.key(), parentRelativePath, batchIdGenerator.get()); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputComponentStore.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputComponentStore.java index c43c8b05025..bec0e176f10 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputComponentStore.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputComponentStore.java @@ -41,7 +41,6 @@ import org.sonar.api.batch.fs.internal.DefaultInputDir; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.batch.fs.internal.FileExtensionPredicate; -import org.sonar.api.batch.fs.internal.FilenamePredicate; import org.sonar.api.scan.filesystem.PathResolver; /** @@ -51,7 +50,6 @@ import org.sonar.api.scan.filesystem.PathResolver; @ScannerSide public class InputComponentStore { - private final PathResolver pathResolver; private final SortedSet<String> globalLanguagesCache = new TreeSet<>(); private final Map<String, SortedSet<String>> languagesCache = new HashMap<>(); private final Map<String, InputFile> globalInputFileCache = new HashMap<>(); @@ -65,8 +63,7 @@ public class InputComponentStore { private final SetMultimap<String, InputFile> filesByExtensionCache = LinkedHashMultimap.create(); private final InputModule root; - public InputComponentStore(PathResolver pathResolver, DefaultInputModule root) { - this.pathResolver = pathResolver; + public InputComponentStore(DefaultInputModule root) { this.root = root; this.put(root); } @@ -129,7 +126,7 @@ public class InputComponentStore { inputFileCache.put(file.moduleKey(), inputFile.relativePath(), inputFile); globalInputFileCache.put(getProjectRelativePath(file), inputFile); inputComponents.put(inputFile.key(), inputFile); - filesByNameCache.put(FilenamePredicate.getFilename(inputFile), inputFile); + filesByNameCache.put(inputFile.filename(), inputFile); filesByExtensionCache.put(FileExtensionPredicate.getExtension(inputFile), inputFile); return this; } @@ -151,11 +148,11 @@ public class InputComponentStore { } private String getProjectRelativePath(DefaultInputFile file) { - return pathResolver.relativePath(getProjectBaseDir(), file.path()); + return PathResolver.relativePath(getProjectBaseDir(), file.path()); } private String getProjectRelativePath(DefaultInputDir dir) { - return pathResolver.relativePath(getProjectBaseDir(), dir.path()); + return PathResolver.relativePath(getProjectBaseDir(), dir.path()); } private Path getProjectBaseDir() { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputComponentStoreProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputComponentStoreProvider.java index 65e78e623e6..6f8ecbb655c 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputComponentStoreProvider.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputComponentStoreProvider.java @@ -21,14 +21,13 @@ package org.sonar.scanner.scan.filesystem; import org.picocontainer.injectors.ProviderAdapter; import org.sonar.api.batch.fs.internal.InputModuleHierarchy; -import org.sonar.api.scan.filesystem.PathResolver; public class InputComponentStoreProvider extends ProviderAdapter { private InputComponentStore store; - public InputComponentStore provide(PathResolver pathResolver, InputModuleHierarchy hierarchy) { + public InputComponentStore provide(InputModuleHierarchy hierarchy) { if (store == null) { - store = new InputComponentStore(pathResolver, hierarchy.root()); + store = new InputComponentStore(hierarchy.root()); } return store; } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdExecutorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdExecutorTest.java index 33717366d07..e3407fc6fe0 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdExecutorTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdExecutorTest.java @@ -19,17 +19,12 @@ */ package org.sonar.scanner.cpd; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; - import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -39,7 +34,6 @@ import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; -import org.sonar.api.scan.filesystem.PathResolver; import org.sonar.api.utils.log.LogTester; import org.sonar.api.utils.log.LoggerLevel; import org.sonar.core.util.CloseableIterator; @@ -55,6 +49,10 @@ import org.sonar.scanner.protocol.output.ScannerReportWriter; import org.sonar.scanner.report.ReportPublisher; import org.sonar.scanner.scan.filesystem.InputComponentStore; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + public class CpdExecutorTest { @Rule public LogTester logTester = new LogTester(); @@ -87,7 +85,7 @@ public class CpdExecutorTest { index = new SonarCpdBlockIndex(publisher, settings); DefaultInputModule inputModule = TestInputFileBuilder.newDefaultInputModule("foo", baseDir); - componentStore = new InputComponentStore(new PathResolver(), inputModule); + componentStore = new InputComponentStore(inputModule); executor = new CpdExecutor(settings, index, publisher, componentStore); reader = new ScannerReportReader(outputDir); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.java index 9f19852e6fd..d1bcef89d99 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.java @@ -31,7 +31,6 @@ import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.api.batch.postjob.issue.PostJobIssue; import org.sonar.api.batch.rule.Severity; import org.sonar.api.config.internal.MapSettings; -import org.sonar.api.scan.filesystem.PathResolver; import org.sonar.scanner.issue.IssueCache; import org.sonar.scanner.issue.tracking.TrackedIssue; import org.sonar.scanner.scan.filesystem.InputComponentStore; @@ -55,7 +54,7 @@ public class DefaultPostJobContextTest { public void setUp() throws IOException { issueCache = mock(IssueCache.class); DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule("foo", temp.newFolder()); - componentStore = new InputComponentStore(new PathResolver(), rootModule); + componentStore = new InputComponentStore(rootModule); settings = new MapSettings(); analysisMode = mock(AnalysisMode.class); context = new DefaultPostJobContext(settings.asConfig(), settings, issueCache, componentStore, analysisMode); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/CoveragePublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/CoveragePublisherTest.java index 395d227be62..794345ebdf7 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/CoveragePublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/CoveragePublisherTest.java @@ -30,7 +30,6 @@ import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure; import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.scan.filesystem.PathResolver; import org.sonar.core.util.CloseableIterator; import org.sonar.scanner.protocol.output.ScannerReport.LineCoverage; import org.sonar.scanner.protocol.output.ScannerReportReader; @@ -58,7 +57,7 @@ public class CoveragePublisherTest { String moduleKey = "foo"; inputFile = new TestInputFileBuilder(moduleKey, "src/Foo.php").setLines(5).build(); DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule(moduleKey, temp.newFolder()); - InputComponentStore componentCache = new InputComponentStore(new PathResolver(), rootModule); + InputComponentStore componentCache = new InputComponentStore(rootModule); componentCache.put(inputFile); measureCache = mock(MeasureCache.class); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MeasuresPublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MeasuresPublisherTest.java index 6f513738f45..224d3533423 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MeasuresPublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MeasuresPublisherTest.java @@ -33,7 +33,6 @@ import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure; import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.scan.filesystem.PathResolver; import org.sonar.core.util.CloseableIterator; import org.sonar.scanner.deprecated.test.TestPlanBuilder; import org.sonar.scanner.protocol.output.ScannerReport; @@ -69,7 +68,7 @@ public class MeasuresPublisherTest { String moduleKey = "foo"; inputModule = TestInputFileBuilder.newDefaultInputModule(moduleKey, temp.newFolder()); inputFile = new TestInputFileBuilder(moduleKey, "src/Foo.php").setPublish(true).build(); - InputComponentStore componentCache = new InputComponentStore(new PathResolver(), inputModule); + InputComponentStore componentCache = new InputComponentStore(inputModule); componentCache.put(inputFile); measureCache = mock(MeasureCache.class); when(measureCache.byComponentKey(anyString())).thenReturn(Collections.<DefaultMeasure<?>>emptyList()); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/SourcePublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/SourcePublisherTest.java index 76f0dc7aee6..8745a546aed 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/SourcePublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/SourcePublisherTest.java @@ -30,7 +30,6 @@ import org.junit.rules.TemporaryFolder; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; -import org.sonar.api.scan.filesystem.PathResolver; import org.sonar.scanner.protocol.output.ScannerReportWriter; import org.sonar.scanner.scan.filesystem.InputComponentStore; @@ -57,7 +56,7 @@ public class SourcePublisherTest { .build(); DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule(moduleKey, baseDir); - InputComponentStore componentStore = new InputComponentStore(new PathResolver(), rootModule); + InputComponentStore componentStore = new InputComponentStore(rootModule); componentStore.put(inputFile); publisher = new SourcePublisher(componentStore); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ModuleIndexerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ModuleIndexerTest.java index 63bd38a6ada..c25b4ce33f1 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ModuleIndexerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ModuleIndexerTest.java @@ -19,19 +19,17 @@ */ package org.sonar.scanner.scan; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - import java.util.Arrays; - import org.junit.Test; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.fs.InputModule; import org.sonar.api.batch.fs.internal.DefaultInputModule; -import org.sonar.api.scan.filesystem.PathResolver; import org.sonar.scanner.scan.filesystem.InputComponentStore; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + public class ModuleIndexerTest { private ModuleIndexer indexer; private DefaultComponentTree tree; @@ -39,19 +37,19 @@ public class ModuleIndexerTest { private InputComponentStore componentStore; public void createIndexer(DefaultInputModule rootModule) { - componentStore = new InputComponentStore(new PathResolver(), rootModule); + componentStore = new InputComponentStore(rootModule); tree = new DefaultComponentTree(); moduleHierarchy = mock(DefaultInputModuleHierarchy.class); indexer = new ModuleIndexer(tree, componentStore, moduleHierarchy); } - + @Test public void testIndex() { ProjectDefinition rootDef = mock(ProjectDefinition.class); ProjectDefinition def = mock(ProjectDefinition.class); when(rootDef.getParent()).thenReturn(null); when(def.getParent()).thenReturn(rootDef); - + DefaultInputModule root = mock(DefaultInputModule.class); DefaultInputModule mod1 = mock(DefaultInputModule.class); DefaultInputModule mod2 = mock(DefaultInputModule.class); @@ -61,7 +59,7 @@ public class ModuleIndexerTest { when(mod1.key()).thenReturn("mod1"); when(mod2.key()).thenReturn("mod2"); when(mod3.key()).thenReturn("mod3"); - + when(root.getKeyWithBranch()).thenReturn("root"); when(mod1.getKeyWithBranch()).thenReturn("mod1"); when(mod2.getKeyWithBranch()).thenReturn("mod2"); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/InputComponentStoreTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/InputComponentStoreTest.java index 38e480e8b7d..097d9b918b4 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/InputComponentStoreTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/InputComponentStoreTest.java @@ -35,7 +35,6 @@ import org.sonar.api.batch.fs.InputPath; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; -import org.sonar.api.scan.filesystem.PathResolver; import static org.assertj.core.api.Assertions.assertThat; @@ -58,7 +57,7 @@ public class InputComponentStoreTest { DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule(rootDef); DefaultInputModule subModule = TestInputFileBuilder.newDefaultInputModule(moduleDef); - InputComponentStore cache = new InputComponentStore(new PathResolver(), rootModule); + InputComponentStore cache = new InputComponentStore(rootModule); cache.put(subModule); DefaultInputFile fooFile = new TestInputFileBuilder(rootModuleKey, "src/main/java/Foo.java") @@ -102,7 +101,7 @@ public class InputComponentStoreTest { static class InputComponentStoreTester extends InputComponentStore { InputComponentStoreTester() throws IOException { - super(new PathResolver(), TestInputFileBuilder.newDefaultInputModule("root", temp.newFolder())); + super(TestInputFileBuilder.newDefaultInputModule("root", temp.newFolder())); } InputFile addFile(String moduleKey, String relpath, String language) { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ModuleInputComponentStoreTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ModuleInputComponentStoreTest.java index 8451685ee3c..4d2e97d0c23 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ModuleInputComponentStoreTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ModuleInputComponentStoreTest.java @@ -28,7 +28,6 @@ import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.InputModule; import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; -import org.sonar.api.scan.filesystem.PathResolver; import org.sonar.scanner.sensor.SensorStrategy; import static org.assertj.core.api.Assertions.assertThat; @@ -48,7 +47,7 @@ public class ModuleInputComponentStoreTest { @Before public void setUp() throws IOException { DefaultInputModule root = TestInputFileBuilder.newDefaultInputModule(moduleKey, temp.newFolder()); - componentStore = new InputComponentStore(new PathResolver(), root); + componentStore = new InputComponentStore(root); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/report/JSONReportTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/report/JSONReportTest.java index 276987ed552..876fcb13286 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/report/JSONReportTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/report/JSONReportTest.java @@ -45,7 +45,6 @@ import org.sonar.api.config.internal.MapSettings; import org.sonar.api.issue.Issue; import org.sonar.api.platform.Server; import org.sonar.api.rule.RuleKey; -import org.sonar.api.scan.filesystem.PathResolver; import org.sonar.scanner.issue.IssueCache; import org.sonar.scanner.issue.tracking.TrackedIssue; import org.sonar.scanner.scan.DefaultComponentTree; @@ -83,7 +82,7 @@ public class JSONReportTest { DefaultComponentTree inputComponentTree = new DefaultComponentTree(); ProjectDefinition def = ProjectDefinition.create().setBaseDir(projectBaseDir).setWorkDir(temp.newFolder()).setKey("struts"); DefaultInputModule rootModule = new DefaultInputModule(def, 1); - InputComponentStore inputComponentStore = new InputComponentStore(new PathResolver(), rootModule); + InputComponentStore inputComponentStore = new InputComponentStore(rootModule); DefaultInputModule moduleA = new DefaultInputModule(ProjectDefinition.create().setKey("struts-core").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder())); inputComponentTree.index(moduleA, rootModule); |