]> source.dussan.org Git - sonarqube.git/commitdiff
Extract implementation from plugin API - Scanner FS
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Wed, 5 Jun 2019 16:01:49 +0000 (11:01 -0500)
committerSonarTech <sonartech@sonarsource.com>
Fri, 12 Jul 2019 18:21:14 +0000 (20:21 +0200)
180 files changed:
plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SignificantCodeSensorTest.java
plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SymbolReferencesSensorTest.java
plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SyntaxHighlightingSensorTest.java
plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/AnalysisErrorSensorTest.java
plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/OneIssuePerLineSensorTest.java
plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/scm/XooBlameCommandTest.java
sonar-core/src/main/java/org/sonar/core/component/ComponentKeys.java
sonar-core/src/test/java/org/sonar/core/component/ComponentKeysTest.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AbstractProjectOrModule.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultIndexedFile.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputComponent.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputDir.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputModule.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputProject.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultTextPointer.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultTextRange.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/InputModuleHierarchy.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/code/internal/DefaultSignificantCode.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/code/internal/package-info.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/internal/DefaultCoverage.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/internal/package-info.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/cpd/internal/DefaultCpdTokens.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/error/internal/DefaultAnalysisError.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/error/internal/package-info.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/DefaultStorable.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorStorage.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/symbol/internal/DefaultSymbolTable.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/symbol/internal/package-info.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/issue/NoSonarFilter.java
sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputDirTest.java [deleted file]
sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputFileTest.java [deleted file]
sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputModuleTest.java [deleted file]
sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputProjectTest.java [deleted file]
sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/PathPatternTest.java
sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/TestInputFileBuilderTest.java [deleted file]
sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/code/internal/DefaultSignificantCodeTest.java [deleted file]
sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/cpd/internal/DefaultCpdTokensTest.java [deleted file]
sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/error/internal/DefaultAnalysisErrorTest.java [deleted file]
sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/symbol/internal/DefaultSymbolTableTest.java [deleted file]
sonar-plugin-api/src/test/java/org/sonar/api/issue/NoSonarFilterTest.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/AnalysisTempFolderProvider.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/CpdExecutor.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/CpdSettings.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/JavaCpdBlockIndexerSensor.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/index/SonarCpdBlockIndex.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/DefaultCoverageBlock.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/DefaultTestCase.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/DefaultTestable.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/TestPlanBuilder.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/TestableBuilder.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/fs/AbstractProjectOrModule.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/fs/DefaultFileSystem.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/fs/DefaultIndexedFile.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/fs/DefaultInputComponent.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/fs/DefaultInputDir.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/fs/DefaultInputFile.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/fs/TestInputFileBuilder.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/AbstractDefaultIssue.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultFilterableIssue.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultIssue.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultIssueLocation.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultNoSonarFilter.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssueFilters.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssuePublisher.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/EnforceIssuesFilter.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/IgnoreIssuesFilter.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsLoader.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsRegexpScanner.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/AnalysisResult.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ChangedLinesPublisher.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ReportPublisher.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/report/SourcePublisher.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/report/TestExecutionPublisher.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ProjectRepositories.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DefaultInputModuleHierarchy.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/InputModuleHierarchyProvider.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/InputProjectProvider.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleConfigurationProvider.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleIndexer.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleScanContainer.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectConfigurationProvider.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectLock.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ScanProperties.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/WorkDirectoriesInitializer.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/AbstractCoverageAndDuplicationExclusions.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/DefaultModuleFileSystem.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/DefaultProjectFileSystem.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputComponentStore.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/MetadataGenerator.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ModuleCoverageAndDuplicationExclusions.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ProjectCoverageAndDuplicationExclusions.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ProjectFileIndexer.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/StatusDetection.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/DefaultBlameOutput.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/ScmChangedFilesProvider.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/ScmConfiguration.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/ScmPublisher.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/ScmRevisionImpl.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/AbstractDefaultIssue.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultAdHocRule.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultAnalysisError.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultCoverage.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultCpdTokens.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultExternalIssue.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultHighlighting.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultIssue.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultIssueLocation.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultMeasure.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorStorage.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSignificantCode.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultStorable.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSymbolTable.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/InMemorySensorStorage.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorContext.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorsExecutor.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ProjectSensorContext.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/SensorContextTester.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/source/ZeroCoverageSensor.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/DefaultFileLinesContextTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/analysis/AnalysisTempFolderProviderTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdExecutorTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdSettingsTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/JavaCpdBlockIndexerSensorTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/ExternalIssueImporterTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/fs/DefaultInputDirTest.java [new file with mode: 0644]
sonar-scanner-engine/src/test/java/org/sonar/scanner/fs/DefaultInputFileTest.java [new file with mode: 0644]
sonar-scanner-engine/src/test/java/org/sonar/scanner/fs/DefaultInputModuleTest.java [new file with mode: 0644]
sonar-scanner-engine/src/test/java/org/sonar/scanner/fs/DefaultInputProjectTest.java [new file with mode: 0644]
sonar-scanner-engine/src/test/java/org/sonar/scanner/fs/FileMetadataTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/fs/TestInputFileBuilderTest.java [new file with mode: 0644]
sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericCoverageReportParserTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericTestExecutionReportParserTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DefaultFilterableIssueTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/IssuePublisherTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/IgnoreIssuesFilterTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsLoaderTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsRegexpScannerTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/branch/BranchMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/branch/DeprecatedBranchMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/ModuleCoverageAndDuplicationExclusionsTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/ModuleSensorsExecutorTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/ProjectCoverageExclusionsTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/report/AnalysisContextReportPublisherTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ChangedLinesPublisherTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MetadataPublisherTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/report/SourcePublisherTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultProjectRepositoriesLoaderTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/DefaultInputModuleHierarchyTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ModuleIndexerTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectLockTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ScanPropertiesTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/WorkDirectoriesInitializerTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/InputComponentStoreTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/MetadataGeneratorTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ModuleInputComponentStoreTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ProjectExclusionFiltersTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/StatusDetectionTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmChangedFilesProviderTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmConfigurationTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmRevisionImplTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultAnalysisErrorTest.java [new file with mode: 0644]
sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultCpdTokensTest.java [new file with mode: 0644]
sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultExternalIssueTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultHighlightingTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultIssueLocationTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultIssueTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultMeasureTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorStorageTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSignificantCodeTest.java [new file with mode: 0644]
sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSymbolTableTest.java [new file with mode: 0644]
sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/ModuleSensorContextTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/SensorContextTesterTest.java

index 5293d3128cfd83ddf2a0beac2b4c95e234859dc6..5bd1c1377a5c903620ffa46a8dcc6cb1b013faeb 100644 (file)
@@ -29,8 +29,8 @@ import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.TextRange;
-import org.sonar.api.batch.fs.internal.DefaultTextPointer;
-import org.sonar.api.batch.fs.internal.DefaultTextRange;
+import org.sonar.scanner.fs.DefaultTextPointer;
+import org.sonar.scanner.fs.DefaultTextRange;
 import org.sonar.scanner.fs.TestInputFileBuilder;
 import org.sonar.scanner.sensor.DefaultSensorDescriptor;
 import org.sonar.scanner.sensor.SensorContextTester;
index 2093e773d49c7075e0357a02e26056ab9687cf19..a15596379af2445aee10ea26a1f9863d28bcbdc5 100644 (file)
@@ -27,8 +27,8 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.fs.internal.DefaultTextPointer;
-import org.sonar.api.batch.fs.internal.DefaultTextRange;
+import org.sonar.scanner.fs.DefaultTextPointer;
+import org.sonar.scanner.fs.DefaultTextRange;
 import org.sonar.scanner.fs.TestInputFileBuilder;
 import org.sonar.scanner.sensor.DefaultSensorDescriptor;
 import org.sonar.scanner.sensor.SensorContextTester;
@@ -77,9 +77,9 @@ public class SymbolReferencesSensorTest {
     sensor.execute(context);
 
     assertThat(context.referencesForSymbolAt("foo:src/foo.xoo", 1, 2))
-      .containsOnly(new DefaultTextRange(new DefaultTextPointer(1, 7), new DefaultTextPointer(1,10)));
+      .containsOnly(new DefaultTextRange(new DefaultTextPointer(1, 7), new DefaultTextPointer(1, 10)));
     assertThat(context.referencesForSymbolAt("foo:src/foo.xoo", 1, 13))
-      .containsOnly(new DefaultTextRange(new DefaultTextPointer(1, 23), new DefaultTextPointer(1,33)));
+      .containsOnly(new DefaultTextRange(new DefaultTextPointer(1, 23), new DefaultTextPointer(1, 33)));
   }
 
 }
index 965d4d653e415c40fbbd6f6ed495c794d78c3473..8cc02238d0acf6a275164ebd7569e38e64a3127f 100644 (file)
@@ -26,8 +26,8 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.sensor.highlighting.TypeOfText;
+import org.sonar.scanner.fs.DefaultInputFile;
 import org.sonar.scanner.fs.TestInputFileBuilder;
 import org.sonar.scanner.sensor.DefaultSensorDescriptor;
 import org.sonar.scanner.sensor.SensorContextTester;
index c5aa5d4534c8bb06216c74515714bf1a5ad6da3c..2f7d074ca101d7048325fbeb87d58d8bc6851e35 100644 (file)
@@ -29,9 +29,9 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.fs.internal.DefaultTextPointer;
 import org.sonar.api.batch.sensor.error.AnalysisError;
+import org.sonar.scanner.fs.DefaultInputFile;
+import org.sonar.scanner.fs.DefaultTextPointer;
 import org.sonar.scanner.fs.TestInputFileBuilder;
 import org.sonar.scanner.sensor.SensorContextTester;
 
index 1d6c610ca49df7ef0af80b76572ebb0b0be1652c..67f9325575c07b59796f48f68a9012d0662dd59c 100644 (file)
 package org.sonar.xoo.rule;
 
 import java.io.IOException;
-import org.sonar.api.SonarEdition;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
+import org.sonar.api.SonarEdition;
 import org.sonar.api.SonarQubeSide;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.rule.Severity;
 import org.sonar.api.batch.sensor.issue.Issue;
 import org.sonar.api.internal.SonarRuntimeImpl;
 import org.sonar.api.utils.Version;
+import org.sonar.scanner.fs.DefaultInputFile;
 import org.sonar.scanner.fs.TestInputFileBuilder;
 import org.sonar.scanner.sensor.DefaultSensorDescriptor;
 import org.sonar.scanner.sensor.SensorContextTester;
index ef30ede34f02a2e04ad3a90061b15f9b739430f5..2b02d2df949971ae61700ebc247ebc9ec7db2550 100644 (file)
@@ -28,12 +28,12 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.scm.BlameCommand.BlameInput;
 import org.sonar.api.batch.scm.BlameCommand.BlameOutput;
 import org.sonar.api.batch.scm.BlameLine;
 import org.sonar.api.utils.DateUtils;
 import org.sonar.scanner.fs.DefaultFileSystem;
+import org.sonar.scanner.fs.DefaultInputFile;
 import org.sonar.scanner.fs.TestInputFileBuilder;
 import org.sonar.xoo.Xoo;
 
index 79330b39fe1e408ff9508a1695e981c26b089328..a661855be61725436960713a3a825243cefab7cb 100644 (file)
@@ -21,7 +21,6 @@ package org.sonar.core.component;
 
 import javax.annotation.Nullable;
 import org.apache.commons.lang.StringUtils;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
 
 import static com.google.common.base.Preconditions.checkArgument;
 
@@ -45,10 +44,6 @@ public final class ComponentKeys {
     // only static stuff
   }
 
