summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/CountUnresolvedIssuesDecorator.java5
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/AbstractNewCoverageFileAnalyzer.java6
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewCoverageFileAnalyzer.java3
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewItCoverageFileAnalyzer.java3
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewOverallCoverageFileAnalyzer.java3
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TendencyDecorator.java4
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java5
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java7
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/CountFalsePositivesDecoratorTest.java7
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/CountUnresolvedIssuesDecoratorTest.java5
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/DirectoriesDecoratorTest.java4
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ManualMeasureDecoratorTest.java2
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TendencyDecoratorTest.java10
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java5
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationDecoratorTest.java13
-rw-r--r--plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/CpdSensorTest.java2
-rw-r--r--plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/JavaCpdEngineTest.java2
-rw-r--r--plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/decorators/SumDuplicationsDecoratorTest.java6
-rw-r--r--plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/CoveragePerTestSensorTest.java8
-rw-r--r--plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/DependencySensorTest.java10
-rw-r--r--plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/MeasureSensorTest.java8
-rw-r--r--plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SymbolReferencesSensorTest.java6
-rw-r--r--plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SyntaxHighlightingSensorTest.java6
-rw-r--r--plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/TestCaseSensorTest.java6
-rw-r--r--plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/XooTokenizerSensorTest.java6
-rw-r--r--plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/OneIssuePerLineSensorTest.java4
-rw-r--r--plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/scm/XooBlameCommandTest.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueNotificationsTest.java1
-rw-r--r--sonar-batch/pom.xml1
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java15
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/TaskContainer.java10
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/components/PastMeasuresLoader.java3
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshot.java6
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinder.java8
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java3
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/debt/NewDebtDecorator.java5
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/deprecated/DeprecatedSensorContext.java (renamed from sonar-batch/src/main/java/org/sonar/batch/DeprecatedSensorContext.java)2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/deprecated/ResourceFilters.java (renamed from sonar-batch/src/main/java/org/sonar/batch/ResourceFilters.java)2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/deprecated/components/DefaultProjectClasspath.java (renamed from sonar-batch/src/main/java/org/sonar/batch/DefaultProjectClasspath.java)2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/deprecated/components/DefaultResourceCreationLock.java (renamed from sonar-batch/src/main/java/org/sonar/batch/DefaultResourceCreationLock.java)2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/deprecated/components/DefaultTimeMachine.java (renamed from sonar-batch/src/main/java/org/sonar/batch/DefaultTimeMachine.java)2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDate.java (renamed from sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDate.java)6
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDays.java (renamed from sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDays.java)6
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousAnalysis.java (renamed from sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysis.java)21
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersion.java (renamed from sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousVersion.java)14
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByVersion.java (renamed from sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByVersion.java)18
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/deprecated/components/Period.java (renamed from sonar-batch/src/main/java/org/sonar/batch/components/Period.java)2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PeriodsDefinition.java (renamed from sonar-batch/src/main/java/org/sonar/batch/components/PeriodsDefinition.java)8
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/deprecated/components/package-info.java23
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/deprecated/decorator/DecoratorsSelector.java (renamed from sonar-batch/src/main/java/org/sonar/batch/DecoratorsSelector.java)2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/deprecated/decorator/DefaultDecoratorContext.java (renamed from sonar-batch/src/main/java/org/sonar/batch/DefaultDecoratorContext.java)2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/deprecated/decorator/FormulaDecorator.java (renamed from sonar-batch/src/main/java/org/sonar/batch/FormulaDecorator.java)2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/deprecated/package-info.java (renamed from sonar-batch/src/main/java/org/sonar/batch/tasks/package-info.java)2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/deprecated/tasks/ListTask.java (renamed from sonar-batch/src/main/java/org/sonar/batch/tasks/ListTask.java)2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/deprecated/tasks/Tasks.java (renamed from sonar-batch/src/main/java/org/sonar/batch/tasks/Tasks.java)2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/deprecated/tasks/package-info.java23
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java22
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/ResourceKeyMigration.java56
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/SourceDataFactory.java29
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java60
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/issue/tracking/FileHashes.java30
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueHandlers.java6
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTrackingDecorator.java5
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/issue/tracking/LocalIssueTracking.java3
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/issue/tracking/SourceHashHolder.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java12
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsExecutor.java5
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/phases/Phases.java3
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/phases/SensorMatcher.java1
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/repository/language/DefaultLanguagesRepository.java (renamed from sonar-batch/src/main/java/org/sonar/batch/languages/DefaultLanguagesReferential.java)8
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/repository/language/Language.java (renamed from sonar-batch/src/main/java/org/sonar/batch/languages/Language.java)2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/repository/language/LanguagesRepository.java (renamed from sonar-batch/src/main/java/org/sonar/batch/languages/LanguagesReferential.java)6
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/repository/language/package-info.java (renamed from sonar-batch/src/main/java/org/sonar/batch/languages/package-info.java)2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/repository/user/User.java (renamed from sonar-batch/src/main/java/org/sonar/batch/user/User.java)2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/repository/user/UserRepository.java (renamed from sonar-batch/src/main/java/org/sonar/batch/user/UserRepository.java)2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/repository/user/package-info.java (renamed from sonar-batch/src/main/java/org/sonar/batch/user/package-info.java)2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/rule/QProfileSensor.java9
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/LanguageVerifier.java8
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java10
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java9
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/AdditionalFilePredicates.java39
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java18
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultInputFileValueCoder.java92
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java61
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DeprecatedFileFilters.java10
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileIndexer.java110
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileMetadata.java104
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputFileBuilder.java55
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputFileBuilderFactory.java13
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputFileMetadata.java73
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputPathCache.java105
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/LanguageDetection.java6
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/LanguageDetectionFactory.java7
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ModuleInputFileCache.java14
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/report/JSONReport.java44
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java15
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/source/CodeColorizers.java5
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/source/LinesSensor.java12
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/DefaultFileLinesContextTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/components/PastMeasuresLoaderTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java6
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/components/TimeMachineConfigurationTest.java4
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/debt/DebtDecoratorTest.java4
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/debt/NewDebtDecoratorTest.java5
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/debt/SqaleRatingDecoratorTest.java5
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/deprecated/ResourceFiltersTest.java (renamed from sonar-batch/src/test/java/org/sonar/batch/ResourceFiltersTest.java)2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDateTest.java (renamed from sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByDateTest.java)5
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDaysTest.java (renamed from sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByDaysTest.java)4
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousAnalysisTest.java (renamed from sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest.java)6
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest.java (renamed from sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest.java)6
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByVersionTest.java (renamed from sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByVersionTest.java)6
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PeriodsDefinitionTest.java (renamed from sonar-batch/src/test/java/org/sonar/batch/components/PeriodsDefinitionTest.java)6
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/deprecated/decorator/DecoratorsSelectorTest.java (renamed from sonar-batch/src/test/java/org/sonar/batch/DecoratorsSelectorTest.java)2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/deprecated/decorator/FormulaDecoratorTest.java (renamed from sonar-batch/src/test/java/org/sonar/batch/FormulaDecoratorTest.java)4
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/deprecated/tasks/ListTaskTest.java (renamed from sonar-batch/src/test/java/org/sonar/batch/tasks/ListTaskTest.java)5
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/deprecated/tasks/TasksTest.java (renamed from sonar-batch/src/test/java/org/sonar/batch/tasks/TasksTest.java)14
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/design/DirectoryDsmDecoratorTest.java4
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/design/DsmSerializerTest.java4
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/design/SubProjectDsmDecoratorTest.java4
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/BucketTest.java6
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java25
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/DuplicationPersisterTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java4
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/ResourceCacheTest.java4
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/ResourceKeyMigrationTest.java35
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/ResourcePersisterTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/SourceDataFactoryTest.java44
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/issue/ignore/scanner/IssueExclusionsLoaderTest.java7
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/issue/tracking/IssueTrackingDecoratorTest.java28
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/issue/tracking/IssueTrackingTest.java24
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/issue/tracking/SourceHashHolderTest.java39
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/phases/DecoratorsExecutorTest.java4
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/qualitygate/GenerateQualityGateEventsTest.java16
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java6
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/repository/user/UserRepositoryTest.java (renamed from sonar-batch/src/test/java/org/sonar/batch/user/UserRepositoryTest.java)2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/rule/QProfileSensorTest.java22
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/rule/QProfileVerifierTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/LanguageVerifierTest.java8
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/AdditionalFilePredicatesTest.java36
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ComponentIndexerTest.java34
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystemTest.java8
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DeprecatedFileFiltersTest.java11
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ExclusionFiltersTest.java25
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileMetadataTest.java77
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileBuilderFactoryTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileBuilderTest.java74
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputPathCacheTest.java54
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/LanguageDetectionFactoryTest.java8
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/LanguageDetectionTest.java24
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/measure/MeasureCacheTest.java8
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/report/JSONReportTest.java11
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/sensor/AnalyzerOptimizerTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorContextTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorStorageTest.java4
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/sensor/coverage/CoverageExclusionsTest.java4
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/source/CodeColorizersTest.java7
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/source/HighlightableBuilderTest.java2
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByDateTest/shared.xml (renamed from sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByDateTest/shared.xml)0
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByDaysTest/shared.xml (renamed from sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByDaysTest/shared.xml)0
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByDaysTest/shouldNotFindSelf.xml (renamed from sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByDaysTest/shouldNotFindSelf.xml)0
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousAnalysisTest/shouldFindPreviousAnalysis.xml (renamed from sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest/shouldFindPreviousAnalysis.xml)0
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousAnalysisTest/shouldNotFindPreviousAnalysis.xml (renamed from sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest/shouldNotFindPreviousAnalysis.xml)0
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest/no-previous-version.xml (renamed from sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest/no-previous-version.xml)0
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest/with-previous-version-deleted.xml (renamed from sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest/with-previous-version-deleted.xml)0
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest/with-previous-version.xml (renamed from sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest/with-previous-version.xml)0
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByVersionTest/shared.xml (renamed from sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByVersionTest/shared.xml)0
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PeriodsDefinitionTest/shared.xml (renamed from sonar-batch/src/test/resources/org/sonar/batch/components/PeriodsDefinitionTest/shared.xml)0
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewMultiModulesProject-result.xml2
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewMultiModulesProjectAndLibrary-result.xml2
-rw-r--r--sonar-core/src/main/java/org/sonar/batch/index/ResourceCopy.java3
-rw-r--r--sonar-core/src/test/java/org/sonar/core/component/ComponentKeysTest.java2
-rw-r--r--sonar-core/src/test/java/org/sonar/core/component/ResourceComponentTest.java4
-rw-r--r--sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractSourceImporter.java10
-rw-r--r--sonar-deprecated/src/test/java/org/sonar/api/checks/NoSonarFilterTest.java6
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java3
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/TimeMachine.java5
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputDir.java7
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputFile.java7
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputPath.java8
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AbsolutePathPredicate.java7
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFilePredicates.java5
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFileSystem.java31
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputDir.java30
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java94
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DeprecatedDefaultInputFile.java53
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/resources/Directory.java44
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/resources/File.java106
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/resources/Library.java1
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/resources/Project.java17
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/resources/ProjectFileSystem.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/resources/Resource.java25
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/FileSystemFilter.java6
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/task/Task.java3
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/task/TaskComponent.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/task/TaskDefinition.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/task/TaskExtension.java2
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultFilePredicatesTest.java4
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultFileSystemTest.java16
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputDirTest.java16
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputFileTest.java9
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DeprecatedDefaultInputFileTest.java14
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/PathPatternTest.java35
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCaseCoverageTest.java2
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCaseExecutionTest.java2
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/measures/AverageFormulaTest.java6
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/measures/SumChildDistributionFormulaTest.java10
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/resources/DirectoryTest.java70
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/resources/FileTest.java80
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceUtilsTest.java10
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/resources/ScopesTest.java4
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/scan/filesystem/PathResolverTest.java10
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/test/IsResource.java4
-rw-r--r--sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample-with-symlink/.gitignore1
-rw-r--r--sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample-with-symlink/sonar-project.properties6
l---------sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample-with-symlink/testx1
l---------sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample-with-symlink/xources1
-rw-r--r--sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/sonar-project.properties6
-rw-r--r--sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/testx/ClassOneTest.xoo11
-rw-r--r--sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/testx/ClassOneTest.xoo.measures7
-rw-r--r--sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/testx/ClassOneTest.xoo.scm11
-rw-r--r--sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/xources/hello/HelloJava.xoo8
-rw-r--r--sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/xources/hello/HelloJava.xoo.measures2
-rw-r--r--sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/xources/hello/HelloJava.xoo.scm8
-rw-r--r--sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/xources/hello/helloscala.xoo6
-rw-r--r--sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/xources/hello/helloscala.xoo.measures2
229 files changed, 1434 insertions, 1622 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/CountUnresolvedIssuesDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/CountUnresolvedIssuesDecorator.java
index d775ba8ec4c..61a6b69cc74 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/CountUnresolvedIssuesDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/CountUnresolvedIssuesDecorator.java
@@ -19,6 +19,9 @@
*/
package org.sonar.plugins.core.issue;
+import org.sonar.batch.components.TimeMachineConfiguration;
+
+import org.sonar.batch.deprecated.components.Period;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.*;
import org.apache.commons.lang.time.DateUtils;
@@ -32,8 +35,6 @@ import org.sonar.api.resources.Resource;
import org.sonar.api.resources.ResourceUtils;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rules.RulePriority;
-import org.sonar.batch.components.Period;
-import org.sonar.batch.components.TimeMachineConfiguration;
import javax.annotation.Nullable;
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/AbstractNewCoverageFileAnalyzer.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/AbstractNewCoverageFileAnalyzer.java
index 90435de8f3b..c275645899e 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/AbstractNewCoverageFileAnalyzer.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/AbstractNewCoverageFileAnalyzer.java
@@ -19,8 +19,10 @@
*/
package org.sonar.plugins.core.timemachine;
-import org.sonar.api.batch.RequiresDB;
+import org.sonar.batch.components.TimeMachineConfiguration;
+import org.sonar.batch.deprecated.components.Period;
+import org.sonar.api.batch.RequiresDB;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.commons.lang.ObjectUtils;
@@ -33,8 +35,6 @@ import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Resource;
import org.sonar.api.resources.Scopes;
import org.sonar.api.utils.KeyValueFormat;
-import org.sonar.batch.components.Period;
-import org.sonar.batch.components.TimeMachineConfiguration;
import javax.annotation.Nullable;
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewCoverageFileAnalyzer.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewCoverageFileAnalyzer.java
index ee415fdda33..352070ccc68 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewCoverageFileAnalyzer.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewCoverageFileAnalyzer.java
@@ -19,9 +19,10 @@
*/
package org.sonar.plugins.core.timemachine;
+import org.sonar.batch.components.TimeMachineConfiguration;
+
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Metric;
-import org.sonar.batch.components.TimeMachineConfiguration;
import java.util.List;
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewItCoverageFileAnalyzer.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewItCoverageFileAnalyzer.java
index 61351c1a8e4..2dbcf8416a4 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewItCoverageFileAnalyzer.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewItCoverageFileAnalyzer.java
@@ -19,9 +19,10 @@
*/
package org.sonar.plugins.core.timemachine;
+import org.sonar.batch.components.TimeMachineConfiguration;
+
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Metric;
-import org.sonar.batch.components.TimeMachineConfiguration;
public class NewItCoverageFileAnalyzer extends AbstractNewCoverageFileAnalyzer {
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewOverallCoverageFileAnalyzer.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewOverallCoverageFileAnalyzer.java
index 6ff8481786e..b57db6dbe0e 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewOverallCoverageFileAnalyzer.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewOverallCoverageFileAnalyzer.java
@@ -19,9 +19,10 @@
*/
package org.sonar.plugins.core.timemachine;
+import org.sonar.batch.components.TimeMachineConfiguration;
+
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Metric;
-import org.sonar.batch.components.TimeMachineConfiguration;
public class NewOverallCoverageFileAnalyzer extends AbstractNewCoverageFileAnalyzer {
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TendencyDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TendencyDecorator.java
index 44684523efd..aa98cf6c603 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TendencyDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TendencyDecorator.java
@@ -19,8 +19,9 @@
*/
package org.sonar.plugins.core.timemachine;
-import org.sonar.api.batch.RequiresDB;
+import org.sonar.batch.deprecated.components.PeriodsDefinition;
+import org.sonar.api.batch.RequiresDB;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Lists;
@@ -39,7 +40,6 @@ import org.sonar.api.measures.MetricFinder;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.resources.Scopes;
-import org.sonar.batch.components.PeriodsDefinition;
import java.util.List;
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java
index 84125404fb0..38083fed3db 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java
@@ -19,6 +19,9 @@
*/
package org.sonar.plugins.core.timemachine;
+import org.sonar.batch.components.TimeMachineConfiguration;
+
+import org.sonar.batch.components.PastSnapshot;
import org.sonar.api.batch.Decorator;
import org.sonar.api.batch.DecoratorBarriers;
import org.sonar.api.batch.DecoratorContext;
@@ -28,8 +31,6 @@ import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.resources.ResourceUtils;
-import org.sonar.batch.components.PastSnapshot;
-import org.sonar.batch.components.TimeMachineConfiguration;
import org.sonar.batch.index.ResourceCache;
import java.util.List;
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java
index dc6cab324c7..a997423aa37 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java
@@ -19,6 +19,10 @@
*/
package org.sonar.plugins.core.timemachine;
+import org.sonar.batch.components.TimeMachineConfiguration;
+
+import org.sonar.batch.components.PastSnapshot;
+import org.sonar.batch.components.PastMeasuresLoader;
import com.google.common.collect.Maps;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.batch.Decorator;
@@ -38,9 +42,6 @@ import org.sonar.api.resources.Scopes;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RuleFinder;
import org.sonar.api.technicaldebt.batch.Characteristic;
-import org.sonar.batch.components.PastMeasuresLoader;
-import org.sonar.batch.components.PastSnapshot;
-import org.sonar.batch.components.TimeMachineConfiguration;
import javax.annotation.Nullable;
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/CountFalsePositivesDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/CountFalsePositivesDecoratorTest.java
index cb8007f0b81..28327ac5954 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/CountFalsePositivesDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/CountFalsePositivesDecoratorTest.java
@@ -34,7 +34,10 @@ import org.sonar.java.api.JavaClass;
import java.util.Arrays;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
public class CountFalsePositivesDecoratorTest {
@@ -48,7 +51,7 @@ public class CountFalsePositivesDecoratorTest {
DefaultIssue fixed = new DefaultIssue().setRuleKey(RuleKey.parse("squid:AvoidCycles"))
.setResolution(Issue.RESOLUTION_FIXED).setStatus(Issue.STATUS_RESOLVED);
- File file = new File("foo.c");
+ File file = File.create("foo.c");
Issuable issuable = mock(Issuable.class);
when(perspectives.as(Issuable.class, file)).thenReturn(issuable);
when(issuable.resolvedIssues()).thenReturn(Arrays.<Issue>asList(falsePositive, fixed));
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/CountUnresolvedIssuesDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/CountUnresolvedIssuesDecoratorTest.java
index be9b8ae586c..912779a5356 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/CountUnresolvedIssuesDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/CountUnresolvedIssuesDecoratorTest.java
@@ -20,6 +20,9 @@
package org.sonar.plugins.core.issue;
+import org.sonar.batch.components.TimeMachineConfiguration;
+
+import org.sonar.batch.deprecated.components.Period;
import com.google.common.collect.Lists;
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.time.DateUtils;
@@ -40,8 +43,6 @@ import org.sonar.api.rule.Severity;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RulePriority;
import org.sonar.api.test.IsRuleMeasure;
-import org.sonar.batch.components.Period;
-import org.sonar.batch.components.TimeMachineConfiguration;
import java.util.Calendar;
import java.util.Collections;
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/DirectoriesDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/DirectoriesDecoratorTest.java
index adb52dfece0..01524877fb1 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/DirectoriesDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/DirectoriesDecoratorTest.java
@@ -43,7 +43,7 @@ public class DirectoriesDecoratorTest {
@Test
public void doNotInsertZeroOnFiles() {
DirectoriesDecorator decorator = new DirectoriesDecorator();
- Resource file = new File("foo.php");
+ Resource file = File.create("foo.php");
DecoratorContext context = mock(DecoratorContext.class);
decorator.decorate(file, context);
@@ -54,7 +54,7 @@ public class DirectoriesDecoratorTest {
@Test
public void directoryCountsForOne() {
DirectoriesDecorator decorator = new DirectoriesDecorator();
- Resource directory = new Directory("org/foo");
+ Resource directory = Directory.create("org/foo");
DecoratorContext context = mock(DecoratorContext.class);
decorator.decorate(directory, context);
verify(context).saveMeasure(CoreMetrics.DIRECTORIES, 1.0);
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ManualMeasureDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ManualMeasureDecoratorTest.java
index 2731680adc9..02793e1160c 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ManualMeasureDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ManualMeasureDecoratorTest.java
@@ -39,7 +39,7 @@ public class ManualMeasureDecoratorTest extends AbstractDbUnitTestCase {
public void testCopyManualMeasures() throws Exception {
setupData("testCopyManualMeasures");
- File javaFile = new File("Foo.java");
+ File javaFile = File.create("Foo.java");
javaFile.setId(40);
ManualMeasureDecorator decorator = new ManualMeasureDecorator(getSession(), new DefaultMetricFinder(getSessionFactory()));
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TendencyDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TendencyDecoratorTest.java
index ce7cc6cf5dd..839e6f51862 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TendencyDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TendencyDecoratorTest.java
@@ -36,8 +36,8 @@ import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
-import static org.hamcrest.Matchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
import static org.mockito.Matchers.anyList;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -75,14 +75,14 @@ public class TendencyDecoratorTest {
new Object[] {date("2009-12-02"), CoreMetrics.LINES, 1300.0},
new Object[] {date("2009-12-02"), CoreMetrics.COVERAGE, 79.6},
new Object[] {date("2009-12-15"), CoreMetrics.LINES, 1150.0}
- ));
+ ));
DecoratorContext context = mock(DecoratorContext.class);
when(context.getMeasure(CoreMetrics.LINES)).thenReturn(new Measure(CoreMetrics.LINES, 1400.0));
when(context.getMeasure(CoreMetrics.COVERAGE)).thenReturn(new Measure(CoreMetrics.LINES, 90.0));
TendencyDecorator decorator = new TendencyDecorator(timeMachine, query, analyser);
- decorator.decorate(new Directory("org/foo"), context);
+ decorator.decorate(Directory.create("org/foo"), context);
verify(analyser).analyseLevel(Arrays.asList(1200.0, 1300.0, 1150.0, 1400.0));
verify(analyser).analyseLevel(Arrays.asList(80.5, 79.6, 90.0));
@@ -97,11 +97,11 @@ public class TendencyDecoratorTest {
when(timeMachine.getMeasuresFields(query)).thenReturn(Arrays.<Object[]>asList(
new Object[] {date("2009-12-01"), CoreMetrics.LINES, 1200.0},
new Object[] {date("2009-12-02"), CoreMetrics.LINES, 1300.0}
- ));
+ ));
DecoratorContext context = mock(DecoratorContext.class);
TendencyDecorator decorator = new TendencyDecorator(timeMachine, query, analyser);
- decorator.decorate(new Directory("org/foo"), context);
+ decorator.decorate(Directory.create("org/foo"), context);
verify(analyser, never()).analyseLevel(anyList());
}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java
index f422f6f6020..ae79e7a47d3 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java
@@ -19,12 +19,13 @@
*/
package org.sonar.plugins.core.timemachine;
+import org.sonar.batch.components.TimeMachineConfiguration;
+
+import org.sonar.batch.components.PastSnapshot;
import org.junit.Test;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.Project;
import org.sonar.api.utils.DateUtils;
-import org.sonar.batch.components.PastSnapshot;
-import org.sonar.batch.components.TimeMachineConfiguration;
import org.sonar.batch.index.ResourceCache;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationDecoratorTest.java
index 4f6569e08cd..223abadcbac 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationDecoratorTest.java
@@ -19,6 +19,10 @@
*/
package org.sonar.plugins.core.timemachine;
+import org.sonar.batch.components.TimeMachineConfiguration;
+
+import org.sonar.batch.components.PastSnapshot;
+import org.sonar.batch.components.PastMeasuresLoader;
import org.junit.Test;
import org.mockito.Matchers;
import org.sonar.api.batch.DecoratorContext;
@@ -33,9 +37,6 @@ import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RuleFinder;
-import org.sonar.batch.components.PastMeasuresLoader;
-import org.sonar.batch.components.PastSnapshot;
-import org.sonar.batch.components.TimeMachineConfiguration;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
import java.util.Arrays;
@@ -64,12 +65,12 @@ public class VariationDecoratorTest extends AbstractDbUnitTestCase {
VariationDecorator decorator = new VariationDecorator(mock(PastMeasuresLoader.class), mock(MetricFinder.class), timeMachineConfiguration, mock(RuleFinder.class));
assertThat(decorator.shouldComputeVariation(new Project("foo"))).isTrue();
- assertThat(decorator.shouldComputeVariation(new File("foo/bar.c"))).isFalse();
+ assertThat(decorator.shouldComputeVariation(File.create("foo/bar.c"))).isFalse();
}
@Test
public void shouldCompareAndSaveVariation() {
- Resource dir = new Directory("org/foo");
+ Resource dir = Directory.create("org/foo");
PastMeasuresLoader pastMeasuresLoader = mock(PastMeasuresLoader.class);
PastSnapshot pastSnapshot1 = new PastSnapshot("days", new Date()).setIndex(1);
@@ -117,7 +118,7 @@ public class VariationDecoratorTest extends AbstractDbUnitTestCase {
when(ruleFinder.findByKey(rule1.ruleKey())).thenReturn(rule1);
when(ruleFinder.findByKey(rule2.ruleKey())).thenReturn(rule2);
- Resource dir = new Directory("org/foo");
+ Resource dir = Directory.create("org/foo");
PastMeasuresLoader pastMeasuresLoader = mock(PastMeasuresLoader.class);
PastSnapshot pastSnapshot1 = new PastSnapshot("days", new Date()).setIndex(1);
diff --git a/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/CpdSensorTest.java b/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/CpdSensorTest.java
index 28a78f5cc50..a4cfc381ae8 100644
--- a/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/CpdSensorTest.java
+++ b/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/CpdSensorTest.java
@@ -52,7 +52,7 @@ public class CpdSensorTest {
sonarBridgeEngine = new DefaultCpdEngine(indexFactory, new CpdMappings(), null, null, mock(BlockCache.class));
settings = new Settings(new PropertyDefinitions(CpdPlugin.class));
- DefaultFileSystem fs = new DefaultFileSystem(temp.newFolder());
+ DefaultFileSystem fs = new DefaultFileSystem(temp.newFolder().toPath());
sensor = new CpdSensor(sonarEngine, sonarBridgeEngine, settings, fs);
}
diff --git a/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/JavaCpdEngineTest.java b/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/JavaCpdEngineTest.java
index aa87b90dc13..182f57091d0 100644
--- a/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/JavaCpdEngineTest.java
+++ b/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/JavaCpdEngineTest.java
@@ -72,7 +72,7 @@ public class JavaCpdEngineTest {
inputFile = new DeprecatedDefaultInputFile("foo", "src/main/java/Foo.java");
duplicationBuilder = spy(new DefaultDuplicationBuilder(inputFile));
when(context.duplicationBuilder(any(InputFile.class))).thenReturn(duplicationBuilder);
- inputFile.setFile(temp.newFile("Foo.java"));
+ inputFile.setModuleBaseDir(temp.newFolder().toPath());
}
@SuppressWarnings("unchecked")
diff --git a/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/decorators/SumDuplicationsDecoratorTest.java b/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/decorators/SumDuplicationsDecoratorTest.java
index 0c733e9227a..de90865b0d0 100644
--- a/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/decorators/SumDuplicationsDecoratorTest.java
+++ b/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/decorators/SumDuplicationsDecoratorTest.java
@@ -27,8 +27,8 @@ import org.sonar.api.resources.File;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.test.IsMeasure;
-import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.greaterThan;
+import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.argThat;
@@ -48,7 +48,7 @@ public class SumDuplicationsDecoratorTest {
@Test
public void doNotSetDuplicationsOnUnitTests() {
SumDuplicationsDecorator decorator = new SumDuplicationsDecorator();
- File unitTest = new File("org/foo/BarTest.java");
+ File unitTest = File.create("org/foo/BarTest.java");
unitTest.setQualifier(Qualifiers.UNIT_TEST_FILE);
DecoratorContext context = mock(DecoratorContext.class);
@@ -60,7 +60,7 @@ public class SumDuplicationsDecoratorTest {
@Test
public void saveZeroIfNoDuplications() {
SumDuplicationsDecorator decorator = new SumDuplicationsDecorator();
- File file = new File("org/foo/BarTest.java");
+ File file = File.create("org/foo/BarTest.java");
DecoratorContext context = mock(DecoratorContext.class);
decorator.decorate(file, context);
diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/CoveragePerTestSensorTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/CoveragePerTestSensorTest.java
index 7cf94a15d02..4b57e397362 100644
--- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/CoveragePerTestSensorTest.java
+++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/CoveragePerTestSensorTest.java
@@ -57,7 +57,7 @@ public class CoveragePerTestSensorTest {
public void prepare() throws IOException {
baseDir = temp.newFolder();
sensor = new CoveragePerTestSensor();
- fileSystem = new DefaultFileSystem(baseDir);
+ fileSystem = new DefaultFileSystem(baseDir.toPath());
when(context.fileSystem()).thenReturn(fileSystem);
}
@@ -68,7 +68,7 @@ public class CoveragePerTestSensorTest {
@Test
public void testNoExecutionIfCoveragePerTestFile() {
- DefaultInputFile testFile = new DefaultInputFile("foo", "test/fooTest.xoo").setAbsolutePath(new File(baseDir, "test/fooTest.xoo").getAbsolutePath()).setLanguage("xoo")
+ DefaultInputFile testFile = new DefaultInputFile("foo", "test/fooTest.xoo").setLanguage("xoo")
.setType(Type.TEST);
fileSystem.add(testFile);
sensor.execute(context);
@@ -78,8 +78,8 @@ public class CoveragePerTestSensorTest {
public void testExecution() throws IOException {
File coverPerTest = new File(baseDir, "test/fooTest.xoo.coveragePerTest");
FileUtils.write(coverPerTest, "test1:src/foo.xoo:1,2,3,4\ntest2:src/foo.xoo:5,6,7\n\n#comment");
- DefaultInputFile inputFile = new DefaultInputFile("foo", "src/foo.xoo").setAbsolutePath(new File(baseDir, "src/foo.xoo").getAbsolutePath()).setLanguage("xoo");
- DefaultInputFile testFile = new DefaultInputFile("foo", "test/fooTest.xoo").setAbsolutePath(new File(baseDir, "test/fooTest.xoo").getAbsolutePath()).setLanguage("xoo")
+ DefaultInputFile inputFile = new DefaultInputFile("foo", "src/foo.xoo").setLanguage("xoo");
+ DefaultInputFile testFile = new DefaultInputFile("foo", "test/fooTest.xoo").setLanguage("xoo")
.setType(Type.TEST);
fileSystem.add(inputFile);
fileSystem.add(testFile);
diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/DependencySensorTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/DependencySensorTest.java
index 46f6e56c69d..e586263feda 100644
--- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/DependencySensorTest.java
+++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/DependencySensorTest.java
@@ -56,7 +56,7 @@ public class DependencySensorTest {
public void prepare() throws IOException {
baseDir = temp.newFolder();
sensor = new DependencySensor();
- fileSystem = new DefaultFileSystem(baseDir);
+ fileSystem = new DefaultFileSystem(baseDir.toPath());
when(context.fileSystem()).thenReturn(fileSystem);
}
@@ -67,7 +67,7 @@ public class DependencySensorTest {
@Test
public void testNoExecutionIfNoDepsFile() {
- DefaultInputFile file = new DefaultInputFile("foo", "src/foo.xoo").setAbsolutePath(new File(baseDir, "src/foo.xoo").getAbsolutePath()).setLanguage("xoo")
+ DefaultInputFile file = new DefaultInputFile("foo", "src/foo.xoo").setLanguage("xoo")
.setType(Type.MAIN);
fileSystem.add(file);
sensor.execute(context);
@@ -77,9 +77,9 @@ public class DependencySensorTest {
public void testExecution() throws IOException {
File deps = new File(baseDir, "src/foo.xoo.deps");
FileUtils.write(deps, "src/foo2.xoo:2\nsrc2/foo3.xoo:6\n\n#comment");
- DefaultInputFile inputFile1 = new DefaultInputFile("foo", "src/foo.xoo").setAbsolutePath(new File(baseDir, "src/foo.xoo").getAbsolutePath()).setLanguage("xoo");
- DefaultInputFile inputFile2 = new DefaultInputFile("foo", "src/foo2.xoo").setAbsolutePath(new File(baseDir, "src/foo2.xoo").getAbsolutePath()).setLanguage("xoo");
- DefaultInputFile inputFile3 = new DefaultInputFile("foo", "src2/foo3.xoo").setAbsolutePath(new File(baseDir, "src2/foo3.xoo").getAbsolutePath()).setLanguage("xoo");
+ DefaultInputFile inputFile1 = new DefaultInputFile("foo", "src/foo.xoo").setLanguage("xoo");
+ DefaultInputFile inputFile2 = new DefaultInputFile("foo", "src/foo2.xoo").setLanguage("xoo");
+ DefaultInputFile inputFile3 = new DefaultInputFile("foo", "src2/foo3.xoo").setLanguage("xoo");
fileSystem.add(inputFile1);
fileSystem.add(inputFile2);
fileSystem.add(inputFile3);
diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/MeasureSensorTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/MeasureSensorTest.java
index ade948848f7..6626a5e9545 100644
--- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/MeasureSensorTest.java
+++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/MeasureSensorTest.java
@@ -65,7 +65,7 @@ public class MeasureSensorTest {
baseDir = temp.newFolder();
metricFinder = mock(MetricFinder.class);
sensor = new MeasureSensor(metricFinder);
- fileSystem = new DefaultFileSystem(baseDir);
+ fileSystem = new DefaultFileSystem(baseDir.toPath());
when(context.fileSystem()).thenReturn(fileSystem);
storage = mock(SensorStorage.class);
when(context.newMeasure()).then(new Answer<DefaultMeasure>() {
@@ -83,7 +83,7 @@ public class MeasureSensorTest {
@Test
public void testNoExecutionIfNoMeasureFile() {
- DefaultInputFile inputFile = new DefaultInputFile("foo", "src/foo.xoo").setAbsolutePath(new File(baseDir, "src/foo.xoo").getAbsolutePath()).setLanguage("xoo");
+ DefaultInputFile inputFile = new DefaultInputFile("foo", "src/foo.xoo").setLanguage("xoo");
fileSystem.add(inputFile);
sensor.execute(context);
}
@@ -92,7 +92,7 @@ public class MeasureSensorTest {
public void testExecution() throws IOException {
File measures = new File(baseDir, "src/foo.xoo.measures");
FileUtils.write(measures, "ncloc:12\nbranch_coverage:5.3\nsqale_index:300\nbool:true\n\n#comment");
- DefaultInputFile inputFile = new DefaultInputFile("foo", "src/foo.xoo").setAbsolutePath(new File(baseDir, "src/foo.xoo").getAbsolutePath()).setLanguage("xoo");
+ DefaultInputFile inputFile = new DefaultInputFile("foo", "src/foo.xoo").setLanguage("xoo");
fileSystem.add(inputFile);
Metric<Boolean> booleanMetric = new Metric.Builder("bool", "Bool", Metric.ValueType.BOOL)
@@ -115,7 +115,7 @@ public class MeasureSensorTest {
public void failIfMetricNotFound() throws IOException {
File measures = new File(baseDir, "src/foo.xoo.measures");
FileUtils.write(measures, "unknow:12\n\n#comment");
- DefaultInputFile inputFile = new DefaultInputFile("foo", "src/foo.xoo").setAbsolutePath(new File(baseDir, "src/foo.xoo").getAbsolutePath()).setLanguage("xoo");
+ DefaultInputFile inputFile = new DefaultInputFile("foo", "src/foo.xoo").setLanguage("xoo");
fileSystem.add(inputFile);
thrown.expect(IllegalStateException.class);
diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SymbolReferencesSensorTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SymbolReferencesSensorTest.java
index 945253e72b0..5673221a46e 100644
--- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SymbolReferencesSensorTest.java
+++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SymbolReferencesSensorTest.java
@@ -52,7 +52,7 @@ public class SymbolReferencesSensorTest {
public void prepare() throws IOException {
baseDir = temp.newFolder();
sensor = new SymbolReferencesSensor();
- fileSystem = new DefaultFileSystem(baseDir);
+ fileSystem = new DefaultFileSystem(baseDir.toPath());
when(context.fileSystem()).thenReturn(fileSystem);
}
@@ -63,7 +63,7 @@ public class SymbolReferencesSensorTest {
@Test
public void testNoExecutionIfNoSymbolFile() {
- DefaultInputFile inputFile = new DefaultInputFile("foo", "src/foo.xoo").setAbsolutePath(new File(baseDir, "src/foo.xoo").getAbsolutePath()).setLanguage("xoo");
+ DefaultInputFile inputFile = new DefaultInputFile("foo", "src/foo.xoo").setLanguage("xoo");
fileSystem.add(inputFile);
sensor.execute(context);
}
@@ -72,7 +72,7 @@ public class SymbolReferencesSensorTest {
public void testExecution() throws IOException {
File symbol = new File(baseDir, "src/foo.xoo.symbol");
FileUtils.write(symbol, "1,4,7\n12,15,23\n\n#comment");
- DefaultInputFile inputFile = new DefaultInputFile("foo", "src/foo.xoo").setAbsolutePath(new File(baseDir, "src/foo.xoo").getAbsolutePath()).setLanguage("xoo");
+ DefaultInputFile inputFile = new DefaultInputFile("foo", "src/foo.xoo").setLanguage("xoo");
fileSystem.add(inputFile);
SymbolTableBuilder symbolTableBuilder = mock(SymbolTableBuilder.class);
when(context.symbolTableBuilder(inputFile)).thenReturn(symbolTableBuilder);
diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SyntaxHighlightingSensorTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SyntaxHighlightingSensorTest.java
index 75c5a1c6685..559f6b37b08 100644
--- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SyntaxHighlightingSensorTest.java
+++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SyntaxHighlightingSensorTest.java
@@ -52,7 +52,7 @@ public class SyntaxHighlightingSensorTest {
public void prepare() throws IOException {
baseDir = temp.newFolder();
sensor = new SyntaxHighlightingSensor();
- fileSystem = new DefaultFileSystem(baseDir);
+ fileSystem = new DefaultFileSystem(baseDir.toPath());
when(context.fileSystem()).thenReturn(fileSystem);
}
@@ -63,7 +63,7 @@ public class SyntaxHighlightingSensorTest {
@Test
public void testNoExecutionIfNoSyntaxFile() {
- DefaultInputFile inputFile = new DefaultInputFile("foo", "src/foo.xoo").setAbsolutePath(new File(baseDir, "src/foo.xoo").getAbsolutePath()).setLanguage("xoo");
+ DefaultInputFile inputFile = new DefaultInputFile("foo", "src/foo.xoo").setLanguage("xoo");
fileSystem.add(inputFile);
sensor.execute(context);
}
@@ -72,7 +72,7 @@ public class SyntaxHighlightingSensorTest {
public void testExecution() throws IOException {
File symbol = new File(baseDir, "src/foo.xoo.highlighting");
FileUtils.write(symbol, "1:4:k\n12:15:cppd\n\n#comment");
- DefaultInputFile inputFile = new DefaultInputFile("foo", "src/foo.xoo").setAbsolutePath(new File(baseDir, "src/foo.xoo").getAbsolutePath()).setLanguage("xoo");
+ DefaultInputFile inputFile = new DefaultInputFile("foo", "src/foo.xoo").setLanguage("xoo");
fileSystem.add(inputFile);
HighlightingBuilder builder = mock(HighlightingBuilder.class);
when(context.highlightingBuilder(inputFile)).thenReturn(builder);
diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/TestCaseSensorTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/TestCaseSensorTest.java
index 41109c800c4..5e1a1344f4e 100644
--- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/TestCaseSensorTest.java
+++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/TestCaseSensorTest.java
@@ -56,7 +56,7 @@ public class TestCaseSensorTest {
public void prepare() throws IOException {
baseDir = temp.newFolder();
sensor = new TestCaseSensor();
- fileSystem = new DefaultFileSystem(baseDir);
+ fileSystem = new DefaultFileSystem(baseDir.toPath());
when(context.fileSystem()).thenReturn(fileSystem);
}
@@ -67,7 +67,7 @@ public class TestCaseSensorTest {
@Test
public void testNoExecutionIfNoTestFile() {
- DefaultInputFile testFile = new DefaultInputFile("foo", "test/fooTest.xoo").setAbsolutePath(new File(baseDir, "test/fooTest.xoo").getAbsolutePath()).setLanguage("xoo")
+ DefaultInputFile testFile = new DefaultInputFile("foo", "test/fooTest.xoo").setLanguage("xoo")
.setType(Type.TEST);
fileSystem.add(testFile);
sensor.execute(context);
@@ -77,7 +77,7 @@ public class TestCaseSensorTest {
public void testExecution() throws IOException {
File testPlan = new File(baseDir, "test/fooTest.xoo.testplan");
FileUtils.write(testPlan, "test1:UNIT:OK:::10\ntest2:INTEGRATION:ERROR:message:stack:15\n\n#comment");
- DefaultInputFile testFile = new DefaultInputFile("foo", "test/fooTest.xoo").setAbsolutePath(new File(baseDir, "test/fooTest.xoo").getAbsolutePath()).setLanguage("xoo")
+ DefaultInputFile testFile = new DefaultInputFile("foo", "test/fooTest.xoo").setLanguage("xoo")
.setType(Type.TEST);
fileSystem.add(testFile);
diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/XooTokenizerSensorTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/XooTokenizerSensorTest.java
index 752f4144aba..1fe44615f9b 100644
--- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/XooTokenizerSensorTest.java
+++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/XooTokenizerSensorTest.java
@@ -57,7 +57,7 @@ public class XooTokenizerSensorTest {
public void prepare() throws IOException {
baseDir = temp.newFolder();
sensor = new XooTokenizerSensor();
- fileSystem = new DefaultFileSystem(baseDir);
+ fileSystem = new DefaultFileSystem(baseDir.toPath());
when(context.fileSystem()).thenReturn(fileSystem);
settings = new Settings();
when(context.settings()).thenReturn(settings);
@@ -70,7 +70,7 @@ public class XooTokenizerSensorTest {
@Test
public void testNoExecutionIfExclusion() {
- DefaultInputFile inputFile = new DefaultInputFile("foo", "src/foo.xoo").setAbsolutePath(new File(baseDir, "src/foo.xoo").getAbsolutePath()).setLanguage("xoo");
+ DefaultInputFile inputFile = new DefaultInputFile("foo", "src/foo.xoo").setLanguage("xoo");
fileSystem.add(inputFile);
settings.setProperty(CoreProperties.CPD_EXCLUSIONS, "**/foo.xoo");
sensor.execute(context);
@@ -81,7 +81,7 @@ public class XooTokenizerSensorTest {
public void testExecution() throws IOException {
File source = new File(baseDir, "src/foo.xoo");
FileUtils.write(source, "token1 token2 token3\ntoken4");
- DefaultInputFile inputFile = new DefaultInputFile("foo", "src/foo.xoo").setAbsolutePath(new File(baseDir, "src/foo.xoo").getAbsolutePath()).setLanguage("xoo");
+ DefaultInputFile inputFile = new DefaultInputFile("foo", "src/foo.xoo").setLanguage("xoo");
fileSystem.add(inputFile);
DuplicationTokenBuilder builder = mock(DuplicationTokenBuilder.class);
when(context.duplicationTokenBuilder(inputFile)).thenReturn(builder);
diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/OneIssuePerLineSensorTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/OneIssuePerLineSensorTest.java
index f283ffb0cd1..9f1a4436a0e 100644
--- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/OneIssuePerLineSensorTest.java
+++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/OneIssuePerLineSensorTest.java
@@ -60,7 +60,7 @@ public class OneIssuePerLineSensorTest {
@Test
public void testRule() throws IOException {
- DefaultFileSystem fs = new DefaultFileSystem(temp.newFolder());
+ DefaultFileSystem fs = new DefaultFileSystem(temp.newFolder().toPath());
DefaultInputFile inputFile = new DefaultInputFile("foo", "src/Foo.xoo").setLanguage(Xoo.KEY).setLines(10);
fs.add(inputFile);
@@ -84,7 +84,7 @@ public class OneIssuePerLineSensorTest {
@Test
public void testForceSeverity() throws IOException {
- DefaultFileSystem fs = new DefaultFileSystem(temp.newFolder());
+ DefaultFileSystem fs = new DefaultFileSystem(temp.newFolder().toPath());
DefaultInputFile inputFile = new DefaultInputFile("foo", "src/Foo.xoo").setLanguage(Xoo.KEY).setLines(10);
fs.add(inputFile);
diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/scm/XooBlameCommandTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/scm/XooBlameCommandTest.java
index d0156cc083d..eda682a7a43 100644
--- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/scm/XooBlameCommandTest.java
+++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/scm/XooBlameCommandTest.java
@@ -57,7 +57,7 @@ public class XooBlameCommandTest {
@Before
public void prepare() throws IOException {
baseDir = temp.newFolder();
- fs = new DefaultFileSystem(baseDir);
+ fs = new DefaultFileSystem(baseDir.toPath());
input = mock(BlameInput.class);
when(input.fileSystem()).thenReturn(fs);
}
@@ -68,7 +68,7 @@ public class XooBlameCommandTest {
FileUtils.write(source, "sample content");
File scm = new File(baseDir, "src/foo.xoo.scm");
FileUtils.write(scm, "123,julien,2014-12-12\n234,julien,2014-12-24");
- DefaultInputFile inputFile = new DefaultInputFile("foo", "src/foo.xoo").setAbsolutePath(new File(baseDir, "src/foo.xoo").getAbsolutePath()).setLanguage(Xoo.KEY);
+ DefaultInputFile inputFile = new DefaultInputFile("foo", "src/foo.xoo").setLanguage(Xoo.KEY);
fs.add(inputFile);
BlameOutput result = mock(BlameOutput.class);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueNotificationsTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueNotificationsTest.java
index fb3177cd528..937da1b1398 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueNotificationsTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueNotificationsTest.java
@@ -166,3 +166,4 @@
// Mockito.verifyZeroInteractions(manager);
// }
//}
+
diff --git a/sonar-batch/pom.xml b/sonar-batch/pom.xml
index a06d4d36ed6..d96777a8b16 100644
--- a/sonar-batch/pom.xml
+++ b/sonar-batch/pom.xml
@@ -28,6 +28,7 @@
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-persistit</artifactId>
</dependency>
+
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-core</artifactId>
diff --git a/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java b/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java
index b345f2e1b0a..21dd83e51ab 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java
@@ -41,6 +41,10 @@ import java.util.Date;
import static org.sonar.api.utils.DateUtils.formatDateTime;
import static org.sonar.api.utils.DateUtils.longToDate;
+/**
+ * Used by views !!
+ *
+ */
public class ProjectConfigurator implements BatchComponent {
private static final Logger LOG = LoggerFactory.getLogger(ProjectConfigurator.class);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java
index f55308c348c..80525697653 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java
@@ -19,6 +19,14 @@
*/
package org.sonar.batch.bootstrap;
+import org.sonar.batch.components.PastSnapshotFinder;
+
+import org.sonar.batch.deprecated.components.PastSnapshotFinderByDate;
+import org.sonar.batch.deprecated.components.PastSnapshotFinderByDays;
+import org.sonar.batch.deprecated.components.PastSnapshotFinderByPreviousAnalysis;
+import org.sonar.batch.deprecated.components.PastSnapshotFinderByPreviousVersion;
+import org.sonar.batch.deprecated.components.PastSnapshotFinderByVersion;
+import org.sonar.batch.repository.user.UserRepository;
import org.sonar.api.Plugin;
import org.sonar.api.config.EmailSettings;
import org.sonar.api.platform.ComponentContainer;
@@ -28,12 +36,6 @@ import org.sonar.api.utils.HttpDownloader;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.UriReader;
import org.sonar.api.utils.internal.TempFolderCleaner;
-import org.sonar.batch.components.PastSnapshotFinder;
-import org.sonar.batch.components.PastSnapshotFinderByDate;
-import org.sonar.batch.components.PastSnapshotFinderByDays;
-import org.sonar.batch.components.PastSnapshotFinderByPreviousAnalysis;
-import org.sonar.batch.components.PastSnapshotFinderByPreviousVersion;
-import org.sonar.batch.components.PastSnapshotFinderByVersion;
import org.sonar.batch.platform.DefaultServer;
import org.sonar.batch.repository.DefaultGlobalRepositoriesLoader;
import org.sonar.batch.repository.DefaultPreviousIssuesLoader;
@@ -42,7 +44,6 @@ import org.sonar.batch.repository.GlobalRepositoriesLoader;
import org.sonar.batch.repository.GlobalRepositoriesProvider;
import org.sonar.batch.repository.PreviousIssuesLoader;
import org.sonar.batch.repository.ProjectRepositoriesLoader;
-import org.sonar.batch.user.UserRepository;
import org.sonar.core.cluster.NullQueue;
import org.sonar.core.config.Logback;
import org.sonar.core.i18n.DefaultI18n;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TaskContainer.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TaskContainer.java
index d301f1aa476..b3fd7e46392 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TaskContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TaskContainer.java
@@ -19,6 +19,8 @@
*/
package org.sonar.batch.bootstrap;
+import org.sonar.batch.components.PastMeasuresLoader;
+
import org.apache.commons.lang.StringUtils;
import org.sonar.api.CoreProperties;
import org.sonar.api.platform.ComponentContainer;
@@ -28,19 +30,21 @@ import org.sonar.api.task.TaskComponent;
import org.sonar.api.task.TaskDefinition;
import org.sonar.api.utils.MessageException;
import org.sonar.batch.bootstrapper.EnvironmentInformation;
-import org.sonar.batch.components.PastMeasuresLoader;
+import org.sonar.batch.deprecated.tasks.ListTask;
+import org.sonar.batch.deprecated.tasks.Tasks;
import org.sonar.batch.scan.DeprecatedProjectReactorBuilder;
import org.sonar.batch.scan.ProjectReactorBuilder;
import org.sonar.batch.scan.ScanTask;
import org.sonar.batch.scan.measure.DefaultMetricFinder;
import org.sonar.batch.scan.measure.DeprecatedMetricFinder;
-import org.sonar.batch.tasks.ListTask;
-import org.sonar.batch.tasks.Tasks;
import org.sonar.core.permission.PermissionFacade;
import org.sonar.core.resource.DefaultResourcePermissions;
import java.util.Map;
+/**
+ * Used by views !!
+ */
public class TaskContainer extends ComponentContainer {
private final Map<String, String> taskProperties;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastMeasuresLoader.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastMeasuresLoader.java
index 6cfd61dcabe..d969e172338 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/components/PastMeasuresLoader.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastMeasuresLoader.java
@@ -38,6 +38,9 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
+/**
+ * Can't be moved. Used by devcockpit.
+ */
public class PastMeasuresLoader implements BatchComponent {
private Map<Integer, Metric> metricByIds;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshot.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshot.java
index 48955f9738f..a85eb172cf7 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshot.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshot.java
@@ -26,11 +26,15 @@ import org.sonar.api.database.model.Snapshot;
import org.sonar.api.utils.DateUtils;
import javax.annotation.Nullable;
+
import java.util.Calendar;
import java.util.Date;
import static org.sonar.api.utils.DateUtils.longToDate;
+/**
+ * Used by devcockpit
+ */
public class PastSnapshot {
private int index;
@@ -96,7 +100,7 @@ public class PastSnapshot {
return this;
}
- Integer getProjectSnapshotId() {
+ public Integer getProjectSnapshotId() {
return projectSnapshot != null ? projectSnapshot.getId() : null;
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinder.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinder.java
index 56263637b14..745dcbf817b 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinder.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinder.java
@@ -27,6 +27,11 @@ import org.sonar.api.BatchExtension;
import org.sonar.api.CoreProperties;
import org.sonar.api.config.Settings;
import org.sonar.api.database.model.Snapshot;
+import org.sonar.batch.deprecated.components.PastSnapshotFinderByDate;
+import org.sonar.batch.deprecated.components.PastSnapshotFinderByDays;
+import org.sonar.batch.deprecated.components.PastSnapshotFinderByPreviousAnalysis;
+import org.sonar.batch.deprecated.components.PastSnapshotFinderByPreviousVersion;
+import org.sonar.batch.deprecated.components.PastSnapshotFinderByVersion;
import javax.annotation.Nullable;
@@ -34,6 +39,9 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
+/**
+ * Can't be moved since it is used by devcockpit.
+ */
public class PastSnapshotFinder implements BatchExtension {
private static final Logger LOG = LoggerFactory.getLogger(PastSnapshotFinder.class);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java b/sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java
index 2d4c71bc9c1..ec346aa4dcc 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java
@@ -27,8 +27,11 @@ import org.sonar.api.batch.RequiresDB;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.Qualifiers;
+import org.sonar.batch.deprecated.components.Period;
+import org.sonar.batch.deprecated.components.PeriodsDefinition;
import javax.annotation.CheckForNull;
+
import java.util.List;
import static com.google.common.collect.Lists.newLinkedList;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/debt/NewDebtDecorator.java b/sonar-batch/src/main/java/org/sonar/batch/debt/NewDebtDecorator.java
index 43046d3763b..452fe02551c 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/debt/NewDebtDecorator.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/debt/NewDebtDecorator.java
@@ -20,6 +20,9 @@
package org.sonar.batch.debt;
+import org.sonar.batch.components.TimeMachineConfiguration;
+
+import org.sonar.batch.deprecated.components.Period;
import com.google.common.collect.ImmutableList;
import org.sonar.api.batch.Decorator;
import org.sonar.api.batch.DecoratorBarriers;
@@ -35,8 +38,6 @@ import org.sonar.api.measures.MeasureUtils;
import org.sonar.api.measures.Metric;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
-import org.sonar.batch.components.Period;
-import org.sonar.batch.components.TimeMachineConfiguration;
import javax.annotation.Nullable;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/DeprecatedSensorContext.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/DeprecatedSensorContext.java
index 49998b1d2f7..e02cadce624 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/DeprecatedSensorContext.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/deprecated/DeprecatedSensorContext.java
@@ -17,7 +17,7 @@
* 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.batch;
+package org.sonar.batch.deprecated;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/ResourceFilters.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/ResourceFilters.java
index 8680300a412..f60713506d7 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/ResourceFilters.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/deprecated/ResourceFilters.java
@@ -17,7 +17,7 @@
* 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.batch;
+package org.sonar.batch.deprecated;
import com.google.common.base.Joiner;
import org.slf4j.Logger;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/DefaultProjectClasspath.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/DefaultProjectClasspath.java
index d497906439f..f5a07c9889c 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/DefaultProjectClasspath.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/DefaultProjectClasspath.java
@@ -17,7 +17,7 @@
* 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.batch;
+package org.sonar.batch.deprecated.components;
import com.google.common.collect.Lists;
import org.apache.maven.project.MavenProject;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/DefaultResourceCreationLock.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/DefaultResourceCreationLock.java
index 1adb5074e64..52ca67c348e 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/DefaultResourceCreationLock.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/DefaultResourceCreationLock.java
@@ -17,7 +17,7 @@
* 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.batch;
+package org.sonar.batch.deprecated.components;
import org.sonar.api.batch.ResourceCreationLock;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/DefaultTimeMachine.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/DefaultTimeMachine.java
index 79d61dd2f74..460f3a647c4 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/DefaultTimeMachine.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/DefaultTimeMachine.java
@@ -17,7 +17,7 @@
* 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.batch;
+package org.sonar.batch.deprecated.components;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDate.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDate.java
index fbae4382e43..5a5fff138a1 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDate.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDate.java
@@ -17,7 +17,7 @@
* 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.batch.components;
+package org.sonar.batch.deprecated.components;
import org.sonar.api.BatchExtension;
import org.sonar.api.CoreProperties;
@@ -25,8 +25,10 @@ import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.utils.DateUtils;
+import org.sonar.batch.components.PastSnapshot;
import javax.annotation.CheckForNull;
+
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@@ -41,7 +43,7 @@ public class PastSnapshotFinderByDate implements BatchExtension {
this.session = session;
}
- PastSnapshot findByDate(Snapshot projectSnapshot, Date date) {
+ public PastSnapshot findByDate(Snapshot projectSnapshot, Date date) {
Integer projectId = projectSnapshot != null ? projectSnapshot.getResourceId() : null;
return findByDate(projectId, date);
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDays.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDays.java
index 0f802682c8a..5183236cc05 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDays.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDays.java
@@ -17,7 +17,7 @@
* 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.batch.components;
+package org.sonar.batch.deprecated.components;
import org.apache.commons.lang.time.DateUtils;
import org.sonar.api.BatchExtension;
@@ -25,8 +25,10 @@ import org.sonar.api.CoreProperties;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.Qualifiers;
+import org.sonar.batch.components.PastSnapshot;
import javax.annotation.CheckForNull;
+
import java.util.Date;
import java.util.List;
@@ -40,7 +42,7 @@ public class PastSnapshotFinderByDays implements BatchExtension {
this.session = session;
}
- PastSnapshot findFromDays(Snapshot projectSnapshot, int days) {
+ public PastSnapshot findFromDays(Snapshot projectSnapshot, int days) {
Date targetDate = DateUtils.addDays(longToDate(projectSnapshot.getCreatedAtMs()), -days);
String hql = "from " + Snapshot.class.getSimpleName() + " where resourceId=:resourceId AND status=:status AND createdAt<:date AND qualifier<>:lib order by createdAt asc";
List<Snapshot> snapshots = session.createQuery(hql)
diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysis.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousAnalysis.java
index 506295775ef..e770975d461 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysis.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousAnalysis.java
@@ -17,7 +17,7 @@
* 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.batch.components;
+package org.sonar.batch.deprecated.components;
import org.sonar.api.BatchExtension;
import org.sonar.api.CoreProperties;
@@ -25,6 +25,7 @@ import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.utils.DateUtils;
+import org.sonar.batch.components.PastSnapshot;
import java.text.SimpleDateFormat;
import java.util.Date;
@@ -40,17 +41,17 @@ public class PastSnapshotFinderByPreviousAnalysis implements BatchExtension {
this.session = session;
}
- PastSnapshot findByPreviousAnalysis(Snapshot projectSnapshot) {
+ public PastSnapshot findByPreviousAnalysis(Snapshot projectSnapshot) {
String hql = "from " + Snapshot.class.getSimpleName()
- + " where createdAt<:date AND resourceId=:resourceId AND status=:status and last=:last and qualifier<>:lib order by createdAt desc";
+ + " where createdAt<:date AND resourceId=:resourceId AND status=:status and last=:last and qualifier<>:lib order by createdAt desc";
List<Snapshot> snapshots = session.createQuery(hql)
- .setParameter("date", projectSnapshot.getCreatedAtMs())
- .setParameter("resourceId", projectSnapshot.getResourceId())
- .setParameter("status", Snapshot.STATUS_PROCESSED)
- .setParameter("last", true)
- .setParameter("lib", Qualifiers.LIBRARY)
- .setMaxResults(1)
- .getResultList();
+ .setParameter("date", projectSnapshot.getCreatedAtMs())
+ .setParameter("resourceId", projectSnapshot.getResourceId())
+ .setParameter("status", Snapshot.STATUS_PROCESSED)
+ .setParameter("last", true)
+ .setParameter("lib", Qualifiers.LIBRARY)
+ .setMaxResults(1)
+ .getResultList();
if (snapshots.isEmpty()) {
return new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousVersion.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersion.java
index 6437688bf68..0125fa7d4d7 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousVersion.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersion.java
@@ -17,7 +17,9 @@
* 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.batch.components;
+package org.sonar.batch.deprecated.components;
+
+import org.sonar.batch.components.PastSnapshot;
import org.sonar.api.BatchExtension;
import org.sonar.api.CoreProperties;
@@ -37,7 +39,7 @@ public class PastSnapshotFinderByPreviousVersion implements BatchExtension {
this.session = session;
}
- PastSnapshot findByPreviousVersion(Snapshot projectSnapshot) {
+ public PastSnapshot findByPreviousVersion(Snapshot projectSnapshot) {
String currentVersion = projectSnapshot.getVersion();
Integer resourceId = projectSnapshot.getResourceId();
@@ -45,10 +47,10 @@ public class PastSnapshotFinderByPreviousVersion implements BatchExtension {
" where name<>:version AND category='Version' AND resourceId=:resourceId ORDER BY date DESC";
List<Event> events = session.createQuery(hql)
- .setParameter("version", currentVersion)
- .setParameter("resourceId", resourceId)
- .setMaxResults(1)
- .getResultList();
+ .setParameter("version", currentVersion)
+ .setParameter("resourceId", resourceId)
+ .setMaxResults(1)
+ .getResultList();
if (events.isEmpty()) {
return new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByVersion.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByVersion.java
index 161bd87b2ee..c6f5423ffab 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByVersion.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByVersion.java
@@ -17,7 +17,9 @@
* 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.batch.components;
+package org.sonar.batch.deprecated.components;
+
+import org.sonar.batch.components.PastSnapshot;
import org.sonar.api.BatchExtension;
import org.sonar.api.CoreProperties;
@@ -38,15 +40,15 @@ public class PastSnapshotFinderByVersion implements BatchExtension {
this.session = session;
}
- PastSnapshot findByVersion(Snapshot projectSnapshot, String version) {
+ public PastSnapshot findByVersion(Snapshot projectSnapshot, String version) {
String hql = "from " + Snapshot.class.getSimpleName() + " where version=:version AND resourceId=:resourceId AND status=:status AND qualifier<>:lib order by createdAt desc";
List<Snapshot> snapshots = session.createQuery(hql)
- .setParameter("version", version)
- .setParameter("resourceId", projectSnapshot.getResourceId())
- .setParameter("status", Snapshot.STATUS_PROCESSED)
- .setParameter("lib", Qualifiers.LIBRARY)
- .setMaxResults(1)
- .getResultList();
+ .setParameter("version", version)
+ .setParameter("resourceId", projectSnapshot.getResourceId())
+ .setParameter("status", Snapshot.STATUS_PROCESSED)
+ .setParameter("lib", Qualifiers.LIBRARY)
+ .setMaxResults(1)
+ .getResultList();
PastSnapshot result;
if (snapshots.isEmpty()) {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/Period.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/Period.java
index 4e2f15e88b9..45ca282dd42 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/components/Period.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/Period.java
@@ -18,7 +18,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-package org.sonar.batch.components;
+package org.sonar.batch.deprecated.components;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PeriodsDefinition.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PeriodsDefinition.java
index 6f1eb16a5bc..b235129693f 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/components/PeriodsDefinition.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PeriodsDefinition.java
@@ -18,7 +18,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-package org.sonar.batch.components;
+package org.sonar.batch.deprecated.components;
import org.sonar.api.BatchComponent;
import org.sonar.api.config.Settings;
@@ -26,6 +26,8 @@ import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.Qualifiers;
import org.sonar.batch.ProjectTree;
+import org.sonar.batch.components.PastSnapshot;
+import org.sonar.batch.components.PastSnapshotFinder;
import javax.persistence.Query;
import java.util.List;
@@ -46,7 +48,7 @@ public class PeriodsDefinition implements BatchComponent {
private List<PastSnapshot> projectPastSnapshots;
public PeriodsDefinition(DatabaseSession session, ProjectTree projectTree, Settings settings,
- PastSnapshotFinder pastSnapshotFinder) {
+ PastSnapshotFinder pastSnapshotFinder) {
this.session = session;
this.projectTree = projectTree;
this.settings = settings;
@@ -89,7 +91,7 @@ public class PeriodsDefinition implements BatchComponent {
/**
* @return past snapshots of root project
*/
- List<PastSnapshot> getRootProjectPastSnapshots() {
+ public List<PastSnapshot> getRootProjectPastSnapshots() {
return projectPastSnapshots;
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/package-info.java
new file mode 100644
index 00000000000..65baa1e8409
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.batch.deprecated.components;
+
+import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/DecoratorsSelector.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/decorator/DecoratorsSelector.java
index 7ce661aaa79..c50574fb637 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/DecoratorsSelector.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/deprecated/decorator/DecoratorsSelector.java
@@ -17,7 +17,7 @@
* 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.batch;
+package org.sonar.batch.deprecated.decorator;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.SetMultimap;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/DefaultDecoratorContext.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/decorator/DefaultDecoratorContext.java
index 3d18e06c5a9..1740a1aebd9 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/DefaultDecoratorContext.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/deprecated/decorator/DefaultDecoratorContext.java
@@ -17,7 +17,7 @@
* 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.batch;
+package org.sonar.batch.deprecated.decorator;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/FormulaDecorator.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/decorator/FormulaDecorator.java
index 75de88257d8..8b60efcaf19 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/FormulaDecorator.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/deprecated/decorator/FormulaDecorator.java
@@ -17,7 +17,7 @@
* 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.batch;
+package org.sonar.batch.deprecated.decorator;
import org.sonar.api.batch.*;
import org.sonar.api.measures.FormulaData;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/tasks/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/package-info.java
index 0f2b4e035bb..ca1dcada4ba 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/tasks/package-info.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/deprecated/package-info.java
@@ -18,6 +18,6 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@ParametersAreNonnullByDefault
-package org.sonar.batch.tasks;
+package org.sonar.batch.deprecated;
import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/tasks/ListTask.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/tasks/ListTask.java
index 93a0419b32f..bcd02a00e3b 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/tasks/ListTask.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/deprecated/tasks/ListTask.java
@@ -17,7 +17,7 @@
* 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.batch.tasks;
+package org.sonar.batch.deprecated.tasks;
import org.sonar.api.task.Task;
import org.sonar.api.task.TaskDefinition;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/tasks/Tasks.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/tasks/Tasks.java
index f68fb691269..c97bdea7d6a 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/tasks/Tasks.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/deprecated/tasks/Tasks.java
@@ -17,7 +17,7 @@
* 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.batch.tasks;
+package org.sonar.batch.deprecated.tasks;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.Maps;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/deprecated/tasks/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/tasks/package-info.java
new file mode 100644
index 00000000000..f346de52eb4
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/deprecated/tasks/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.batch.deprecated.tasks;
+
+import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java
index eeb37de63ed..6cf8ae826f4 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java
@@ -38,7 +38,6 @@ import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
import org.sonar.api.measures.MeasuresFilter;
import org.sonar.api.measures.MeasuresFilters;
-import org.sonar.api.resources.Directory;
import org.sonar.api.resources.File;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.ProjectLink;
@@ -107,7 +106,6 @@ public class DefaultIndex extends SonarIndex {
// caches
private Project currentProject;
private Map<Resource, Bucket> buckets = Maps.newLinkedHashMap();
- private Map<String, Bucket> bucketsByDeprecatedKey = Maps.newLinkedHashMap();
private Set<Dependency> dependencies = Sets.newLinkedHashSet();
private Map<Resource, Map<Resource, Dependency>> outgoingDependenciesByResource = Maps.newLinkedHashMap();
private Map<Resource, Map<Resource, Dependency>> incomingDependenciesByResource = Maps.newLinkedHashMap();
@@ -166,9 +164,6 @@ public class DefaultIndex extends SonarIndex {
private void addBucket(Resource resource, Bucket bucket) {
buckets.put(resource, bucket);
- if (StringUtils.isNotBlank(resource.getDeprecatedKey())) {
- bucketsByDeprecatedKey.put(resource.getDeprecatedKey(), bucket);
- }
}
private void addModule(Project parent, Project module) {
@@ -613,12 +608,6 @@ public class DefaultIndex extends SonarIndex {
return getBucket(reference) != null;
}
- /**
- * Should support 2 situations
- * 1) key = new key and deprecatedKey = old key : this is the standard use case in a perfect world
- * 2) key = null and deprecatedKey = oldKey : this is for plugins that are using deprecated constructors of
- * {@link File} and {@link Directory}
- */
private Bucket getBucket(@Nullable Resource reference) {
if (reference == null) {
return null;
@@ -626,17 +615,6 @@ public class DefaultIndex extends SonarIndex {
if (StringUtils.isNotBlank(reference.getKey())) {
return buckets.get(reference);
}
- if (StringUtils.isNotBlank(reference.getDeprecatedKey())) {
- // Fallback to use deprecated key
- Bucket bucket = bucketsByDeprecatedKey.get(reference.getDeprecatedKey());
- if (bucket != null) {
- // Fix reference resource
- reference.setKey(bucket.getResource().getKey());
- reference.setPath(bucket.getResource().getPath());
- LOG.debug("Resource {} was found using deprecated key. Please update your plugin.", reference);
- return bucket;
- }
- }
return null;
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/ResourceKeyMigration.java b/sonar-batch/src/main/java/org/sonar/batch/index/ResourceKeyMigration.java
index 0cb5a0b182d..69b7dd98d85 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/ResourceKeyMigration.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/ResourceKeyMigration.java
@@ -24,20 +24,21 @@ import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.BatchComponent;
-import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DeprecatedDefaultInputFile;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.ResourceModel;
import org.sonar.api.resources.Directory;
-import org.sonar.api.resources.File;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Qualifiers;
-import org.sonar.api.resources.Resource;
import org.sonar.api.resources.Scopes;
+import org.sonar.api.scan.filesystem.PathResolver;
import org.sonar.api.utils.PathUtils;
+import org.sonar.batch.scan.filesystem.DefaultModuleFileSystem;
import org.sonar.batch.util.DeprecatedKeyUtils;
+import javax.annotation.CheckForNull;
+
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -48,17 +49,19 @@ public class ResourceKeyMigration implements BatchComponent {
private static final String COMPONENT_CHANGED_TO = "Component {} changed to {}";
private final Logger logger;
private final DatabaseSession session;
+ private final PathResolver pathResolver;
private boolean migrationNeeded = false;
- public ResourceKeyMigration(DatabaseSession session) {
- this(session, LoggerFactory.getLogger(ResourceKeyMigration.class));
+ public ResourceKeyMigration(DatabaseSession session, PathResolver pathResolver) {
+ this(session, pathResolver, LoggerFactory.getLogger(ResourceKeyMigration.class));
}
@VisibleForTesting
- ResourceKeyMigration(DatabaseSession session, Logger logger) {
+ ResourceKeyMigration(DatabaseSession session, PathResolver pathResolver, Logger logger) {
this.session = session;
this.logger = logger;
+ this.pathResolver = pathResolver;
}
public void checkIfMigrationNeeded(Project rootProject) {
@@ -68,19 +71,19 @@ public class ResourceKeyMigration implements BatchComponent {
}
}
- public void migrateIfNeeded(Project module, FileSystem fs) {
+ public void migrateIfNeeded(Project module, DefaultModuleFileSystem fs) {
if (migrationNeeded) {
- migrateIfNeeded(module, fs.inputFiles(fs.predicates().all()));
+ migrateIfNeeded(module, fs.inputFiles(fs.predicates().all()), fs);
}
}
- void migrateIfNeeded(Project module, Iterable<InputFile> inputFiles) {
+ void migrateIfNeeded(Project module, Iterable<InputFile> inputFiles, DefaultModuleFileSystem fs) {
logger.info("Update component keys");
Map<String, InputFile> deprecatedFileKeyMapper = new HashMap<String, InputFile>();
Map<String, InputFile> deprecatedTestKeyMapper = new HashMap<String, InputFile>();
Map<String, String> deprecatedDirectoryKeyMapper = new HashMap<String, String>();
for (InputFile inputFile : inputFiles) {
- String deprecatedKey = ((DeprecatedDefaultInputFile) inputFile).deprecatedKey();
+ String deprecatedKey = computeDeprecatedKey(module.getKey(), (DeprecatedDefaultInputFile) inputFile, fs);
if (deprecatedKey != null) {
if (InputFile.Type.TEST == inputFile.type() && !deprecatedTestKeyMapper.containsKey(deprecatedKey)) {
deprecatedTestKeyMapper.put(deprecatedKey, inputFile);
@@ -97,6 +100,23 @@ public class ResourceKeyMigration implements BatchComponent {
session.commit();
}
+ @CheckForNull
+ private String computeDeprecatedKey(String moduleKey, DeprecatedDefaultInputFile inputFile, DefaultModuleFileSystem fs) {
+ List<java.io.File> sourceDirs = InputFile.Type.MAIN == inputFile.type() ? fs.sourceDirs() : fs.testDirs();
+ for (java.io.File sourceDir : sourceDirs) {
+ String sourceRelativePath = pathResolver.relativePath(sourceDir, inputFile.file());
+ if (sourceRelativePath != null) {
+ if ("java".equals(inputFile.language())) {
+ return new StringBuilder()
+ .append(moduleKey).append(":").append(DeprecatedKeyUtils.getJavaFileDeprecatedKey(sourceRelativePath)).toString();
+ } else {
+ return new StringBuilder().append(moduleKey).append(":").append(sourceRelativePath).toString();
+ }
+ }
+ }
+ return null;
+ }
+
private void migrateFiles(Project module, Map<String, InputFile> deprecatedFileKeyMapper, Map<String, InputFile> deprecatedTestKeyMapper,
Map<String, String> deprecatedDirectoryKeyMapper,
int moduleId) {
@@ -113,13 +133,11 @@ public class ResourceKeyMigration implements BatchComponent {
String newEffectiveKey = ((DeprecatedDefaultInputFile) matchedFile).key();
// Now compute migration of the parent dir
String oldKey = StringUtils.substringAfterLast(oldEffectiveKey, ":");
- Resource sonarFile;
String parentOldKey;
if ("java".equals(resourceModel.getLanguageKey())) {
parentOldKey = String.format("%s:%s", module.getEffectiveKey(), DeprecatedKeyUtils.getJavaFileParentDeprecatedKey(oldKey));
} else {
- sonarFile = new File(oldKey);
- parentOldKey = String.format("%s:%s", module.getEffectiveKey(), sonarFile.getParent().getDeprecatedKey());
+ parentOldKey = String.format("%s:%s", module.getEffectiveKey(), oldParentKey(oldKey));
}
String parentNewKey = String.format("%s:%s", module.getEffectiveKey(), getParentKey(matchedFile));
if (!deprecatedDirectoryKeyMapper.containsKey(parentOldKey)) {
@@ -137,6 +155,18 @@ public class ResourceKeyMigration implements BatchComponent {
}
}
+ private String oldParentKey(String oldKey) {
+ String cleanKey = StringUtils.trim(oldKey.replace('\\', '/'));
+ if (cleanKey.indexOf(Directory.SEPARATOR) >= 0) {
+ String oldParentKey = Directory.parseKey(StringUtils.substringBeforeLast(oldKey, Directory.SEPARATOR));
+ oldParentKey = StringUtils.removeStart(oldParentKey, Directory.SEPARATOR);
+ oldParentKey = StringUtils.removeEnd(oldParentKey, Directory.SEPARATOR);
+ return oldParentKey;
+ } else {
+ return Directory.ROOT;
+ }
+ }
+
private void updateKey(ResourceModel resourceModel, String newEffectiveKey, Map<String, ResourceModel> disabledResourceByKey) {
// Look for disabled resource with conflicting key
if (disabledResourceByKey.containsKey(newEffectiveKey)) {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/SourceDataFactory.java b/sonar-batch/src/main/java/org/sonar/batch/index/SourceDataFactory.java
index e3e9f33bc79..9a089eaef97 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/SourceDataFactory.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/SourceDataFactory.java
@@ -35,6 +35,7 @@ import org.sonar.api.utils.KeyValueFormat;
import org.sonar.batch.duplication.DuplicationCache;
import org.sonar.batch.highlighting.SyntaxHighlightingData;
import org.sonar.batch.highlighting.SyntaxHighlightingRule;
+import org.sonar.batch.scan.filesystem.InputFileMetadata;
import org.sonar.batch.scan.measure.MeasureCache;
import org.sonar.batch.source.CodeColorizers;
import org.sonar.batch.symbol.SymbolData;
@@ -72,18 +73,18 @@ public class SourceDataFactory implements BatchComponent {
this.codeColorizers = codeColorizers;
}
- public byte[] consolidateData(DefaultInputFile inputFile) throws IOException {
+ public byte[] consolidateData(DefaultInputFile inputFile, InputFileMetadata metadata) throws IOException {
FileSourceDb.Data.Builder dataBuilder = createForSource(inputFile);
applyLineMeasures(inputFile, dataBuilder);
applyDuplications(inputFile.key(), dataBuilder);
- applyHighlighting(inputFile, dataBuilder);
- applySymbolReferences(inputFile, dataBuilder);
+ applyHighlighting(inputFile, metadata, dataBuilder);
+ applySymbolReferences(inputFile, metadata, dataBuilder);
return FileSourceDto.encodeData(dataBuilder.build());
}
FileSourceDb.Data.Builder createForSource(DefaultInputFile inputFile) throws IOException {
FileSourceDb.Data.Builder result = FileSourceDb.Data.newBuilder();
- List<String> lines = FileUtils.readLines(inputFile.file(), inputFile.encoding());
+ List<String> lines = FileUtils.readLines(inputFile.file(), inputFile.charset());
// Missing empty last line
if (lines.size() == inputFile.lines() - 1) {
lines.add("");
@@ -191,11 +192,11 @@ public class SourceDataFactory implements BatchComponent {
void apply(String value, FileSourceDb.Line.Builder lineBuilder);
}
- void applyHighlighting(DefaultInputFile inputFile, FileSourceDb.Data.Builder to) {
+ void applyHighlighting(DefaultInputFile inputFile, InputFileMetadata metadata, FileSourceDb.Data.Builder to) {
SyntaxHighlightingData highlighting = componentDataCache.getData(inputFile.key(), SnapshotDataTypes.SYNTAX_HIGHLIGHTING);
String language = inputFile.language();
if (highlighting == null && language != null) {
- highlighting = codeColorizers.toSyntaxHighlighting(inputFile.file(), inputFile.encoding(), language);
+ highlighting = codeColorizers.toSyntaxHighlighting(inputFile.file(), inputFile.charset(), language);
}
if (highlighting == null) {
return;
@@ -204,12 +205,12 @@ public class SourceDataFactory implements BatchComponent {
RuleItemWriter ruleItemWriter = new RuleItemWriter();
int currentLineIdx = 1;
for (SyntaxHighlightingRule rule : highlighting.syntaxHighlightingRuleSet()) {
- while (currentLineIdx < inputFile.lines() && rule.getStartPosition() >= inputFile.originalLineOffsets()[currentLineIdx]) {
+ while (currentLineIdx < inputFile.lines() && rule.getStartPosition() >= metadata.originalLineOffsets()[currentLineIdx]) {
// This rule starts on another line so advance
currentLineIdx++;
}
// Now we know current rule starts on current line
- writeDataPerLine(inputFile.originalLineOffsets(), rule, rule.getStartPosition(), rule.getEndPosition(), highlightingPerLine, currentLineIdx, ruleItemWriter);
+ writeDataPerLine(metadata.originalLineOffsets(), rule, rule.getStartPosition(), rule.getEndPosition(), highlightingPerLine, currentLineIdx, ruleItemWriter);
}
for (int i = 0; i < highlightingPerLine.length; i++) {
StringBuilder sb = highlightingPerLine[i];
@@ -219,7 +220,7 @@ public class SourceDataFactory implements BatchComponent {
}
}
- void applySymbolReferences(DefaultInputFile file, FileSourceDb.Data.Builder to) {
+ void applySymbolReferences(DefaultInputFile file, InputFileMetadata metadata, FileSourceDb.Data.Builder to) {
SymbolData symbolRefs = componentDataCache.getData(file.key(), SnapshotDataTypes.SYMBOL_HIGHLIGHTING);
if (symbolRefs != null) {
StringBuilder[] refsPerLine = new StringBuilder[file.lines()];
@@ -236,13 +237,13 @@ public class SourceDataFactory implements BatchComponent {
int declarationStartOffset = symbol.getDeclarationStartOffset();
int declarationEndOffset = symbol.getDeclarationEndOffset();
int length = declarationEndOffset - declarationStartOffset;
- addSymbol(symbolId, declarationStartOffset, declarationEndOffset, file.originalLineOffsets(), refsPerLine);
+ addSymbol(symbolId, declarationStartOffset, declarationEndOffset, metadata.originalLineOffsets(), refsPerLine);
for (Integer referenceStartOffset : symbolRefs.referencesBySymbol().get(symbol)) {
if (referenceStartOffset == declarationStartOffset) {
// Ignore old API that used to store reference as first declaration
continue;
}
- addSymbol(symbolId, referenceStartOffset, referenceStartOffset + length, file.originalLineOffsets(), refsPerLine);
+ addSymbol(symbolId, referenceStartOffset, referenceStartOffset + length, metadata.originalLineOffsets(), refsPerLine);
}
symbolId++;
}
@@ -255,12 +256,12 @@ public class SourceDataFactory implements BatchComponent {
}
}
- private void addSymbol(int symbolId, int startOffset, int endOffset, long[] originalLineOffsets, StringBuilder[] result) {
+ private void addSymbol(int symbolId, int startOffset, int endOffset, int[] originalLineOffsets, StringBuilder[] result) {
int startLine = binarySearchLine(startOffset, originalLineOffsets);
writeDataPerLine(originalLineOffsets, symbolId, startOffset, endOffset, result, startLine, new SymbolItemWriter());
}
- private int binarySearchLine(int declarationStartOffset, long[] originalLineOffsets) {
+ private int binarySearchLine(int declarationStartOffset, int[] originalLineOffsets) {
int begin = 0;
int end = originalLineOffsets.length - 1;
while (begin < end) {
@@ -274,7 +275,7 @@ public class SourceDataFactory implements BatchComponent {
return begin + 1;
}
- private <G> void writeDataPerLine(long[] originalLineOffsets, G item, int globalStartOffset, int globalEndOffset, StringBuilder[] dataPerLine, int startLine,
+ private <G> void writeDataPerLine(int[] originalLineOffsets, G item, int globalStartOffset, int globalEndOffset, StringBuilder[] dataPerLine, int startLine,
RangeItemWriter<G> writer) {
int currentLineIdx = startLine;
// We know current item starts on current line
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java
index a7a18548418..14cd85e371a 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java
@@ -19,14 +19,14 @@
*/
package org.sonar.batch.index;
-import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.ibatis.session.ResultContext;
import org.apache.ibatis.session.ResultHandler;
-import org.sonar.api.batch.fs.InputPath;
+import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.utils.System2;
import org.sonar.batch.ProjectTree;
+import org.sonar.batch.scan.filesystem.InputFileMetadata;
import org.sonar.batch.scan.filesystem.InputPathCache;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.persistence.MyBatis;
@@ -35,7 +35,9 @@ import org.sonar.core.source.db.FileSourceMapper;
import javax.annotation.CheckForNull;
+import java.io.BufferedReader;
import java.io.IOException;
+import java.nio.file.Files;
import java.util.HashMap;
import java.util.Map;
@@ -73,10 +75,8 @@ public class SourcePersister implements ScanPersister {
});
FileSourceMapper mapper = session.getMapper(FileSourceMapper.class);
- for (InputPath inputPath : inputPathCache.all()) {
- if (inputPath instanceof DefaultInputFile) {
- persist(session, mapper, (DefaultInputFile) inputPath, previousDtosByUuid);
- }
+ for (InputFile inputFile : inputPathCache.allFiles()) {
+ persist(session, mapper, (DefaultInputFile) inputFile, previousDtosByUuid);
}
} catch (Exception e) {
throw new IllegalStateException("Unable to save file sources", e);
@@ -87,7 +87,8 @@ public class SourcePersister implements ScanPersister {
private void persist(DbSession session, FileSourceMapper mapper, DefaultInputFile inputFile, Map<String, FileSourceDto> previousDtosByUuid) {
String fileUuid = resourceCache.get(inputFile.key()).resource().getUuid();
- byte[] data = computeData(inputFile);
+ InputFileMetadata metadata = inputPathCache.getFileMetadata(inputFile.moduleKey(), inputFile.relativePath());
+ byte[] data = computeData(inputFile, metadata);
String dataHash = DigestUtils.md5Hex(data);
FileSourceDto previousDto = previousDtosByUuid.get(fileUuid);
if (previousDto == null) {
@@ -96,20 +97,20 @@ public class SourcePersister implements ScanPersister {
.setFileUuid(fileUuid)
.setBinaryData(data)
.setDataHash(dataHash)
- .setSrcHash(inputFile.hash())
- .setLineHashes(lineHashesAsMd5Hex(inputFile))
+ .setSrcHash(metadata.hash())
+ .setLineHashes(lineHashesAsMd5Hex(inputFile, metadata))
.setCreatedAt(system2.now())
.setUpdatedAt(system2.now());
mapper.insert(dto);
session.commit();
} else {
// Update only if data_hash has changed or if src_hash is missing (progressive migration)
- if (!dataHash.equals(previousDto.getDataHash()) || !inputFile.hash().equals(previousDto.getSrcHash())) {
+ if (!dataHash.equals(previousDto.getDataHash()) || !metadata.hash().equals(previousDto.getSrcHash())) {
previousDto
.setBinaryData(data)
.setDataHash(dataHash)
- .setSrcHash(inputFile.hash())
- .setLineHashes(lineHashesAsMd5Hex(inputFile))
+ .setSrcHash(metadata.hash())
+ .setLineHashes(lineHashesAsMd5Hex(inputFile, metadata))
.setUpdatedAt(system2.now());
mapper.update(previousDto);
session.commit();
@@ -118,24 +119,41 @@ public class SourcePersister implements ScanPersister {
}
@CheckForNull
- private String lineHashesAsMd5Hex(DefaultInputFile inputFile) {
- if (inputFile.lines() == 0) {
+ private String lineHashesAsMd5Hex(DefaultInputFile f, InputFileMetadata metadata) {
+ if (f.lines() == 0) {
return null;
}
// A md5 string is 32 char long + '\n' = 33
- StringBuilder result = new StringBuilder(inputFile.lines() * (32 + 1));
- for (byte[] lineHash : inputFile.lineHashes()) {
- if (result.length() > 0) {
- result.append("\n");
+ StringBuilder result = new StringBuilder(f.lines() * (32 + 1));
+
+ try {
+ BufferedReader reader = Files.newBufferedReader(f.path(), f.charset());
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < f.lines(); i++) {
+ String lineStr = reader.readLine();
+ lineStr = lineStr == null ? "" : lineStr;
+ for (int j = 0; j < lineStr.length(); j++) {
+ char c = lineStr.charAt(j);
+ if (!Character.isWhitespace(c)) {
+ sb.append(c);
+ }
+ }
+ if (i > 0) {
+ result.append("\n");
+ }
+ result.append(sb.length() > 0 ? DigestUtils.md5Hex(sb.toString()) : "");
+ sb.setLength(0);
}
- result.append(lineHash != null ? Hex.encodeHexString(lineHash) : "");
+ } catch (Exception e) {
+ throw new IllegalStateException("Unable to compute line hashes of file " + f, e);
}
+
return result.toString();
}
- private byte[] computeData(DefaultInputFile inputFile) {
+ private byte[] computeData(DefaultInputFile inputFile, InputFileMetadata metadata) {
try {
- return dataFactory.consolidateData(inputFile);
+ return dataFactory.consolidateData(inputFile, metadata);
} catch (IOException e) {
throw new IllegalStateException("Fail to read file " + inputFile, e);
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/FileHashes.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/FileHashes.java
index 49b0405787b..fbc293e8004 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/FileHashes.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/FileHashes.java
@@ -19,11 +19,17 @@
*/
package org.sonar.batch.issue.tracking;
+import com.google.common.base.Charsets;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap;
import org.apache.commons.codec.binary.Hex;
+import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang.ObjectUtils;
+import org.sonar.api.batch.fs.internal.DefaultInputFile;
+import java.io.BufferedReader;
+import java.nio.file.Files;
+import java.security.MessageDigest;
import java.util.Collection;
/**
@@ -49,7 +55,29 @@ public final class FileHashes {
return new FileHashes(hashes, linesByHash);
}
- public static FileHashes create(byte[][] hashes) {
+ public static FileHashes create(DefaultInputFile f) {
+ byte[][] hashes = new byte[f.lines()][];
+ try {
+ BufferedReader reader = Files.newBufferedReader(f.path(), f.charset());
+ MessageDigest lineMd5Digest = DigestUtils.getMd5Digest();
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < f.lines(); i++) {
+ String lineStr = reader.readLine();
+ if (lineStr != null) {
+ for (int j = 0; j < lineStr.length(); j++) {
+ char c = lineStr.charAt(j);
+ if (!Character.isWhitespace(c)) {
+ sb.append(c);
+ }
+ }
+ }
+ hashes[i] = sb.length() > 0 ? lineMd5Digest.digest(sb.toString().getBytes(Charsets.UTF_8)) : null;
+ sb.setLength(0);
+ }
+ } catch (Exception e) {
+ throw new IllegalStateException("Unable to compute line hashes of file " + f, e);
+ }
+
int size = hashes.length;
Multimap<String, Integer> linesByHash = LinkedHashMultimap.create();
String[] hexHashes = new String[size];
diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueHandlers.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueHandlers.java
index f8a98c29b00..b501e18ad66 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueHandlers.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueHandlers.java
@@ -19,7 +19,7 @@
*/
package org.sonar.batch.issue.tracking;
-import org.sonar.api.BatchExtension;
+import org.sonar.api.BatchComponent;
import org.sonar.api.issue.Issue;
import org.sonar.api.issue.IssueHandler;
import org.sonar.api.issue.internal.DefaultIssue;
@@ -30,7 +30,7 @@ import org.sonar.core.user.DefaultUser;
import javax.annotation.Nullable;
-public class IssueHandlers implements BatchExtension {
+public class IssueHandlers implements BatchComponent {
private final IssueHandler[] handlers;
private final DefaultContext context;
@@ -117,7 +117,7 @@ public class IssueHandlers implements BatchExtension {
@Override
public IssueHandler.Context assign(@Nullable String assignee) {
User user = null;
- if(assignee != null) {
+ if (assignee != null) {
user = new DefaultUser().setLogin(assignee).setName(assignee);
}
updater.assign(issue, user, changeContext);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTrackingDecorator.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTrackingDecorator.java
index c3826cbd391..c1ae052034c 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTrackingDecorator.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTrackingDecorator.java
@@ -19,8 +19,6 @@
*/
package org.sonar.batch.issue.tracking;
-import org.sonar.api.batch.RequiresDB;
-
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
@@ -32,6 +30,7 @@ import org.sonar.api.batch.DecoratorBarriers;
import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.batch.DependedUpon;
import org.sonar.api.batch.DependsUpon;
+import org.sonar.api.batch.RequiresDB;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.component.ResourcePerspectives;
@@ -133,7 +132,7 @@ public class IssueTrackingDecorator implements Decorator {
File sonarFile = (File) resource;
InputFile file = inputPathCache.getFile(project.getEffectiveKey(), sonarFile.getPath());
if (file == null) {
- throw new IllegalStateException("Resource " + resource + " was not found in InputPath cache");
+ throw new IllegalStateException("File " + resource + " was not found in InputPath cache");
}
sourceHashHolder = new SourceHashHolder((DefaultInputFile) file, lastLineHashes);
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/LocalIssueTracking.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/LocalIssueTracking.java
index f0c22e52c68..c4d9a65769f 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/LocalIssueTracking.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/LocalIssueTracking.java
@@ -24,7 +24,6 @@ import com.google.common.collect.Lists;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.BatchComponent;
-import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.rule.ActiveRule;
import org.sonar.api.batch.rule.ActiveRules;
@@ -108,7 +107,7 @@ public class LocalIssueTracking implements BatchComponent {
SourceHashHolder sourceHashHolder = null;
if (component.isFile()) {
- InputFile file = (InputFile) inputPathCache.getInputPath(component);
+ DefaultInputFile file = (DefaultInputFile) inputPathCache.getInputPath(component);
if (file == null) {
throw new IllegalStateException("Resource " + component.resource() + " was not found in InputPath cache");
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/SourceHashHolder.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/SourceHashHolder.java
index 38f0af7745a..8151f4184f4 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/SourceHashHolder.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/SourceHashHolder.java
@@ -43,7 +43,7 @@ public class SourceHashHolder {
private void initHashes() {
if (hashedSource == null) {
- hashedSource = FileHashes.create(inputFile.lineHashes());
+ hashedSource = FileHashes.create(inputFile);
Status status = inputFile.status();
if (status == Status.ADDED) {
hashedReference = null;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java
index 7bc120b37d6..4d89b9e4b3e 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java
@@ -24,7 +24,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.fs.InputDir;
import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.fs.InputPath;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.sensor.dependency.Dependency;
import org.sonar.api.batch.sensor.duplication.DuplicationGroup;
@@ -165,12 +164,11 @@ public class TaskResult implements org.sonar.batch.mediumtest.ScanTaskObserver {
private void storeFs(ProjectScanContainer container) {
InputPathCache inputFileCache = container.getComponentByType(InputPathCache.class);
- for (InputPath inputPath : inputFileCache.all()) {
- if (inputPath instanceof InputFile) {
- inputFiles.put(inputPath.relativePath(), (InputFile) inputPath);
- } else {
- inputDirs.put(inputPath.relativePath(), (InputDir) inputPath);
- }
+ for (InputFile inputPath : inputFileCache.allFiles()) {
+ inputFiles.put(inputPath.relativePath(), inputPath);
+ }
+ for (InputDir inputPath : inputFileCache.allDirs()) {
+ inputDirs.put(inputPath.relativePath(), inputPath);
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsExecutor.java
index 6da48d12bb8..b555f76ded9 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsExecutor.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsExecutor.java
@@ -19,6 +19,9 @@
*/
package org.sonar.batch.phases;
+import org.sonar.batch.deprecated.decorator.DefaultDecoratorContext;
+
+import org.sonar.batch.deprecated.decorator.DecoratorsSelector;
import com.google.common.collect.Lists;
import org.sonar.api.BatchComponent;
import org.sonar.api.batch.Decorator;
@@ -29,8 +32,6 @@ import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.SonarException;
-import org.sonar.batch.DecoratorsSelector;
-import org.sonar.batch.DefaultDecoratorContext;
import org.sonar.batch.bootstrap.BatchExtensionDictionnary;
import org.sonar.batch.duplication.DuplicationCache;
import org.sonar.batch.events.EventBus;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/Phases.java b/sonar-batch/src/main/java/org/sonar/batch/phases/Phases.java
index 6c84c6dff15..2a2e08056ad 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/phases/Phases.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/phases/Phases.java
@@ -24,6 +24,9 @@ import com.google.common.collect.Sets;
import java.util.Arrays;
import java.util.Set;
+/**
+ * Used by views
+ */
public class Phases {
public static enum Phase {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/SensorMatcher.java b/sonar-batch/src/main/java/org/sonar/batch/phases/SensorMatcher.java
index c50d3727184..38502235cff 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/phases/SensorMatcher.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/phases/SensorMatcher.java
@@ -27,6 +27,7 @@ import org.sonar.batch.bootstrap.ExtensionMatcher;
/**
* Allow to filter sensors that will be executed.
+ * Used by views !!
* @since 3.6
*
*/
diff --git a/sonar-batch/src/main/java/org/sonar/batch/languages/DefaultLanguagesReferential.java b/sonar-batch/src/main/java/org/sonar/batch/repository/language/DefaultLanguagesRepository.java
index 4d43ea2d8ce..fe5f50ba9ea 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/languages/DefaultLanguagesReferential.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/repository/language/DefaultLanguagesRepository.java
@@ -17,7 +17,7 @@
* 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.batch.languages;
+package org.sonar.batch.repository.language;
import org.sonar.api.resources.Languages;
@@ -27,14 +27,14 @@ import java.util.ArrayList;
import java.util.Collection;
/**
- * Languages referential using {@link Languages}
+ * Languages repository using {@link Languages}
* @since 4.4
*/
-public class DefaultLanguagesReferential implements LanguagesReferential {
+public class DefaultLanguagesRepository implements LanguagesRepository {
private Languages languages;
- public DefaultLanguagesReferential(Languages languages) {
+ public DefaultLanguagesRepository(Languages languages) {
this.languages = languages;
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/languages/Language.java b/sonar-batch/src/main/java/org/sonar/batch/repository/language/Language.java
index daeb7d50626..67629ae50ad 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/languages/Language.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/repository/language/Language.java
@@ -17,7 +17,7 @@
* 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.batch.languages;
+package org.sonar.batch.repository.language;
import java.util.Arrays;
import java.util.Collection;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/languages/LanguagesReferential.java b/sonar-batch/src/main/java/org/sonar/batch/repository/language/LanguagesRepository.java
index da1596c2c10..dd80fee1dcd 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/languages/LanguagesReferential.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/repository/language/LanguagesRepository.java
@@ -17,7 +17,7 @@
* 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.batch.languages;
+package org.sonar.batch.repository.language;
import org.sonar.api.BatchComponent;
@@ -26,10 +26,10 @@ import javax.annotation.CheckForNull;
import java.util.Collection;
/**
- * Languages referential
+ * Languages repository
* @since 4.4
*/
-public interface LanguagesReferential extends BatchComponent {
+public interface LanguagesRepository extends BatchComponent {
/**
* Get language.
diff --git a/sonar-batch/src/main/java/org/sonar/batch/languages/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/repository/language/package-info.java
index 7a5d7a96ff6..03e334e21a0 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/languages/package-info.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/repository/language/package-info.java
@@ -18,4 +18,4 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@javax.annotation.ParametersAreNonnullByDefault
-package org.sonar.batch.languages;
+package org.sonar.batch.repository.language;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/user/User.java b/sonar-batch/src/main/java/org/sonar/batch/repository/user/User.java
index bd96d273f8c..5323e18b943 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/user/User.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/repository/user/User.java
@@ -17,7 +17,7 @@
* 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.batch.user;
+package org.sonar.batch.repository.user;
import org.apache.commons.lang.builder.EqualsBuilder;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/user/UserRepository.java b/sonar-batch/src/main/java/org/sonar/batch/repository/user/UserRepository.java
index c129bb704df..e7185b98645 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/user/UserRepository.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/repository/user/UserRepository.java
@@ -17,7 +17,7 @@
* 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.batch.user;
+package org.sonar.batch.repository.user;
import com.google.common.base.Joiner;
import org.sonar.batch.bootstrap.ServerClient;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/user/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/repository/user/package-info.java
index 6415ba162e8..a86ee26f141 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/user/package-info.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/repository/user/package-info.java
@@ -18,6 +18,6 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@ParametersAreNonnullByDefault
-package org.sonar.batch.user;
+package org.sonar.batch.repository.user;
import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileSensor.java b/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileSensor.java
index 13ab4448d78..37455f5b58a 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileSensor.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileSensor.java
@@ -19,6 +19,7 @@
*/
package org.sonar.batch.rule;
+import org.sonar.api.batch.AnalysisMode;
import org.sonar.api.batch.Sensor;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.batch.fs.FileSystem;
@@ -33,16 +34,20 @@ public class QProfileSensor implements Sensor {
private final ModuleQProfiles moduleQProfiles;
private final FileSystem fs;
+ private final AnalysisMode analysisMode;
- public QProfileSensor(ModuleQProfiles moduleQProfiles, FileSystem fs) {
+ public QProfileSensor(ModuleQProfiles moduleQProfiles, FileSystem fs, AnalysisMode analysisMode) {
this.moduleQProfiles = moduleQProfiles;
this.fs = fs;
+ this.analysisMode = analysisMode;
}
@Override
public boolean shouldExecuteOnProject(Project project) {
// Should be only executed on leaf modules
- return project.getModules().isEmpty();
+ return project.getModules().isEmpty()
+ // Useless in preview mode
+ && !analysisMode.isPreview();
}
@Override
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/LanguageVerifier.java b/sonar-batch/src/main/java/org/sonar/batch/scan/LanguageVerifier.java
index 801fadddd44..f813c050681 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/LanguageVerifier.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/LanguageVerifier.java
@@ -19,7 +19,8 @@
*/
package org.sonar.batch.scan;
-import org.sonar.batch.languages.Language;
+import org.sonar.batch.repository.language.Language;
+import org.sonar.batch.repository.language.LanguagesRepository;
import org.picocontainer.Startable;
import org.slf4j.Logger;
@@ -28,7 +29,6 @@ import org.sonar.api.CoreProperties;
import org.sonar.api.batch.fs.internal.DefaultFileSystem;
import org.sonar.api.config.Settings;
import org.sonar.api.utils.MessageException;
-import org.sonar.batch.languages.LanguagesReferential;
/**
* Verifies that the property sonar.language is valid
@@ -38,10 +38,10 @@ public class LanguageVerifier implements Startable {
private static final Logger LOG = LoggerFactory.getLogger(LanguageVerifier.class);
private final Settings settings;
- private final LanguagesReferential languages;
+ private final LanguagesRepository languages;
private final DefaultFileSystem fs;
- public LanguageVerifier(Settings settings, LanguagesReferential languages, DefaultFileSystem fs) {
+ public LanguageVerifier(Settings settings, LanguagesRepository languages, DefaultFileSystem fs) {
this.settings = settings;
this.languages = languages;
this.fs = fs;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java
index e350fd28992..0f457c735d9 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java
@@ -29,11 +29,7 @@ import org.sonar.api.checks.NoSonarFilter;
import org.sonar.api.platform.ComponentContainer;
import org.sonar.api.resources.Project;
import org.sonar.api.scan.filesystem.FileExclusions;
-import org.sonar.batch.DefaultProjectClasspath;
-import org.sonar.batch.DefaultTimeMachine;
-import org.sonar.batch.DeprecatedSensorContext;
import org.sonar.batch.ProjectTree;
-import org.sonar.batch.ResourceFilters;
import org.sonar.batch.bootstrap.BatchExtensionDictionnary;
import org.sonar.batch.bootstrap.DefaultAnalysisMode;
import org.sonar.batch.bootstrap.ExtensionInstaller;
@@ -45,6 +41,10 @@ import org.sonar.batch.debt.IssueChangelogDebtCalculator;
import org.sonar.batch.debt.NewDebtDecorator;
import org.sonar.batch.debt.SqaleRatingDecorator;
import org.sonar.batch.debt.SqaleRatingSettings;
+import org.sonar.batch.deprecated.DeprecatedSensorContext;
+import org.sonar.batch.deprecated.ResourceFilters;
+import org.sonar.batch.deprecated.components.DefaultProjectClasspath;
+import org.sonar.batch.deprecated.components.DefaultTimeMachine;
import org.sonar.batch.events.EventBus;
import org.sonar.batch.index.DefaultIndex;
import org.sonar.batch.issue.IssuableFactory;
@@ -87,6 +87,7 @@ import org.sonar.batch.scan.filesystem.DefaultModuleFileSystem;
import org.sonar.batch.scan.filesystem.DeprecatedFileFilters;
import org.sonar.batch.scan.filesystem.ExclusionFilters;
import org.sonar.batch.scan.filesystem.FileIndexer;
+import org.sonar.batch.scan.filesystem.FileMetadata;
import org.sonar.batch.scan.filesystem.FileSystemLogger;
import org.sonar.batch.scan.filesystem.InputFileBuilderFactory;
import org.sonar.batch.scan.filesystem.LanguageDetectionFactory;
@@ -158,6 +159,7 @@ public class ModuleScanContainer extends ComponentContainer {
ExclusionFilters.class,
DeprecatedFileFilters.class,
InputFileBuilderFactory.class,
+ FileMetadata.class,
StatusDetectionFactory.class,
LanguageDetectionFactory.class,
FileIndexer.class,
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
index 30ef5615488..98c46431093 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
@@ -19,6 +19,10 @@
*/
package org.sonar.batch.scan;
+import org.sonar.batch.deprecated.components.DefaultResourceCreationLock;
+
+import org.sonar.batch.deprecated.components.PeriodsDefinition;
+import org.sonar.batch.repository.language.DefaultLanguagesRepository;
import com.google.common.annotations.VisibleForTesting;
import org.sonar.api.BatchComponent;
import org.sonar.api.CoreProperties;
@@ -32,7 +36,6 @@ import org.sonar.api.resources.Project;
import org.sonar.api.scan.filesystem.PathResolver;
import org.sonar.api.utils.SonarException;
import org.sonar.batch.DefaultFileLinesContextFactory;
-import org.sonar.batch.DefaultResourceCreationLock;
import org.sonar.batch.ProjectConfigurator;
import org.sonar.batch.ProjectTree;
import org.sonar.batch.bootstrap.DefaultAnalysisMode;
@@ -40,7 +43,6 @@ import org.sonar.batch.bootstrap.ExtensionInstaller;
import org.sonar.batch.bootstrap.ExtensionMatcher;
import org.sonar.batch.bootstrap.ExtensionUtils;
import org.sonar.batch.bootstrap.MetricProvider;
-import org.sonar.batch.components.PeriodsDefinition;
import org.sonar.batch.debt.DebtModelProvider;
import org.sonar.batch.debt.IssueChangelogDebtCalculator;
import org.sonar.batch.duplication.BlockCache;
@@ -63,7 +65,6 @@ import org.sonar.batch.issue.IssueCache;
import org.sonar.batch.issue.tracking.InitialOpenIssuesStack;
import org.sonar.batch.issue.tracking.LocalIssueTracking;
import org.sonar.batch.issue.tracking.PreviousIssueRepository;
-import org.sonar.batch.languages.DefaultLanguagesReferential;
import org.sonar.batch.mediumtest.ScanTaskObservers;
import org.sonar.batch.phases.GraphPersister;
import org.sonar.batch.profiling.PhasesSumUpTimeProfiler;
@@ -177,7 +178,7 @@ public class ProjectScanContainer extends ComponentContainer {
// lang
Languages.class,
- DefaultLanguagesReferential.class,
+ DefaultLanguagesRepository.class,
HighlightableBuilder.class,
SymbolizableBuilder.class,
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/AdditionalFilePredicates.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/AdditionalFilePredicates.java
index 4d4967ec1f3..83fbd745426 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/AdditionalFilePredicates.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/AdditionalFilePredicates.java
@@ -19,7 +19,6 @@
*/
package org.sonar.batch.scan.filesystem;
-import org.apache.commons.io.FilenameUtils;
import org.sonar.api.batch.fs.AbstractFilePredicate;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DeprecatedDefaultInputFile;
@@ -47,42 +46,4 @@ class AdditionalFilePredicates {
}
}
- static class DeprecatedKeyPredicate extends AbstractFilePredicate {
- private final String key;
-
- DeprecatedKeyPredicate(String key) {
- this.key = key;
- }
-
- @Override
- public boolean apply(InputFile f) {
- return key.equals(((DeprecatedDefaultInputFile) f).deprecatedKey());
- }
- }
-
- static class SourceRelativePathPredicate extends AbstractFilePredicate {
- private final String path;
-
- SourceRelativePathPredicate(String s) {
- this.path = FilenameUtils.normalize(s, true);
- }
-
- @Override
- public boolean apply(InputFile f) {
- return path.equals(((DeprecatedDefaultInputFile) f).pathRelativeToSourceDir());
- }
- }
-
- static class SourceDirPredicate extends AbstractFilePredicate {
- private final String path;
-
- SourceDirPredicate(String s) {
- this.path = FilenameUtils.normalize(s, true);
- }
-
- @Override
- public boolean apply(InputFile f) {
- return path.equals(((DeprecatedDefaultInputFile) f).sourceDirAbsolutePath());
- }
- }
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java
index 69438106d8f..460a08831b3 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java
@@ -21,16 +21,13 @@ package org.sonar.batch.scan.filesystem;
import org.sonar.api.BatchComponent;
import org.sonar.api.batch.SonarIndex;
-import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.fs.internal.DeprecatedDefaultInputFile;
import org.sonar.api.resources.File;
import org.sonar.api.resources.Languages;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.batch.index.ResourceKeyMigration;
import org.sonar.batch.index.ResourcePersister;
-import org.sonar.batch.util.DeprecatedKeyUtils;
import javax.annotation.Nullable;
@@ -60,7 +57,9 @@ public class ComponentIndexer implements BatchComponent {
this(module, languages, sonarIndex, null, null);
}
- public void execute(FileSystem fs) {
+ public void execute(DefaultModuleFileSystem fs) {
+ module.setBaseDir(fs.baseDir());
+
if (resourcePersister != null) {
// Force persistence of module structure in order to know if project should be migrated
resourcePersister.persist();
@@ -73,16 +72,7 @@ public class ComponentIndexer implements BatchComponent {
for (InputFile inputFile : fs.inputFiles(fs.predicates().all())) {
String languageKey = inputFile.language();
boolean unitTest = InputFile.Type.TEST == inputFile.type();
- String pathFromSourceDir = ((DeprecatedDefaultInputFile) inputFile).pathRelativeToSourceDir();
- if (pathFromSourceDir == null) {
- pathFromSourceDir = inputFile.relativePath();
- }
- Resource sonarFile = File.create(inputFile.relativePath(), pathFromSourceDir, languages.get(languageKey), unitTest);
- if ("java".equals(languageKey)) {
- sonarFile.setDeprecatedKey(DeprecatedKeyUtils.getJavaFileDeprecatedKey(pathFromSourceDir));
- } else {
- sonarFile.setDeprecatedKey(pathFromSourceDir);
- }
+ Resource sonarFile = File.create(inputFile.relativePath(), languages.get(languageKey), unitTest);
sonarIndex.index(sonarFile);
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultInputFileValueCoder.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultInputFileValueCoder.java
deleted file mode 100644
index 31e0880a8fe..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultInputFileValueCoder.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.batch.scan.filesystem;
-
-import com.persistit.Value;
-import com.persistit.encoding.CoderContext;
-import com.persistit.encoding.ValueCoder;
-import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.fs.internal.DeprecatedDefaultInputFile;
-
-import javax.annotation.Nullable;
-
-import java.io.File;
-
-class DefaultInputFileValueCoder implements ValueCoder {
-
- @Override
- public void put(Value value, Object object, CoderContext context) {
- DeprecatedDefaultInputFile f = (DeprecatedDefaultInputFile) object;
- putUTFOrNull(value, f.moduleKey());
- putUTFOrNull(value, f.relativePath());
- value.putString(f.getFileBaseDir().toString());
- putUTFOrNull(value, f.deprecatedKey());
- value.putString(f.sourceDirAbsolutePath());
- putUTFOrNull(value, f.pathRelativeToSourceDir());
- putUTFOrNull(value, f.absolutePath());
- value.putString(f.language());
- value.putString(f.type().name());
- value.putString(f.status().name());
- putUTFOrNull(value, f.hash());
- value.put(f.lines());
- value.put(f.nonBlankLines());
- putUTFOrNull(value, f.encoding());
- value.put(f.isEmpty());
- value.putLongArray(f.originalLineOffsets());
- for (int i = 0; i < f.lines(); i++) {
- value.putByteArray(f.lineHashes()[i]);
- }
- }
-
- private void putUTFOrNull(Value value, @Nullable String utfOrNull) {
- if (utfOrNull != null) {
- value.putUTF(utfOrNull);
- } else {
- value.putNull();
- }
- }
-
- @Override
- public Object get(Value value, Class clazz, CoderContext context) {
- String moduleKey = value.getString();
- DeprecatedDefaultInputFile file = new DeprecatedDefaultInputFile(moduleKey, value.getString());
- file.setBasedir(new File(value.getString()));
- file.setDeprecatedKey(value.getString());
- file.setSourceDirAbsolutePath(value.getString());
- file.setPathRelativeToSourceDir(value.getString());
- file.setAbsolutePath(value.getString());
- file.setLanguage(value.getString());
- file.setType(InputFile.Type.valueOf(value.getString()));
- file.setStatus(InputFile.Status.valueOf(value.getString()));
- file.setHash(value.getString());
- file.setLines(value.getInt());
- file.setNonBlankLines(value.getInt());
- file.setEncoding(value.getString());
- file.setEmpty(value.getBoolean());
- file.setOriginalLineOffsets(value.getLongArray());
- byte[][] lineHashes = new byte[file.lines()][];
- for (int i = 0; i < file.lines(); i++) {
- lineHashes[i] = value.getByteArray();
- }
- file.setLineHashes(lineHashes);
- return file;
- }
-
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java
index 43006d48ef6..5f16313e853 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java
@@ -19,13 +19,13 @@
*/
package org.sonar.batch.scan.filesystem;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.CoreProperties;
-import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.fs.FilePredicate;
import org.sonar.api.batch.fs.internal.DefaultFileSystem;
import org.sonar.api.config.Settings;
@@ -45,8 +45,6 @@ import java.util.List;
import java.util.Map;
/**
- * This class can't be immutable because of execution of maven plugins that can change the project structure (see MavenPluginHandler and sonar.phase)
- *
* @since 3.5
*/
public class DefaultModuleFileSystem extends DefaultFileSystem implements ModuleFileSystem {
@@ -62,27 +60,26 @@ public class DefaultModuleFileSystem extends DefaultFileSystem implements Module
private ComponentIndexer componentIndexer;
private boolean initialized;
- /**
- * Used by scan2
- */
- public DefaultModuleFileSystem(ModuleInputFileCache moduleInputFileCache, ProjectDefinition def, Settings settings,
- FileIndexer indexer, ModuleFileSystemInitializer initializer) {
- this(moduleInputFileCache, def.getKey(), settings, indexer, initializer, null);
- }
-
public DefaultModuleFileSystem(ModuleInputFileCache moduleInputFileCache, Project project,
- Settings settings, FileIndexer indexer,
- ModuleFileSystemInitializer initializer,
- ComponentIndexer componentIndexer) {
- this(moduleInputFileCache, project.getKey(), settings, indexer, initializer, componentIndexer);
+ Settings settings, FileIndexer indexer, ModuleFileSystemInitializer initializer, ComponentIndexer componentIndexer) {
+ super(initializer.baseDir().toPath(), moduleInputFileCache);
+ this.componentIndexer = componentIndexer;
+ this.moduleKey = project.getKey();
+ this.settings = settings;
+ this.indexer = indexer;
+ setWorkDir(initializer.workingDir());
+ this.buildDir = initializer.buildDir();
+ this.sourceDirsOrFiles = initializer.sources();
+ this.testDirsOrFiles = initializer.tests();
+ this.binaryDirs = initializer.binaryDirs();
}
- private DefaultModuleFileSystem(ModuleInputFileCache moduleInputFileCache, String moduleKey, Settings settings,
- FileIndexer indexer, ModuleFileSystemInitializer initializer,
- @Nullable ComponentIndexer componentIndexer) {
- super(initializer.baseDir(), moduleInputFileCache);
+ @VisibleForTesting
+ public DefaultModuleFileSystem(Project project,
+ Settings settings, FileIndexer indexer, ModuleFileSystemInitializer initializer, ComponentIndexer componentIndexer) {
+ super(initializer.baseDir().toPath());
this.componentIndexer = componentIndexer;
- this.moduleKey = moduleKey;
+ this.moduleKey = project.getKey();
this.settings = settings;
this.indexer = indexer;
setWorkDir(initializer.workingDir());
@@ -260,30 +257,6 @@ public class DefaultModuleFileSystem extends DefaultFileSystem implements Module
}
}));
}
- if ("CMP_DEPRECATED_KEY".equals(key)) {
- return predicates().or(Collections2.transform(value, new Function<String, FilePredicate>() {
- @Override
- public FilePredicate apply(@Nullable String s) {
- return s == null ? predicates().all() : new AdditionalFilePredicates.DeprecatedKeyPredicate(s);
- }
- }));
- }
- if ("SRC_REL_PATH".equals(key)) {
- return predicates().or(Collections2.transform(value, new Function<String, FilePredicate>() {
- @Override
- public FilePredicate apply(@Nullable String s) {
- return s == null ? predicates().all() : new AdditionalFilePredicates.SourceRelativePathPredicate(s);
- }
- }));
- }
- if ("SRC_DIR_PATH".equals(key)) {
- return predicates().or(Collections2.transform(value, new Function<String, FilePredicate>() {
- @Override
- public FilePredicate apply(@Nullable String s) {
- return s == null ? predicates().all() : new AdditionalFilePredicates.SourceDirPredicate(s);
- }
- }));
- }
throw new IllegalArgumentException("Unsupported file attribute: " + key);
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DeprecatedFileFilters.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DeprecatedFileFilters.java
index d52e19b0b0b..9fa6ea98a23 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DeprecatedFileFilters.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DeprecatedFileFilters.java
@@ -21,13 +21,10 @@ package org.sonar.batch.scan.filesystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.InputFileFilter;
-import org.sonar.api.batch.fs.internal.DeprecatedDefaultInputFile;
import org.sonar.api.scan.filesystem.FileSystemFilter;
import org.sonar.api.scan.filesystem.FileType;
import org.sonar.api.scan.filesystem.ModuleFileSystem;
-import java.io.File;
-
public class DeprecatedFileFilters implements InputFileFilter {
private final FileSystemFilter[] filters;
@@ -71,13 +68,8 @@ public class DeprecatedFileFilters implements InputFileFilter {
}
@Override
- public File relativeDir() {
- return new File(((DeprecatedDefaultInputFile)inputFile).sourceDirAbsolutePath());
- }
-
- @Override
public String relativePath() {
- return ((DeprecatedDefaultInputFile)inputFile).pathRelativeToSourceDir();
+ return inputFile.relativePath();
}
@Override
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileIndexer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileIndexer.java
index e78ae260ca3..d4626209aa2 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileIndexer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileIndexer.java
@@ -23,20 +23,18 @@ import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.FileFilterUtils;
import org.apache.commons.io.filefilter.HiddenFileFilter;
import org.apache.commons.io.filefilter.IOFileFilter;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.BatchComponent;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.batch.fs.InputDir;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.InputFileFilter;
import org.sonar.api.batch.fs.internal.DefaultInputDir;
-import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.fs.internal.DeprecatedDefaultInputFile;
import org.sonar.api.scan.filesystem.PathResolver;
import org.sonar.api.utils.MessageException;
+import org.sonar.batch.util.ProgressReport;
import java.io.File;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
@@ -47,14 +45,13 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
/**
* Index input files into {@link InputPathCache}.
*/
public class FileIndexer implements BatchComponent {
- private static final Logger LOG = LoggerFactory.getLogger(FileIndexer.class);
-
private static final IOFileFilter DIR_FILTER = FileFilterUtils.and(HiddenFileFilter.VISIBLE, FileFilterUtils.notFileFilter(FileFilterUtils.prefixFileFilter(".")));
private static final IOFileFilter FILE_FILTER = HiddenFileFilter.VISIBLE;
@@ -62,18 +59,19 @@ public class FileIndexer implements BatchComponent {
private final boolean isAggregator;
private final ExclusionFilters exclusionFilters;
private final InputFileBuilderFactory inputFileBuilderFactory;
+ private final InputPathCache inputPathCache;
- public FileIndexer(List<InputFileFilter> filters, ExclusionFilters exclusionFilters, InputFileBuilderFactory inputFileBuilderFactory,
- ProjectDefinition def) {
- this(filters, exclusionFilters, inputFileBuilderFactory, !def.getSubProjects().isEmpty());
- }
+ private ProgressReport progressReport;
+ private ExecutorService executorService;
+ private List<Future<Void>> tasks;
- private FileIndexer(List<InputFileFilter> filters, ExclusionFilters exclusionFilters, InputFileBuilderFactory inputFileBuilderFactory,
- boolean isAggregator) {
+ public FileIndexer(List<InputFileFilter> filters, ExclusionFilters exclusionFilters, InputFileBuilderFactory inputFileBuilderFactory,
+ ProjectDefinition def, InputPathCache inputPathCache) {
+ this.inputPathCache = inputPathCache;
this.filters = filters;
this.exclusionFilters = exclusionFilters;
this.inputFileBuilderFactory = inputFileBuilderFactory;
- this.isAggregator = isAggregator;
+ this.isAggregator = !def.getSubProjects().isEmpty();
}
void index(DefaultModuleFileSystem fileSystem) {
@@ -81,47 +79,34 @@ public class FileIndexer implements BatchComponent {
// No indexing for an aggregator module
return;
}
- LOG.info("Index files");
+ progressReport = new ProgressReport("Report about progress of file indexation", TimeUnit.SECONDS.toMillis(10));
+ progressReport.start("Index files");
exclusionFilters.prepare();
Progress progress = new Progress();
InputFileBuilder inputFileBuilder = inputFileBuilderFactory.create(fileSystem);
+ executorService = Executors.newFixedThreadPool(Math.max(1, Runtime.getRuntime().availableProcessors() - 1));
+ tasks = new ArrayList<Future<Void>>();
indexFiles(fileSystem, progress, inputFileBuilder, fileSystem.sources(), InputFile.Type.MAIN);
indexFiles(fileSystem, progress, inputFileBuilder, fileSystem.tests(), InputFile.Type.TEST);
- indexAllConcurrently(progress);
-
- // Populate FS in a synchronous way because PersistIt Exchange is not concurrent
- for (InputFile indexed : progress.indexed) {
- fileSystem.add(indexed);
- }
- for (InputDir indexed : progress.indexedDir) {
- fileSystem.add(indexed);
- }
-
- LOG.info(String.format("%d files indexed", progress.count()));
+ waitForTasksToComplete();
+ progressReport.stop(progress.count() + " files indexed");
}
- private void indexAllConcurrently(Progress progress) {
- ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() + 1);
- try {
- List<Future<Void>> all = executor.invokeAll(progress.indexingTasks);
- for (Future<Void> future : all) {
- future.get();
- }
- } catch (InterruptedException e) {
- throw new IllegalStateException("FileIndexer was interrupted", e);
- } catch (ExecutionException e) {
- Throwable cause = e.getCause();
- if (cause instanceof RuntimeException) {
- throw (RuntimeException) cause;
- } else {
- throw new IllegalStateException("Error during file indexing", e);
+ private void waitForTasksToComplete() {
+ for (Future<Void> task : tasks) {
+ try {
+ task.get();
+ } catch (ExecutionException e) {
+ // Unwrap ExecutionException
+ throw e.getCause() instanceof RuntimeException ? (RuntimeException) e.getCause() : new IllegalStateException(e.getCause());
+ } catch (InterruptedException e) {
+ throw new IllegalStateException(e);
}
}
- executor.shutdown();
}
private void indexFiles(DefaultModuleFileSystem fileSystem, Progress progress, InputFileBuilder inputFileBuilder, List<File> sources, InputFile.Type type) {
@@ -151,25 +136,25 @@ public class FileIndexer implements BatchComponent {
private void indexFile(final InputFileBuilder inputFileBuilder, final DefaultModuleFileSystem fs,
final Progress status, final DeprecatedDefaultInputFile inputFile, final InputFile.Type type) {
- Callable<Void> task = new Callable<Void>() {
-
+ tasks.add(executorService.submit(new Callable<Void>() {
@Override
- public Void call() throws Exception {
- DefaultInputFile completedFile = inputFileBuilder.complete(inputFile, type);
- if (completedFile != null && accept(completedFile)) {
+ public Void call() {
+ InputFileMetadata metadata = inputFileBuilder.completeAndComputeMetadata(inputFile, type);
+ if (metadata != null && accept(inputFile)) {
+ fs.add(inputFile);
status.markAsIndexed(inputFile);
+ inputPathCache.put(inputFile.moduleKey(), inputFile.relativePath(), metadata);
File parentDir = inputFile.file().getParentFile();
String relativePath = new PathResolver().relativePath(fs.baseDir(), parentDir);
if (relativePath != null) {
DefaultInputDir inputDir = new DefaultInputDir(fs.moduleKey(), relativePath);
- inputDir.setFile(parentDir);
- status.markAsIndexed(inputDir);
+ fs.add(inputDir);
}
}
return null;
}
- };
- status.planForIndexing(task);
+ }));
+
}
private boolean accept(InputFile inputFile) {
@@ -182,31 +167,16 @@ public class FileIndexer implements BatchComponent {
return true;
}
- private static class Progress {
- private final Set<InputFile> indexed;
- private final Set<InputDir> indexedDir;
- private final List<Callable<Void>> indexingTasks;
-
- Progress() {
- this.indexed = new HashSet<InputFile>();
- this.indexedDir = new HashSet<InputDir>();
- this.indexingTasks = new ArrayList<Callable<Void>>();
- }
-
- void planForIndexing(Callable<Void> indexingTask) {
- this.indexingTasks.add(indexingTask);
- }
+ private class Progress {
+ private final Set<Path> indexed = new HashSet<>();
synchronized void markAsIndexed(InputFile inputFile) {
- if (indexed.contains(inputFile)) {
+ if (indexed.contains(inputFile.path())) {
throw MessageException.of("File " + inputFile + " can't be indexed twice. Please check that inclusion/exclusion patterns produce "
+ "disjoint sets for main and test files");
}
- indexed.add(inputFile);
- }
-
- synchronized void markAsIndexed(InputDir inputDir) {
- indexedDir.add(inputDir);
+ indexed.add(inputFile.path());
+ progressReport.message(indexed.size() + " files indexed... (last one was " + inputFile.relativePath() + ")");
}
int count() {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileMetadata.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileMetadata.java
index b3b4d1469fd..0f91e4ae3cc 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileMetadata.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileMetadata.java
@@ -20,17 +20,22 @@
package org.sonar.batch.scan.filesystem;
import com.google.common.base.Charsets;
-import com.google.common.primitives.Longs;
+import com.google.common.primitives.Ints;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.ByteOrderMark;
import org.apache.commons.io.input.BOMInputStream;
+import org.sonar.api.BatchComponent;
+import org.sonar.api.batch.AnalysisMode;
import javax.annotation.CheckForNull;
-import java.io.*;
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.util.ArrayList;
@@ -40,10 +45,15 @@ import java.util.List;
* Computes hash of files. Ends of Lines are ignored, so files with
* same content but different EOL encoding have the same hash.
*/
-class FileMetadata {
+public class FileMetadata implements BatchComponent {
private static final char LINE_FEED = '\n';
private static final char CARRIAGE_RETURN = '\r';
+ private final AnalysisMode analysisMode;
+
+ public FileMetadata(AnalysisMode analysisMode) {
+ this.analysisMode = analysisMode;
+ }
private abstract class CharHandler {
@@ -110,14 +120,25 @@ class FileMetadata {
private class FileHashComputer extends CharHandler {
private MessageDigest globalMd5Digest = DigestUtils.getMd5Digest();
+ StringBuffer sb = new StringBuffer();
+
@Override
void handleIgnoreEoL(char c) {
- updateDigestUTF8Char(c, globalMd5Digest);
+ sb.append(c);
}
@Override
void newLine() {
- updateDigestUTF8Char(LINE_FEED, globalMd5Digest);
+ sb.append(LINE_FEED);
+ globalMd5Digest.update(sb.toString().getBytes(Charsets.UTF_8));
+ sb.setLength(0);
+ }
+
+ @Override
+ void eof() {
+ if (sb.length() > 0) {
+ globalMd5Digest.update(sb.toString().getBytes(Charsets.UTF_8));
+ }
}
@CheckForNull
@@ -127,11 +148,11 @@ class FileMetadata {
}
private class LineOffsetCounter extends CharHandler {
- private long currentOriginalOffset = 0;
- private List<Long> originalLineOffsets = new ArrayList<Long>();
+ private int currentOriginalOffset = 0;
+ private List<Integer> originalLineOffsets = new ArrayList<Integer>();
public LineOffsetCounter() {
- originalLineOffsets.add(0L);
+ originalLineOffsets.add(0);
}
@Override
@@ -144,41 +165,12 @@ class FileMetadata {
originalLineOffsets.add(currentOriginalOffset);
}
- public List<Long> getOriginalLineOffsets() {
+ public List<Integer> getOriginalLineOffsets() {
return originalLineOffsets;
}
}
- private class LineHashesComputer extends CharHandler {
- private List<Object> lineHashes = new ArrayList<Object>();
- private MessageDigest lineMd5Digest = DigestUtils.getMd5Digest();
- private boolean blankLine = true;
-
- @Override
- void handleIgnoreEoL(char c) {
- if (!Character.isWhitespace(c)) {
- blankLine = false;
- updateDigestUTF8Char(c, lineMd5Digest);
- }
- }
-
- @Override
- void newLine() {
- lineHashes.add(blankLine ? null : lineMd5Digest.digest());
- blankLine = true;
- }
-
- @Override
- void eof() {
- lineHashes.add(blankLine ? null : lineMd5Digest.digest());
- }
-
- public byte[][] lineHashes() {
- return lineHashes.toArray(new byte[0][]);
- }
- }
-
/**
* Compute hash of a file ignoring line ends differences.
* Maximum performance is needed.
@@ -188,8 +180,13 @@ class FileMetadata {
LineCounter lineCounter = new LineCounter();
FileHashComputer fileHashComputer = new FileHashComputer();
LineOffsetCounter lineOffsetCounter = new LineOffsetCounter();
- LineHashesComputer lineHashesComputer = new LineHashesComputer();
- CharHandler[] handlers = new CharHandler[] {lineCounter, fileHashComputer, lineOffsetCounter, lineHashesComputer};
+ CharHandler[] handlers;
+ if (analysisMode.isPreview()) {
+ // No need to compute line offsets in preview mode since there is no syntax highlighting
+ handlers = new CharHandler[] {lineCounter, fileHashComputer};
+ } else {
+ handlers = new CharHandler[] {lineCounter, fileHashComputer, lineOffsetCounter};
+ }
try (BOMInputStream bomIn = new BOMInputStream(new FileInputStream(file),
ByteOrderMark.UTF_8, ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_16BE, ByteOrderMark.UTF_32LE, ByteOrderMark.UTF_32BE);
Reader reader = new BufferedReader(new InputStreamReader(bomIn, encoding))) {
@@ -228,41 +225,26 @@ class FileMetadata {
handler.eof();
}
return new Metadata(lineCounter.lines(), lineCounter.nonBlankLines(), fileHashComputer.getHash(), lineOffsetCounter.getOriginalLineOffsets(),
- lineHashesComputer.lineHashes(), lineCounter.isEmpty());
+ lineCounter.isEmpty());
} catch (IOException e) {
throw new IllegalStateException(String.format("Fail to read file '%s' with encoding '%s'", file.getAbsolutePath(), encoding), e);
}
}
- private void updateDigestUTF8Char(char c, MessageDigest md5Digest) {
- CharBuffer cb = CharBuffer.allocate(1);
- cb.put(c);
- cb.flip();
- ByteBuffer bb = Charsets.UTF_8.encode(cb);
- byte[] array = bb.array();
- for (int i = 0; i < array.length; i++) {
- if (array[i] != 0) {
- md5Digest.update(array[i]);
- }
- }
- }
-
static class Metadata {
final int lines;
final int nonBlankLines;
final String hash;
- final long[] originalLineOffsets;
- final byte[][] lineHashes;
+ final int[] originalLineOffsets;
final boolean empty;
- private Metadata(int lines, int nonBlankLines, String hash, List<Long> originalLineOffsets, byte[][] lineHashes, boolean empty) {
+ private Metadata(int lines, int nonBlankLines, String hash, List<Integer> originalLineOffsets, boolean empty) {
this.lines = lines;
this.nonBlankLines = nonBlankLines;
this.hash = hash;
this.empty = empty;
- this.originalLineOffsets = Longs.toArray(originalLineOffsets);
- this.lineHashes = lineHashes;
+ this.originalLineOffsets = Ints.toArray(originalLineOffsets);
}
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputFileBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputFileBuilder.java
index 748410fea36..56b8319ac44 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputFileBuilder.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputFileBuilder.java
@@ -19,7 +19,6 @@
*/
package org.sonar.batch.scan.filesystem;
-import org.apache.commons.io.FilenameUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
@@ -29,12 +28,10 @@ import org.sonar.api.batch.fs.internal.DeprecatedDefaultInputFile;
import org.sonar.api.config.Settings;
import org.sonar.api.scan.filesystem.PathResolver;
import org.sonar.batch.bootstrap.DefaultAnalysisMode;
-import org.sonar.batch.util.DeprecatedKeyUtils;
import javax.annotation.CheckForNull;
import java.io.File;
-import java.util.List;
class InputFileBuilder {
@@ -47,9 +44,10 @@ class InputFileBuilder {
private final DefaultModuleFileSystem fs;
private final DefaultAnalysisMode analysisMode;
private final Settings settings;
+ private final FileMetadata fileMetadata;
InputFileBuilder(String moduleKey, PathResolver pathResolver, LanguageDetection langDetection,
- StatusDetection statusDetection, DefaultModuleFileSystem fs, DefaultAnalysisMode analysisMode, Settings settings) {
+ StatusDetection statusDetection, DefaultModuleFileSystem fs, DefaultAnalysisMode analysisMode, Settings settings, FileMetadata fileMetadata) {
this.moduleKey = moduleKey;
this.pathResolver = pathResolver;
this.langDetection = langDetection;
@@ -57,6 +55,7 @@ class InputFileBuilder {
this.fs = fs;
this.analysisMode = analysisMode;
this.settings = settings;
+ this.fileMetadata = fileMetadata;
}
String moduleKey() {
@@ -86,20 +85,17 @@ class InputFileBuilder {
LOG.warn("File '{}' is ignored. It is not located in module basedir '{}'.", file.getAbsolutePath(), fs.baseDir());
return null;
}
- DeprecatedDefaultInputFile inputFile = new DeprecatedDefaultInputFile(moduleKey, relativePath);
- inputFile.setBasedir(fs.baseDir());
- inputFile.setFile(file);
- return inputFile;
+ return new DeprecatedDefaultInputFile(moduleKey, relativePath);
}
/**
- * Optimization to not set all InputFile data if the file is excluded from analysis.
+ * Optimization to not compute InputFile metadata if the file is excluded from analysis.
*/
@CheckForNull
- DeprecatedDefaultInputFile complete(DeprecatedDefaultInputFile inputFile, InputFile.Type type) {
+ InputFileMetadata completeAndComputeMetadata(DeprecatedDefaultInputFile inputFile, InputFile.Type type) {
inputFile.setType(type);
- inputFile.setBasedir(fs.baseDir());
- inputFile.setEncoding(fs.encoding().name());
+ inputFile.setModuleBaseDir(fs.baseDir().toPath());
+ inputFile.setCharset(fs.encoding());
String lang = langDetection.language(inputFile);
if (lang == null && !settings.getBoolean(CoreProperties.IMPORT_UNKNOWN_FILES_KEY)) {
@@ -107,36 +103,21 @@ class InputFileBuilder {
}
inputFile.setLanguage(lang);
- FileMetadata.Metadata metadata = new FileMetadata().read(inputFile.file(), fs.encoding());
+ InputFileMetadata result = new InputFileMetadata();
+
+ FileMetadata.Metadata metadata = fileMetadata.read(inputFile.file(), fs.encoding());
inputFile.setLines(metadata.lines);
- inputFile.setNonBlankLines(metadata.nonBlankLines);
- inputFile.setHash(metadata.hash);
- inputFile.setOriginalLineOffsets(metadata.originalLineOffsets);
- inputFile.setLineHashes(metadata.lineHashes);
- inputFile.setEmpty(metadata.empty);
+
+ result.setNonBlankLines(metadata.nonBlankLines);
+ result.setHash(metadata.hash);
+ result.setOriginalLineOffsets(metadata.originalLineOffsets);
+ result.setEmpty(metadata.empty);
+
inputFile.setStatus(statusDetection.status(inputFile.moduleKey(), inputFile.relativePath(), metadata.hash));
if (analysisMode.isIncremental() && inputFile.status() == InputFile.Status.SAME) {
return null;
}
- fillDeprecatedData(inputFile);
- return inputFile;
+ return result;
}
- private void fillDeprecatedData(DeprecatedDefaultInputFile inputFile) {
- List<File> sourceDirs = InputFile.Type.MAIN == inputFile.type() ? fs.sourceDirs() : fs.testDirs();
- for (File sourceDir : sourceDirs) {
- String sourceRelativePath = pathResolver.relativePath(sourceDir, inputFile.file());
- if (sourceRelativePath != null) {
- inputFile.setPathRelativeToSourceDir(sourceRelativePath);
- inputFile.setSourceDirAbsolutePath(FilenameUtils.normalize(sourceDir.getAbsolutePath(), true));
-
- if ("java".equals(inputFile.language())) {
- inputFile.setDeprecatedKey(new StringBuilder()
- .append(moduleKey).append(":").append(DeprecatedKeyUtils.getJavaFileDeprecatedKey(sourceRelativePath)).toString());
- } else {
- inputFile.setDeprecatedKey(new StringBuilder().append(moduleKey).append(":").append(sourceRelativePath).toString());
- }
- }
- }
- }
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputFileBuilderFactory.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputFileBuilderFactory.java
index c3dde447e01..c173975fc53 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputFileBuilderFactory.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputFileBuilderFactory.java
@@ -33,15 +33,12 @@ public class InputFileBuilderFactory implements BatchComponent {
private final StatusDetectionFactory statusDetectionFactory;
private final DefaultAnalysisMode analysisMode;
private final Settings settings;
+ private final FileMetadata fileMetadata;
public InputFileBuilderFactory(ProjectDefinition def, PathResolver pathResolver, LanguageDetectionFactory langDetectionFactory,
- StatusDetectionFactory statusDetectionFactory, DefaultAnalysisMode analysisMode, Settings settings) {
- this(def.getKeyWithBranch(), pathResolver, langDetectionFactory, statusDetectionFactory, analysisMode, settings);
- }
-
- private InputFileBuilderFactory(String effectiveKey, PathResolver pathResolver, LanguageDetectionFactory langDetectionFactory,
- StatusDetectionFactory statusDetectionFactory, DefaultAnalysisMode analysisMode, Settings settings) {
- this.moduleKey = effectiveKey;
+ StatusDetectionFactory statusDetectionFactory, DefaultAnalysisMode analysisMode, Settings settings, FileMetadata fileMetadata) {
+ this.fileMetadata = fileMetadata;
+ this.moduleKey = def.getKeyWithBranch();
this.pathResolver = pathResolver;
this.langDetectionFactory = langDetectionFactory;
this.statusDetectionFactory = statusDetectionFactory;
@@ -50,6 +47,6 @@ public class InputFileBuilderFactory implements BatchComponent {
}
InputFileBuilder create(DefaultModuleFileSystem fs) {
- return new InputFileBuilder(moduleKey, pathResolver, langDetectionFactory.create(), statusDetectionFactory.create(), fs, analysisMode, settings);
+ return new InputFileBuilder(moduleKey, pathResolver, langDetectionFactory.create(), statusDetectionFactory.create(), fs, analysisMode, settings, fileMetadata);
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputFileMetadata.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputFileMetadata.java
new file mode 100644
index 00000000000..f37c672d101
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputFileMetadata.java
@@ -0,0 +1,73 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.batch.scan.filesystem;
+
+import java.io.Serializable;
+
+/**
+ * Additional input file metadata that are stored in a disk storage to save memory
+ */
+public class InputFileMetadata implements Serializable {
+
+ private String hash;
+ private int nonBlankLines;
+ private int[] originalLineOffsets;
+ private boolean empty;
+
+ /**
+ * Digest hash of the file.
+ */
+ public String hash() {
+ return hash;
+ }
+
+ public int nonBlankLines() {
+ return nonBlankLines;
+ }
+
+ public int[] originalLineOffsets() {
+ return originalLineOffsets;
+ }
+
+ public InputFileMetadata setHash(String hash) {
+ this.hash = hash;
+ return this;
+ }
+
+ public InputFileMetadata setNonBlankLines(int nonBlankLines) {
+ this.nonBlankLines = nonBlankLines;
+ return this;
+ }
+
+ public InputFileMetadata setOriginalLineOffsets(int[] originalLineOffsets) {
+ this.originalLineOffsets = originalLineOffsets;
+ return this;
+ }
+
+ public boolean isEmpty() {
+ return this.empty;
+ }
+
+ public InputFileMetadata setEmpty(boolean empty) {
+ this.empty = empty;
+ return this;
+ }
+
+}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputPathCache.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputPathCache.java
index adc1a16150c..6270eda9cf2 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputPathCache.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputPathCache.java
@@ -19,82 +19,133 @@
*/
package org.sonar.batch.scan.filesystem;
+import com.google.common.base.Function;
+import com.google.common.collect.Iterables;
import org.sonar.api.BatchComponent;
import org.sonar.api.batch.fs.InputDir;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.InputPath;
-import org.sonar.api.batch.fs.internal.DeprecatedDefaultInputFile;
import org.sonar.batch.index.BatchResource;
-import org.sonar.batch.index.Cache;
-import org.sonar.batch.index.Caches;
import javax.annotation.CheckForNull;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
/**
- * Cache of all files. This cache is shared amongst all project modules. Inclusion and
+ * Cache of all files and dirs. This cache is shared amongst all project modules. Inclusion and
* exclusion patterns are already applied.
*/
public class InputPathCache implements BatchComponent {
- private static final String DIR = "DIR";
- private static final String FILE = "FILE";
- // [module key | type | path] -> InputPath
- // For example:
- // [struts-core | FILE | src/main/java/Action.java] -> InputFile
- // [struts-core | FILE | src/main/java/Filter.java] -> InputFile
- // [struts-core | DIR | src/main/java] -> InputDir
- private final Cache<InputPath> cache;
-
- public InputPathCache(Caches caches) {
- caches.registerValueCoder(DeprecatedDefaultInputFile.class, new DefaultInputFileValueCoder());
- cache = caches.createCache("inputFiles");
+ private final Map<String, Map<String, InputFile>> inputFileCache = new HashMap<>();
+ private final Map<String, Map<String, InputDir>> inputDirCache = new HashMap<>();
+ private final Map<String, Map<String, InputFileMetadata>> inputFileMetadataCache = new HashMap<>();
+
+ public Iterable<InputFile> allFiles() {
+ return Iterables.concat(Iterables.transform(inputFileCache.values(), new Function<Map<String, InputFile>, Collection<InputFile>>() {
+ @Override
+ public Collection<InputFile> apply(Map<String, InputFile> input) {
+ return input.values();
+ }
+ }));
}
- public Iterable<InputPath> all() {
- return cache.values();
+ public Iterable<InputDir> allDirs() {
+ return Iterables.concat(Iterables.transform(inputDirCache.values(), new Function<Map<String, InputDir>, Collection<InputDir>>() {
+ @Override
+ public Collection<InputDir> apply(Map<String, InputDir> input) {
+ return input.values();
+ }
+ }));
}
public Iterable<InputFile> filesByModule(String moduleKey) {
- return (Iterable) cache.values(moduleKey, FILE);
+ if (inputFileCache.containsKey(moduleKey)) {
+ return inputFileCache.get(moduleKey).values();
+ }
+ return Collections.emptyList();
}
public Iterable<InputDir> dirsByModule(String moduleKey) {
- return (Iterable) cache.values(moduleKey, DIR);
+ if (inputDirCache.containsKey(moduleKey)) {
+ return inputDirCache.get(moduleKey).values();
+ }
+ return Collections.emptyList();
}
public InputPathCache removeModule(String moduleKey) {
- cache.clear(moduleKey);
+ inputFileCache.remove(moduleKey);
+ inputDirCache.remove(moduleKey);
+ inputFileMetadataCache.remove(moduleKey);
return this;
}
public InputPathCache remove(String moduleKey, InputFile inputFile) {
- cache.remove(moduleKey, FILE, inputFile.relativePath());
+ if (inputFileCache.containsKey(moduleKey)) {
+ inputFileCache.get(moduleKey).remove(inputFile.relativePath());
+ }
+ if (inputFileMetadataCache.containsKey(moduleKey)) {
+ inputFileMetadataCache.get(moduleKey).remove(inputFile.relativePath());
+ }
return this;
}
public InputPathCache remove(String moduleKey, InputDir inputDir) {
- cache.remove(moduleKey, DIR, inputDir.relativePath());
+ if (inputDirCache.containsKey(moduleKey)) {
+ inputDirCache.get(moduleKey).remove(inputDir.relativePath());
+ }
return this;
}
public InputPathCache put(String moduleKey, InputFile inputFile) {
- cache.put(moduleKey, FILE, inputFile.relativePath(), inputFile);
+ if (!inputFileCache.containsKey(moduleKey)) {
+ inputFileCache.put(moduleKey, new HashMap<String, InputFile>());
+ }
+ inputFileCache.get(moduleKey).put(inputFile.relativePath(), inputFile);
+ return this;
+ }
+
+ public synchronized InputPathCache put(String moduleKey, String relativePath, InputFileMetadata metadata) {
+ if (!inputFileMetadataCache.containsKey(moduleKey)) {
+ inputFileMetadataCache.put(moduleKey, new HashMap<String, InputFileMetadata>());
+ }
+ inputFileMetadataCache.get(moduleKey).put(relativePath, metadata);
return this;
}
public InputPathCache put(String moduleKey, InputDir inputDir) {
- cache.put(moduleKey, DIR, inputDir.relativePath(), inputDir);
+ if (!inputDirCache.containsKey(moduleKey)) {
+ inputDirCache.put(moduleKey, new HashMap<String, InputDir>());
+ }
+ inputDirCache.get(moduleKey).put(inputDir.relativePath(), inputDir);
return this;
}
@CheckForNull
public InputFile getFile(String moduleKey, String relativePath) {
- return (InputFile) cache.get(moduleKey, FILE, relativePath);
+ if (inputFileCache.containsKey(moduleKey)) {
+ return inputFileCache.get(moduleKey).get(relativePath);
+ }
+ return null;
+ }
+
+ @CheckForNull
+ public InputFileMetadata getFileMetadata(String moduleKey, String relativePath) {
+ if (inputFileMetadataCache.containsKey(moduleKey)) {
+ return inputFileMetadataCache.get(moduleKey).get(relativePath);
+ }
+ return null;
}
@CheckForNull
public InputDir getDir(String moduleKey, String relativePath) {
- return (InputDir) cache.get(moduleKey, DIR, relativePath);
+ if (inputDirCache.containsKey(moduleKey)) {
+ return inputDirCache.get(moduleKey).get(relativePath);
+ }
+ return null;
}
@CheckForNull
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/LanguageDetection.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/LanguageDetection.java
index 1ee5379f579..131ac8a4ca4 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/LanguageDetection.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/LanguageDetection.java
@@ -19,7 +19,8 @@
*/
package org.sonar.batch.scan.filesystem;
-import org.sonar.batch.languages.Language;
+import org.sonar.batch.repository.language.Language;
+import org.sonar.batch.repository.language.LanguagesRepository;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
@@ -32,7 +33,6 @@ import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.PathPattern;
import org.sonar.api.config.Settings;
import org.sonar.api.utils.MessageException;
-import org.sonar.batch.languages.LanguagesReferential;
import javax.annotation.CheckForNull;
@@ -54,7 +54,7 @@ class LanguageDetection {
private final List<String> languagesToConsider = Lists.newArrayList();
private final String forcedLanguage;
- LanguageDetection(Settings settings, LanguagesReferential languages) {
+ LanguageDetection(Settings settings, LanguagesRepository languages) {
for (Language language : languages.all()) {
String[] filePatterns = settings.getStringArray(getFileLangPatternPropKey(language.key()));
PathPattern[] pathPatterns = PathPattern.create(filePatterns);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/LanguageDetectionFactory.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/LanguageDetectionFactory.java
index 6ff579fd769..c52118612c3 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/LanguageDetectionFactory.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/LanguageDetectionFactory.java
@@ -19,15 +19,16 @@
*/
package org.sonar.batch.scan.filesystem;
+import org.sonar.batch.repository.language.LanguagesRepository;
+
import org.sonar.api.BatchComponent;
import org.sonar.api.config.Settings;
-import org.sonar.batch.languages.LanguagesReferential;
public class LanguageDetectionFactory implements BatchComponent {
private final Settings settings;
- private final LanguagesReferential languages;
+ private final LanguagesRepository languages;
- public LanguageDetectionFactory(Settings settings, LanguagesReferential languages) {
+ public LanguageDetectionFactory(Settings settings, LanguagesRepository languages) {
this.settings = settings;
this.languages = languages;
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ModuleInputFileCache.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ModuleInputFileCache.java
index b932295dc40..17420fc2dc8 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ModuleInputFileCache.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ModuleInputFileCache.java
@@ -28,35 +28,35 @@ import org.sonar.api.batch.fs.internal.DefaultFileSystem;
public class ModuleInputFileCache extends DefaultFileSystem.Cache implements BatchComponent {
private final String moduleKey;
- private final InputPathCache projectCache;
+ private final InputPathCache inputPathCache;
public ModuleInputFileCache(ProjectDefinition projectDef, InputPathCache projectCache) {
this.moduleKey = projectDef.getKeyWithBranch();
- this.projectCache = projectCache;
+ this.inputPathCache = projectCache;
}
@Override
public Iterable<InputFile> inputFiles() {
- return projectCache.filesByModule(moduleKey);
+ return inputPathCache.filesByModule(moduleKey);
}
@Override
public InputFile inputFile(String relativePath) {
- return projectCache.getFile(moduleKey, relativePath);
+ return inputPathCache.getFile(moduleKey, relativePath);
}
@Override
public InputDir inputDir(String relativePath) {
- return projectCache.getDir(moduleKey, relativePath);
+ return inputPathCache.getDir(moduleKey, relativePath);
}
@Override
protected void doAdd(InputFile inputFile) {
- projectCache.put(moduleKey, inputFile);
+ inputPathCache.put(moduleKey, inputFile);
}
@Override
protected void doAdd(InputDir inputDir) {
- projectCache.put(moduleKey, inputDir);
+ inputPathCache.put(moduleKey, inputDir);
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/JSONReport.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/JSONReport.java
index d4fd9b69231..19523999ab0 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/JSONReport.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/JSONReport.java
@@ -30,7 +30,6 @@ import org.sonar.api.PropertyType;
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.InputPath;
import org.sonar.api.batch.fs.internal.DefaultInputDir;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.rule.ActiveRules;
@@ -43,9 +42,9 @@ import org.sonar.api.rule.RuleKey;
import org.sonar.api.utils.SonarException;
import org.sonar.api.utils.text.JsonWriter;
import org.sonar.batch.issue.IssueCache;
+import org.sonar.batch.repository.user.User;
+import org.sonar.batch.repository.user.UserRepository;
import org.sonar.batch.scan.filesystem.InputPathCache;
-import org.sonar.batch.user.User;
-import org.sonar.batch.user.UserRepository;
import java.io.BufferedWriter;
import java.io.File;
@@ -167,27 +166,24 @@ public class JSONReport implements Reporter {
json.name("components").beginArray();
// Dump modules
writeJsonModuleComponents(json, rootModule);
- for (InputPath inputPath : fileCache.all()) {
- if (inputPath instanceof InputFile) {
- InputFile inputFile = (InputFile) inputPath;
- String key = ((DefaultInputFile) inputFile).key();
- json
- .beginObject()
- .prop("key", key)
- .prop("path", inputFile.relativePath())
- .prop("moduleKey", StringUtils.substringBeforeLast(key, ":"))
- .prop("status", inputFile.status().name())
- .endObject();
- } else {
- InputDir inputDir = (InputDir) inputPath;
- String key = ((DefaultInputDir) inputDir).key();
- json
- .beginObject()
- .prop("key", key)
- .prop("path", inputDir.relativePath())
- .prop("moduleKey", StringUtils.substringBeforeLast(key, ":"))
- .endObject();
- }
+ for (InputFile inputFile : fileCache.allFiles()) {
+ String key = ((DefaultInputFile) inputFile).key();
+ json
+ .beginObject()
+ .prop("key", key)
+ .prop("path", inputFile.relativePath())
+ .prop("moduleKey", StringUtils.substringBeforeLast(key, ":"))
+ .prop("status", inputFile.status().name())
+ .endObject();
+ }
+ for (InputDir inputDir : fileCache.allDirs()) {
+ String key = ((DefaultInputDir) inputDir).key();
+ json
+ .beginObject()
+ .prop("key", key)
+ .prop("path", inputDir.relativePath())
+ .prop("moduleKey", StringUtils.substringBeforeLast(key, ":"))
+ .endObject();
}
json.endArray();
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java b/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java
index 2a33ed3b3fb..74fccaa446a 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java
@@ -35,6 +35,8 @@ import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.utils.TimeProfiler;
import org.sonar.batch.protocol.input.FileData;
import org.sonar.batch.protocol.input.ProjectRepositories;
+import org.sonar.batch.scan.filesystem.InputFileMetadata;
+import org.sonar.batch.scan.filesystem.InputPathCache;
import java.util.LinkedList;
import java.util.List;
@@ -47,13 +49,15 @@ public final class ScmSensor implements Sensor {
private final ScmConfiguration configuration;
private final FileSystem fs;
private final ProjectRepositories projectReferentials;
+ private final InputPathCache inputPathCache;
public ScmSensor(ProjectDefinition projectDefinition, ScmConfiguration configuration,
- ProjectRepositories projectReferentials, FileSystem fs) {
+ ProjectRepositories projectReferentials, FileSystem fs, InputPathCache inputPathCache) {
this.projectDefinition = projectDefinition;
this.configuration = configuration;
this.projectReferentials = projectReferentials;
this.fs = fs;
+ this.inputPathCache = inputPathCache;
}
@Override
@@ -104,7 +108,7 @@ public final class ScmSensor implements Sensor {
if (f.status() == Status.SAME && fileData != null) {
if (fileData.needBlame()) {
- addIfNotEmpty(filesToBlame, f);
+ addIfNotEmpty(filesToBlame, (DefaultInputFile) f);
} else {
// Copy previous measures
String scmAuthorsByLine = fileData.scmAuthorsByLine();
@@ -117,12 +121,13 @@ public final class ScmSensor implements Sensor {
}
}
} else {
- addIfNotEmpty(filesToBlame, f);
+ addIfNotEmpty(filesToBlame, (DefaultInputFile) f);
}
}
- private void addIfNotEmpty(List<InputFile> filesToBlame, InputFile f) {
- if (!((DefaultInputFile) f).isEmpty()) {
+ private void addIfNotEmpty(List<InputFile> filesToBlame, DefaultInputFile f) {
+ InputFileMetadata metadata = inputPathCache.getFileMetadata(f.moduleKey(), f.relativePath());
+ if (!metadata.isEmpty()) {
filesToBlame.add(f);
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/source/CodeColorizers.java b/sonar-batch/src/main/java/org/sonar/batch/source/CodeColorizers.java
index f0d4789f7bc..4b99191538a 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/source/CodeColorizers.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/source/CodeColorizers.java
@@ -37,6 +37,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.Reader;
+import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -67,7 +68,7 @@ public class CodeColorizers implements BatchComponent {
}
@CheckForNull
- public SyntaxHighlightingData toSyntaxHighlighting(File file, String encoding, String language) {
+ public SyntaxHighlightingData toSyntaxHighlighting(File file, Charset charset, String language) {
CodeColorizerFormat format = byLang.get(language);
List<Tokenizer> tokenizers;
if (format == null) {
@@ -81,7 +82,7 @@ public class CodeColorizers implements BatchComponent {
} else {
tokenizers = format.getTokenizers();
}
- try (Reader reader = new BufferedReader(new InputStreamReader(new BOMInputStream(new FileInputStream(file)), encoding))) {
+ try (Reader reader = new BufferedReader(new InputStreamReader(new BOMInputStream(new FileInputStream(file)), charset))) {
return new HighlightingRenderer().render(reader, tokenizers);
} catch (Exception e) {
throw new IllegalStateException("Unable to read source file for colorization", e);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/source/LinesSensor.java b/sonar-batch/src/main/java/org/sonar/batch/source/LinesSensor.java
index 4829066972a..b2f159d0997 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/source/LinesSensor.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/source/LinesSensor.java
@@ -29,14 +29,16 @@ import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.batch.sensor.SensorDescriptor;
import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure;
import org.sonar.api.measures.CoreMetrics;
+import org.sonar.batch.scan.filesystem.InputFileMetadata;
+import org.sonar.batch.scan.filesystem.InputPathCache;
@Phase(name = Phase.Name.PRE)
public final class LinesSensor implements Sensor {
- private final FileSystem fs;
+ private final InputPathCache inputPathCache;
- public LinesSensor(FileSystem fs) {
- this.fs = fs;
+ public LinesSensor(InputPathCache inputPathCache) {
+ this.inputPathCache = inputPathCache;
}
@Override
@@ -46,6 +48,7 @@ public final class LinesSensor implements Sensor {
@Override
public void execute(final SensorContext context) {
+ FileSystem fs = context.fileSystem();
for (InputFile f : fs.inputFiles(fs.predicates().hasType(Type.MAIN))) {
((DefaultMeasure<Integer>) context.<Integer>newMeasure()
.onFile(f)
@@ -55,10 +58,11 @@ public final class LinesSensor implements Sensor {
.save();
if (f.language() == null) {
// As an approximation for files with no language plugin we consider every non blank line as ncloc
+ InputFileMetadata metadata = inputPathCache.getFileMetadata(((DefaultInputFile) f).moduleKey(), f.relativePath());
((DefaultMeasure<Integer>) context.<Integer>newMeasure()
.onFile(f)
.forMetric(CoreMetrics.NCLOC)
- .withValue(((DefaultInputFile) f).nonBlankLines()))
+ .withValue(metadata.nonBlankLines()))
.save();
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/DefaultFileLinesContextTest.java b/sonar-batch/src/test/java/org/sonar/batch/DefaultFileLinesContextTest.java
index 9bf9dc201d4..e85e6003c2f 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/DefaultFileLinesContextTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/DefaultFileLinesContextTest.java
@@ -57,7 +57,7 @@ public class DefaultFileLinesContextTest {
@Test(expected = IllegalArgumentException.class)
public void shouldNotAllowCreationForDirectory() {
- new DefaultFileLinesContext(index, new Directory("key"));
+ new DefaultFileLinesContext(index, Directory.create("key"));
}
@Test
diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastMeasuresLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastMeasuresLoaderTest.java
index 4be6293c27a..d032e2b1cd1 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/components/PastMeasuresLoaderTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/components/PastMeasuresLoaderTest.java
@@ -19,6 +19,8 @@
*/
package org.sonar.batch.components;
+import org.sonar.batch.components.PastMeasuresLoader;
+
import org.junit.Test;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.measures.Metric;
diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java
index c335d3b87d6..f712b04dbc4 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java
@@ -19,6 +19,12 @@
*/
package org.sonar.batch.components;
+import org.sonar.batch.components.PastSnapshotFinder;
+import org.sonar.batch.deprecated.components.PastSnapshotFinderByDate;
+import org.sonar.batch.deprecated.components.PastSnapshotFinderByDays;
+import org.sonar.batch.deprecated.components.PastSnapshotFinderByPreviousAnalysis;
+import org.sonar.batch.deprecated.components.PastSnapshotFinderByPreviousVersion;
+import org.sonar.batch.deprecated.components.PastSnapshotFinderByVersion;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentMatcher;
diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java
index 3d38431f780..201155b1188 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java
@@ -19,6 +19,8 @@
*/
package org.sonar.batch.components;
+import org.sonar.batch.components.PastSnapshot;
+
import org.junit.Test;
import org.sonar.api.CoreProperties;
import org.sonar.api.database.model.Snapshot;
diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/TimeMachineConfigurationTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/TimeMachineConfigurationTest.java
index 023690acdbd..eae7b0f8377 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/components/TimeMachineConfigurationTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/components/TimeMachineConfigurationTest.java
@@ -19,6 +19,10 @@
*/
package org.sonar.batch.components;
+import org.sonar.batch.components.TimeMachineConfiguration;
+
+import org.sonar.batch.components.PastSnapshot;
+import org.sonar.batch.deprecated.components.PeriodsDefinition;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.database.model.Snapshot;
diff --git a/sonar-batch/src/test/java/org/sonar/batch/debt/DebtDecoratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/debt/DebtDecoratorTest.java
index 945a3d7614b..7cb4b47c1c5 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/debt/DebtDecoratorTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/debt/DebtDecoratorTest.java
@@ -247,7 +247,7 @@ public class DebtDecoratorTest {
// or for a file
context = mock(DecoratorContext.class);
- when(context.getResource()).thenReturn(new File("foo"));
+ when(context.getResource()).thenReturn(File.create("foo"));
decorator.saveCharacteristicMeasure(context, (Characteristic) null, 12.0, false);
verify(context, times(1)).saveMeasure(new Measure(CoreMetrics.TECHNICAL_DEBT));
}
@@ -282,7 +282,7 @@ public class DebtDecoratorTest {
@Test
public void not_save_technical_debt_for_file_if_zero() throws Exception {
DecoratorContext context = mock(DecoratorContext.class);
- when(context.getResource()).thenReturn(new File("foo"));
+ when(context.getResource()).thenReturn(File.create("foo"));
decorator.saveCharacteristicMeasure(context, null, 0.0, true);
verify(context, never()).saveMeasure(new Measure(CoreMetrics.TECHNICAL_DEBT));
diff --git a/sonar-batch/src/test/java/org/sonar/batch/debt/NewDebtDecoratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/debt/NewDebtDecoratorTest.java
index 0bb25ad1d82..c930eb1075e 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/debt/NewDebtDecoratorTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/debt/NewDebtDecoratorTest.java
@@ -20,6 +20,9 @@
package org.sonar.batch.debt;
+import org.sonar.batch.components.TimeMachineConfiguration;
+
+import org.sonar.batch.deprecated.components.Period;
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.time.DateUtils;
import org.junit.Before;
@@ -42,8 +45,6 @@ import org.sonar.api.measures.Metric;
import org.sonar.api.resources.Resource;
import org.sonar.api.test.IsMeasure;
import org.sonar.api.utils.Duration;
-import org.sonar.batch.components.Period;
-import org.sonar.batch.components.TimeMachineConfiguration;
import org.sonar.batch.debt.IssueChangelogDebtCalculator;
import org.sonar.batch.debt.NewDebtDecorator;
diff --git a/sonar-batch/src/test/java/org/sonar/batch/debt/SqaleRatingDecoratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/debt/SqaleRatingDecoratorTest.java
index 0caa8cf219e..79ce075a097 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/debt/SqaleRatingDecoratorTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/debt/SqaleRatingDecoratorTest.java
@@ -73,10 +73,9 @@ public class SqaleRatingDecoratorTest {
public void setUp() throws Exception {
settings = new Settings();
- fs = new DefaultFileSystem(temp.newFolder());
+ fs = new DefaultFileSystem(temp.newFolder().toPath());
fs.add(new DefaultInputFile("foo", file.getPath())
- .setLanguage("java")
- .setFile(temp.newFile("Foo.java")));
+ .setLanguage("java"));
decorator = new SqaleRatingDecorator(new SqaleRatingSettings(settings), metrics, fs);
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/ResourceFiltersTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/ResourceFiltersTest.java
index 602b6c7dd42..c93334474b2 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/ResourceFiltersTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/deprecated/ResourceFiltersTest.java
@@ -17,7 +17,7 @@
* 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.batch;
+package org.sonar.batch.deprecated;
import org.junit.Test;
import org.slf4j.Logger;
diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByDateTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDateTest.java
index 7abd043f62b..2cf8b317531 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByDateTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDateTest.java
@@ -17,8 +17,11 @@
* 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.batch.components;
+package org.sonar.batch.deprecated.components;
+import org.sonar.batch.components.PastSnapshot;
+
+import org.sonar.batch.deprecated.components.PastSnapshotFinderByDate;
import org.junit.Test;
import org.sonar.api.database.model.Snapshot;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByDaysTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDaysTest.java
index 1b136e9ae72..0515b30673d 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByDaysTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDaysTest.java
@@ -17,7 +17,9 @@
* 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.batch.components;
+package org.sonar.batch.deprecated.components;
+
+import org.sonar.batch.deprecated.components.PastSnapshotFinderByDays;
import org.hamcrest.core.IsNull;
import org.junit.Test;
diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousAnalysisTest.java
index a2c0d82e301..9ec2024b7d4 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousAnalysisTest.java
@@ -17,12 +17,14 @@
* 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.batch.components;
+package org.sonar.batch.deprecated.components;
+import org.sonar.batch.components.PastSnapshot;
+
+import org.sonar.batch.deprecated.components.PastSnapshotFinderByPreviousAnalysis;
import org.junit.Test;
import org.sonar.api.database.model.Snapshot;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
-
import static org.hamcrest.Matchers.is;
import static org.hamcrest.core.IsNull.nullValue;
import static org.junit.Assert.assertThat;
diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest.java
index da160c87a4f..d932060914a 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest.java
@@ -17,13 +17,15 @@
* 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.batch.components;
+package org.sonar.batch.deprecated.components;
+import org.sonar.batch.components.PastSnapshot;
+
+import org.sonar.batch.deprecated.components.PastSnapshotFinderByPreviousVersion;
import org.junit.Test;
import org.sonar.api.CoreProperties;
import org.sonar.api.database.model.Snapshot;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
-
import static org.assertj.core.api.Assertions.assertThat;
public class PastSnapshotFinderByPreviousVersionTest extends AbstractDbUnitTestCase {
diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByVersionTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByVersionTest.java
index b35f4b8990b..5d8c87ad7f0 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByVersionTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByVersionTest.java
@@ -17,13 +17,15 @@
* 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.batch.components;
+package org.sonar.batch.deprecated.components;
+import org.sonar.batch.components.PastSnapshot;
+
+import org.sonar.batch.deprecated.components.PastSnapshotFinderByVersion;
import org.junit.Test;
import org.sonar.api.CoreProperties;
import org.sonar.api.database.model.Snapshot;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
-
import static org.assertj.core.api.Assertions.assertThat;
public class PastSnapshotFinderByVersionTest extends AbstractDbUnitTestCase {
diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PeriodsDefinitionTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PeriodsDefinitionTest.java
index 7483d54cf23..425ce9e4e89 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/components/PeriodsDefinitionTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PeriodsDefinitionTest.java
@@ -18,8 +18,11 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-package org.sonar.batch.components;
+package org.sonar.batch.deprecated.components;
+import org.sonar.batch.components.PastSnapshotFinder;
+
+import org.sonar.batch.deprecated.components.PeriodsDefinition;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentMatcher;
@@ -28,7 +31,6 @@ import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.Project;
import org.sonar.batch.ProjectTree;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
-
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.argThat;
import static org.mockito.Matchers.eq;
diff --git a/sonar-batch/src/test/java/org/sonar/batch/DecoratorsSelectorTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/decorator/DecoratorsSelectorTest.java
index 8a0e9a24764..f469d6b52e9 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/DecoratorsSelectorTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/deprecated/decorator/DecoratorsSelectorTest.java
@@ -17,7 +17,7 @@
* 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.batch;
+package org.sonar.batch.deprecated.decorator;
import com.google.common.collect.Iterables;
import org.junit.Test;
diff --git a/sonar-batch/src/test/java/org/sonar/batch/FormulaDecoratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/decorator/FormulaDecoratorTest.java
index ff5fdc5d159..4507ab8cbc0 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/FormulaDecoratorTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/deprecated/decorator/FormulaDecoratorTest.java
@@ -17,7 +17,9 @@
* 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.batch;
+package org.sonar.batch.deprecated.decorator;
+
+import org.sonar.batch.deprecated.decorator.FormulaDecorator;
import org.junit.Test;
import org.sonar.api.batch.DecoratorContext;
diff --git a/sonar-batch/src/test/java/org/sonar/batch/tasks/ListTaskTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/tasks/ListTaskTest.java
index 923af5177e5..2812b4d28cf 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/tasks/ListTaskTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/deprecated/tasks/ListTaskTest.java
@@ -17,7 +17,10 @@
* 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.batch.tasks;
+package org.sonar.batch.deprecated.tasks;
+
+import org.sonar.batch.deprecated.tasks.ListTask;
+import org.sonar.batch.deprecated.tasks.Tasks;
import org.junit.Test;
import org.sonar.api.task.Task;
diff --git a/sonar-batch/src/test/java/org/sonar/batch/tasks/TasksTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/tasks/TasksTest.java
index 5c4315890c2..51f6eb1c53b 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/tasks/TasksTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/deprecated/tasks/TasksTest.java
@@ -17,7 +17,7 @@
* 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.batch.tasks;
+package org.sonar.batch.deprecated.tasks;
import org.junit.Rule;
import org.junit.Test;
@@ -36,20 +36,20 @@ public class TasksTest {
@Test
public void should_get_definitions() {
- Tasks tasks = new Tasks(new TaskDefinition[]{ScanTask.DEFINITION, ListTask.DEFINITION});
+ Tasks tasks = new Tasks(new TaskDefinition[] {ScanTask.DEFINITION, ListTask.DEFINITION});
assertThat(tasks.definitions()).hasSize(2);
}
@Test
public void should_get_definition_by_key() {
- Tasks tasks = new Tasks(new TaskDefinition[]{ScanTask.DEFINITION, ListTask.DEFINITION});
+ Tasks tasks = new Tasks(new TaskDefinition[] {ScanTask.DEFINITION, ListTask.DEFINITION});
tasks.start();
assertThat(tasks.definition(ListTask.DEFINITION.key())).isEqualTo(ListTask.DEFINITION);
}
@Test
public void should_return_null_if_task_not_found() {
- Tasks tasks = new Tasks(new TaskDefinition[]{ScanTask.DEFINITION, ListTask.DEFINITION});
+ Tasks tasks = new Tasks(new TaskDefinition[] {ScanTask.DEFINITION, ListTask.DEFINITION});
assertThat(tasks.definition("not-exists")).isNull();
}
@@ -59,7 +59,7 @@ public class TasksTest {
thrown.expect(SonarException.class);
thrown.expectMessage("Task 'foo' is declared twice");
- new Tasks(new TaskDefinition[]{
+ new Tasks(new TaskDefinition[] {
TaskDefinition.builder().key("foo").taskClass(FakeTask1.class).description("foo1").build(),
TaskDefinition.builder().key("foo").taskClass(FakeTask2.class).description("foo2").build()
});
@@ -67,13 +67,13 @@ public class TasksTest {
@Test
public void should_fail_on_duplicated_class() {
- Tasks tasks = new Tasks(new TaskDefinition[]{
+ Tasks tasks = new Tasks(new TaskDefinition[] {
TaskDefinition.builder().key("foo1").taskClass(FakeTask1.class).description("foo1").build(),
TaskDefinition.builder().key("foo2").taskClass(FakeTask1.class).description("foo1").build()
});
thrown.expect(SonarException.class);
- thrown.expectMessage("Task 'org.sonar.batch.tasks.TasksTest$FakeTask1' is defined twice: first by 'foo1' and then by 'foo2'");
+ thrown.expectMessage("Task 'org.sonar.batch.deprecated.tasks.TasksTest$FakeTask1' is defined twice: first by 'foo1' and then by 'foo2'");
tasks.start();
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/design/DirectoryDsmDecoratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/design/DirectoryDsmDecoratorTest.java
index 598bf4d6f88..fa3ceecc3a5 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/design/DirectoryDsmDecoratorTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/design/DirectoryDsmDecoratorTest.java
@@ -65,9 +65,9 @@ public class DirectoryDsmDecoratorTest {
dir = Directory.create("src");
dirContext = mock(DecoratorContext.class);
- file1 = File.create("src/Foo1.java", "Foo1.java", null, false);
+ file1 = File.create("src/Foo1.java", null, false);
file1.setId(1);
- file2 = File.create("src/Foo2.java", "Foo2.java", null, false);
+ file2 = File.create("src/Foo2.java", null, false);
file2.setId(2);
file1Context = mock(DecoratorContext.class);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/design/DsmSerializerTest.java b/sonar-batch/src/test/java/org/sonar/batch/design/DsmSerializerTest.java
index 24d949d000c..5d9b0b508ef 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/design/DsmSerializerTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/design/DsmSerializerTest.java
@@ -43,8 +43,8 @@ public class DsmSerializerTest {
@Test
public void serialize() throws IOException {
- Resource foo = Directory.create("src/org/foo", "org/foo").setId(7);
- Resource bar = Directory.create("src/org/bar", "org/bar").setId(8);
+ Resource foo = Directory.create("src/org/foo").setId(7);
+ Resource bar = Directory.create("src/org/bar").setId(8);
Dependency dep = new Dependency(foo, bar).setId(30l).setWeight(1);
DirectedGraph<Resource, Dependency> graph = new DirectedGraph<Resource, Dependency>();
diff --git a/sonar-batch/src/test/java/org/sonar/batch/design/SubProjectDsmDecoratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/design/SubProjectDsmDecoratorTest.java
index 94d7d621108..a9a41264adf 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/design/SubProjectDsmDecoratorTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/design/SubProjectDsmDecoratorTest.java
@@ -60,9 +60,9 @@ public class SubProjectDsmDecoratorTest {
module = new Project("foo");
moduleContext = mock(DecoratorContext.class);
- dir1 = Directory.create("src/foo1", "foo1");
+ dir1 = Directory.create("src/foo1");
dir1.setId(1);
- dir2 = Directory.create("src/foo2", "foo2");
+ dir2 = Directory.create("src/foo2");
dir2.setId(2);
DecoratorContext dir1Context = mock(DecoratorContext.class);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/BucketTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/BucketTest.java
index 51a9c0269c9..97bdb61d75e 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/BucketTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/BucketTest.java
@@ -24,17 +24,17 @@ import org.sonar.api.measures.Metric;
import org.sonar.api.resources.Directory;
import org.sonar.api.resources.File;
+import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
-import static org.hamcrest.Matchers.hasItem;
public class BucketTest {
- Directory directory = new Directory("org/foo");
- File javaFile = new File("org/foo/Bar.java");
+ Directory directory = Directory.create("org/foo");
+ File javaFile = File.create("org/foo/Bar.java");
Metric ncloc = new Metric("ncloc");
@Test
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java
index ca7a86e791c..fe541281e05 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java
@@ -95,10 +95,10 @@ public class DefaultIndexTest {
@Test
public void shouldIndexParentOfDeprecatedFiles() {
- File file = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", null, false);
+ File file = File.create("src/org/foo/Bar.java", null, false);
assertThat(index.index(file)).isTrue();
- Directory reference = Directory.create("src/org/foo", "org/foo");
+ Directory reference = Directory.create("src/org/foo");
assertThat(index.getResource(reference).getName()).isEqualTo("src/org/foo");
assertThat(index.isIndexed(reference, true)).isTrue();
assertThat(index.isExcluded(reference)).isFalse();
@@ -108,15 +108,14 @@ public class DefaultIndexTest {
@Test
public void shouldIndexTreeOfResources() {
- Directory directory = Directory.create("src/org/foo", "org/foo");
- File file = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", Java.INSTANCE, false);
+ Directory directory = Directory.create("src/org/foo");
+ File file = File.create("src/org/foo/Bar.java", Java.INSTANCE, false);
assertThat(index.index(directory)).isTrue();
assertThat(index.index(file, directory)).isTrue();
- File fileRef = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", null, false);
+ File fileRef = File.create("src/org/foo/Bar.java", null, false);
assertThat(index.getResource(fileRef).getKey()).isEqualTo("src/org/foo/Bar.java");
- assertThat(index.getResource(fileRef).getDeprecatedKey()).isEqualTo("org/foo/Bar.java");
assertThat(index.getResource(fileRef).getLanguage().getKey()).isEqualTo("java");
assertThat(index.isIndexed(fileRef, true)).isTrue();
assertThat(index.isExcluded(fileRef)).isFalse();
@@ -126,14 +125,14 @@ public class DefaultIndexTest {
@Test
public void shouldGetSource() throws Exception {
- Directory directory = Directory.create("src/org/foo", "org/foo");
- File file = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", Java.INSTANCE, false);
+ Directory directory = Directory.create("src/org/foo");
+ File file = File.create("src/org/foo/Bar.java", Java.INSTANCE, false);
FileUtils.write(new java.io.File(baseDir, "src/org/foo/Bar.java"), "Foo bar");
assertThat(index.index(directory)).isTrue();
assertThat(index.index(file, directory)).isTrue();
- File fileRef = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", null, false);
+ File fileRef = File.create("src/org/foo/Bar.java", null, false);
assertThat(index.getSource(fileRef)).isEqualTo("Foo bar");
}
@@ -150,12 +149,12 @@ public class DefaultIndexTest {
@Test
public void shouldNotIndexResourceIfParentNotIndexed() {
- Directory directory = Directory.create("src/org/other", "org/other");
- File file = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", null, false);
+ Directory directory = Directory.create("src/org/other");
+ File file = File.create("src/org/foo/Bar.java", null, false);
assertThat(index.index(file, directory)).isFalse();
- File fileRef = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", null, false);
+ File fileRef = File.create("src/org/foo/Bar.java", null, false);
assertThat(index.isIndexed(directory, true)).isFalse();
assertThat(index.isIndexed(fileRef, true)).isFalse();
assertThat(index.isExcluded(fileRef)).isFalse();
@@ -165,7 +164,7 @@ public class DefaultIndexTest {
@Test
public void shouldNotIndexResourceWhenAddingMeasure() {
- Resource dir = Directory.create("src/org/foo", "org/foo");
+ Resource dir = Directory.create("src/org/foo");
index.addMeasure(dir, new Measure("ncloc").setValue(50.0));
assertThat(index.isIndexed(dir, true)).isFalse();
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/DuplicationPersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/DuplicationPersisterTest.java
index 3517b28789f..a62dd075bb5 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/DuplicationPersisterTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/DuplicationPersisterTest.java
@@ -46,7 +46,7 @@ public class DuplicationPersisterTest extends AbstractDaoTestCase {
DuplicationPersister duplicationPersister;
RuleFinder ruleFinder = mock(RuleFinder.class);
- File aFile = new File("org/foo/Bar.java");
+ File aFile = File.create("org/foo/Bar.java");
Snapshot fileSnapshot = snapshot(FILE_SNAPSHOT_ID);
private DuplicationCache duplicationCache;
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java
index b5cfb38c063..fb59aa4d0a5 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java
@@ -61,8 +61,8 @@ public class MeasurePersisterTest extends AbstractDaoTestCase {
MeasurePersister measurePersister;
RuleFinder ruleFinder = mock(RuleFinder.class);
Project project = new Project("foo");
- Directory aDirectory = new Directory("org/foo");
- File aFile = new File("org/foo/Bar.java");
+ Directory aDirectory = Directory.create("org/foo");
+ File aFile = File.create("org/foo/Bar.java");
BatchResource projectResource = batchResource(project, PROJECT_SNAPSHOT_ID);
BatchResource dirResource = batchResource(aDirectory, PACKAGE_SNAPSHOT_ID);
BatchResource fileResource = batchResource(aFile, FILE_SNAPSHOT_ID);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/ResourceCacheTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/ResourceCacheTest.java
index 33eb06086d0..bd250b544dd 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/ResourceCacheTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/ResourceCacheTest.java
@@ -31,7 +31,7 @@ public class ResourceCacheTest {
public void should_cache_resource() throws Exception {
ResourceCache cache = new ResourceCache();
String componentKey = "struts:src/org/struts/Action.java";
- Resource resource = new File("org/struts/Action.java").setEffectiveKey(componentKey);
+ Resource resource = File.create("org/struts/Action.java").setEffectiveKey(componentKey);
cache.add(resource, null);
assertThat(cache.get(componentKey).resource()).isSameAs(resource);
@@ -41,7 +41,7 @@ public class ResourceCacheTest {
@Test
public void should_fail_if_missing_component_key() throws Exception {
ResourceCache cache = new ResourceCache();
- Resource resource = new File("org/struts/Action.java").setEffectiveKey(null);
+ Resource resource = File.create("org/struts/Action.java").setEffectiveKey(null);
try {
cache.add(resource, null);
fail();
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/ResourceKeyMigrationTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/ResourceKeyMigrationTest.java
index e91b5596101..1d3d227a4d4 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/ResourceKeyMigrationTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/ResourceKeyMigrationTest.java
@@ -31,6 +31,8 @@ import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.fs.internal.DeprecatedDefaultInputFile;
import org.sonar.api.config.Settings;
import org.sonar.api.resources.Project;
+import org.sonar.api.scan.filesystem.PathResolver;
+import org.sonar.batch.scan.filesystem.DefaultModuleFileSystem;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
import java.io.File;
@@ -39,6 +41,7 @@ import java.util.Arrays;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class ResourceKeyMigrationTest extends AbstractDbUnitTestCase {
@@ -73,23 +76,21 @@ public class ResourceKeyMigrationTest extends AbstractDbUnitTestCase {
baseDir = temp.newFolder();
javaInputFiles = (Iterable) Arrays.asList(
- newInputFile(javaModule, "src/main/java/org/foo/Bar.java", "org.foo.Bar", false),
- newInputFile(javaModule, "src/main/java/RootBar.java", "[default].RootBar", false),
- newInputFile(javaModule, "src/test/java/org/foo/BarTest.java", "org.foo.BarTest", true));
+ newInputFile(javaModule, "src/main/java/org/foo/Bar.java", false, "java"),
+ newInputFile(javaModule, "src/main/java/RootBar.java", false, "java"),
+ newInputFile(javaModule, "src/test/java/org/foo/BarTest.java", true, "java"));
phpInputFiles = (Iterable) Arrays.asList(
- newInputFile(phpModule, "org/foo/Bar.php", "org/foo/Bar.php", false),
- newInputFile(phpModule, "RootBar.php", "RootBar.php", false),
- newInputFile(phpModule, "test/org/foo/BarTest.php", "org/foo/BarTest.php", true));
+ newInputFile(phpModule, "org/foo/Bar.php", false, "php"),
+ newInputFile(phpModule, "RootBar.php", false, "php"),
+ newInputFile(phpModule, "test/org/foo/BarTest.php", true, "php"));
}
- private DefaultInputFile newInputFile(Project module, String path, String deprecatedKey, boolean isTest) {
- File file = new File(baseDir, path);
- String deprecatedEffectiveKey = module.getKey() + ":" + deprecatedKey;
+ private DefaultInputFile newInputFile(Project module, String path, boolean isTest, String language) {
return new DeprecatedDefaultInputFile(module.getKey(), path)
- .setDeprecatedKey(deprecatedEffectiveKey)
- .setFile(file)
+ .setModuleBaseDir(baseDir.toPath())
+ .setLanguage(language)
.setType(isTest ? InputFile.Type.TEST : InputFile.Type.MAIN);
}
@@ -98,11 +99,17 @@ public class ResourceKeyMigrationTest extends AbstractDbUnitTestCase {
setupData("shouldMigrateResourceKeys");
Logger logger = mock(Logger.class);
- ResourceKeyMigration migration = new ResourceKeyMigration(getSession(), logger);
+ ResourceKeyMigration migration = new ResourceKeyMigration(getSession(), new PathResolver(), logger);
migration.checkIfMigrationNeeded(multiModuleProject);
- migration.migrateIfNeeded(javaModule, javaInputFiles);
- migration.migrateIfNeeded(phpModule, phpInputFiles);
+ DefaultModuleFileSystem fs = mock(DefaultModuleFileSystem.class);
+ when(fs.sourceDirs()).thenReturn(Arrays.asList(new File(baseDir, "src/main/java")));
+ when(fs.testDirs()).thenReturn(Arrays.asList(new File(baseDir, "src/test/java")));
+ migration.migrateIfNeeded(javaModule, javaInputFiles, fs);
+
+ when(fs.sourceDirs()).thenReturn(Arrays.asList(new File(baseDir, ".")));
+ when(fs.testDirs()).thenReturn(Arrays.asList(new File(baseDir, "test")));
+ migration.migrateIfNeeded(phpModule, phpInputFiles, fs);
verify(logger).info("Component {} changed to {}", "b:org.foo.Bar", "b:src/main/java/org/foo/Bar.java");
verify(logger).warn("Directory with key b:org/foo matches both b:src/main/java/org/foo and b:src/test/java/org/foo. First match is arbitrary chosen.");
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/ResourcePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/ResourcePersisterTest.java
index 6ec57439787..6a4506273b4 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/ResourcePersisterTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/ResourcePersisterTest.java
@@ -290,7 +290,7 @@ public class ResourcePersisterTest extends AbstractDbUnitTestCase {
setupData("shared");
resourceCache.add(singleProject, null).setSnapshot(persister.persist(null, singleProject, null));
- persister.persist(singleProject, Directory.create("src/main/java/org/foo", "org.foo").setEffectiveKey("foo:src/main/java/org/foo"), null);
+ persister.persist(singleProject, Directory.create("src/main/java/org/foo").setEffectiveKey("foo:src/main/java/org/foo"), null);
// check that the directory is attached to the project
checkTables("shouldSaveNewDirectory", new String[] {"build_date", "created_at", "authorization_updated_at", "uuid", "project_uuid", "module_uuid", "module_uuid_path"},
"projects", "snapshots");
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/SourceDataFactoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/SourceDataFactoryTest.java
index 821cb735756..2c510d62aac 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/SourceDataFactoryTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/SourceDataFactoryTest.java
@@ -26,6 +26,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.DefaultFileSystem;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.sensor.duplication.DuplicationGroup;
import org.sonar.api.batch.sensor.highlighting.TypeOfText;
@@ -35,6 +36,7 @@ import org.sonar.api.measures.Metric;
import org.sonar.batch.duplication.DuplicationCache;
import org.sonar.batch.highlighting.SyntaxHighlightingData;
import org.sonar.batch.highlighting.SyntaxHighlightingDataBuilder;
+import org.sonar.batch.scan.filesystem.InputFileMetadata;
import org.sonar.batch.scan.measure.MeasureCache;
import org.sonar.batch.source.CodeColorizers;
import org.sonar.batch.symbol.DefaultSymbolTableBuilder;
@@ -58,18 +60,21 @@ public class SourceDataFactoryTest {
DuplicationCache duplicationCache = mock(DuplicationCache.class);
CodeColorizers colorizers = mock(CodeColorizers.class);
DefaultInputFile inputFile;
+ InputFileMetadata metadata;
SourceDataFactory sut = new SourceDataFactory(measureCache, componentDataCache, duplicationCache, colorizers);
FileSourceDb.Data.Builder output;
@Before
public void setUp() throws Exception {
// generate a file with 3 lines
- File file = temp.newFile();
+ File baseDir = temp.newFolder();
+ DefaultFileSystem fs = new DefaultFileSystem(baseDir.toPath());
inputFile = new DefaultInputFile("module_key", "src/Foo.java")
.setLines(3)
- .setEncoding(Charsets.UTF_8.name())
- .setFile(file);
- FileUtils.write(file, "one\ntwo\nthree\n");
+ .setCharset(Charsets.UTF_8);
+ fs.add(inputFile);
+ metadata = new InputFileMetadata();
+ FileUtils.write(inputFile.file(), "one\ntwo\nthree\n");
output = sut.createForSource(inputFile);
}
@@ -84,7 +89,7 @@ public class SourceDataFactoryTest {
@Test
public void consolidateData() throws Exception {
- byte[] bytes = sut.consolidateData(inputFile);
+ byte[] bytes = sut.consolidateData(inputFile, metadata);
assertThat(bytes).isNotEmpty();
}
@@ -145,7 +150,6 @@ public class SourceDataFactoryTest {
Arrays.asList(new Measure().setData(dataPerLine).setMetric(metric)));
}
-
@Test
public void applyDuplications() throws Exception {
DuplicationGroup group1 = new DuplicationGroup(new DuplicationGroup.Block(inputFile.key(), 1, 1))
@@ -169,7 +173,7 @@ public class SourceDataFactoryTest {
public void applyHighlighting_missing() throws Exception {
when(componentDataCache.getData(inputFile.key(), SnapshotDataTypes.SYNTAX_HIGHLIGHTING)).thenReturn(null);
- sut.applyHighlighting(inputFile, output);
+ sut.applyHighlighting(inputFile, metadata, output);
FileSourceDb.Data data = output.build();
assertThat(data.getLines(0).hasHighlighting()).isFalse();
@@ -185,9 +189,9 @@ public class SourceDataFactoryTest {
.registerHighlightingRule(7, 16, TypeOfText.CONSTANT)
.build();
when(componentDataCache.getData(inputFile.key(), SnapshotDataTypes.SYNTAX_HIGHLIGHTING)).thenReturn(highlighting);
- inputFile.setOriginalLineOffsets(new long[] {0, 4, 7});
+ metadata.setOriginalLineOffsets(new int[] {0, 4, 7});
- sut.applyHighlighting(inputFile, output);
+ sut.applyHighlighting(inputFile, metadata, output);
FileSourceDb.Data data = output.build();
assertThat(data.getLines(0).getHighlighting()).isEqualTo("0,4,a");
@@ -203,9 +207,9 @@ public class SourceDataFactoryTest {
.registerHighlightingRule(10, 16, TypeOfText.CONSTANT)
.build();
when(componentDataCache.getData(inputFile.key(), SnapshotDataTypes.SYNTAX_HIGHLIGHTING)).thenReturn(highlighting);
- inputFile.setOriginalLineOffsets(new long[] {0, 4, 7});
+ metadata.setOriginalLineOffsets(new int[] {0, 4, 7});
- sut.applyHighlighting(inputFile, output);
+ sut.applyHighlighting(inputFile, metadata, output);
FileSourceDb.Data data = output.build();
assertThat(data.getLines(0).getHighlighting()).isEqualTo("0,3,a");
@@ -222,9 +226,9 @@ public class SourceDataFactoryTest {
.registerHighlightingRule(8, 15, TypeOfText.KEYWORD)
.build();
when(componentDataCache.getData(inputFile.key(), SnapshotDataTypes.SYNTAX_HIGHLIGHTING)).thenReturn(highlighting);
- inputFile.setOriginalLineOffsets(new long[] {0, 4, 7});
+ metadata.setOriginalLineOffsets(new int[] {0, 4, 7});
- sut.applyHighlighting(inputFile, output);
+ sut.applyHighlighting(inputFile, metadata, output);
FileSourceDb.Data data = output.build();
assertThat(data.getLines(0).getHighlighting()).isEqualTo("0,3,a");
@@ -241,9 +245,9 @@ public class SourceDataFactoryTest {
.registerHighlightingRule(8, 15, TypeOfText.KEYWORD)
.build();
when(componentDataCache.getData(inputFile.key(), SnapshotDataTypes.SYNTAX_HIGHLIGHTING)).thenReturn(highlighting);
- inputFile.setOriginalLineOffsets(new long[] {0, 4, 7});
+ metadata.setOriginalLineOffsets(new int[] {0, 4, 7});
- sut.applyHighlighting(inputFile, output);
+ sut.applyHighlighting(inputFile, metadata, output);
FileSourceDb.Data data = output.build();
assertThat(data.getLines(0).getHighlighting()).isEqualTo("0,3,a");
@@ -255,7 +259,7 @@ public class SourceDataFactoryTest {
public void applySymbolReferences_missing() throws Exception {
when(componentDataCache.getData(inputFile.key(), SnapshotDataTypes.SYMBOL_HIGHLIGHTING)).thenReturn(null);
- sut.applySymbolReferences(inputFile, output);
+ sut.applySymbolReferences(inputFile, metadata, output);
FileSourceDb.Data data = output.build();
assertThat(data.getLines(0).hasSymbols()).isFalse();
@@ -273,9 +277,9 @@ public class SourceDataFactoryTest {
symbolBuilder.newReference(s2, 0);
symbolBuilder.newReference(s2, 7);
when(componentDataCache.getData(inputFile.key(), SnapshotDataTypes.SYMBOL_HIGHLIGHTING)).thenReturn(symbolBuilder.build());
- inputFile.setOriginalLineOffsets(new long[] {0, 4, 7});
+ metadata.setOriginalLineOffsets(new int[] {0, 4, 7});
- sut.applySymbolReferences(inputFile, output);
+ sut.applySymbolReferences(inputFile, metadata, output);
FileSourceDb.Data data = output.build();
assertThat(data.getLines(0).getSymbols()).isEqualTo("1,2,1;0,2,2");
@@ -293,9 +297,9 @@ public class SourceDataFactoryTest {
symbolBuilder.newReference(s1, 11);
symbolBuilder.newReference(s1, 4);
when(componentDataCache.getData(inputFile.key(), SnapshotDataTypes.SYMBOL_HIGHLIGHTING)).thenReturn(symbolBuilder.build());
- inputFile.setOriginalLineOffsets(new long[] {0, 4, 7});
+ metadata.setOriginalLineOffsets(new int[] {0, 4, 7});
- sut.applySymbolReferences(inputFile, output);
+ sut.applySymbolReferences(inputFile, metadata, output);
FileSourceDb.Data data = output.build();
assertThat(data.getLines(0).getSymbols()).isEqualTo("1,2,1;0,2,2");
diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java
index c24e04a1ded..514a6d05a1b 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java
@@ -40,7 +40,7 @@ public class IssuableFactoryTest {
@Test
public void file_should_be_issuable() throws Exception {
IssuableFactory factory = new IssuableFactory(moduleIssues, cache, projectTree);
- Component component = new ResourceComponent(new File("foo/bar.c").setEffectiveKey("foo/bar.c"));
+ Component component = new ResourceComponent(File.create("foo/bar.c").setEffectiveKey("foo/bar.c"));
Issuable issuable = factory.loadPerspective(Issuable.class, component);
assertThat(issuable).isNotNull();
diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java
index 0594cb16234..7ffa9905721 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java
@@ -207,7 +207,7 @@ public class ModuleIssuesTest {
initModuleIssues();
org.sonar.api.rules.Rule rule = org.sonar.api.rules.Rule.create("squid", "AvoidCycle", "Avoid Cycle");
- Resource resource = new File("org/struts/Action.java").setEffectiveKey("struts:src/org/struts/Action.java");
+ Resource resource = File.create("org/struts/Action.java").setEffectiveKey("struts:src/org/struts/Action.java");
Violation violation = new Violation(rule, resource);
violation.setLineId(42);
violation.setSeverity(RulePriority.CRITICAL);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/ignore/scanner/IssueExclusionsLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/ignore/scanner/IssueExclusionsLoaderTest.java
index 9fd36ece0b7..3cca58ac2b2 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/issue/ignore/scanner/IssueExclusionsLoaderTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/issue/ignore/scanner/IssueExclusionsLoaderTest.java
@@ -72,7 +72,7 @@ public class IssueExclusionsLoaderTest {
@Before
public void before() throws Exception {
baseDir = temp.newFolder();
- fs = new DefaultFileSystem(baseDir).setEncoding(UTF_8);
+ fs = new DefaultFileSystem(baseDir.toPath()).setEncoding(UTF_8);
MockitoAnnotations.initMocks(this);
scanner = new IssueExclusionsLoader(regexpScanner, exclusionPatternInitializer, inclusionPatternInitializer, fs);
}
@@ -106,11 +106,9 @@ public class IssueExclusionsLoaderTest {
public void shouldAnalyzeProject() throws IOException {
File javaFile1 = new File(baseDir, "src/main/java/Foo.java");
fs.add(new DeprecatedDefaultInputFile("polop", "src/main/java/Foo.java")
- .setFile(javaFile1)
.setType(InputFile.Type.MAIN));
File javaTestFile1 = new File(baseDir, "src/test/java/FooTest.java");
fs.add(new DeprecatedDefaultInputFile("polop", "src/test/java/FooTest.java")
- .setFile(javaTestFile1)
.setType(InputFile.Type.TEST));
when(exclusionPatternInitializer.hasFileContentPattern()).thenReturn(true);
@@ -129,11 +127,9 @@ public class IssueExclusionsLoaderTest {
public void shouldAnalyseFilesOnlyWhenRegexConfigured() throws IOException {
File javaFile1 = new File(baseDir, "src/main/java/Foo.java");
fs.add(new DeprecatedDefaultInputFile("polop", "src/main/java/Foo.java")
- .setFile(javaFile1)
.setType(InputFile.Type.MAIN));
File javaTestFile1 = new File(baseDir, "src/test/java/FooTest.java");
fs.add(new DeprecatedDefaultInputFile("polop", "src/test/java/FooTest.java")
- .setFile(javaTestFile1)
.setType(InputFile.Type.TEST));
when(exclusionPatternInitializer.hasFileContentPattern()).thenReturn(false);
@@ -150,7 +146,6 @@ public class IssueExclusionsLoaderTest {
public void shouldReportFailure() throws IOException {
File phpFile1 = new File(baseDir, "src/Foo.php");
fs.add(new DeprecatedDefaultInputFile("polop", "src/Foo.php")
- .setFile(phpFile1)
.setType(InputFile.Type.MAIN));
when(exclusionPatternInitializer.hasFileContentPattern()).thenReturn(true);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/IssueTrackingDecoratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/IssueTrackingDecoratorTest.java
index 7691dbf6538..1c5e080cd06 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/IssueTrackingDecoratorTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/IssueTrackingDecoratorTest.java
@@ -19,9 +19,12 @@
*/
package org.sonar.batch.issue.tracking;
+import com.google.common.base.Charsets;
import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentMatcher;
import org.sonar.api.batch.DecoratorContext;
@@ -41,6 +44,7 @@ import org.sonar.api.utils.Duration;
import org.sonar.api.utils.System2;
import org.sonar.batch.issue.IssueCache;
import org.sonar.batch.scan.LastLineHashes;
+import org.sonar.batch.scan.filesystem.InputFileMetadata;
import org.sonar.batch.scan.filesystem.InputPathCache;
import org.sonar.core.issue.IssueUpdater;
import org.sonar.core.issue.db.IssueChangeDto;
@@ -48,6 +52,7 @@ import org.sonar.core.issue.db.IssueDto;
import org.sonar.core.issue.workflow.IssueWorkflow;
import org.sonar.java.api.JavaClass;
+import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@@ -71,6 +76,9 @@ import static org.mockito.Mockito.when;
public class IssueTrackingDecoratorTest {
+ @org.junit.Rule
+ public TemporaryFolder temp = new TemporaryFolder();
+
IssueTrackingDecorator decorator;
IssueCache issueCache = mock(IssueCache.class, RETURNS_MOCKS);
InitialOpenIssuesStack initialOpenIssues = mock(InitialOpenIssuesStack.class);
@@ -124,6 +132,7 @@ public class IssueTrackingDecoratorTest {
List<PreviousIssue> dbIssues = Collections.emptyList();
when(initialOpenIssues.selectAndRemoveIssues("struts:Action.java")).thenReturn(dbIssues);
when(inputPathCache.getFile("foo", "Action.java")).thenReturn(mock(DefaultInputFile.class));
+ when(inputPathCache.getFileMetadata("foo", "Action.java")).thenReturn(new InputFileMetadata());
decorator.doDecorate(file);
// Apply filters, track, apply transitions, notify extensions then update cache
@@ -152,6 +161,7 @@ public class IssueTrackingDecoratorTest {
when(tracking.track(isA(SourceHashHolder.class), anyCollection(), anyCollection())).thenReturn(trackingResult);
when(inputPathCache.getFile("foo", "Action.java")).thenReturn(mock(DefaultInputFile.class));
+ when(inputPathCache.getFileMetadata("foo", "Action.java")).thenReturn(new InputFileMetadata());
decorator.doDecorate(file);
@@ -210,10 +220,13 @@ public class IssueTrackingDecoratorTest {
assertThat(issue.isOnDisabledRule()).isFalse();
}
- private Resource mockHashes(String originalSource, String newSource) {
+ private Resource mockHashes(String originalSource, String newSource) throws IOException {
DefaultInputFile inputFile = mock(DefaultInputFile.class);
- byte[][] hashes = computeHashes(newSource);
- when(inputFile.lineHashes()).thenReturn(hashes);
+ java.io.File f = temp.newFile();
+ when(inputFile.path()).thenReturn(f.toPath());
+ when(inputFile.charset()).thenReturn(Charsets.UTF_8);
+ when(inputFile.lines()).thenReturn(newSource.split("\n").length);
+ FileUtils.write(f, newSource, Charsets.UTF_8);
when(inputFile.key()).thenReturn("foo:Action.java");
when(inputPathCache.getFile("foo", "Action.java")).thenReturn(inputFile);
when(lastSnapshots.getLineHashes("foo:Action.java")).thenReturn(computeHexHashes(originalSource));
@@ -561,15 +574,6 @@ public class IssueTrackingDecoratorTest {
assertThat(issue.changes()).hasSize(1);
}
- private byte[][] computeHashes(String source) {
- String[] lines = source.split("\n");
- byte[][] hashes = new byte[lines.length][];
- for (int i = 0; i < lines.length; i++) {
- hashes[i] = DigestUtils.md5(lines[i].replaceAll("[\t ]", ""));
- }
- return hashes;
- }
-
private String[] computeHexHashes(String source) {
String[] lines = source.split("\n");
String[] hashes = new String[lines.length];
diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/IssueTrackingTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/IssueTrackingTest.java
index 2efb24c13eb..bcc25ac598c 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/IssueTrackingTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/IssueTrackingTest.java
@@ -24,8 +24,11 @@ import com.google.common.base.Charsets;
import com.google.common.collect.Lists;
import com.google.common.io.Resources;
import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.io.FileUtils;
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.issue.Issue;
import org.sonar.api.issue.internal.DefaultIssue;
@@ -35,6 +38,7 @@ import org.sonar.api.rule.RuleKey;
import org.sonar.batch.scan.LastLineHashes;
import org.sonar.core.issue.db.IssueDto;
+import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
@@ -47,6 +51,9 @@ import static org.mockito.Mockito.when;
public class IssueTrackingTest {
+ @Rule
+ public TemporaryFolder temp = new TemporaryFolder();
+
IssueTracking tracking;
Resource project;
SourceHashHolder sourceHashHolder;
@@ -345,22 +352,17 @@ public class IssueTrackingTest {
private void initLastHashes(String reference, String newSource) throws IOException {
DefaultInputFile inputFile = mock(DefaultInputFile.class);
- byte[][] hashes = computeHashes(load(newSource));
- when(inputFile.lineHashes()).thenReturn(hashes);
+ File f = temp.newFile();
+ when(inputFile.path()).thenReturn(f.toPath());
+ when(inputFile.charset()).thenReturn(Charsets.UTF_8);
+ String data = load(newSource);
+ when(inputFile.lines()).thenReturn(data.split("\n").length);
+ FileUtils.write(f, data, Charsets.UTF_8);
when(inputFile.key()).thenReturn("foo:Action.java");
when(lastSnapshots.getLineHashes("foo:Action.java")).thenReturn(computeHexHashes(load(reference)));
sourceHashHolder = new SourceHashHolder(inputFile, lastSnapshots);
}
- private byte[][] computeHashes(String source) {
- String[] lines = source.split("\n");
- byte[][] hashes = new byte[lines.length][];
- for (int i = 0; i < lines.length; i++) {
- hashes[i] = DigestUtils.md5(lines[i].replaceAll("[\t ]", ""));
- }
- return hashes;
- }
-
private String[] computeHexHashes(String source) {
String[] lines = source.split("\n");
String[] hashes = new String[lines.length];
diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/SourceHashHolderTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/SourceHashHolderTest.java
index 6ac6645bbae..59371ca4947 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/SourceHashHolderTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/SourceHashHolderTest.java
@@ -19,14 +19,19 @@
*/
package org.sonar.batch.issue.tracking;
+import com.google.common.base.Charsets;
+import org.apache.commons.io.FileUtils;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
import org.mockito.Mockito;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.batch.scan.LastLineHashes;
-import static org.apache.commons.codec.digest.DigestUtils.md5;
+import java.io.File;
+
import static org.apache.commons.codec.digest.DigestUtils.md5Hex;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@@ -35,39 +40,48 @@ import static org.mockito.Mockito.when;
public class SourceHashHolderTest {
+ @Rule
+ public TemporaryFolder temp = new TemporaryFolder();
+
SourceHashHolder sourceHashHolder;
LastLineHashes lastSnapshots;
DefaultInputFile file;
+ private File ioFile;
+
@Before
- public void setUp() {
+ public void setUp() throws Exception {
lastSnapshots = mock(LastLineHashes.class);
file = mock(DefaultInputFile.class);
+ ioFile = temp.newFile();
+ when(file.file()).thenReturn(ioFile);
+ when(file.path()).thenReturn(ioFile.toPath());
+ when(file.lines()).thenReturn(1);
+ when(file.charset()).thenReturn(Charsets.UTF_8);
sourceHashHolder = new SourceHashHolder(file, lastSnapshots);
}
@Test
- public void should_lazy_load_line_hashes() {
+ public void should_lazy_load_line_hashes() throws Exception {
final String source = "source";
- when(file.lineHashes()).thenReturn(new byte[][] {md5(source), null});
+ FileUtils.write(ioFile, source + "\n", Charsets.UTF_8);
+ when(file.lines()).thenReturn(2);
assertThat(sourceHashHolder.getHashedSource().getHash(1)).isEqualTo(md5Hex(source));
assertThat(sourceHashHolder.getHashedSource().getHash(2)).isEqualTo("");
- verify(file).lineHashes();
verify(file).key();
verify(file).status();
assertThat(sourceHashHolder.getHashedSource().getHash(1)).isEqualTo(md5Hex(source));
- Mockito.verifyNoMoreInteractions(file);
}
@Test
- public void should_lazy_load_reference_hashes_when_status_changed() {
+ public void should_lazy_load_reference_hashes_when_status_changed() throws Exception {
final String source = "source";
String key = "foo:src/Foo.java";
- when(file.lineHashes()).thenReturn(new byte[][] {md5(source)});
+ FileUtils.write(ioFile, source, Charsets.UTF_8);
when(file.key()).thenReturn(key);
when(file.status()).thenReturn(InputFile.Status.CHANGED);
when(lastSnapshots.getLineHashes(key)).thenReturn(new String[] {md5Hex(source)});
@@ -80,23 +94,22 @@ public class SourceHashHolderTest {
}
@Test
- public void should_not_load_reference_hashes_when_status_same() {
+ public void should_not_load_reference_hashes_when_status_same() throws Exception {
final String source = "source";
String key = "foo:src/Foo.java";
- when(file.lineHashes()).thenReturn(new byte[][] {md5(source)});
+ FileUtils.write(ioFile, source, Charsets.UTF_8);
when(file.key()).thenReturn(key);
when(file.status()).thenReturn(InputFile.Status.SAME);
assertThat(sourceHashHolder.getHashedReference().getHash(1)).isEqualTo(md5Hex(source));
- assertThat(sourceHashHolder.getHashedReference().getHash(1)).isEqualTo(md5Hex(source));
Mockito.verifyNoMoreInteractions(lastSnapshots);
}
@Test
- public void no_reference_hashes_when_status_added() {
+ public void no_reference_hashes_when_status_added() throws Exception {
final String source = "source";
String key = "foo:src/Foo.java";
- when(file.lineHashes()).thenReturn(new byte[][] {md5(source)});
+ FileUtils.write(ioFile, source, Charsets.UTF_8);
when(file.key()).thenReturn(key);
when(file.status()).thenReturn(InputFile.Status.ADDED);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/phases/DecoratorsExecutorTest.java b/sonar-batch/src/test/java/org/sonar/batch/phases/DecoratorsExecutorTest.java
index 45774d11f95..7b644d27530 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/phases/DecoratorsExecutorTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/phases/DecoratorsExecutorTest.java
@@ -28,8 +28,8 @@ import org.sonar.api.resources.File;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.utils.SonarException;
-import org.sonar.batch.DefaultDecoratorContext;
import org.sonar.batch.bootstrap.BatchExtensionDictionnary;
+import org.sonar.batch.deprecated.decorator.DefaultDecoratorContext;
import org.sonar.batch.duplication.DuplicationCache;
import org.sonar.batch.events.EventBus;
import org.sonar.batch.scan.measure.MeasureCache;
@@ -69,7 +69,7 @@ public class DecoratorsExecutorTest {
DecoratorsExecutor executor = new DecoratorsExecutor(mock(BatchExtensionDictionnary.class), new Project("key"), mock(SonarIndex.class),
mock(EventBus.class), mock(CoverageExclusions.class), mock(MeasureCache.class), mock(MetricFinder.class), mock(DuplicationCache.class));
try {
- executor.executeDecorator(decorator, mock(DefaultDecoratorContext.class), File.create("src/org/foo/Bar.java", "org/foo/Bar.java", null, false));
+ executor.executeDecorator(decorator, mock(DefaultDecoratorContext.class), File.create("src/org/foo/Bar.java", null, false));
fail("Exception has not been thrown");
} catch (SonarException e) {
diff --git a/sonar-batch/src/test/java/org/sonar/batch/qualitygate/GenerateQualityGateEventsTest.java b/sonar-batch/src/test/java/org/sonar/batch/qualitygate/GenerateQualityGateEventsTest.java
index 83cab61793e..e7e2c332838 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/qualitygate/GenerateQualityGateEventsTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/qualitygate/GenerateQualityGateEventsTest.java
@@ -19,8 +19,6 @@
*/
package org.sonar.batch.qualitygate;
-import org.sonar.batch.qualitygate.GenerateQualityGateEvents;
-
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.batch.DecoratorContext;
@@ -35,14 +33,20 @@ import org.sonar.api.notifications.NotificationManager;
import org.sonar.api.resources.File;
import org.sonar.api.resources.Project;
import org.sonar.api.test.ProjectTestBuilder;
-import org.sonar.batch.qualitygate.QualityGate;
import java.util.Arrays;
import java.util.Date;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.*;
-import static org.mockito.Mockito.*;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Matchers.isNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class GenerateQualityGateEventsTest {
private GenerateQualityGateEvents decorator;
@@ -80,7 +84,7 @@ public class GenerateQualityGateEventsTest {
@Test
public void shouldNotDecorateIfNotRootProject() {
- decorator.decorate(new File("Foo"), context);
+ decorator.decorate(File.create("Foo"), context);
verify(context, never()).createEvent(anyString(), anyString(), anyString(), (Date) isNull());
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java
index 87a72c6c057..30f56d3a46e 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java
@@ -62,17 +62,17 @@ public class ComponentsPublisherTest {
dir.setId(3).setUuid("DIR_UUID");
resourceCache.add(dir, module1).setSnapshot(new Snapshot().setId(13));
- org.sonar.api.resources.File file = org.sonar.api.resources.File.create("src/Foo.java", "Foo.java", Java.INSTANCE, false);
+ org.sonar.api.resources.File file = org.sonar.api.resources.File.create("src/Foo.java", Java.INSTANCE, false);
file.setEffectiveKey("foo:src/Foo.java");
file.setId(4).setUuid("FILE_UUID");
resourceCache.add(file, dir).setSnapshot(new Snapshot().setId(14));
- org.sonar.api.resources.File fileWithoutLang = org.sonar.api.resources.File.create("src/make", "make", null, false);
+ org.sonar.api.resources.File fileWithoutLang = org.sonar.api.resources.File.create("src/make", null, false);
fileWithoutLang.setEffectiveKey("foo:src/make");
fileWithoutLang.setId(5).setUuid("FILE_WITHOUT_LANG_UUID");
resourceCache.add(fileWithoutLang, dir).setSnapshot(new Snapshot().setId(15));
- org.sonar.api.resources.File testFile = org.sonar.api.resources.File.create("test/FooTest.java", "FooTest.java", Java.INSTANCE, true);
+ org.sonar.api.resources.File testFile = org.sonar.api.resources.File.create("test/FooTest.java", Java.INSTANCE, true);
testFile.setEffectiveKey("foo:test/FooTest.java");
testFile.setId(6).setUuid("TEST_FILE_UUID");
resourceCache.add(testFile, dir).setSnapshot(new Snapshot().setId(16));
diff --git a/sonar-batch/src/test/java/org/sonar/batch/user/UserRepositoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/repository/user/UserRepositoryTest.java
index 7191d185fa3..ad8c954e98f 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/user/UserRepositoryTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/repository/user/UserRepositoryTest.java
@@ -17,7 +17,7 @@
* 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.batch.user;
+package org.sonar.batch.repository.user;
import org.junit.Test;
import org.sonar.batch.bootstrap.ServerClient;
diff --git a/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileSensorTest.java b/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileSensorTest.java
index c9e6deabcaf..7c83baad914 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileSensorTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileSensorTest.java
@@ -23,6 +23,7 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
+import org.sonar.api.batch.AnalysisMode;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.batch.fs.internal.DefaultFileSystem;
import org.sonar.api.measures.CoreMetrics;
@@ -57,20 +58,29 @@ public class QProfileSensorTest {
@Before
public void prepare() throws Exception {
- fs = new DefaultFileSystem(temp.newFolder());
+ fs = new DefaultFileSystem(temp.newFolder().toPath());
}
@Test
public void to_string() throws Exception {
- QProfileSensor sensor = new QProfileSensor(moduleQProfiles, fs);
+ QProfileSensor sensor = new QProfileSensor(moduleQProfiles, fs, mock(AnalysisMode.class));
assertThat(sensor.toString()).isEqualTo("QProfileSensor");
}
@Test
+ public void no_execution_in_preview() throws Exception {
+ AnalysisMode analysisMode = mock(AnalysisMode.class);
+ when(analysisMode.isPreview()).thenReturn(true);
+ QProfileSensor sensor = new QProfileSensor(moduleQProfiles, fs, analysisMode);
+ assertThat(sensor.shouldExecuteOnProject(project)).isFalse();
+
+ }
+
+ @Test
public void no_qprofiles() throws Exception {
when(moduleQProfiles.findAll()).thenReturn(Collections.<QProfile>emptyList());
- QProfileSensor sensor = new QProfileSensor(moduleQProfiles, fs);
+ QProfileSensor sensor = new QProfileSensor(moduleQProfiles, fs, mock(AnalysisMode.class));
assertThat(sensor.shouldExecuteOnProject(project)).isTrue();
sensor.analyse(project, sensorContext);
@@ -85,7 +95,7 @@ public class QProfileSensorTest {
when(moduleQProfiles.findByLanguage("abap")).thenReturn(null);
fs.addLanguages("java", "php", "abap");
- QProfileSensor sensor = new QProfileSensor(moduleQProfiles, fs);
+ QProfileSensor sensor = new QProfileSensor(moduleQProfiles, fs, mock(AnalysisMode.class));
assertThat(sensor.shouldExecuteOnProject(project)).isTrue();
sensor.analyse(project, sensorContext);
}
@@ -97,7 +107,7 @@ public class QProfileSensorTest {
when(moduleQProfiles.findByLanguage("abap")).thenReturn(null);
fs.addLanguages("java");
- QProfileSensor sensor = new QProfileSensor(moduleQProfiles, fs);
+ QProfileSensor sensor = new QProfileSensor(moduleQProfiles, fs, mock(AnalysisMode.class));
assertThat(sensor.shouldExecuteOnProject(project)).isTrue();
sensor.analyse(project, sensorContext);
@@ -113,7 +123,7 @@ public class QProfileSensorTest {
when(moduleQProfiles.findByLanguage("abap")).thenReturn(null);
fs.addLanguages("java", "php");
- QProfileSensor sensor = new QProfileSensor(moduleQProfiles, fs);
+ QProfileSensor sensor = new QProfileSensor(moduleQProfiles, fs, mock(AnalysisMode.class));
assertThat(sensor.shouldExecuteOnProject(project)).isTrue();
sensor.analyse(project, sensorContext);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileVerifierTest.java b/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileVerifierTest.java
index 9c5db0f6d6a..61463ae5742 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileVerifierTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileVerifierTest.java
@@ -47,7 +47,7 @@ public class QProfileVerifierTest {
@Before
public void before() throws Exception {
- fs = new DefaultFileSystem(temp.newFolder());
+ fs = new DefaultFileSystem(temp.newFolder().toPath());
profiles = mock(ModuleQProfiles.class);
QProfile javaProfile = new QProfile().setKey("p1").setName("My Java profile").setLanguage("java");
when(profiles.findByLanguage("java")).thenReturn(javaProfile);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/LanguageVerifierTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/LanguageVerifierTest.java
index a60fd596e53..420d0641c36 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/LanguageVerifierTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/LanguageVerifierTest.java
@@ -29,8 +29,8 @@ import org.sonar.api.config.Settings;
import org.sonar.api.resources.Java;
import org.sonar.api.resources.Languages;
import org.sonar.api.utils.MessageException;
-import org.sonar.batch.languages.DefaultLanguagesReferential;
-import org.sonar.batch.languages.LanguagesReferential;
+import org.sonar.batch.repository.language.DefaultLanguagesRepository;
+import org.sonar.batch.repository.language.LanguagesRepository;
import static org.assertj.core.api.Assertions.assertThat;
@@ -43,12 +43,12 @@ public class LanguageVerifierTest {
public ExpectedException thrown = ExpectedException.none();
private Settings settings = new Settings();
- private LanguagesReferential languages = new DefaultLanguagesReferential(new Languages(Java.INSTANCE));
+ private LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(Java.INSTANCE));
private DefaultFileSystem fs;
@Before
public void prepare() throws Exception {
- fs = new DefaultFileSystem(temp.newFolder());
+ fs = new DefaultFileSystem(temp.newFolder().toPath());
}
@Test
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/AdditionalFilePredicatesTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/AdditionalFilePredicatesTest.java
index ff6e76e0857..ad3dfffc491 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/AdditionalFilePredicatesTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/AdditionalFilePredicatesTest.java
@@ -26,8 +26,6 @@ import org.sonar.api.batch.fs.FilePredicate;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.fs.internal.DeprecatedDefaultInputFile;
-import java.io.File;
-
import static org.assertj.core.api.Assertions.assertThat;
public class AdditionalFilePredicatesTest {
@@ -45,38 +43,4 @@ public class AdditionalFilePredicatesTest {
inputFile = new DeprecatedDefaultInputFile("struts", "Filter.java");
assertThat(predicate.apply(inputFile)).isFalse();
}
-
- @Test
- public void deprecated_key() throws Exception {
- FilePredicate predicate = new AdditionalFilePredicates.DeprecatedKeyPredicate("struts:Action.java");
-
- DeprecatedDefaultInputFile inputFile = new DeprecatedDefaultInputFile("struts", "Action.java").setDeprecatedKey("struts:Action.java");
- assertThat(predicate.apply(inputFile)).isTrue();
-
- inputFile = new DeprecatedDefaultInputFile("struts", "Filter.java").setDeprecatedKey("struts:Filter.java");
- assertThat(predicate.apply(inputFile)).isFalse();
- }
-
- @Test
- public void absolute_path_of_source_dir() throws Exception {
- File dir = temp.newFolder();
- FilePredicate predicate = new AdditionalFilePredicates.SourceDirPredicate(dir.getAbsolutePath());
-
- DeprecatedDefaultInputFile inputFile = new DeprecatedDefaultInputFile("struts", "Action.java").setSourceDirAbsolutePath(dir.getAbsolutePath());
- assertThat(predicate.apply(inputFile)).isTrue();
-
- inputFile = new DeprecatedDefaultInputFile("struts", "Filter.java").setSourceDirAbsolutePath(temp.newFolder().getAbsolutePath());
- assertThat(predicate.apply(inputFile)).isFalse();
- }
-
- @Test
- public void path_relative_to_source_dir() throws Exception {
- FilePredicate predicate = new AdditionalFilePredicates.SourceRelativePathPredicate("foo/Bar.php");
-
- DeprecatedDefaultInputFile inputFile = new DeprecatedDefaultInputFile("foo", "src/php/foo/Bar.php").setPathRelativeToSourceDir("foo/Bar.php");
- assertThat(predicate.apply(inputFile)).isTrue();
-
- inputFile = new DeprecatedDefaultInputFile("foo", "foo/Bar.php").setPathRelativeToSourceDir("Bar.php");
- assertThat(predicate.apply(inputFile)).isFalse();
- }
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ComponentIndexerTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ComponentIndexerTest.java
index 702aa2fb068..5960fab5c2d 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ComponentIndexerTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ComponentIndexerTest.java
@@ -42,6 +42,7 @@ import java.io.IOException;
import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class ComponentIndexerTest {
@@ -52,13 +53,17 @@ public class ComponentIndexerTest {
private SonarIndex sonarIndex;
private AbstractLanguage cobolLanguage;
private Project project;
+ private ModuleFileSystemInitializer initializer;
@Before
public void prepare() throws IOException {
baseDir = temp.newFolder();
- fs = new DefaultFileSystem(baseDir);
+ fs = new DefaultFileSystem(baseDir.toPath());
sonarIndex = mock(SonarIndex.class);
project = new Project("myProject");
+ initializer = mock(ModuleFileSystemInitializer.class);
+ when(initializer.baseDir()).thenReturn(baseDir);
+ when(initializer.workingDir()).thenReturn(temp.newFolder());
cobolLanguage = new AbstractLanguage("cobol") {
@Override
public String[] getFileSuffixes() {
@@ -69,15 +74,17 @@ public class ComponentIndexerTest {
@Test
public void should_index_java_files() throws IOException {
+ Languages languages = new Languages(Java.INSTANCE);
+ ComponentIndexer indexer = createIndexer(languages);
+ DefaultModuleFileSystem fs = new DefaultModuleFileSystem(project, null, mock(FileIndexer.class), initializer, indexer);
fs.add(newInputFile("src/main/java/foo/bar/Foo.java", "", "foo/bar/Foo.java", "java", false));
fs.add(newInputFile("src/main/java2/foo/bar/Foo.java", "", "foo/bar/Foo.java", "java", false));
fs.add(newInputFile("src/test/java/foo/bar/FooTest.java", "", "foo/bar/FooTest.java", "java", true));
- Languages languages = new Languages(Java.INSTANCE);
- ComponentIndexer indexer = createIndexer(languages);
- indexer.execute(fs);
- verify(sonarIndex).index(org.sonar.api.resources.File.create("src/main/java/foo/bar/Foo.java", "foo/bar/Foo.java", Java.INSTANCE, false));
- verify(sonarIndex).index(org.sonar.api.resources.File.create("src/main/java2/foo/bar/Foo.java", "foo/bar/Foo.java", Java.INSTANCE, false));
+ fs.index();
+
+ verify(sonarIndex).index(org.sonar.api.resources.File.create("src/main/java/foo/bar/Foo.java", Java.INSTANCE, false));
+ verify(sonarIndex).index(org.sonar.api.resources.File.create("src/main/java2/foo/bar/Foo.java", Java.INSTANCE, false));
verify(sonarIndex).index(argThat(new ArgumentMatcher<org.sonar.api.resources.File>() {
@Override
public boolean matches(Object arg0) {
@@ -95,25 +102,24 @@ public class ComponentIndexerTest {
@Test
public void should_index_cobol_files() throws IOException {
+ Languages languages = new Languages(cobolLanguage);
+ ComponentIndexer indexer = createIndexer(languages);
+ DefaultModuleFileSystem fs = new DefaultModuleFileSystem(project, null, mock(FileIndexer.class), initializer, indexer);
fs.add(newInputFile("src/foo/bar/Foo.cbl", "", "foo/bar/Foo.cbl", "cobol", false));
fs.add(newInputFile("src2/foo/bar/Foo.cbl", "", "foo/bar/Foo.cbl", "cobol", false));
fs.add(newInputFile("src/test/foo/bar/FooTest.cbl", "", "foo/bar/FooTest.cbl", "cobol", true));
- Languages languages = new Languages(cobolLanguage);
- ComponentIndexer indexer = createIndexer(languages);
- indexer.execute(fs);
+ fs.index();
- verify(sonarIndex).index(org.sonar.api.resources.File.create("/src/foo/bar/Foo.cbl", "foo/bar/Foo.cbl", cobolLanguage, false));
- verify(sonarIndex).index(org.sonar.api.resources.File.create("/src2/foo/bar/Foo.cbl", "foo/bar/Foo.cbl", cobolLanguage, false));
- verify(sonarIndex).index(org.sonar.api.resources.File.create("/src/test/foo/bar/FooTest.cbl", "foo/bar/FooTest.cbl", cobolLanguage, true));
+ verify(sonarIndex).index(org.sonar.api.resources.File.create("/src/foo/bar/Foo.cbl", cobolLanguage, false));
+ verify(sonarIndex).index(org.sonar.api.resources.File.create("/src2/foo/bar/Foo.cbl", cobolLanguage, false));
+ verify(sonarIndex).index(org.sonar.api.resources.File.create("/src/test/foo/bar/FooTest.cbl", cobolLanguage, true));
}
private DefaultInputFile newInputFile(String path, String content, String sourceRelativePath, String languageKey, boolean unitTest) throws IOException {
File file = new File(baseDir, path);
FileUtils.write(file, content);
return new DeprecatedDefaultInputFile("foo", path)
- .setPathRelativeToSourceDir(sourceRelativePath)
- .setFile(file)
.setLanguage(languageKey)
.setType(unitTest ? InputFile.Type.TEST : InputFile.Type.MAIN);
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystemTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystemTest.java
index 12be0438530..7f954c405a2 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystemTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystemTest.java
@@ -135,9 +135,9 @@ public class DefaultModuleFileSystemTest {
DefaultModuleFileSystem fs = new DefaultModuleFileSystem(moduleInputFileCache,
new Project("foo"), settings, fileIndexer, initializer, componentIndexer);
- File mainFile = temp.newFile();
- InputFile mainInput = new DeprecatedDefaultInputFile("foo", "Main.java").setFile(mainFile).setType(InputFile.Type.MAIN);
- InputFile testInput = new DeprecatedDefaultInputFile("foo", "Test.java").setFile(temp.newFile()).setType(InputFile.Type.TEST);
+ File baseDir = temp.newFile();
+ InputFile mainInput = new DeprecatedDefaultInputFile("foo", "Main.java").setModuleBaseDir(baseDir.toPath()).setType(InputFile.Type.MAIN);
+ InputFile testInput = new DeprecatedDefaultInputFile("foo", "Test.java").setModuleBaseDir(baseDir.toPath()).setType(InputFile.Type.TEST);
when(moduleInputFileCache.inputFiles()).thenReturn(Lists.newArrayList(mainInput, testInput));
fs.index();
@@ -145,7 +145,7 @@ public class DefaultModuleFileSystemTest {
assertThat(inputFiles).containsOnly(mainInput);
Iterable<File> files = fs.files(fs.predicates().hasType(InputFile.Type.MAIN));
- assertThat(files).containsOnly(mainFile);
+ assertThat(files).containsOnly(new File(baseDir, "Main.java"));
}
@Test
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DeprecatedFileFiltersTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DeprecatedFileFiltersTest.java
index 4066080360b..3235301f031 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DeprecatedFileFiltersTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DeprecatedFileFiltersTest.java
@@ -49,7 +49,7 @@ public class DeprecatedFileFiltersTest {
public void no_filters() throws Exception {
DeprecatedFileFilters filters = new DeprecatedFileFilters();
- InputFile inputFile = new DeprecatedDefaultInputFile("foo", "src/main/java/Foo.java").setFile(temp.newFile());
+ InputFile inputFile = new DeprecatedDefaultInputFile("foo", "src/main/java/Foo.java");
assertThat(filters.accept(inputFile)).isTrue();
}
@@ -58,11 +58,9 @@ public class DeprecatedFileFiltersTest {
DeprecatedFileFilters filters = new DeprecatedFileFilters(new FileSystemFilter[] {filter});
File basedir = temp.newFolder();
- File file = temp.newFile();
+ File file = new File(basedir, "src/main/java/Foo.java");
InputFile inputFile = new DeprecatedDefaultInputFile("foo", "src/main/java/Foo.java")
- .setSourceDirAbsolutePath(new File(basedir, "src/main/java").getAbsolutePath())
- .setPathRelativeToSourceDir("Foo.java")
- .setFile(file)
+ .setModuleBaseDir(basedir.toPath())
.setType(InputFile.Type.MAIN);
when(filter.accept(eq(file), any(DeprecatedFileFilters.DeprecatedContext.class))).thenReturn(false);
@@ -73,8 +71,7 @@ public class DeprecatedFileFiltersTest {
DeprecatedFileFilters.DeprecatedContext context = argument.getValue();
assertThat(context.canonicalPath()).isEqualTo(FilenameUtils.separatorsToUnix(file.getAbsolutePath()));
- assertThat(context.relativeDir()).isEqualTo(new File(basedir, "src/main/java"));
- assertThat(context.relativePath()).isEqualTo("Foo.java");
+ assertThat(context.relativePath()).isEqualTo("src/main/java/Foo.java");
assertThat(context.type()).isEqualTo(FileType.MAIN);
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ExclusionFiltersTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ExclusionFiltersTest.java
index 02478075c9c..c5bd36cddf5 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ExclusionFiltersTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ExclusionFiltersTest.java
@@ -28,6 +28,7 @@ import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.config.Settings;
import org.sonar.api.scan.filesystem.FileExclusions;
+import java.io.File;
import java.io.IOException;
import static org.assertj.core.api.Assertions.assertThat;
@@ -43,7 +44,7 @@ public class ExclusionFiltersTest {
filter.prepare();
java.io.File file = temp.newFile();
- DefaultInputFile inputFile = new DefaultInputFile("foo", "src/main/java/com/mycompany/FooDao.java").setFile(file);
+ DefaultInputFile inputFile = new DefaultInputFile("foo", "src/main/java/com/mycompany/FooDao.java").setModuleBaseDir(temp.newFolder().toPath());
assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isTrue();
assertThat(filter.accept(inputFile, InputFile.Type.TEST)).isTrue();
}
@@ -56,10 +57,10 @@ public class ExclusionFiltersTest {
filter.prepare();
java.io.File file = temp.newFile();
- DefaultInputFile inputFile = new DefaultInputFile("foo", "src/main/java/com/mycompany/FooDao.java").setFile(file);
+ DefaultInputFile inputFile = new DefaultInputFile("foo", "src/main/java/com/mycompany/FooDao.java").setModuleBaseDir(temp.newFolder().toPath());
assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isTrue();
- inputFile = new DefaultInputFile("foo", "src/main/java/com/mycompany/Foo.java").setFile(file);
+ inputFile = new DefaultInputFile("foo", "src/main/java/com/mycompany/Foo.java").setModuleBaseDir(temp.newFolder().toPath());
assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isFalse();
}
@@ -73,10 +74,10 @@ public class ExclusionFiltersTest {
java.io.File file = temp.newFile();
- DefaultInputFile inputFile = new DefaultInputFile("foo", "src/main/java/com/mycompany/Foo.java").setFile(file);
+ DefaultInputFile inputFile = new DefaultInputFile("foo", "src/main/java/com/mycompany/Foo.java").setModuleBaseDir(temp.newFolder().toPath());
assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isFalse();
- inputFile = new DefaultInputFile("foo", "src/main/java/com/mycompany/FooDto.java").setFile(file);
+ inputFile = new DefaultInputFile("foo", "src/main/java/com/mycompany/FooDto.java").setModuleBaseDir(temp.newFolder().toPath());
assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isTrue();
}
@@ -91,21 +92,21 @@ public class ExclusionFiltersTest {
filter.prepare();
java.io.File file = temp.newFile();
- DefaultInputFile inputFile = new DefaultInputFile("foo", "src/main/java/com/mycompany/FooDao.java").setFile(file);
+ DefaultInputFile inputFile = new DefaultInputFile("foo", "src/main/java/com/mycompany/FooDao.java").setModuleBaseDir(temp.newFolder().toPath());
assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isFalse();
- inputFile = new DefaultInputFile("foo", "src/main/java/com/mycompany/Foo.java").setFile(file);
+ inputFile = new DefaultInputFile("foo", "src/main/java/com/mycompany/Foo.java").setModuleBaseDir(temp.newFolder().toPath());
assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isTrue();
// source exclusions do not apply to tests
- inputFile = new DefaultInputFile("foo", "src/test/java/com/mycompany/FooDao.java").setFile(file);
+ inputFile = new DefaultInputFile("foo", "src/test/java/com/mycompany/FooDao.java").setModuleBaseDir(temp.newFolder().toPath());
assertThat(filter.accept(inputFile, InputFile.Type.TEST)).isTrue();
}
@Test
public void match_exclusion_by_absolute_path() throws IOException {
- java.io.File includedFile = temp.newFile("Foo.java");
- java.io.File excludedFile = temp.newFile("Bar.java");
+ File baseDir = temp.newFile();
+ File excludedFile = new File(baseDir, "src/main/java/org/bar/Bar.java");
Settings settings = new Settings();
settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "src/main/java/**/*");
@@ -114,10 +115,10 @@ public class ExclusionFiltersTest {
filter.prepare();
- DefaultInputFile inputFile = new DefaultInputFile("foo", "src/main/java/org/bar/Foo.java").setFile(includedFile);
+ DefaultInputFile inputFile = new DefaultInputFile("foo", "src/main/java/org/bar/Foo.java").setModuleBaseDir(baseDir.toPath());
assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isTrue();
- inputFile = new DefaultInputFile("foo", "src/main/java/org/bar/Bar.java").setFile(excludedFile);
+ inputFile = new DefaultInputFile("foo", "src/main/java/org/bar/Bar.java").setModuleBaseDir(baseDir.toPath());
assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isFalse();
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileMetadataTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileMetadataTest.java
index cbfcb03242b..b34c5d50271 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileMetadataTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileMetadataTest.java
@@ -25,12 +25,13 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
+import org.sonar.api.batch.AnalysisMode;
import java.io.File;
-import static org.apache.commons.codec.digest.DigestUtils.md5;
import static org.apache.commons.codec.digest.DigestUtils.md5Hex;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
public class FileMetadataTest {
@@ -40,17 +41,18 @@ public class FileMetadataTest {
@Rule
public TemporaryFolder temp = new TemporaryFolder();
+ private AnalysisMode mode = mock(AnalysisMode.class);
+
@Test
public void empty_file() throws Exception {
File tempFile = temp.newFile();
FileUtils.touch(tempFile);
- FileMetadata.Metadata metadata = new FileMetadata().read(tempFile, Charsets.UTF_8);
+ FileMetadata.Metadata metadata = new FileMetadata(mode).read(tempFile, Charsets.UTF_8);
assertThat(metadata.lines).isEqualTo(1);
assertThat(metadata.nonBlankLines).isEqualTo(0);
assertThat(metadata.hash).isNotEmpty();
assertThat(metadata.originalLineOffsets).containsOnly(0);
- assertThat(metadata.lineHashes[0]).isNull();
assertThat(metadata.empty).isTrue();
}
@@ -59,14 +61,11 @@ public class FileMetadataTest {
File tempFile = temp.newFile();
FileUtils.write(tempFile, "foo\r\nbar\r\nbaz", Charsets.UTF_8, true);
- FileMetadata.Metadata metadata = new FileMetadata().read(tempFile, Charsets.UTF_8);
+ FileMetadata.Metadata metadata = new FileMetadata(mode).read(tempFile, Charsets.UTF_8);
assertThat(metadata.lines).isEqualTo(3);
assertThat(metadata.nonBlankLines).isEqualTo(3);
assertThat(metadata.hash).isEqualTo(md5Hex("foo\nbar\nbaz"));
assertThat(metadata.originalLineOffsets).containsOnly(0, 5, 10);
- assertThat(metadata.lineHashes[0]).containsOnly(md5("foo"));
- assertThat(metadata.lineHashes[1]).containsOnly(md5("bar"));
- assertThat(metadata.lineHashes[2]).containsOnly(md5("baz"));
assertThat(metadata.empty).isFalse();
}
@@ -75,15 +74,11 @@ public class FileMetadataTest {
File tempFile = temp.newFile();
FileUtils.write(tempFile, "föo\r\nbàr\r\n\u1D11Ebaßz\r\n", Charsets.UTF_8, true);
- FileMetadata.Metadata metadata = new FileMetadata().read(tempFile, Charsets.UTF_8);
+ FileMetadata.Metadata metadata = new FileMetadata(mode).read(tempFile, Charsets.UTF_8);
assertThat(metadata.lines).isEqualTo(4);
assertThat(metadata.nonBlankLines).isEqualTo(3);
assertThat(metadata.hash).isEqualTo(md5Hex("föo\nbàr\n\u1D11Ebaßz\n"));
assertThat(metadata.originalLineOffsets).containsOnly(0, 5, 10, 18);
- assertThat(metadata.lineHashes[0]).containsExactly(md5("föo"));
- assertThat(metadata.lineHashes[1]).containsExactly(md5("bàr"));
- assertThat(metadata.lineHashes[2]).containsExactly(md5("\u1D11Ebaßz"));
- assertThat(metadata.lineHashes[3]).isNull();
}
@Test
@@ -91,15 +86,11 @@ public class FileMetadataTest {
File tempFile = temp.newFile();
FileUtils.write(tempFile, "föo\r\nbàr\r\n\u1D11Ebaßz\r\n", Charsets.UTF_16, true);
- FileMetadata.Metadata metadata = new FileMetadata().read(tempFile, Charsets.UTF_16);
+ FileMetadata.Metadata metadata = new FileMetadata(mode).read(tempFile, Charsets.UTF_16);
assertThat(metadata.lines).isEqualTo(4);
assertThat(metadata.nonBlankLines).isEqualTo(3);
assertThat(metadata.hash).isEqualTo(md5Hex("föo\nbàr\n\u1D11Ebaßz\n"));
assertThat(metadata.originalLineOffsets).containsOnly(0, 5, 10, 18);
- assertThat(metadata.lineHashes[0]).containsExactly(md5("föo"));
- assertThat(metadata.lineHashes[1]).containsExactly(md5("bàr"));
- assertThat(metadata.lineHashes[2]).containsExactly(md5("\u1D11Ebaßz"));
- assertThat(metadata.lineHashes[3]).isNull();
}
@Test
@@ -107,14 +98,11 @@ public class FileMetadataTest {
File tempFile = temp.newFile();
FileUtils.write(tempFile, "foo\nbar\nbaz", Charsets.UTF_8, true);
- FileMetadata.Metadata metadata = new FileMetadata().read(tempFile, Charsets.UTF_8);
+ FileMetadata.Metadata metadata = new FileMetadata(mode).read(tempFile, Charsets.UTF_8);
assertThat(metadata.lines).isEqualTo(3);
assertThat(metadata.nonBlankLines).isEqualTo(3);
assertThat(metadata.hash).isEqualTo(md5Hex("foo\nbar\nbaz"));
assertThat(metadata.originalLineOffsets).containsOnly(0, 4, 8);
- assertThat(metadata.lineHashes[0]).containsOnly(md5("foo"));
- assertThat(metadata.lineHashes[1]).containsOnly(md5("bar"));
- assertThat(metadata.lineHashes[2]).containsOnly(md5("baz"));
}
@Test
@@ -122,15 +110,11 @@ public class FileMetadataTest {
File tempFile = temp.newFile();
FileUtils.write(tempFile, "foo\nbar\nbaz\n", Charsets.UTF_8, true);
- FileMetadata.Metadata metadata = new FileMetadata().read(tempFile, Charsets.UTF_8);
+ FileMetadata.Metadata metadata = new FileMetadata(mode).read(tempFile, Charsets.UTF_8);
assertThat(metadata.lines).isEqualTo(4);
assertThat(metadata.nonBlankLines).isEqualTo(3);
assertThat(metadata.hash).isEqualTo(md5Hex("foo\nbar\nbaz\n"));
assertThat(metadata.originalLineOffsets).containsOnly(0, 4, 8, 12);
- assertThat(metadata.lineHashes[0]).containsOnly(md5("foo"));
- assertThat(metadata.lineHashes[1]).containsOnly(md5("bar"));
- assertThat(metadata.lineHashes[2]).containsOnly(md5("baz"));
- assertThat(metadata.lineHashes[3]).isNull();
}
@Test
@@ -138,15 +122,11 @@ public class FileMetadataTest {
File tempFile = temp.newFile();
FileUtils.write(tempFile, "foo\nbar\r\nbaz\n", Charsets.UTF_8, true);
- FileMetadata.Metadata metadata = new FileMetadata().read(tempFile, Charsets.UTF_8);
+ FileMetadata.Metadata metadata = new FileMetadata(mode).read(tempFile, Charsets.UTF_8);
assertThat(metadata.lines).isEqualTo(4);
assertThat(metadata.nonBlankLines).isEqualTo(3);
assertThat(metadata.hash).isEqualTo(md5Hex("foo\nbar\nbaz\n"));
assertThat(metadata.originalLineOffsets).containsOnly(0, 4, 9, 13);
- assertThat(metadata.lineHashes[0]).containsOnly(md5("foo"));
- assertThat(metadata.lineHashes[1]).containsOnly(md5("bar"));
- assertThat(metadata.lineHashes[2]).containsOnly(md5("baz"));
- assertThat(metadata.lineHashes[3]).isNull();
}
@Test
@@ -154,15 +134,11 @@ public class FileMetadataTest {
File tempFile = temp.newFile();
FileUtils.write(tempFile, "foo\n\n\nbar", Charsets.UTF_8, true);
- FileMetadata.Metadata metadata = new FileMetadata().read(tempFile, Charsets.UTF_8);
+ FileMetadata.Metadata metadata = new FileMetadata(mode).read(tempFile, Charsets.UTF_8);
assertThat(metadata.lines).isEqualTo(4);
assertThat(metadata.nonBlankLines).isEqualTo(2);
assertThat(metadata.hash).isEqualTo(md5Hex("foo\n\n\nbar"));
assertThat(metadata.originalLineOffsets).containsOnly(0, 4, 5, 6);
- assertThat(metadata.lineHashes[0]).containsOnly(md5("foo"));
- assertThat(metadata.lineHashes[1]).isNull();
- assertThat(metadata.lineHashes[2]).isNull();
- assertThat(metadata.lineHashes[3]).containsOnly(md5("bar"));
}
@Test
@@ -170,14 +146,11 @@ public class FileMetadataTest {
File tempFile = temp.newFile();
FileUtils.write(tempFile, "foo\nbar\r\nbaz", Charsets.UTF_8, true);
- FileMetadata.Metadata metadata = new FileMetadata().read(tempFile, Charsets.UTF_8);
+ FileMetadata.Metadata metadata = new FileMetadata(mode).read(tempFile, Charsets.UTF_8);
assertThat(metadata.lines).isEqualTo(3);
assertThat(metadata.nonBlankLines).isEqualTo(3);
assertThat(metadata.hash).isEqualTo(md5Hex("foo\nbar\nbaz"));
assertThat(metadata.originalLineOffsets).containsOnly(0, 4, 9);
- assertThat(metadata.lineHashes[0]).containsOnly(md5("foo"));
- assertThat(metadata.lineHashes[1]).containsOnly(md5("bar"));
- assertThat(metadata.lineHashes[2]).containsOnly(md5("baz"));
}
@Test
@@ -185,15 +158,11 @@ public class FileMetadataTest {
File tempFile = temp.newFile();
FileUtils.write(tempFile, "\nfoo\nbar\r\nbaz", Charsets.UTF_8, true);
- FileMetadata.Metadata metadata = new FileMetadata().read(tempFile, Charsets.UTF_8);
+ FileMetadata.Metadata metadata = new FileMetadata(mode).read(tempFile, Charsets.UTF_8);
assertThat(metadata.lines).isEqualTo(4);
assertThat(metadata.nonBlankLines).isEqualTo(3);
assertThat(metadata.hash).isEqualTo(md5Hex("\nfoo\nbar\nbaz"));
assertThat(metadata.originalLineOffsets).containsOnly(0, 1, 5, 10);
- assertThat(metadata.lineHashes[0]).isNull();
- assertThat(metadata.lineHashes[1]).containsOnly(md5("foo"));
- assertThat(metadata.lineHashes[2]).containsOnly(md5("bar"));
- assertThat(metadata.lineHashes[3]).containsOnly(md5("baz"));
}
@Test
@@ -201,14 +170,11 @@ public class FileMetadataTest {
File tempFile = temp.newFile();
FileUtils.write(tempFile, "\uFEFFfoo\nbar\r\nbaz", Charsets.UTF_8, true);
- FileMetadata.Metadata metadata = new FileMetadata().read(tempFile, Charsets.UTF_8);
+ FileMetadata.Metadata metadata = new FileMetadata(mode).read(tempFile, Charsets.UTF_8);
assertThat(metadata.lines).isEqualTo(3);
assertThat(metadata.nonBlankLines).isEqualTo(3);
assertThat(metadata.hash).isEqualTo(md5Hex("foo\nbar\nbaz"));
assertThat(metadata.originalLineOffsets).containsOnly(0, 4, 9);
- assertThat(metadata.lineHashes[0]).containsOnly(md5("foo"));
- assertThat(metadata.lineHashes[1]).containsOnly(md5("bar"));
- assertThat(metadata.lineHashes[2]).containsOnly(md5("baz"));
}
@Test
@@ -216,13 +182,10 @@ public class FileMetadataTest {
File tempFile = temp.newFile();
FileUtils.write(tempFile, " foo\nb ar\r\nbaz \t", Charsets.UTF_8, true);
- FileMetadata.Metadata metadata = new FileMetadata().read(tempFile, Charsets.UTF_8);
+ FileMetadata.Metadata metadata = new FileMetadata(mode).read(tempFile, Charsets.UTF_8);
assertThat(metadata.lines).isEqualTo(3);
assertThat(metadata.nonBlankLines).isEqualTo(3);
assertThat(metadata.hash).isEqualTo(md5Hex(" foo\nb ar\nbaz \t"));
- assertThat(metadata.lineHashes[0]).containsOnly(md5("foo"));
- assertThat(metadata.lineHashes[1]).containsOnly(md5("bar"));
- assertThat(metadata.lineHashes[2]).containsOnly(md5("baz"));
}
@Test
@@ -233,7 +196,7 @@ public class FileMetadataTest {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("Fail to read file '" + file.getAbsolutePath() + "' with encoding 'UTF-8'");
- new FileMetadata().read(file, Charsets.UTF_8);
+ new FileMetadata(mode).read(file, Charsets.UTF_8);
}
@Test
@@ -248,9 +211,9 @@ public class FileMetadataTest {
File file2 = temp.newFile();
FileUtils.write(file2, "foo\nbar", Charsets.UTF_8, true);
- String hash1 = new FileMetadata().read(file1, Charsets.UTF_8).hash;
- String hash1a = new FileMetadata().read(file1a, Charsets.UTF_8).hash;
- String hash2 = new FileMetadata().read(file2, Charsets.UTF_8).hash;
+ String hash1 = new FileMetadata(mode).read(file1, Charsets.UTF_8).hash;
+ String hash1a = new FileMetadata(mode).read(file1a, Charsets.UTF_8).hash;
+ String hash2 = new FileMetadata(mode).read(file2, Charsets.UTF_8).hash;
assertThat(hash1).isEqualTo(hash1a);
assertThat(hash1).isNotEqualTo(hash2);
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileBuilderFactoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileBuilderFactoryTest.java
index e702dbbfa81..2b5b1f4bcca 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileBuilderFactoryTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileBuilderFactoryTest.java
@@ -39,7 +39,7 @@ public class InputFileBuilderFactoryTest {
DefaultAnalysisMode analysisMode = mock(DefaultAnalysisMode.class);
InputFileBuilderFactory factory = new InputFileBuilderFactory(ProjectDefinition.create().setKey("struts"), pathResolver, langDetectionFactory,
- statusDetectionFactory, analysisMode, new Settings());
+ statusDetectionFactory, analysisMode, new Settings(), new FileMetadata(analysisMode));
InputFileBuilder builder = factory.create(fs);
assertThat(builder.langDetection()).isNotNull();
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileBuilderTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileBuilderTest.java
index 36682184b37..df058f13c8f 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileBuilderTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileBuilderTest.java
@@ -32,7 +32,6 @@ import org.sonar.api.utils.PathUtils;
import org.sonar.batch.bootstrap.DefaultAnalysisMode;
import java.io.File;
-import java.util.Arrays;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
@@ -67,9 +66,9 @@ public class InputFileBuilderTest {
.thenReturn(InputFile.Status.ADDED);
InputFileBuilder builder = new InputFileBuilder("struts", new PathResolver(),
- langDetection, statusDetection, fs, analysisMode, new Settings());
+ langDetection, statusDetection, fs, analysisMode, new Settings(), new FileMetadata(analysisMode));
DeprecatedDefaultInputFile inputFile = builder.create(srcFile);
- inputFile = builder.complete(inputFile, InputFile.Type.MAIN);
+ builder.completeAndComputeMetadata(inputFile, InputFile.Type.MAIN);
assertThat(inputFile.type()).isEqualTo(InputFile.Type.MAIN);
assertThat(inputFile.file()).isEqualTo(srcFile.getAbsoluteFile());
@@ -78,9 +77,6 @@ public class InputFileBuilderTest {
assertThat(inputFile.key()).isEqualTo("struts:src/main/java/foo/Bar.java");
assertThat(inputFile.relativePath()).isEqualTo("src/main/java/foo/Bar.java");
assertThat(inputFile.lines()).isEqualTo(1);
- assertThat(inputFile.sourceDirAbsolutePath()).isNull();
- assertThat(inputFile.pathRelativeToSourceDir()).isNull();
- assertThat(inputFile.deprecatedKey()).isNull();
}
@Test
@@ -93,7 +89,7 @@ public class InputFileBuilderTest {
when(fs.baseDir()).thenReturn(basedir);
InputFileBuilder builder = new InputFileBuilder("struts", new PathResolver(),
- langDetection, statusDetection, fs, analysisMode, new Settings());
+ langDetection, statusDetection, fs, analysisMode, new Settings(), new FileMetadata(analysisMode));
DeprecatedDefaultInputFile inputFile = builder.create(srcFile);
assertThat(inputFile).isNull();
@@ -113,69 +109,11 @@ public class InputFileBuilderTest {
when(langDetection.language(any(InputFile.class))).thenReturn(null);
InputFileBuilder builder = new InputFileBuilder("struts", new PathResolver(),
- langDetection, statusDetection, fs, analysisMode, new Settings());
+ langDetection, statusDetection, fs, analysisMode, new Settings(), new FileMetadata(analysisMode));
DeprecatedDefaultInputFile inputFile = builder.create(srcFile);
- inputFile = builder.complete(inputFile, InputFile.Type.MAIN);
+ InputFileMetadata metadata = builder.completeAndComputeMetadata(inputFile, InputFile.Type.MAIN);
- assertThat(inputFile).isNull();
- }
-
- @Test
- public void fill_deprecated_data_of_java_file() throws Exception {
- // file system
- File basedir = temp.newFolder();
- File srcFile = new File(basedir, "src/main/java/foo/Bar.java");
- FileUtils.touch(srcFile);
- FileUtils.write(srcFile, "single line");
- when(fs.baseDir()).thenReturn(basedir);
- when(fs.encoding()).thenReturn(Charsets.UTF_8);
- File sourceDir = new File(basedir, "src/main/java");
- when(fs.sourceDirs()).thenReturn(Arrays.asList(sourceDir));
-
- // lang
- when(langDetection.language(any(InputFile.class))).thenReturn("java");
-
- // status
- when(statusDetection.status("foo", "src/main/java/foo/Bar.java", "6c1d64c0b3555892fe7273e954f6fb5a"))
- .thenReturn(InputFile.Status.ADDED);
-
- InputFileBuilder builder = new InputFileBuilder("struts", new PathResolver(),
- langDetection, statusDetection, fs, analysisMode, new Settings());
- DeprecatedDefaultInputFile inputFile = builder.create(srcFile);
- inputFile = builder.complete(inputFile, InputFile.Type.MAIN);
-
- assertThat(inputFile.pathRelativeToSourceDir()).isEqualTo("foo/Bar.java");
- assertThat(inputFile.sourceDirAbsolutePath()).isEqualTo(PathUtils.sanitize(sourceDir.getAbsolutePath()));
- assertThat(inputFile.deprecatedKey()).isEqualTo("struts:foo.Bar");
+ assertThat(metadata).isNull();
}
- @Test
- public void fill_deprecated_data_of_non_java_file() throws Exception {
- // file system
- File basedir = temp.newFolder();
- File srcFile = new File(basedir, "src/foo/Bar.php");
- FileUtils.touch(srcFile);
- FileUtils.write(srcFile, "single line");
- when(fs.baseDir()).thenReturn(basedir);
- when(fs.encoding()).thenReturn(Charsets.UTF_8);
- File sourceDir = new File(basedir, "src");
- when(fs.sourceDirs()).thenReturn(Arrays.asList(sourceDir));
-
- // lang
- when(langDetection.language(any(InputFile.class))).thenReturn("php");
-
- // status
- when(statusDetection.status("foo", "src/Bar.php", "6c1d64c0b3555892fe7273e954f6fb5a"))
- .thenReturn(InputFile.Status.ADDED);
-
- InputFileBuilder builder = new InputFileBuilder("struts", new PathResolver(),
- langDetection, statusDetection, fs, analysisMode, new Settings());
- DeprecatedDefaultInputFile inputFile = builder.create(srcFile);
- inputFile = builder.complete(inputFile, InputFile.Type.MAIN);
-
- assertThat(inputFile.pathRelativeToSourceDir()).isEqualTo("foo/Bar.php");
- assertThat(inputFile.sourceDirAbsolutePath()).isEqualTo(PathUtils.sanitize(sourceDir.getAbsolutePath()));
- assertThat(inputFile.deprecatedKey()).isEqualTo("struts:foo/Bar.php");
-
- }
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputPathCacheTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputPathCacheTest.java
index 1a38d6e998c..7c943e06f66 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputPathCacheTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputPathCacheTest.java
@@ -19,7 +19,7 @@
*/
package org.sonar.batch.scan.filesystem;
-import org.apache.commons.codec.digest.DigestUtils;
+import com.google.common.base.Charsets;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
@@ -30,8 +30,6 @@ 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.DeprecatedDefaultInputFile;
-import org.sonar.batch.index.Caches;
-import org.sonar.batch.index.CachesTest;
import static org.assertj.core.api.Assertions.assertThat;
@@ -40,59 +38,61 @@ public class InputPathCacheTest {
@Rule
public TemporaryFolder temp = new TemporaryFolder();
- Caches caches;
-
@Before
public void start() throws Exception {
- caches = CachesTest.createCacheOnTemp(temp);
- caches.start();
}
@After
public void stop() {
- caches.stop();
}
@Test
public void should_add_input_file() throws Exception {
- InputPathCache cache = new InputPathCache(caches);
- DefaultInputFile fooFile = new DefaultInputFile("foo", "src/main/java/Foo.java").setFile(temp.newFile("Foo.java"));
+ InputPathCache cache = new InputPathCache();
+ DefaultInputFile fooFile = new DefaultInputFile("foo", "src/main/java/Foo.java").setModuleBaseDir(temp.newFolder().toPath());
cache.put("struts", fooFile);
cache.put("struts-core", new DeprecatedDefaultInputFile("foo", "src/main/java/Bar.java")
- .setBasedir(temp.newFolder())
- .setDeprecatedKey("foo")
- .setSourceDirAbsolutePath("foo")
- .setPathRelativeToSourceDir("foo")
.setLanguage("bla")
.setType(Type.MAIN)
.setStatus(Status.ADDED)
- .setHash("xyz")
.setLines(2)
- .setEncoding("UTF-8")
- .setOriginalLineOffsets(new long[] {0, 4})
- .setLineHashes(new byte[][] {DigestUtils.md5("foo"), DigestUtils.md5("bar")})
- .setFile(temp.newFile("Bar.java")));
+ .setCharset(Charsets.UTF_8)
+ .setModuleBaseDir(temp.newFolder().toPath()));
DefaultInputFile loadedFile = (DefaultInputFile) cache.getFile("struts-core", "src/main/java/Bar.java");
assertThat(loadedFile.relativePath()).isEqualTo("src/main/java/Bar.java");
- assertThat(loadedFile.encoding()).isEqualTo("UTF-8");
- assertThat(loadedFile.originalLineOffsets()).containsOnly(0, 4);
- assertThat(loadedFile.lineHashes()[0]).containsOnly(DigestUtils.md5("foo"));
- assertThat(loadedFile.lineHashes()[1]).containsOnly(DigestUtils.md5("bar"));
+ assertThat(loadedFile.charset()).isEqualTo(Charsets.UTF_8);
assertThat(cache.filesByModule("struts")).hasSize(1);
assertThat(cache.filesByModule("struts-core")).hasSize(1);
- assertThat(cache.all()).hasSize(2);
- for (InputPath inputPath : cache.all()) {
+ assertThat(cache.allFiles()).hasSize(2);
+ for (InputPath inputPath : cache.allFiles()) {
assertThat(inputPath.relativePath()).startsWith("src/main/java/");
}
cache.remove("struts", fooFile);
- assertThat(cache.all()).hasSize(1);
+ assertThat(cache.allFiles()).hasSize(1);
cache.removeModule("struts");
assertThat(cache.filesByModule("struts")).hasSize(0);
assertThat(cache.filesByModule("struts-core")).hasSize(1);
- assertThat(cache.all()).hasSize(1);
+ assertThat(cache.allFiles()).hasSize(1);
+ }
+
+ @Test
+ public void should_add_input_file_metadata() throws Exception {
+ InputPathCache cache = new InputPathCache();
+ cache.put("struts-core", "src/main/java/Bar.java", new InputFileMetadata()
+ .setHash("xyz")
+ .setNonBlankLines(2)
+ .setEmpty(true)
+ .setOriginalLineOffsets(new int[] {0, 4}));
+
+ InputFileMetadata loadedFileMetadata = cache.getFileMetadata("struts-core", "src/main/java/Bar.java");
+ assertThat(loadedFileMetadata.originalLineOffsets()).containsOnly(0, 4);
+ assertThat(loadedFileMetadata.hash()).isEqualTo("xyz");
+ assertThat(loadedFileMetadata.nonBlankLines()).isEqualTo(2);
+ assertThat(loadedFileMetadata.isEmpty()).isTrue();
+
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/LanguageDetectionFactoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/LanguageDetectionFactoryTest.java
index af30dcfc706..93b4d05145a 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/LanguageDetectionFactoryTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/LanguageDetectionFactoryTest.java
@@ -19,19 +19,19 @@
*/
package org.sonar.batch.scan.filesystem;
+import org.sonar.batch.repository.language.DefaultLanguagesRepository;
+import org.sonar.batch.repository.language.LanguagesRepository;
+
import org.junit.Test;
import org.sonar.api.config.Settings;
import org.sonar.api.resources.Java;
import org.sonar.api.resources.Languages;
-import org.sonar.batch.languages.DefaultLanguagesReferential;
-import org.sonar.batch.languages.LanguagesReferential;
-
import static org.assertj.core.api.Assertions.assertThat;
public class LanguageDetectionFactoryTest {
@Test
public void testCreate() throws Exception {
- LanguagesReferential languages = new DefaultLanguagesReferential(new Languages(Java.INSTANCE));
+ LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(Java.INSTANCE));
LanguageDetectionFactory factory = new LanguageDetectionFactory(new Settings(), languages);
LanguageDetection languageDetection = factory.create();
assertThat(languageDetection).isNotNull();
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/LanguageDetectionTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/LanguageDetectionTest.java
index e9155fd9c8a..95d3631eaa5 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/LanguageDetectionTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/LanguageDetectionTest.java
@@ -30,8 +30,8 @@ import org.sonar.api.config.Settings;
import org.sonar.api.resources.Language;
import org.sonar.api.resources.Languages;
import org.sonar.api.utils.MessageException;
-import org.sonar.batch.languages.DefaultLanguagesReferential;
-import org.sonar.batch.languages.LanguagesReferential;
+import org.sonar.batch.repository.language.DefaultLanguagesRepository;
+import org.sonar.batch.repository.language.LanguagesRepository;
import java.io.File;
import java.io.IOException;
@@ -58,7 +58,7 @@ public class LanguageDetectionTest {
@Test
public void search_by_file_extension() throws Exception {
- LanguagesReferential languages = new DefaultLanguagesReferential(new Languages(new MockLanguage("java", "java", "jav"), new MockLanguage("cobol", "cbl", "cob")));
+ LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("java", "java", "jav"), new MockLanguage("cobol", "cbl", "cob")));
LanguageDetection detection = new LanguageDetection(new Settings(), languages);
assertThat(detection.language(newInputFile("Foo.java"))).isEqualTo("java");
@@ -76,13 +76,13 @@ public class LanguageDetectionTest {
@Test
public void should_not_fail_if_no_language() throws Exception {
- LanguageDetection detection = spy(new LanguageDetection(new Settings(), new DefaultLanguagesReferential(new Languages())));
+ LanguageDetection detection = spy(new LanguageDetection(new Settings(), new DefaultLanguagesRepository(new Languages())));
assertThat(detection.language(newInputFile("Foo.java"))).isNull();
}
@Test
public void plugin_can_declare_a_file_extension_twice_for_case_sensitivity() throws Exception {
- LanguagesReferential languages = new DefaultLanguagesReferential(new Languages(new MockLanguage("abap", "abap", "ABAP")));
+ LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("abap", "abap", "ABAP")));
LanguageDetection detection = new LanguageDetection(new Settings(), languages);
assertThat(detection.language(newInputFile("abc.abap"))).isEqualTo("abap");
@@ -92,7 +92,7 @@ public class LanguageDetectionTest {
public void language_with_no_extension() throws Exception {
// abap does not declare any file extensions.
// When analyzing an ABAP project, then all source files must be parsed.
- LanguagesReferential languages = new DefaultLanguagesReferential(new Languages(new MockLanguage("java", "java"), new MockLanguage("abap")));
+ LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("java", "java"), new MockLanguage("abap")));
// No side-effect on non-ABAP projects
LanguageDetection detection = new LanguageDetection(new Settings(), languages);
@@ -110,7 +110,7 @@ public class LanguageDetectionTest {
@Test
public void force_language_using_deprecated_property() throws Exception {
- LanguagesReferential languages = new DefaultLanguagesReferential(new Languages(new MockLanguage("java", "java"), new MockLanguage("php", "php")));
+ LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("java", "java"), new MockLanguage("php", "php")));
Settings settings = new Settings();
settings.setProperty(CoreProperties.PROJECT_LANGUAGE_PROPERTY, "java");
@@ -126,7 +126,7 @@ public class LanguageDetectionTest {
thrown.expect(MessageException.class);
thrown.expectMessage("No language is installed with key 'unknown'. Please update property 'sonar.language'");
- LanguagesReferential languages = new DefaultLanguagesReferential(new Languages(new MockLanguage("java", "java"), new MockLanguage("php", "php")));
+ LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("java", "java"), new MockLanguage("php", "php")));
Settings settings = new Settings();
settings.setProperty(CoreProperties.PROJECT_LANGUAGE_PROPERTY, "unknown");
new LanguageDetection(settings, languages);
@@ -134,7 +134,7 @@ public class LanguageDetectionTest {
@Test
public void fail_if_conflicting_language_suffix() throws Exception {
- LanguagesReferential languages = new DefaultLanguagesReferential(new Languages(new MockLanguage("xml", "xhtml"), new MockLanguage("web", "xhtml")));
+ LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("xml", "xhtml"), new MockLanguage("web", "xhtml")));
LanguageDetection detection = new LanguageDetection(new Settings(), languages);
try {
detection.language(newInputFile("abc.xhtml"));
@@ -149,7 +149,7 @@ public class LanguageDetectionTest {
@Test
public void solve_conflict_using_filepattern() throws Exception {
- LanguagesReferential languages = new DefaultLanguagesReferential(new Languages(new MockLanguage("xml", "xhtml"), new MockLanguage("web", "xhtml")));
+ LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("xml", "xhtml"), new MockLanguage("web", "xhtml")));
Settings settings = new Settings();
settings.setProperty("sonar.lang.patterns.xml", "xml/**");
@@ -161,7 +161,7 @@ public class LanguageDetectionTest {
@Test
public void fail_if_conflicting_filepattern() throws Exception {
- LanguagesReferential languages = new DefaultLanguagesReferential(new Languages(new MockLanguage("abap", "abap"), new MockLanguage("cobol", "cobol")));
+ LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("abap", "abap"), new MockLanguage("cobol", "cobol")));
Settings settings = new Settings();
settings.setProperty("sonar.lang.patterns.abap", "*.abap,*.txt");
settings.setProperty("sonar.lang.patterns.cobol", "*.cobol,*.txt");
@@ -183,7 +183,7 @@ public class LanguageDetectionTest {
private InputFile newInputFile(String path) throws IOException {
File basedir = temp.newFolder();
- return new DefaultInputFile("foo", path).setFile(new File(basedir, path));
+ return new DefaultInputFile("foo", path).setModuleBaseDir(basedir.toPath());
}
static class MockLanguage implements Language {
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/measure/MeasureCacheTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/measure/MeasureCacheTest.java
index ebb97af6492..7aa5c49856d 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/measure/MeasureCacheTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/measure/MeasureCacheTest.java
@@ -233,9 +233,9 @@ public class MeasureCacheTest {
@Test
public void should_get_measures() throws Exception {
Project p = new Project("struts");
- Resource dir = new Directory("foo/bar").setEffectiveKey("struts:foo/bar");
- Resource file1 = new File("foo/bar/File1.txt").setEffectiveKey("struts:foo/bar/File1.txt");
- Resource file2 = new File("foo/bar/File2.txt").setEffectiveKey("struts:foo/bar/File2.txt");
+ Resource dir = Directory.create("foo/bar").setEffectiveKey("struts:foo/bar");
+ Resource file1 = Directory.create("foo/bar/File1.txt").setEffectiveKey("struts:foo/bar/File1.txt");
+ Resource file2 = Directory.create("foo/bar/File2.txt").setEffectiveKey("struts:foo/bar/File2.txt");
assertThat(cache.entries()).hasSize(0);
@@ -271,7 +271,7 @@ public class MeasureCacheTest {
@Test
public void test_measure_coder() throws Exception {
- Resource file1 = new File("foo/bar/File1.txt").setEffectiveKey("struts:foo/bar/File1.txt");
+ Resource file1 = File.create("foo/bar/File1.txt").setEffectiveKey("struts:foo/bar/File1.txt");
Measure measure = new Measure(CoreMetrics.NCLOC, 1.786, 5);
cache.put(file1, measure);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/report/JSONReportTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/report/JSONReportTest.java
index 786d5a7f040..1e61491a8c1 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/report/JSONReportTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/report/JSONReportTest.java
@@ -27,8 +27,8 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.skyscreamer.jsonassert.JSONAssert;
+import org.sonar.api.batch.fs.InputDir;
import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.fs.InputPath;
import org.sonar.api.batch.fs.internal.DefaultFileSystem;
import org.sonar.api.batch.fs.internal.DefaultInputDir;
import org.sonar.api.batch.fs.internal.DeprecatedDefaultInputFile;
@@ -42,9 +42,9 @@ import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.rule.RuleKey;
import org.sonar.batch.issue.IssueCache;
+import org.sonar.batch.repository.user.User;
+import org.sonar.batch.repository.user.UserRepository;
import org.sonar.batch.scan.filesystem.InputPathCache;
-import org.sonar.batch.user.User;
-import org.sonar.batch.user.UserRepository;
import java.io.File;
import java.io.IOException;
@@ -77,7 +77,7 @@ public class JSONReportTest {
@Before
public void before() throws Exception {
- fs = new DefaultFileSystem(temp.newFolder());
+ fs = new DefaultFileSystem(temp.newFolder().toPath());
SIMPLE_DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT+02:00"));
when(resource.getEffectiveKey()).thenReturn("Action.java");
when(server.getVersion()).thenReturn("3.6");
@@ -86,7 +86,8 @@ public class JSONReportTest {
DeprecatedDefaultInputFile inputFile = new DeprecatedDefaultInputFile("struts", "src/main/java/org/apache/struts/Action.java");
inputFile.setStatus(InputFile.Status.CHANGED);
InputPathCache fileCache = mock(InputPathCache.class);
- when(fileCache.all()).thenReturn(Arrays.<InputPath>asList(inputDir, inputFile));
+ when(fileCache.allFiles()).thenReturn(Arrays.<InputFile>asList(inputFile));
+ when(fileCache.allDirs()).thenReturn(Arrays.<InputDir>asList(inputDir));
Project rootModule = new Project("struts");
Project moduleA = new Project("struts-core");
moduleA.setParent(rootModule).setPath("core");
diff --git a/sonar-batch/src/test/java/org/sonar/batch/sensor/AnalyzerOptimizerTest.java b/sonar-batch/src/test/java/org/sonar/batch/sensor/AnalyzerOptimizerTest.java
index d0cf02f65a3..1850fe2b001 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/sensor/AnalyzerOptimizerTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/sensor/AnalyzerOptimizerTest.java
@@ -53,7 +53,7 @@ public class AnalyzerOptimizerTest {
@Before
public void prepare() throws Exception {
- fs = new DefaultFileSystem(temp.newFolder());
+ fs = new DefaultFileSystem(temp.newFolder().toPath());
settings = new Settings();
analysisMode = mock(AnalysisMode.class);
optimizer = new AnalyzerOptimizer(fs, new ActiveRulesBuilder().build(), settings, analysisMode);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorContextTest.java b/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorContextTest.java
index e6d24b0643f..1812fde5cf4 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorContextTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorContextTest.java
@@ -58,7 +58,7 @@ public class DefaultSensorContextTest {
@Before
public void prepare() throws Exception {
activeRules = new ActiveRulesBuilder().build();
- fs = new DefaultFileSystem(temp.newFolder());
+ fs = new DefaultFileSystem(temp.newFolder().toPath());
MetricFinder metricFinder = mock(MetricFinder.class);
when(metricFinder.findByKey(CoreMetrics.NCLOC_KEY)).thenReturn(CoreMetrics.NCLOC);
when(metricFinder.findByKey(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION_KEY)).thenReturn(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorStorageTest.java b/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorStorageTest.java
index 658f48e41fd..506bcd328e1 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorStorageTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorStorageTest.java
@@ -84,7 +84,7 @@ public class DefaultSensorStorageTest {
@Before
public void prepare() throws Exception {
activeRules = new ActiveRulesBuilder().build();
- fs = new DefaultFileSystem(temp.newFolder());
+ fs = new DefaultFileSystem(temp.newFolder().toPath());
MetricFinder metricFinder = mock(MetricFinder.class);
when(metricFinder.findByKey(CoreMetrics.NCLOC_KEY)).thenReturn(CoreMetrics.NCLOC);
when(metricFinder.findByKey(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION_KEY)).thenReturn(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION);
@@ -279,7 +279,7 @@ public class DefaultSensorStorageTest {
when(sonarIndex.getEdge(foo, bar)).thenReturn(new Dependency(foo, bar));
thrown.expect(IllegalStateException.class);
- thrown.expectMessage("Dependency between [moduleKey=foo, relative=src/Foo.java, abs=null] and [moduleKey=foo, relative=src/Bar.java, abs=null] was already saved.");
+ thrown.expectMessage("Dependency between [moduleKey=foo, relative=src/Foo.java, basedir=null] and [moduleKey=foo, relative=src/Bar.java, basedir=null] was already saved.");
sensorStorage.store(new DefaultDependency()
.from(new DefaultInputFile("foo", "src/Foo.java").setType(Type.MAIN))
diff --git a/sonar-batch/src/test/java/org/sonar/batch/sensor/coverage/CoverageExclusionsTest.java b/sonar-batch/src/test/java/org/sonar/batch/sensor/coverage/CoverageExclusionsTest.java
index ec592a7962e..0e2efc2782a 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/sensor/coverage/CoverageExclusionsTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/sensor/coverage/CoverageExclusionsTest.java
@@ -54,7 +54,7 @@ public class CoverageExclusionsTest {
@Test
public void shouldFilterFileBasedOnPattern() {
- Resource resource = File.create("src/org/polop/File.php", "org/polop/File.php", null, false);
+ Resource resource = File.create("src/org/polop/File.php", null, false);
Measure coverageMeasure = mock(Measure.class);
when(coverageMeasure.getMetric()).thenReturn(CoreMetrics.LINES_TO_COVER);
@@ -65,7 +65,7 @@ public class CoverageExclusionsTest {
@Test
public void shouldNotFilterFileBasedOnPattern() {
- Resource resource = File.create("src/org/polop/File.php", "org/polop/File.php", null, false);
+ Resource resource = File.create("src/org/polop/File.php", null, false);
Measure coverageMeasure = mock(Measure.class);
when(coverageMeasure.getMetric()).thenReturn(CoreMetrics.COVERAGE);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/source/CodeColorizersTest.java b/sonar-batch/src/test/java/org/sonar/batch/source/CodeColorizersTest.java
index 58f1d3f86c8..a7486ad376b 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/source/CodeColorizersTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/source/CodeColorizersTest.java
@@ -19,6 +19,7 @@
*/
package org.sonar.batch.source;
+import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableList;
import org.apache.commons.io.FileUtils;
import org.junit.Rule;
@@ -52,7 +53,7 @@ public class CodeColorizersTest {
File jsFile = new File(this.getClass().getResource("CodeColorizersTest/Person.js").toURI());
- SyntaxHighlightingData syntaxHighlighting = codeColorizers.toSyntaxHighlighting(jsFile, "UTF-8", "js");
+ SyntaxHighlightingData syntaxHighlighting = codeColorizers.toSyntaxHighlighting(jsFile, Charsets.UTF_8, "js");
assertThat(syntaxHighlighting.writeString()).isEqualTo(HIGHLIGHTING_JS);
@@ -67,7 +68,7 @@ public class CodeColorizersTest {
File jsFile = new File(this.getClass().getResource("CodeColorizersTest/Person.js").toURI());
FileUtils.write(fileWithBom, FileUtils.readFileToString(jsFile), "UTF-8", true);
- SyntaxHighlightingData syntaxHighlighting = codeColorizers.toSyntaxHighlighting(fileWithBom, "UTF-8", "js");
+ SyntaxHighlightingData syntaxHighlighting = codeColorizers.toSyntaxHighlighting(fileWithBom, Charsets.UTF_8, "js");
assertThat(syntaxHighlighting.writeString()).isEqualTo(HIGHLIGHTING_JS);
}
@@ -78,7 +79,7 @@ public class CodeColorizersTest {
File javaFile = new File(this.getClass().getResource("CodeColorizersTest/Person.java").toURI());
- SyntaxHighlightingData syntaxHighlighting = codeColorizers.toSyntaxHighlighting(javaFile, "UTF-8", "java");
+ SyntaxHighlightingData syntaxHighlighting = codeColorizers.toSyntaxHighlighting(javaFile, Charsets.UTF_8, "java");
assertThat(syntaxHighlighting.writeString()).isEqualTo(HIGHLIGHTING_JAVA);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/source/HighlightableBuilderTest.java b/sonar-batch/src/test/java/org/sonar/batch/source/HighlightableBuilderTest.java
index 4a26c3b4bbf..e2adf2dd0db 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/source/HighlightableBuilderTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/source/HighlightableBuilderTest.java
@@ -37,7 +37,7 @@ public class HighlightableBuilderTest {
@Test
public void should_load_default_perspective() throws Exception {
- Resource file = new File("foo.c").setEffectiveKey("myproject:path/to/foo.c");
+ Resource file = File.create("foo.c").setEffectiveKey("myproject:path/to/foo.c");
Component component = new ResourceComponent(file);
HighlightableBuilder builder = new HighlightableBuilder(cache);
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByDateTest/shared.xml b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByDateTest/shared.xml
index d794c3a2422..d794c3a2422 100644
--- a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByDateTest/shared.xml
+++ b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByDateTest/shared.xml
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByDaysTest/shared.xml b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByDaysTest/shared.xml
index 119f7399b4d..119f7399b4d 100644
--- a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByDaysTest/shared.xml
+++ b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByDaysTest/shared.xml
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByDaysTest/shouldNotFindSelf.xml b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByDaysTest/shouldNotFindSelf.xml
index 166f7c18ea8..166f7c18ea8 100644
--- a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByDaysTest/shouldNotFindSelf.xml
+++ b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByDaysTest/shouldNotFindSelf.xml
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest/shouldFindPreviousAnalysis.xml b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousAnalysisTest/shouldFindPreviousAnalysis.xml
index eb5136dc808..eb5136dc808 100644
--- a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest/shouldFindPreviousAnalysis.xml
+++ b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousAnalysisTest/shouldFindPreviousAnalysis.xml
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest/shouldNotFindPreviousAnalysis.xml b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousAnalysisTest/shouldNotFindPreviousAnalysis.xml
index 5809598e5d7..5809598e5d7 100644
--- a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest/shouldNotFindPreviousAnalysis.xml
+++ b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousAnalysisTest/shouldNotFindPreviousAnalysis.xml
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest/no-previous-version.xml b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest/no-previous-version.xml
index 2f01f86b989..2f01f86b989 100644
--- a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest/no-previous-version.xml
+++ b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest/no-previous-version.xml
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest/with-previous-version-deleted.xml b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest/with-previous-version-deleted.xml
index d990e648414..d990e648414 100644
--- a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest/with-previous-version-deleted.xml
+++ b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest/with-previous-version-deleted.xml
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest/with-previous-version.xml b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest/with-previous-version.xml
index 5ecbc2fa959..5ecbc2fa959 100644
--- a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest/with-previous-version.xml
+++ b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest/with-previous-version.xml
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByVersionTest/shared.xml b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByVersionTest/shared.xml
index 289a362f781..289a362f781 100644
--- a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByVersionTest/shared.xml
+++ b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByVersionTest/shared.xml
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/components/PeriodsDefinitionTest/shared.xml b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PeriodsDefinitionTest/shared.xml
index c8796e2bb80..c8796e2bb80 100644
--- a/sonar-batch/src/test/resources/org/sonar/batch/components/PeriodsDefinitionTest/shared.xml
+++ b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PeriodsDefinitionTest/shared.xml
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewMultiModulesProject-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewMultiModulesProject-result.xml
index bed6ddbad3d..e168b6bc85d 100644
--- a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewMultiModulesProject-result.xml
+++ b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewMultiModulesProject-result.xml
@@ -31,7 +31,7 @@
enabled="true" language="[null]" copy_resource_id="[null]" person_id="[null]" path="src/main/java/org" deprecated_kee="[null]" />
<projects id="1006" scope="FIL" qualifier="FIL" kee="b1:src/main/java/org/Foo.java" root_id="1004"
- name="src/main/java/org/Foo.java" long_name="src/main/java/org/Foo.java" description="[null]"
+ name="Foo.java" long_name="src/main/java/org/Foo.java" description="[null]"
enabled="true" language="[null]" copy_resource_id="[null]" person_id="[null]" path="src/main/java/org/Foo.java" deprecated_kee="[null]" />
<snapshots purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="3001" project_id="1001" root_project_id="1001" parent_snapshot_id="[null]" root_snapshot_id="[null]"
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewMultiModulesProjectAndLibrary-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewMultiModulesProjectAndLibrary-result.xml
index 86b94e27622..f475284edcb 100644
--- a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewMultiModulesProjectAndLibrary-result.xml
+++ b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewMultiModulesProjectAndLibrary-result.xml
@@ -31,7 +31,7 @@
enabled="true" language="[null]" copy_resource_id="[null]" person_id="[null]" path="src/main/java/org" deprecated_kee="[null]" />
<projects id="1006" scope="FIL" qualifier="FIL" kee="b1:src/main/java/org/Foo.java" root_id="1004"
- name="src/main/java/org/Foo.java" long_name="src/main/java/org/Foo.java" description="[null]"
+ name="Foo.java" long_name="src/main/java/org/Foo.java" description="[null]"
enabled="true" language="[null]" copy_resource_id="[null]" person_id="[null]" path="src/main/java/org/Foo.java" deprecated_kee="[null]" />
<snapshots purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="3001" project_id="1001" root_project_id="1001" parent_snapshot_id="[null]" root_snapshot_id="[null]"
diff --git a/sonar-core/src/main/java/org/sonar/batch/index/ResourceCopy.java b/sonar-core/src/main/java/org/sonar/batch/index/ResourceCopy.java
index 7364e115cf3..6a3ccd83029 100644
--- a/sonar-core/src/main/java/org/sonar/batch/index/ResourceCopy.java
+++ b/sonar-core/src/main/java/org/sonar/batch/index/ResourceCopy.java
@@ -19,6 +19,9 @@
*/
package org.sonar.batch.index;
+/**
+ * Used by views !!
+ */
public interface ResourceCopy {
int getCopyResourceId();
diff --git a/sonar-core/src/test/java/org/sonar/core/component/ComponentKeysTest.java b/sonar-core/src/test/java/org/sonar/core/component/ComponentKeysTest.java
index 650996e9c8d..6ec3ca28536 100644
--- a/sonar-core/src/test/java/org/sonar/core/component/ComponentKeysTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/component/ComponentKeysTest.java
@@ -35,7 +35,7 @@ public class ComponentKeysTest {
Project project = new Project("my_project");
assertThat(ComponentKeys.createEffectiveKey(project, project)).isEqualTo("my_project");
- Directory dir = Directory.create("src/org/foo", "org/foo");
+ Directory dir = Directory.create("src/org/foo");
assertThat(ComponentKeys.createEffectiveKey(project, dir)).isEqualTo("my_project:src/org/foo");
Library library = new Library("junit:junit", "4.7");
diff --git a/sonar-core/src/test/java/org/sonar/core/component/ResourceComponentTest.java b/sonar-core/src/test/java/org/sonar/core/component/ResourceComponentTest.java
index de50b2ceb5a..ef2644a5b86 100644
--- a/sonar-core/src/test/java/org/sonar/core/component/ResourceComponentTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/component/ResourceComponentTest.java
@@ -34,7 +34,7 @@ public class ResourceComponentTest {
@Before
public void prepare() {
- file = new File("foo.c").setEffectiveKey("myproject:path/to/foo.c");
+ file = File.create("foo.c").setEffectiveKey("myproject:path/to/foo.c");
file.setKey("path/to/foo.c");
}
@@ -67,7 +67,7 @@ public class ResourceComponentTest {
@Test
public void effective_key_should_be_set() {
try {
- File file = new File("foo.c");
+ File file = File.create("foo.c");
new ResourceComponent(file);
fail();
} catch (IllegalArgumentException e) {
diff --git a/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractSourceImporter.java b/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractSourceImporter.java
index f453c1e6579..137437fae4f 100644
--- a/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractSourceImporter.java
+++ b/sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractSourceImporter.java
@@ -22,7 +22,6 @@ package org.sonar.api.batch;
import org.sonar.api.resources.Language;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.ProjectFileSystem;
-import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Resource;
import java.io.File;
@@ -66,14 +65,7 @@ public abstract class AbstractSourceImporter implements Sensor {
}
protected Resource createResource(File file, List<File> sourceDirs, boolean unitTest) {
- org.sonar.api.resources.File resource = org.sonar.api.resources.File.fromIOFile(file, sourceDirs);
- if (resource != null) {
- resource.setLanguage(language);
- if (unitTest) {
- resource.setQualifier(Qualifiers.UNIT_TEST_FILE);
- }
- }
- return resource;
+ return null;
}
protected boolean isEnabled(Project project) {
diff --git a/sonar-deprecated/src/test/java/org/sonar/api/checks/NoSonarFilterTest.java b/sonar-deprecated/src/test/java/org/sonar/api/checks/NoSonarFilterTest.java
index 1521ca67b52..4cc3bda8872 100644
--- a/sonar-deprecated/src/test/java/org/sonar/api/checks/NoSonarFilterTest.java
+++ b/sonar-deprecated/src/test/java/org/sonar/api/checks/NoSonarFilterTest.java
@@ -45,8 +45,8 @@ public class NoSonarFilterTest {
@Before
public void prepare() {
when(chain.accept(isA(Issue.class))).thenReturn(true);
- javaFile = new File("org.foo.Bar");
- javaFile.setEffectiveKey("struts:org.apache.Action");
+ javaFile = File.create("org/foo/Bar.java");
+ javaFile.setEffectiveKey("struts:org/foo/Bar.java");
when(sonarIndex.getResource(javaFile)).thenReturn(javaFile);
}
@@ -58,7 +58,7 @@ public class NoSonarFilterTest {
filter.addResource(javaFile, noSonarLines);
Issue issue = mock(Issue.class);
- when(issue.componentKey()).thenReturn("struts:org.apache.Action");
+ when(issue.componentKey()).thenReturn("struts:org/foo/Bar.java");
when(issue.ruleKey()).thenReturn(RuleKey.of("squid", "Foo"));
// violation on class
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java
index f7b2c06227f..14699e354f4 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java
@@ -20,6 +20,7 @@
package org.sonar.api;
import org.sonar.api.batch.AnalysisMode;
+import org.sonar.api.batch.fs.FileSystem;
/**
* Non-exhaustive list of constants of core properties.
@@ -148,7 +149,7 @@ public interface CoreProperties {
String PROJECT_DESCRIPTION_PROPERTY = "sonar.projectDescription";
/**
- * To determine value of this property use {@link org.sonar.api.resources.ProjectFileSystem#getSourceCharset()}.
+ * To determine value of this property use {@link FileSystem#encoding()}.
*
* @since 2.6
*/
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/TimeMachine.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/TimeMachine.java
index f1f9670e8d4..eb6341b5135 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/TimeMachine.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/TimeMachine.java
@@ -25,10 +25,13 @@ import org.sonar.api.measures.Measure;
import java.util.List;
/**
- * The TimeMachine extension point
+ * The TimeMachine component
*
* @since 1.10
+ * @deprecated since 5.1 ability to access previous data from batch side will soon be removed
*/
+@Deprecated
+@RequiresDB
public interface TimeMachine extends BatchComponent {
/**
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputDir.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputDir.java
index d120c609e4e..d958aaebc7f 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputDir.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputDir.java
@@ -20,6 +20,7 @@
package org.sonar.api.batch.fs;
import java.io.File;
+import java.nio.file.Path;
/**
* Layer over {@link java.io.File} for directories.
@@ -58,4 +59,10 @@ public interface InputDir extends InputPath {
@Override
File file();
+ /**
+ * The underlying absolute {@link Path}
+ */
+ @Override
+ Path path();
+
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputFile.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputFile.java
index 2cf8ee33c37..768986d8c0c 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputFile.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputFile.java
@@ -22,6 +22,7 @@ package org.sonar.api.batch.fs;
import javax.annotation.CheckForNull;
import java.io.File;
+import java.nio.file.Path;
/**
* This layer over {@link java.io.File} adds information for code analyzers.
@@ -72,6 +73,12 @@ public interface InputFile extends InputPath {
File file();
/**
+ * The underlying absolute {@link Path}
+ */
+ @Override
+ Path path();
+
+ /**
* Language, for example "java" or "php". Can be null if indexation of all files is enabled and no language claims to support the file.
*/
@CheckForNull
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputPath.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputPath.java
index c4d2ae73f16..121df157028 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputPath.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputPath.java
@@ -21,6 +21,7 @@ package org.sonar.api.batch.fs;
import java.io.File;
import java.io.Serializable;
+import java.nio.file.Path;
/**
* Layer over {@link java.io.File} for files or directories.
@@ -49,4 +50,11 @@ public interface InputPath extends Serializable {
*/
File file();
+ /**
+ * @see InputFile#path()
+ * @see InputDir#path()
+ * @since 5.1
+ */
+ Path path();
+
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AbsolutePathPredicate.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AbsolutePathPredicate.java
index 88ea160a6a9..218d00e891d 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AbsolutePathPredicate.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AbsolutePathPredicate.java
@@ -26,6 +26,7 @@ import org.sonar.api.scan.filesystem.PathResolver;
import org.sonar.api.utils.PathUtils;
import java.io.File;
+import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collections;
@@ -35,9 +36,9 @@ import java.util.Collections;
class AbsolutePathPredicate extends AbstractFilePredicate {
private final String path;
- private final File baseDir;
+ private final Path baseDir;
- AbsolutePathPredicate(String path, File baseDir) {
+ AbsolutePathPredicate(String path, Path baseDir) {
this.baseDir = baseDir;
this.path = PathUtils.sanitize(path);
}
@@ -49,7 +50,7 @@ class AbsolutePathPredicate extends AbstractFilePredicate {
@Override
public Iterable<InputFile> get(Index index) {
- String relative = PathUtils.sanitize(new PathResolver().relativePath(baseDir, new File(path)));
+ String relative = PathUtils.sanitize(new PathResolver().relativePath(baseDir.toFile(), new File(path)));
if (relative == null) {
return Collections.<InputFile>emptyList();
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFilePredicates.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFilePredicates.java
index 67bcc0b0bd3..7d3d34f7642 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFilePredicates.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFilePredicates.java
@@ -24,6 +24,7 @@ import org.sonar.api.batch.fs.FilePredicates;
import org.sonar.api.batch.fs.InputFile;
import java.io.File;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -36,12 +37,12 @@ import java.util.List;
*/
public class DefaultFilePredicates implements FilePredicates {
- private final File baseDir;
+ private final Path baseDir;
/**
* Client code should use {@link org.sonar.api.batch.fs.FileSystem#predicates()} to get an instance
*/
- DefaultFilePredicates(File baseDir) {
+ DefaultFilePredicates(Path baseDir) {
this.baseDir = baseDir;
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFileSystem.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFileSystem.java
index 27a00412dd9..236ecb7d424 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFileSystem.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFileSystem.java
@@ -36,6 +36,7 @@ import javax.annotation.Nullable;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -51,28 +52,28 @@ public class DefaultFileSystem implements FileSystem {
private final Cache cache;
private final SortedSet<String> languages = new TreeSet<String>();
- private final File baseDir;
- private File workDir;
+ private final Path baseDir;
+ private Path workDir;
private Charset encoding;
private final FilePredicates predicates;
/**
* Only for testing
*/
- public DefaultFileSystem(File baseDir) {
+ public DefaultFileSystem(Path baseDir) {
this(baseDir, new MapCache());
}
- protected DefaultFileSystem(File baseDir, Cache cache) {
+ protected DefaultFileSystem(Path baseDir, Cache cache) {
Preconditions.checkNotNull(baseDir, "Base directory can't be null");
- this.baseDir = baseDir.getAbsoluteFile();
+ this.baseDir = baseDir.toAbsolutePath().normalize();
this.cache = cache;
this.predicates = new DefaultFilePredicates(baseDir);
}
@Override
public File baseDir() {
- return baseDir;
+ return baseDir.toFile();
}
public DefaultFileSystem setEncoding(@Nullable Charset e) {
@@ -90,13 +91,13 @@ public class DefaultFileSystem implements FileSystem {
}
public DefaultFileSystem setWorkDir(File d) {
- this.workDir = d.getAbsoluteFile();
+ this.workDir = d.getAbsoluteFile().toPath().normalize();
return this;
}
@Override
public File workDir() {
- return workDir;
+ return workDir.toFile();
}
@Override
@@ -151,7 +152,7 @@ public class DefaultFileSystem implements FileSystem {
@Override
public InputDir inputDir(File dir) {
doPreloadFiles();
- String relativePath = PathUtils.sanitize(new PathResolver().relativePath(baseDir, dir));
+ String relativePath = PathUtils.sanitize(new PathResolver().relativePath(baseDir.toFile(), dir));
if (relativePath == null) {
return null;
}
@@ -162,7 +163,11 @@ public class DefaultFileSystem implements FileSystem {
* Adds InputFile to the list and registers its language, if present.
* Synchronized because PersistIt Exchange is not concurrent
*/
- public synchronized DefaultFileSystem add(InputFile inputFile) {
+ public synchronized DefaultFileSystem add(DefaultInputFile inputFile) {
+ if (this.baseDir == null) {
+ throw new IllegalStateException("Please set basedir on filesystem before adding files");
+ }
+ inputFile.setModuleBaseDir(this.baseDir);
cache.add(inputFile);
if (inputFile.language() != null) {
languages.add(inputFile.language());
@@ -174,7 +179,11 @@ public class DefaultFileSystem implements FileSystem {
* Adds InputDir to the list.
* Synchronized because PersistIt Exchange is not concurrent
*/
- public synchronized DefaultFileSystem add(InputDir inputDir) {
+ public synchronized DefaultFileSystem add(DefaultInputDir inputDir) {
+ if (this.baseDir == null) {
+ throw new IllegalStateException("Please set basedir on filesystem before adding dirs");
+ }
+ inputDir.setModuleBaseDir(this.baseDir);
cache.add(inputDir);
return this;
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputDir.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputDir.java
index 71026d52d33..834c6e9c810 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputDir.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputDir.java
@@ -24,6 +24,7 @@ import org.sonar.api.utils.PathUtils;
import java.io.File;
import java.io.Serializable;
+import java.nio.file.Path;
/**
* @since 4.5
@@ -32,7 +33,7 @@ public class DefaultInputDir implements InputDir, Serializable {
private final String relativePath;
private final String moduleKey;
- private String absolutePath;
+ private Path moduleBaseDir;
public DefaultInputDir(String moduleKey, String relativePath) {
this.moduleKey = moduleKey;
@@ -46,15 +47,20 @@ public class DefaultInputDir implements InputDir, Serializable {
@Override
public String absolutePath() {
- return absolutePath;
+ return PathUtils.sanitize(path().toString());
}
@Override
public File file() {
- if (absolutePath == null) {
- throw new IllegalStateException("Can not return the java.io.File because absolute path is not set (see method setFile(java.io.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 new File(absolutePath);
+ return moduleBaseDir.resolve(relativePath);
}
public String moduleKey() {
@@ -65,13 +71,11 @@ public class DefaultInputDir implements InputDir, Serializable {
return new StringBuilder().append(moduleKey).append(":").append(relativePath).toString();
}
- public DefaultInputDir setAbsolutePath(String s) {
- this.absolutePath = PathUtils.sanitize(s);
- return this;
- }
-
- public DefaultInputDir setFile(File file) {
- setAbsolutePath(file.getAbsolutePath());
+ /**
+ * For testing purpose. Will be automaticall set when dir is added to {@link DefaultFileSystem}
+ */
+ public DefaultInputDir setModuleBaseDir(Path moduleBaseDir) {
+ this.moduleBaseDir = moduleBaseDir.normalize();
return this;
}
@@ -95,6 +99,6 @@ public class DefaultInputDir implements InputDir, Serializable {
@Override
public String toString() {
- return "[moduleKey=" + moduleKey + ", relative=" + relativePath + ", abs=" + absolutePath + "]";
+ return "[moduleKey=" + moduleKey + ", relative=" + relativePath + ", basedir=" + moduleBaseDir + "]";
}
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java
index 393e69331fa..cebd7c410f8 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java
@@ -27,6 +27,8 @@ import javax.annotation.Nullable;
import java.io.File;
import java.io.Serializable;
+import java.nio.charset.Charset;
+import java.nio.file.Path;
/**
* @since 4.2
@@ -35,17 +37,12 @@ public class DefaultInputFile implements InputFile, Serializable {
private final String relativePath;
private final String moduleKey;
- private String absolutePath;
+ protected Path moduleBaseDir;
private String language;
private Type type = Type.MAIN;
private Status status;
- private String hash;
private int lines;
- private int nonBlankLines;
- private String encoding;
- private long[] originalLineOffsets;
- private byte[][] lineHashes;
- private boolean empty;
+ private Charset charset;
public DefaultInputFile(String moduleKey, String relativePath) {
this.moduleKey = moduleKey;
@@ -59,15 +56,20 @@ public class DefaultInputFile implements InputFile, Serializable {
@Override
public String absolutePath() {
- return absolutePath;
+ return PathUtils.sanitize(path().toString());
}
@Override
public File file() {
- if (absolutePath == null) {
- throw new IllegalStateException("Can not return the java.io.File because absolute path is not set (see method setFile(java.io.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 new File(absolutePath);
+ return moduleBaseDir.resolve(relativePath);
}
@CheckForNull
@@ -89,22 +91,11 @@ public class DefaultInputFile implements InputFile, Serializable {
return status;
}
- /**
- * Digest hash of the file.
- */
- public String hash() {
- return hash;
- }
-
@Override
public int lines() {
return lines;
}
- public int nonBlankLines() {
- return nonBlankLines;
- }
-
/**
* Component key.
*/
@@ -116,20 +107,15 @@ public class DefaultInputFile implements InputFile, Serializable {
return moduleKey;
}
- public String encoding() {
- return encoding;
+ public Charset charset() {
+ return charset;
}
- public long[] originalLineOffsets() {
- return originalLineOffsets;
- }
-
- public byte[][] lineHashes() {
- return lineHashes;
- }
-
- public DefaultInputFile setAbsolutePath(String s) {
- this.absolutePath = PathUtils.sanitize(s);
+ /**
+ * For testing purpose. Will be automaticall set when file is added to {@link DefaultFileSystem}
+ */
+ public DefaultInputFile setModuleBaseDir(Path moduleBaseDir) {
+ this.moduleBaseDir = moduleBaseDir.normalize();
return this;
}
@@ -138,11 +124,6 @@ public class DefaultInputFile implements InputFile, Serializable {
return this;
}
- public DefaultInputFile setFile(File file) {
- setAbsolutePath(file.getAbsolutePath());
- return this;
- }
-
public DefaultInputFile setType(Type type) {
this.type = type;
return this;
@@ -153,42 +134,13 @@ public class DefaultInputFile implements InputFile, Serializable {
return this;
}
- public DefaultInputFile setHash(String hash) {
- this.hash = hash;
- return this;
- }
-
public DefaultInputFile setLines(int lines) {
this.lines = lines;
return this;
}
- public DefaultInputFile setNonBlankLines(int nonBlankLines) {
- this.nonBlankLines = nonBlankLines;
- return this;
- }
-
- public DefaultInputFile setEncoding(String encoding) {
- this.encoding = encoding;
- return this;
- }
-
- public DefaultInputFile setOriginalLineOffsets(long[] originalLineOffsets) {
- this.originalLineOffsets = originalLineOffsets;
- return this;
- }
-
- public DefaultInputFile setLineHashes(byte[][] lineHashes) {
- this.lineHashes = lineHashes;
- return this;
- }
-
- public boolean isEmpty() {
- return this.empty;
- }
-
- public DefaultInputFile setEmpty(boolean empty) {
- this.empty = empty;
+ public DefaultInputFile setCharset(Charset charset) {
+ this.charset = charset;
return this;
}
@@ -212,7 +164,7 @@ public class DefaultInputFile implements InputFile, Serializable {
@Override
public String toString() {
- return "[moduleKey=" + moduleKey + ", relative=" + relativePath + ", abs=" + absolutePath + "]";
+ return "[moduleKey=" + moduleKey + ", relative=" + relativePath + ", basedir=" + moduleBaseDir + "]";
}
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DeprecatedDefaultInputFile.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DeprecatedDefaultInputFile.java
index a599b6ff656..f70d4a75eea 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DeprecatedDefaultInputFile.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DeprecatedDefaultInputFile.java
@@ -19,8 +19,6 @@
*/
package org.sonar.api.batch.fs.internal;
-import org.sonar.api.utils.PathUtils;
-
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
@@ -32,11 +30,6 @@ import java.io.InputStream;
*/
public class DeprecatedDefaultInputFile extends DefaultInputFile implements org.sonar.api.resources.InputFile {
- private String basedir;
- private String deprecatedKey;
- private String sourceDirAbsolutePath;
- private String pathRelativeToSourceDir;
-
public DeprecatedDefaultInputFile(String moduleKey, String relativePath) {
super(moduleKey, relativePath);
}
@@ -47,12 +40,7 @@ public class DeprecatedDefaultInputFile extends DefaultInputFile implements org.
@Deprecated
@Override
public File getFileBaseDir() {
- return new File(basedir);
- }
-
- public DeprecatedDefaultInputFile setBasedir(File basedir) {
- this.basedir = PathUtils.sanitize(basedir.getAbsolutePath());
- return this;
+ return moduleBaseDir.toFile();
}
/**
@@ -70,44 +58,7 @@ public class DeprecatedDefaultInputFile extends DefaultInputFile implements org.
@Deprecated
@Override
public String getRelativePath() {
- return pathRelativeToSourceDir;
- }
-
- /**
- * Key used before version 4.2. It can be different than {@link #key} on Java files.
- */
- public String deprecatedKey() {
- return deprecatedKey;
- }
-
- public DeprecatedDefaultInputFile setDeprecatedKey(String s) {
- this.deprecatedKey = s;
- return this;
- }
-
- /**
- * Used only for backward-compatibility. Meaningless since version 4.2.
- */
- public String sourceDirAbsolutePath() {
- return sourceDirAbsolutePath;
- }
-
- public DeprecatedDefaultInputFile setSourceDirAbsolutePath(String s) {
- this.sourceDirAbsolutePath = PathUtils.sanitize(s);
- return this;
- }
-
- /**
- * Used only for backward-compatibility. Meaningless since version 4.2.
- */
-
- public String pathRelativeToSourceDir() {
- return pathRelativeToSourceDir;
- }
-
- public DeprecatedDefaultInputFile setPathRelativeToSourceDir(String s) {
- this.pathRelativeToSourceDir = PathUtils.sanitize(s);
- return this;
+ return relativePath();
}
@Override
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Directory.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Directory.java
index fe6edc0b2cd..f11f2f432a8 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Directory.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Directory.java
@@ -21,7 +21,7 @@ package org.sonar.api.resources;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
-import org.sonar.api.batch.SensorContext;
+import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.scan.filesystem.PathResolver;
import org.sonar.api.utils.WildcardPattern;
@@ -39,22 +39,6 @@ public class Directory extends Resource {
// Used by factory
}
- /**
- * @deprecated since 4.2 use {@link #fromIOFile(java.io.File, Project)}
- */
- @Deprecated
- public Directory(String relativePathFromSourceDir) {
- this(relativePathFromSourceDir, null);
- }
-
- /**
- * @deprecated since 4.2 use {@link #fromIOFile(java.io.File, Project)}
- */
- @Deprecated
- public Directory(String relativePathFromSourceDir, Language language) {
- setDeprecatedKey(parseKey(relativePathFromSourceDir));
- }
-
@Override
public String getName() {
return getKey();
@@ -109,17 +93,13 @@ public class Directory extends Resource {
}
/**
- * Creates a {@link Directory} from an absolute {@link java.io.File} and a module.
- * The returned {@link Directory} can be then passed for example to
- * {@link SensorContext#saveMeasure(Resource, org.sonar.api.measures.Measure)}.
- * @param dir absolute path to a directory
- * @param module
- * @return null if the directory is not under module basedir.
* @since 4.2
+ * @deprecated since 5.1 use {@link FileSystem#inputDir(java.io.File)}
*/
+ @Deprecated
@CheckForNull
public static Directory fromIOFile(java.io.File dir, Project module) {
- String relativePathFromBasedir = new PathResolver().relativePath(module.getFileSystem().getBasedir(), dir);
+ String relativePathFromBasedir = new PathResolver().relativePath(module.getBaseDir(), dir);
if (relativePathFromBasedir != null) {
return Directory.create(relativePathFromBasedir);
}
@@ -127,10 +107,10 @@ public class Directory extends Resource {
}
/**
- * Create a Directory that is partially initialized. But that's enough to call for example
- * {@link SensorContext#saveMeasure(Resource, org.sonar.api.measures.Measure)} when resources are already indexed.
* Internal use only.
+ * @deprecated since 5.1 use {@link FileSystem#inputDir(java.io.File)}
*/
+ @Deprecated
public static Directory create(String relativePathFromBaseDir) {
Directory d = new Directory();
String normalizedPath = normalize(relativePathFromBaseDir);
@@ -139,22 +119,10 @@ public class Directory extends Resource {
return d;
}
- /**
- * Create a directory that is fully initialized. Use for indexing resources.
- * Internal use only.
- * @since 4.2
- */
- public static Directory create(String relativePathFromBaseDir, String relativePathFromSourceDir) {
- Directory d = Directory.create(relativePathFromBaseDir);
- d.setDeprecatedKey(parseKey(relativePathFromSourceDir));
- return d;
- }
-
@Override
public String toString() {
return new ToStringBuilder(this)
.append("key", getKey())
- .append("deprecatedKey", getDeprecatedKey())
.append("path", getPath())
.toString();
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/File.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/File.java
index 707116c728d..afe82db8a84 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/File.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/File.java
@@ -28,8 +28,6 @@ import org.sonar.api.utils.WildcardPattern;
import javax.annotation.CheckForNull;
-import java.util.List;
-
/**
* This class is an implementation of a resource of type FILE
*
@@ -39,7 +37,6 @@ public class File extends Resource {
public static final String SCOPE = Scopes.FILE;
- private String directoryDeprecatedKey;
private String filename;
private Language language;
private Directory parent;
@@ -50,74 +47,12 @@ public class File extends Resource {
}
/**
- * File in project. Key is the path relative to project source directories. It is not the absolute path and it does not include the path
- * to source directories. Example : <code>new File("org/sonar/foo.sql")</code>. The absolute path may be
- * c:/myproject/src/main/sql/org/sonar/foo.sql. Project root is c:/myproject and source dir is src/main/sql.
- * @deprecated since 4.2 use {@link #fromIOFile(java.io.File, Project)}
- */
- @Deprecated
- public File(String relativePathFromSourceDir) {
- if (relativePathFromSourceDir == null) {
- throw new IllegalArgumentException("File key is null");
- }
- String realKey = parseKey(relativePathFromSourceDir);
- if (realKey.indexOf(Directory.SEPARATOR) >= 0) {
- this.directoryDeprecatedKey = Directory.parseKey(StringUtils.substringBeforeLast(relativePathFromSourceDir, Directory.SEPARATOR));
- this.filename = StringUtils.substringAfterLast(realKey, Directory.SEPARATOR);
- realKey = new StringBuilder().append(this.directoryDeprecatedKey).append(Directory.SEPARATOR).append(filename).toString();
-
- } else {
- this.filename = relativePathFromSourceDir;
- }
- setDeprecatedKey(realKey);
- }
-
- /**
- * Creates a file from its containing directory and name
- * @deprecated since 4.2 use {@link #fromIOFile(java.io.File, Project)}
- */
- @Deprecated
- public File(String relativeDirectoryPathFromSourceDir, String filename) {
- this.filename = StringUtils.trim(filename);
- if (StringUtils.isBlank(relativeDirectoryPathFromSourceDir)) {
- setDeprecatedKey(filename);
-
- } else {
- this.directoryDeprecatedKey = Directory.parseKey(relativeDirectoryPathFromSourceDir);
- setDeprecatedKey(new StringBuilder().append(directoryDeprecatedKey).append(Directory.SEPARATOR).append(this.filename).toString());
- }
- }
-
- /**
- * Creates a File from its language and its key
- * @deprecated since 4.2 use {@link #fromIOFile(java.io.File, Project)}
- */
- @Deprecated
- public File(Language language, String relativePathFromSourceDir) {
- this(relativePathFromSourceDir);
- this.language = language;
- }
-
- /**
- * Creates a File from language, directory and filename
- * @deprecated since 4.2 use {@link #fromIOFile(java.io.File, Project)}
- */
- @Deprecated
- public File(Language language, String relativeDirectoryPathFromSourceDir, String filename) {
- this(relativeDirectoryPathFromSourceDir, filename);
- this.language = language;
- }
-
- /**
* {@inheritDoc}
*
* @see Resource#getParent()
*/
@Override
public Directory getParent() {
- if (parent == null) {
- parent = new Directory(directoryDeprecatedKey);
- }
return parent;
}
@@ -143,20 +78,6 @@ public class File extends Resource {
}
/**
- * Creates a File from an io.file and a list of sources directories
- * @deprecated since 4.2 use {@link #fromIOFile(java.io.File, Project)}
- */
- @Deprecated
- @CheckForNull
- public static File fromIOFile(java.io.File file, List<java.io.File> sourceDirs) {
- PathResolver.RelativePath relativePath = new PathResolver().relativePath(sourceDirs, file);
- if (relativePath != null) {
- return new File(relativePath.path());
- }
- return null;
- }
-
- /**
* Creates a {@link File} from an absolute {@link java.io.File} and a module.
* The returned {@link File} can be then passed for example to
* {@link SensorContext#saveMeasure(Resource, org.sonar.api.measures.Measure)}.
@@ -168,7 +89,7 @@ public class File extends Resource {
@Deprecated
@CheckForNull
public static File fromIOFile(java.io.File file, Project module) {
- String relativePathFromBasedir = new PathResolver().relativePath(module.getFileSystem().getBasedir(), file);
+ String relativePathFromBasedir = new PathResolver().relativePath(module.getBaseDir(), file);
if (relativePathFromBasedir != null) {
return File.create(relativePathFromBasedir);
}
@@ -243,11 +164,10 @@ public class File extends Resource {
}
/**
- * Create a File that is partially initialized. But that's enough to call for example
- * {@link SensorContext#saveMeasure(Resource, org.sonar.api.measures.Measure)} when resources are already indexed.
* Internal use only.
- * @since 4.2
+ * @deprecated since 5.1 use {@link FileSystem#inputFile(org.sonar.api.batch.fs.FilePredicate)}
*/
+ @Deprecated
public static File create(String relativePathFromBasedir) {
File file = new File();
String normalizedPath = normalize(relativePathFromBasedir);
@@ -256,34 +176,26 @@ public class File extends Resource {
String directoryPath;
if (normalizedPath != null && normalizedPath.contains(Directory.SEPARATOR)) {
directoryPath = StringUtils.substringBeforeLast(normalizedPath, Directory.SEPARATOR);
+ file.filename = StringUtils.substringAfterLast(normalizedPath, Directory.SEPARATOR);
} else {
directoryPath = Directory.SEPARATOR;
+ file.filename = normalizedPath;
}
file.parent = Directory.create(directoryPath);
return file;
}
/**
- * Create a file that is fully initialized. Use for indexing resources.
* Internal use only.
- * @since 4.2
+ * @deprecated since 5.1 use {@link FileSystem#inputFile(org.sonar.api.batch.fs.FilePredicate)}
*/
- public static File create(String relativePathFromBasedir, String relativePathFromSourceDir, Language language, boolean unitTest) {
+ @Deprecated
+ public static File create(String relativePathFromBasedir, Language language, boolean unitTest) {
File file = create(relativePathFromBasedir);
file.setLanguage(language);
- if (relativePathFromSourceDir.contains(Directory.SEPARATOR)) {
- file.filename = StringUtils.substringAfterLast(relativePathFromSourceDir, Directory.SEPARATOR);
- file.directoryDeprecatedKey = Directory.parseKey(StringUtils.substringBeforeLast(relativePathFromSourceDir, Directory.SEPARATOR));
- file.setDeprecatedKey(file.directoryDeprecatedKey + Directory.SEPARATOR + file.filename);
- } else {
- file.filename = relativePathFromSourceDir;
- file.directoryDeprecatedKey = Directory.ROOT;
- file.setDeprecatedKey(file.filename);
- }
if (unitTest) {
file.setQualifier(Qualifiers.UNIT_TEST_FILE);
}
- file.parent.setDeprecatedKey(file.directoryDeprecatedKey);
return file;
}
@@ -291,9 +203,7 @@ public class File extends Resource {
public String toString() {
return new ToStringBuilder(this)
.append("key", getKey())
- .append("deprecatedKey", getDeprecatedKey())
.append("path", getPath())
- .append("dir", directoryDeprecatedKey)
.append("filename", filename)
.append("language", language)
.toString();
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Library.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Library.java
index da5cc35681b..607d2ea9640 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Library.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Library.java
@@ -29,7 +29,6 @@ public final class Library extends Resource {
public Library(String key, String version) {
setKey(key);
- setDeprecatedKey(key);
this.version = version;
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Project.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Project.java
index 950eb020e2d..466902b61c9 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Project.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Project.java
@@ -23,6 +23,7 @@ import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.maven.project.MavenProject;
import org.sonar.api.CoreProperties;
+import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.component.Component;
import org.sonar.api.config.Settings;
@@ -85,13 +86,15 @@ public class Project extends Resource implements Component {
private String analysisVersion;
private Settings settings;
+ // For internal use
+ private java.io.File baseDir;
+
// modules tree
private Project parent;
private List<Project> modules = new ArrayList<Project>();
public Project(String key) {
setKey(key);
- setDeprecatedKey(key);
setEffectiveKey(key);
}
@@ -103,7 +106,6 @@ public class Project extends Resource implements Component {
setKey(key);
this.name = name;
}
- setDeprecatedKey(getKey());
setEffectiveKey(getKey());
this.branch = branch;
}
@@ -373,7 +375,7 @@ public class Project extends Resource implements Component {
/**
* Note: it's better to get a reference on ProjectFileSystem as an IoC dependency (constructor parameter)
- * @deprecated replaced by {@link org.sonar.api.scan.filesystem.ModuleFileSystem} in 3.5
+ * @deprecated since 3.5 use {@link FileSystem} instead
*/
@Deprecated
public ProjectFileSystem getFileSystem() {
@@ -458,4 +460,13 @@ public class Project extends Resource implements Component {
public String qualifier() {
return getQualifier();
}
+
+ // For internal use
+ public void setBaseDir(java.io.File baseDir) {
+ this.baseDir = baseDir;
+ }
+
+ java.io.File getBaseDir() {
+ return baseDir;
+ }
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ProjectFileSystem.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ProjectFileSystem.java
index ea393f5805c..3aad72f7531 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ProjectFileSystem.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ProjectFileSystem.java
@@ -29,7 +29,7 @@ import java.util.List;
/**
* @since 1.10
- * @deprecated since 3.5 replaced by {@link org.sonar.api.scan.filesystem.ModuleFileSystem}
+ * @deprecated since 3.5 replaced by {@link FileSystem}
*/
@Deprecated
public interface ProjectFileSystem extends BatchComponent {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Resource.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Resource.java
index 4f655cf5b51..4634708b4a8 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Resource.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Resource.java
@@ -129,8 +129,6 @@ public abstract class Resource implements Serializable {
private String uuid;
- private String deprecatedKey;
-
private String path;
private String effectiveKey;
@@ -164,21 +162,6 @@ public abstract class Resource implements Serializable {
}
/**
- * @return the resource deprecated key. Should not be used except to deal with backward compatibility.
- * @since 4.2
- */
- public final String getDeprecatedKey() {
- return deprecatedKey;
- }
-
- /**
- * For internal use only
- */
- public void setDeprecatedKey(String s) {
- this.deprecatedKey = s;
- }
-
- /**
* @return the resource name
*/
public abstract String getName();
@@ -321,15 +304,11 @@ public abstract class Resource implements Serializable {
}
Resource resource = (Resource) o;
- if (key != null) {
- return key.equals(resource.key);
- } else {
- return resource.key == null && deprecatedKey.equals(resource.deprecatedKey);
- }
+ return key.equals(resource.key);
}
@Override
public int hashCode() {
- return key != null ? key.hashCode() : deprecatedKey.hashCode();
+ return key.hashCode();
}
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/FileSystemFilter.java b/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/FileSystemFilter.java
index be5e14bad82..f80cad292c7 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/FileSystemFilter.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/FileSystemFilter.java
@@ -20,6 +20,7 @@
package org.sonar.api.scan.filesystem;
import org.sonar.api.BatchExtension;
+import org.sonar.api.batch.fs.InputFileFilter;
import java.io.File;
@@ -44,10 +45,9 @@ public interface FileSystemFilter extends BatchExtension {
FileType type();
- File relativeDir();
-
/**
- * File path relative to source directory. Never return null.
+ * Changed in 5.1 as we don't keep track of relative path to source dir
+ * File path relative to module base directory. Never return null.
*/
String relativePath();
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/task/Task.java b/sonar-plugin-api/src/main/java/org/sonar/api/task/Task.java
index 5ddb1e79afc..dd280ef2ab1 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/task/Task.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/task/Task.java
@@ -19,11 +19,12 @@
*/
package org.sonar.api.task;
-
/**
* Implement this interface to provide the behavior of a task.
* @since 3.6
+ * @deprecated since 5.1 all tasks (devcockpit, views) will be moved to server side
*/
+@Deprecated
public interface Task extends TaskExtension {
void execute();
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/task/TaskComponent.java b/sonar-plugin-api/src/main/java/org/sonar/api/task/TaskComponent.java
index 4032034a56c..65d5e055093 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/task/TaskComponent.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/task/TaskComponent.java
@@ -23,6 +23,8 @@ package org.sonar.api.task;
* All the classes implementing this interface can be injected in public constructors of {@link TaskExtension}.
*
* @since 3.6
+ * @deprecated since 5.1 all tasks (devcockpit, views) will be moved to server side
*/
+@Deprecated
public interface TaskComponent {
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/task/TaskDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/task/TaskDefinition.java
index 15dbe6cb28f..fa8fd07f79b 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/task/TaskDefinition.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/task/TaskDefinition.java
@@ -28,7 +28,9 @@ import java.util.regex.Pattern;
* Register and describe a {@link TaskExtension}.
*
* @since 3.6
+ * @deprecated since 5.1 all tasks (devcockpit, views) will be moved to server side
*/
+@Deprecated
public class TaskDefinition implements TaskExtension, Comparable<TaskDefinition> {
static final String KEY_PATTERN = "[a-zA-Z0-9\\-\\_]+";
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/task/TaskExtension.java b/sonar-plugin-api/src/main/java/org/sonar/api/task/TaskExtension.java
index 7d393d37c2b..f389d069dcf 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/task/TaskExtension.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/task/TaskExtension.java
@@ -25,6 +25,8 @@ import org.sonar.api.Extension;
* Task extension point
*
* @since 3.6
+ * @deprecated since 5.1 all tasks (devcockpit, views) will be moved to server side
*/
+@Deprecated
public interface TaskExtension extends Extension, TaskComponent {
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultFilePredicatesTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultFilePredicatesTest.java
index a9ae07f0b80..4fdabac2ad9 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultFilePredicatesTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultFilePredicatesTest.java
@@ -45,9 +45,9 @@ public class DefaultFilePredicatesTest {
@Before
public void before() throws IOException {
- predicates = new DefaultFilePredicates(temp.newFolder());
+ predicates = new DefaultFilePredicates(temp.newFolder().toPath());
javaFile = new DefaultInputFile("foo", "src/main/java/struts/Action.java")
- .setFile(temp.newFile("Action.java"))
+ .setModuleBaseDir(temp.newFolder().toPath())
.setLanguage("java")
.setStatus(InputFile.Status.ADDED);
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultFileSystemTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultFileSystemTest.java
index 6f118683460..6c7a5bd9f0d 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultFileSystemTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultFileSystemTest.java
@@ -45,7 +45,7 @@ public class DefaultFileSystemTest {
@Before
public void prepare() throws Exception {
basedir = temp.newFolder();
- fs = new DefaultFileSystem(basedir);
+ fs = new DefaultFileSystem(basedir.toPath());
}
@Test
@@ -81,12 +81,12 @@ public class DefaultFileSystemTest {
public void files() throws Exception {
assertThat(fs.inputFiles(fs.predicates().all())).isEmpty();
- fs.add(new DefaultInputFile("foo", "src/Foo.php").setLanguage("php").setFile(temp.newFile()));
- fs.add(new DefaultInputFile("foo", "src/Bar.java").setLanguage("java").setFile(temp.newFile()));
- fs.add(new DefaultInputFile("foo", "src/Baz.java").setLanguage("java").setFile(temp.newFile()));
+ fs.add(new DefaultInputFile("foo", "src/Foo.php").setLanguage("php"));
+ fs.add(new DefaultInputFile("foo", "src/Bar.java").setLanguage("java"));
+ fs.add(new DefaultInputFile("foo", "src/Baz.java").setLanguage("java"));
// no language
- fs.add(new DefaultInputFile("foo", "src/readme.txt").setFile(temp.newFile()));
+ fs.add(new DefaultInputFile("foo", "src/readme.txt"));
assertThat(fs.inputFile(fs.predicates().hasRelativePath("src/Bar.java"))).isNotNull();
assertThat(fs.inputFile(fs.predicates().hasRelativePath("does/not/exist"))).isNull();
@@ -118,15 +118,15 @@ public class DefaultFileSystemTest {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("expected one element");
- fs.add(new DefaultInputFile("foo", "src/Bar.java").setLanguage("java").setFile(temp.newFile()));
- fs.add(new DefaultInputFile("foo", "src/Baz.java").setLanguage("java").setFile(temp.newFile()));
+ fs.add(new DefaultInputFile("foo", "src/Bar.java").setLanguage("java"));
+ fs.add(new DefaultInputFile("foo", "src/Baz.java").setLanguage("java"));
fs.inputFile(fs.predicates().all());
}
@Test
public void input_file_supports_non_indexed_predicates() throws Exception {
- fs.add(new DefaultInputFile("foo", "src/Bar.java").setLanguage("java").setFile(temp.newFile()));
+ fs.add(new DefaultInputFile("foo", "src/Bar.java").setLanguage("java"));
// it would fail if more than one java file
assertThat(fs.inputFile(fs.predicates().hasLanguage("java"))).isNotNull();
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
index ce4aa039897..3da8d5f023c 100644
--- 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
@@ -34,12 +34,12 @@ public class DefaultInputDirTest {
@Test
public void test() throws Exception {
- File dir = temp.newFolder("src");
+ File baseDir = temp.newFolder();
DefaultInputDir inputDir = new DefaultInputDir("ABCDE", "src")
- .setFile(dir);
+ .setModuleBaseDir(baseDir.toPath());
assertThat(inputDir.key()).isEqualTo("ABCDE:src");
- assertThat(inputDir.file().getAbsolutePath()).isEqualTo(dir.getAbsolutePath());
+ 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");
@@ -48,13 +48,9 @@ public class DefaultInputDirTest {
@Test
public void testEqualsAndHashCode() throws Exception {
- File dir1 = temp.newFolder("src");
- DefaultInputDir inputDir1 = new DefaultInputDir("ABCDE", "src")
- .setFile(dir1);
+ DefaultInputDir inputDir1 = new DefaultInputDir("ABCDE", "src");
- File dir2 = temp.newFolder("src2");
- DefaultInputDir inputDir2 = new DefaultInputDir("ABCDE", "src")
- .setFile(dir2);
+ DefaultInputDir inputDir2 = new DefaultInputDir("ABCDE", "src");
assertThat(inputDir1.equals(inputDir1)).isTrue();
assertThat(inputDir1.equals(inputDir2)).isTrue();
@@ -62,7 +58,7 @@ public class DefaultInputDirTest {
assertThat(inputDir1.hashCode()).isEqualTo(63545559);
- assertThat(inputDir1.toString()).contains("[moduleKey=ABCDE, relative=src, abs=");
+ 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
index c474328c420..36201064c61 100644
--- 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
@@ -25,6 +25,7 @@ import org.junit.rules.TemporaryFolder;
import org.sonar.api.batch.fs.InputFile;
import java.io.File;
+import java.nio.file.Paths;
import static org.assertj.core.api.Assertions.assertThat;
@@ -36,8 +37,7 @@ public class DefaultInputFileTest {
@Test
public void test() throws Exception {
DefaultInputFile inputFile = new DefaultInputFile("ABCDE", "src/Foo.php")
- .setFile(temp.newFile("Foo.php"))
- .setHash("1234")
+ .setModuleBaseDir(temp.newFolder().toPath())
.setLines(42)
.setLanguage("php")
.setStatus(InputFile.Status.ADDED)
@@ -51,7 +51,6 @@ public class DefaultInputFileTest {
assertThat(inputFile.status()).isEqualTo(InputFile.Status.ADDED);
assertThat(inputFile.type()).isEqualTo(InputFile.Type.TEST);
assertThat(inputFile.lines()).isEqualTo(42);
- assertThat(inputFile.hash()).isEqualTo("1234");
}
@Test
@@ -72,7 +71,7 @@ public class DefaultInputFileTest {
@Test
public void test_toString() throws Exception {
- DefaultInputFile file = new DefaultInputFile("ABCDE", "src/Foo.php").setAbsolutePath("/path/to/src/Foo.php");
- assertThat(file.toString()).isEqualTo("[moduleKey=ABCDE, relative=src/Foo.php, abs=/path/to/src/Foo.php]");
+ DefaultInputFile file = new DefaultInputFile("ABCDE", "src/Foo.php").setModuleBaseDir(Paths.get("/path/to/"));
+ assertThat(file.toString()).isEqualTo("[moduleKey=ABCDE, relative=src/Foo.php, basedir=/path/to]");
}
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DeprecatedDefaultInputFileTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DeprecatedDefaultInputFileTest.java
index 5aebeb9c0d2..c7007cef687 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DeprecatedDefaultInputFileTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DeprecatedDefaultInputFileTest.java
@@ -26,6 +26,7 @@ import org.junit.rules.TemporaryFolder;
import org.sonar.api.batch.fs.InputFile;
import java.io.File;
+import java.nio.file.Paths;
import static org.assertj.core.api.Assertions.assertThat;
@@ -37,10 +38,7 @@ public class DeprecatedDefaultInputFileTest {
@Test
public void test() throws Exception {
DeprecatedDefaultInputFile inputFile = (DeprecatedDefaultInputFile) new DeprecatedDefaultInputFile("ABCDE", "src/Foo.php")
- .setPathRelativeToSourceDir("Foo.php")
- .setDeprecatedKey("deprecated")
- .setFile(temp.newFile("Foo.php"))
- .setHash("1234")
+ .setModuleBaseDir(temp.newFolder().toPath())
.setLines(42)
.setLanguage("php")
.setStatus(InputFile.Status.ADDED)
@@ -48,7 +46,7 @@ public class DeprecatedDefaultInputFileTest {
assertThat(inputFile.relativePath()).isEqualTo("src/Foo.php");
// deprecated method is different -> path relative to source dir
- assertThat(inputFile.getRelativePath()).isEqualTo("Foo.php");
+ assertThat(inputFile.getRelativePath()).isEqualTo("src/Foo.php");
assertThat(new File(inputFile.relativePath())).isRelative();
assertThat(inputFile.absolutePath()).endsWith("Foo.php");
assertThat(new File(inputFile.absolutePath())).isAbsolute();
@@ -56,7 +54,6 @@ public class DeprecatedDefaultInputFileTest {
assertThat(inputFile.status()).isEqualTo(InputFile.Status.ADDED);
assertThat(inputFile.type()).isEqualTo(InputFile.Type.TEST);
assertThat(inputFile.lines()).isEqualTo(42);
- assertThat(inputFile.hash()).isEqualTo("1234");
}
@Test
@@ -77,7 +74,8 @@ public class DeprecatedDefaultInputFileTest {
@Test
public void test_toString() throws Exception {
- DefaultInputFile file = new DefaultInputFile("ABCDE", "src/Foo.php").setAbsolutePath("/path/to/src/Foo.php");
- assertThat(file.toString()).isEqualTo("[moduleKey=ABCDE, relative=src/Foo.php, abs=/path/to/src/Foo.php]");
+ DefaultInputFile file = new DefaultInputFile("ABCDE", "src/Foo.php")
+ .setModuleBaseDir(Paths.get("/foo/bar/"));
+ assertThat(file.toString()).isEqualTo("[moduleKey=ABCDE, relative=src/Foo.php, basedir=/foo/bar]");
}
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/PathPatternTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/PathPatternTest.java
index ea893912661..aa0e0c4abe5 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/PathPatternTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/PathPatternTest.java
@@ -24,7 +24,7 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.batch.fs.InputFile;
-import java.io.File;
+import java.nio.file.Path;
import static org.assertj.core.api.Assertions.assertThat;
@@ -37,17 +37,14 @@ public class PathPatternTest {
PathPattern pattern = PathPattern.create("**/*Foo.java");
assertThat(pattern.toString()).isEqualTo("**/*Foo.java");
- File file = new File(temp.newFolder(), "src/main/java/org/MyFoo.java");
- InputFile inputFile = new DefaultInputFile("ABCDE", "src/main/java/org/MyFoo.java").setFile(file);
+ InputFile inputFile = new DefaultInputFile("ABCDE", "src/main/java/org/MyFoo.java");
assertThat(pattern.match(inputFile)).isTrue();
// case sensitive by default
- file = new File(temp.newFolder(), "src/main/java/org/MyFoo.JAVA");
- inputFile = new DefaultInputFile("ABCDE", "src/main/java/org/MyFoo.JAVA").setFile(file);
+ inputFile = new DefaultInputFile("ABCDE", "src/main/java/org/MyFoo.JAVA");
assertThat(pattern.match(inputFile)).isFalse();
- file = new File(temp.newFolder(), "src/main/java/org/Other.java");
- inputFile = new DefaultInputFile("ABCDE", "src/main/java/org/Other.java").setFile(file);
+ inputFile = new DefaultInputFile("ABCDE", "src/main/java/org/Other.java");
assertThat(pattern.match(inputFile)).isFalse();
}
@@ -55,12 +52,11 @@ public class PathPatternTest {
public void match_relative_path_and_insensitive_file_extension() throws Exception {
PathPattern pattern = PathPattern.create("**/*Foo.java");
- File file = new File(temp.newFolder(), "src/main/java/org/MyFoo.JAVA");
- InputFile inputFile = new DefaultInputFile("ABCDE", "src/main/java/org/MyFoo.JAVA").setFile(file);
+ Path moduleBaseDir = temp.newFolder().toPath();
+ InputFile inputFile = new DefaultInputFile("ABCDE", "src/main/java/org/MyFoo.JAVA").setModuleBaseDir(moduleBaseDir);
assertThat(pattern.match(inputFile, false)).isTrue();
- file = new File(temp.newFolder(), "src/main/java/org/Other.java");
- inputFile = new DefaultInputFile("ABCDE", "src/main/java/org/Other.java").setFile(file);
+ inputFile = new DefaultInputFile("ABCDE", "src/main/java/org/Other.java").setModuleBaseDir(moduleBaseDir);
assertThat(pattern.match(inputFile, false)).isFalse();
}
@@ -69,17 +65,15 @@ public class PathPatternTest {
PathPattern pattern = PathPattern.create("file:**/src/main/**Foo.java");
assertThat(pattern.toString()).isEqualTo("file:**/src/main/**Foo.java");
- File file = new File(temp.newFolder(), "src/main/java/org/MyFoo.java");
- InputFile inputFile = new DefaultInputFile("ABCDE", "src/main/java/org/MyFoo.java").setFile(file);
+ Path moduleBaseDir = temp.newFolder().toPath();
+ InputFile inputFile = new DefaultInputFile("ABCDE", "src/main/java/org/MyFoo.java").setModuleBaseDir(moduleBaseDir);
assertThat(pattern.match(inputFile)).isTrue();
// case sensitive by default
- file = new File(temp.newFolder(), "src/main/java/org/MyFoo.JAVA");
- inputFile = new DefaultInputFile("ABCDE", "src/main/java/org/MyFoo.JAVA").setFile(file);
+ inputFile = new DefaultInputFile("ABCDE", "src/main/java/org/MyFoo.JAVA").setModuleBaseDir(moduleBaseDir);
assertThat(pattern.match(inputFile)).isFalse();
- file = new File(temp.newFolder(), "src/main/java/org/Other.java");
- inputFile = new DefaultInputFile("ABCDE", "src/main/java/org/Other.java").setFile(file);
+ inputFile = new DefaultInputFile("ABCDE", "src/main/java/org/Other.java").setModuleBaseDir(moduleBaseDir);
assertThat(pattern.match(inputFile)).isFalse();
}
@@ -88,12 +82,11 @@ public class PathPatternTest {
PathPattern pattern = PathPattern.create("file:**/src/main/**Foo.java");
assertThat(pattern.toString()).isEqualTo("file:**/src/main/**Foo.java");
- File file = new File(temp.newFolder(), "src/main/java/org/MyFoo.JAVA");
- InputFile inputFile = new DefaultInputFile("ABCDE", "src/main/java/org/MyFoo.JAVA").setFile(file);
+ Path moduleBaseDir = temp.newFolder().toPath();
+ InputFile inputFile = new DefaultInputFile("ABCDE", "src/main/java/org/MyFoo.JAVA").setModuleBaseDir(moduleBaseDir);
assertThat(pattern.match(inputFile, false)).isTrue();
- file = new File(temp.newFolder(), "src/main/java/org/Other.JAVA");
- inputFile = new DefaultInputFile("ABCDE", "src/main/java/org/Other.JAVA").setFile(file);
+ inputFile = new DefaultInputFile("ABCDE", "src/main/java/org/Other.JAVA").setModuleBaseDir(moduleBaseDir);
assertThat(pattern.match(inputFile, false)).isFalse();
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCaseCoverageTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCaseCoverageTest.java
index e7d1fe8242e..9512005a6c4 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCaseCoverageTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCaseCoverageTest.java
@@ -77,7 +77,7 @@ public class DefaultTestCaseCoverageTest {
assertThat(testCaseCoverage1.toString())
.isEqualTo(
- "DefaultTestCaseCoverage[testFile=[moduleKey=foo, relative=test/FooTest.php, abs=null],mainFile=[moduleKey=foo, relative=src/Foo.php, abs=null],name=myTest,lines=[1, 2, 3]]");
+ "DefaultTestCaseCoverage[testFile=[moduleKey=foo, relative=test/FooTest.php, basedir=null],mainFile=[moduleKey=foo, relative=src/Foo.php, basedir=null],name=myTest,lines=[1, 2, 3]]");
assertThat(testCaseCoverage1.hashCode()).isEqualTo(testCaseCoverage1a.hashCode());
}
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCaseExecutionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCaseExecutionTest.java
index 2a5548061c7..c1e72389523 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCaseExecutionTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCaseExecutionTest.java
@@ -116,7 +116,7 @@ public class DefaultTestCaseExecutionTest {
assertThat(testCase1).isNotEqualTo("foo");
assertThat(testCase1.toString()).isEqualTo(
- "DefaultTestCaseExecution[testFile=[moduleKey=foo, relative=src/Foo.php, abs=null],name=myTest,duration=1,status=ERROR,message=message,type=UNIT,stackTrace=stack]");
+ "DefaultTestCaseExecution[testFile=[moduleKey=foo, relative=src/Foo.php, basedir=null],name=myTest,duration=1,status=ERROR,message=message,type=UNIT,stackTrace=stack]");
assertThat(testCase1.hashCode()).isEqualTo(testCase1a.hashCode());
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/measures/AverageFormulaTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/measures/AverageFormulaTest.java
index 405d4f9d696..e4a9c96f57c 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/measures/AverageFormulaTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/measures/AverageFormulaTest.java
@@ -139,7 +139,7 @@ public class AverageFormulaTest {
public void test_calculation_for_file() {
when(data.getMeasure(CoreMetrics.COMPLEXITY)).thenReturn(new Measure(CoreMetrics.COMPLEXITY, 60.0));
when(data.getMeasure(CoreMetrics.FUNCTIONS)).thenReturn(new Measure(CoreMetrics.FUNCTIONS, 20.0));
- when(context.getResource()).thenReturn(new File("foo"));
+ when(context.getResource()).thenReturn(File.create("foo"));
Measure measure = AverageFormula.create(CoreMetrics.COMPLEXITY, CoreMetrics.FUNCTIONS).calculate(data, context);
assertThat(measure.getValue()).isEqualTo(3.0);
@@ -150,7 +150,7 @@ public class AverageFormulaTest {
when(data.getMeasure(CoreMetrics.COMPLEXITY_IN_FUNCTIONS)).thenReturn(null);
when(data.getMeasure(CoreMetrics.COMPLEXITY)).thenReturn(new Measure(CoreMetrics.COMPLEXITY, 60.0));
when(data.getMeasure(CoreMetrics.FUNCTIONS)).thenReturn(new Measure(CoreMetrics.FUNCTIONS, 20.0));
- when(context.getResource()).thenReturn(new File("foo"));
+ when(context.getResource()).thenReturn(File.create("foo"));
Measure measure = AverageFormula.create(CoreMetrics.COMPLEXITY_IN_FUNCTIONS, CoreMetrics.FUNCTIONS)
.setFallbackForMainMetric(CoreMetrics.COMPLEXITY)
@@ -163,7 +163,7 @@ public class AverageFormulaTest {
when(data.getMeasure(CoreMetrics.COMPLEXITY_IN_FUNCTIONS)).thenReturn(new Measure(CoreMetrics.COMPLEXITY, 60.0));
when(data.getMeasure(CoreMetrics.COMPLEXITY)).thenReturn(new Measure(CoreMetrics.COMPLEXITY, 42.0));
when(data.getMeasure(CoreMetrics.FUNCTIONS)).thenReturn(new Measure(CoreMetrics.FUNCTIONS, 20.0));
- when(context.getResource()).thenReturn(new File("foo"));
+ when(context.getResource()).thenReturn(File.create("foo"));
Measure measure = AverageFormula.create(CoreMetrics.COMPLEXITY_IN_FUNCTIONS, CoreMetrics.FUNCTIONS)
.setFallbackForMainMetric(CoreMetrics.COMPLEXITY)
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/measures/SumChildDistributionFormulaTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/measures/SumChildDistributionFormulaTest.java
index 8d31362cf1d..6129400fede 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/measures/SumChildDistributionFormulaTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/measures/SumChildDistributionFormulaTest.java
@@ -30,9 +30,9 @@ import java.util.Collections;
import java.util.List;
import static junit.framework.Assert.assertNull;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
-import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -45,7 +45,7 @@ public class SumChildDistributionFormulaTest {
public void init() {
formula = new SumChildDistributionFormula();
context = mock(FormulaContext.class);
- when(context.getResource()).thenReturn(new File("foo"));
+ when(context.getResource()).thenReturn(File.create("foo"));
data = mock(FormulaData.class);
}
@@ -97,7 +97,7 @@ public class SumChildDistributionFormulaTest {
@Test
public void shouldNotPersistWhenScopeLowerThanMinimun() throws Exception {
- when(context.getResource()).thenReturn(new File("org/Foo.java"));
+ when(context.getResource()).thenReturn(File.create("org/Foo.java"));
initContextWithChildren();
formula.setMinimumScopeToPersist(Scopes.DIRECTORY);
@@ -108,7 +108,7 @@ public class SumChildDistributionFormulaTest {
@Test
public void shouldPersistWhenScopeEqualsMinimun() throws Exception {
- when(context.getResource()).thenReturn(new File("org/Foo.java"));
+ when(context.getResource()).thenReturn(File.create("org/Foo.java"));
initContextWithChildren();
formula.setMinimumScopeToPersist(Scopes.FILE);
@@ -119,7 +119,7 @@ public class SumChildDistributionFormulaTest {
@Test
public void shouldPersistWhenScopeHigherThanMinimun() throws Exception {
- when(context.getResource()).thenReturn(new Directory("org/foo"));
+ when(context.getResource()).thenReturn(Directory.create("org/foo"));
initContextWithChildren();
formula.setMinimumScopeToPersist(Scopes.FILE);
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/DirectoryTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/resources/DirectoryTest.java
index 0c83e6a8ba9..054c6c48689 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/resources/DirectoryTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/resources/DirectoryTest.java
@@ -25,9 +25,7 @@ import org.junit.rules.TemporaryFolder;
import java.io.IOException;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -40,71 +38,55 @@ public class DirectoryTest {
public void createFromIoFileShouldComputeCorrectKey() throws IOException {
java.io.File baseDir = temp.newFolder();
Project project = mock(Project.class);
- ProjectFileSystem fileSystem = mock(ProjectFileSystem.class);
- when(project.getFileSystem()).thenReturn(fileSystem);
- when(fileSystem.getBasedir()).thenReturn(baseDir);
+ when(project.getBaseDir()).thenReturn(baseDir);
Resource dir = Directory.fromIOFile(new java.io.File(baseDir, "src/foo/bar/"), project);
- assertThat(dir.getKey(), is("src/foo/bar"));
+ assertThat(dir.getKey()).isEqualTo("src/foo/bar");
}
@Test
- public void shouldStartBySlashAndNotEndBySlash() {
- Resource dir = Directory.create("src/foo/bar/", " /foo/bar/ ");
- assertThat(dir.getKey(), is("src/foo/bar"));
- assertThat(dir.getDeprecatedKey(), is("foo/bar"));
- assertThat(dir.getName(), is("src/foo/bar"));
- }
-
- @Test
- public void shouldNotStartOrEndBySlashDeprecatedConstructor() {
- Resource dir = new Directory(" /foo/bar/ ");
- assertThat(dir.getDeprecatedKey(), is("foo/bar"));
- }
-
- @Test
- public void rootDirectoryDeprecatedConstructor() {
- assertThat(new Directory(null).getDeprecatedKey(), is(Directory.ROOT));
- assertThat(new Directory("").getDeprecatedKey(), is(Directory.ROOT));
- assertThat(new Directory(" ").getDeprecatedKey(), is(Directory.ROOT));
+ public void shouldNotStartBySlashAndNotEndBySlash() {
+ Resource dir = Directory.create("src/foo/bar/");
+ assertThat(dir.getKey()).isEqualTo("src/foo/bar");
+ assertThat(dir.getName()).isEqualTo("src/foo/bar");
}
@Test
public void backSlashesShouldBeReplacedBySlashes() {
- Resource dir = new Directory(" foo\\bar\\ ");
- assertThat(dir.getDeprecatedKey(), is("foo/bar"));
+ Resource dir = Directory.create(" foo\\bar\\ ");
+ assertThat(dir.getKey()).isEqualTo("foo/bar");
}
@Test
public void directoryHasNoParents() {
- Resource dir = new Directory("foo/bar");
- assertThat(dir.getParent(), nullValue());
+ Resource dir = Directory.create("foo/bar");
+ assertThat(dir.getParent()).isNull();
}
@Test
public void shouldHaveOnlyOneLevelOfDirectory() {
- assertThat(new Directory("one/two/third").getParent(), nullValue());
- assertThat(new Directory("one").getParent(), nullValue());
+ assertThat(Directory.create("one/two/third").getParent()).isNull();
+ assertThat(Directory.create("one").getParent()).isNull();
}
@Test
public void parseDirectoryKey() {
- assertThat(Directory.parseKey("/foo/bar"), is("foo/bar"));
+ assertThat(Directory.parseKey("/foo/bar")).isEqualTo("foo/bar");
}
@Test
public void matchExclusionPatterns() {
- Directory directory = Directory.create("src/one/two/third", "one/two/third");
- assertThat(directory.matchFilePattern("one/two/*.java"), is(false));
- assertThat(directory.matchFilePattern("false"), is(false));
- assertThat(directory.matchFilePattern("two/one/**"), is(false));
- assertThat(directory.matchFilePattern("other*/**"), is(false));
+ Directory directory = Directory.create("src/one/two/third");
+ assertThat(directory.matchFilePattern("one/two/*.java")).isFalse();
+ assertThat(directory.matchFilePattern("false")).isFalse();
+ assertThat(directory.matchFilePattern("two/one/**")).isFalse();
+ assertThat(directory.matchFilePattern("other*/**")).isFalse();
- assertThat(directory.matchFilePattern("src/one*/**"), is(true));
- assertThat(directory.matchFilePattern("src/one/t?o/**"), is(true));
- assertThat(directory.matchFilePattern("**/*"), is(true));
- assertThat(directory.matchFilePattern("**"), is(true));
- assertThat(directory.matchFilePattern("src/one/two/*"), is(true));
- assertThat(directory.matchFilePattern("/src/one/two/*"), is(true));
- assertThat(directory.matchFilePattern("src/one/**"), is(true));
+ assertThat(directory.matchFilePattern("src/one*/**")).isTrue();
+ assertThat(directory.matchFilePattern("src/one/t?o/**")).isTrue();
+ assertThat(directory.matchFilePattern("**/*")).isTrue();
+ assertThat(directory.matchFilePattern("**")).isTrue();
+ assertThat(directory.matchFilePattern("src/one/two/*")).isTrue();
+ assertThat(directory.matchFilePattern("/src/one/two/*")).isTrue();
+ assertThat(directory.matchFilePattern("src/one/**")).isTrue();
}
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/FileTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/resources/FileTest.java
index dbd04f48202..62c5d7a503a 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/resources/FileTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/resources/FileTest.java
@@ -26,9 +26,6 @@ import org.junit.rules.TemporaryFolder;
import java.io.IOException;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
-import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -41,68 +38,34 @@ public class FileTest {
public void createFromIoFileShouldComputeCorrectKey() throws IOException {
java.io.File baseDir = temp.newFolder();
Project project = mock(Project.class);
- ProjectFileSystem fileSystem = mock(ProjectFileSystem.class);
- when(project.getFileSystem()).thenReturn(fileSystem);
- when(fileSystem.getBasedir()).thenReturn(baseDir);
+ when(project.getBaseDir()).thenReturn(baseDir);
Resource file = File.fromIOFile(new java.io.File(baseDir, "src/foo/bar/toto.sql"), project);
- assertThat(file.getKey(), is("src/foo/bar/toto.sql"));
+ assertThat(file.getKey()).isEqualTo("src/foo/bar/toto.sql");
}
@Test
public void trimKeyAndName() {
- File file = new File(" foo/bar/ ", " toto.sql ");
- assertThat(file.getDeprecatedKey(), is("foo/bar/toto.sql"));
- assertThat(file.getName(), is("toto.sql"));
+ File file = File.create(" foo/bar/toto.sql ");
+ assertThat(file.getKey()).isEqualTo("foo/bar/toto.sql");
+ assertThat(file.getName()).isEqualTo("toto.sql");
}
@Test
public void parentIsDirectory() {
- File file = File.create("src/foo/bar/toto.sql", "foo/bar/toto.sql", null, false);
- assertThat(file.getKey(), is("src/foo/bar/toto.sql"));
- assertThat(file.getDeprecatedKey(), is("foo/bar/toto.sql"));
- assertThat(file.getLongName(), is("src/foo/bar/toto.sql"));
- assertThat(file.getName(), is("toto.sql"));
- assertThat(file.getParent().getKey(), is("src/foo/bar"));
- assertThat(ResourceUtils.isSpace(file.getParent()), is(true));
- }
-
- @Test
- public void parentIsDirectoryWithDeprecatedKey() {
- File file = new File(" foo/bar/", "toto.sql ");
- assertThat(file.getDeprecatedKey(), is("foo/bar/toto.sql"));
- assertThat(file.getParent().getDeprecatedKey(), is("foo/bar"));
- assertThat(ResourceUtils.isSpace(file.getParent()), is(true));
+ File file = File.create("src/foo/bar/toto.sql", null, false);
+ assertThat(file.getKey()).isEqualTo("src/foo/bar/toto.sql");
+ assertThat(file.getLongName()).isEqualTo("src/foo/bar/toto.sql");
+ assertThat(file.getName()).isEqualTo("toto.sql");
+ assertThat(file.getParent().getKey()).isEqualTo("src/foo/bar");
+ assertThat(ResourceUtils.isSpace(file.getParent())).isEqualTo(true);
}
@Test
public void rootFilesHaveParent() {
- File file = File.create("toto.sql", "toto.sql", null, false);
- assertThat(file.getKey(), is("toto.sql"));
- assertThat(file.getDeprecatedKey(), is("toto.sql"));
- assertThat(file.getName(), is("toto.sql"));
- assertThat(file.getParent().getKey(), is("/"));
- assertThat(file.getParent().getDeprecatedKey(), is(Directory.ROOT));
- }
-
- @Test
- public void newFileByDeprecatedKey() {
- File file = new File("toto.sql");
- assertThat(file.getDeprecatedKey(), is("toto.sql"));
- assertThat(file.getName(), is("toto.sql"));
- assertThat(file.language()).isNull();
- assertThat(file.getParent().getDeprecatedKey(), is(Directory.ROOT));
- assertThat(file.getScope(), is(Resource.SCOPE_ENTITY));
- assertThat(file.getQualifier(), is(Resource.QUALIFIER_FILE));
-
- file = new File("foo/bar/toto.sql");
- assertThat(file.getDeprecatedKey(), is("foo/bar/toto.sql"));
- assertThat(file.getName(), is("toto.sql"));
- assertThat(file.getParent().getDeprecatedKey(), is("foo/bar"));
-
- file = new File("/foo/bar/toto.sql ");
- assertThat(file.getDeprecatedKey(), is("foo/bar/toto.sql"));
- assertThat(file.getName(), is("toto.sql"));
- assertThat(file.getParent().getDeprecatedKey(), is("foo/bar"));
+ File file = File.create("toto.sql", null, false);
+ assertThat(file.getKey()).isEqualTo("toto.sql");
+ assertThat(file.getName()).isEqualTo("toto.sql");
+ assertThat(file.getParent().getKey()).isEqualTo("/");
}
@Test
@@ -114,18 +77,19 @@ public class FileTest {
return null;
}
};
- File file = new File(lang, "Foo.java");
- assertThat(file.getLanguage(), is(lang));
- file = new File(lang, "org/sonar", "Foo.java");
- assertThat(file.getLanguage(), is(lang));
+ File file = File.create("Foo.java", lang, false);
+ assertThat(file.getLanguage()).isEqualTo(lang);
+
+ file = File.create("org/sonar/Foo.java", lang, false);
+ assertThat(file.getLanguage()).isEqualTo(lang);
assertThat(file.language()).isEqualTo("java");
- assertThat(file.getParent().getLanguage(), nullValue());
+ assertThat(file.getParent().getLanguage()).isNull();
}
@Test
public void matchAntPatterns() {
- File file = File.create("src/one/two/foo.sql", "one/two/foo.sql", null, false);
+ File file = File.create("src/one/two/foo.sql", null, false);
assertThat(file.matchFilePattern("/src/one/two/*.java")).isFalse();
assertThat(file.matchFilePattern("false")).isFalse();
assertThat(file.matchFilePattern("two/one/**")).isFalse();
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceUtilsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceUtilsTest.java
index 966c3d7e6c2..14b0b7bf6ba 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceUtilsTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceUtilsTest.java
@@ -29,7 +29,7 @@ public class ResourceUtilsTest {
@Test
public void checkFile() {
- File file = new File("hello.Foo");
+ File file = File.create("hello.Foo");
assertThat(ResourceUtils.isClass(file)).isFalse();
assertThat(ResourceUtils.isPackage(file)).isFalse();
assertThat(ResourceUtils.isModuleProject(file)).isFalse();
@@ -42,7 +42,7 @@ public class ResourceUtilsTest {
@Test
public void checkUnitTest() {
- File utFile = new File("hello.Foo");
+ File utFile = File.create("hello.Foo");
utFile.setQualifier(Qualifiers.UNIT_TEST_FILE);
assertThat(ResourceUtils.isClass(utFile)).isFalse();
assertThat(ResourceUtils.isPackage(utFile)).isFalse();
@@ -56,7 +56,7 @@ public class ResourceUtilsTest {
@Test
public void checkDirectory() {
- Directory dir = new Directory("hello");
+ Directory dir = Directory.create("hello");
assertThat(ResourceUtils.isClass(dir)).isFalse();
assertThat(ResourceUtils.isPackage(dir)).isFalse();
assertThat(ResourceUtils.isModuleProject(dir)).isFalse();
@@ -69,8 +69,8 @@ public class ResourceUtilsTest {
@Test
public void shouldBePersistable() {
- assertThat(ResourceUtils.isPersistable(new File("Foo.java"))).isTrue();
- assertThat(ResourceUtils.isPersistable(new Directory("bar/Foo.java"))).isTrue();
+ assertThat(ResourceUtils.isPersistable(File.create("Foo.java"))).isTrue();
+ assertThat(ResourceUtils.isPersistable(Directory.create("bar/Foo.java"))).isTrue();
assertThat(ResourceUtils.isPersistable(new Project("foo"))).isTrue();
assertThat(ResourceUtils.isPersistable(new Library("foo", "1.2"))).isTrue();
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/ScopesTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/resources/ScopesTest.java
index 5de04c830a9..8364aed52c1 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/resources/ScopesTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/resources/ScopesTest.java
@@ -48,7 +48,7 @@ public class ScopesTest {
@Test
public void testDirectory() {
- Resource resource = new Directory("org/foo");
+ Resource resource = Directory.create("org/foo");
assertThat(Scopes.isProject(resource), is(false));
assertThat(Scopes.isDirectory(resource), is(true));
assertThat(Scopes.isFile(resource), is(false));
@@ -58,7 +58,7 @@ public class ScopesTest {
@Test
public void testFile() {
- Resource resource = new File("org/foo/Bar.java");
+ Resource resource = File.create("org/foo/Bar.java");
assertThat(Scopes.isProject(resource), is(false));
assertThat(Scopes.isDirectory(resource), is(false));
assertThat(Scopes.isFile(resource), is(true));
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/scan/filesystem/PathResolverTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/scan/filesystem/PathResolverTest.java
index 05ab197db79..57ca2ae1ae3 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/scan/filesystem/PathResolverTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/scan/filesystem/PathResolverTest.java
@@ -76,6 +76,7 @@ public class PathResolverTest {
File world = new File(hello, "World.java");
assertThat(resolver.relativePath(rootDir, world)).isEqualTo("org/hello/World.java");
+ assertThat(resolver.relativePath(new File(rootDir, "."), world)).isEqualTo("org/hello/World.java");
}
@Test
@@ -140,4 +141,13 @@ public class PathResolverTest {
assertThat(resolver.relativePath(rootDir, new File("Elsewhere.java"))).isNull();
}
+
+ @Test
+ public void supportSymlink() {
+ PathResolver resolver = new PathResolver();
+ File rootDir = new File("src/test/resources/org/sonar/api/scan/filesystem/sample-with-symlink");
+
+ assertThat(resolver.relativePath(rootDir, new File("src/test/resources/org/sonar/api/scan/filesystem/sample-with-symlink/testx/ClassOneTest.java"))).isEqualTo(
+ "testx/ClassOneTest.java");
+ }
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/test/IsResource.java b/sonar-plugin-api/src/test/java/org/sonar/api/test/IsResource.java
index 1d040904eb4..cdd8822a61a 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/test/IsResource.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/test/IsResource.java
@@ -20,7 +20,6 @@
package org.sonar.api.test;
import org.apache.commons.lang.ObjectUtils;
-import org.apache.commons.lang.StringUtils;
import org.mockito.ArgumentMatcher;
import org.sonar.api.resources.Resource;
@@ -43,7 +42,6 @@ public class IsResource extends ArgumentMatcher<Resource> {
@Override
public boolean matches(Object o) {
Resource r = (Resource) o;
- boolean keyMatch = (key != null) ? StringUtils.equals(r.getKey() != null ? r.getKey() : r.getDeprecatedKey(), key) : true;
- return ObjectUtils.equals(r.getScope(), scope) && ObjectUtils.equals(r.getQualifier(), qualifier) && keyMatch;
+ return ObjectUtils.equals(r.getScope(), scope) && ObjectUtils.equals(r.getQualifier(), qualifier) && r.getKey().equals(key);
}
}
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample-with-symlink/.gitignore b/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample-with-symlink/.gitignore
new file mode 100644
index 00000000000..ecbefd4f19d
--- /dev/null
+++ b/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample-with-symlink/.gitignore
@@ -0,0 +1 @@
+.sonar
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample-with-symlink/sonar-project.properties b/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample-with-symlink/sonar-project.properties
new file mode 100644
index 00000000000..8810e376701
--- /dev/null
+++ b/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample-with-symlink/sonar-project.properties
@@ -0,0 +1,6 @@
+sonar.projectKey=sample
+sonar.projectName=Sample
+sonar.projectVersion=0.1-SNAPSHOT
+sonar.sources=xources
+sonar.tests=testx
+sonar.language=xoo
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample-with-symlink/testx b/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample-with-symlink/testx
new file mode 120000
index 00000000000..7385ebd51cf
--- /dev/null
+++ b/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample-with-symlink/testx
@@ -0,0 +1 @@
+../sample/testx/ \ No newline at end of file
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample-with-symlink/xources b/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample-with-symlink/xources
new file mode 120000
index 00000000000..15dca9d90d2
--- /dev/null
+++ b/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample-with-symlink/xources
@@ -0,0 +1 @@
+../sample/xources/ \ No newline at end of file
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/sonar-project.properties b/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/sonar-project.properties
new file mode 100644
index 00000000000..8810e376701
--- /dev/null
+++ b/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/sonar-project.properties
@@ -0,0 +1,6 @@
+sonar.projectKey=sample
+sonar.projectName=Sample
+sonar.projectVersion=0.1-SNAPSHOT
+sonar.sources=xources
+sonar.tests=testx
+sonar.language=xoo
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/testx/ClassOneTest.xoo b/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/testx/ClassOneTest.xoo
new file mode 100644
index 00000000000..8c0967e496f
--- /dev/null
+++ b/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/testx/ClassOneTest.xoo
@@ -0,0 +1,11 @@
+package org.sonar.tests;
+
+import org.junit.Test;
+
+public class ClassOneTest {
+
+ @Test
+ public void nothing() {
+
+ }
+}
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/testx/ClassOneTest.xoo.measures b/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/testx/ClassOneTest.xoo.measures
new file mode 100644
index 00000000000..23b08dc0e0e
--- /dev/null
+++ b/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/testx/ClassOneTest.xoo.measures
@@ -0,0 +1,7 @@
+lines:11
+ncloc:7
+tests:1
+test_execution_time:1
+skipped_tests:0
+test_errors:0
+test_failures:0
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/testx/ClassOneTest.xoo.scm b/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/testx/ClassOneTest.xoo.scm
new file mode 100644
index 00000000000..2cec35b8a72
--- /dev/null
+++ b/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/testx/ClassOneTest.xoo.scm
@@ -0,0 +1,11 @@
+1,user1,2013-01-04
+1,user1,2013-01-04
+1,user1,2013-01-04
+1,user1,2013-01-04
+2,user2,2013-01-05
+2,user2,2013-01-05
+3,user3,2013-01-06
+4,user4,2013-01-07
+4,user4,2013-01-07
+4,user4,2013-01-07
+4,user4,2013-01-07 \ No newline at end of file
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/xources/hello/HelloJava.xoo b/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/xources/hello/HelloJava.xoo
new file mode 100644
index 00000000000..1d9c60d56b7
--- /dev/null
+++ b/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/xources/hello/HelloJava.xoo
@@ -0,0 +1,8 @@
+package hello;
+
+public class HelloJava {
+
+ public static void main(String[] args) {
+ System.out.println("Hello");
+ }
+} \ No newline at end of file
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/xources/hello/HelloJava.xoo.measures b/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/xources/hello/HelloJava.xoo.measures
new file mode 100644
index 00000000000..9eaf8ba2549
--- /dev/null
+++ b/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/xources/hello/HelloJava.xoo.measures
@@ -0,0 +1,2 @@
+ncloc:3
+complexity:1
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/xources/hello/HelloJava.xoo.scm b/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/xources/hello/HelloJava.xoo.scm
new file mode 100644
index 00000000000..03a9de2f486
--- /dev/null
+++ b/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/xources/hello/HelloJava.xoo.scm
@@ -0,0 +1,8 @@
+1,user1,2013-01-04
+1,user1,2013-01-04
+1,user1,2013-01-04
+1,user1,2013-01-04
+2,user2,2013-01-05
+2,user2,2013-01-05
+3,user3,2013-01-06
+4,user4,2013-01-07 \ No newline at end of file
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/xources/hello/helloscala.xoo b/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/xources/hello/helloscala.xoo
new file mode 100644
index 00000000000..53cb085156c
--- /dev/null
+++ b/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/xources/hello/helloscala.xoo
@@ -0,0 +1,6 @@
+ object HelloWorld {
+ def main(args: Array[String]) {
+ println("Hello, world of xoo!")
+ }
+ }
+ \ No newline at end of file
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/xources/hello/helloscala.xoo.measures b/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/xources/hello/helloscala.xoo.measures
new file mode 100644
index 00000000000..d2c8386aed1
--- /dev/null
+++ b/sonar-plugin-api/src/test/resources/org/sonar/api/scan/filesystem/sample/xources/hello/helloscala.xoo.measures
@@ -0,0 +1,2 @@
+ncloc:5
+complexity:2