-  public static String createEffectiveKey(String projectKey, DefaultInputFile inputPath) {
-    return createEffectiveKey(projectKey, inputPath.getProjectRelativePath());
-  }
-
   public static String createEffectiveKey(String projectKey, @Nullable String path) {
     StringBuilder sb = new StringBuilder(MAX_COMPONENT_KEY_LENGTH);
     sb.append(projectKey);
index 5187d09bd24932f95750d88aad57631ea4beca21..e476adcab740bd1c8c2eb0a872369983bc777be7 100644 (file)
@@ -22,23 +22,13 @@ package org.sonar.core.component;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
-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 {
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
 
-  @Test
-  public void create_effective_key() {
-    DefaultInputFile file = mock(DefaultInputFile.class);
-    when(file.getProjectRelativePath()).thenReturn("foo/Bar.php");
-    assertThat(ComponentKeys.createEffectiveKey("my_project", file)).isEqualTo("my_project:foo/Bar.php");
-  }
-
   @Test
   public void create_key_from_module_key_path_and_branch() {
     assertThat(ComponentKeys.createKey("module_key", "file", "origin/master")).isEqualTo("module_key:origin/master:file");
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
deleted file mode 100644 (file)
index 2f45fb0..0000000
+++ /dev/null
@@ -1,161 +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.io.File;
-import java.io.IOException;
-import java.nio.charset.Charset;
-import java.nio.file.Files;
-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.apache.commons.lang.StringUtils;
-import org.apache.commons.lang.SystemUtils;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.utils.log.Logger;
-import org.sonar.api.utils.log.Loggers;
-
-@Immutable
-public abstract class AbstractProjectOrModule extends DefaultInputComponent {
-  private static final Logger LOGGER = Loggers.get(AbstractProjectOrModule.class);
-  private final Path baseDir;
-  private final Path workDir;
-  private final String name;
-  private final String originalName;
-  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;
-  private final Charset encoding;
-
-  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.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();
-    this.encoding = initEncoding(definition);
-  }
-
-  private static Charset initEncoding(ProjectDefinition module) {
-    String encodingStr = module.properties().get(CoreProperties.ENCODING_PROPERTY);
-    Charset result;
-    if (StringUtils.isNotEmpty(encodingStr)) {
-      result = Charset.forName(StringUtils.trim(encodingStr));
-    } else {
-      result = Charset.defaultCharset();
-    }
-    return result;
-  }
-
-  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();
-    Path workingDir = workingDirAsFile.getAbsoluteFile().toPath().normalize();
-    if (SystemUtils.IS_OS_WINDOWS) {
-      try {
-        Files.createDirectories(workingDir);
-        Files.setAttribute(workingDir, "dos:hidden", true, LinkOption.NOFOLLOW_LINKS);
-      } catch (IOException e) {
-        LOGGER.warn("Failed to set working directory hidden: {}", e.getMessage());
-      }
-    }
-    return workingDir;
-  }
-
-  /**
-   * 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 getOriginalName() {
-    return originalName;
-  }
-
-  public String getName() {
-    return name;
-  }
-
-  public String getDescription() {
-    return description;
-  }
-
-  public Charset getEncoding() {
-    return encoding;
-  }
-}
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
deleted file mode 100644 (file)
index 229280f..0000000
+++ /dev/null
@@ -1,161 +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.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.concurrent.atomic.AtomicInteger;
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-import javax.annotation.concurrent.Immutable;
-import org.sonar.api.batch.fs.IndexedFile;
-import org.sonar.api.batch.fs.InputFile.Type;
-import org.sonar.api.utils.PathUtils;
-
-/**
- * @since 6.3
- */
-@Immutable
-public class DefaultIndexedFile extends DefaultInputComponent implements IndexedFile {
-  private static AtomicInteger intGenerator = new AtomicInteger(0);
-
-  private final String projectRelativePath;
-  private final String moduleRelativePath;
-  private final String projectKey;
-  private final String language;
-  private final Type type;
-  private final Path absolutePath;
-  private final SensorStrategy sensorStrategy;
-
-  /**
-   * Testing purposes only!
-   */
-  public DefaultIndexedFile(String projectKey, Path baseDir, String relativePath, @Nullable String language) {
-    this(baseDir.resolve(relativePath), projectKey, relativePath, relativePath, Type.MAIN, language, intGenerator.getAndIncrement(),
-      new SensorStrategy());
-  }
-
-  public DefaultIndexedFile(Path absolutePath, String projectKey, String projectRelativePath, String moduleRelativePath, Type type, @Nullable String language, int batchId,
-    SensorStrategy sensorStrategy) {
-    super(batchId);
-    this.projectKey = projectKey;
-    this.projectRelativePath = PathUtils.sanitize(projectRelativePath);
-    this.moduleRelativePath = PathUtils.sanitize(moduleRelativePath);
-    this.type = type;
-    this.language = language;
-    this.sensorStrategy = sensorStrategy;
-    this.absolutePath = absolutePath;
-  }
-
-  @Override
-  public String relativePath() {
-    return sensorStrategy.isGlobal() ? projectRelativePath : moduleRelativePath;
-  }
-
-  public String getModuleRelativePath() {
-    return moduleRelativePath;
-  }
-
-  public String getProjectRelativePath() {
-    return projectRelativePath;
-  }
-
-  @Override
-  public String absolutePath() {
-    return PathUtils.sanitize(path().toString());
-  }
-
-  @Override
-  public File file() {
-    return path().toFile();
-  }
-
-  @Override
-  public Path path() {
-    return absolutePath;
-  }
-
-  @Override
-  public InputStream inputStream() throws IOException {
-    return Files.newInputStream(path());
-  }
-
-  @CheckForNull
-  @Override
-  public String language() {
-    return language;
-  }
-
-  @Override
-  public Type type() {
-    return type;
-  }
-
-  /**
-   * Component key (without branch).
-   */
-  @Override
-  public String key() {
-    return new StringBuilder().append(projectKey).append(":").append(projectRelativePath).toString();
-  }
-
-  @Override
-  public boolean equals(Object o) {
-    if (this == o) {
-      return true;
-    }
-
-    if (!(o instanceof DefaultIndexedFile)) {
-      return false;
-    }
-
-    DefaultIndexedFile that = (DefaultIndexedFile) o;
-    return projectRelativePath.equals(that.projectRelativePath);
-  }
-
-  @Override
-  public int hashCode() {
-    return projectRelativePath.hashCode();
-  }
-
-  @Override
-  public String toString() {
-    return projectRelativePath;
-  }
-
-  @Override
-  public boolean isFile() {
-    return true;
-  }
-
-  @Override
-  public String filename() {
-    return path().getFileName().toString();
-  }
-
-  @Override
-  public URI uri() {
-    return path().toUri();
-  }
-}
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
deleted file mode 100644 (file)
index 19a5cce..0000000
+++ /dev/null
@@ -1,72 +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.HashSet;
-import java.util.Set;
-import org.sonar.api.batch.fs.InputComponent;
-import org.sonar.api.batch.measure.Metric;
-
-/**
- * @since 5.2
- */
-public abstract class DefaultInputComponent implements InputComponent {
-  private int id;
-  private Set<String> storedMetricKeys = new HashSet<>();
-
-  public DefaultInputComponent(int scannerId) {
-    this.id = scannerId;
-  }
-
-  @Override
-  public boolean equals(Object o) {
-    if (this == o) {
-      return true;
-    }
-    if (o == null || this.getClass() != o.getClass()) {
-      return false;
-    }
-
-    DefaultInputComponent that = (DefaultInputComponent) o;
-    return key().equals(that.key());
-  }
-
-  public int scannerId() {
-    return id;
-  }
-
-  @Override
-  public int hashCode() {
-    return key().hashCode();
-  }
-
-  @Override
-  public String toString() {
-    return "[key=" + key() + "]";
-  }
-
-  public void setHasMeasureFor(Metric metric) {
-    storedMetricKeys.add(metric.key());
-  }
-
-  public boolean hasMeasureFor(Metric metric) {
-    return storedMetricKeys.contains(metric.key());
-  }
-}
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
deleted file mode 100644 (file)
index 14a39ee..0000000
+++ /dev/null
@@ -1,122 +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.io.File;
-import java.net.URI;
-import java.nio.file.Path;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.api.batch.fs.InputDir;
-import org.sonar.api.utils.PathUtils;
-
-/**
- * @since 4.5
- */
-public class DefaultInputDir extends DefaultInputComponent implements InputDir {
-
-  private final String relativePath;
-  private final String moduleKey;
-  private Path moduleBaseDir;
-
-  public DefaultInputDir(String moduleKey, String relativePath) {
-    super(-1);
-    this.moduleKey = moduleKey;
-    this.relativePath = PathUtils.sanitize(relativePath);
-  }
-
-  @Override
-  public String relativePath() {
-    return relativePath;
-  }
-
-  @Override
-  public String absolutePath() {
-    return PathUtils.sanitize(path().toString());
-  }
-
-  @Override
-  public File file() {
-    return path().toFile();
-  }
-
-  @Override
-  public Path path() {
-    if (moduleBaseDir == null) {
-      throw new IllegalStateException("Can not return the java.nio.file.Path because module baseDir is not set (see method setModuleBaseDir(java.io.File))");
-    }
-    return moduleBaseDir.resolve(relativePath);
-  }
-
-  public String moduleKey() {
-    return moduleKey;
-  }
-
-  @Override
-  public String key() {
-    StringBuilder sb = new StringBuilder().append(moduleKey).append(":");
-    if (StringUtils.isEmpty(relativePath)) {
-      sb.append("/");
-    } else {
-      sb.append(relativePath);
-    }
-    return sb.toString();
-  }
-
-  /**
-   * For testing purpose. Will be automatically set when dir is added to {@link DefaultFileSystem}
-   */
-  public DefaultInputDir setModuleBaseDir(Path moduleBaseDir) {
-    this.moduleBaseDir = moduleBaseDir.normalize();
-    return this;
-  }
-
-  @Override
-  public boolean isFile() {
-    return false;
-  }
-
-  @Override
-  public boolean equals(Object o) {
-    if (this == o) {
-      return true;
-    }
-    if (o == null || this.getClass() != o.getClass()) {
-      return false;
-    }
-
-    DefaultInputDir that = (DefaultInputDir) o;
-    return moduleKey.equals(that.moduleKey) && relativePath.equals(that.relativePath);
-  }
-
-  @Override
-  public int hashCode() {
-    return moduleKey.hashCode() + relativePath.hashCode() * 13;
-  }
-
-  @Override
-  public String toString() {
-    return "[moduleKey=" + moduleKey + ", relative=" + relativePath + ", basedir=" + moduleBaseDir + "]";
-  }
-
-  @Override
-  public URI uri() {
-    return path().toUri();
-  }
-}
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
deleted file mode 100644 (file)
index 19381e4..0000000
+++ /dev/null
@@ -1,439 +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.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.nio.charset.Charset;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.BitSet;
-import java.util.Collection;
-import java.util.Optional;
-import java.util.Set;
-import java.util.function.Consumer;
-import java.util.stream.Collectors;
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-import org.apache.commons.io.ByteOrderMark;
-import org.apache.commons.io.input.BOMInputStream;
-import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.fs.TextPointer;
-import org.sonar.api.batch.fs.TextRange;
-
-import static org.sonar.api.utils.Preconditions.checkArgument;
-import static org.sonar.api.utils.Preconditions.checkState;
-
-/**
- * @since 4.2
- * To create {@link InputFile} in tests, use TestInputFileBuilder.
- */
-public class DefaultInputFile extends DefaultInputComponent implements InputFile {
-
-  private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
-
-  private final DefaultIndexedFile indexedFile;
-  private final String contents;
-  private final Consumer<DefaultInputFile> metadataGenerator;
-
-  private boolean published;
-  private boolean excludedForCoverage;
-  private boolean excludedForDuplication;
-  private boolean ignoreAllIssues;
-  // Lazy init to save memory
-  private BitSet noSonarLines;
-  private Status status;
-  private Charset charset;
-  private Metadata metadata;
-  private Collection<int[]> ignoreIssuesOnlineRanges;
-  private BitSet executableLines;
-
-  public DefaultInputFile(DefaultIndexedFile indexedFile, Consumer<DefaultInputFile> metadataGenerator) {
-    this(indexedFile, metadataGenerator, null);
-  }
-
-  // For testing
-  public DefaultInputFile(DefaultIndexedFile indexedFile, Consumer<DefaultInputFile> metadataGenerator, @Nullable String contents) {
-    super(indexedFile.scannerId());
-    this.indexedFile = indexedFile;
-    this.metadataGenerator = metadataGenerator;
-    this.metadata = null;
-    this.published = false;
-    this.excludedForCoverage = false;
-    this.contents = contents;
-  }
-
-  public void checkMetadata() {
-    if (metadata == null) {
-      metadataGenerator.accept(this);
-    }
-  }
-
-  @Override
-  public InputStream inputStream() throws IOException {
-    return contents != null ? new ByteArrayInputStream(contents.getBytes(charset()))
-      : new BOMInputStream(Files.newInputStream(path()),
-      ByteOrderMark.UTF_8, ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_16BE, ByteOrderMark.UTF_32LE, ByteOrderMark.UTF_32BE);
-  }
-
-  @Override
-  public String contents() throws IOException {
-    if (contents != null) {
-      return contents;
-    } else {
-      ByteArrayOutputStream result = new ByteArrayOutputStream();
-      try (InputStream inputStream = inputStream()) {
-        byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
-        int length;
-        while ((length = inputStream.read(buffer)) != -1) {
-          result.write(buffer, 0, length);
-        }
-      }
-      return result.toString(charset().name());
-    }
-  }
-
-  public DefaultInputFile setPublished(boolean published) {
-    this.published = published;
-    return this;
-  }
-
-  public boolean isPublished() {
-    return published;
-  }
-
-  public DefaultInputFile setExcludedForCoverage(boolean excludedForCoverage) {
-    this.excludedForCoverage = excludedForCoverage;
-    return this;
-  }
-
-  public boolean isExcludedForCoverage() {
-    return excludedForCoverage;
-  }
-
-  public DefaultInputFile setExcludedForDuplication(boolean excludedForDuplication) {
-    this.excludedForDuplication = excludedForDuplication;
-    return this;
-  }
-
-  public boolean isExcludedForDuplication() {
-    return excludedForDuplication;
-  }
-
-  /**
-   * @deprecated since 6.6
-   */
-  @Deprecated
-  @Override
-  public String relativePath() {
-    return indexedFile.relativePath();
-  }
-
-  public String getModuleRelativePath() {
-    return indexedFile.getModuleRelativePath();
-  }
-
-  public String getProjectRelativePath() {
-    return indexedFile.getProjectRelativePath();
-  }
-
-  @Override
-  public String absolutePath() {
-    return indexedFile.absolutePath();
-  }
-
-  @Override
-  public File file() {
-    return indexedFile.file();
-  }
-
-  @Override
-  public Path path() {
-    return indexedFile.path();
-  }
-
-  @CheckForNull
-  @Override
-  public String language() {
-    return indexedFile.language();
-  }
-
-  @Override
-  public Type type() {
-    return indexedFile.type();
-  }
-
-  /**
-   * Component key (without branch).
-   */
-  @Override
-  public String key() {
-    return indexedFile.key();
-  }
-
-  @Override
-  public int hashCode() {
-    return indexedFile.hashCode();
-  }
-
-  @Override
-  public String toString() {
-    return indexedFile.toString();
-  }
-
-  /**
-   * {@link #setStatus(org.sonar.api.batch.fs.InputFile.Status)}
-   */
-  @Override
-  public Status status() {
-    checkMetadata();
-    return status;
-  }
-
-  @Override
-  public int lines() {
-    checkMetadata();
-    return metadata.lines();
-  }
-
-  @Override
-  public boolean isEmpty() {
-    checkMetadata();
-    return metadata.isEmpty();
-  }
-
-  @Override
-  public Charset charset() {
-    checkMetadata();
-    return charset;
-  }
-
-  public int lastValidOffset() {
-    checkMetadata();
-    return metadata.lastValidOffset();
-  }
-
-  /**
-   * Digest hash of the file.
-   */
-  public String hash() {
-    checkMetadata();
-    return metadata.hash();
-  }
-
-  public int nonBlankLines() {
-    checkMetadata();
-    return metadata.nonBlankLines();
-  }
-
-  public int[] originalLineStartOffsets() {
-    checkMetadata();
-    checkState(metadata.originalLineStartOffsets() != null, "InputFile is not properly initialized.");
-    checkState(metadata.originalLineStartOffsets().length == metadata.lines(),
-      "InputFile is not properly initialized. 'originalLineStartOffsets' property length should be equal to 'lines'");
-    return metadata.originalLineStartOffsets();
-  }
-
-  public int[] originalLineEndOffsets() {
-    checkMetadata();
-    checkState(metadata.originalLineEndOffsets() != null, "InputFile is not properly initialized.");
-    checkState(metadata.originalLineEndOffsets().length == metadata.lines(),
-      "InputFile is not properly initialized. 'originalLineEndOffsets' property length should be equal to 'lines'");
-    return metadata.originalLineEndOffsets();
-  }
-
-  @Override
-  public TextPointer newPointer(int line, int lineOffset) {
-    checkMetadata();
-    DefaultTextPointer textPointer = new DefaultTextPointer(line, lineOffset);
-    checkValid(textPointer, "pointer");
-    return textPointer;
-  }
-
-  @Override
-  public TextRange newRange(TextPointer start, TextPointer end) {
-    checkMetadata();
-    checkValid(start, "start pointer");
-    checkValid(end, "end pointer");
-    return newRangeValidPointers(start, end, false);
-  }
-
-  @Override
-  public TextRange newRange(int startLine, int startLineOffset, int endLine, int endLineOffset) {
-    checkMetadata();
-    TextPointer start = newPointer(startLine, startLineOffset);
-    TextPointer end = newPointer(endLine, endLineOffset);
-    return newRangeValidPointers(start, end, false);
-  }
-
-  @Override
-  public TextRange selectLine(int line) {
-    checkMetadata();
-    TextPointer startPointer = newPointer(line, 0);
-    TextPointer endPointer = newPointer(line, lineLength(line));
-    return newRangeValidPointers(startPointer, endPointer, true);
-  }
-
-  public void validate(TextRange range) {
-    checkMetadata();
-    checkValid(range.start(), "start pointer");
-    checkValid(range.end(), "end pointer");
-  }
-
-  /**
-   * Create Range from global offsets. Used for backward compatibility with older API.
-   */
-  public TextRange newRange(int startOffset, int endOffset) {
-    checkMetadata();
-    return newRangeValidPointers(newPointer(startOffset), newPointer(endOffset), false);
-  }
-
-  public TextPointer newPointer(int globalOffset) {
-    checkMetadata();
-    checkArgument(globalOffset >= 0, "%s is not a valid offset for a file", globalOffset);
-    checkArgument(globalOffset <= lastValidOffset(), "%s is not a valid offset for file %s. Max offset is %s", globalOffset, this, lastValidOffset());
-    int line = findLine(globalOffset);
-    int startLineOffset = originalLineStartOffsets()[line - 1];
-    // In case the global offset is between \r and \n, move the pointer to a valid location
-    return new DefaultTextPointer(line, Math.min(globalOffset, originalLineEndOffsets()[line - 1]) - startLineOffset);
-  }
-
-  public DefaultInputFile setStatus(Status status) {
-    this.status = status;
-    return this;
-  }
-
-  public DefaultInputFile setCharset(Charset charset) {
-    this.charset = charset;
-    return this;
-  }
-
-  private void checkValid(TextPointer pointer, String owner) {
-    checkArgument(pointer.line() >= 1, "%s is not a valid line for a file", pointer.line());
-    checkArgument(pointer.line() <= this.metadata.lines(), "%s is not a valid line for %s. File %s has %s line(s)", pointer.line(), owner, this, metadata.lines());
-    checkArgument(pointer.lineOffset() >= 0, "%s is not a valid line offset for a file", pointer.lineOffset());
-    int lineLength = lineLength(pointer.line());
-    checkArgument(pointer.lineOffset() <= lineLength,
-      "%s is not a valid line offset for %s. File %s has %s character(s) at line %s", pointer.lineOffset(), owner, this, lineLength, pointer.line());
-  }
-
-  private int lineLength(int line) {
-    return originalLineEndOffsets()[line - 1] - originalLineStartOffsets()[line - 1];
-  }
-
-  private static TextRange newRangeValidPointers(TextPointer start, TextPointer end, boolean acceptEmptyRange) {
-    checkArgument(acceptEmptyRange ? (start.compareTo(end) <= 0) : (start.compareTo(end) < 0),
-      "Start pointer %s should be before end pointer %s", start, end);
-    return new DefaultTextRange(start, end);
-  }
-
-  private int findLine(int globalOffset) {
-    return Math.abs(Arrays.binarySearch(originalLineStartOffsets(), globalOffset) + 1);
-  }
-
-  public DefaultInputFile setMetadata(Metadata metadata) {
-    this.metadata = metadata;
-    return this;
-  }
-
-  @Override
-  public boolean equals(Object obj) {
-    if (obj == null) {
-      return false;
-    }
-
-    if (this.getClass() != obj.getClass()) {
-      return false;
-    }
-
-    DefaultInputFile that = (DefaultInputFile) obj;
-    return this.getProjectRelativePath().equals(that.getProjectRelativePath());
-  }
-
-  @Override
-  public boolean isFile() {
-    return true;
-  }
-
-  @Override
-  public String filename() {
-    return indexedFile.filename();
-  }
-
-  @Override
-  public URI uri() {
-    return indexedFile.uri();
-  }
-
-  public void noSonarAt(Set<Integer> noSonarLines) {
-    if (this.noSonarLines == null) {
-      this.noSonarLines = new BitSet(lines());
-    }
-    noSonarLines.forEach(l -> this.noSonarLines.set(l - 1));
-  }
-
-  public boolean hasNoSonarAt(int line) {
-    if (this.noSonarLines == null) {
-      return false;
-    }
-    return this.noSonarLines.get(line - 1);
-  }
-
-  public boolean isIgnoreAllIssues() {
-    return ignoreAllIssues;
-  }
-
-  public void setIgnoreAllIssues(boolean ignoreAllIssues) {
-    this.ignoreAllIssues = ignoreAllIssues;
-  }
-
-  public void addIgnoreIssuesOnLineRanges(Collection<int[]> lineRanges) {
-    if (this.ignoreIssuesOnlineRanges == null) {
-      this.ignoreIssuesOnlineRanges = new ArrayList<>();
-    }
-    this.ignoreIssuesOnlineRanges.addAll(lineRanges);
-  }
-
-  public boolean isIgnoreAllIssuesOnLine(@Nullable Integer line) {
-    if (line == null || ignoreIssuesOnlineRanges == null) {
-      return false;
-    }
-    return ignoreIssuesOnlineRanges.stream().anyMatch(r -> r[0] <= line && line <= r[1]);
-  }
-
-  public void setExecutableLines(Set<Integer> executableLines) {
-    checkState(this.executableLines == null, "Executable lines have already been saved for file: {}", this.toString());
-    this.executableLines = new BitSet(lines());
-    executableLines.forEach(l -> this.executableLines.set(l - 1));
-  }
-
-  public Optional<Set<Integer>> getExecutableLines() {
-    if (this.executableLines == null) {
-      return Optional.empty();
-    }
-    return Optional.of(this.executableLines.stream().map(i -> i + 1).boxed().collect(Collectors.toSet()));
-  }
-}
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
deleted file mode 100644 (file)
index 73fa8dd..0000000
+++ /dev/null
@@ -1,81 +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.io.File;
-import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
-import javax.annotation.CheckForNull;
-import javax.annotation.concurrent.Immutable;
-import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.batch.fs.InputModule;
-import org.sonar.api.scan.filesystem.PathResolver;
-
-import static org.sonar.api.config.internal.MultivalueProperty.parseAsCsv;
-
-@Immutable
-public class DefaultInputModule extends AbstractProjectOrModule implements InputModule {
-
-  private final List<Path> sourceDirsOrFiles;
-  private final List<Path> testDirsOrFiles;
-
-  /**
-   * For testing only!
-   */
-  public DefaultInputModule(ProjectDefinition definition) {
-    this(definition, 0);
-  }
-
-  public DefaultInputModule(ProjectDefinition definition, int scannerComponentId) {
-    super(definition, scannerComponentId);
-
-    this.sourceDirsOrFiles = initSources(definition, ProjectDefinition.SOURCES_PROPERTY);
-    this.testDirsOrFiles = initSources(definition, ProjectDefinition.TESTS_PROPERTY);
-  }
-
-  @CheckForNull
-  private List<Path> initSources(ProjectDefinition module, String propertyKey) {
-    if (!module.properties().containsKey(propertyKey)) {
-      return null;
-    }
-    List<Path> result = new ArrayList<>();
-    PathResolver pathResolver = new PathResolver();
-    String srcPropValue = module.properties().get(propertyKey);
-    if (srcPropValue != null) {
-      for (String sourcePath : parseAsCsv(propertyKey, srcPropValue)) {
-        File dirOrFile = pathResolver.relativeFile(getBaseDir().toFile(), sourcePath);
-        if (dirOrFile.exists()) {
-          result.add(dirOrFile.toPath());
-        }
-      }
-    }
-    return result;
-  }
-
-  public Optional<List<Path>> getSourceDirsOrFiles() {
-    return Optional.ofNullable(sourceDirsOrFiles);
-  }
-
-  public Optional<List<Path>> getTestDirsOrFiles() {
-    return Optional.ofNullable(testDirsOrFiles);
-  }
-}
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
deleted file mode 100644 (file)
index b6f07c8..0000000
+++ /dev/null
@@ -1,39 +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 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 {
-
-  /**
-   * For testing only!
-   */
-  public DefaultInputProject(ProjectDefinition definition) {
-    super(definition, 0);
-  }
-
-  public DefaultInputProject(ProjectDefinition definition, int scannerComponentId) {
-    super(definition, scannerComponentId);
-  }
-}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultTextPointer.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultTextPointer.java
deleted file mode 100644 (file)
index c10efd0..0000000
+++ /dev/null
@@ -1,74 +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 org.sonar.api.batch.fs.TextPointer;
-
-/**
- * @since 5.2
- */
-public class DefaultTextPointer implements TextPointer {
-
-  private final int line;
-  private final int lineOffset;
-
-  public DefaultTextPointer(int line, int lineOffset) {
-    this.line = line;
-    this.lineOffset = lineOffset;
-  }
-
-  @Override
-  public int line() {
-    return line;
-  }
-
-  @Override
-  public int lineOffset() {
-    return lineOffset;
-  }
-
-  @Override
-  public String toString() {
-    return "[line=" + line + ", lineOffset=" + lineOffset + "]";
-  }
-
-  @Override
-  public boolean equals(Object obj) {
-    if (!(obj instanceof DefaultTextPointer)) {
-      return false;
-    }
-    DefaultTextPointer other = (DefaultTextPointer) obj;
-    return other.line == this.line && other.lineOffset == this.lineOffset;
-  }
-
-  @Override
-  public int hashCode() {
-    return 37 * this.line + lineOffset;
-  }
-
-  @Override
-  public int compareTo(TextPointer o) {
-    if (this.line == o.line()) {
-      return Integer.compare(this.lineOffset, o.lineOffset());
-    }
-    return Integer.compare(this.line, o.line());
-  }
-
-}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultTextRange.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultTextRange.java
deleted file mode 100644 (file)
index efef79c..0000000
+++ /dev/null
@@ -1,74 +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 org.sonar.api.batch.fs.TextPointer;
-import org.sonar.api.batch.fs.TextRange;
-
-/**
- * @since 5.2
- */
-public class DefaultTextRange implements TextRange {
-
-  private final TextPointer start;
-  private final TextPointer end;
-
-  public DefaultTextRange(TextPointer start, TextPointer end) {
-    this.start = start;
-    this.end = end;
-  }
-
-  @Override
-  public TextPointer start() {
-    return start;
-  }
-
-  @Override
-  public TextPointer end() {
-    return end;
-  }
-
-  @Override
-  public boolean overlap(TextRange another) {
-    // [A,B] and [C,D]
-    // B > C && D > A
-    return this.end.compareTo(another.start()) > 0 && another.end().compareTo(this.start) > 0;
-  }
-
-  @Override
-  public String toString() {
-    return "Range[from " + start + " to " + end + "]";
-  }
-
-  @Override
-  public boolean equals(Object obj) {
-    if (!(obj instanceof DefaultTextRange)) {
-      return false;
-    }
-    DefaultTextRange other = (DefaultTextRange) obj;
-    return start.equals(other.start) && end.equals(other.end);
-  }
-
-  @Override
-  public int hashCode() {
-    return start.hashCode() * 17 + end.hashCode();
-  }
-
-}
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
deleted file mode 100644 (file)
index b3304cb..0000000
+++ /dev/null
@@ -1,42 +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 javax.annotation.CheckForNull;
-import javax.annotation.concurrent.Immutable;
-
-@Immutable
-public interface InputModuleHierarchy {
-  DefaultInputModule root();
-  
-  boolean isRoot(DefaultInputModule module);
-
-  Collection<DefaultInputModule> children(DefaultInputModule module);
-
-  @CheckForNull
-  DefaultInputModule parent(DefaultInputModule module);
-  
-  @CheckForNull
-  String relativePath(DefaultInputModule module);
-
-  @CheckForNull
-  String relativePathToRoot(DefaultInputModule module);
-}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/code/internal/DefaultSignificantCode.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/code/internal/DefaultSignificantCode.java
deleted file mode 100644 (file)
index 40ea16b..0000000
+++ /dev/null
@@ -1,76 +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.sensor.code.internal;
-
-import java.util.SortedMap;
-import java.util.TreeMap;
-import javax.annotation.Nullable;
-import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.fs.TextRange;
-import org.sonar.api.batch.sensor.code.NewSignificantCode;
-import org.sonar.api.batch.sensor.internal.DefaultStorable;
-import org.sonar.api.batch.sensor.internal.SensorStorage;
-import org.sonar.api.utils.Preconditions;
-
-public class DefaultSignificantCode extends DefaultStorable implements NewSignificantCode {
-  private SortedMap<Integer, TextRange> significantCodePerLine = new TreeMap<>();
-  private InputFile inputFile;
-
-  public DefaultSignificantCode() {
-    super();
-  }
-
-  public DefaultSignificantCode(@Nullable SensorStorage storage) {
-    super(storage);
-  }
-
-  @Override
-  public DefaultSignificantCode onFile(InputFile inputFile) {
-    this.inputFile = inputFile;
-    return this;
-  }
-
-  @Override
-  public DefaultSignificantCode addRange(TextRange range) {
-    Preconditions.checkState(this.inputFile != null, "addRange() should be called after on()");
-
-    int line = range.start().line();
-
-    Preconditions.checkArgument(line == range.end().line(), "Ranges of significant code must be located in a single line");
-    Preconditions.checkState(!significantCodePerLine.containsKey(line), "Significant code was already reported for line '%s'. Can only report once per line.", line);
-
-    significantCodePerLine.put(line, range);
-    return this;
-  }
-
-  @Override
-  protected void doSave() {
-    Preconditions.checkState(inputFile != null, "Call onFile() first");
-    storage.store(this);
-  }
-
-  public InputFile inputFile() {
-    return inputFile;
-  }
-
-  public SortedMap<Integer, TextRange> significantCodePerLine() {
-    return significantCodePerLine;
-  }
-}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/code/internal/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/code/internal/package-info.java
deleted file mode 100644 (file)
index 95f3885..0000000
+++ /dev/null
@@ -1,21 +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.
- */
-@javax.annotation.ParametersAreNonnullByDefault
-package org.sonar.api.batch.sensor.code.internal;
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/internal/DefaultCoverage.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/internal/DefaultCoverage.java
deleted file mode 100644 (file)
index 94fc188..0000000
+++ /dev/null
@@ -1,158 +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.sensor.coverage.internal;
-
-import java.util.Collections;
-import java.util.SortedMap;
-import java.util.TreeMap;
-import javax.annotation.Nullable;
-import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.sensor.coverage.CoverageType;
-import org.sonar.api.batch.sensor.coverage.NewCoverage;
-import org.sonar.api.batch.sensor.internal.DefaultStorable;
-import org.sonar.api.batch.sensor.internal.SensorStorage;
-
-import static java.util.Objects.requireNonNull;
-import static org.sonar.api.utils.Preconditions.checkState;
-
-public class DefaultCoverage extends DefaultStorable implements NewCoverage {
-
-  private InputFile inputFile;
-  private CoverageType type;
-  private int totalCoveredLines = 0;
-  private int totalConditions = 0;
-  private int totalCoveredConditions = 0;
-  private SortedMap<Integer, Integer> hitsByLine = new TreeMap<>();
-  private SortedMap<Integer, Integer> conditionsByLine = new TreeMap<>();
-  private SortedMap<Integer, Integer> coveredConditionsByLine = new TreeMap<>();
-
-  public DefaultCoverage() {
-    super();
-  }
-
-  public DefaultCoverage(@Nullable SensorStorage storage) {
-    super(storage);
-  }
-
-  @Override
-  public DefaultCoverage onFile(InputFile inputFile) {
-    this.inputFile = inputFile;
-    return this;
-  }
-
-  public InputFile inputFile() {
-    return inputFile;
-  }
-
-  @Override
-  public NewCoverage ofType(CoverageType type) {
-    this.type = requireNonNull(type, "type can't be null");
-    return this;
-  }
-
-  public CoverageType type() {
-    return type;
-  }
-
-  @Override
-  public NewCoverage lineHits(int line, int hits) {
-    validateFile();
-    if (isExcluded()) {
-      return this;
-    }
-    validateLine(line);
-
-    if (!hitsByLine.containsKey(line)) {
-      hitsByLine.put(line, hits);
-      if (hits > 0) {
-        totalCoveredLines += 1;
-      }
-    }
-    return this;
-  }
-
-  private void validateLine(int line) {
-    checkState(line <= inputFile.lines(), "Line %s is out of range in the file %s (lines: %s)", line, inputFile, inputFile.lines());
-    checkState(line > 0, "Line number must be strictly positive: %s", line);
-  }
-
-  private void validateFile() {
-    requireNonNull(inputFile, "Call onFile() first");
-  }
-
-  @Override
-  public NewCoverage conditions(int line, int conditions, int coveredConditions) {
-    validateFile();
-    if (isExcluded()) {
-      return this;
-    }
-    validateLine(line);
-
-    if (conditions > 0 && !conditionsByLine.containsKey(line)) {
-      totalConditions += conditions;
-      totalCoveredConditions += coveredConditions;
-      conditionsByLine.put(line, conditions);
-      coveredConditionsByLine.put(line, coveredConditions);
-    }
-    return this;
-  }
-
-  public int coveredLines() {
-    return totalCoveredLines;
-  }
-
-  public int linesToCover() {
-    return hitsByLine.size();
-  }
-
-  public int conditions() {
-    return totalConditions;
-  }
-
-  public int coveredConditions() {
-    return totalCoveredConditions;
-  }
-
-  public SortedMap<Integer, Integer> hitsByLine() {
-    return Collections.unmodifiableSortedMap(hitsByLine);
-  }
-
-  public SortedMap<Integer, Integer> conditionsByLine() {
-    return Collections.unmodifiableSortedMap(conditionsByLine);
-  }
-
-  public SortedMap<Integer, Integer> coveredConditionsByLine() {
-    return Collections.unmodifiableSortedMap(coveredConditionsByLine);
-  }
-
-  @Override
-  public void doSave() {
-    validateFile();
-    if (!isExcluded()) {
-      storage.store(this);
-    }
-  }
-
-  private boolean isExcluded() {
-    return ((DefaultInputFile) inputFile).isExcludedForCoverage();
-  }
-
-}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/internal/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/internal/package-info.java
deleted file mode 100644 (file)
index a0b5e87..0000000
+++ /dev/null
@@ -1,21 +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.
- */
-@javax.annotation.ParametersAreNonnullByDefault
-package org.sonar.api.batch.sensor.coverage.internal;
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/cpd/internal/DefaultCpdTokens.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/cpd/internal/DefaultCpdTokens.java
deleted file mode 100644 (file)
index a2c592c..0000000
+++ /dev/null
@@ -1,136 +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.sensor.cpd.internal;
-
-import java.util.ArrayList;
-import java.util.List;
-import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.fs.TextRange;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.sensor.cpd.NewCpdTokens;
-import org.sonar.api.batch.sensor.internal.DefaultStorable;
-import org.sonar.api.batch.sensor.internal.SensorStorage;
-import org.sonar.api.utils.log.Logger;
-import org.sonar.api.utils.log.Loggers;
-
-import static java.util.Collections.unmodifiableList;
-import static java.util.Objects.requireNonNull;
-import static org.sonar.api.utils.Preconditions.checkState;
-
-public class DefaultCpdTokens extends DefaultStorable implements NewCpdTokens {
-  private static final Logger LOG = Loggers.get(DefaultCpdTokens.class);
-  private final List<TokensLine> result = new ArrayList<>();
-  private DefaultInputFile inputFile;
-  private int startLine = Integer.MIN_VALUE;
-  private int startIndex = 0;
-  private int currentIndex = 0;
-  private StringBuilder sb = new StringBuilder();
-  private TextRange lastRange;
-  private boolean loggedTestCpdWarning = false;
-
-  public DefaultCpdTokens(SensorStorage storage) {
-    super(storage);
-  }
-
-  @Override
-  public DefaultCpdTokens onFile(InputFile inputFile) {
-    this.inputFile = (DefaultInputFile) requireNonNull(inputFile, "file can't be null");
-    return this;
-  }
-
-  public InputFile inputFile() {
-    return inputFile;
-  }
-
-  @Override
-  public NewCpdTokens addToken(int startLine, int startLineOffset, int endLine, int endLineOffset, String image) {
-    checkInputFileNotNull();
-    TextRange newRange;
-    try {
-      newRange = inputFile.newRange(startLine, startLineOffset, endLine, endLineOffset);
-    } catch (Exception e) {
-      throw new IllegalArgumentException("Unable to register token in file " + inputFile, e);
-    }
-    return addToken(newRange, image);
-  }
-
-  @Override
-  public DefaultCpdTokens addToken(TextRange range, String image) {
-    requireNonNull(range, "Range should not be null");
-    requireNonNull(image, "Image should not be null");
-    checkInputFileNotNull();
-    if (isExcludedForDuplication()) {
-      return this;
-    }
-    checkState(lastRange == null || lastRange.end().compareTo(range.start()) <= 0,
-      "Tokens of file %s should be provided in order.\nPrevious token: %s\nLast token: %s", inputFile, lastRange, range);
-
-    int line = range.start().line();
-    if (line != startLine) {
-      addNewTokensLine(result, startIndex, currentIndex, startLine, sb);
-      startIndex = currentIndex + 1;
-      startLine = line;
-    }
-    currentIndex++;
-    sb.append(image);
-    lastRange = range;
-
-    return this;
-  }
-
-  private boolean isExcludedForDuplication() {
-    if (inputFile.isExcludedForDuplication()) {
-      return true;
-    }
-    if (inputFile.type() == InputFile.Type.TEST) {
-      if (!loggedTestCpdWarning) {
-        LOG.warn("Duplication reported for '{}' will be ignored because it's a test file.", inputFile);
-        loggedTestCpdWarning = true;
-      }
-      return true;
-    }
-    return false;
-  }
-
-  public List<TokensLine> getTokenLines() {
-    return unmodifiableList(new ArrayList<>(result));
-  }
-
-  private static void addNewTokensLine(List<TokensLine> result, int startUnit, int endUnit, int startLine, StringBuilder sb) {
-    if (sb.length() != 0) {
-      result.add(new TokensLine(startUnit, endUnit, startLine, sb.toString()));
-      sb.setLength(0);
-    }
-  }
-
-  @Override
-  protected void doSave() {
-    checkState(inputFile != null, "Call onFile() first");
-    if (isExcludedForDuplication()) {
-      return;
-    }
-    addNewTokensLine(result, startIndex, currentIndex, startLine, sb);
-    storage.store(this);
-  }
-
-  private void checkInputFileNotNull() {
-    checkState(inputFile != null, "Call onFile() first");
-  }
-}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/error/internal/DefaultAnalysisError.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/error/internal/DefaultAnalysisError.java
deleted file mode 100644 (file)
index 3a9073a..0000000
+++ /dev/null
@@ -1,88 +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.sensor.error.internal;
-
-import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.fs.TextPointer;
-import org.sonar.api.batch.sensor.error.AnalysisError;
-import org.sonar.api.batch.sensor.error.NewAnalysisError;
-import org.sonar.api.batch.sensor.internal.DefaultStorable;
-import org.sonar.api.batch.sensor.internal.SensorStorage;
-
-import static java.util.Objects.requireNonNull;
-import static org.sonar.api.utils.Preconditions.checkArgument;
-import static org.sonar.api.utils.Preconditions.checkState;
-
-public class DefaultAnalysisError extends DefaultStorable implements NewAnalysisError, AnalysisError {
-  private InputFile inputFile;
-  private String message;
-  private TextPointer location;
-
-  public DefaultAnalysisError() {
-    super(null);
-  }
-
-  public DefaultAnalysisError(SensorStorage storage) {
-    super(storage);
-  }
-
-  @Override
-  public InputFile inputFile() {
-    return inputFile;
-  }
-
-  @Override
-  public String message() {
-    return message;
-  }
-
-  @Override
-  public TextPointer location() {
-    return location;
-  }
-
-  @Override
-  public NewAnalysisError onFile(InputFile inputFile) {
-    checkArgument(inputFile != null, "Cannot use a inputFile that is null");
-    checkState(this.inputFile == null, "onFile() already called");
-    this.inputFile = inputFile;
-    return this;
-  }
-
-  @Override
-  public NewAnalysisError message(String message) {
-    this.message = message;
-    return this;
-  }
-
-  @Override
-  public NewAnalysisError at(TextPointer location) {
-    checkState(this.location == null, "at() already called");
-    this.location = location;
-    return this;
-  }
-
-  @Override
-  protected void doSave() {
-    requireNonNull(this.inputFile, "inputFile is mandatory on AnalysisError");
-    storage.store(this);
-  }
-
-}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/error/internal/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/error/internal/package-info.java
deleted file mode 100644 (file)
index 1abae58..0000000
+++ /dev/null
@@ -1,21 +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.
- */
-@javax.annotation.ParametersAreNonnullByDefault
-package org.sonar.api.batch.sensor.error.internal;
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/DefaultStorable.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/DefaultStorable.java
deleted file mode 100644 (file)
index 822ffbc..0000000
+++ /dev/null
@@ -1,56 +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.sensor.internal;
-
-import javax.annotation.Nullable;
-import org.apache.commons.lang.builder.ToStringBuilder;
-import org.apache.commons.lang.builder.ToStringStyle;
-
-import static java.util.Objects.requireNonNull;
-import static org.sonar.api.utils.Preconditions.checkState;
-
-public abstract class DefaultStorable {
-
-  protected final transient SensorStorage storage;
-  private transient boolean saved = false;
-
-  public DefaultStorable() {
-    this.storage = null;
-  }
-
-  public DefaultStorable(@Nullable SensorStorage storage) {
-    this.storage = storage;
-  }
-
-  public final void save() {
-    requireNonNull(this.storage, "No persister on this object");
-    checkState(!saved, "This object was already saved");
-    doSave();
-    this.saved = true;
-  }
-
-  protected abstract void doSave();
-
-  @Override
-  public String toString() {
-    return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
-  }
-
-}
index fde8e22e5ac6948632bd9eff6d0c6e807709c76d..1e0e5580de49357f064c0cee7ccf05a10d00b284 100644 (file)
  */
 package org.sonar.api.batch.sensor.internal;
 
-import org.sonar.api.batch.sensor.code.internal.DefaultSignificantCode;
-import org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage;
-import org.sonar.api.batch.sensor.cpd.internal.DefaultCpdTokens;
+import org.sonar.api.batch.sensor.code.NewSignificantCode;
+import org.sonar.api.batch.sensor.coverage.NewCoverage;
+import org.sonar.api.batch.sensor.cpd.NewCpdTokens;
 import org.sonar.api.batch.sensor.error.AnalysisError;
 import org.sonar.api.batch.sensor.highlighting.NewHighlighting;
 import org.sonar.api.batch.sensor.issue.ExternalIssue;
 import org.sonar.api.batch.sensor.issue.Issue;
 import org.sonar.api.batch.sensor.measure.Measure;
 import org.sonar.api.batch.sensor.rule.AdHocRule;
-import org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable;
+import org.sonar.api.batch.sensor.symbol.NewSymbolTable;
 import org.sonar.api.scanner.ScannerSide;
 
 /**
@@ -52,17 +52,17 @@ public interface SensorStorage {
   /**
    * @since 5.2
    */
-  void store(DefaultCoverage defaultCoverage);
+  void store(NewCoverage defaultCoverage);
 
   /**
    * @since 5.5
    */
-  void store(DefaultCpdTokens defaultCpdTokens);
+  void store(NewCpdTokens cpdTokens);
 
   /**
    * @since 5.6
    */
-  void store(DefaultSymbolTable symbolTable);
+  void store(NewSymbolTable symbolTable);
 
   /**
    * @since 6.0
@@ -81,5 +81,5 @@ public interface SensorStorage {
   /**
    * @since 7.2
    */
-  void store(DefaultSignificantCode significantCode);
+  void store(NewSignificantCode significantCode);
 }
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/symbol/internal/DefaultSymbolTable.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/symbol/internal/DefaultSymbolTable.java
deleted file mode 100644 (file)
index 087681a..0000000
+++ /dev/null
@@ -1,149 +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.sensor.symbol.internal;
-
-import java.util.Collection;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
-import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.fs.TextRange;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.sensor.internal.DefaultStorable;
-import org.sonar.api.batch.sensor.internal.SensorStorage;
-import org.sonar.api.batch.sensor.symbol.NewSymbol;
-import org.sonar.api.batch.sensor.symbol.NewSymbolTable;
-
-import static java.util.Objects.requireNonNull;
-import static org.sonar.api.utils.Preconditions.checkArgument;
-import static org.sonar.api.utils.Preconditions.checkState;
-
-public class DefaultSymbolTable extends DefaultStorable implements NewSymbolTable {
-
-  private final Map<TextRange, Set<TextRange>> referencesBySymbol;
-  private DefaultInputFile inputFile;
-
-  public DefaultSymbolTable(SensorStorage storage) {
-    super(storage);
-    referencesBySymbol = new LinkedHashMap<>();
-  }
-
-  public Map<TextRange, Set<TextRange>> getReferencesBySymbol() {
-    return referencesBySymbol;
-  }
-
-  @Override
-  public DefaultSymbolTable onFile(InputFile inputFile) {
-    requireNonNull(inputFile, "file can't be null");
-    this.inputFile = (DefaultInputFile) inputFile;
-    return this;
-  }
-
-  public InputFile inputFile() {
-    return inputFile;
-  }
-
-  @Override
-  public NewSymbol newSymbol(int startLine, int startLineOffset, int endLine, int endLineOffset) {
-    checkInputFileNotNull();
-    TextRange declarationRange;
-    try {
-      declarationRange = inputFile.newRange(startLine, startLineOffset, endLine, endLineOffset);
-    } catch (Exception e) {
-      throw new IllegalArgumentException("Unable to create symbol on file " + inputFile, e);
-    }
-    return newSymbol(declarationRange);
-  }
-
-  @Override
-  public NewSymbol newSymbol(int startOffset, int endOffset) {
-    checkInputFileNotNull();
-    TextRange declarationRange;
-    try {
-      declarationRange = inputFile.newRange(startOffset, endOffset);
-    } catch (Exception e) {
-      throw new IllegalArgumentException("Unable to create symbol on file " + inputFile, e);
-    }
-    return newSymbol(declarationRange);
-  }
-
-  @Override
-  public NewSymbol newSymbol(TextRange range) {
-    checkInputFileNotNull();
-    TreeSet<TextRange> references = new TreeSet<>((o1, o2) -> o1.start().compareTo(o2.start()));
-    referencesBySymbol.put(range, references);
-    return new DefaultSymbol(inputFile, range, references);
-  }
-
-  private static class DefaultSymbol implements NewSymbol {
-
-    private final Collection<TextRange> references;
-    private final DefaultInputFile inputFile;
-    private final TextRange declaration;
-
-    public DefaultSymbol(DefaultInputFile inputFile, TextRange declaration, Collection<TextRange> references) {
-      this.inputFile = inputFile;
-      this.declaration = declaration;
-      this.references = references;
-    }
-
-    @Override
-    public NewSymbol newReference(int startOffset, int endOffset) {
-      TextRange referenceRange;
-      try {
-        referenceRange = inputFile.newRange(startOffset, endOffset);
-      } catch (Exception e) {
-        throw new IllegalArgumentException("Unable to create symbol reference on file " + inputFile, e);
-      }
-      return newReference(referenceRange);
-    }
-
-    @Override
-    public NewSymbol newReference(int startLine, int startLineOffset, int endLine, int endLineOffset) {
-      TextRange referenceRange;
-      try {
-        referenceRange = inputFile.newRange(startLine, startLineOffset, endLine, endLineOffset);
-      } catch (Exception e) {
-        throw new IllegalArgumentException("Unable to create symbol reference on file " + inputFile, e);
-      }
-      return newReference(referenceRange);
-    }
-
-    @Override
-    public NewSymbol newReference(TextRange range) {
-      requireNonNull(range, "Provided range is null");
-      checkArgument(!declaration.overlap(range), "Overlapping symbol declaration and reference for symbol at %s", declaration);
-      references.add(range);
-      return this;
-    }
-
-  }
-
-  @Override
-  protected void doSave() {
-    checkInputFileNotNull();
-    storage.store(this);
-  }
-
-  private void checkInputFileNotNull() {
-    checkState(inputFile != null, "Call onFile() first");
-  }
-}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/symbol/internal/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/symbol/internal/package-info.java
deleted file mode 100644 (file)
index e8dcd39..0000000
+++ /dev/null
@@ -1,21 +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.
- */
-@javax.annotation.ParametersAreNonnullByDefault
-package org.sonar.api.batch.sensor.symbol.internal;
index a58e5f02e4f1b019d293ebc27ed6cac0a82ca44e..a94fd4f2123f693cc6b80932d06a0eb8be03461e 100644 (file)
@@ -21,7 +21,6 @@ package org.sonar.api.issue;
 
 import java.util.Set;
 import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.scanner.ScannerSide;
 
 /**
@@ -34,7 +33,7 @@ import org.sonar.api.scanner.ScannerSide;
  * @since 3.6
  */
 @ScannerSide
-public class NoSonarFilter {
+public abstract class NoSonarFilter {
 
   /**
    * Register lines in a file that contains the NOSONAR flag.
@@ -44,9 +43,5 @@ public class NoSonarFilter {
    * @since 5.0
    * @since 7.6 the method can be called multiple times by different sensors, and NOSONAR lines are merged
    */
-  public NoSonarFilter noSonarInFile(InputFile inputFile, Set<Integer> noSonarLines) {
-    ((DefaultInputFile) inputFile).noSonarAt(noSonarLines);
-    return this;
-  }
-
+  public abstract NoSonarFilter noSonarInFile(InputFile inputFile, Set<Integer> noSonarLines);
 }
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputDirTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputDirTest.java
deleted file mode 100644 (file)
index ed2c2b3..0000000
+++ /dev/null
@@ -1,65 +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 org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-
-import java.io.File;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class DefaultInputDirTest {
-
-  @Rule
-  public TemporaryFolder temp = new TemporaryFolder();
-
-  @Test
-  public void test() throws Exception {
-    File baseDir = temp.newFolder();
-    DefaultInputDir inputDir = new DefaultInputDir("ABCDE", "src")
-      .setModuleBaseDir(baseDir.toPath());
-
-    assertThat(inputDir.key()).isEqualTo("ABCDE:src");
-    assertThat(inputDir.file().getAbsolutePath()).isEqualTo(new File(baseDir, "src").getAbsolutePath());
-    assertThat(inputDir.relativePath()).isEqualTo("src");
-    assertThat(new File(inputDir.relativePath())).isRelative();
-    assertThat(inputDir.absolutePath()).endsWith("src");
-    assertThat(new File(inputDir.absolutePath())).isAbsolute();
-  }
-
-  @Test
-  public void testEqualsAndHashCode() throws Exception {
-    DefaultInputDir inputDir1 = new DefaultInputDir("ABCDE", "src");
-
-    DefaultInputDir inputDir2 = new DefaultInputDir("ABCDE", "src");
-
-    assertThat(inputDir1.equals(inputDir1)).isTrue();
-    assertThat(inputDir1.equals(inputDir2)).isTrue();
-    assertThat(inputDir1.equals("foo")).isFalse();
-
-    assertThat(inputDir1.hashCode()).isEqualTo(63545559);
-
-    assertThat(inputDir1.toString()).contains("[moduleKey=ABCDE, relative=src, basedir=null");
-
-  }
-
-}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputFileTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputFileTest.java
deleted file mode 100644 (file)
index 85feccc..0000000
+++ /dev/null
@@ -1,314 +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.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.StringReader;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.nio.file.StandardOpenOption;
-import java.util.stream.Collectors;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.fs.TextRange;
-import org.sonar.scanner.fs.FileMetadata;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
-
-public class DefaultInputFileTest {
-
-  private static final String PROJECT_RELATIVE_PATH = "module1/src/Foo.php";
-  private static final String MODULE_RELATIVE_PATH = "src/Foo.php";
-
-  @Rule
-  public TemporaryFolder temp = new TemporaryFolder();
-
-  private DefaultIndexedFile indexedFile;
-
-  private Path baseDir;
-  private SensorStrategy sensorStrategy;
-
-  @Before
-  public void prepare() throws IOException {
-    baseDir = temp.newFolder().toPath();
-    sensorStrategy = new SensorStrategy();
-    indexedFile = new DefaultIndexedFile(baseDir.resolve(PROJECT_RELATIVE_PATH), "ABCDE", PROJECT_RELATIVE_PATH, MODULE_RELATIVE_PATH, InputFile.Type.TEST, "php", 0,
-      sensorStrategy);
-  }
-
-  @Test
-  public void test() throws Exception {
-
-    Metadata metadata = new Metadata(42, 42, "", new int[0], new int[0], 10);
-    DefaultInputFile inputFile = new DefaultInputFile(indexedFile, (f) -> f.setMetadata(metadata))
-      .setStatus(InputFile.Status.ADDED)
-      .setCharset(StandardCharsets.ISO_8859_1);
-
-    assertThat(inputFile.absolutePath()).endsWith("Foo.php");
-    assertThat(inputFile.filename()).isEqualTo("Foo.php");
-    assertThat(inputFile.uri()).hasPath(baseDir.resolve(PROJECT_RELATIVE_PATH).toUri().getPath());
-    assertThat(new File(inputFile.absolutePath())).isAbsolute();
-    assertThat(inputFile.language()).isEqualTo("php");
-    assertThat(inputFile.status()).isEqualTo(InputFile.Status.ADDED);
-    assertThat(inputFile.type()).isEqualTo(InputFile.Type.TEST);
-    assertThat(inputFile.lines()).isEqualTo(42);
-    assertThat(inputFile.charset()).isEqualTo(StandardCharsets.ISO_8859_1);
-
-    assertThat(inputFile.getModuleRelativePath()).isEqualTo(MODULE_RELATIVE_PATH);
-    assertThat(inputFile.getProjectRelativePath()).isEqualTo(PROJECT_RELATIVE_PATH);
-
-    sensorStrategy.setGlobal(false);
-    assertThat(inputFile.relativePath()).isEqualTo(MODULE_RELATIVE_PATH);
-    assertThat(new File(inputFile.relativePath())).isRelative();
-    sensorStrategy.setGlobal(true);
-    assertThat(inputFile.relativePath()).isEqualTo(PROJECT_RELATIVE_PATH);
-    assertThat(new File(inputFile.relativePath())).isRelative();
-  }
-
-  @Test
-  public void test_content() throws IOException {
-    Path testFile = baseDir.resolve(PROJECT_RELATIVE_PATH);
-    Files.createDirectories(testFile.getParent());
-    String content = "test Ã© string";
-    Files.write(testFile, content.getBytes(StandardCharsets.ISO_8859_1));
-
-    assertThat(Files.readAllLines(testFile, StandardCharsets.ISO_8859_1).get(0)).hasSize(content.length());
-
-    Metadata metadata = new Metadata(42, 30, "", new int[0], new int[0], 10);
-
-    DefaultInputFile inputFile = new DefaultInputFile(indexedFile, f -> f.setMetadata(metadata))
-      .setStatus(InputFile.Status.ADDED)
-      .setCharset(StandardCharsets.ISO_8859_1);
-
-    assertThat(inputFile.contents()).isEqualTo(content);
-    try (InputStream inputStream = inputFile.inputStream()) {
-      String result = new BufferedReader(new InputStreamReader(inputStream, inputFile.charset())).lines().collect(Collectors.joining());
-      assertThat(result).isEqualTo(content);
-    }
-
-  }
-
-  @Test
-  public void test_content_exclude_bom() throws IOException {
-    Path testFile = baseDir.resolve(PROJECT_RELATIVE_PATH);
-    Files.createDirectories(testFile.getParent());
-    try (BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(testFile.toFile()), StandardCharsets.UTF_8))) {
-      out.write('\ufeff');
-    }
-    String content = "test Ã© string â‚¬";
-    Files.write(testFile, content.getBytes(StandardCharsets.UTF_8), StandardOpenOption.APPEND);
-
-    assertThat(Files.readAllLines(testFile, StandardCharsets.UTF_8).get(0)).hasSize(content.length() + 1);
-
-    Metadata metadata = new Metadata(42, 30, "", new int[0], new int[0], 10);
-
-    DefaultInputFile inputFile = new DefaultInputFile(indexedFile, f -> f.setMetadata(metadata))
-      .setStatus(InputFile.Status.ADDED)
-      .setCharset(StandardCharsets.UTF_8);
-
-    assertThat(inputFile.contents()).isEqualTo(content);
-    try (InputStream inputStream = inputFile.inputStream()) {
-      String result = new BufferedReader(new InputStreamReader(inputStream, inputFile.charset())).lines().collect(Collectors.joining());
-      assertThat(result).isEqualTo(content);
-    }
-
-  }
-
-  @Test
-  public void test_equals_and_hashcode() throws Exception {
-    DefaultInputFile f1 = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), (f) -> mock(Metadata.class));
-    DefaultInputFile f1a = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), (f) -> mock(Metadata.class));
-    DefaultInputFile f2 = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), "src/Bar.php", null), (f) -> mock(Metadata.class));
-
-    assertThat(f1).isEqualTo(f1);
-    assertThat(f1).isEqualTo(f1a);
-    assertThat(f1).isNotEqualTo(f2);
-    assertThat(f1.equals("foo")).isFalse();
-    assertThat(f1.equals(null)).isFalse();
-
-    assertThat(f1.hashCode()).isEqualTo(f1.hashCode());
-    assertThat(f1.hashCode()).isEqualTo(f1a.hashCode());
-  }
-
-  @Test
-  public void test_toString() throws Exception {
-    DefaultInputFile file = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), (f) -> mock(Metadata.class));
-    assertThat(file.toString()).isEqualTo(MODULE_RELATIVE_PATH);
-  }
-
-  @Test
-  public void checkValidPointer() {
-    Metadata metadata = new Metadata(2, 2, "", new int[] {0, 10}, new int[] {9, 15}, 16);
-    DefaultInputFile file = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), f -> f.setMetadata(metadata));
-    assertThat(file.newPointer(1, 0).line()).isEqualTo(1);
-    assertThat(file.newPointer(1, 0).lineOffset()).isEqualTo(0);
-    // Don't fail
-    file.newPointer(1, 9);
-    file.newPointer(2, 0);
-    file.newPointer(2, 5);
-
-    try {
-      file.newPointer(0, 1);
-      fail();
-    } catch (Exception e) {
-      assertThat(e).hasMessage("0 is not a valid line for a file");
-    }
-    try {
-      file.newPointer(3, 1);
-      fail();
-    } catch (Exception e) {
-      assertThat(e).hasMessage("3 is not a valid line for pointer. File src/Foo.php has 2 line(s)");
-    }
-    try {
-      file.newPointer(1, -1);
-      fail();
-    } catch (Exception e) {
-      assertThat(e).hasMessage("-1 is not a valid line offset for a file");
-    }
-    try {
-      file.newPointer(1, 10);
-      fail();
-    } catch (Exception e) {
-      assertThat(e).hasMessage("10 is not a valid line offset for pointer. File src/Foo.php has 9 character(s) at line 1");
-    }
-  }
-
-  @Test
-  public void checkValidPointerUsingGlobalOffset() {
-    Metadata metadata = new Metadata(2, 2, "", new int[] {0, 10}, new int[] {8, 15}, 16);
-    DefaultInputFile file = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), f -> f.setMetadata(metadata));
-    assertThat(file.newPointer(0).line()).isEqualTo(1);
-    assertThat(file.newPointer(0).lineOffset()).isEqualTo(0);
-
-    assertThat(file.newPointer(9).line()).isEqualTo(1);
-    // Ignore eol characters
-    assertThat(file.newPointer(9).lineOffset()).isEqualTo(8);
-
-    assertThat(file.newPointer(10).line()).isEqualTo(2);
-    assertThat(file.newPointer(10).lineOffset()).isEqualTo(0);
-
-    assertThat(file.newPointer(15).line()).isEqualTo(2);
-    assertThat(file.newPointer(15).lineOffset()).isEqualTo(5);
-
-    assertThat(file.newPointer(16).line()).isEqualTo(2);
-    // Ignore eol characters
-    assertThat(file.newPointer(16).lineOffset()).isEqualTo(5);
-
-    try {
-      file.newPointer(-1);
-      fail();
-    } catch (Exception e) {
-      assertThat(e).hasMessage("-1 is not a valid offset for a file");
-    }
-
-    try {
-      file.newPointer(17);
-      fail();
-    } catch (Exception e) {
-      assertThat(e).hasMessage("17 is not a valid offset for file src/Foo.php. Max offset is 16");
-    }
-  }
-
-  @Test
-  public void checkValidRange() {
-    Metadata metadata = new FileMetadata().readMetadata(new StringReader("bla bla a\nabcde"));
-    DefaultInputFile file = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), f -> f.setMetadata(metadata));
-
-    assertThat(file.newRange(file.newPointer(1, 0), file.newPointer(2, 1)).start().line()).isEqualTo(1);
-    // Don't fail
-    file.newRange(file.newPointer(1, 0), file.newPointer(1, 1));
-    file.newRange(file.newPointer(1, 0), file.newPointer(1, 9));
-    file.newRange(file.newPointer(1, 0), file.newPointer(2, 0));
-    assertThat(file.newRange(file.newPointer(1, 0), file.newPointer(2, 5))).isEqualTo(file.newRange(0, 15));
-
-    try {
-      file.newRange(file.newPointer(1, 0), file.newPointer(1, 0));
-      fail();
-    } catch (Exception e) {
-      assertThat(e).hasMessage("Start pointer [line=1, lineOffset=0] should be before end pointer [line=1, lineOffset=0]");
-    }
-    try {
-      file.newRange(file.newPointer(1, 0), file.newPointer(1, 10));
-      fail();
-    } catch (Exception e) {
-      assertThat(e).hasMessage("10 is not a valid line offset for pointer. File src/Foo.php has 9 character(s) at line 1");
-    }
-  }
-
-  @Test
-  public void selectLine() {
-    Metadata metadata = new FileMetadata().readMetadata(new StringReader("bla bla a\nabcde\n\nabc"));
-    DefaultInputFile file = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), f -> f.setMetadata(metadata));
-
-    assertThat(file.selectLine(1).start().line()).isEqualTo(1);
-    assertThat(file.selectLine(1).start().lineOffset()).isEqualTo(0);
-    assertThat(file.selectLine(1).end().line()).isEqualTo(1);
-    assertThat(file.selectLine(1).end().lineOffset()).isEqualTo(9);
-
-    // Don't fail when selecting empty line
-    assertThat(file.selectLine(3).start().line()).isEqualTo(3);
-    assertThat(file.selectLine(3).start().lineOffset()).isEqualTo(0);
-    assertThat(file.selectLine(3).end().line()).isEqualTo(3);
-    assertThat(file.selectLine(3).end().lineOffset()).isEqualTo(0);
-
-    try {
-      file.selectLine(5);
-      fail();
-    } catch (Exception e) {
-      assertThat(e).hasMessage("5 is not a valid line for pointer. File src/Foo.php has 4 line(s)");
-    }
-  }
-
-  @Test
-  public void checkValidRangeUsingGlobalOffset() {
-    Metadata metadata = new Metadata(2, 2, "", new int[] {0, 10}, new int[] {9, 15}, 16);
-    DefaultInputFile file = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), f -> f.setMetadata(metadata));
-    TextRange newRange = file.newRange(10, 13);
-    assertThat(newRange.start().line()).isEqualTo(2);
-    assertThat(newRange.start().lineOffset()).isEqualTo(0);
-    assertThat(newRange.end().line()).isEqualTo(2);
-    assertThat(newRange.end().lineOffset()).isEqualTo(3);
-  }
-
-  @Test
-  public void testRangeOverlap() {
-    Metadata metadata = new Metadata(2, 2, "", new int[] {0, 10}, new int[] {9, 15}, 16);
-    DefaultInputFile file = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), f -> f.setMetadata(metadata));
-    // Don't fail
-    assertThat(file.newRange(file.newPointer(1, 0), file.newPointer(1, 1)).overlap(file.newRange(file.newPointer(1, 0), file.newPointer(1, 1)))).isTrue();
-    assertThat(file.newRange(file.newPointer(1, 0), file.newPointer(1, 1)).overlap(file.newRange(file.newPointer(1, 0), file.newPointer(1, 2)))).isTrue();
-    assertThat(file.newRange(file.newPointer(1, 0), file.newPointer(1, 1)).overlap(file.newRange(file.newPointer(1, 1), file.newPointer(1, 2)))).isFalse();
-    assertThat(file.newRange(file.newPointer(1, 2), file.newPointer(1, 3)).overlap(file.newRange(file.newPointer(1, 0), file.newPointer(1, 2)))).isFalse();
-  }
-}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputModuleTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputModuleTest.java
deleted file mode 100644 (file)
index 42394d7..0000000
+++ /dev/null
@@ -1,110 +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.io.File;
-import java.io.IOException;
-import java.nio.charset.Charset;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.sonar.api.batch.bootstrap.ProjectDefinition;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class DefaultInputModuleTest {
-
-  private static final String FILE_1 = "file1";
-  private static final String TEST_1 = "test1";
-  @Rule
-  public TemporaryFolder temp = new TemporaryFolder();
-
-  @Test
-  public void check_getters() throws IOException {
-    ProjectDefinition def = ProjectDefinition.create();
-    def.setKey("moduleKey");
-    File baseDir = temp.newFolder();
-    Path src = baseDir.toPath().resolve(FILE_1);
-    Files.createFile(src);
-    Path test = baseDir.toPath().resolve(TEST_1);
-    Files.createFile(test);
-    def.setBaseDir(baseDir);
-    File workDir = temp.newFolder();
-    def.setWorkDir(workDir);
-    def.setSources(FILE_1);
-    def.setTests(TEST_1);
-    DefaultInputModule module = new DefaultInputModule(def);
-
-    assertThat(module.key()).isEqualTo("moduleKey");
-    assertThat(module.definition()).isEqualTo(def);
-    assertThat(module.getBranch()).isNull();
-    assertThat(module.getBaseDir()).isEqualTo(baseDir.toPath());
-    assertThat(module.getKeyWithBranch()).isEqualTo("moduleKey");
-    assertThat(module.getWorkDir()).isEqualTo(workDir.toPath());
-    assertThat(module.getEncoding()).isEqualTo(Charset.defaultCharset());
-    assertThat(module.getSourceDirsOrFiles().get()).containsExactlyInAnyOrder(src);
-    assertThat(module.getTestDirsOrFiles().get()).containsExactlyInAnyOrder(test);
-    assertThat(module.getEncoding()).isEqualTo(Charset.defaultCharset());
-
-    assertThat(module.isFile()).isFalse();
-  }
-
-  @Test
-  public void no_sources() throws IOException {
-    ProjectDefinition def = ProjectDefinition.create();
-    def.setKey("moduleKey");
-    File baseDir = temp.newFolder();
-    Path src = baseDir.toPath().resolve(FILE_1);
-    Files.createFile(src);
-    Path test = baseDir.toPath().resolve(TEST_1);
-    Files.createFile(test);
-    def.setBaseDir(baseDir);
-    File workDir = temp.newFolder();
-    def.setWorkDir(workDir);
-    DefaultInputModule module = new DefaultInputModule(def);
-
-    assertThat(module.key()).isEqualTo("moduleKey");
-    assertThat(module.definition()).isEqualTo(def);
-    assertThat(module.getBranch()).isNull();
-    assertThat(module.getBaseDir()).isEqualTo(baseDir.toPath());
-    assertThat(module.getKeyWithBranch()).isEqualTo("moduleKey");
-    assertThat(module.getWorkDir()).isEqualTo(workDir.toPath());
-    assertThat(module.getEncoding()).isEqualTo(Charset.defaultCharset());
-    assertThat(module.getSourceDirsOrFiles()).isNotPresent();
-    assertThat(module.getTestDirsOrFiles()).isNotPresent();
-    assertThat(module.getEncoding()).isEqualTo(Charset.defaultCharset());
-
-    assertThat(module.isFile()).isFalse();
-  }
-
-  @Test
-  public void working_directory_should_be_hidden() throws IOException {
-    ProjectDefinition def = ProjectDefinition.create();
-    File workDir = temp.newFolder(".sonar");
-    def.setWorkDir(workDir);
-    File baseDir = temp.newFolder();
-    def.setBaseDir(baseDir);
-    DefaultInputModule module = new DefaultInputModule(def);
-    assertThat(workDir.isHidden()).isTrue();
-  }
-
-}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputProjectTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputProjectTest.java
deleted file mode 100644 (file)
index 8a4a33b..0000000
+++ /dev/null
@@ -1,86 +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.io.File;
-import java.io.IOException;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.sonar.api.batch.bootstrap.ProjectDefinition;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class DefaultInputProjectTest {
-
-  @Rule
-  public TemporaryFolder temp = new TemporaryFolder();
-
-  @Test
-  public void testGetters() throws IOException {
-    ProjectDefinition def = ProjectDefinition.create();
-    def.setKey("projectKey");
-    def.setName("projectName");
-    File baseDir = temp.newFolder();
-    def.setBaseDir(baseDir);
-    def.setDescription("desc");
-    File workDir = temp.newFolder();
-    def.setWorkDir(workDir);
-    def.setSources("file1");
-    def.setTests("test1");
-    AbstractProjectOrModule project = new DefaultInputProject(def);
-
-    assertThat(project.key()).isEqualTo("projectKey");
-    assertThat(project.getName()).isEqualTo("projectName");
-    assertThat(project.getOriginalName()).isEqualTo("projectName");
-    assertThat(project.definition()).isEqualTo(def);
-    assertThat(project.getBranch()).isNull();
-    assertThat(project.getBaseDir()).isEqualTo(baseDir.toPath());
-    assertThat(project.getKeyWithBranch()).isEqualTo("projectKey");
-    assertThat(project.getDescription()).isEqualTo("desc");
-    assertThat(project.getWorkDir()).isEqualTo(workDir.toPath());
-    assertThat(project.getEncoding()).isEqualTo(Charset.defaultCharset());
-
-    assertThat(project.properties()).hasSize(5);
-
-    assertThat(project.isFile()).isFalse();
-  }
-
-  @Test
-  public void testEncoding() throws IOException {
-    ProjectDefinition def = ProjectDefinition.create();
-    def.setKey("projectKey");
-    def.setName("projectName");
-    File baseDir = temp.newFolder();
-    def.setBaseDir(baseDir);
-    def.setProjectVersion("version");
-    def.setDescription("desc");
-    File workDir = temp.newFolder();
-    def.setWorkDir(workDir);
-    def.setSources("file1");
-    def.setProperty("sonar.sourceEncoding", "UTF-16");
-    AbstractProjectOrModule project = new DefaultInputProject(def);
-
-    assertThat(project.getEncoding()).isEqualTo(StandardCharsets.UTF_16);
-  }
-
-}
index cc2d186da447ac59546b9bfeb4fbd1e6666dfc40..8296da8465e0c5416008a18007530326b3180345 100644 (file)
@@ -27,6 +27,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.fs.IndexedFile;
+import org.sonar.scanner.fs.DefaultIndexedFile;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/TestInputFileBuilderTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/TestInputFileBuilderTest.java
deleted file mode 100644 (file)
index 3055be6..0000000
+++ /dev/null
@@ -1,73 +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.io.File;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import org.apache.commons.io.IOUtils;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.sonar.api.batch.fs.InputFile.Status;
-import org.sonar.api.batch.fs.InputFile.Type;
-import org.sonar.scanner.fs.TestInputFileBuilder;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class TestInputFileBuilderTest {
-
-  @Rule
-  public TemporaryFolder temp = new TemporaryFolder();
-
-  @Test
-  public void setContent() throws IOException {
-    DefaultInputFile file = TestInputFileBuilder.create("module", "invalidPath")
-      .setContents("my content")
-      .setCharset(StandardCharsets.UTF_8)
-      .build();
-    assertThat(file.contents()).isEqualTo("my content");
-    assertThat(IOUtils.toString(file.inputStream())).isEqualTo("my content");
-  }
-
-  @Test
-  public void testGetters() {
-    DefaultInputFile file = TestInputFileBuilder.create("module", new File("baseDir"), new File("baseDir", "path"))
-      .setStatus(Status.SAME)
-      .setType(Type.MAIN)
-      .build();
-
-    assertThat(file.type()).isEqualTo(Type.MAIN);
-    assertThat(file.status()).isEqualTo(Status.SAME);
-    assertThat(file.isPublished()).isTrue();
-    assertThat(file.type()).isEqualTo(Type.MAIN);
-    assertThat(file.relativePath()).isEqualTo("path");
-    assertThat(file.absolutePath()).isEqualTo("baseDir/path");
-
-  }
-
-  @Test
-  public void testCreateInputModule() throws IOException {
-    File baseDir = temp.newFolder();
-    AbstractProjectOrModule module = TestInputFileBuilder.newDefaultInputModule("key", baseDir);
-    assertThat(module.key()).isEqualTo("key");
-    assertThat(module.getBaseDir()).isEqualTo(baseDir.toPath());
-  }
-}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/code/internal/DefaultSignificantCodeTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/code/internal/DefaultSignificantCodeTest.java
deleted file mode 100644 (file)
index 5d853e4..0000000
+++ /dev/null
@@ -1,82 +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.sensor.code.internal;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.sensor.internal.SensorStorage;
-import org.sonar.scanner.fs.TestInputFileBuilder;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
-public class DefaultSignificantCodeTest {
-  private SensorStorage sensorStorage = mock(SensorStorage.class);
-  private DefaultSignificantCode underTest = new DefaultSignificantCode(sensorStorage);
-  private InputFile inputFile = TestInputFileBuilder.create("module", "file1.xoo")
-    .setContents("this is\na file\n with some code")
-    .build();
-
-  @Rule
-  public ExpectedException exception = ExpectedException.none();
-
-  @Test
-  public void should_save_ranges() {
-    underTest.onFile(inputFile)
-      .addRange(inputFile.selectLine(1))
-      .save();
-    verify(sensorStorage).store(underTest);
-  }
-
-  @Test
-  public void fail_if_save_without_file() {
-    exception.expect(IllegalStateException.class);
-    exception.expectMessage("Call onFile() first");
-    underTest.save();
-  }
-
-  @Test
-  public void fail_if_add_range_to_same_line_twice() {
-    underTest.onFile(inputFile);
-    underTest.addRange(inputFile.selectLine(1));
-
-    exception.expect(IllegalStateException.class);
-    exception.expectMessage("Significant code was already reported for line '1'.");
-    underTest.addRange(inputFile.selectLine(1));
-  }
-
-  @Test
-  public void fail_if_range_includes_many_lines() {
-    underTest.onFile(inputFile);
-
-    exception.expect(IllegalArgumentException.class);
-    exception.expectMessage("Ranges of significant code must be located in a single line");
-    underTest.addRange(inputFile.newRange(1, 1, 2, 1));
-  }
-
-  @Test
-  public void fail_if_add_range_before_setting_file() {
-    exception.expect(IllegalStateException.class);
-    exception.expectMessage("addRange() should be called after on()");
-    underTest.addRange(inputFile.selectLine(1));
-  }
-}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/cpd/internal/DefaultCpdTokensTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/cpd/internal/DefaultCpdTokensTest.java
deleted file mode 100644 (file)
index 1adb0c7..0000000
+++ /dev/null
@@ -1,170 +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.sensor.cpd.internal;
-
-import org.junit.Test;
-import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.sensor.internal.SensorStorage;
-import org.sonar.scanner.fs.TestInputFileBuilder;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.fail;
-import static org.assertj.core.api.Assertions.tuple;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
-
-public class DefaultCpdTokensTest {
-  private final SensorStorage sensorStorage = mock(SensorStorage.class);
-
-  private final DefaultInputFile inputFile = new TestInputFileBuilder("foo", "src/Foo.java")
-    .setLines(2)
-    .setOriginalLineStartOffsets(new int[] {0, 50})
-    .setOriginalLineEndOffsets(new int[] {49, 100})
-    .setLastValidOffset(101)
-    .build();
-
-  @Test
-  public void save_no_tokens() {
-    DefaultCpdTokens tokens = new DefaultCpdTokens(sensorStorage)
-      .onFile(inputFile);
-
-    tokens.save();
-
-    verify(sensorStorage).store(tokens);
-
-    assertThat(tokens.inputFile()).isEqualTo(inputFile);
-  }
-
-  @Test
-  public void save_one_token() {
-    DefaultCpdTokens tokens = new DefaultCpdTokens(sensorStorage)
-      .onFile(inputFile)
-      .addToken(inputFile.newRange(1, 2, 1, 5), "foo");
-
-    tokens.save();
-
-    verify(sensorStorage).store(tokens);
-
-    assertThat(tokens.getTokenLines()).extracting("value", "startLine", "hashCode", "startUnit", "endUnit").containsExactly(tuple("foo", 1, "foo".hashCode(), 1, 1));
-  }
-
-  @Test
-  public void handle_exclusions() {
-    inputFile.setExcludedForDuplication(true);
-    DefaultCpdTokens tokens = new DefaultCpdTokens(sensorStorage)
-      .onFile(inputFile)
-      .addToken(inputFile.newRange(1, 2, 1, 5), "foo");
-
-    tokens.save();
-
-    verifyZeroInteractions(sensorStorage);
-
-    assertThat(tokens.getTokenLines()).isEmpty();
-  }
-
-  @Test
-  public void dont_save_for_test_files() {
-    DefaultInputFile testInputFile = new TestInputFileBuilder("foo", "src/Foo.java")
-      .setLines(2)
-      .setOriginalLineStartOffsets(new int[] {0, 50})
-      .setOriginalLineEndOffsets(new int[] {49, 100})
-      .setLastValidOffset(101)
-      .setType(InputFile.Type.TEST)
-      .build();
-
-    DefaultCpdTokens tokens = new DefaultCpdTokens(sensorStorage)
-      .onFile(testInputFile)
-      .addToken(testInputFile.newRange(1, 2, 1, 5), "foo");
-
-    tokens.save();
-    verifyZeroInteractions(sensorStorage);
-    assertThat(tokens.getTokenLines()).isEmpty();
-  }
-
-  @Test
-  public void save_many_tokens() {
-    DefaultCpdTokens tokens = new DefaultCpdTokens(sensorStorage)
-      .onFile(inputFile)
-      .addToken(inputFile.newRange(1, 2, 1, 5), "foo")
-      .addToken(inputFile.newRange(1, 6, 1, 10), "bar")
-      .addToken(inputFile.newRange(1, 20, 1, 25), "biz")
-      .addToken(inputFile.newRange(2, 1, 2, 10), "next");
-
-    tokens.save();
-
-    verify(sensorStorage).store(tokens);
-
-    assertThat(tokens.getTokenLines())
-      .extracting("value", "startLine", "hashCode", "startUnit", "endUnit")
-      .containsExactly(
-        tuple("foobarbiz", 1, "foobarbiz".hashCode(), 1, 3),
-        tuple("next", 2, "next".hashCode(), 4, 4));
-  }
-
-  @Test
-  public void basic_validation() {
-    SensorStorage sensorStorage = mock(SensorStorage.class);
-    DefaultCpdTokens tokens = new DefaultCpdTokens(sensorStorage);
-    try {
-      tokens.save();
-      fail("Expected exception");
-    } catch (Exception e) {
-      assertThat(e).hasMessage("Call onFile() first");
-    }
-    try {
-      tokens.addToken(inputFile.newRange(1, 2, 1, 5), "foo");
-      fail("Expected exception");
-    } catch (Exception e) {
-      assertThat(e).hasMessage("Call onFile() first");
-    }
-    try {
-      tokens.addToken(null, "foo");
-      fail("Expected exception");
-    } catch (Exception e) {
-      assertThat(e).hasMessage("Range should not be null");
-    }
-    try {
-      tokens.addToken(inputFile.newRange(1, 2, 1, 5), null);
-      fail("Expected exception");
-    } catch (Exception e) {
-      assertThat(e).hasMessage("Image should not be null");
-    }
-  }
-
-  @Test
-  public void validate_tokens_order() {
-    SensorStorage sensorStorage = mock(SensorStorage.class);
-    DefaultCpdTokens tokens = new DefaultCpdTokens(sensorStorage)
-      .onFile(inputFile)
-      .addToken(inputFile.newRange(1, 6, 1, 10), "bar");
-
-    try {
-      tokens.addToken(inputFile.newRange(1, 2, 1, 5), "foo");
-      fail("Expected exception");
-    } catch (Exception e) {
-      assertThat(e).hasMessage("Tokens of file src/Foo.java should be provided in order.\n" +
-        "Previous token: Range[from [line=1, lineOffset=6] to [line=1, lineOffset=10]]\n" +
-        "Last token: Range[from [line=1, lineOffset=2] to [line=1, lineOffset=5]]");
-    }
-  }
-
-}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/error/internal/DefaultAnalysisErrorTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/error/internal/DefaultAnalysisErrorTest.java
deleted file mode 100644 (file)
index ae920c9..0000000
+++ /dev/null
@@ -1,115 +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.sensor.error.internal;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.fs.TextPointer;
-import org.sonar.api.batch.fs.internal.DefaultTextPointer;
-import org.sonar.api.batch.sensor.error.NewAnalysisError;
-import org.sonar.api.batch.sensor.internal.SensorStorage;
-import org.sonar.scanner.fs.TestInputFileBuilder;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.*;
-
-public class DefaultAnalysisErrorTest {
-  private InputFile inputFile;
-  private SensorStorage storage;
-  private TextPointer textPointer;
-
-  @Rule
-  public ExpectedException exception = ExpectedException.none();
-
-  @Before
-  public void setUp() {
-    inputFile = new TestInputFileBuilder("module1", "src/File.java").build();
-    textPointer = new DefaultTextPointer(5, 2);
-    storage = mock(SensorStorage.class);
-  }
-
-  @Test
-  public void test_analysis_error() {
-    DefaultAnalysisError analysisError = new DefaultAnalysisError(storage);
-    analysisError.onFile(inputFile)
-      .at(textPointer)
-      .message("msg");
-
-    assertThat(analysisError.location()).isEqualTo(textPointer);
-    assertThat(analysisError.message()).isEqualTo("msg");
-    assertThat(analysisError.inputFile()).isEqualTo(inputFile);
-  }
-
-  @Test
-  public void test_save() {
-    DefaultAnalysisError analysisError = new DefaultAnalysisError(storage);
-    analysisError.onFile(inputFile).save();
-
-    verify(storage).store(analysisError);
-    verifyNoMoreInteractions(storage);
-  }
-
-  @Test
-  public void test_no_storage() {
-    exception.expect(NullPointerException.class);
-    DefaultAnalysisError analysisError = new DefaultAnalysisError();
-    analysisError.onFile(inputFile).save();
-  }
-
-  @Test
-  public void test_validation() {
-    try {
-      new DefaultAnalysisError(storage).onFile(null);
-      fail("Expected exception");
-    } catch (IllegalArgumentException e) {
-      // expected
-    }
-
-    NewAnalysisError error = new DefaultAnalysisError(storage).onFile(inputFile);
-    try {
-      error.onFile(inputFile);
-      fail("Expected exception");
-    } catch (IllegalStateException e) {
-      // expected
-    }
-
-    error = new DefaultAnalysisError(storage).at(textPointer);
-    try {
-      error.at(textPointer);
-      fail("Expected exception");
-    } catch (IllegalStateException e) {
-      // expected
-    }
-
-    try {
-      new DefaultAnalysisError(storage).save();
-      fail("Expected exception");
-    } catch (NullPointerException e) {
-      // expected
-    }
-  }
-}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/symbol/internal/DefaultSymbolTableTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/symbol/internal/DefaultSymbolTableTest.java
deleted file mode 100644 (file)
index c880f7f..0000000
+++ /dev/null
@@ -1,72 +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.sensor.symbol.internal;
-
-import java.util.Map;
-import java.util.Set;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.fs.TextRange;
-import org.sonar.api.batch.sensor.internal.SensorStorage;
-import org.sonar.scanner.fs.TestInputFileBuilder;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-
-public class DefaultSymbolTableTest {
-
-  private static final InputFile INPUT_FILE = new TestInputFileBuilder("foo", "src/Foo.java")
-    .setLines(2)
-    .setOriginalLineStartOffsets(new int[] {0, 50})
-    .setOriginalLineEndOffsets(new int[] {49, 100})
-    .setLastValidOffset(101)
-    .build();
-
-  private Map<TextRange, Set<TextRange>> referencesPerSymbol;
-
-  @Rule
-  public ExpectedException throwable = ExpectedException.none();
-
-  @Before
-  public void setUpSampleSymbols() {
-
-    DefaultSymbolTable symbolTableBuilder = new DefaultSymbolTable(mock(SensorStorage.class))
-      .onFile(INPUT_FILE);
-    symbolTableBuilder
-      .newSymbol(0, 10)
-      .newReference(12, 15)
-      .newReference(2, 10, 2, 15);
-
-    symbolTableBuilder.newSymbol(1, 12, 1, 15).newReference(52, 55);
-
-    symbolTableBuilder.save();
-
-    referencesPerSymbol = symbolTableBuilder.getReferencesBySymbol();
-  }
-
-  @Test
-  public void should_register_symbols() {
-    assertThat(referencesPerSymbol).hasSize(2);
-  }
-
-}
index 76ac2f6758ad724a01129fa60e4071ce602f5fb0..20427354f25a0c7b11fd260cc9e9c9439500ef4e 100644 (file)
@@ -22,8 +22,9 @@ package org.sonar.api.issue;
 import java.util.Arrays;
 import java.util.HashSet;
 import org.junit.Test;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
+import org.sonar.scanner.fs.DefaultInputFile;
 import org.sonar.scanner.fs.TestInputFileBuilder;
+import org.sonar.scanner.issue.DefaultNoSonarFilter;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
@@ -32,7 +33,7 @@ public class NoSonarFilterTest {
   @Test
   public void should_store_nosonar_lines_on_inputfile() {
     DefaultInputFile f = TestInputFileBuilder.create("module1", "myfile.java").setLines(8).build();
-    new NoSonarFilter().noSonarInFile(f, new HashSet<>(Arrays.asList(1, 4)));
+    new DefaultNoSonarFilter().noSonarInFile(f, new HashSet<>(Arrays.asList(1, 4)));
 
     assertThat(f.hasNoSonarAt(1)).isTrue();
     assertThat(f.hasNoSonarAt(2)).isFalse();
index 9d263b17667646aa016c0cce7f7c804b2e03aa91..dee0cc79aa78da2dfeda0100b3e641a913bf8326 100644 (file)
@@ -25,9 +25,9 @@ import java.nio.file.Path;
 import org.picocontainer.ComponentLifecycle;
 import org.picocontainer.PicoContainer;
 import org.picocontainer.injectors.ProviderAdapter;
-import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.utils.TempFolder;
 import org.sonar.api.utils.internal.DefaultTempFolder;
+import org.sonar.scanner.fs.DefaultInputProject;
 
 public class AnalysisTempFolderProvider extends ProviderAdapter implements ComponentLifecycle<TempFolder> {
   static final String TMP_NAME = ".sonartmp";
index 0800b49bc5e2226ef94a1b6fede2ca81d2764680..c5c1112317d02786aa09d63f8766c657feb2cd66 100644 (file)
@@ -34,8 +34,6 @@ import java.util.function.Function;
 import java.util.function.Predicate;
 import java.util.stream.Collectors;
 import org.sonar.api.batch.fs.InputComponent;
-import org.sonar.api.batch.fs.internal.DefaultInputComponent;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.duplications.block.Block;
@@ -44,6 +42,8 @@ import org.sonar.duplications.index.CloneGroup;
 import org.sonar.duplications.index.ClonePart;
 import org.sonar.duplications.index.PackedMemoryCloneIndex.ResourceBlocks;
 import org.sonar.scanner.cpd.index.SonarCpdBlockIndex;
+import org.sonar.scanner.fs.DefaultInputComponent;
+import org.sonar.scanner.fs.DefaultInputFile;
 import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.scanner.protocol.output.ScannerReport.Duplicate;
 import org.sonar.scanner.protocol.output.ScannerReport.Duplication;
@@ -160,7 +160,8 @@ public class CpdExecutor {
     saveDuplications(inputFile, filtered);
   }
 
-  @VisibleForTesting final void saveDuplications(final DefaultInputComponent component, List<CloneGroup> duplications) {
+  @VisibleForTesting
+  final void saveDuplications(final DefaultInputComponent component, List<CloneGroup> duplications) {
     if (duplications.size() > MAX_CLONE_GROUP_PER_FILE) {
       LOG.warn("Too many duplication groups on file {}. Keep only the first {} groups.", component, MAX_CLONE_GROUP_PER_FILE);
     }
index 54b8307b120f195f9b1c2bf49d9acb68ca99f04a..f40e5d107bdc520b879fab8d616c2eaa0fb50004 100644 (file)
@@ -21,9 +21,9 @@ package org.sonar.scanner.cpd;
 
 import org.apache.commons.lang.StringUtils;
 import org.sonar.api.CoreProperties;
-import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.config.Configuration;
 import org.sonar.duplications.block.BlockChunker;
+import org.sonar.scanner.fs.DefaultInputProject;
 
 public class CpdSettings {
   private final Configuration settings;
@@ -41,8 +41,8 @@ public class CpdSettings {
   }
 
   /**
-   * Not applicable to Java, as the {@link BlockChunker} that it uses does not record start and end units of each block. 
-   * Also, it uses statements instead of tokens. 
+   * Not applicable to Java, as the {@link BlockChunker} that it uses does not record start and end units of each block.
+   * Also, it uses statements instead of tokens.
    */
   int getMinimumTokens(String languageKey) {
     return settings.getInt("sonar.cpd." + languageKey + ".minimumTokens").orElse(100);
index 13c59fc40dd07871ffaad2bcc1e861d548b138cd..a66df96bbed5a78e37bbf9522d8f22a7e5d22b03 100644 (file)
@@ -32,7 +32,6 @@ import org.slf4j.LoggerFactory;
 import org.sonar.api.batch.Phase;
 import org.sonar.api.batch.fs.FilePredicates;
 import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.sensor.SensorContext;
 import org.sonar.api.batch.sensor.SensorDescriptor;
 import org.sonar.api.scanner.sensor.ProjectSensor;
@@ -44,6 +43,7 @@ import org.sonar.duplications.statement.Statement;
 import org.sonar.duplications.statement.StatementChunker;
 import org.sonar.duplications.token.TokenChunker;
 import org.sonar.scanner.cpd.index.SonarCpdBlockIndex;
+import org.sonar.scanner.fs.DefaultInputFile;
 
 /**
  * Special case for Java that use a dedicated block indexer.
index 3816f214c8679fc37f1c19d8e42bfbe9de4cff87..645d9fab4b103f8434b6f62a3914ddff1d26fe9e 100644 (file)
@@ -24,9 +24,7 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
 import java.util.stream.Collectors;
-
 import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.duplications.block.Block;
@@ -36,6 +34,7 @@ import org.sonar.duplications.index.CloneIndex;
 import org.sonar.duplications.index.PackedMemoryCloneIndex;
 import org.sonar.duplications.index.PackedMemoryCloneIndex.ResourceBlocks;
 import org.sonar.scanner.cpd.CpdSettings;
+import org.sonar.scanner.fs.DefaultInputFile;
 import org.sonar.scanner.protocol.output.FileStructure;
 import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.scanner.report.ReportPublisher;
index 39c54302e682aec11bfc8a18819b20946eb9fc89..364544377ed28d4ad13f7bb98195d81f2f453752 100644 (file)
 package org.sonar.scanner.deprecated.test;
 
 import java.util.List;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.test.CoverageBlock;
 import org.sonar.api.test.TestCase;
 import org.sonar.api.test.Testable;
+import org.sonar.scanner.fs.DefaultInputFile;
 
 public class DefaultCoverageBlock implements CoverageBlock {
 
index ae10c57c8362f8eae9aef301ef6964d99b117aad..960a6cf03b56834d561b32a294a12445518597ab 100644 (file)
@@ -26,13 +26,13 @@ import java.util.Map;
 import javax.annotation.Nullable;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.InputFile.Type;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.test.CoverageBlock;
 import org.sonar.api.test.MutableTestCase;
 import org.sonar.api.test.TestPlan;
 import org.sonar.api.test.Testable;
 import org.sonar.api.test.exception.CoverageAlreadyExistsException;
 import org.sonar.api.test.exception.IllegalDurationException;
+import org.sonar.scanner.fs.DefaultInputFile;
 
 public class DefaultTestCase implements MutableTestCase {
 
index 5e13e2652325c8249425be887ffa74e5dddf631b..20a0abfec50200440e32d473a5d5166fcea6ef38 100644 (file)
@@ -22,10 +22,10 @@ package org.sonar.scanner.deprecated.test;
 import java.util.List;
 import java.util.Map;
 import java.util.SortedSet;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.test.CoverageBlock;
 import org.sonar.api.test.MutableTestable;
 import org.sonar.api.test.TestCase;
+import org.sonar.scanner.fs.DefaultInputFile;
 
 public class DefaultTestable implements MutableTestable {
 
index fc2f413c4e8fe1475d339043d5edb7168d57a1a2..615ebd2f5cf00077d282f87c27deca39fb4660de 100644 (file)
@@ -25,9 +25,9 @@ import javax.annotation.CheckForNull;
 import org.sonar.api.batch.fs.InputComponent;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.InputFile.Type;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.test.MutableTestPlan;
 import org.sonar.scanner.deprecated.perspectives.PerspectiveBuilder;
+import org.sonar.scanner.fs.DefaultInputFile;
 
 public class TestPlanBuilder extends PerspectiveBuilder<MutableTestPlan> {
 
index 6fe7a1a4f37c09e2d8b7d0742c807f5aa48df4df..84f74e12ff5e8dfc74e2ad9cfe5e90b0533c5778 100644 (file)
@@ -23,9 +23,9 @@ import javax.annotation.CheckForNull;
 import org.sonar.api.batch.fs.InputComponent;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.InputFile.Type;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.test.MutableTestable;
 import org.sonar.scanner.deprecated.perspectives.PerspectiveBuilder;
+import org.sonar.scanner.fs.DefaultInputFile;
 
 public class TestableBuilder extends PerspectiveBuilder<MutableTestable> {
 
index d458edd0ca92ed5683c9b813c2173bfebd7f9b29..9fc2d130f4a99abee04877f384af45096ea49fd0 100644 (file)
@@ -34,7 +34,6 @@ import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.SystemUtils;
 import org.sonar.api.CoreProperties;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.batch.fs.internal.DefaultInputComponent;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 
index de882ad0c54f85181dc2e0bc930347f7c8067672..1c1729634e12dc508427983f6cbf64352b624110 100644 (file)
@@ -37,7 +37,6 @@ import org.sonar.api.batch.fs.FilePredicates;
 import org.sonar.api.batch.fs.FileSystem;
 import org.sonar.api.batch.fs.InputDir;
 import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputDir;
 import org.sonar.api.scan.filesystem.PathResolver;
 import org.sonar.api.utils.PathUtils;
 import org.sonar.scanner.fs.predicates.DefaultFilePredicates;
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/fs/DefaultIndexedFile.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/fs/DefaultIndexedFile.java
new file mode 100644 (file)
index 0000000..e52e0b4
--- /dev/null
@@ -0,0 +1,162 @@
+/*
+ * 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.scanner.fs;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.concurrent.atomic.AtomicInteger;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+import javax.annotation.concurrent.Immutable;
+import org.sonar.api.batch.fs.IndexedFile;
+import org.sonar.api.batch.fs.InputFile.Type;
+import org.sonar.api.batch.fs.internal.SensorStrategy;
+import org.sonar.api.utils.PathUtils;
+
+/**
+ * @since 6.3
+ */
+@Immutable
+public class DefaultIndexedFile extends DefaultInputComponent implements IndexedFile {
+  private static AtomicInteger intGenerator = new AtomicInteger(0);
+
+  private final String projectRelativePath;
+  private final String moduleRelativePath;
+  private final String projectKey;
+  private final String language;
+  private final Type type;
+  private final Path absolutePath;
+  private final SensorStrategy sensorStrategy;
+
+  /**
+   * Testing purposes only!
+   */
+  public DefaultIndexedFile(String projectKey, Path baseDir, String relativePath, @Nullable String language) {
+    this(baseDir.resolve(relativePath), projectKey, relativePath, relativePath, Type.MAIN, language, intGenerator.getAndIncrement(),
+      new SensorStrategy());
+  }
+
+  public DefaultIndexedFile(Path absolutePath, String projectKey, String projectRelativePath, String moduleRelativePath, Type type, @Nullable String language, int batchId,
+    SensorStrategy sensorStrategy) {
+    super(batchId);
+    this.projectKey = projectKey;
+    this.projectRelativePath = PathUtils.sanitize(projectRelativePath);
+    this.moduleRelativePath = PathUtils.sanitize(moduleRelativePath);
+    this.type = type;
+    this.language = language;
+    this.sensorStrategy = sensorStrategy;
+    this.absolutePath = absolutePath;
+  }
+
+  @Override
+  public String relativePath() {
+    return sensorStrategy.isGlobal() ? projectRelativePath : moduleRelativePath;
+  }
+
+  public String getModuleRelativePath() {
+    return moduleRelativePath;
+  }
+
+  public String getProjectRelativePath() {
+    return projectRelativePath;
+  }
+
+  @Override
+  public String absolutePath() {
+    return PathUtils.sanitize(path().toString());
+  }
+
+  @Override
+  public File file() {
+    return path().toFile();
+  }
+
+  @Override
+  public Path path() {
+    return absolutePath;
+  }
+
+  @Override
+  public InputStream inputStream() throws IOException {
+    return Files.newInputStream(path());
+  }
+
+  @CheckForNull
+  @Override
+  public String language() {
+    return language;
+  }
+
+  @Override
+  public Type type() {
+    return type;
+  }
+
+  /**
+   * Component key (without branch).
+   */
+  @Override
+  public String key() {
+    return new StringBuilder().append(projectKey).append(":").append(projectRelativePath).toString();
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) {
+      return true;
+    }
+
+    if (!(o instanceof DefaultIndexedFile)) {
+      return false;
+    }
+
+    DefaultIndexedFile that = (DefaultIndexedFile) o;
+    return projectRelativePath.equals(that.projectRelativePath);
+  }
+
+  @Override
+  public int hashCode() {
+    return projectRelativePath.hashCode();
+  }
+
+  @Override
+  public String toString() {
+    return projectRelativePath;
+  }
+
+  @Override
+  public boolean isFile() {
+    return true;
+  }
+
+  @Override
+  public String filename() {
+    return path().getFileName().toString();
+  }
+
+  @Override
+  public URI uri() {
+    return path().toUri();
+  }
+}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/fs/DefaultInputComponent.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/fs/DefaultInputComponent.java
new file mode 100644 (file)
index 0000000..11601e0
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * 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.scanner.fs;
+
+import java.util.HashSet;
+import java.util.Set;
+import org.sonar.api.batch.fs.InputComponent;
+import org.sonar.api.batch.measure.Metric;
+
+/**
+ * @since 5.2
+ */
+public abstract class DefaultInputComponent implements InputComponent {
+  private int id;
+  private Set<String> storedMetricKeys = new HashSet<>();
+
+  public DefaultInputComponent(int scannerId) {
+    this.id = scannerId;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) {
+      return true;
+    }
+    if (o == null || this.getClass() != o.getClass()) {
+      return false;
+    }
+
+    DefaultInputComponent that = (DefaultInputComponent) o;
+    return key().equals(that.key());
+  }
+
+  public int scannerId() {
+    return id;
+  }
+
+  @Override
+  public int hashCode() {
+    return key().hashCode();
+  }
+
+  @Override
+  public String toString() {
+    return "[key=" + key() + "]";
+  }
+
+  public void setHasMeasureFor(Metric metric) {
+    storedMetricKeys.add(metric.key());
+  }
+
+  public boolean hasMeasureFor(Metric metric) {
+    return storedMetricKeys.contains(metric.key());
+  }
+}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/fs/DefaultInputDir.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/fs/DefaultInputDir.java
new file mode 100644 (file)
index 0000000..13eb77b
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * 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.scanner.fs;
+
+import java.io.File;
+import java.net.URI;
+import java.nio.file.Path;
+import org.apache.commons.lang.StringUtils;
+import org.sonar.api.batch.fs.InputDir;
+import org.sonar.api.utils.PathUtils;
+
+/**
+ * @since 4.5
+ */
+public class DefaultInputDir extends DefaultInputComponent implements InputDir {
+
+  private final String relativePath;
+  private final String moduleKey;
+  private Path moduleBaseDir;
+
+  public DefaultInputDir(String moduleKey, String relativePath) {
+    super(-1);
+    this.moduleKey = moduleKey;
+    this.relativePath = PathUtils.sanitize(relativePath);
+  }
+
+  @Override
+  public String relativePath() {
+    return relativePath;
+  }
+
+  @Override
+  public String absolutePath() {
+    return PathUtils.sanitize(path().toString());
+  }
+
+  @Override
+  public File file() {
+    return path().toFile();
+  }
+
+  @Override
+  public Path path() {
+    if (moduleBaseDir == null) {
+      throw new IllegalStateException("Can not return the java.nio.file.Path because module baseDir is not set (see method setModuleBaseDir(java.io.File))");
+    }
+    return moduleBaseDir.resolve(relativePath);
+  }
+
+  public String moduleKey() {
+    return moduleKey;
+  }
+
+  @Override
+  public String key() {
+    StringBuilder sb = new StringBuilder().append(moduleKey).append(":");
+    if (StringUtils.isEmpty(relativePath)) {
+      sb.append("/");
+    } else {
+      sb.append(relativePath);
+    }
+    return sb.toString();
+  }
+
+  /**
+   * For testing purpose. Will be automatically set when dir is added to {@link DefaultFileSystem}
+   */
+  public DefaultInputDir setModuleBaseDir(Path moduleBaseDir) {
+    this.moduleBaseDir = moduleBaseDir.normalize();
+    return this;
+  }
+
+  @Override
+  public boolean isFile() {
+    return false;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) {
+      return true;
+    }
+    if (o == null || this.getClass() != o.getClass()) {
+      return false;
+    }
+
+    DefaultInputDir that = (DefaultInputDir) o;
+    return moduleKey.equals(that.moduleKey) && relativePath.equals(that.relativePath);
+  }
+
+  @Override
+  public int hashCode() {
+    return moduleKey.hashCode() + relativePath.hashCode() * 13;
+  }
+
+  @Override
+  public String toString() {
+    return "[moduleKey=" + moduleKey + ", relative=" + relativePath + ", basedir=" + moduleBaseDir + "]";
+  }
+
+  @Override
+  public URI uri() {
+    return path().toUri();
+  }
+}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/fs/DefaultInputFile.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/fs/DefaultInputFile.java
new file mode 100644 (file)
index 0000000..c74f1c4
--- /dev/null
@@ -0,0 +1,440 @@
+/*
+ * 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.scanner.fs;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.BitSet;
+import java.util.Collection;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+import org.apache.commons.io.ByteOrderMark;
+import org.apache.commons.io.input.BOMInputStream;
+import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.fs.TextPointer;
+import org.sonar.api.batch.fs.TextRange;
+import org.sonar.api.batch.fs.internal.Metadata;
+
+import static org.sonar.api.utils.Preconditions.checkArgument;
+import static org.sonar.api.utils.Preconditions.checkState;
+
+/**
+ * @since 4.2
+ * To create {@link InputFile} in tests, use TestInputFileBuilder.
+ */
+public class DefaultInputFile extends DefaultInputComponent implements InputFile {
+
+  private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
+
+  private final DefaultIndexedFile indexedFile;
+  private final String contents;
+  private final Consumer<DefaultInputFile> metadataGenerator;
+
+  private boolean published;
+  private boolean excludedForCoverage;
+  private boolean excludedForDuplication;
+  private boolean ignoreAllIssues;
+  // Lazy init to save memory
+  private BitSet noSonarLines;
+  private Status status;
+  private Charset charset;
+  private Metadata metadata;
+  private Collection<int[]> ignoreIssuesOnlineRanges;
+  private BitSet executableLines;
+
+  public DefaultInputFile(DefaultIndexedFile indexedFile, Consumer<DefaultInputFile> metadataGenerator) {
+    this(indexedFile, metadataGenerator, null);
+  }
+
+  // For testing
+  public DefaultInputFile(DefaultIndexedFile indexedFile, Consumer<DefaultInputFile> metadataGenerator, @Nullable String contents) {
+    super(indexedFile.scannerId());
+    this.indexedFile = indexedFile;
+    this.metadataGenerator = metadataGenerator;
+    this.metadata = null;
+    this.published = false;
+    this.excludedForCoverage = false;
+    this.contents = contents;
+  }
+
+  public void checkMetadata() {
+    if (metadata == null) {
+      metadataGenerator.accept(this);
+    }
+  }
+
+  @Override
+  public InputStream inputStream() throws IOException {
+    return contents != null ? new ByteArrayInputStream(contents.getBytes(charset()))
+      : new BOMInputStream(Files.newInputStream(path()),
+      ByteOrderMark.UTF_8, ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_16BE, ByteOrderMark.UTF_32LE, ByteOrderMark.UTF_32BE);
+  }
+
+  @Override
+  public String contents() throws IOException {
+    if (contents != null) {
+      return contents;
+    } else {
+      ByteArrayOutputStream result = new ByteArrayOutputStream();
+      try (InputStream inputStream = inputStream()) {
+        byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
+        int length;
+        while ((length = inputStream.read(buffer)) != -1) {
+          result.write(buffer, 0, length);
+        }
+      }
+      return result.toString(charset().name());
+    }
+  }
+
+  public DefaultInputFile setPublished(boolean published) {
+    this.published = published;
+    return this;
+  }
+
+  public boolean isPublished() {
+    return published;
+  }
+
+  public DefaultInputFile setExcludedForCoverage(boolean excludedForCoverage) {
+    this.excludedForCoverage = excludedForCoverage;
+    return this;
+  }
+
+  public boolean isExcludedForCoverage() {
+    return excludedForCoverage;
+  }
+
+  public DefaultInputFile setExcludedForDuplication(boolean excludedForDuplication) {
+    this.excludedForDuplication = excludedForDuplication;
+    return this;
+  }
+
+  public boolean isExcludedForDuplication() {
+    return excludedForDuplication;
+  }
+
+  /**
+   * @deprecated since 6.6
+   */
+  @Deprecated
+  @Override
+  public String relativePath() {
+    return indexedFile.relativePath();
+  }
+
+  public String getModuleRelativePath() {
+    return indexedFile.getModuleRelativePath();
+  }
+
+  public String getProjectRelativePath() {
+    return indexedFile.getProjectRelativePath();
+  }
+
+  @Override
+  public String absolutePath() {
+    return indexedFile.absolutePath();
+  }
+
+  @Override
+  public File file() {
+    return indexedFile.file();
+  }
+
+  @Override
+  public Path path() {
+    return indexedFile.path();
+  }
+
+  @CheckForNull
+  @Override
+  public String language() {
+    return indexedFile.language();
+  }
+
+  @Override
+  public Type type() {
+    return indexedFile.type();
+  }
+
+  /**
+   * Component key (without branch).
+   */
+  @Override
+  public String key() {
+    return indexedFile.key();
+  }
+
+  @Override
+  public int hashCode() {
+    return indexedFile.hashCode();
+  }
+
+  @Override
+  public String toString() {
+    return indexedFile.toString();
+  }
+
+  /**
+   * {@link #setStatus(Status)}
+   */
+  @Override
+  public Status status() {
+    checkMetadata();
+    return status;
+  }
+
+  @Override
+  public int lines() {
+    checkMetadata();
+    return metadata.lines();
+  }
+
+  @Override
+  public boolean isEmpty() {
+    checkMetadata();
+    return metadata.isEmpty();
+  }
+
+  @Override
+  public Charset charset() {
+    checkMetadata();
+    return charset;
+  }
+
+  public int lastValidOffset() {
+    checkMetadata();
+    return metadata.lastValidOffset();
+  }
+
+  /**
+   * Digest hash of the file.
+   */
+  public String hash() {
+    checkMetadata();
+    return metadata.hash();
+  }
+
+  public int nonBlankLines() {
+    checkMetadata();
+    return metadata.nonBlankLines();
+  }
+
+  public int[] originalLineStartOffsets() {
+    checkMetadata();
+    checkState(metadata.originalLineStartOffsets() != null, "InputFile is not properly initialized.");
+    checkState(metadata.originalLineStartOffsets().length == metadata.lines(),
+      "InputFile is not properly initialized. 'originalLineStartOffsets' property length should be equal to 'lines'");
+    return metadata.originalLineStartOffsets();
+  }
+
+  public int[] originalLineEndOffsets() {
+    checkMetadata();
+    checkState(metadata.originalLineEndOffsets() != null, "InputFile is not properly initialized.");
+    checkState(metadata.originalLineEndOffsets().length == metadata.lines(),
+      "InputFile is not properly initialized. 'originalLineEndOffsets' property length should be equal to 'lines'");
+    return metadata.originalLineEndOffsets();
+  }
+
+  @Override
+  public TextPointer newPointer(int line, int lineOffset) {
+    checkMetadata();
+    DefaultTextPointer textPointer = new DefaultTextPointer(line, lineOffset);
+    checkValid(textPointer, "pointer");
+    return textPointer;
+  }
+
+  @Override
+  public TextRange newRange(TextPointer start, TextPointer end) {
+    checkMetadata();
+    checkValid(start, "start pointer");
+    checkValid(end, "end pointer");
+    return newRangeValidPointers(start, end, false);
+  }
+
+  @Override
+  public TextRange newRange(int startLine, int startLineOffset, int endLine, int endLineOffset) {
+    checkMetadata();
+    TextPointer start = newPointer(startLine, startLineOffset);
+    TextPointer end = newPointer(endLine, endLineOffset);
+    return newRangeValidPointers(start, end, false);
+  }
+
+  @Override
+  public TextRange selectLine(int line) {
+    checkMetadata();
+    TextPointer startPointer = newPointer(line, 0);
+    TextPointer endPointer = newPointer(line, lineLength(line));
+    return newRangeValidPointers(startPointer, endPointer, true);
+  }
+
+  public void validate(TextRange range) {
+    checkMetadata();
+    checkValid(range.start(), "start pointer");
+    checkValid(range.end(), "end pointer");
+  }
+
+  /**
+   * Create Range from global offsets. Used for backward compatibility with older API.
+   */
+  public TextRange newRange(int startOffset, int endOffset) {
+    checkMetadata();
+    return newRangeValidPointers(newPointer(startOffset), newPointer(endOffset), false);
+  }
+
+  public TextPointer newPointer(int globalOffset) {
+    checkMetadata();
+    checkArgument(globalOffset >= 0, "%s is not a valid offset for a file", globalOffset);
+    checkArgument(globalOffset <= lastValidOffset(), "%s is not a valid offset for file %s. Max offset is %s", globalOffset, this, lastValidOffset());
+    int line = findLine(globalOffset);
+    int startLineOffset = originalLineStartOffsets()[line - 1];
+    // In case the global offset is between \r and \n, move the pointer to a valid location
+    return new DefaultTextPointer(line, Math.min(globalOffset, originalLineEndOffsets()[line - 1]) - startLineOffset);
+  }
+
+  public DefaultInputFile setStatus(Status status) {
+    this.status = status;
+    return this;
+  }
+
+  public DefaultInputFile setCharset(Charset charset) {
+    this.charset = charset;
+    return this;
+  }
+
+  private void checkValid(TextPointer pointer, String owner) {
+    checkArgument(pointer.line() >= 1, "%s is not a valid line for a file", pointer.line());
+    checkArgument(pointer.line() <= this.metadata.lines(), "%s is not a valid line for %s. File %s has %s line(s)", pointer.line(), owner, this, metadata.lines());
+    checkArgument(pointer.lineOffset() >= 0, "%s is not a valid line offset for a file", pointer.lineOffset());
+    int lineLength = lineLength(pointer.line());
+    checkArgument(pointer.lineOffset() <= lineLength,
+      "%s is not a valid line offset for %s. File %s has %s character(s) at line %s", pointer.lineOffset(), owner, this, lineLength, pointer.line());
+  }
+
+  private int lineLength(int line) {
+    return originalLineEndOffsets()[line - 1] - originalLineStartOffsets()[line - 1];
+  }
+
+  private static TextRange newRangeValidPointers(TextPointer start, TextPointer end, boolean acceptEmptyRange) {
+    checkArgument(acceptEmptyRange ? (start.compareTo(end) <= 0) : (start.compareTo(end) < 0),
+      "Start pointer %s should be before end pointer %s", start, end);
+    return new DefaultTextRange(start, end);
+  }
+
+  private int findLine(int globalOffset) {
+    return Math.abs(Arrays.binarySearch(originalLineStartOffsets(), globalOffset) + 1);
+  }
+
+  public DefaultInputFile setMetadata(Metadata metadata) {
+    this.metadata = metadata;
+    return this;
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (obj == null) {
+      return false;
+    }
+
+    if (this.getClass() != obj.getClass()) {
+      return false;
+    }
+
+    DefaultInputFile that = (DefaultInputFile) obj;
+    return this.getProjectRelativePath().equals(that.getProjectRelativePath());
+  }
+
+  @Override
+  public boolean isFile() {
+    return true;
+  }
+
+  @Override
+  public String filename() {
+    return indexedFile.filename();
+  }
+
+  @Override
+  public URI uri() {
+    return indexedFile.uri();
+  }
+
+  public void noSonarAt(Set<Integer> noSonarLines) {
+    if (this.noSonarLines == null) {
+      this.noSonarLines = new BitSet(lines());
+    }
+    noSonarLines.forEach(l -> this.noSonarLines.set(l - 1));
+  }
+
+  public boolean hasNoSonarAt(int line) {
+    if (this.noSonarLines == null) {
+      return false;
+    }
+    return this.noSonarLines.get(line - 1);
+  }
+
+  public boolean isIgnoreAllIssues() {
+    return ignoreAllIssues;
+  }
+
+  public void setIgnoreAllIssues(boolean ignoreAllIssues) {
+    this.ignoreAllIssues = ignoreAllIssues;
+  }
+
+  public void addIgnoreIssuesOnLineRanges(Collection<int[]> lineRanges) {
+    if (this.ignoreIssuesOnlineRanges == null) {
+      this.ignoreIssuesOnlineRanges = new ArrayList<>();
+    }
+    this.ignoreIssuesOnlineRanges.addAll(lineRanges);
+  }
+
+  public boolean isIgnoreAllIssuesOnLine(@Nullable Integer line) {
+    if (line == null || ignoreIssuesOnlineRanges == null) {
+      return false;
+    }
+    return ignoreIssuesOnlineRanges.stream().anyMatch(r -> r[0] <= line && line <= r[1]);
+  }
+
+  public void setExecutableLines(Set<Integer> executableLines) {
+    checkState(this.executableLines == null, "Executable lines have already been saved for file: {}", this.toString());
+    this.executableLines = new BitSet(lines());
+    executableLines.forEach(l -> this.executableLines.set(l - 1));
+  }
+
+  public Optional<Set<Integer>> getExecutableLines() {
+    if (this.executableLines == null) {
+      return Optional.empty();
+    }
+    return Optional.of(this.executableLines.stream().map(i -> i + 1).boxed().collect(Collectors.toSet()));
+  }
+}
index eee66064b29fe5b9be1e6f2c73d38822cc117fb8..6764b6180d5c83e624ef8c661ba56515978052ba 100644 (file)
@@ -31,12 +31,6 @@ import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
 import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.fs.internal.AbstractProjectOrModule;
-import org.sonar.api.batch.fs.internal.DefaultIndexedFile;
-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.DefaultInputProject;
 import org.sonar.api.batch.fs.internal.Metadata;
 import org.sonar.api.batch.fs.internal.SensorStrategy;
 import org.sonar.api.utils.PathUtils;
@@ -218,14 +212,14 @@ public class TestInputFileBuilder {
     return setMetadata(new FileMetadata().readMetadata(new StringReader(content)));
   }
 
-  public org.sonar.api.batch.fs.internal.DefaultInputFile build() {
+  public DefaultInputFile build() {
     Path absolutePath = moduleBaseDir.resolve(relativePath);
     if (projectBaseDir == null) {
       projectBaseDir = moduleBaseDir;
     }
     String projectRelativePath = projectBaseDir.relativize(absolutePath).toString();
-    org.sonar.api.batch.fs.internal.DefaultIndexedFile indexedFile = new DefaultIndexedFile(absolutePath, projectKey, projectRelativePath, relativePath, type, language, id, new SensorStrategy());
-    org.sonar.api.batch.fs.internal.DefaultInputFile inputFile = new org.sonar.api.batch.fs.internal.DefaultInputFile(indexedFile,
+    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);
     inputFile.setStatus(status);
@@ -234,7 +228,7 @@ public class TestInputFileBuilder {
     return inputFile;
   }
 
-  public static org.sonar.api.batch.fs.internal.DefaultInputModule newDefaultInputModule(String moduleKey, File baseDir) {
+  public static DefaultInputModule newDefaultInputModule(String moduleKey, File baseDir) {
     ProjectDefinition definition = ProjectDefinition.create()
       .setKey(moduleKey)
       .setBaseDir(baseDir)
@@ -242,17 +236,17 @@ public class TestInputFileBuilder {
     return newDefaultInputModule(definition);
   }
 
-  public static org.sonar.api.batch.fs.internal.DefaultInputModule newDefaultInputModule(ProjectDefinition projectDefinition) {
-    return new org.sonar.api.batch.fs.internal.DefaultInputModule(projectDefinition, TestInputFileBuilder.nextBatchId());
+  public static DefaultInputModule newDefaultInputModule(ProjectDefinition projectDefinition) {
+    return new DefaultInputModule(projectDefinition, TestInputFileBuilder.nextBatchId());
   }
 
-  public static DefaultInputModule newDefaultInputModule(org.sonar.api.batch.fs.internal.AbstractProjectOrModule 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 org.sonar.api.batch.fs.internal.DefaultInputProject newDefaultInputProject(String projectKey, File baseDir) {
+  public static DefaultInputProject newDefaultInputProject(String projectKey, File baseDir) {
     ProjectDefinition definition = ProjectDefinition.create()
       .setKey(projectKey)
       .setBaseDir(baseDir)
@@ -260,8 +254,8 @@ public class TestInputFileBuilder {
     return newDefaultInputProject(definition);
   }
 
-  public static org.sonar.api.batch.fs.internal.DefaultInputProject newDefaultInputProject(ProjectDefinition projectDefinition) {
-    return new org.sonar.api.batch.fs.internal.DefaultInputProject(projectDefinition, TestInputFileBuilder.nextBatchId());
+  public static DefaultInputProject newDefaultInputProject(ProjectDefinition projectDefinition) {
+    return new DefaultInputProject(projectDefinition, TestInputFileBuilder.nextBatchId());
   }
 
   public static DefaultInputProject newDefaultInputProject(String key, Path baseDir) throws IOException {
@@ -269,7 +263,7 @@ public class TestInputFileBuilder {
     return newDefaultInputProject(key, baseDir.toFile());
   }
 
-  public static org.sonar.api.batch.fs.internal.DefaultInputDir newDefaultInputDir(org.sonar.api.batch.fs.internal.AbstractProjectOrModule module, String relativePath) throws IOException {
+  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)
index 113d44544f7100082249085dc4c259f8133b426c..4b13e2016d1ee1afd3260fa51122d28762685b92 100644 (file)
@@ -27,15 +27,15 @@ import java.util.Objects;
 import java.util.Optional;
 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.scanner.sensor.DefaultStorable;
 import org.sonar.api.batch.sensor.internal.SensorStorage;
 import org.sonar.api.batch.sensor.issue.Issue.Flow;
 import org.sonar.api.batch.sensor.issue.IssueLocation;
 import org.sonar.api.batch.sensor.issue.NewIssueLocation;
 import org.sonar.api.utils.PathUtils;
+import org.sonar.scanner.fs.DefaultInputDir;
+import org.sonar.scanner.fs.DefaultInputModule;
+import org.sonar.scanner.fs.DefaultInputProject;
 
 import static java.util.Collections.unmodifiableList;
 import static java.util.stream.Collectors.toList;
index 8dd8829d9b311a1f5f219053803ab7a9525fe7ff..5485c348c8774a1399d52035ef60f00f5ec2e3ec 100644 (file)
@@ -25,12 +25,12 @@ import org.apache.commons.lang.builder.ToStringBuilder;
 import org.apache.commons.lang.builder.ToStringStyle;
 import org.sonar.api.batch.fs.InputComponent;
 import org.sonar.api.batch.fs.TextRange;
-import org.sonar.api.batch.fs.internal.DefaultInputProject;
-import org.sonar.api.batch.fs.internal.DefaultTextPointer;
-import org.sonar.api.batch.fs.internal.DefaultTextRange;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.scan.issue.filter.FilterableIssue;
 import org.sonar.scanner.ProjectInfo;
+import org.sonar.scanner.fs.DefaultInputProject;
+import org.sonar.scanner.fs.DefaultTextPointer;
+import org.sonar.scanner.fs.DefaultTextRange;
 import org.sonar.scanner.protocol.output.ScannerReport.Issue;
 
 @ThreadSafe
index bf36bf5ac55411c6ba7f176efc30af83512e0d71..154dfc91c814e1b4968e7ada459b9ebb21dc9192 100644 (file)
 package org.sonar.scanner.issue;
 
 import javax.annotation.Nullable;
-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;
 import org.sonar.api.batch.sensor.issue.IssueLocation;
 import org.sonar.api.batch.sensor.issue.NewIssue;
 import org.sonar.api.rule.RuleKey;
+import org.sonar.scanner.fs.DefaultInputProject;
 
 import static java.lang.String.format;
 import static java.util.Objects.requireNonNull;
index 95147bc75a0c2d2963791ef941ed7dd1d9a57e3e..33018bbcc8ffd3e3d2d8b8bb1be6e6e8b686ad40 100644 (file)
@@ -22,9 +22,9 @@ package org.sonar.scanner.issue;
 import javax.annotation.Nullable;
 import org.sonar.api.batch.fs.InputComponent;
 import org.sonar.api.batch.fs.TextRange;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.sensor.issue.IssueLocation;
 import org.sonar.api.batch.sensor.issue.NewIssueLocation;
+import org.sonar.scanner.fs.DefaultInputFile;
 
 import static java.util.Objects.requireNonNull;
 import static org.apache.commons.lang.StringUtils.abbreviate;
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultNoSonarFilter.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultNoSonarFilter.java
new file mode 100644 (file)
index 0000000..00d3ba5
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * 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.scanner.issue;
+
+import java.util.Set;
+import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.issue.NoSonarFilter;
+import org.sonar.scanner.fs.DefaultInputFile;
+
+public class DefaultNoSonarFilter extends NoSonarFilter {
+  public NoSonarFilter noSonarInFile(InputFile inputFile, Set<Integer> noSonarLines) {
+    ((DefaultInputFile) inputFile).noSonarAt(noSonarLines);
+    return this;
+  }
+}
index 2a3e6374dc000312deebad1cad67404c66cc031d..87a4846a81a5625143ce1a2d9a278095776b0a44 100644 (file)
 package org.sonar.scanner.issue;
 
 import org.sonar.api.batch.fs.InputComponent;
-import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.scan.issue.filter.FilterableIssue;
 import org.sonar.api.scan.issue.filter.IssueFilter;
 import org.sonar.api.scan.issue.filter.IssueFilterChain;
 import org.sonar.scanner.ProjectInfo;
+import org.sonar.scanner.fs.DefaultInputProject;
 import org.sonar.scanner.protocol.output.ScannerReport;
 
 /**
index f8a652553ea0e17e5f1a8b95e6e4d474b394186d..ac02497f4745e1411764cad6581c646aebca3ee1 100644 (file)
@@ -24,13 +24,13 @@ import java.util.function.Consumer;
 import javax.annotation.concurrent.ThreadSafe;
 import org.apache.commons.lang.StringUtils;
 import org.sonar.api.batch.fs.TextRange;
-import org.sonar.api.batch.fs.internal.DefaultInputComponent;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.rule.ActiveRule;
 import org.sonar.api.batch.rule.ActiveRules;
 import org.sonar.api.batch.sensor.issue.ExternalIssue;
 import org.sonar.api.batch.sensor.issue.Issue;
 import org.sonar.api.batch.sensor.issue.Issue.Flow;
+import org.sonar.scanner.fs.DefaultInputComponent;
+import org.sonar.scanner.fs.DefaultInputFile;
 import org.sonar.scanner.protocol.Constants.Severity;
 import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.scanner.protocol.output.ScannerReport.IssueLocation;
index 0cf870ea06b8411632ff94bb0f7067d1a7fc5ca8..e518408f13beb47ff2317a64f81aff2085f08cbc 100644 (file)
@@ -24,13 +24,13 @@ import java.util.Collections;
 import java.util.List;
 import javax.annotation.concurrent.ThreadSafe;
 import org.sonar.api.batch.fs.InputComponent;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.notifications.AnalysisWarnings;
 import org.sonar.api.scan.issue.filter.FilterableIssue;
 import org.sonar.api.scan.issue.filter.IssueFilter;
 import org.sonar.api.scan.issue.filter.IssueFilterChain;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
+import org.sonar.scanner.fs.DefaultInputFile;
 import org.sonar.scanner.issue.DefaultFilterableIssue;
 import org.sonar.scanner.issue.ignore.pattern.IssueInclusionPatternInitializer;
 import org.sonar.scanner.issue.ignore.pattern.IssuePattern;
index 666b1732deabdb7ebda4bde7ee50152009d03c7d..8d825944b849e2bccad4a74b8de86680831d7a6e 100644 (file)
@@ -22,13 +22,13 @@ package org.sonar.scanner.issue.ignore;
 import com.google.common.collect.LinkedHashMultimap;
 import com.google.common.collect.Multimap;
 import org.sonar.api.batch.fs.InputComponent;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.scan.issue.filter.FilterableIssue;
 import org.sonar.api.scan.issue.filter.IssueFilter;
 import org.sonar.api.scan.issue.filter.IssueFilterChain;
 import org.sonar.api.utils.WildcardPattern;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
+import org.sonar.scanner.fs.DefaultInputFile;
 import org.sonar.scanner.issue.DefaultFilterableIssue;
 
 public class IgnoreIssuesFilter implements IssueFilter {
index 858a4dd5d2f06c7792dc5812afe8609bcb0c4acf..4c3117835ca37de5481d520b4767ecdde25cde09 100644 (file)
@@ -23,10 +23,10 @@ import java.util.ArrayList;
 import java.util.List;
 import javax.annotation.CheckForNull;
 import org.apache.commons.lang.StringUtils;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.notifications.AnalysisWarnings;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
+import org.sonar.scanner.fs.DefaultInputFile;
 import org.sonar.scanner.fs.charhandler.CharHandler;
 import org.sonar.scanner.issue.ignore.IgnoreIssuesFilter;
 import org.sonar.scanner.issue.ignore.pattern.BlockIssuePattern;
index 19079dbac4f42dc24acfbb94d8d0674d64d8a1ae..2ab767f7f3b7e9052b5f988b5a585d6531f1ffb8 100644 (file)
@@ -25,9 +25,9 @@ import java.util.List;
 import java.util.Set;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
+import org.sonar.scanner.fs.DefaultInputFile;
 import org.sonar.scanner.fs.charhandler.CharHandler;
 import org.sonar.scanner.issue.ignore.pattern.LineRange;
 import org.sonar.scanner.issue.ignore.scanner.IssueExclusionsLoader.DoubleRegexpMatcher;
index cd9f6f67421ab87b31ab59ab5d8671d75a0b8a40..c75da29f0ed1bac3bf9464b76330e8534cdfd2f5 100644 (file)
@@ -34,11 +34,11 @@ import org.sonar.api.batch.fs.InputComponent;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.TextPointer;
 import org.sonar.api.batch.fs.TextRange;
-import org.sonar.api.batch.fs.internal.DefaultInputComponent;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.sensor.highlighting.TypeOfText;
 import org.sonar.api.scanner.fs.InputProject;
 import org.sonar.core.util.CloseableIterator;
+import org.sonar.scanner.fs.DefaultInputComponent;
+import org.sonar.scanner.fs.DefaultInputFile;
 import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.scanner.protocol.output.ScannerReport.Component;
 import org.sonar.scanner.protocol.output.ScannerReport.Symbol;
index ff393c42773f8fce249ddb73dae99ab7eeadfc54..00d8bed5abfb56ef9bb90bf57fa77064bc297a4f 100644 (file)
@@ -25,12 +25,12 @@ import java.util.Map;
 import java.util.Set;
 import java.util.stream.Collectors;
 import java.util.stream.StreamSupport;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.batch.scm.ScmProvider;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.api.utils.log.Profiler;
+import org.sonar.scanner.fs.DefaultInputFile;
+import org.sonar.scanner.fs.DefaultInputProject;
 import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.scanner.protocol.output.ScannerReportWriter;
 import org.sonar.scanner.scan.branch.BranchConfiguration;
index dfd8163cb5289b66bd99d4c509b4f968fae09351..597785f763258caac0064291e78aeb5f95198fb4 100644 (file)
@@ -25,9 +25,9 @@ import org.apache.commons.lang.StringUtils;
 import org.sonar.api.CoreProperties;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.InputFile.Status;
-import org.sonar.api.batch.fs.internal.AbstractProjectOrModule;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputProject;
+import org.sonar.scanner.fs.AbstractProjectOrModule;
+import org.sonar.scanner.fs.DefaultInputFile;
+import org.sonar.scanner.fs.DefaultInputProject;
 import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType;
 import org.sonar.scanner.protocol.output.ScannerReport.Component.FileStatus;
@@ -44,7 +44,6 @@ public class ComponentsPublisher implements ReportPublisherStep {
   private final InputComponentStore inputComponentStore;
   private final DefaultInputProject project;
 
-
   public ComponentsPublisher(DefaultInputProject project, InputComponentStore inputComponentStore) {
     this.project = project;
     this.inputComponentStore = inputComponentStore;
@@ -123,7 +122,7 @@ public class ComponentsPublisher implements ReportPublisherStep {
   }
 
   private static void writeProjectLink(ScannerReport.Component.Builder componentBuilder, Map<String, String> properties, ComponentLink.Builder linkBuilder, String linkProp,
-                                       ComponentLinkType linkType) {
+    ComponentLinkType linkType) {
     String link = properties.get(linkProp);
     if (StringUtils.isNotBlank(link)) {
       linkBuilder.setType(linkType);
index 06f20e70e95d20e4ddb1e81ef053054033e90de7..be1e838b810f36770511b83232cda60bf8f4896a 100644 (file)
@@ -25,9 +25,6 @@ import java.util.LinkedList;
 import java.util.Map.Entry;
 import java.util.regex.Pattern;
 import javax.annotation.Nullable;
-import org.sonar.api.batch.fs.internal.AbstractProjectOrModule;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
-import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
 import org.sonar.api.batch.scm.ScmProvider;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
@@ -35,6 +32,9 @@ import org.sonar.scanner.ProjectInfo;
 import org.sonar.scanner.bootstrap.ScannerPlugin;
 import org.sonar.scanner.bootstrap.ScannerPluginRepository;
 import org.sonar.scanner.cpd.CpdSettings;
+import org.sonar.scanner.fs.AbstractProjectOrModule;
+import org.sonar.scanner.fs.DefaultInputModule;
+import org.sonar.scanner.fs.InputModuleHierarchy;
 import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.scanner.protocol.output.ScannerReport.Metadata.BranchType;
 import org.sonar.scanner.protocol.output.ScannerReportWriter;
index dbee000ded12d8d9bea62543da9491d7cc6e35e0..c2afdc1baf275c75419c080caac4eeda8d6ba277 100644 (file)
@@ -36,7 +36,6 @@ import javax.annotation.Nullable;
 import okhttp3.HttpUrl;
 import org.apache.commons.io.FileUtils;
 import org.picocontainer.Startable;
-import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
 import org.sonar.api.platform.Server;
 import org.sonar.api.utils.MessageException;
 import org.sonar.api.utils.TempFolder;
@@ -45,6 +44,7 @@ import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
 import org.sonar.scanner.bootstrap.ScannerWsClient;
+import org.sonar.scanner.fs.InputModuleHierarchy;
 import org.sonar.scanner.protocol.output.ScannerReportReader;
 import org.sonar.scanner.protocol.output.ScannerReportWriter;
 import org.sonar.scanner.scan.ScanProperties;
index 3ab19165dcc5502a993df4ac2f13b578b485554d..765ac95da04c739e8e7e7a60f74643be57a9ce29 100644 (file)
@@ -28,9 +28,8 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.nio.charset.StandardCharsets;
-
 import org.apache.commons.io.IOUtils;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
+import org.sonar.scanner.fs.DefaultInputFile;
 import org.sonar.scanner.protocol.output.ScannerReportWriter;
 import org.sonar.scanner.scan.filesystem.InputComponentStore;
 
index ad4ac749120bfbc3dfd7f251ff2501d1de2c808b..f04f204bf2b82f6836464ff444929f4ed0ac93ef 100644 (file)
@@ -24,16 +24,16 @@ import java.util.Objects;
 import java.util.stream.StreamSupport;
 import org.sonar.api.batch.fs.InputComponent;
 import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputComponent;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.scanner.sensor.DefaultMeasure;
 import org.sonar.api.test.MutableTestPlan;
 import org.sonar.api.test.TestCase;
 import org.sonar.api.test.TestCase.Status;
 import org.sonar.scanner.deprecated.test.TestPlanBuilder;
+import org.sonar.scanner.fs.DefaultInputComponent;
+import org.sonar.scanner.fs.DefaultInputFile;
 import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.scanner.protocol.output.ScannerReportWriter;
 import org.sonar.scanner.scan.filesystem.InputComponentStore;
+import org.sonar.scanner.sensor.DefaultMeasure;
 
 import static org.sonar.api.measures.CoreMetrics.SKIPPED_TESTS;
 import static org.sonar.api.measures.CoreMetrics.TESTS;
index 7ca0913805c5915d9cd8aa1effccf60b6897a7e9..d1a7a30080ca7b0464087129c3e6a544de654e77 100644 (file)
@@ -21,7 +21,7 @@ package org.sonar.scanner.repository;
 
 import javax.annotation.CheckForNull;
 import javax.annotation.concurrent.Immutable;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
+import org.sonar.scanner.fs.DefaultInputFile;
 
 @Immutable
 public abstract class ProjectRepositories {
index 067f830edbe3f64ebe11b86862fa0d364ca8701a..aa6cbeb0db1d82a28492249c73c5b1f64a06c8c1 100644 (file)
@@ -27,10 +27,10 @@ import java.util.HashMap;
 import java.util.Map;
 import javax.annotation.CheckForNull;
 import javax.annotation.concurrent.Immutable;
-import org.sonar.api.batch.fs.internal.AbstractProjectOrModule;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
-import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
 import org.sonar.api.scan.filesystem.PathResolver;
+import org.sonar.scanner.fs.AbstractProjectOrModule;
+import org.sonar.scanner.fs.DefaultInputModule;
+import org.sonar.scanner.fs.InputModuleHierarchy;
 
 @Immutable
 public class DefaultInputModuleHierarchy implements InputModuleHierarchy {
index ffe0e15f073721bb9329341185cb6d17d1b2b2d7..da0b8781ddecc176105a6b148339609fb3ceb4ba 100644 (file)
@@ -24,10 +24,10 @@ import java.util.Locale;
 import java.util.Map;
 import org.picocontainer.injectors.ProviderAdapter;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
-import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
+import org.sonar.scanner.fs.DefaultInputModule;
+import org.sonar.scanner.fs.DefaultInputProject;
 import org.sonar.scanner.scan.filesystem.ScannerComponentIdGenerator;
 
 public class InputModuleHierarchyProvider extends ProviderAdapter {
@@ -51,7 +51,7 @@ public class InputModuleHierarchyProvider extends ProviderAdapter {
   }
 
   private static Map<DefaultInputModule, DefaultInputModule> createChildren(DefaultInputModule parent, ScannerComponentIdGenerator scannerComponentIdGenerator,
-                                                                                      Map<DefaultInputModule, DefaultInputModule> parents) {
+    Map<DefaultInputModule, DefaultInputModule> parents) {
     for (ProjectDefinition def : parent.definition().getSubProjects()) {
       DefaultInputModule child = createModule(def, scannerComponentIdGenerator.getAsInt());
       parents.put(child, parent);
index 08303ac0a0bc97a01e8e72fecdabcc100e17fada..1219f2871dd5decd2e1d39690182d82c8fc2ab87 100644 (file)
@@ -22,15 +22,14 @@ package org.sonar.scanner.scan;
 import java.util.Locale;
 import org.picocontainer.injectors.ProviderAdapter;
 import org.sonar.api.batch.bootstrap.ProjectReactor;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
-import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
+import org.sonar.scanner.fs.DefaultInputProject;
 import org.sonar.scanner.scan.filesystem.ScannerComponentIdGenerator;
 
 public class InputProjectProvider extends ProviderAdapter {
 
-  private static final Logger LOG = Loggers.get(DefaultInputModule.class);
+  private static final Logger LOG = Loggers.get(InputProjectProvider.class);
 
   private DefaultInputProject project = null;
 
index fd409e22d6b7c16a4707bc4b110bf7791e5b8538..21d241c23f4bea5e498271499e352bf4486ded7b 100644 (file)
@@ -25,9 +25,9 @@ import java.util.List;
 import java.util.Map;
 import org.picocontainer.injectors.ProviderAdapter;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
 import org.sonar.scanner.bootstrap.GlobalConfiguration;
 import org.sonar.scanner.bootstrap.GlobalServerSettings;
+import org.sonar.scanner.fs.DefaultInputModule;
 
 public class ModuleConfigurationProvider extends ProviderAdapter {
 
index da1c14363ca3a43aa16011f2afc093667ce8ff91..1bc1611097fa94ee7c05b1e151f3d1c3fa26d976 100644 (file)
@@ -20,8 +20,8 @@
 package org.sonar.scanner.scan;
 
 import org.picocontainer.Startable;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
-import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
+import org.sonar.scanner.fs.DefaultInputModule;
+import org.sonar.scanner.fs.InputModuleHierarchy;
 import org.sonar.scanner.scan.filesystem.InputComponentStore;
 
 /**
index e771f958e7ce3223865fab71c541ea947d356e88..1a7a78f93cf889ffd9b2aa6e8da206d39227be7b 100644 (file)
  */
 package org.sonar.scanner.scan;
 
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
 import org.sonar.api.scan.filesystem.FileExclusions;
 import org.sonar.core.platform.ComponentContainer;
 import org.sonar.scanner.bootstrap.ExtensionInstaller;
 import org.sonar.scanner.deprecated.perspectives.ScannerPerspectives;
+import org.sonar.scanner.fs.DefaultInputModule;
 import org.sonar.scanner.scan.filesystem.DefaultModuleFileSystem;
 import org.sonar.scanner.scan.filesystem.ModuleInputComponentStore;
 import org.sonar.scanner.sensor.ModuleSensorContext;
index b3e127a80cde0a38085f1a0df919c7faf83dfe0f..0d17b4a81142ca226f4d2456dbca7bc65e905dab 100644 (file)
@@ -22,9 +22,9 @@ package org.sonar.scanner.scan;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import org.picocontainer.injectors.ProviderAdapter;
-import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.scanner.bootstrap.GlobalConfiguration;
 import org.sonar.scanner.bootstrap.GlobalServerSettings;
+import org.sonar.scanner.fs.DefaultInputProject;
 
 public class ProjectConfigurationProvider extends ProviderAdapter {
 
index 89bfe76c1f278b68e777fb03b794baa3d19bdbe4..9bf6bf731152ec42c679245e956c0ee2b19f2321 100644 (file)
@@ -24,7 +24,7 @@ import java.nio.channels.OverlappingFileLockException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import org.picocontainer.Startable;
-import org.sonar.api.batch.fs.internal.AbstractProjectOrModule;
+import org.sonar.scanner.fs.AbstractProjectOrModule;
 
 public class ProjectLock implements Startable {
   private final DirectoryLock lock;
index 411625c7546b8abf4c958a015965678c214e4f71..8cd93d031c46686fb5dbe0199744d349f8c08fc9 100644 (file)
@@ -23,11 +23,8 @@ import com.google.common.annotations.VisibleForTesting;
 import javax.annotation.Nullable;
 import org.sonar.api.SonarEdition;
 import org.sonar.api.SonarRuntime;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
-import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
 import org.sonar.api.batch.fs.internal.SensorStrategy;
 import org.sonar.api.batch.rule.CheckFactory;
-import org.sonar.api.issue.NoSonarFilter;
 import org.sonar.api.resources.Languages;
 import org.sonar.api.resources.ResourceTypes;
 import org.sonar.api.scan.filesystem.PathResolver;
@@ -66,7 +63,10 @@ import org.sonar.scanner.cpd.CpdSettings;
 import org.sonar.scanner.cpd.index.SonarCpdBlockIndex;
 import org.sonar.scanner.deprecated.test.TestPlanBuilder;
 import org.sonar.scanner.deprecated.test.TestableBuilder;
+import org.sonar.scanner.fs.DefaultInputModule;
 import org.sonar.scanner.fs.FileMetadata;
+import org.sonar.scanner.fs.InputModuleHierarchy;
+import org.sonar.scanner.issue.DefaultNoSonarFilter;
 import org.sonar.scanner.issue.IssueFilters;
 import org.sonar.scanner.issue.IssuePublisher;
 import org.sonar.scanner.issue.ignore.EnforceIssuesFilter;
@@ -203,7 +203,7 @@ public class ProjectScanContainer extends ComponentContainer {
       QProfileVerifier.class,
 
       // issues
-      NoSonarFilter.class,
+      DefaultNoSonarFilter.class,
       IssueFilters.class,
       IssuePublisher.class,
 
index 22a7751c0355379030248991fe71e30f3ecb1902..2fa3bbeaf02374b2c58658eb283f47b1ad703d30 100644 (file)
@@ -22,9 +22,9 @@ package org.sonar.scanner.scan;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.Optional;
-import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.config.Configuration;
 import org.sonar.api.utils.MessageException;
+import org.sonar.scanner.fs.DefaultInputProject;
 
 import static org.sonar.core.config.ScannerProperties.BRANCH_NAME;
 import static org.sonar.core.config.ScannerProperties.ORGANIZATION;
index 77ab7341bba538d7633e090e46fd47e5a9d44eca..8c5b01e4b2bd24249ceb7a4f7d7dad16172ae8a4 100644 (file)
@@ -24,9 +24,9 @@ import java.nio.file.DirectoryStream;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.Iterator;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
-import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
 import org.sonar.core.util.FileUtils;
+import org.sonar.scanner.fs.DefaultInputModule;
+import org.sonar.scanner.fs.InputModuleHierarchy;
 
 /**
  * Clean and create working directories of each module.
index bb8f5fc22f1ca6b74e7866c41366a91228d3db34..1bcbad7f75a86151948321bf0b033b68705d2699 100644 (file)
@@ -25,10 +25,10 @@ import java.util.stream.Collectors;
 import java.util.stream.Stream;
 import javax.annotation.concurrent.Immutable;
 import org.sonar.api.CoreProperties;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.utils.WildcardPattern;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
+import org.sonar.scanner.fs.DefaultInputFile;
 
 import static java.util.stream.Collectors.toList;
 
index 74e82cd853594abf9a9b2f43301c13e77706bc08..d25948764dd70a2e9cb0886f818658cfafa98f13 100644 (file)
@@ -20,8 +20,8 @@
 package org.sonar.scanner.scan.filesystem;
 
 import com.google.common.annotations.VisibleForTesting;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
 import org.sonar.scanner.fs.DefaultFileSystem;
+import org.sonar.scanner.fs.DefaultInputModule;
 
 public class DefaultModuleFileSystem extends DefaultFileSystem {
 
index 7e0dbc6f6af5dcb797e791c55abeae6cf1466d57..294b0b946d118bb09be5b3c92f90ad2d56b6ede3 100644 (file)
@@ -20,8 +20,8 @@
 package org.sonar.scanner.scan.filesystem;
 
 import com.google.common.annotations.VisibleForTesting;
-import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.scanner.fs.DefaultFileSystem;
+import org.sonar.scanner.fs.DefaultInputProject;
 
 public class DefaultProjectFileSystem extends DefaultFileSystem {
 
index 982d413a71fd7f4dcd690d5d7fd28523ca9189de..56c2133396229915194fcf772c881369f0828ede 100644 (file)
@@ -30,16 +30,16 @@ import org.sonar.api.CoreProperties;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.InputFile.Type;
 import org.sonar.api.batch.fs.InputFileFilter;
-import org.sonar.api.batch.fs.internal.DefaultIndexedFile;
-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.SensorStrategy;
 import org.sonar.api.batch.scm.IgnoreCommand;
 import org.sonar.api.notifications.AnalysisWarnings;
 import org.sonar.api.utils.MessageException;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
+import org.sonar.scanner.fs.DefaultIndexedFile;
+import org.sonar.scanner.fs.DefaultInputFile;
+import org.sonar.scanner.fs.DefaultInputModule;
+import org.sonar.scanner.fs.DefaultInputProject;
 import org.sonar.scanner.issue.ignore.scanner.IssueExclusionsLoader;
 import org.sonar.scanner.scan.ScanProperties;
 import org.sonar.scanner.util.ProgressReport;
index cd9f0db73472696c1005640221e32d787b05c8b2..4eab927136dd9cbae6c2233ae4298a8a6e0e013a 100644 (file)
@@ -35,9 +35,9 @@ import java.util.stream.Stream;
 import javax.annotation.CheckForNull;
 import org.sonar.api.batch.fs.InputComponent;
 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.scanner.fs.DefaultFileSystem;
+import org.sonar.scanner.fs.DefaultInputFile;
+import org.sonar.scanner.fs.DefaultInputModule;
 import org.sonar.scanner.fs.predicates.FileExtensionPredicate;
 import org.sonar.scanner.scan.branch.BranchConfiguration;
 
index 80731033ac01fc3b9dffe79fb0a2ed5ceb829f25..2da2f6db0c411627904e2b8837eb7efed375ba91 100644 (file)
@@ -23,10 +23,10 @@ import com.google.common.annotations.VisibleForTesting;
 import java.io.InputStream;
 import java.nio.charset.Charset;
 import org.sonar.api.batch.fs.InputFile.Type;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.fs.internal.Metadata;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
+import org.sonar.scanner.fs.DefaultInputFile;
 import org.sonar.scanner.fs.FileMetadata;
 import org.sonar.scanner.issue.ignore.scanner.IssueExclusionsLoader;
 
index 5cb50568741c73cec95a35852d88787bb340639f..3ef961f83e2cd732048bd4aeb90ddc9d724c9824 100644 (file)
@@ -20,7 +20,7 @@
 package org.sonar.scanner.scan.filesystem;
 
 import javax.annotation.concurrent.Immutable;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
+import org.sonar.scanner.fs.DefaultInputFile;
 import org.sonar.scanner.scan.ModuleConfiguration;
 
 @Immutable
index 1cf496f1310a8c666f65b5271696338d3a37c6cd..4ab146afb275a80a48d69b71da35e6b64c3a924c 100644 (file)
@@ -20,7 +20,7 @@
 package org.sonar.scanner.scan.filesystem;
 
 import javax.annotation.concurrent.Immutable;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
+import org.sonar.scanner.fs.DefaultInputFile;
 import org.sonar.scanner.scan.ProjectConfiguration;
 
 @Immutable
index 2a60b91322a44bbf936bcee9113f0c289449924d..118b3eb5567c687963cee9dca3bab464f7998a93 100644 (file)
@@ -39,14 +39,14 @@ import java.util.concurrent.atomic.AtomicInteger;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.SystemUtils;
 import org.sonar.api.batch.fs.InputFile.Type;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
-import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
 import org.sonar.api.batch.scm.IgnoreCommand;
 import org.sonar.api.scan.filesystem.PathResolver;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.scanner.bootstrap.GlobalConfiguration;
 import org.sonar.scanner.bootstrap.GlobalServerSettings;
+import org.sonar.scanner.fs.DefaultInputModule;
+import org.sonar.scanner.fs.InputModuleHierarchy;
 import org.sonar.scanner.scan.ModuleConfiguration;
 import org.sonar.scanner.scan.ModuleConfigurationProvider;
 import org.sonar.scanner.scan.ProjectServerSettings;
@@ -163,7 +163,7 @@ public class ProjectFileIndexer {
   private static void logPaths(String label, Path baseDir, List<Path> paths) {
     if (!paths.isEmpty()) {
       StringBuilder sb = new StringBuilder(label);
-      for (Iterator<Path> it = paths.iterator(); it.hasNext();) {
+      for (Iterator<Path> it = paths.iterator(); it.hasNext(); ) {
         Path file = it.next();
         Optional<String> relativePathToBaseDir = PathResolver.relativize(baseDir, file);
         if (!relativePathToBaseDir.isPresent()) {
index 09561999935295f3218abfcbce6b9434fcf4483f..2cd3f8d5240b96fd5a2382531260d08a6c362ba7 100644 (file)
@@ -22,7 +22,7 @@ package org.sonar.scanner.scan.filesystem;
 import javax.annotation.concurrent.Immutable;
 import org.apache.commons.lang.StringUtils;
 import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
+import org.sonar.scanner.fs.DefaultInputFile;
 import org.sonar.scanner.repository.FileData;
 import org.sonar.scanner.repository.ProjectRepositoriesSupplier;
 import org.sonar.scanner.scm.ScmChangedFiles;
index 3e6833cf34ba35f90febf036298ee7dd23fd07f5..e2742ea4d3a86245b15b92d814485120f18603b8 100644 (file)
@@ -30,11 +30,11 @@ import java.util.concurrent.TimeUnit;
 import javax.annotation.Nullable;
 import org.apache.commons.lang.StringUtils;
 import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.scm.BlameCommand.BlameOutput;
 import org.sonar.api.batch.scm.BlameLine;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
+import org.sonar.scanner.fs.DefaultInputFile;
 import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.scanner.protocol.output.ScannerReport.Changesets.Builder;
 import org.sonar.scanner.protocol.output.ScannerReportWriter;
index b7fd4c8bf76c112dfbae388449f20702d86e02ec..6e93b9d4ad64d1a5189d7ded0a279985c7f6115d 100644 (file)
@@ -23,11 +23,11 @@ import java.nio.file.Path;
 import java.util.Collection;
 import javax.annotation.CheckForNull;
 import org.picocontainer.injectors.ProviderAdapter;
-import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.batch.scm.ScmProvider;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.api.utils.log.Profiler;
+import org.sonar.scanner.fs.DefaultInputProject;
 import org.sonar.scanner.scan.branch.BranchConfiguration;
 import org.sonar.scanner.util.ScannerUtils;
 
index 5c0e2902d8e48079b921885f93ab0f683c70a9e3..3ee057eacb7854d6c0ca0b2795a62a37be4b7d62 100644 (file)
@@ -30,7 +30,6 @@ import org.sonar.api.Properties;
 import org.sonar.api.Property;
 import org.sonar.api.PropertyType;
 import org.sonar.api.batch.AnalysisMode;
-import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
 import org.sonar.api.batch.scm.ScmProvider;
 import org.sonar.api.config.Configuration;
 import org.sonar.api.notifications.AnalysisWarnings;
@@ -38,6 +37,7 @@ import org.sonar.api.utils.MessageException;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.core.config.ScannerProperties;
+import org.sonar.scanner.fs.InputModuleHierarchy;
 
 import static org.sonar.api.CoreProperties.SCM_PROVIDER_KEY;
 
index 819abc8adcec209130d8d4c6280cf105b88202fb..7b048096dab308213e5f5f314791181b34250e31 100644 (file)
@@ -26,10 +26,10 @@ import org.sonar.api.CoreProperties;
 import org.sonar.api.batch.fs.FileSystem;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.InputFile.Status;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.scm.ScmProvider;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
+import org.sonar.scanner.fs.DefaultInputFile;
 import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.scanner.protocol.output.ScannerReport.Changesets.Builder;
 import org.sonar.scanner.protocol.output.ScannerReportWriter;
index 6eb15be6e8109100c434744bc727df0df2dd0e6e..94cd490cbe24bf2e17eb5f8e96f5ab89bab82740 100644 (file)
 package org.sonar.scanner.scm;
 
 import java.util.Optional;
-import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
 import org.sonar.api.batch.scm.ScmProvider;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.scanner.bootstrap.RawScannerProperties;
 import org.sonar.scanner.ci.CiConfiguration;
+import org.sonar.scanner.fs.InputModuleHierarchy;
 
 import static org.apache.commons.lang.StringUtils.isBlank;
 import static org.sonar.scanner.scan.ScanProperties.SCM_REVISION;
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/AbstractDefaultIssue.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/AbstractDefaultIssue.java
deleted file mode 100644 (file)
index b77d114..0000000
+++ /dev/null
@@ -1,122 +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.scanner.sensor;
-
-import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Objects;
-import java.util.Optional;
-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;
-import org.sonar.api.batch.sensor.issue.IssueLocation;
-import org.sonar.api.batch.sensor.issue.NewIssueLocation;
-import org.sonar.api.utils.PathUtils;
-
-import static java.util.Collections.unmodifiableList;
-import static java.util.stream.Collectors.toList;
-import static org.sonar.api.utils.Preconditions.checkArgument;
-import static org.sonar.api.utils.Preconditions.checkState;
-
-public abstract class AbstractDefaultIssue<T extends AbstractDefaultIssue> extends DefaultStorable {
-  protected IssueLocation primaryLocation;
-  protected List<List<IssueLocation>> flows = new ArrayList<>();
-  protected DefaultInputProject project;
-
-  protected AbstractDefaultIssue(DefaultInputProject project) {
-    this(project, null);
-  }
-
-  public AbstractDefaultIssue(DefaultInputProject project, @Nullable SensorStorage storage) {
-    super(storage);
-    this.project = project;
-  }
-
-  public IssueLocation primaryLocation() {
-    return primaryLocation;
-  }
-
-  public List<Flow> flows() {
-    return this.flows.stream()
-      .<Flow>map(l -> () -> unmodifiableList(new ArrayList<>(l)))
-      .collect(toList());
-  }
-
-  public NewIssueLocation newLocation() {
-    return new DefaultIssueLocation();
-  }
-
-  public T at(NewIssueLocation primaryLocation) {
-    checkArgument(primaryLocation != null, "Cannot use a location that is null");
-    checkState(this.primaryLocation == null, "at() already called");
-    this.primaryLocation = rewriteLocation((DefaultIssueLocation) primaryLocation);
-    checkArgument(this.primaryLocation.inputComponent() != null, "Cannot use a location with no input component");
-    return (T) this;
-  }
-
-  public T addLocation(NewIssueLocation secondaryLocation) {
-    flows.add(Collections.singletonList(rewriteLocation((DefaultIssueLocation) secondaryLocation)));
-    return (T) this;
-  }
-
-  public T addFlow(Iterable<NewIssueLocation> locations) {
-    List<IssueLocation> flowAsList = new ArrayList<>();
-    for (NewIssueLocation issueLocation : locations) {
-      flowAsList.add(rewriteLocation((DefaultIssueLocation) issueLocation));
-    }
-    flows.add(flowAsList);
-    return (T) this;
-  }
-
-  private DefaultIssueLocation rewriteLocation(DefaultIssueLocation location) {
-    InputComponent component = location.inputComponent();
-    Optional<Path> dirOrModulePath = Optional.empty();
-
-    if (component instanceof DefaultInputDir) {
-      DefaultInputDir dirComponent = (DefaultInputDir) component;
-      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(project.getBaseDir().relativize(moduleComponent.getBaseDir()));
-    }
-
-    if (dirOrModulePath.isPresent()) {
-      String path = PathUtils.sanitize(dirOrModulePath.get().toString());
-      DefaultIssueLocation fixedLocation = new DefaultIssueLocation();
-      fixedLocation.on(project);
-      StringBuilder fullMessage = new StringBuilder();
-      if (path != null && !path.isEmpty()) {
-        fullMessage.append("[").append(path).append("] ");
-      }
-      fullMessage.append(location.message());
-      fixedLocation.message(fullMessage.toString());
-      return fixedLocation;
-    } else {
-      return location;
-    }
-  }
-}
index 23dbd341c36980736907de1d1942d7eeaf11ff6d..1dde73e2c5c7eec39db7ebf3869b7ef1262bdc9d 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.scanner.sensor;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 import org.sonar.api.batch.rule.Severity;
-import org.sonar.api.batch.sensor.internal.DefaultStorable;
 import org.sonar.api.batch.sensor.internal.SensorStorage;
 import org.sonar.api.batch.sensor.rule.AdHocRule;
 import org.sonar.api.batch.sensor.rule.NewAdHocRule;
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultAnalysisError.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultAnalysisError.java
new file mode 100644 (file)
index 0000000..3da46d8
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * 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.scanner.sensor;
+
+import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.fs.TextPointer;
+import org.sonar.api.batch.sensor.error.AnalysisError;
+import org.sonar.api.batch.sensor.error.NewAnalysisError;
+import org.sonar.api.batch.sensor.internal.SensorStorage;
+
+import static java.util.Objects.requireNonNull;
+import static org.sonar.api.utils.Preconditions.checkArgument;
+import static org.sonar.api.utils.Preconditions.checkState;
+
+public class DefaultAnalysisError extends DefaultStorable implements NewAnalysisError, AnalysisError {
+  private InputFile inputFile;
+  private String message;
+  private TextPointer location;
+
+  public DefaultAnalysisError() {
+    super(null);
+  }
+
+  public DefaultAnalysisError(SensorStorage storage) {
+    super(storage);
+  }
+
+  @Override
+  public InputFile inputFile() {
+    return inputFile;
+  }
+
+  @Override
+  public String message() {
+    return message;
+  }
+
+  @Override
+  public TextPointer location() {
+    return location;
+  }
+
+  @Override
+  public NewAnalysisError onFile(InputFile inputFile) {
+    checkArgument(inputFile != null, "Cannot use a inputFile that is null");
+    checkState(this.inputFile == null, "onFile() already called");
+    this.inputFile = inputFile;
+    return this;
+  }
+
+  @Override
+  public NewAnalysisError message(String message) {
+    this.message = message;
+    return this;
+  }
+
+  @Override
+  public NewAnalysisError at(TextPointer location) {
+    checkState(this.location == null, "at() already called");
+    this.location = location;
+    return this;
+  }
+
+  @Override
+  protected void doSave() {
+    requireNonNull(this.inputFile, "inputFile is mandatory on AnalysisError");
+    storage.store(this);
+  }
+
+}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultCoverage.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultCoverage.java
new file mode 100644 (file)
index 0000000..5a2f048
--- /dev/null
@@ -0,0 +1,157 @@
+/*
+ * 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.scanner.sensor;
+
+import java.util.Collections;
+import java.util.SortedMap;
+import java.util.TreeMap;
+import javax.annotation.Nullable;
+import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.sensor.coverage.CoverageType;
+import org.sonar.api.batch.sensor.coverage.NewCoverage;
+import org.sonar.api.batch.sensor.internal.SensorStorage;
+import org.sonar.scanner.fs.DefaultInputFile;
+
+import static java.util.Objects.requireNonNull;
+import static org.sonar.api.utils.Preconditions.checkState;
+
+public class DefaultCoverage extends DefaultStorable implements NewCoverage {
+
+  private InputFile inputFile;
+  private CoverageType type;
+  private int totalCoveredLines = 0;
+  private int totalConditions = 0;
+  private int totalCoveredConditions = 0;
+  private SortedMap<Integer, Integer> hitsByLine = new TreeMap<>();
+  private SortedMap<Integer, Integer> conditionsByLine = new TreeMap<>();
+  private SortedMap<Integer, Integer> coveredConditionsByLine = new TreeMap<>();
+
+  public DefaultCoverage() {
+    super();
+  }
+
+  public DefaultCoverage(@Nullable SensorStorage storage) {
+    super(storage);
+  }
+
+  @Override
+  public DefaultCoverage onFile(InputFile inputFile) {
+    this.inputFile = inputFile;
+    return this;
+  }
+
+  public InputFile inputFile() {
+    return inputFile;
+  }
+
+  @Override
+  public NewCoverage ofType(CoverageType type) {
+    this.type = requireNonNull(type, "type can't be null");
+    return this;
+  }
+
+  public CoverageType type() {
+    return type;
+  }
+
+  @Override
+  public NewCoverage lineHits(int line, int hits) {
+    validateFile();
+    if (isExcluded()) {
+      return this;
+    }
+    validateLine(line);
+
+    if (!hitsByLine.containsKey(line)) {
+      hitsByLine.put(line, hits);
+      if (hits > 0) {
+        totalCoveredLines += 1;
+      }
+    }
+    return this;
+  }
+
+  private void validateLine(int line) {
+    checkState(line <= inputFile.lines(), "Line %s is out of range in the file %s (lines: %s)", line, inputFile, inputFile.lines());
+    checkState(line > 0, "Line number must be strictly positive: %s", line);
+  }
+
+  private void validateFile() {
+    requireNonNull(inputFile, "Call onFile() first");
+  }
+
+  @Override
+  public NewCoverage conditions(int line, int conditions, int coveredConditions) {
+    validateFile();
+    if (isExcluded()) {
+      return this;
+    }
+    validateLine(line);
+
+    if (conditions > 0 && !conditionsByLine.containsKey(line)) {
+      totalConditions += conditions;
+      totalCoveredConditions += coveredConditions;
+      conditionsByLine.put(line, conditions);
+      coveredConditionsByLine.put(line, coveredConditions);
+    }
+    return this;
+  }
+
+  public int coveredLines() {
+    return totalCoveredLines;
+  }
+
+  public int linesToCover() {
+    return hitsByLine.size();
+  }
+
+  public int conditions() {
+    return totalConditions;
+  }
+
+  public int coveredConditions() {
+    return totalCoveredConditions;
+  }
+
+  public SortedMap<Integer, Integer> hitsByLine() {
+    return Collections.unmodifiableSortedMap(hitsByLine);
+  }
+
+  public SortedMap<Integer, Integer> conditionsByLine() {
+    return Collections.unmodifiableSortedMap(conditionsByLine);
+  }
+
+  public SortedMap<Integer, Integer> coveredConditionsByLine() {
+    return Collections.unmodifiableSortedMap(coveredConditionsByLine);
+  }
+
+  @Override
+  public void doSave() {
+    validateFile();
+    if (!isExcluded()) {
+      storage.store(this);
+    }
+  }
+
+  private boolean isExcluded() {
+    return ((DefaultInputFile) inputFile).isExcludedForCoverage();
+  }
+
+}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultCpdTokens.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultCpdTokens.java
new file mode 100644 (file)
index 0000000..d470ab7
--- /dev/null
@@ -0,0 +1,136 @@
+/*
+ * 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.scanner.sensor;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.fs.TextRange;
+import org.sonar.api.batch.sensor.cpd.NewCpdTokens;
+import org.sonar.api.batch.sensor.cpd.internal.TokensLine;
+import org.sonar.api.batch.sensor.internal.SensorStorage;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
+import org.sonar.scanner.fs.DefaultInputFile;
+
+import static java.util.Collections.unmodifiableList;
+import static java.util.Objects.requireNonNull;
+import static org.sonar.api.utils.Preconditions.checkState;
+
+public class DefaultCpdTokens extends DefaultStorable implements NewCpdTokens {
+  private static final Logger LOG = Loggers.get(DefaultCpdTokens.class);
+  private final List<TokensLine> result = new ArrayList<>();
+  private DefaultInputFile inputFile;
+  private int startLine = Integer.MIN_VALUE;
+  private int startIndex = 0;
+  private int currentIndex = 0;
+  private StringBuilder sb = new StringBuilder();
+  private TextRange lastRange;
+  private boolean loggedTestCpdWarning = false;
+
+  public DefaultCpdTokens(SensorStorage storage) {
+    super(storage);
+  }
+
+  @Override
+  public DefaultCpdTokens onFile(InputFile inputFile) {
+    this.inputFile = (DefaultInputFile) requireNonNull(inputFile, "file can't be null");
+    return this;
+  }
+
+  public InputFile inputFile() {
+    return inputFile;
+  }
+
+  @Override
+  public NewCpdTokens addToken(int startLine, int startLineOffset, int endLine, int endLineOffset, String image) {
+    checkInputFileNotNull();
+    TextRange newRange;
+    try {
+      newRange = inputFile.newRange(startLine, startLineOffset, endLine, endLineOffset);
+    } catch (Exception e) {
+      throw new IllegalArgumentException("Unable to register token in file " + inputFile, e);
+    }
+    return addToken(newRange, image);
+  }
+
+  @Override
+  public DefaultCpdTokens addToken(TextRange range, String image) {
+    requireNonNull(range, "Range should not be null");
+    requireNonNull(image, "Image should not be null");
+    checkInputFileNotNull();
+    if (isExcludedForDuplication()) {
+      return this;
+    }
+    checkState(lastRange == null || lastRange.end().compareTo(range.start()) <= 0,
+      "Tokens of file %s should be provided in order.\nPrevious token: %s\nLast token: %s", inputFile, lastRange, range);
+
+    int line = range.start().line();
+    if (line != startLine) {
+      addNewTokensLine(result, startIndex, currentIndex, startLine, sb);
+      startIndex = currentIndex + 1;
+      startLine = line;
+    }
+    currentIndex++;
+    sb.append(image);
+    lastRange = range;
+
+    return this;
+  }
+
+  private boolean isExcludedForDuplication() {
+    if (inputFile.isExcludedForDuplication()) {
+      return true;
+    }
+    if (inputFile.type() == InputFile.Type.TEST) {
+      if (!loggedTestCpdWarning) {
+        LOG.warn("Duplication reported for '{}' will be ignored because it's a test file.", inputFile);
+        loggedTestCpdWarning = true;
+      }
+      return true;
+    }
+    return false;
+  }
+
+  public List<TokensLine> getTokenLines() {
+    return unmodifiableList(new ArrayList<>(result));
+  }
+
+  private static void addNewTokensLine(List<TokensLine> result, int startUnit, int endUnit, int startLine, StringBuilder sb) {
+    if (sb.length() != 0) {
+      result.add(new TokensLine(startUnit, endUnit, startLine, sb.toString()));
+      sb.setLength(0);
+    }
+  }
+
+  @Override
+  protected void doSave() {
+    checkState(inputFile != null, "Call onFile() first");
+    if (isExcludedForDuplication()) {
+      return;
+    }
+    addNewTokensLine(result, startIndex, currentIndex, startLine, sb);
+    storage.store(this);
+  }
+
+  private void checkInputFileNotNull() {
+    checkState(inputFile != null, "Call onFile() first");
+  }
+}
index 3c09a40acebdcb293dbf89aa7d12493230be0fc5..7141a3ec39dc33a3b25d8a8241e111c7a55ee514 100644 (file)
 package org.sonar.scanner.sensor;
 
 import javax.annotation.Nullable;
-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;
 import org.sonar.api.batch.sensor.issue.NewExternalIssue;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.rules.RuleType;
+import org.sonar.scanner.fs.DefaultInputProject;
+import org.sonar.scanner.issue.AbstractDefaultIssue;
 
 import static java.lang.String.format;
 import static java.util.Objects.requireNonNull;
index 42129a261772276643e7653ad285bdbbe58b38e6..0f972804991b4d7b2d5fa545ae2540c301e57ce1 100644 (file)
@@ -25,11 +25,10 @@ import java.util.Iterator;
 import java.util.List;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.TextRange;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.sensor.highlighting.NewHighlighting;
 import org.sonar.api.batch.sensor.highlighting.TypeOfText;
-import org.sonar.api.batch.sensor.internal.DefaultStorable;
 import org.sonar.api.batch.sensor.internal.SensorStorage;
+import org.sonar.scanner.fs.DefaultInputFile;
 
 import static java.util.Objects.requireNonNull;
 import static org.sonar.api.utils.Preconditions.checkState;
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultIssue.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultIssue.java
deleted file mode 100644 (file)
index 369d731..0000000
+++ /dev/null
@@ -1,93 +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.scanner.sensor;
-
-import javax.annotation.Nullable;
-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;
-import org.sonar.api.batch.sensor.issue.IssueLocation;
-import org.sonar.api.batch.sensor.issue.NewIssue;
-import org.sonar.api.rule.RuleKey;
-
-import static java.lang.String.format;
-import static java.util.Objects.requireNonNull;
-import static org.sonar.api.utils.Preconditions.checkArgument;
-import static org.sonar.api.utils.Preconditions.checkState;
-
-public class DefaultIssue extends AbstractDefaultIssue<DefaultIssue> implements Issue, NewIssue {
-  private RuleKey ruleKey;
-  private Double gap;
-  private Severity overriddenSeverity;
-
-  public DefaultIssue(DefaultInputProject project) {
-    this(project, null);
-  }
-
-  public DefaultIssue(DefaultInputProject project, @Nullable SensorStorage storage) {
-    super(project, storage);
-  }
-
-  public DefaultIssue forRule(RuleKey ruleKey) {
-    this.ruleKey = ruleKey;
-    return this;
-  }
-
-  public RuleKey ruleKey() {
-    return this.ruleKey;
-  }
-
-  @Override
-  public DefaultIssue gap(@Nullable Double gap) {
-    checkArgument(gap == null || gap >= 0, format("Gap must be greater than or equal 0 (got %s)", gap));
-    this.gap = gap;
-    return this;
-  }
-
-  @Override
-  public DefaultIssue overrideSeverity(@Nullable Severity severity) {
-    this.overriddenSeverity = severity;
-    return this;
-  }
-
-  @Override
-  public Severity overriddenSeverity() {
-    return this.overriddenSeverity;
-  }
-
-  @Override
-  public Double gap() {
-    return this.gap;
-  }
-
-  @Override
-  public IssueLocation primaryLocation() {
-    return primaryLocation;
-  }
-
-  @Override
-  public void doSave() {
-    requireNonNull(this.ruleKey, "ruleKey is mandatory on issue");
-    checkState(primaryLocation != null, "Primary location is mandatory on every issue");
-    storage.store(this);
-  }
-
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultIssueLocation.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultIssueLocation.java
deleted file mode 100644 (file)
index b08d093..0000000
+++ /dev/null
@@ -1,92 +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.scanner.sensor;
-
-import javax.annotation.Nullable;
-import org.sonar.api.batch.fs.InputComponent;
-import org.sonar.api.batch.fs.TextRange;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.sensor.issue.IssueLocation;
-import org.sonar.api.batch.sensor.issue.NewIssueLocation;
-
-import static java.util.Objects.requireNonNull;
-import static org.apache.commons.lang.StringUtils.abbreviate;
-import static org.apache.commons.lang.StringUtils.trim;
-import static org.sonar.api.utils.Preconditions.checkArgument;
-import static org.sonar.api.utils.Preconditions.checkState;
-
-public class DefaultIssueLocation implements NewIssueLocation, IssueLocation {
-
-  private InputComponent component;
-  private TextRange textRange;
-  private String message;
-
-  @Override
-  public DefaultIssueLocation on(InputComponent component) {
-    checkArgument(component != null, "Component can't be null");
-    checkState(this.component == null, "on() already called");
-    this.component = component;
-    return this;
-  }
-
-  @Override
-  public DefaultIssueLocation at(TextRange location) {
-    checkState(this.component != null, "at() should be called after on()");
-    checkState(this.component.isFile(), "at() should be called only for an InputFile.");
-    DefaultInputFile file = (DefaultInputFile) this.component;
-    file.validate(location);
-    this.textRange = location;
-    return this;
-  }
-
-  @Override
-  public DefaultIssueLocation message(String message) {
-    requireNonNull(message, "Message can't be null");
-    if (message.contains("\u0000")) {
-      throw new IllegalArgumentException(unsupportedCharacterError(message, component));
-    }
-    this.message = abbreviate(trim(message), MESSAGE_MAX_SIZE);
-    return this;
-  }
-
-  private static String unsupportedCharacterError(String message, @Nullable InputComponent component) {
-    String error = "Character \\u0000 is not supported in issue message '" + message + "'";
-    if (component != null) {
-      error += ", on component: " + component.toString();
-    }
-    return error;
-  }
-
-  @Override
-  public InputComponent inputComponent() {
-    return this.component;
-  }
-
-  @Override
-  public TextRange textRange() {
-    return textRange;
-  }
-
-  @Override
-  public String message() {
-    return this.message;
-  }
-
-}
index 87d1aa18c1d0ea9e029155be46e2afe3960e9555..1ad7b83ce99253347ecc435051ac5a96b41cd4c1 100644 (file)
@@ -25,7 +25,6 @@ import org.apache.commons.lang.builder.EqualsBuilder;
 import org.apache.commons.lang.builder.HashCodeBuilder;
 import org.sonar.api.batch.fs.InputComponent;
 import org.sonar.api.batch.measure.Metric;
-import org.sonar.api.batch.sensor.internal.DefaultStorable;
 import org.sonar.api.batch.sensor.internal.SensorStorage;
 import org.sonar.api.batch.sensor.measure.Measure;
 import org.sonar.api.batch.sensor.measure.NewMeasure;
index b9ca180c5983d8987aea8d376522356007e15b34..13b72b07f7b1a8538744cb1562cd447347e455c7 100644 (file)
@@ -32,14 +32,11 @@ import org.sonar.api.batch.fs.InputComponent;
 import org.sonar.api.batch.fs.InputDir;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.TextRange;
-import org.sonar.api.batch.fs.internal.DefaultInputComponent;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
 import org.sonar.api.batch.measure.Metric;
 import org.sonar.api.batch.measure.MetricFinder;
-import org.sonar.api.batch.sensor.code.internal.DefaultSignificantCode;
-import org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage;
-import org.sonar.api.batch.sensor.cpd.internal.DefaultCpdTokens;
+import org.sonar.api.batch.sensor.code.NewSignificantCode;
+import org.sonar.api.batch.sensor.coverage.NewCoverage;
+import org.sonar.api.batch.sensor.cpd.NewCpdTokens;
 import org.sonar.api.batch.sensor.error.AnalysisError;
 import org.sonar.api.batch.sensor.highlighting.NewHighlighting;
 import org.sonar.api.batch.sensor.internal.SensorStorage;
@@ -47,7 +44,7 @@ import org.sonar.api.batch.sensor.issue.ExternalIssue;
 import org.sonar.api.batch.sensor.issue.Issue;
 import org.sonar.api.batch.sensor.measure.Measure;
 import org.sonar.api.batch.sensor.rule.AdHocRule;
-import org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable;
+import org.sonar.api.batch.sensor.symbol.NewSymbolTable;
 import org.sonar.api.config.Configuration;
 import org.sonar.api.measures.CoreMetrics;
 import org.sonar.api.utils.KeyValueFormat;
@@ -58,6 +55,9 @@ import org.sonar.core.util.CloseableIterator;
 import org.sonar.duplications.block.Block;
 import org.sonar.duplications.internal.pmd.PmdBlockChunker;
 import org.sonar.scanner.cpd.index.SonarCpdBlockIndex;
+import org.sonar.scanner.fs.DefaultInputComponent;
+import org.sonar.scanner.fs.DefaultInputFile;
+import org.sonar.scanner.fs.DefaultInputModule;
 import org.sonar.scanner.issue.IssuePublisher;
 import org.sonar.scanner.protocol.Constants;
 import org.sonar.scanner.protocol.output.FileStructure;
@@ -284,7 +284,8 @@ public class DefaultSensorStorage implements SensorStorage {
   }
 
   @Override
-  public void store(DefaultSymbolTable symbolTable) {
+  public void store(NewSymbolTable newSymbolTable) {
+    DefaultSymbolTable symbolTable = (DefaultSymbolTable) newSymbolTable;
     ScannerReportWriter writer = reportPublisher.getWriter();
     DefaultInputFile inputFile = (DefaultInputFile) symbolTable.inputFile();
     if (shouldSkipStorage(inputFile)) {
@@ -320,7 +321,8 @@ public class DefaultSensorStorage implements SensorStorage {
   }
 
   @Override
-  public void store(DefaultCoverage defaultCoverage) {
+  public void store(NewCoverage coverage) {
+    DefaultCoverage defaultCoverage = (DefaultCoverage) coverage;
     DefaultInputFile inputFile = (DefaultInputFile) defaultCoverage.inputFile();
     inputFile.setPublished(true);
 
@@ -363,16 +365,9 @@ public class DefaultSensorStorage implements SensorStorage {
     }
   }
 
-  private static void validatePositiveLine(Map<Integer, Integer> m, String filePath) {
-    for (int l : m.keySet()) {
-      if (l <= 0) {
-        throw new IllegalStateException(String.format("Measure with line %d for file '%s' must be > 0", l, filePath));
-      }
-    }
-  }
-
   @Override
-  public void store(DefaultCpdTokens defaultCpdTokens) {
+  public void store(NewCpdTokens cpdTokens) {
+    DefaultCpdTokens defaultCpdTokens = (DefaultCpdTokens) cpdTokens;
     DefaultInputFile inputFile = (DefaultInputFile) defaultCpdTokens.inputFile();
     inputFile.setPublished(true);
     PmdBlockChunker blockChunker = new PmdBlockChunker(getCpdBlockSize(inputFile.language()));
@@ -411,7 +406,8 @@ public class DefaultSensorStorage implements SensorStorage {
   }
 
   @Override
-  public void store(DefaultSignificantCode significantCode) {
+  public void store(NewSignificantCode newSignificantCode) {
+    DefaultSignificantCode significantCode = (DefaultSignificantCode) newSignificantCode;
     ScannerReportWriter writer = reportPublisher.getWriter();
     DefaultInputFile inputFile = (DefaultInputFile) significantCode.inputFile();
     if (shouldSkipStorage(inputFile)) {
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSignificantCode.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSignificantCode.java
new file mode 100644 (file)
index 0000000..04ff5f1
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * 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.scanner.sensor;
+
+import java.util.SortedMap;
+import java.util.TreeMap;
+import javax.annotation.Nullable;
+import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.fs.TextRange;
+import org.sonar.api.batch.sensor.code.NewSignificantCode;
+import org.sonar.api.batch.sensor.internal.SensorStorage;
+import org.sonar.api.utils.Preconditions;
+
+public class DefaultSignificantCode extends DefaultStorable implements NewSignificantCode {
+  private SortedMap<Integer, TextRange> significantCodePerLine = new TreeMap<>();
+  private InputFile inputFile;
+
+  public DefaultSignificantCode() {
+    super();
+  }
+
+  public DefaultSignificantCode(@Nullable SensorStorage storage) {
+    super(storage);
+  }
+
+  @Override
+  public DefaultSignificantCode onFile(InputFile inputFile) {
+    this.inputFile = inputFile;
+    return this;
+  }
+
+  @Override
+  public DefaultSignificantCode addRange(TextRange range) {
+    Preconditions.checkState(this.inputFile != null, "addRange() should be called after on()");
+
+    int line = range.start().line();
+
+    Preconditions.checkArgument(line == range.end().line(), "Ranges of significant code must be located in a single line");
+    Preconditions.checkState(!significantCodePerLine.containsKey(line), "Significant code was already reported for line '%s'. Can only report once per line.", line);
+
+    significantCodePerLine.put(line, range);
+    return this;
+  }
+
+  @Override
+  protected void doSave() {
+    Preconditions.checkState(inputFile != null, "Call onFile() first");
+    storage.store(this);
+  }
+
+  public InputFile inputFile() {
+    return inputFile;
+  }
+
+  public SortedMap<Integer, TextRange> significantCodePerLine() {
+    return significantCodePerLine;
+  }
+}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultStorable.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultStorable.java
new file mode 100644 (file)
index 0000000..23b989c
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * 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.scanner.sensor;
+
+import javax.annotation.Nullable;
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
+import org.sonar.api.batch.sensor.internal.SensorStorage;
+
+import static java.util.Objects.requireNonNull;
+import static org.sonar.api.utils.Preconditions.checkState;
+
+public abstract class DefaultStorable {
+
+  protected final transient SensorStorage storage;
+  private transient boolean saved = false;
+
+  public DefaultStorable() {
+    this.storage = null;
+  }
+
+  public DefaultStorable(@Nullable SensorStorage storage) {
+    this.storage = storage;
+  }
+
+  public final void save() {
+    requireNonNull(this.storage, "No persister on this object");
+    checkState(!saved, "This object was already saved");
+    doSave();
+    this.saved = true;
+  }
+
+  protected abstract void doSave();
+
+  @Override
+  public String toString() {
+    return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
+  }
+
+}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSymbolTable.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSymbolTable.java
new file mode 100644 (file)
index 0000000..ca8b162
--- /dev/null
@@ -0,0 +1,148 @@
+/*
+ * 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.scanner.sensor;
+
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.fs.TextRange;
+import org.sonar.api.batch.sensor.internal.SensorStorage;
+import org.sonar.api.batch.sensor.symbol.NewSymbol;
+import org.sonar.api.batch.sensor.symbol.NewSymbolTable;
+import org.sonar.scanner.fs.DefaultInputFile;
+
+import static java.util.Objects.requireNonNull;
+import static org.sonar.api.utils.Preconditions.checkArgument;
+import static org.sonar.api.utils.Preconditions.checkState;
+
+public class DefaultSymbolTable extends DefaultStorable implements NewSymbolTable {
+
+  private final Map<TextRange, Set<TextRange>> referencesBySymbol;
+  private DefaultInputFile inputFile;
+
+  public DefaultSymbolTable(SensorStorage storage) {
+    super(storage);
+    referencesBySymbol = new LinkedHashMap<>();
+  }
+
+  public Map<TextRange, Set<TextRange>> getReferencesBySymbol() {
+    return referencesBySymbol;
+  }
+
+  @Override
+  public DefaultSymbolTable onFile(InputFile inputFile) {
+    requireNonNull(inputFile, "file can't be null");
+    this.inputFile = (DefaultInputFile) inputFile;
+    return this;
+  }
+
+  public InputFile inputFile() {
+    return inputFile;
+  }
+
+  @Override
+  public NewSymbol newSymbol(int startLine, int startLineOffset, int endLine, int endLineOffset) {
+    checkInputFileNotNull();
+    TextRange declarationRange;
+    try {
+      declarationRange = inputFile.newRange(startLine, startLineOffset, endLine, endLineOffset);
+    } catch (Exception e) {
+      throw new IllegalArgumentException("Unable to create symbol on file " + inputFile, e);
+    }
+    return newSymbol(declarationRange);
+  }
+
+  @Override
+  public NewSymbol newSymbol(int startOffset, int endOffset) {
+    checkInputFileNotNull();
+    TextRange declarationRange;
+    try {
+      declarationRange = inputFile.newRange(startOffset, endOffset);
+    } catch (Exception e) {
+      throw new IllegalArgumentException("Unable to create symbol on file " + inputFile, e);
+    }
+    return newSymbol(declarationRange);
+  }
+
+  @Override
+  public NewSymbol newSymbol(TextRange range) {
+    checkInputFileNotNull();
+    TreeSet<TextRange> references = new TreeSet<>((o1, o2) -> o1.start().compareTo(o2.start()));
+    referencesBySymbol.put(range, references);
+    return new DefaultSymbol(inputFile, range, references);
+  }
+
+  private static class DefaultSymbol implements NewSymbol {
+
+    private final Collection<TextRange> references;
+    private final DefaultInputFile inputFile;
+    private final TextRange declaration;
+
+    public DefaultSymbol(DefaultInputFile inputFile, TextRange declaration, Collection<TextRange> references) {
+      this.inputFile = inputFile;
+      this.declaration = declaration;
+      this.references = references;
+    }
+
+    @Override
+    public NewSymbol newReference(int startOffset, int endOffset) {
+      TextRange referenceRange;
+      try {
+        referenceRange = inputFile.newRange(startOffset, endOffset);
+      } catch (Exception e) {
+        throw new IllegalArgumentException("Unable to create symbol reference on file " + inputFile, e);
+      }
+      return newReference(referenceRange);
+    }
+
+    @Override
+    public NewSymbol newReference(int startLine, int startLineOffset, int endLine, int endLineOffset) {
+      TextRange referenceRange;
+      try {
+        referenceRange = inputFile.newRange(startLine, startLineOffset, endLine, endLineOffset);
+      } catch (Exception e) {
+        throw new IllegalArgumentException("Unable to create symbol reference on file " + inputFile, e);
+      }
+      return newReference(referenceRange);
+    }
+
+    @Override
+    public NewSymbol newReference(TextRange range) {
+      requireNonNull(range, "Provided range is null");
+      checkArgument(!declaration.overlap(range), "Overlapping symbol declaration and reference for symbol at %s", declaration);
+      references.add(range);
+      return this;
+    }
+
+  }
+
+  @Override
+  protected void doSave() {
+    checkInputFileNotNull();
+    storage.store(this);
+  }
+
+  private void checkInputFileNotNull() {
+    checkState(inputFile != null, "Call onFile() first");
+  }
+}
index 45933fe1730225b4938129196ebee1af52ddc933..472537df9597ead62f17b8ce9b6974350ef2570d 100644 (file)
@@ -25,9 +25,9 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import org.sonar.api.batch.sensor.code.internal.DefaultSignificantCode;
-import org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage;
-import org.sonar.api.batch.sensor.cpd.internal.DefaultCpdTokens;
+import org.sonar.api.batch.sensor.code.NewSignificantCode;
+import org.sonar.api.batch.sensor.coverage.NewCoverage;
+import org.sonar.api.batch.sensor.cpd.NewCpdTokens;
 import org.sonar.api.batch.sensor.error.AnalysisError;
 import org.sonar.api.batch.sensor.highlighting.NewHighlighting;
 import org.sonar.api.batch.sensor.internal.SensorStorage;
@@ -35,7 +35,7 @@ import org.sonar.api.batch.sensor.issue.ExternalIssue;
 import org.sonar.api.batch.sensor.issue.Issue;
 import org.sonar.api.batch.sensor.measure.Measure;
 import org.sonar.api.batch.sensor.rule.AdHocRule;
-import org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable;
+import org.sonar.api.batch.sensor.symbol.NewSymbolTable;
 
 import static org.sonar.api.utils.Preconditions.checkArgument;
 
@@ -88,13 +88,15 @@ class InMemorySensorStorage implements SensorStorage {
   }
 
   @Override
-  public void store(DefaultCoverage defaultCoverage) {
+  public void store(NewCoverage coverage) {
+    DefaultCoverage defaultCoverage = (DefaultCoverage) coverage;
     String fileKey = defaultCoverage.inputFile().key();
     coverageByComponent.computeIfAbsent(fileKey, x -> new ArrayList<>()).add(defaultCoverage);
   }
 
   @Override
-  public void store(DefaultCpdTokens defaultCpdTokens) {
+  public void store(NewCpdTokens cpdTokens) {
+    DefaultCpdTokens defaultCpdTokens = (DefaultCpdTokens) cpdTokens;
     String fileKey = defaultCpdTokens.inputFile().key();
     // Emulate duplicate storage check
     if (cpdTokensByComponent.containsKey(fileKey)) {
@@ -104,7 +106,8 @@ class InMemorySensorStorage implements SensorStorage {
   }
 
   @Override
-  public void store(DefaultSymbolTable symbolTable) {
+  public void store(NewSymbolTable newSymbolTable) {
+    DefaultSymbolTable symbolTable = (DefaultSymbolTable) newSymbolTable;
     String fileKey = symbolTable.inputFile().key();
     // Emulate duplicate storage check
     if (symbolsPerComponent.containsKey(fileKey)) {
@@ -131,7 +134,8 @@ class InMemorySensorStorage implements SensorStorage {
   }
 
   @Override
-  public void store(DefaultSignificantCode significantCode) {
+  public void store(NewSignificantCode newSignificantCode) {
+    DefaultSignificantCode significantCode = (DefaultSignificantCode) newSignificantCode;
     String fileKey = significantCode.inputFile().key();
     // Emulate duplicate storage check
     if (significantCodePerComponent.containsKey(fileKey)) {
index 76aa74d3bf054b37aa0d612a5465b9e429405d37..1e8f6009f8d5b28b9e73751d758a9a3c0c3f4ffb 100644 (file)
@@ -23,11 +23,11 @@ import javax.annotation.concurrent.ThreadSafe;
 import org.sonar.api.SonarRuntime;
 import org.sonar.api.batch.fs.FileSystem;
 import org.sonar.api.batch.fs.InputModule;
-import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.batch.rule.ActiveRules;
 import org.sonar.api.batch.sensor.internal.SensorStorage;
 import org.sonar.api.config.Configuration;
 import org.sonar.api.config.Settings;
+import org.sonar.scanner.fs.DefaultInputProject;
 
 @ThreadSafe
 public class ModuleSensorContext extends ProjectSensorContext {
@@ -35,7 +35,7 @@ public class ModuleSensorContext extends ProjectSensorContext {
   private final InputModule module;
 
   public ModuleSensorContext(DefaultInputProject project, InputModule module, Configuration config, Settings mutableSettings, FileSystem fs, ActiveRules activeRules,
-                             SensorStorage sensorStorage, SonarRuntime sonarRuntime) {
+    SensorStorage sensorStorage, SonarRuntime sonarRuntime) {
     super(project, config, mutableSettings, fs, activeRules, sensorStorage, sonarRuntime);
     this.module = module;
   }
index ba78bb1a758f54bce83c456c8be9727b7004eb0e..ec3d21f661352af8b76664ba8b83c747205e40e3 100644 (file)
@@ -23,13 +23,13 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
-import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
 import org.sonar.api.batch.fs.internal.SensorStrategy;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.core.util.logs.Profiler;
 import org.sonar.scanner.bootstrap.ScannerPluginRepository;
+import org.sonar.scanner.fs.DefaultInputModule;
+import org.sonar.scanner.fs.InputModuleHierarchy;
 
 public class ModuleSensorsExecutor {
   private static final Logger LOG = Loggers.get(ModuleSensorsExecutor.class);
@@ -40,7 +40,7 @@ public class ModuleSensorsExecutor {
   private final boolean isRoot;
 
   public ModuleSensorsExecutor(ModuleSensorExtensionDictionnary selector, DefaultInputModule module, InputModuleHierarchy hierarchy,
-                               SensorStrategy strategy, ScannerPluginRepository pluginRepo) {
+    SensorStrategy strategy, ScannerPluginRepository pluginRepo) {
     this.selector = selector;
     this.strategy = strategy;
     this.pluginRepo = pluginRepo;
index 42e8559e83b0d277f69ebe255a30eb559e0bf7da..8a24451032828316c6714c93cb0f44d01978135c 100644 (file)
@@ -25,16 +25,11 @@ import org.sonar.api.SonarRuntime;
 import org.sonar.api.batch.fs.FileSystem;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.InputModule;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.batch.rule.ActiveRules;
 import org.sonar.api.batch.sensor.SensorContext;
 import org.sonar.api.batch.sensor.code.NewSignificantCode;
-import org.sonar.api.batch.sensor.code.internal.DefaultSignificantCode;
 import org.sonar.api.batch.sensor.coverage.NewCoverage;
-import org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage;
 import org.sonar.api.batch.sensor.cpd.NewCpdTokens;
-import org.sonar.api.batch.sensor.cpd.internal.DefaultCpdTokens;
 import org.sonar.api.batch.sensor.error.NewAnalysisError;
 import org.sonar.api.batch.sensor.highlighting.NewHighlighting;
 import org.sonar.api.batch.sensor.internal.SensorStorage;
@@ -43,11 +38,13 @@ import org.sonar.api.batch.sensor.issue.NewIssue;
 import org.sonar.api.batch.sensor.measure.NewMeasure;
 import org.sonar.api.batch.sensor.rule.NewAdHocRule;
 import org.sonar.api.batch.sensor.symbol.NewSymbolTable;
-import org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable;
 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;
+import org.sonar.scanner.fs.DefaultInputFile;
+import org.sonar.scanner.fs.DefaultInputProject;
+import org.sonar.scanner.issue.DefaultIssue;
 import org.sonar.scanner.sensor.noop.NoOpNewAnalysisError;
 
 @ThreadSafe
index 785920220ff15713c56f9811dc71f23f8089ec42..e3ffc324ede074b90d1124384649727039332b14 100644 (file)
@@ -39,23 +39,15 @@ import org.sonar.api.batch.bootstrap.ProjectDefinition;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.InputModule;
 import org.sonar.api.batch.fs.TextRange;
-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.sensor.Sensor;
 import org.sonar.api.batch.sensor.SensorContext;
 import org.sonar.api.batch.sensor.code.NewSignificantCode;
-import org.sonar.api.batch.sensor.code.internal.DefaultSignificantCode;
 import org.sonar.api.batch.sensor.coverage.NewCoverage;
-import org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage;
 import org.sonar.api.batch.sensor.cpd.NewCpdTokens;
-import org.sonar.api.batch.sensor.cpd.internal.DefaultCpdTokens;
 import org.sonar.api.batch.sensor.cpd.internal.TokensLine;
 import org.sonar.api.batch.sensor.error.AnalysisError;
 import org.sonar.api.batch.sensor.error.NewAnalysisError;
-import org.sonar.api.batch.sensor.error.internal.DefaultAnalysisError;
 import org.sonar.api.batch.sensor.highlighting.NewHighlighting;
 import org.sonar.api.batch.sensor.highlighting.TypeOfText;
 import org.sonar.api.batch.sensor.issue.ExternalIssue;
@@ -67,7 +59,6 @@ import org.sonar.api.batch.sensor.measure.NewMeasure;
 import org.sonar.api.batch.sensor.rule.AdHocRule;
 import org.sonar.api.batch.sensor.rule.NewAdHocRule;
 import org.sonar.api.batch.sensor.symbol.NewSymbolTable;
-import org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable;
 import org.sonar.api.config.Configuration;
 import org.sonar.api.config.Settings;
 import org.sonar.api.config.internal.ConfigurationBridge;
@@ -79,6 +70,11 @@ import org.sonar.api.scanner.fs.InputProject;
 import org.sonar.api.utils.System2;
 import org.sonar.api.utils.Version;
 import org.sonar.scanner.fs.DefaultFileSystem;
+import org.sonar.scanner.fs.DefaultInputFile;
+import org.sonar.scanner.fs.DefaultInputModule;
+import org.sonar.scanner.fs.DefaultInputProject;
+import org.sonar.scanner.fs.DefaultTextPointer;
+import org.sonar.scanner.issue.DefaultIssue;
 import org.sonar.scanner.rule.ActiveRulesBuilder;
 
 import static java.util.Collections.unmodifiableMap;
index f549ec6216c3aab710ac949efe4232f3ac68fb31..54bf590d75884848085af50875b521e5c83965bc 100644 (file)
@@ -24,11 +24,11 @@ import org.sonar.api.batch.Phase;
 import org.sonar.api.batch.fs.FileSystem;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.InputFile.Type;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.sensor.SensorContext;
 import org.sonar.api.batch.sensor.SensorDescriptor;
 import org.sonar.api.batch.sensor.coverage.NewCoverage;
 import org.sonar.api.scanner.sensor.ProjectSensor;
+import org.sonar.scanner.fs.DefaultInputFile;
 import org.sonar.scanner.report.ReportPublisher;
 
 @Phase(name = Phase.Name.POST)
index d60f344a516f05ba5bc2a1c8e77e21f3896900e0..f6e59a75f9a0f15234d476c41ad3741616146c13 100644 (file)
@@ -25,12 +25,12 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.mockito.ArgumentCaptor;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.scanner.fs.TestInputFileBuilder;
 import org.sonar.api.batch.measure.MetricFinder;
 import org.sonar.api.batch.sensor.internal.SensorStorage;
-import org.sonar.scanner.sensor.DefaultMeasure;
 import org.sonar.api.measures.CoreMetrics;
+import org.sonar.scanner.fs.DefaultInputFile;
+import org.sonar.scanner.fs.TestInputFileBuilder;
+import org.sonar.scanner.sensor.DefaultMeasure;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.tuple;
@@ -151,5 +151,4 @@ public class DefaultFileLinesContextTest {
     fileLineMeasures.setIntValue(HITS_METRIC_KEY, 1, 2);
   }
 
-
 }
index df848a5600689839c63ded9c508a5ad027092d26..d625da5f8dfd5c3065f3bdd7ea10a0c693263c70 100644 (file)
 package org.sonar.scanner.analysis;
 
 import java.io.File;
-import java.io.IOException;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
-import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.utils.TempFolder;
+import org.sonar.scanner.fs.DefaultInputProject;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
@@ -47,7 +46,7 @@ public class AnalysisTempFolderProviderTest {
   }
 
   @Test
-  public void createTempFolder() throws IOException {
+  public void createTempFolder() {
     File defaultDir = new File(temp.getRoot(), AnalysisTempFolderProvider.TMP_NAME);
 
     TempFolder tempFolder = tempFolderProvider.provide(project);
index ecc155cd5e54c597ab5ab943795140f7f064b224..a649c5e9f24eeb95a034ba88a8995cca1e88e638 100644 (file)
@@ -36,9 +36,6 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
 import org.mockito.ArgumentMatchers;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputProject;
-import org.sonar.scanner.fs.TestInputFileBuilder;
 import org.sonar.api.utils.log.LogTester;
 import org.sonar.api.utils.log.LoggerLevel;
 import org.sonar.core.util.CloseableIterator;
@@ -47,6 +44,9 @@ import org.sonar.duplications.block.ByteArray;
 import org.sonar.duplications.index.CloneGroup;
 import org.sonar.duplications.index.ClonePart;
 import org.sonar.scanner.cpd.index.SonarCpdBlockIndex;
+import org.sonar.scanner.fs.DefaultInputFile;
+import org.sonar.scanner.fs.DefaultInputProject;
+import org.sonar.scanner.fs.TestInputFileBuilder;
 import org.sonar.scanner.protocol.output.ScannerReport.Duplicate;
 import org.sonar.scanner.protocol.output.ScannerReport.Duplication;
 import org.sonar.scanner.protocol.output.ScannerReportReader;
index 627114cce88c152847c14949ce833e2825c8d1ce..2e3e6d2898d7a4d9c4035136e2defdd648647363 100644 (file)
@@ -22,8 +22,8 @@ package org.sonar.scanner.cpd;
 import java.util.Optional;
 import org.junit.Before;
 import org.junit.Test;
-import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.config.Configuration;
+import org.sonar.scanner.fs.DefaultInputProject;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.ArgumentMatchers.anyString;
index 3d7c748603421ce37fdffc97f397f73ae8eac8f0..f62bb729defbd3028f1c9638e695d9bd0074ef25 100644 (file)
@@ -32,9 +32,9 @@ import org.mockito.ArgumentCaptor;
 import org.mockito.Captor;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.duplications.block.Block;
 import org.sonar.scanner.cpd.index.SonarCpdBlockIndex;
+import org.sonar.scanner.fs.DefaultInputFile;
 import org.sonar.scanner.fs.TestInputFileBuilder;
 import org.sonar.scanner.sensor.SensorContextTester;
 
index 596a25f9275354093d3e539036d4f7e7d77495c2..3eaeb9997adf7ec35e7c07b3107990c42d9b2cee 100644 (file)
@@ -27,12 +27,12 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.fs.TextRange;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.scanner.fs.TestInputFileBuilder;
 import org.sonar.api.batch.rule.Severity;
 import org.sonar.api.batch.sensor.issue.ExternalIssue;
 import org.sonar.api.utils.log.LogTester;
 import org.sonar.api.utils.log.LoggerLevel;
+import org.sonar.scanner.fs.DefaultInputFile;
+import org.sonar.scanner.fs.TestInputFileBuilder;
 import org.sonar.scanner.sensor.SensorContextTester;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
@@ -105,8 +105,8 @@ public class ExternalIssueImporterTest {
     ReportParser.TextRange input = new ReportParser.TextRange();
     input.startLine = 1;
     input.startColumn = 4;
-    input.endLine= 2;
-    input.endColumn= 3;
+    input.endLine = 2;
+    input.endColumn = 3;
 
     runOn(newIssue(input));
 
@@ -124,8 +124,8 @@ public class ExternalIssueImporterTest {
     ReportParser.TextRange input = new ReportParser.TextRange();
     input.startLine = 1;
     input.startColumn = null;
-    input.endLine= 2;
-    input.endColumn= null;
+    input.endLine = 2;
+    input.endColumn = null;
 
     runOn(newIssue(input));
 
@@ -145,8 +145,8 @@ public class ExternalIssueImporterTest {
     ReportParser.TextRange input = new ReportParser.TextRange();
     input.startLine = 1;
     input.startColumn = 3;
-    input.endLine= 2;
-    input.endColumn= null;
+    input.endLine = 2;
+    input.endColumn = null;
 
     runOn(newIssue(input));
 
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/fs/DefaultInputDirTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/fs/DefaultInputDirTest.java
new file mode 100644 (file)
index 0000000..1679a8d
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * 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.scanner.fs;
+
+import java.io.File;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class DefaultInputDirTest {
+
+  @Rule
+  public TemporaryFolder temp = new TemporaryFolder();
+
+  @Test
+  public void test() throws Exception {
+    File baseDir = temp.newFolder();
+    DefaultInputDir inputDir = new DefaultInputDir("ABCDE", "src")
+      .setModuleBaseDir(baseDir.toPath());
+
+    assertThat(inputDir.key()).isEqualTo("ABCDE:src");
+    assertThat(inputDir.file().getAbsolutePath()).isEqualTo(new File(baseDir, "src").getAbsolutePath());
+    assertThat(inputDir.relativePath()).isEqualTo("src");
+    assertThat(new File(inputDir.relativePath())).isRelative();
+    assertThat(inputDir.absolutePath()).endsWith("src");
+    assertThat(new File(inputDir.absolutePath())).isAbsolute();
+  }
+
+  @Test
+  public void testEqualsAndHashCode() throws Exception {
+    DefaultInputDir inputDir1 = new DefaultInputDir("ABCDE", "src");
+
+    DefaultInputDir inputDir2 = new DefaultInputDir("ABCDE", "src");
+
+    assertThat(inputDir1.equals(inputDir1)).isTrue();
+    assertThat(inputDir1.equals(inputDir2)).isTrue();
+    assertThat(inputDir1.equals("foo")).isFalse();
+
+    assertThat(inputDir1.hashCode()).isEqualTo(63545559);
+
+    assertThat(inputDir1.toString()).contains("[moduleKey=ABCDE, relative=src, basedir=null");
+
+  }
+
+}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/fs/DefaultInputFileTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/fs/DefaultInputFileTest.java
new file mode 100644 (file)
index 0000000..6673977
--- /dev/null
@@ -0,0 +1,315 @@
+/*
+ * 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.scanner.fs;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.StringReader;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardOpenOption;
+import java.util.stream.Collectors;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.fs.TextRange;
+import org.sonar.api.batch.fs.internal.Metadata;
+import org.sonar.api.batch.fs.internal.SensorStrategy;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+
+public class DefaultInputFileTest {
+
+  private static final String PROJECT_RELATIVE_PATH = "module1/src/Foo.php";
+  private static final String MODULE_RELATIVE_PATH = "src/Foo.php";
+
+  @Rule
+  public TemporaryFolder temp = new TemporaryFolder();
+
+  private DefaultIndexedFile indexedFile;
+
+  private Path baseDir;
+  private SensorStrategy sensorStrategy;
+
+  @Before
+  public void prepare() throws IOException {
+    baseDir = temp.newFolder().toPath();
+    sensorStrategy = new SensorStrategy();
+    indexedFile = new DefaultIndexedFile(baseDir.resolve(PROJECT_RELATIVE_PATH), "ABCDE", PROJECT_RELATIVE_PATH, MODULE_RELATIVE_PATH, InputFile.Type.TEST, "php", 0,
+      sensorStrategy);
+  }
+
+  @Test
+  public void test() throws Exception {
+
+    Metadata metadata = new Metadata(42, 42, "", new int[0], new int[0], 10);
+    DefaultInputFile inputFile = new DefaultInputFile(indexedFile, (f) -> f.setMetadata(metadata))
+      .setStatus(InputFile.Status.ADDED)
+      .setCharset(StandardCharsets.ISO_8859_1);
+
+    assertThat(inputFile.absolutePath()).endsWith("Foo.php");
+    assertThat(inputFile.filename()).isEqualTo("Foo.php");
+    assertThat(inputFile.uri()).hasPath(baseDir.resolve(PROJECT_RELATIVE_PATH).toUri().getPath());
+    assertThat(new File(inputFile.absolutePath())).isAbsolute();
+    assertThat(inputFile.language()).isEqualTo("php");
+    assertThat(inputFile.status()).isEqualTo(InputFile.Status.ADDED);
+    assertThat(inputFile.type()).isEqualTo(InputFile.Type.TEST);
+    assertThat(inputFile.lines()).isEqualTo(42);
+    assertThat(inputFile.charset()).isEqualTo(StandardCharsets.ISO_8859_1);
+
+    assertThat(inputFile.getModuleRelativePath()).isEqualTo(MODULE_RELATIVE_PATH);
+    assertThat(inputFile.getProjectRelativePath()).isEqualTo(PROJECT_RELATIVE_PATH);
+
+    sensorStrategy.setGlobal(false);
+    assertThat(inputFile.relativePath()).isEqualTo(MODULE_RELATIVE_PATH);
+    assertThat(new File(inputFile.relativePath())).isRelative();
+    sensorStrategy.setGlobal(true);
+    assertThat(inputFile.relativePath()).isEqualTo(PROJECT_RELATIVE_PATH);
+    assertThat(new File(inputFile.relativePath())).isRelative();
+  }
+
+  @Test
+  public void test_content() throws IOException {
+    Path testFile = baseDir.resolve(PROJECT_RELATIVE_PATH);
+    Files.createDirectories(testFile.getParent());
+    String content = "test Ã© string";
+    Files.write(testFile, content.getBytes(StandardCharsets.ISO_8859_1));
+
+    assertThat(Files.readAllLines(testFile, StandardCharsets.ISO_8859_1).get(0)).hasSize(content.length());
+
+    Metadata metadata = new Metadata(42, 30, "", new int[0], new int[0], 10);
+
+    DefaultInputFile inputFile = new DefaultInputFile(indexedFile, f -> f.setMetadata(metadata))
+      .setStatus(InputFile.Status.ADDED)
+      .setCharset(StandardCharsets.ISO_8859_1);
+
+    assertThat(inputFile.contents()).isEqualTo(content);
+    try (InputStream inputStream = inputFile.inputStream()) {
+      String result = new BufferedReader(new InputStreamReader(inputStream, inputFile.charset())).lines().collect(Collectors.joining());
+      assertThat(result).isEqualTo(content);
+    }
+
+  }
+
+  @Test
+  public void test_content_exclude_bom() throws IOException {
+    Path testFile = baseDir.resolve(PROJECT_RELATIVE_PATH);
+    Files.createDirectories(testFile.getParent());
+    try (BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(testFile.toFile()), StandardCharsets.UTF_8))) {
+      out.write('\ufeff');
+    }
+    String content = "test Ã© string â‚¬";
+    Files.write(testFile, content.getBytes(StandardCharsets.UTF_8), StandardOpenOption.APPEND);
+
+    assertThat(Files.readAllLines(testFile, StandardCharsets.UTF_8).get(0)).hasSize(content.length() + 1);
+
+    Metadata metadata = new Metadata(42, 30, "", new int[0], new int[0], 10);
+
+    DefaultInputFile inputFile = new DefaultInputFile(indexedFile, f -> f.setMetadata(metadata))
+      .setStatus(InputFile.Status.ADDED)
+      .setCharset(StandardCharsets.UTF_8);
+
+    assertThat(inputFile.contents()).isEqualTo(content);
+    try (InputStream inputStream = inputFile.inputStream()) {
+      String result = new BufferedReader(new InputStreamReader(inputStream, inputFile.charset())).lines().collect(Collectors.joining());
+      assertThat(result).isEqualTo(content);
+    }
+
+  }
+
+  @Test
+  public void test_equals_and_hashcode() throws Exception {
+    DefaultInputFile f1 = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), (f) -> mock(Metadata.class));
+    DefaultInputFile f1a = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), (f) -> mock(Metadata.class));
+    DefaultInputFile f2 = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), "src/Bar.php", null), (f) -> mock(Metadata.class));
+
+    assertThat(f1).isEqualTo(f1);
+    assertThat(f1).isEqualTo(f1a);
+    assertThat(f1).isNotEqualTo(f2);
+    assertThat(f1.equals("foo")).isFalse();
+    assertThat(f1.equals(null)).isFalse();
+
+    assertThat(f1.hashCode()).isEqualTo(f1.hashCode());
+    assertThat(f1.hashCode()).isEqualTo(f1a.hashCode());
+  }
+
+  @Test
+  public void test_toString() throws Exception {
+    DefaultInputFile file = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), (f) -> mock(Metadata.class));
+    assertThat(file.toString()).isEqualTo(MODULE_RELATIVE_PATH);
+  }
+
+  @Test
+  public void checkValidPointer() {
+    Metadata metadata = new Metadata(2, 2, "", new int[] {0, 10}, new int[] {9, 15}, 16);
+    DefaultInputFile file = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), f -> f.setMetadata(metadata));
+    assertThat(file.newPointer(1, 0).line()).isEqualTo(1);
+    assertThat(file.newPointer(1, 0).lineOffset()).isEqualTo(0);
+    // Don't fail
+    file.newPointer(1, 9);
+    file.newPointer(2, 0);
+    file.newPointer(2, 5);
+
+    try {
+      file.newPointer(0, 1);
+      fail();
+    } catch (Exception e) {
+      assertThat(e).hasMessage("0 is not a valid line for a file");
+    }
+    try {
+      file.newPointer(3, 1);
+      fail();
+    } catch (Exception e) {
+      assertThat(e).hasMessage("3 is not a valid line for pointer. File src/Foo.php has 2 line(s)");
+    }
+    try {
+      file.newPointer(1, -1);
+      fail();
+    } catch (Exception e) {
+      assertThat(e).hasMessage("-1 is not a valid line offset for a file");
+    }
+    try {
+      file.newPointer(1, 10);
+      fail();
+    } catch (Exception e) {
+      assertThat(e).hasMessage("10 is not a valid line offset for pointer. File src/Foo.php has 9 character(s) at line 1");
+    }
+  }
+
+  @Test
+  public void checkValidPointerUsingGlobalOffset() {
+    Metadata metadata = new Metadata(2, 2, "", new int[] {0, 10}, new int[] {8, 15}, 16);
+    DefaultInputFile file = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), f -> f.setMetadata(metadata));
+    assertThat(file.newPointer(0).line()).isEqualTo(1);
+    assertThat(file.newPointer(0).lineOffset()).isEqualTo(0);
+
+    assertThat(file.newPointer(9).line()).isEqualTo(1);
+    // Ignore eol characters
+    assertThat(file.newPointer(9).lineOffset()).isEqualTo(8);
+
+    assertThat(file.newPointer(10).line()).isEqualTo(2);
+    assertThat(file.newPointer(10).lineOffset()).isEqualTo(0);
+
+    assertThat(file.newPointer(15).line()).isEqualTo(2);
+    assertThat(file.newPointer(15).lineOffset()).isEqualTo(5);
+
+    assertThat(file.newPointer(16).line()).isEqualTo(2);
+    // Ignore eol characters
+    assertThat(file.newPointer(16).lineOffset()).isEqualTo(5);
+
+    try {
+      file.newPointer(-1);
+      fail();
+    } catch (Exception e) {
+      assertThat(e).hasMessage("-1 is not a valid offset for a file");
+    }
+
+    try {
+      file.newPointer(17);
+      fail();
+    } catch (Exception e) {
+      assertThat(e).hasMessage("17 is not a valid offset for file src/Foo.php. Max offset is 16");
+    }
+  }
+
+  @Test
+  public void checkValidRange() {
+    Metadata metadata = new FileMetadata().readMetadata(new StringReader("bla bla a\nabcde"));
+    DefaultInputFile file = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), f -> f.setMetadata(metadata));
+
+    assertThat(file.newRange(file.newPointer(1, 0), file.newPointer(2, 1)).start().line()).isEqualTo(1);
+    // Don't fail
+    file.newRange(file.newPointer(1, 0), file.newPointer(1, 1));
+    file.newRange(file.newPointer(1, 0), file.newPointer(1, 9));
+    file.newRange(file.newPointer(1, 0), file.newPointer(2, 0));
+    assertThat(file.newRange(file.newPointer(1, 0), file.newPointer(2, 5))).isEqualTo(file.newRange(0, 15));
+
+    try {
+      file.newRange(file.newPointer(1, 0), file.newPointer(1, 0));
+      fail();
+    } catch (Exception e) {
+      assertThat(e).hasMessage("Start pointer [line=1, lineOffset=0] should be before end pointer [line=1, lineOffset=0]");
+    }
+    try {
+      file.newRange(file.newPointer(1, 0), file.newPointer(1, 10));
+      fail();
+    } catch (Exception e) {
+      assertThat(e).hasMessage("10 is not a valid line offset for pointer. File src/Foo.php has 9 character(s) at line 1");
+    }
+  }
+
+  @Test
+  public void selectLine() {
+    Metadata metadata = new FileMetadata().readMetadata(new StringReader("bla bla a\nabcde\n\nabc"));
+    DefaultInputFile file = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), f -> f.setMetadata(metadata));
+
+    assertThat(file.selectLine(1).start().line()).isEqualTo(1);
+    assertThat(file.selectLine(1).start().lineOffset()).isEqualTo(0);
+    assertThat(file.selectLine(1).end().line()).isEqualTo(1);
+    assertThat(file.selectLine(1).end().lineOffset()).isEqualTo(9);
+
+    // Don't fail when selecting empty line
+    assertThat(file.selectLine(3).start().line()).isEqualTo(3);
+    assertThat(file.selectLine(3).start().lineOffset()).isEqualTo(0);
+    assertThat(file.selectLine(3).end().line()).isEqualTo(3);
+    assertThat(file.selectLine(3).end().lineOffset()).isEqualTo(0);
+
+    try {
+      file.selectLine(5);
+      fail();
+    } catch (Exception e) {
+      assertThat(e).hasMessage("5 is not a valid line for pointer. File src/Foo.php has 4 line(s)");
+    }
+  }
+
+  @Test
+  public void checkValidRangeUsingGlobalOffset() {
+    Metadata metadata = new Metadata(2, 2, "", new int[] {0, 10}, new int[] {9, 15}, 16);
+    DefaultInputFile file = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), f -> f.setMetadata(metadata));
+    TextRange newRange = file.newRange(10, 13);
+    assertThat(newRange.start().line()).isEqualTo(2);
+    assertThat(newRange.start().lineOffset()).isEqualTo(0);
+    assertThat(newRange.end().line()).isEqualTo(2);
+    assertThat(newRange.end().lineOffset()).isEqualTo(3);
+  }
+
+  @Test
+  public void testRangeOverlap() {
+    Metadata metadata = new Metadata(2, 2, "", new int[] {0, 10}, new int[] {9, 15}, 16);
+    DefaultInputFile file = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), f -> f.setMetadata(metadata));
+    // Don't fail
+    assertThat(file.newRange(file.newPointer(1, 0), file.newPointer(1, 1)).overlap(file.newRange(file.newPointer(1, 0), file.newPointer(1, 1)))).isTrue();
+    assertThat(file.newRange(file.newPointer(1, 0), file.newPointer(1, 1)).overlap(file.newRange(file.newPointer(1, 0), file.newPointer(1, 2)))).isTrue();
+    assertThat(file.newRange(file.newPointer(1, 0), file.newPointer(1, 1)).overlap(file.newRange(file.newPointer(1, 1), file.newPointer(1, 2)))).isFalse();
+    assertThat(file.newRange(file.newPointer(1, 2), file.newPointer(1, 3)).overlap(file.newRange(file.newPointer(1, 0), file.newPointer(1, 2)))).isFalse();
+  }
+}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/fs/DefaultInputModuleTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/fs/DefaultInputModuleTest.java
new file mode 100644 (file)
index 0000000..02570d3
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * 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.scanner.fs;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class DefaultInputModuleTest {
+
+  private static final String FILE_1 = "file1";
+  private static final String TEST_1 = "test1";
+  @Rule
+  public TemporaryFolder temp = new TemporaryFolder();
+
+  @Test
+  public void check_getters() throws IOException {
+    ProjectDefinition def = ProjectDefinition.create();
+    def.setKey("moduleKey");
+    File baseDir = temp.newFolder();
+    Path src = baseDir.toPath().resolve(FILE_1);
+    Files.createFile(src);
+    Path test = baseDir.toPath().resolve(TEST_1);
+    Files.createFile(test);
+    def.setBaseDir(baseDir);
+    File workDir = temp.newFolder();
+    def.setWorkDir(workDir);
+    def.setSources(FILE_1);
+    def.setTests(TEST_1);
+    DefaultInputModule module = new DefaultInputModule(def);
+
+    assertThat(module.key()).isEqualTo("moduleKey");
+    assertThat(module.definition()).isEqualTo(def);
+    assertThat(module.getBranch()).isNull();
+    assertThat(module.getBaseDir()).isEqualTo(baseDir.toPath());
+    assertThat(module.getKeyWithBranch()).isEqualTo("moduleKey");
+    assertThat(module.getWorkDir()).isEqualTo(workDir.toPath());
+    assertThat(module.getEncoding()).isEqualTo(Charset.defaultCharset());
+    assertThat(module.getSourceDirsOrFiles().get()).containsExactlyInAnyOrder(src);
+    assertThat(module.getTestDirsOrFiles().get()).containsExactlyInAnyOrder(test);
+    assertThat(module.getEncoding()).isEqualTo(Charset.defaultCharset());
+
+    assertThat(module.isFile()).isFalse();
+  }
+
+  @Test
+  public void no_sources() throws IOException {
+    ProjectDefinition def = ProjectDefinition.create();
+    def.setKey("moduleKey");
+    File baseDir = temp.newFolder();
+    Path src = baseDir.toPath().resolve(FILE_1);
+    Files.createFile(src);
+    Path test = baseDir.toPath().resolve(TEST_1);
+    Files.createFile(test);
+    def.setBaseDir(baseDir);
+    File workDir = temp.newFolder();
+    def.setWorkDir(workDir);
+    DefaultInputModule module = new DefaultInputModule(def);
+
+    assertThat(module.key()).isEqualTo("moduleKey");
+    assertThat(module.definition()).isEqualTo(def);
+    assertThat(module.getBranch()).isNull();
+    assertThat(module.getBaseDir()).isEqualTo(baseDir.toPath());
+    assertThat(module.getKeyWithBranch()).isEqualTo("moduleKey");
+    assertThat(module.getWorkDir()).isEqualTo(workDir.toPath());
+    assertThat(module.getEncoding()).isEqualTo(Charset.defaultCharset());
+    assertThat(module.getSourceDirsOrFiles()).isNotPresent();
+    assertThat(module.getTestDirsOrFiles()).isNotPresent();
+    assertThat(module.getEncoding()).isEqualTo(Charset.defaultCharset());
+
+    assertThat(module.isFile()).isFalse();
+  }
+
+  @Test
+  public void working_directory_should_be_hidden() throws IOException {
+    ProjectDefinition def = ProjectDefinition.create();
+    File workDir = temp.newFolder(".sonar");
+    def.setWorkDir(workDir);
+    File baseDir = temp.newFolder();
+    def.setBaseDir(baseDir);
+    DefaultInputModule module = new DefaultInputModule(def);
+    assertThat(workDir.isHidden()).isTrue();
+  }
+
+}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/fs/DefaultInputProjectTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/fs/DefaultInputProjectTest.java
new file mode 100644 (file)
index 0000000..0324847
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * 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.scanner.fs;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class DefaultInputProjectTest {
+
+  @Rule
+  public TemporaryFolder temp = new TemporaryFolder();
+
+  @Test
+  public void testGetters() throws IOException {
+    ProjectDefinition def = ProjectDefinition.create();
+    def.setKey("projectKey");
+    def.setName("projectName");
+    File baseDir = temp.newFolder();
+    def.setBaseDir(baseDir);
+    def.setDescription("desc");
+    File workDir = temp.newFolder();
+    def.setWorkDir(workDir);
+    def.setSources("file1");
+    def.setTests("test1");
+    AbstractProjectOrModule project = new DefaultInputProject(def);
+
+    assertThat(project.key()).isEqualTo("projectKey");
+    assertThat(project.getName()).isEqualTo("projectName");
+    assertThat(project.getOriginalName()).isEqualTo("projectName");
+    assertThat(project.definition()).isEqualTo(def);
+    assertThat(project.getBranch()).isNull();
+    assertThat(project.getBaseDir()).isEqualTo(baseDir.toPath());
+    assertThat(project.getKeyWithBranch()).isEqualTo("projectKey");
+    assertThat(project.getDescription()).isEqualTo("desc");
+    assertThat(project.getWorkDir()).isEqualTo(workDir.toPath());
+    assertThat(project.getEncoding()).isEqualTo(Charset.defaultCharset());
+
+    assertThat(project.properties()).hasSize(5);
+
+    assertThat(project.isFile()).isFalse();
+  }
+
+  @Test
+  public void testEncoding() throws IOException {
+    ProjectDefinition def = ProjectDefinition.create();
+    def.setKey("projectKey");
+    def.setName("projectName");
+    File baseDir = temp.newFolder();
+    def.setBaseDir(baseDir);
+    def.setProjectVersion("version");
+    def.setDescription("desc");
+    File workDir = temp.newFolder();
+    def.setWorkDir(workDir);
+    def.setSources("file1");
+    def.setProperty("sonar.sourceEncoding", "UTF-16");
+    AbstractProjectOrModule project = new DefaultInputProject(def);
+
+    assertThat(project.getEncoding()).isEqualTo(StandardCharsets.UTF_16);
+  }
+
+}
index 826edf9d08677d2fd3982ed17d837734c6392492..c2665324ebc0d0bb678058b10167a40a7417d9fa 100644 (file)
@@ -23,7 +23,6 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
-
 import javax.annotation.Nullable;
 import org.apache.commons.codec.binary.Hex;
 import org.apache.commons.io.FileUtils;
@@ -31,7 +30,6 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.fs.internal.Metadata;
 import org.sonar.api.utils.log.LogTester;
 import org.sonar.api.utils.log.LoggerLevel;
@@ -223,7 +221,7 @@ public class FileMetadataTest {
     File tempFile = temp.newFile();
     FileUtils.write(tempFile, " foo\nb ar\r\nbaz \t", StandardCharsets.UTF_8, true);
 
-    org.sonar.api.batch.fs.internal.DefaultInputFile f = new TestInputFileBuilder("foo", tempFile.getName())
+    DefaultInputFile f = new TestInputFileBuilder("foo", tempFile.getName())
       .setModuleBaseDir(tempFile.getParentFile().toPath())
       .setCharset(StandardCharsets.UTF_8)
       .build();
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/fs/TestInputFileBuilderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/fs/TestInputFileBuilderTest.java
new file mode 100644 (file)
index 0000000..2d83007
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * 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.scanner.fs;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import org.apache.commons.io.IOUtils;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.sonar.api.batch.fs.InputFile.Status;
+import org.sonar.api.batch.fs.InputFile.Type;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class TestInputFileBuilderTest {
+
+  @Rule
+  public TemporaryFolder temp = new TemporaryFolder();
+
+  @Test
+  public void setContent() throws IOException {
+    DefaultInputFile file = TestInputFileBuilder.create("module", "invalidPath")
+      .setContents("my content")
+      .setCharset(StandardCharsets.UTF_8)
+      .build();
+    assertThat(file.contents()).isEqualTo("my content");
+    assertThat(IOUtils.toString(file.inputStream())).isEqualTo("my content");
+  }
+
+  @Test
+  public void testGetters() {
+    DefaultInputFile file = TestInputFileBuilder.create("module", new File("baseDir"), new File("baseDir", "path"))
+      .setStatus(Status.SAME)
+      .setType(Type.MAIN)
+      .build();
+
+    assertThat(file.type()).isEqualTo(Type.MAIN);
+    assertThat(file.status()).isEqualTo(Status.SAME);
+    assertThat(file.isPublished()).isTrue();
+    assertThat(file.type()).isEqualTo(Type.MAIN);
+    assertThat(file.relativePath()).isEqualTo("path");
+    assertThat(file.absolutePath()).isEqualTo("baseDir/path");
+
+  }
+
+  @Test
+  public void testCreateInputModule() throws IOException {
+    File baseDir = temp.newFolder();
+    AbstractProjectOrModule module = TestInputFileBuilder.newDefaultInputModule("key", baseDir);
+    assertThat(module.key()).isEqualTo("key");
+    assertThat(module.getBaseDir()).isEqualTo(baseDir.toPath());
+  }
+}
index b90e6a19dd48c44f4c995e36374cb5e5046e3834..ccd628b0a17dc462d4ca1b533dffa0e1a987fe5f 100644 (file)
@@ -27,8 +27,8 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.utils.MessageException;
+import org.sonar.scanner.fs.DefaultInputFile;
 import org.sonar.scanner.fs.TestInputFileBuilder;
 import org.sonar.scanner.sensor.SensorContextTester;
 
index c9f44cd5b8f0e12118db587866a37590f911769b..40ac5200719b848bd0130c1ad26e272c40c99bc0 100644 (file)
@@ -27,11 +27,11 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.test.MutableTestCase;
 import org.sonar.api.test.MutableTestPlan;
 import org.sonar.api.utils.MessageException;
 import org.sonar.scanner.deprecated.test.TestPlanBuilder;
+import org.sonar.scanner.fs.DefaultInputFile;
 import org.sonar.scanner.fs.TestInputFileBuilder;
 import org.sonar.scanner.sensor.SensorContextTester;
 
index b506b78f0749f44be3a83933c1cf4b39746fbce8..5250e1aa5d1311fdca91406e2c0d758b31229f68 100644 (file)
@@ -23,8 +23,8 @@ import java.util.Date;
 import org.junit.Before;
 import org.junit.Test;
 import org.sonar.api.batch.fs.InputComponent;
-import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.scanner.ProjectInfo;
+import org.sonar.scanner.fs.DefaultInputProject;
 import org.sonar.scanner.protocol.Constants.Severity;
 import org.sonar.scanner.protocol.output.ScannerReport.Issue;
 import org.sonar.scanner.protocol.output.ScannerReport.TextRange;
index 50c247f5b51fcbbd8cc102bb5ca5bd3bfb868b7e..881a3629a04f60844ebb8b5b4f1ffdbc2b1ef43f 100644 (file)
@@ -32,20 +32,18 @@ import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
 import org.sonar.api.batch.fs.InputComponent;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputProject;
-import org.sonar.scanner.fs.TestInputFileBuilder;
-import org.sonar.scanner.rule.ActiveRulesBuilder;
-import org.sonar.scanner.rule.NewActiveRule;
-import org.sonar.scanner.rule.RulesBuilder;
-import org.sonar.scanner.sensor.DefaultExternalIssue;
-import org.sonar.scanner.sensor.DefaultIssue;
-import org.sonar.scanner.sensor.DefaultIssueLocation;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.rule.Severity;
 import org.sonar.api.rules.RuleType;
+import org.sonar.scanner.fs.DefaultInputFile;
+import org.sonar.scanner.fs.DefaultInputProject;
+import org.sonar.scanner.fs.TestInputFileBuilder;
 import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.scanner.report.ReportPublisher;
+import org.sonar.scanner.rule.ActiveRulesBuilder;
+import org.sonar.scanner.rule.NewActiveRule;
+import org.sonar.scanner.rule.RulesBuilder;
+import org.sonar.scanner.sensor.DefaultExternalIssue;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.ArgumentMatchers.any;
index 8a9df4a744a83f0f7a0640b057987f6e49b96f2d..d5a99ff296fecf44afa6b60e77f78e8b30742f9f 100644 (file)
@@ -21,10 +21,10 @@ package org.sonar.scanner.issue.ignore;
 
 import org.junit.Before;
 import org.junit.Test;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.scan.issue.filter.IssueFilterChain;
 import org.sonar.api.utils.WildcardPattern;
+import org.sonar.scanner.fs.DefaultInputFile;
 import org.sonar.scanner.issue.DefaultFilterableIssue;
 
 import static org.assertj.core.api.Assertions.assertThat;
index 6a597ef85b3b78c0818ee6234e76d4a9a11bccd7..94cebe5f0bdc96ad2bec20c73a67b8fe3c354f4b 100644 (file)
@@ -27,9 +27,9 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.scanner.fs.TestInputFileBuilder;
 import org.sonar.api.notifications.AnalysisWarnings;
+import org.sonar.scanner.fs.DefaultInputFile;
+import org.sonar.scanner.fs.TestInputFileBuilder;
 import org.sonar.scanner.issue.ignore.IgnoreIssuesFilter;
 import org.sonar.scanner.issue.ignore.pattern.IssueExclusionPatternInitializer;
 import org.sonar.scanner.issue.ignore.pattern.IssuePattern;
index 07c39d82113022b872fc584aa1103370118d98c5..fb4165825e750fe3fded201ffab88fb5ac24bff8 100644 (file)
@@ -34,7 +34,7 @@ import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
+import org.sonar.scanner.fs.DefaultInputFile;
 import org.sonar.scanner.fs.FileMetadata;
 import org.sonar.scanner.fs.TestInputFileBuilder;
 import org.sonar.scanner.issue.ignore.pattern.IssueExclusionPatternInitializer;
index 16154f5ff0c6bdd82154cdead85e62c0c6070509..40695d3529e397518fc8463fa328279884063300 100644 (file)
@@ -30,7 +30,7 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
+import org.sonar.scanner.fs.DefaultInputFile;
 import org.sonar.scanner.fs.FileMetadata;
 import org.sonar.scanner.mediumtest.AnalysisResult;
 import org.sonar.scanner.mediumtest.ScannerMediumTester;
index 627e285af3a0710aa3fce7a4a9ad6de0245ebd7a..d6f141aa0f87b879156936ed50504a7b51168e98 100644 (file)
@@ -32,8 +32,8 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.SonarEdition;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.utils.MessageException;
+import org.sonar.scanner.fs.DefaultInputFile;
 import org.sonar.scanner.mediumtest.AnalysisResult;
 import org.sonar.scanner.mediumtest.ScannerMediumTester;
 import org.sonar.xoo.XooPlugin;
index 6ae40643542fc2888eea77df889876f1ffaca9d6..e64c47b7edb77ecc964425ab9457ef3abc6e5150 100644 (file)
@@ -36,12 +36,12 @@ import org.junit.rules.TemporaryFolder;
 import org.sonar.api.CoreProperties;
 import org.sonar.api.SonarEdition;
 import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.utils.MessageException;
 import org.sonar.api.utils.PathUtils;
 import org.sonar.api.utils.System2;
 import org.sonar.api.utils.log.LogTester;
 import org.sonar.api.utils.log.LoggerLevel;
+import org.sonar.scanner.fs.DefaultInputFile;
 import org.sonar.scanner.mediumtest.AnalysisResult;
 import org.sonar.scanner.mediumtest.ScannerMediumTester;
 import org.sonar.xoo.XooPlugin;
index fe18fdb725fb86e45d803603c773ca2f1a30a580..6bfffc32384e7aa8837539211a41769df651ad90 100644 (file)
@@ -25,7 +25,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.CoreProperties;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
+import org.sonar.scanner.fs.DefaultInputFile;
 import org.sonar.scanner.fs.TestInputFileBuilder;
 import org.sonar.scanner.scan.ModuleConfiguration;
 import org.sonar.scanner.scan.filesystem.ModuleCoverageAndDuplicationExclusions;
index bce232d44f08a1435ddb3ee1661bf8a580dbb260..d48402ea9edff75ed61b41e24ccb53ff85c330dc 100644 (file)
@@ -26,15 +26,15 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
-import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
 import org.sonar.api.batch.fs.internal.SensorStrategy;
-import org.sonar.scanner.fs.TestInputFileBuilder;
 import org.sonar.api.batch.sensor.Sensor;
-import org.sonar.scanner.sensor.ModuleSensorExtensionDictionnary;
 import org.sonar.scanner.bootstrap.ScannerPluginRepository;
-import org.sonar.scanner.sensor.ModuleSensorsExecutor;
+import org.sonar.scanner.fs.DefaultInputModule;
+import org.sonar.scanner.fs.InputModuleHierarchy;
+import org.sonar.scanner.fs.TestInputFileBuilder;
+import org.sonar.scanner.sensor.ModuleSensorExtensionDictionnary;
 import org.sonar.scanner.sensor.ModuleSensorWrapper;
+import org.sonar.scanner.sensor.ModuleSensorsExecutor;
 
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
index b041c6badc87de239cc3944224d2f2d4b2f4bcd9..a225093a650321bdf8b898f6a27648046a98d46d 100644 (file)
@@ -25,7 +25,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.CoreProperties;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
+import org.sonar.scanner.fs.DefaultInputFile;
 import org.sonar.scanner.fs.TestInputFileBuilder;
 import org.sonar.scanner.scan.ProjectConfiguration;
 import org.sonar.scanner.scan.filesystem.ProjectCoverageAndDuplicationExclusions;
index 22c8528301fb4e5cec6b16ffa5131c911e311818..f795cf9740809d1a4ca3265d8e4e272bfce0bd0a 100644 (file)
@@ -32,14 +32,14 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
-import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
 import org.sonar.api.utils.System2;
 import org.sonar.api.utils.log.LogTester;
 import org.sonar.api.utils.log.LoggerLevel;
 import org.sonar.core.platform.PluginInfo;
 import org.sonar.scanner.bootstrap.GlobalServerSettings;
 import org.sonar.scanner.bootstrap.ScannerPluginRepository;
+import org.sonar.scanner.fs.DefaultInputModule;
+import org.sonar.scanner.fs.InputModuleHierarchy;
 import org.sonar.scanner.protocol.output.ScannerReportWriter;
 import org.sonar.scanner.scan.ProjectServerSettings;
 import org.sonar.scanner.scan.filesystem.InputComponentStore;
@@ -147,6 +147,66 @@ public class AnalysisContextReportPublisherTest {
       "  - sonar.projectKey=foo");
   }
 
+  @Test
+  public void shouldNotDumpSQPropsInSystemProps() throws Exception {
+    logTester.setLevel(LoggerLevel.DEBUG);
+    ScannerReportWriter writer = new ScannerReportWriter(temp.newFolder());
+    Properties props = new Properties();
+    props.setProperty(COM_FOO, "bar");
+    props.setProperty(SONAR_SKIP, "true");
+    when(system2.properties()).thenReturn(props);
+    DefaultInputModule rootModule = new DefaultInputModule(ProjectDefinition.create()
+      .setBaseDir(temp.newFolder())
+      .setWorkDir(temp.newFolder())
+      .setProperty("sonar.projectKey", "foo")
+      .setProperty(COM_FOO, "bar")
+      .setProperty(SONAR_SKIP, "true"));
+    when(store.allModules()).thenReturn(singletonList(rootModule));
+    when(hierarchy.root()).thenReturn(rootModule);
+
+    publisher.init(writer);
+
+    List<String> lines = FileUtils.readLines(writer.getFileStructure().analysisLog(), StandardCharsets.UTF_8);
+    assertThat(lines).containsExactly("Environment variables:",
+      "System properties:",
+      "  - com.foo=bar",
+      "SonarQube plugins:",
+      "Global server settings:",
+      "Project server settings:",
+      "Project scanner properties:",
+      "  - sonar.projectKey=foo",
+      "  - sonar.skip=true");
+  }
+
+  @Test
+  public void shouldNotDumpEnvTwice() throws Exception {
+    logTester.setLevel(LoggerLevel.DEBUG);
+    ScannerReportWriter writer = new ScannerReportWriter(temp.newFolder());
+
+    Map<String, String> env = new HashMap<>();
+    env.put(FOO, "BAR");
+    env.put(BIZ, "BAZ");
+    when(system2.envVariables()).thenReturn(env);
+    DefaultInputModule rootModule = new DefaultInputModule(ProjectDefinition.create()
+      .setBaseDir(temp.newFolder())
+      .setWorkDir(temp.newFolder())
+      .setProperty("sonar.projectKey", "foo")
+      .setProperty("env." + FOO, "BAR"));
+    when(store.allModules()).thenReturn(singletonList(rootModule));
+    when(hierarchy.root()).thenReturn(rootModule);
+    publisher.init(writer);
+
+    String content = FileUtils.readFileToString(writer.getFileStructure().analysisLog(), StandardCharsets.UTF_8);
+    assertThat(content).containsOnlyOnce(FOO);
+    assertThat(content).containsOnlyOnce(BIZ);
+    assertThat(content).containsSubsequence(BIZ, FOO);
+
+    content = FileUtils.readFileToString(writer.getFileStructure().analysisLog(), StandardCharsets.UTF_8);
+    assertThat(content).containsOnlyOnce(FOO);
+    assertThat(content).containsOnlyOnce(BIZ);
+    assertThat(content).doesNotContain("env." + FOO);
+  }
+
   @Test
   public void shouldNotDumpSensitiveModuleProperties() throws Exception {
     ScannerReportWriter writer = new ScannerReportWriter(temp.newFolder());
@@ -187,7 +247,6 @@ public class AnalysisContextReportPublisherTest {
 
     assertThat(writer.getFileStructure().analysisLog()).exists();
 
-
     assertThat(FileUtils.readFileToString(writer.getFileStructure().analysisLog(), StandardCharsets.UTF_8)).containsSubsequence(
       "sonar.aVeryLongProp=" + StringUtils.repeat("abcde", 199) + "ab...",
       "sonar.projectBaseDir=" + baseDir.toString(),
index 4d4a3476553b34a9a7e0144f7646dc12894dc207..18ce32fab0a154c558d3e256358167bdf81e1ddd 100644 (file)
@@ -30,11 +30,11 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputProject;
-import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
-import org.sonar.scanner.fs.TestInputFileBuilder;
 import org.sonar.api.batch.scm.ScmProvider;
+import org.sonar.scanner.fs.DefaultInputFile;
+import org.sonar.scanner.fs.DefaultInputProject;
+import org.sonar.scanner.fs.InputModuleHierarchy;
+import org.sonar.scanner.fs.TestInputFileBuilder;
 import org.sonar.scanner.protocol.output.ScannerReportReader;
 import org.sonar.scanner.protocol.output.ScannerReportWriter;
 import org.sonar.scanner.scan.branch.BranchConfiguration;
index 36134513be999c25cfc53fcbe7cb1ea8da2b497f..b812747c69228efd8690b652722a1617e3082f58 100644 (file)
@@ -31,11 +31,11 @@ import org.sonar.api.CoreProperties;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.InputFile.Type;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputProject;
-import org.sonar.scanner.fs.TestInputFileBuilder;
 import org.sonar.api.utils.DateUtils;
 import org.sonar.scanner.ProjectInfo;
+import org.sonar.scanner.fs.DefaultInputFile;
+import org.sonar.scanner.fs.DefaultInputProject;
+import org.sonar.scanner.fs.TestInputFileBuilder;
 import org.sonar.scanner.protocol.output.FileStructure;
 import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.scanner.protocol.output.ScannerReport.Component;
index 7a66973ec2016617c0b3eefff17136f11feed96d..3eb07e5e945daa87492372b1ae8d64bd9099425c 100644 (file)
@@ -39,14 +39,14 @@ import org.junit.rules.TemporaryFolder;
 import org.junit.runner.RunWith;
 import org.sonar.api.CoreProperties;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
-import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
-import org.sonar.scanner.fs.TestInputFileBuilder;
 import org.sonar.api.batch.scm.ScmProvider;
 import org.sonar.scanner.ProjectInfo;
 import org.sonar.scanner.bootstrap.ScannerPlugin;
 import org.sonar.scanner.bootstrap.ScannerPluginRepository;
 import org.sonar.scanner.cpd.CpdSettings;
+import org.sonar.scanner.fs.DefaultInputModule;
+import org.sonar.scanner.fs.InputModuleHierarchy;
+import org.sonar.scanner.fs.TestInputFileBuilder;
 import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.scanner.protocol.output.ScannerReportReader;
 import org.sonar.scanner.protocol.output.ScannerReportWriter;
@@ -145,9 +145,9 @@ public class MetadataPublisherTest {
       .setRulesUpdatedAt(date.getTime())
       .build()));
     assertThat(metadata.getPluginsByKey()).containsOnly(entry("java", org.sonar.scanner.protocol.output.ScannerReport.Metadata.Plugin.newBuilder()
-      .setKey("java")
-      .setUpdatedAt(12345)
-      .build()),
+        .setKey("java")
+        .setUpdatedAt(12345)
+        .build()),
       entry("php", org.sonar.scanner.protocol.output.ScannerReport.Metadata.Plugin.newBuilder()
         .setKey("php")
         .setUpdatedAt(45678)
index 4c3699326a09cde9bcc0f0ea5be5bdc770b49781..3c7893722adb1fcb52a15d1183cf8d5fe4645504 100644 (file)
@@ -34,8 +34,6 @@ import org.junit.rules.TemporaryFolder;
 import org.mockito.ArgumentCaptor;
 import org.mockito.Mockito;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
-import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
 import org.sonar.api.platform.Server;
 import org.sonar.api.utils.MessageException;
 import org.sonar.api.utils.TempFolder;
@@ -43,6 +41,8 @@ import org.sonar.api.utils.log.LogTester;
 import org.sonar.api.utils.log.LoggerLevel;
 import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
 import org.sonar.scanner.bootstrap.ScannerWsClient;
+import org.sonar.scanner.fs.DefaultInputModule;
+import org.sonar.scanner.fs.InputModuleHierarchy;
 import org.sonar.scanner.scan.ScanProperties;
 import org.sonar.scanner.scan.branch.BranchConfiguration;
 import org.sonarqube.ws.Ce;
index 5f6054f81c997b65fa73bfbe558ee0697f6d7eb0..835e423f9ee3828f5bd0618b2206b97bc0aa1ce9 100644 (file)
@@ -27,8 +27,8 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputProject;
+import org.sonar.scanner.fs.DefaultInputFile;
+import org.sonar.scanner.fs.DefaultInputProject;
 import org.sonar.scanner.fs.TestInputFileBuilder;
 import org.sonar.scanner.protocol.output.ScannerReportWriter;
 import org.sonar.scanner.scan.branch.BranchConfiguration;
index 26bb3a6e1aaf658f2eb900605d38c833d1ea34fc..f2888be4c655607ee7f4e92e4a3ef678556f55a2 100644 (file)
@@ -29,10 +29,10 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.utils.MessageException;
 import org.sonar.scanner.WsTestUtil;
 import org.sonar.scanner.bootstrap.ScannerWsClient;
+import org.sonar.scanner.fs.DefaultInputFile;
 import org.sonarqube.ws.Batch.WsProjectResponse;
 import org.sonarqube.ws.client.HttpException;
 import org.sonarqube.ws.client.WsRequest;
index 87da83b2cd573b6f41c5ad7e02ee48f9397cb91f..aadf37e6a7542ef3bb857667f2f4baf1965ae18b 100644 (file)
@@ -28,7 +28,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.scanner.fs.DefaultInputModule;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
index 8c09090dff4a242df46e7edcdcbc2b036d7b959c..3c4cb6ffb15765e6588214c0b81e98244e2c7edc 100644 (file)
@@ -22,8 +22,7 @@ package org.sonar.scanner.scan;
 import java.util.Arrays;
 import org.junit.Test;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
-import org.sonar.api.batch.fs.internal.DefaultInputProject;
+import org.sonar.scanner.fs.DefaultInputModule;
 import org.sonar.scanner.scan.branch.BranchConfiguration;
 import org.sonar.scanner.scan.filesystem.InputComponentStore;
 
@@ -36,7 +35,7 @@ public class ModuleIndexerTest {
   private DefaultInputModuleHierarchy moduleHierarchy;
   private InputComponentStore componentStore;
 
-  public void createIndexer(DefaultInputProject rootProject) {
+  public void createIndexer() {
     componentStore = new InputComponentStore(mock(BranchConfiguration.class));
     moduleHierarchy = mock(DefaultInputModuleHierarchy.class);
     indexer = new ModuleIndexer(componentStore, moduleHierarchy);
@@ -69,7 +68,7 @@ public class ModuleIndexerTest {
     when(mod2.definition()).thenReturn(def);
     when(mod3.definition()).thenReturn(def);
 
-    createIndexer(mock(DefaultInputProject.class));
+    createIndexer();
     when(moduleHierarchy.root()).thenReturn(root);
     when(moduleHierarchy.children(root)).thenReturn(Arrays.asList(mod1, mod2, mod3));
 
index 4a1b0b5a4a2deac4d9a7a5e99b2c261d17f3f045..12f20933bdb4f240c337d036854b64e24266bb13 100644 (file)
@@ -29,7 +29,7 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.batch.fs.internal.DefaultInputProject;
+import org.sonar.scanner.fs.DefaultInputProject;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
index 49f1804c550596b65a7fc4b2dd8b05b42f33afd2..a2622ae4cbd7fbf4ade5978cf9e2bf89dca06b82 100644 (file)
@@ -27,9 +27,9 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
-import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.utils.MessageException;
+import org.sonar.scanner.fs.DefaultInputProject;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
index b4497362413da383c0e102e4612c3ff4073175b9..ba5aedb451f4e80a16954f21200013c086f0b9be 100644 (file)
@@ -26,8 +26,8 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
-import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
+import org.sonar.scanner.fs.DefaultInputModule;
+import org.sonar.scanner.fs.InputModuleHierarchy;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
index 04490bd02e4bad5e04f1cfe13de7f8cab01bf7b9..e9365140bd2a4cadf160cb7be8c2ff81c89e9f4a 100644 (file)
@@ -32,9 +32,9 @@ import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.InputFile.Status;
 import org.sonar.api.batch.fs.InputFile.Type;
 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.DefaultInputProject;
+import org.sonar.scanner.fs.DefaultInputFile;
+import org.sonar.scanner.fs.DefaultInputModule;
+import org.sonar.scanner.fs.DefaultInputProject;
 import org.sonar.scanner.fs.TestInputFileBuilder;
 import org.sonar.scanner.scan.branch.BranchConfiguration;
 
index 9bd732b9287ce15aab99c81b78f2fb71ad80915b..0682ccaf345a28af3359f9d8b642e98ea00a387e 100644 (file)
@@ -32,9 +32,9 @@ import org.junit.rules.TemporaryFolder;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.notifications.AnalysisWarnings;
 import org.sonar.api.utils.PathUtils;
+import org.sonar.scanner.fs.DefaultInputFile;
 import org.sonar.scanner.fs.FileMetadata;
 import org.sonar.scanner.fs.TestInputFileBuilder;
 import org.sonar.scanner.issue.ignore.IgnoreIssuesFilter;
index 2ead8234b68806eed2a209eea5eb35de2d3292cc..c624be2c6f1ebf8c0026058886795b233d2c845e 100644 (file)
@@ -26,8 +26,8 @@ import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.InputModule;
-import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.batch.fs.internal.SensorStrategy;
+import org.sonar.scanner.fs.DefaultInputProject;
 import org.sonar.scanner.fs.TestInputFileBuilder;
 import org.sonar.scanner.scan.branch.BranchConfiguration;
 
index 7e6540f69f1e87799308d90b8bc4599a08ae245e..9f613f48ed703f1ed9807534da60691040e4e59e 100644 (file)
@@ -30,7 +30,7 @@ import org.junit.rules.TemporaryFolder;
 import org.sonar.api.CoreProperties;
 import org.sonar.api.batch.fs.IndexedFile;
 import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.fs.internal.DefaultIndexedFile;
+import org.sonar.scanner.fs.DefaultIndexedFile;
 import org.sonar.api.config.internal.MapSettings;
 
 import static org.assertj.core.api.Assertions.assertThat;
index ccd56feef74a1dee97ed043cff76490b83fd72aa..167b4e33a9cfd8193127fea454381c8258a09826 100644 (file)
@@ -26,7 +26,7 @@ import java.util.Map;
 import org.junit.Before;
 import org.junit.Test;
 import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
+import org.sonar.scanner.fs.DefaultInputFile;
 import org.sonar.scanner.fs.TestInputFileBuilder;
 import org.sonar.scanner.repository.FileData;
 import org.sonar.scanner.repository.ProjectRepositoriesSupplier;
index 4b81bb45f5ea29ffb8deb1664e14134d076620fe..681433767ff5961cba6d79cd2f70d00ab0b751dd 100644 (file)
@@ -28,9 +28,9 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
-import org.sonar.api.batch.fs.internal.DefaultInputProject;
-import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
 import org.sonar.api.batch.scm.ScmProvider;
+import org.sonar.scanner.fs.DefaultInputProject;
+import org.sonar.scanner.fs.InputModuleHierarchy;
 import org.sonar.scanner.scan.branch.BranchConfiguration;
 
 import static org.assertj.core.api.Assertions.assertThat;
index a5ca3a8d26eaa3ebd93af84fb3d96358cbd509c4..a8f6ec829405b21ccd4d92b29d71852c1ecd7fdb 100644 (file)
@@ -32,13 +32,13 @@ import org.junit.runner.RunWith;
 import org.mockito.Answers;
 import org.sonar.api.CoreProperties;
 import org.sonar.api.batch.AnalysisMode;
-import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
 import org.sonar.api.batch.scm.ScmProvider;
 import org.sonar.api.config.Configuration;
 import org.sonar.api.notifications.AnalysisWarnings;
 import org.sonar.api.utils.MessageException;
 import org.sonar.api.utils.log.LogTester;
 import org.sonar.core.config.ScannerProperties;
+import org.sonar.scanner.fs.InputModuleHierarchy;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.any;
index ff6ca35bca7689c08ccc6df1a2f648b7f6ff5213..77d29126e44aad35bbf246ba71b58999af1f68fe 100644 (file)
@@ -24,9 +24,9 @@ import java.util.Map;
 import java.util.Optional;
 import javax.annotation.Nullable;
 import org.junit.Test;
-import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
 import org.sonar.scanner.bootstrap.RawScannerProperties;
 import org.sonar.scanner.ci.CiConfiguration;
+import org.sonar.scanner.fs.InputModuleHierarchy;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.ArgumentMatchers.any;
@@ -60,7 +60,7 @@ public class ScmRevisionImplTest {
   public void ignore_failure_if_scm_does_not_support_revisions() {
     CiConfiguration ciConfiguration = mock(CiConfiguration.class);
     when(ciConfiguration.getScmRevision()).thenReturn(Optional.empty());
-    Map<String,String> scannerConfiguration = new HashMap<>();
+    Map<String, String> scannerConfiguration = new HashMap<>();
     ScmConfiguration scmConfiguration = mock(ScmConfiguration.class, RETURNS_DEEP_STUBS);
     when(scmConfiguration.provider().revisionId(any())).thenThrow(new UnsupportedOperationException("BOOM"));
     InputModuleHierarchy moduleHierarchy = mock(InputModuleHierarchy.class, RETURNS_DEEP_STUBS);
@@ -73,7 +73,7 @@ public class ScmRevisionImplTest {
   private Optional<String> testGet(@Nullable String cliValue, @Nullable String ciValue, @Nullable String scmValue) {
     CiConfiguration ciConfiguration = mock(CiConfiguration.class);
     when(ciConfiguration.getScmRevision()).thenReturn(Optional.ofNullable(ciValue));
-    Map<String,String> scannerConfiguration = new HashMap<>();
+    Map<String, String> scannerConfiguration = new HashMap<>();
     scannerConfiguration.put("sonar.scm.revision", cliValue);
     ScmConfiguration scmConfiguration = mock(ScmConfiguration.class, RETURNS_DEEP_STUBS);
     when(scmConfiguration.provider().revisionId(any())).thenReturn(scmValue);
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultAnalysisErrorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultAnalysisErrorTest.java
new file mode 100644 (file)
index 0000000..afff924
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+ * 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.scanner.sensor;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.fs.TextPointer;
+import org.sonar.api.batch.sensor.error.NewAnalysisError;
+import org.sonar.api.batch.sensor.internal.SensorStorage;
+import org.sonar.scanner.fs.DefaultTextPointer;
+import org.sonar.scanner.fs.TestInputFileBuilder;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+
+public class DefaultAnalysisErrorTest {
+  private InputFile inputFile;
+  private SensorStorage storage;
+  private TextPointer textPointer;
+
+  @Rule
+  public ExpectedException exception = ExpectedException.none();
+
+  @Before
+  public void setUp() {
+    inputFile = new TestInputFileBuilder("module1", "src/File.java").build();
+    textPointer = new DefaultTextPointer(5, 2);
+    storage = mock(SensorStorage.class);
+  }
+
+  @Test
+  public void test_analysis_error() {
+    DefaultAnalysisError analysisError = new DefaultAnalysisError(storage);
+    analysisError.onFile(inputFile)
+      .at(textPointer)
+      .message("msg");
+
+    assertThat(analysisError.location()).isEqualTo(textPointer);
+    assertThat(analysisError.message()).isEqualTo("msg");
+    assertThat(analysisError.inputFile()).isEqualTo(inputFile);
+  }
+
+  @Test
+  public void test_save() {
+    DefaultAnalysisError analysisError = new DefaultAnalysisError(storage);
+    analysisError.onFile(inputFile).save();
+
+    verify(storage).store(analysisError);
+    verifyNoMoreInteractions(storage);
+  }
+
+  @Test
+  public void test_no_storage() {
+    exception.expect(NullPointerException.class);
+    DefaultAnalysisError analysisError = new DefaultAnalysisError();
+    analysisError.onFile(inputFile).save();
+  }
+
+  @Test
+  public void test_validation() {
+    try {
+      new DefaultAnalysisError(storage).onFile(null);
+      fail("Expected exception");
+    } catch (IllegalArgumentException e) {
+      // expected
+    }
+
+    NewAnalysisError error = new DefaultAnalysisError(storage).onFile(inputFile);
+    try {
+      error.onFile(inputFile);
+      fail("Expected exception");
+    } catch (IllegalStateException e) {
+      // expected
+    }
+
+    error = new DefaultAnalysisError(storage).at(textPointer);
+    try {
+      error.at(textPointer);
+      fail("Expected exception");
+    } catch (IllegalStateException e) {
+      // expected
+    }
+
+    try {
+      new DefaultAnalysisError(storage).save();
+      fail("Expected exception");
+    } catch (NullPointerException e) {
+      // expected
+    }
+  }
+}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultCpdTokensTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultCpdTokensTest.java
new file mode 100644 (file)
index 0000000..7a55979
--- /dev/null
@@ -0,0 +1,170 @@
+/*
+ * 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.scanner.sensor;
+
+import org.junit.Test;
+import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.sensor.internal.SensorStorage;
+import org.sonar.scanner.fs.DefaultInputFile;
+import org.sonar.scanner.fs.TestInputFileBuilder;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
+import static org.assertj.core.api.Assertions.tuple;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+
+public class DefaultCpdTokensTest {
+  private final SensorStorage sensorStorage = mock(SensorStorage.class);
+
+  private final DefaultInputFile inputFile = new TestInputFileBuilder("foo", "src/Foo.java")
+    .setLines(2)
+    .setOriginalLineStartOffsets(new int[] {0, 50})
+    .setOriginalLineEndOffsets(new int[] {49, 100})
+    .setLastValidOffset(101)
+    .build();
+
+  @Test
+  public void save_no_tokens() {
+    DefaultCpdTokens tokens = new DefaultCpdTokens(sensorStorage)
+      .onFile(inputFile);
+
+    tokens.save();
+
+    verify(sensorStorage).store(tokens);
+
+    assertThat(tokens.inputFile()).isEqualTo(inputFile);
+  }
+
+  @Test
+  public void save_one_token() {
+    DefaultCpdTokens tokens = new DefaultCpdTokens(sensorStorage)
+      .onFile(inputFile)
+      .addToken(inputFile.newRange(1, 2, 1, 5), "foo");
+
+    tokens.save();
+
+    verify(sensorStorage).store(tokens);
+
+    assertThat(tokens.getTokenLines()).extracting("value", "startLine", "hashCode", "startUnit", "endUnit").containsExactly(tuple("foo", 1, "foo".hashCode(), 1, 1));
+  }
+
+  @Test
+  public void handle_exclusions() {
+    inputFile.setExcludedForDuplication(true);
+    DefaultCpdTokens tokens = new DefaultCpdTokens(sensorStorage)
+      .onFile(inputFile)
+      .addToken(inputFile.newRange(1, 2, 1, 5), "foo");
+
+    tokens.save();
+
+    verifyZeroInteractions(sensorStorage);
+
+    assertThat(tokens.getTokenLines()).isEmpty();
+  }
+
+  @Test
+  public void dont_save_for_test_files() {
+    DefaultInputFile testInputFile = new TestInputFileBuilder("foo", "src/Foo.java")
+      .setLines(2)
+      .setOriginalLineStartOffsets(new int[] {0, 50})
+      .setOriginalLineEndOffsets(new int[] {49, 100})
+      .setLastValidOffset(101)
+      .setType(InputFile.Type.TEST)
+      .build();
+
+    DefaultCpdTokens tokens = new DefaultCpdTokens(sensorStorage)
+      .onFile(testInputFile)
+      .addToken(testInputFile.newRange(1, 2, 1, 5), "foo");
+
+    tokens.save();
+    verifyZeroInteractions(sensorStorage);
+    assertThat(tokens.getTokenLines()).isEmpty();
+  }
+
+  @Test
+  public void save_many_tokens() {
+    DefaultCpdTokens tokens = new DefaultCpdTokens(sensorStorage)
+      .onFile(inputFile)
+      .addToken(inputFile.newRange(1, 2, 1, 5), "foo")
+      .addToken(inputFile.newRange(1, 6, 1, 10), "bar")
+      .addToken(inputFile.newRange(1, 20, 1, 25), "biz")
+      .addToken(inputFile.newRange(2, 1, 2, 10), "next");
+
+    tokens.save();
+
+    verify(sensorStorage).store(tokens);
+
+    assertThat(tokens.getTokenLines())
+      .extracting("value", "startLine", "hashCode", "startUnit", "endUnit")
+      .containsExactly(
+        tuple("foobarbiz", 1, "foobarbiz".hashCode(), 1, 3),
+        tuple("next", 2, "next".hashCode(), 4, 4));
+  }
+
+  @Test
+  public void basic_validation() {
+    SensorStorage sensorStorage = mock(SensorStorage.class);
+    DefaultCpdTokens tokens = new DefaultCpdTokens(sensorStorage);
+    try {
+      tokens.save();
+      fail("Expected exception");
+    } catch (Exception e) {
+      assertThat(e).hasMessage("Call onFile() first");
+    }
+    try {
+      tokens.addToken(inputFile.newRange(1, 2, 1, 5), "foo");
+      fail("Expected exception");
+    } catch (Exception e) {
+      assertThat(e).hasMessage("Call onFile() first");
+    }
+    try {
+      tokens.addToken(null, "foo");
+      fail("Expected exception");
+    } catch (Exception e) {
+      assertThat(e).hasMessage("Range should not be null");
+    }
+    try {
+      tokens.addToken(inputFile.newRange(1, 2, 1, 5), null);
+      fail("Expected exception");
+    } catch (Exception e) {
+      assertThat(e).hasMessage("Image should not be null");
+    }
+  }
+
+  @Test
+  public void validate_tokens_order() {
+    SensorStorage sensorStorage = mock(SensorStorage.class);
+    DefaultCpdTokens tokens = new DefaultCpdTokens(sensorStorage)
+      .onFile(inputFile)
+      .addToken(inputFile.newRange(1, 6, 1, 10), "bar");
+
+    try {
+      tokens.addToken(inputFile.newRange(1, 2, 1, 5), "foo");
+      fail("Expected exception");
+    } catch (Exception e) {
+      assertThat(e).hasMessage("Tokens of file src/Foo.java should be provided in order.\n" +
+        "Previous token: Range[from [line=1, lineOffset=6] to [line=1, lineOffset=10]]\n" +
+        "Last token: Range[from [line=1, lineOffset=2] to [line=1, lineOffset=5]]");
+    }
+  }
+
+}
index ca91e301cc8d2b402fe62c2ee5b7be18a14c2023..0081480f4667805dbd07a74506c1db424fb8dab6 100644 (file)
@@ -27,13 +27,14 @@ import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
 import org.sonar.api.batch.fs.InputComponent;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
-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.rule.RuleKey;
 import org.sonar.api.rules.RuleType;
+import org.sonar.scanner.fs.DefaultInputFile;
+import org.sonar.scanner.fs.DefaultInputProject;
 import org.sonar.scanner.fs.TestInputFileBuilder;
+import org.sonar.scanner.issue.DefaultIssueLocation;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
index 712703976c2133a527d7225b7b19aaf6579c0a99..f70f92dd982d0bece8cda9ad67cb82b6961300bd 100644 (file)
@@ -26,9 +26,9 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.TextRange;
-import org.sonar.api.batch.fs.internal.DefaultTextPointer;
-import org.sonar.api.batch.fs.internal.DefaultTextRange;
 import org.sonar.api.batch.sensor.internal.SensorStorage;
+import org.sonar.scanner.fs.DefaultTextPointer;
+import org.sonar.scanner.fs.DefaultTextRange;
 import org.sonar.scanner.fs.TestInputFileBuilder;
 
 import static org.assertj.core.api.Assertions.assertThat;
index 96bd5936b6bcfb335c760039bd5523e0ed805648..f869f6f17f0f606e8663541572d04e8b130a9f00 100644 (file)
@@ -28,6 +28,7 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.scanner.fs.TestInputFileBuilder;
+import org.sonar.scanner.issue.DefaultIssueLocation;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.rules.ExpectedException.none;
index 0ab0b99655b99bfe1a16549fb054b91a8682a980..c6659dbc8a1429a5528ab3b8223134305ab7f9c2 100644 (file)
@@ -26,14 +26,16 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
-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.DefaultInputProject;
 import org.sonar.api.batch.rule.Severity;
 import org.sonar.api.batch.sensor.internal.SensorStorage;
 import org.sonar.api.rule.RuleKey;
+import org.sonar.scanner.fs.DefaultInputDir;
+import org.sonar.scanner.fs.DefaultInputFile;
+import org.sonar.scanner.fs.DefaultInputModule;
+import org.sonar.scanner.fs.DefaultInputProject;
 import org.sonar.scanner.fs.TestInputFileBuilder;
+import org.sonar.scanner.issue.DefaultIssue;
+import org.sonar.scanner.issue.DefaultIssueLocation;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
index 43844837e1e806b030b6cd141ce4ebd8c203ea4c..43de69f19d09441d53e2115e64349f777be8c45d 100644 (file)
@@ -25,10 +25,10 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.batch.fs.internal.AbstractProjectOrModule;
-import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.batch.sensor.internal.SensorStorage;
 import org.sonar.api.measures.CoreMetrics;
+import org.sonar.scanner.fs.AbstractProjectOrModule;
+import org.sonar.scanner.fs.DefaultInputProject;
 import org.sonar.scanner.fs.TestInputFileBuilder;
 
 import static org.assertj.core.api.Assertions.assertThat;
index d0aca624090495bc1ff1801e23125d5e660dcf4c..d95d44a69ed2ffd05c3ffa725826384fbee7af90 100644 (file)
@@ -29,21 +29,21 @@ import org.junit.rules.TemporaryFolder;
 import org.mockito.ArgumentCaptor;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
 import org.sonar.api.batch.fs.InputFile;
-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.DefaultInputProject;
 import org.sonar.api.batch.measure.MetricFinder;
-import org.sonar.api.batch.sensor.code.internal.DefaultSignificantCode;
 import org.sonar.api.batch.sensor.highlighting.TypeOfText;
 import org.sonar.api.batch.sensor.issue.ExternalIssue;
 import org.sonar.api.batch.sensor.issue.Issue;
-import org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.measures.CoreMetrics;
 import org.sonar.core.metric.ScannerMetrics;
 import org.sonar.scanner.cpd.index.SonarCpdBlockIndex;
+import org.sonar.scanner.fs.DefaultInputDir;
+import org.sonar.scanner.fs.DefaultInputFile;
+import org.sonar.scanner.fs.DefaultInputModule;
+import org.sonar.scanner.fs.DefaultInputProject;
 import org.sonar.scanner.fs.TestInputFileBuilder;
+import org.sonar.scanner.issue.DefaultIssue;
+import org.sonar.scanner.issue.DefaultIssueLocation;
 import org.sonar.scanner.issue.IssuePublisher;
 import org.sonar.scanner.protocol.output.FileStructure;
 import org.sonar.scanner.protocol.output.ScannerReport;
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSignificantCodeTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSignificantCodeTest.java
new file mode 100644 (file)
index 0000000..73a7f1c
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * 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.scanner.sensor;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.sensor.internal.SensorStorage;
+import org.sonar.scanner.fs.TestInputFileBuilder;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+public class DefaultSignificantCodeTest {
+  private SensorStorage sensorStorage = mock(SensorStorage.class);
+  private DefaultSignificantCode underTest = new DefaultSignificantCode(sensorStorage);
+  private InputFile inputFile = TestInputFileBuilder.create("module", "file1.xoo")
+    .setContents("this is\na file\n with some code")
+    .build();
+
+  @Rule
+  public ExpectedException exception = ExpectedException.none();
+
+  @Test
+  public void should_save_ranges() {
+    underTest.onFile(inputFile)
+      .addRange(inputFile.selectLine(1))
+      .save();
+    verify(sensorStorage).store(underTest);
+  }
+
+  @Test
+  public void fail_if_save_without_file() {
+    exception.expect(IllegalStateException.class);
+    exception.expectMessage("Call onFile() first");
+    underTest.save();
+  }
+
+  @Test
+  public void fail_if_add_range_to_same_line_twice() {
+    underTest.onFile(inputFile);
+    underTest.addRange(inputFile.selectLine(1));
+
+    exception.expect(IllegalStateException.class);
+    exception.expectMessage("Significant code was already reported for line '1'.");
+    underTest.addRange(inputFile.selectLine(1));
+  }
+
+  @Test
+  public void fail_if_range_includes_many_lines() {
+    underTest.onFile(inputFile);
+
+    exception.expect(IllegalArgumentException.class);
+    exception.expectMessage("Ranges of significant code must be located in a single line");
+    underTest.addRange(inputFile.newRange(1, 1, 2, 1));
+  }
+
+  @Test
+  public void fail_if_add_range_before_setting_file() {
+    exception.expect(IllegalStateException.class);
+    exception.expectMessage("addRange() should be called after on()");
+    underTest.addRange(inputFile.selectLine(1));
+  }
+}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSymbolTableTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSymbolTableTest.java
new file mode 100644 (file)
index 0000000..3339e1d
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * 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.scanner.sensor;
+
+import java.util.Map;
+import java.util.Set;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.fs.TextRange;
+import org.sonar.api.batch.sensor.internal.SensorStorage;
+import org.sonar.scanner.fs.TestInputFileBuilder;
+import org.sonar.scanner.sensor.DefaultSymbolTable;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+
+public class DefaultSymbolTableTest {
+
+  private static final InputFile INPUT_FILE = new TestInputFileBuilder("foo", "src/Foo.java")
+    .setLines(2)
+    .setOriginalLineStartOffsets(new int[] {0, 50})
+    .setOriginalLineEndOffsets(new int[] {49, 100})
+    .setLastValidOffset(101)
+    .build();
+
+  private Map<TextRange, Set<TextRange>> referencesPerSymbol;
+
+  @Rule
+  public ExpectedException throwable = ExpectedException.none();
+
+  @Before
+  public void setUpSampleSymbols() {
+
+    DefaultSymbolTable symbolTableBuilder = new DefaultSymbolTable(mock(SensorStorage.class))
+      .onFile(INPUT_FILE);
+    symbolTableBuilder
+      .newSymbol(0, 10)
+      .newReference(12, 15)
+      .newReference(2, 10, 2, 15);
+
+    symbolTableBuilder.newSymbol(1, 12, 1, 15).newReference(52, 55);
+
+    symbolTableBuilder.save();
+
+    referencesPerSymbol = symbolTableBuilder.getReferencesBySymbol();
+  }
+
+  @Test
+  public void should_register_symbols() {
+    assertThat(referencesPerSymbol).hasSize(2);
+  }
+
+}
index 01d3b6046e89fc55b572f4b7591ffab3508fa60c..668a050119ade6d8c9cb6d11c3c159e502de69d4 100644 (file)
@@ -28,7 +28,6 @@ import org.sonar.api.SonarEdition;
 import org.sonar.api.SonarQubeSide;
 import org.sonar.api.SonarRuntime;
 import org.sonar.api.batch.fs.InputModule;
-import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.batch.measure.MetricFinder;
 import org.sonar.api.batch.rule.ActiveRules;
 import org.sonar.api.batch.sensor.internal.SensorStorage;
@@ -37,6 +36,7 @@ import org.sonar.api.internal.SonarRuntimeImpl;
 import org.sonar.api.measures.CoreMetrics;
 import org.sonar.api.utils.Version;
 import org.sonar.scanner.fs.DefaultFileSystem;
+import org.sonar.scanner.fs.DefaultInputProject;
 import org.sonar.scanner.rule.ActiveRulesBuilder;
 
 import static org.assertj.core.api.Assertions.assertThat;
index cf1d452f76a1ac333d30a035a4561bda12210003..24e93796c3104f457b18849a1fd9df52637a90dd 100644 (file)
@@ -28,11 +28,6 @@ import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
 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.DefaultTextPointer;
-import org.sonar.scanner.fs.DefaultFileSystem;
-import org.sonar.scanner.fs.TestInputFileBuilder;
 import org.sonar.api.batch.rule.ActiveRules;
 import org.sonar.api.batch.rule.Severity;
 import org.sonar.api.batch.sensor.error.AnalysisError;
@@ -46,6 +41,11 @@ import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.measures.CoreMetrics;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.rules.RuleType;
+import org.sonar.scanner.fs.DefaultFileSystem;
+import org.sonar.scanner.fs.DefaultInputFile;
+import org.sonar.scanner.fs.DefaultInputModule;
+import org.sonar.scanner.fs.DefaultTextPointer;
+import org.sonar.scanner.fs.TestInputFileBuilder;
 import org.sonar.scanner.rule.ActiveRulesBuilder;
 import org.sonar.scanner.rule.NewActiveRule;