From cfcbe278f7ced12599d898d50f3fe68bfbf95155 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Thu, 17 Mar 2016 17:05:56 +0100 Subject: Rename batch into scanner --- sonar-batch/pom.xml | 170 ----- .../org/sonar/batch/DefaultFileLinesContext.java | 156 ----- .../batch/DefaultFileLinesContextFactory.java | 52 -- .../java/org/sonar/batch/DefaultProjectTree.java | 101 --- .../java/org/sonar/batch/ProjectConfigurator.java | 100 --- .../sonar/batch/analysis/AnalysisProperties.java | 40 -- .../batch/analysis/AnalysisTempFolderProvider.java | 80 --- .../batch/analysis/AnalysisWSLoaderProvider.java | 49 -- .../sonar/batch/analysis/DefaultAnalysisMode.java | 121 ---- .../org/sonar/batch/analysis/package-info.java | 23 - .../batch/bootstrap/AbstractAnalysisMode.java | 67 -- .../org/sonar/batch/bootstrap/BatchComponents.java | 90 --- .../batch/bootstrap/BatchExtensionDictionnary.java | 264 -------- .../batch/bootstrap/BatchPluginInstaller.java | 159 ----- .../batch/bootstrap/BatchPluginJarExploder.java | 80 --- .../batch/bootstrap/BatchPluginPredicate.java | 98 --- .../batch/bootstrap/BatchPluginRepository.java | 110 ---- .../org/sonar/batch/bootstrap/BatchWsClient.java | 113 ---- .../batch/bootstrap/BatchWsClientProvider.java | 62 -- .../batch/bootstrap/DroppedPropertyChecker.java | 48 -- .../sonar/batch/bootstrap/ExtensionInstaller.java | 77 --- .../sonar/batch/bootstrap/ExtensionMatcher.java | 30 - .../org/sonar/batch/bootstrap/ExtensionUtils.java | 48 -- .../sonar/batch/bootstrap/FileCacheProvider.java | 37 -- .../org/sonar/batch/bootstrap/GlobalContainer.java | 129 ---- .../java/org/sonar/batch/bootstrap/GlobalMode.java | 44 -- .../sonar/batch/bootstrap/GlobalProperties.java | 36 -- .../org/sonar/batch/bootstrap/GlobalSettings.java | 78 --- .../batch/bootstrap/GlobalTempFolderProvider.java | 175 ------ .../org/sonar/batch/bootstrap/MetricProvider.java | 54 -- .../org/sonar/batch/bootstrap/PluginInstaller.java | 42 -- .../org/sonar/batch/bootstrap/Slf4jLogger.java | 54 -- .../org/sonar/batch/bootstrap/UserProperties.java | 62 -- .../org/sonar/batch/bootstrap/package-info.java | 23 - .../java/org/sonar/batch/bootstrapper/Batch.java | 274 --------- .../batch/bootstrapper/EnvironmentInformation.java | 59 -- .../sonar/batch/bootstrapper/IssueListener.java | 167 ----- .../batch/bootstrapper/LogCallbackAppender.java | 57 -- .../org/sonar/batch/bootstrapper/LogOutput.java | 33 - .../batch/bootstrapper/LoggingConfiguration.java | 153 ----- .../batch/bootstrapper/LoggingConfigurator.java | 76 --- .../org/sonar/batch/bootstrapper/package-info.java | 27 - .../batch/cache/DefaultProjectCacheStatus.java | 80 --- .../batch/cache/GlobalPersistentCacheProvider.java | 55 -- .../cache/NonAssociatedCacheSynchronizer.java | 96 --- .../org/sonar/batch/cache/ProjectCacheStatus.java | 30 - .../batch/cache/ProjectCacheSynchronizer.java | 185 ------ .../org/sonar/batch/cache/ProjectKeySupplier.java | 36 -- .../cache/ProjectPersistentCacheProvider.java | 67 -- .../sonar/batch/cache/ProjectSyncContainer.java | 93 --- .../batch/cache/StrategyWSLoaderProvider.java | 41 -- .../main/java/org/sonar/batch/cache/WSLoader.java | 240 -------- .../java/org/sonar/batch/cache/WSLoaderResult.java | 41 -- .../java/org/sonar/batch/cache/package-info.java | 23 - .../java/org/sonar/batch/cpd/CpdComponents.java | 38 -- .../main/java/org/sonar/batch/cpd/CpdExecutor.java | 218 ------- .../main/java/org/sonar/batch/cpd/CpdIndexer.java | 49 -- .../main/java/org/sonar/batch/cpd/CpdMappings.java | 52 -- .../main/java/org/sonar/batch/cpd/CpdSensor.java | 99 --- .../sonar/batch/cpd/DefaultCpdBlockIndexer.java | 114 ---- .../org/sonar/batch/cpd/DuplicationPredicates.java | 49 -- .../org/sonar/batch/cpd/JavaCpdBlockIndexer.java | 105 ---- .../sonar/batch/cpd/index/SonarCpdBlockIndex.java | 119 ---- .../org/sonar/batch/cpd/index/package-info.java | 24 - .../java/org/sonar/batch/cpd/package-info.java | 24 - .../batch/deprecated/DeprecatedSensorContext.java | 221 ------- .../sonar/batch/deprecated/InputFileComponent.java | 60 -- .../org/sonar/batch/deprecated/package-info.java | 23 - .../deprecated/perspectives/BatchPerspectives.java | 73 --- .../perspectives/PerspectiveBuilder.java | 42 -- .../perspectives/PerspectiveNotFoundException.java | 26 - .../deprecated/perspectives/package-info.java | 23 - .../java/org/sonar/batch/events/BatchEvent.java | 45 -- .../org/sonar/batch/events/BatchStepEvent.java | 54 -- .../org/sonar/batch/events/BatchStepHandler.java | 47 -- .../main/java/org/sonar/batch/events/EventBus.java | 63 -- .../java/org/sonar/batch/events/package-info.java | 23 - .../java/org/sonar/batch/index/BatchComponent.java | 84 --- .../org/sonar/batch/index/BatchComponentCache.java | 72 --- .../main/java/org/sonar/batch/index/Bucket.java | 99 --- .../src/main/java/org/sonar/batch/index/Cache.java | 505 --------------- .../main/java/org/sonar/batch/index/Caches.java | 100 --- .../java/org/sonar/batch/index/CachesManager.java | 98 --- .../java/org/sonar/batch/index/DefaultIndex.java | 353 ----------- .../java/org/sonar/batch/index/package-info.java | 23 - .../sonar/batch/issue/DefaultFilterableIssue.java | 92 --- .../org/sonar/batch/issue/DefaultIssuable.java | 65 -- .../sonar/batch/issue/DefaultIssueCallback.java | 122 ---- .../sonar/batch/issue/DefaultIssueFilterChain.java | 54 -- .../sonar/batch/issue/DefaultProjectIssues.java | 79 --- .../issue/DeprecatedIssueAdapterForFilter.java | 193 ------ .../batch/issue/DeprecatedIssueBuilderWrapper.java | 135 ---- .../batch/issue/DeprecatedIssueFilterChain.java | 57 -- .../sonar/batch/issue/DeprecatedIssueWrapper.java | 193 ------ .../org/sonar/batch/issue/IssuableFactory.java | 45 -- .../java/org/sonar/batch/issue/IssueCache.java | 63 -- .../java/org/sonar/batch/issue/IssueCallback.java | 24 - .../java/org/sonar/batch/issue/IssueFilters.java | 69 --- .../org/sonar/batch/issue/IssueTransformer.java | 115 ---- .../java/org/sonar/batch/issue/ModuleIssues.java | 155 ----- .../org/sonar/batch/issue/TrackedIssueAdapter.java | 202 ------ .../batch/issue/ignore/EnforceIssuesFilter.java | 67 -- .../batch/issue/ignore/IgnoreIssuesFilter.java | 63 -- .../org/sonar/batch/issue/ignore/package-info.java | 23 - .../ignore/pattern/AbstractPatternInitializer.java | 81 --- .../pattern/IssueExclusionPatternInitializer.java | 105 ---- .../pattern/IssueInclusionPatternInitializer.java | 49 -- .../batch/issue/ignore/pattern/IssuePattern.java | 167 ----- .../batch/issue/ignore/pattern/LineRange.java | 90 --- .../batch/issue/ignore/pattern/PatternDecoder.java | 143 ----- .../batch/issue/ignore/pattern/PatternMatcher.java | 63 -- .../batch/issue/ignore/pattern/package-info.java | 23 - .../ignore/scanner/IssueExclusionsLoader.java | 81 --- .../scanner/IssueExclusionsRegexpScanner.java | 198 ------ .../batch/issue/ignore/scanner/package-info.java | 23 - .../java/org/sonar/batch/issue/package-info.java | 23 - .../tracking/DefaultServerLineHashesLoader.java | 68 -- .../org/sonar/batch/issue/tracking/FileHashes.java | 96 --- .../batch/issue/tracking/IssueTrackingInput.java | 58 -- .../batch/issue/tracking/IssueTransition.java | 124 ---- .../batch/issue/tracking/LocalIssueTracking.java | 266 -------- .../batch/issue/tracking/RollingFileHashes.java | 89 --- .../batch/issue/tracking/ServerIssueFromWs.java | 65 -- .../issue/tracking/ServerIssueRepository.java | 92 --- .../issue/tracking/ServerIssueValueCoder.java | 46 -- .../issue/tracking/ServerLineHashesLoader.java | 32 - .../batch/issue/tracking/SourceHashHolder.java | 77 --- .../sonar/batch/issue/tracking/TrackedIssue.java | 262 -------- .../sonar/batch/issue/tracking/package-info.java | 23 - .../batch/mediumtest/FakePluginInstaller.java | 54 -- .../sonar/batch/mediumtest/ScanTaskObserver.java | 32 - .../sonar/batch/mediumtest/ScanTaskObservers.java | 44 -- .../org/sonar/batch/mediumtest/TaskResult.java | 292 --------- .../org/sonar/batch/mediumtest/package-info.java | 23 - .../main/java/org/sonar/batch/package-info.java | 23 - .../org/sonar/batch/phases/AbstractPhaseEvent.java | 41 -- .../sonar/batch/phases/AbstractPhaseExecutor.java | 120 ---- .../batch/phases/InitializerExecutionEvent.java | 50 -- .../sonar/batch/phases/InitializersExecutor.java | 67 -- .../sonar/batch/phases/InitializersPhaseEvent.java | 52 -- .../sonar/batch/phases/IssuesPhaseExecutor.java | 84 --- .../org/sonar/batch/phases/PhasesTimeProfiler.java | 53 -- .../sonar/batch/phases/PostJobExecutionEvent.java | 50 -- .../org/sonar/batch/phases/PostJobPhaseEvent.java | 52 -- .../org/sonar/batch/phases/PostJobsExecutor.java | 75 --- .../sonar/batch/phases/ProjectAnalysisEvent.java | 50 -- .../org/sonar/batch/phases/ProjectInitializer.java | 63 -- .../sonar/batch/phases/PublishPhaseExecutor.java | 67 -- .../sonar/batch/phases/SensorExecutionEvent.java | 50 -- .../org/sonar/batch/phases/SensorsExecutor.java | 61 -- .../org/sonar/batch/phases/SensorsPhaseEvent.java | 52 -- .../java/org/sonar/batch/phases/package-info.java | 23 - .../org/sonar/batch/platform/DefaultServer.java | 110 ---- .../org/sonar/batch/platform/package-info.java | 24 - .../sonar/batch/postjob/DefaultPostJobContext.java | 154 ----- .../org/sonar/batch/postjob/PostJobOptimizer.java | 68 -- .../org/sonar/batch/postjob/PostJobWrapper.java | 65 -- .../java/org/sonar/batch/postjob/package-info.java | 21 - .../batch/profiling/AbstractTimeProfiling.java | 116 ---- .../org/sonar/batch/profiling/ItemProfiling.java | 37 -- .../org/sonar/batch/profiling/ModuleProfiling.java | 105 ---- .../main/java/org/sonar/batch/profiling/Phase.java | 37 -- .../org/sonar/batch/profiling/PhaseProfiling.java | 98 --- .../batch/profiling/PhasesSumUpTimeProfiler.java | 278 --------- .../org/sonar/batch/profiling/package-info.java | 24 - .../sonar/batch/report/ActiveRulesPublisher.java | 62 -- .../report/AnalysisContextReportPublisher.java | 164 ----- .../org/sonar/batch/report/BatchReportUtils.java | 83 --- .../sonar/batch/report/ComponentsPublisher.java | 175 ------ .../org/sonar/batch/report/CoveragePublisher.java | 139 ----- .../org/sonar/batch/report/MeasuresPublisher.java | 168 ----- .../org/sonar/batch/report/MetadataPublisher.java | 61 -- .../org/sonar/batch/report/ReportPublisher.java | 242 -------- .../sonar/batch/report/ReportPublisherStep.java | 31 - .../org/sonar/batch/report/SourcePublisher.java | 73 --- .../report/TestExecutionAndCoveragePublisher.java | 139 ----- .../java/org/sonar/batch/report/package-info.java | 23 - .../DefaultGlobalRepositoriesLoader.java | 49 -- .../DefaultProjectRepositoriesLoader.java | 129 ---- .../repository/DefaultQualityProfileLoader.java | 88 --- .../repository/DefaultServerIssuesLoader.java | 59 -- .../java/org/sonar/batch/repository/FileData.java | 41 -- .../batch/repository/GlobalRepositoriesLoader.java | 32 - .../repository/GlobalRepositoriesProvider.java | 45 -- .../batch/repository/ProjectRepositories.java | 79 --- .../repository/ProjectRepositoriesLoader.java | 28 - .../repository/ProjectRepositoriesProvider.java | 68 -- .../batch/repository/QualityProfileLoader.java | 33 - .../batch/repository/QualityProfileProvider.java | 69 --- .../sonar/batch/repository/ServerIssuesLoader.java | 29 - .../language/DefaultLanguagesRepository.java | 78 --- .../sonar/batch/repository/language/Language.java | 63 -- .../repository/language/LanguagesRepository.java | 46 -- .../batch/repository/language/package-info.java | 21 - .../org/sonar/batch/repository/package-info.java | 23 - .../repository/user/UserRepositoryLoader.java | 118 ---- .../sonar/batch/repository/user/package-info.java | 23 - .../org/sonar/batch/rule/ActiveRulesLoader.java | 30 - .../org/sonar/batch/rule/ActiveRulesProvider.java | 116 ---- .../sonar/batch/rule/DefaultActiveRulesLoader.java | 136 ---- .../org/sonar/batch/rule/DefaultRulesLoader.java | 66 -- .../org/sonar/batch/rule/LoadedActiveRule.java | 93 --- .../java/org/sonar/batch/rule/ModuleQProfiles.java | 64 -- .../main/java/org/sonar/batch/rule/QProfile.java | 96 --- .../java/org/sonar/batch/rule/QProfileSensor.java | 72 --- .../org/sonar/batch/rule/QProfileVerifier.java | 71 --- .../sonar/batch/rule/RuleFinderCompatibility.java | 123 ---- .../java/org/sonar/batch/rule/RulesLoader.java | 29 - .../org/sonar/batch/rule/RulesProfileProvider.java | 95 --- .../org/sonar/batch/rule/RulesProfileWrapper.java | 140 ----- .../java/org/sonar/batch/rule/RulesProvider.java | 65 -- .../java/org/sonar/batch/rule/UsedQProfiles.java | 112 ---- .../java/org/sonar/batch/rule/package-info.java | 23 - .../sonar/batch/scan/ImmutableProjectReactor.java | 71 --- .../scan/ImmutableProjectReactorProvider.java | 44 -- .../org/sonar/batch/scan/LanguageVerifier.java | 69 --- .../org/sonar/batch/scan/ModuleScanContainer.java | 197 ------ .../java/org/sonar/batch/scan/ModuleSettings.java | 96 --- .../batch/scan/MutableProjectReactorProvider.java | 34 - .../sonar/batch/scan/ProjectBuildersExecutor.java | 54 -- .../org/sonar/batch/scan/ProjectExclusions.java | 94 --- .../java/org/sonar/batch/scan/ProjectLock.java | 70 --- .../sonar/batch/scan/ProjectReactorBuilder.java | 423 ------------- .../sonar/batch/scan/ProjectReactorValidator.java | 101 --- .../org/sonar/batch/scan/ProjectScanContainer.java | 277 --------- .../java/org/sonar/batch/scan/ProjectSettings.java | 62 -- .../org/sonar/batch/scan/WorkDirectoryCleaner.java | 63 -- .../scan/filesystem/AdditionalFilePredicates.java | 49 -- .../batch/scan/filesystem/ComponentIndexer.java | 68 -- .../scan/filesystem/DefaultModuleFileSystem.java | 285 --------- .../scan/filesystem/DeprecatedFileFilters.java | 80 --- .../batch/scan/filesystem/ExclusionFilters.java | 131 ---- .../sonar/batch/scan/filesystem/FileIndexer.java | 268 -------- .../batch/scan/filesystem/FileSystemLogger.java | 92 --- .../batch/scan/filesystem/InputFileBuilder.java | 111 ---- .../scan/filesystem/InputFileBuilderFactory.java | 51 -- .../batch/scan/filesystem/InputPathCache.java | 92 --- .../batch/scan/filesystem/LanguageDetection.java | 143 ----- .../scan/filesystem/LanguageDetectionFactory.java | 39 -- .../filesystem/ModuleFileSystemInitializer.java | 122 ---- .../scan/filesystem/ModuleInputFileCache.java | 63 -- .../batch/scan/filesystem/StatusDetection.java | 50 -- .../scan/filesystem/StatusDetectionFactory.java | 38 -- .../sonar/batch/scan/filesystem/package-info.java | 26 - .../batch/scan/measure/DefaultMetricFinder.java | 65 -- .../batch/scan/measure/DeprecatedMetricFinder.java | 81 --- .../org/sonar/batch/scan/measure/MeasureCache.java | 84 --- .../batch/scan/measure/MeasureValueCoder.java | 94 --- .../org/sonar/batch/scan/measure/package-info.java | 26 - .../java/org/sonar/batch/scan/package-info.java | 23 - .../org/sonar/batch/scan/report/ConsoleReport.java | 143 ----- .../org/sonar/batch/scan/report/HtmlReport.java | 179 ------ .../sonar/batch/scan/report/IssueVariation.java | 63 -- .../org/sonar/batch/scan/report/IssuesReport.java | 102 --- .../batch/scan/report/IssuesReportBuilder.java | 103 ---- .../org/sonar/batch/scan/report/IssuesReports.java | 38 -- .../org/sonar/batch/scan/report/JSONReport.java | 247 -------- .../org/sonar/batch/scan/report/ReportRuleKey.java | 84 --- .../org/sonar/batch/scan/report/ReportSummary.java | 92 --- .../java/org/sonar/batch/scan/report/Reporter.java | 29 - .../sonar/batch/scan/report/ResourceReport.java | 155 ----- .../sonar/batch/scan/report/RuleNameProvider.java | 59 -- .../org/sonar/batch/scan/report/RuleReport.java | 57 -- .../batch/scan/report/RuleReportComparator.java | 64 -- .../sonar/batch/scan/report/SourceProvider.java | 63 -- .../org/sonar/batch/scan/report/package-info.java | 23 - .../org/sonar/batch/scm/DefaultBlameInput.java | 46 -- .../org/sonar/batch/scm/DefaultBlameOutput.java | 147 ----- .../java/org/sonar/batch/scm/ScmConfiguration.java | 155 ----- .../main/java/org/sonar/batch/scm/ScmSensor.java | 115 ---- .../java/org/sonar/batch/scm/package-info.java | 23 - .../sonar/batch/sensor/DefaultSensorContext.java | 115 ---- .../sonar/batch/sensor/DefaultSensorStorage.java | 285 --------- .../org/sonar/batch/sensor/SensorOptimizer.java | 98 --- .../java/org/sonar/batch/sensor/SensorWrapper.java | 64 -- .../batch/sensor/coverage/CoverageConstants.java | 42 -- .../batch/sensor/coverage/CoverageExclusions.java | 210 ------- .../sonar/batch/sensor/coverage/package-info.java | 21 - .../sonar/batch/sensor/noop/NoOpNewCpdTokens.java | 43 -- .../batch/sensor/noop/NoOpNewHighlighting.java | 43 -- .../org/sonar/batch/sensor/noop/package-info.java | 21 - .../java/org/sonar/batch/sensor/package-info.java | 21 - .../sonar/batch/source/CodeColorizerSensor.java | 64 -- .../org/sonar/batch/source/CodeColorizers.java | 91 --- .../sonar/batch/source/DefaultHighlightable.java | 88 --- .../java/org/sonar/batch/source/DefaultSymbol.java | 66 -- .../org/sonar/batch/source/DefaultSymbolTable.java | 123 ---- .../sonar/batch/source/DefaultSymbolizable.java | 113 ---- .../sonar/batch/source/HighlightableBuilder.java | 51 -- .../batch/source/HighlightingCodeBuilder.java | 91 --- .../sonar/batch/source/HighlightingRenderer.java | 43 -- .../java/org/sonar/batch/source/LinesSensor.java | 68 -- .../sonar/batch/source/SymbolizableBuilder.java | 51 -- .../org/sonar/batch/source/ZeroCoverageSensor.java | 112 ---- .../java/org/sonar/batch/source/package-info.java | 23 - .../main/java/org/sonar/batch/task/ListTask.java | 56 -- .../main/java/org/sonar/batch/task/ScanTask.java | 72 --- .../java/org/sonar/batch/task/TaskContainer.java | 91 --- .../java/org/sonar/batch/task/TaskProperties.java | 36 -- .../src/main/java/org/sonar/batch/task/Tasks.java | 75 --- .../java/org/sonar/batch/task/package-info.java | 23 - .../org/sonar/batch/test/DefaultCoverageBlock.java | 54 -- .../java/org/sonar/batch/test/DefaultTestCase.java | 163 ----- .../java/org/sonar/batch/test/DefaultTestPlan.java | 57 -- .../java/org/sonar/batch/test/DefaultTestable.java | 86 --- .../java/org/sonar/batch/test/TestPlanBuilder.java | 54 -- .../java/org/sonar/batch/test/TestableBuilder.java | 47 -- .../java/org/sonar/batch/test/package-info.java | 23 - .../main/java/org/sonar/batch/util/BatchUtils.java | 87 --- .../java/org/sonar/batch/util/ProgressReport.java | 79 --- .../java/org/sonar/batch/util/package-info.java | 22 - .../org/sonar/batch/bootstrapper/logback.xml | 50 -- .../src/main/resources/org/sonar/batch/logback.xml | 47 -- .../org/sonar/batch/scan/report/issuesreport.ftl | 462 -------------- .../batch/scan/report/issuesreport_files/DIR.png | Bin 390 -> 0 bytes .../batch/scan/report/issuesreport_files/FIL.png | Bin 416 -> 0 bytes .../batch/scan/report/issuesreport_files/PRJ.png | Bin 575 -> 0 bytes .../scan/report/issuesreport_files/favicon.ico | Bin 5430 -> 0 bytes .../scan/report/issuesreport_files/jquery.min.js | 6 - .../batch/scan/report/issuesreport_files/sep12.png | Bin 118 -> 0 bytes .../batch/scan/report/issuesreport_files/sonar.css | 396 ------------ .../batch/scan/report/issuesreport_files/sonar.eot | Bin 6468 -> 0 bytes .../batch/scan/report/issuesreport_files/sonar.svg | 33 - .../batch/scan/report/issuesreport_files/sonar.ttf | Bin 6312 -> 0 bytes .../scan/report/issuesreport_files/sonar.woff | Bin 6904 -> 0 bytes .../report/issuesreport_files/sonarqube-24x100.png | Bin 1477 -> 0 bytes .../sonar/batch/DefaultFileLinesContextTest.java | 148 ----- .../org/sonar/batch/ProjectConfiguratorTest.java | 130 ---- .../analysis/AnalysisTempFolderProviderTest.java | 66 -- .../analysis/AnalysisWSLoaderProviderTest.java | 62 -- .../batch/analysis/DefaultAnalysisModeTest.java | 141 ----- .../bootstrap/BatchExtensionDictionnaryTest.java | 412 ------------- .../batch/bootstrap/BatchPluginInstallerTest.java | 86 --- .../bootstrap/BatchPluginJarExploderTest.java | 80 --- .../batch/bootstrap/BatchPluginPredicateTest.java | 103 ---- .../batch/bootstrap/BatchPluginRepositoryTest.java | 76 --- .../batch/bootstrap/BatchWsClientProviderTest.java | 76 --- .../sonar/batch/bootstrap/BatchWsClientTest.java | 116 ---- .../bootstrap/DroppedPropertyCheckerTest.java | 62 -- .../batch/bootstrap/ExtensionInstallerTest.java | 136 ---- .../sonar/batch/bootstrap/ExtensionUtilsTest.java | 88 --- .../batch/bootstrap/FileCacheProviderTest.java | 65 -- .../sonar/batch/bootstrap/GlobalContainerTest.java | 76 --- .../org/sonar/batch/bootstrap/GlobalModeTest.java | 89 --- .../batch/bootstrap/GlobalPropertiesTest.java | 43 -- .../sonar/batch/bootstrap/GlobalSettingsTest.java | 78 --- .../bootstrap/GlobalTempFolderProviderTest.java | 142 ----- .../sonar/batch/bootstrap/MetricProviderTest.java | 55 -- .../org/sonar/batch/bootstrap/MockHttpServer.java | 118 ---- .../org/sonar/batch/bootstrapper/BatchTest.java | 73 --- .../bootstrapper/EnvironmentInformationTest.java | 41 -- .../bootstrapper/LogCallbackAppenderTest.java | 76 --- .../bootstrapper/LoggingConfigurationTest.java | 167 ----- .../bootstrapper/LoggingConfiguratorTest.java | 184 ------ .../batch/cache/DefaultProjectCacheStatusTest.java | 91 --- .../cache/GlobalPersistentCacheProviderTest.java | 83 --- .../cache/NonAssociatedCacheSynchronizerTest.java | 93 --- .../batch/cache/ProjectCacheSynchronizerTest.java | 197 ------ .../cache/ProjectPersistentCacheProviderTest.java | 80 --- .../batch/cache/ProjectSyncContainerTest.java | 52 -- .../batch/cache/StrategyWSLoaderProviderTest.java | 59 -- .../java/org/sonar/batch/cache/WSLoaderTest.java | 264 -------- .../org/sonar/batch/cpd/CpdComponentsTest.java | 32 - .../java/org/sonar/batch/cpd/CpdExecutorTest.java | 240 -------- .../java/org/sonar/batch/cpd/CpdSensorTest.java | 80 --- .../batch/cpd/DefaultCpdBlockIndexerTest.java | 80 --- .../sonar/batch/cpd/DuplicationPredicatesTest.java | 38 -- .../sonar/batch/cpd/JavaCpdBlockIndexerTest.java | 106 ---- .../perspectives/PerspectiveBuilderTest.java | 44 -- .../org/sonar/batch/events/BatchStepEventTest.java | 45 -- .../java/org/sonar/batch/events/EventBusTest.java | 77 --- .../org/sonar/batch/index/AbstractCachesTest.java | 77 --- .../sonar/batch/index/BatchComponentCacheTest.java | 53 -- .../java/org/sonar/batch/index/BucketTest.java | 58 -- .../test/java/org/sonar/batch/index/CacheTest.java | 250 -------- .../org/sonar/batch/index/CachesManagerTest.java | 42 -- .../java/org/sonar/batch/index/CachesTest.java | 89 --- .../org/sonar/batch/index/DefaultIndexTest.java | 163 ----- .../batch/issue/DefaultFilterableIssueTest.java | 86 --- .../batch/issue/DefaultIssueCallbackTest.java | 137 ----- .../batch/issue/DefaultIssueFilterChainTest.java | 95 --- .../batch/issue/DefaultProjectIssuesTest.java | 78 --- .../issue/DeprecatedIssueAdapterForFilterTest.java | 157 ----- .../issue/DeprecatedIssueFilterChainTest.java | 96 --- .../org/sonar/batch/issue/IssuableFactoryTest.java | 57 -- .../java/org/sonar/batch/issue/IssueCacheTest.java | 98 --- .../org/sonar/batch/issue/ModuleIssuesTest.java | 221 ------- .../sonar/batch/issue/TrackedIssueAdapterTest.java | 84 --- .../issue/ignore/EnforceIssuesFilterTest.java | 149 ----- .../batch/issue/ignore/IgnoreIssuesFilterTest.java | 67 -- .../IssueExclusionPatternInitializerTest.java | 141 ----- .../IssueInclusionPatternInitializerTest.java | 70 --- .../issue/ignore/pattern/IssuePatternTest.java | 114 ---- .../batch/issue/ignore/pattern/LineRangeTest.java | 72 --- .../issue/ignore/pattern/PatternDecoderTest.java | 187 ------ .../issue/ignore/pattern/PatternMatcherTest.java | 119 ---- .../ignore/scanner/IssueExclusionsLoaderTest.java | 157 ----- .../scanner/IssueExclusionsRegexpScannerTest.java | 168 ----- .../DefaultServerLineHashesLoaderTest.java | 89 --- .../issue/tracking/RollingFileHashesTest.java | 43 -- .../batch/issue/tracking/SourceHashHolderTest.java | 119 ---- .../batch/issue/tracking/TrackedIssueTest.java | 47 -- .../sonar/batch/mediumtest/BatchMediumTester.java | 497 --------------- .../sonar/batch/mediumtest/LogOutputRecorder.java | 54 -- .../batch/mediumtest/cache/CacheSyncTest.java | 155 ----- .../mediumtest/coverage/CoverageMediumTest.java | 180 ------ .../sonar/batch/mediumtest/cpd/CpdMediumTest.java | 336 ---------- .../deprecated/DeprecatedApiMediumTest.java | 134 ---- .../batch/mediumtest/fs/FileSystemMediumTest.java | 296 --------- .../fs/NoLanguagesPluginsMediumTest.java | 76 --- .../mediumtest/fs/ProjectBuilderMediumTest.java | 168 ----- .../highlighting/HighlightingMediumTest.java | 133 ---- .../batch/mediumtest/issues/ChecksMediumTest.java | 127 ---- .../issues/IssuesIssuesModeMediumTest.java | 100 --- .../batch/mediumtest/issues/IssuesMediumTest.java | 187 ------ .../mediumtest/issues/IssuesOnDirMediumTest.java | 113 ---- .../issues/IssuesOnModuleMediumTest.java | 84 --- .../issues/MultilineIssuesMediumTest.java | 131 ---- .../batch/mediumtest/issuesmode/EmptyFileTest.java | 94 --- .../issuesmode/IssueModeAndReportsMediumTest.java | 316 ---------- .../issuesmode/NoPreviousAnalysisTest.java | 86 --- .../issuesmode/NonAssociatedProject.java | 89 --- .../mediumtest/issuesmode/ScanOnlyChangedTest.java | 212 ------- .../log/ExceptionHandlingMediumTest.java | 116 ---- .../batch/mediumtest/log/LogListenerTest.java | 216 ------- .../mediumtest/measures/MeasuresMediumTest.java | 131 ---- .../sonar/batch/mediumtest/scm/ScmMediumTest.java | 363 ----------- .../batch/mediumtest/symbol/SymbolMediumTest.java | 116 ---- .../batch/mediumtest/tasks/TasksMediumTest.java | 160 ----- .../tests/CoveragePerTestMediumTest.java | 160 ----- .../mediumtest/tests/TestExecutionMediumTest.java | 105 ---- .../sonar/batch/phases/PostJobsExecutorTest.java | 60 -- .../sonar/batch/platform/DefaultServerTest.java | 51 -- .../batch/postjob/DefaultPostJobContextTest.java | 87 --- .../sonar/batch/postjob/PostJobOptimizerTest.java | 77 --- .../profiling/PhasesSumUpTimeProfilerTest.java | 410 ------------- .../batch/report/ActiveRulesPublisherTest.java | 70 --- .../report/AnalysisContextReportPublisherTest.java | 207 ------- .../batch/report/ComponentsPublisherTest.java | 170 ----- .../sonar/batch/report/CoveragePublisherTest.java | 116 ---- .../sonar/batch/report/MeasuresPublisherTest.java | 113 ---- .../sonar/batch/report/MetadataPublisherTest.java | 100 --- .../sonar/batch/report/ReportPublisherTest.java | 164 ----- .../sonar/batch/report/SourcePublisherTest.java | 119 ---- .../DefaultGlobalRepositoriesLoaderTest.java | 78 --- .../DefaultProjectRepositoriesLoaderTest.java | 144 ----- .../DefaultQualityProfileLoaderTest.java | 116 ---- .../repository/DefaultServerIssuesLoaderTest.java | 83 --- .../ProjectRepositoriesProviderTest.java | 115 ---- .../repository/QualityProfileProviderTest.java | 165 ----- .../repository/user/UserRepositoryLoaderTest.java | 120 ---- .../sonar/batch/rule/ActiveRulesProviderTest.java | 97 --- .../batch/rule/DefaultActiveRulesLoaderTest.java | 85 --- .../sonar/batch/rule/DefaultRulesLoaderTest.java | 79 --- .../org/sonar/batch/rule/QProfileSensorTest.java | 135 ---- .../org/sonar/batch/rule/QProfileVerifierTest.java | 101 --- .../batch/rule/RuleFinderCompatibilityTest.java | 101 --- .../sonar/batch/rule/RulesProfileProviderTest.java | 86 --- .../org/sonar/batch/rule/RulesProviderTest.java | 66 -- .../org/sonar/batch/rule/UsedQProfilesTest.java | 72 --- .../org/sonar/batch/scan/LanguageVerifierTest.java | 99 --- .../org/sonar/batch/scan/ModuleSettingsTest.java | 162 ----- .../sonar/batch/scan/ProjectExclusionsTest.java | 122 ---- .../java/org/sonar/batch/scan/ProjectLockTest.java | 103 ---- .../batch/scan/ProjectReactorBuilderTest.java | 683 --------------------- .../batch/scan/ProjectReactorValidatorTest.java | 185 ------ .../sonar/batch/scan/ProjectScanContainerTest.java | 63 -- .../org/sonar/batch/scan/ProjectSettingsTest.java | 142 ----- .../sonar/batch/scan/WorkDirectoryCleanerTest.java | 79 --- .../filesystem/AdditionalFilePredicatesTest.java | 45 -- .../scan/filesystem/ComponentIndexerTest.java | 141 ----- .../filesystem/DefaultModuleFileSystemTest.java | 200 ------ .../scan/filesystem/DeprecatedFileFiltersTest.java | 77 --- .../scan/filesystem/ExclusionFiltersTest.java | 134 ---- .../filesystem/InputFileBuilderFactoryTest.java | 49 -- .../scan/filesystem/InputFileBuilderTest.java | 118 ---- .../batch/scan/filesystem/InputPathCacheTest.java | 82 --- .../filesystem/LanguageDetectionFactoryTest.java | 41 -- .../scan/filesystem/LanguageDetectionTest.java | 213 ------- .../ModuleFileSystemInitializerTest.java | 92 --- .../filesystem/StatusDetectionFactoryTest.java | 35 -- .../batch/scan/filesystem/StatusDetectionTest.java | 52 -- .../sonar/batch/scan/measure/MeasureCacheTest.java | 231 ------- .../sonar/batch/scan/report/ConsoleReportTest.java | 145 ----- .../sonar/batch/scan/report/JSONReportTest.java | 174 ------ .../batch/scan/report/RuleNameProviderTest.java | 67 -- .../sonar/batch/scm/DefaultBlameOutputTest.java | 94 --- .../batch/sensor/DefaultSensorContextTest.java | 79 --- .../batch/sensor/DefaultSensorStorageTest.java | 140 ----- .../sonar/batch/sensor/SensorOptimizerTest.java | 136 ---- .../sensor/coverage/CoverageExclusionsTest.java | 143 ----- .../org/sonar/batch/source/CodeColorizersTest.java | 230 ------- .../batch/source/DefaultHighlightableTest.java | 55 -- .../sonar/batch/source/DefaultSymbolTableTest.java | 100 --- .../batch/source/DefaultSymbolizableTest.java | 66 -- .../batch/source/HighlightableBuilderTest.java | 58 -- .../batch/source/SymbolizableBuilderTest.java | 59 -- .../java/org/sonar/batch/task/ListTaskTest.java | 63 -- .../test/java/org/sonar/batch/task/TasksTest.java | 90 --- .../java/org/sonar/batch/util/BatchUtilsTest.java | 51 -- .../org/sonar/batch/util/ProgressReportTest.java | 90 --- sonar-batch/src/test/resources/logback-test.xml | 42 -- .../com/sonar/it/samples/modules/a1/HelloA1.xoo | 16 - .../com/sonar/it/samples/modules/a2/HelloA2.xoo | 12 - .../com/sonar/it/samples/modules/b1/HelloB1.xoo | 12 - .../com/sonar/it/samples/modules/b2/HelloB2.xoo | 12 - .../sonar-project.properties | 31 - .../module_a/module_a1/.sonar/sonar-report.json | 1 - .../com/sonar/it/samples/modules/a1/HelloA1.xoo | 16 - .../com/sonar/it/samples/modules/a2/HelloA2.xoo | 12 - .../com/sonar/it/samples/modules/b1/HelloB1.xoo | 12 - .../com/sonar/it/samples/modules/b2/HelloB2.xoo | 12 - .../multi-modules-sample/sonar-project.properties | 31 - .../xoo/sample-multiline/sonar-project.properties | 4 - .../sample-multiline/xources/hello/Multiline.xoo | 9 - .../sample-multiline/xources/hello/Multiple.xoo | 9 - .../xoo/sample-multiline/xources/hello/Single.xoo | 8 - .../sample-multiline/xources/hello/WithFlow.xoo | 14 - .../sonar-project.properties | 5 - .../sample-with-empty-file/xources/hello/Empty.xoo | 0 .../xources/hello/HelloJava.xoo | 8 - .../mediumtest/xoo/sample-with-symlink/.gitignore | 1 - .../sample-with-symlink/sonar-project.properties | 6 - .../mediumtest/xoo/sample-with-symlink/testx | 1 - .../mediumtest/xoo/sample-with-symlink/xources | 1 - .../mediumtest/xoo/sample/sonar-project.properties | 6 - .../mediumtest/xoo/sample/testx/ClassOneTest.xoo | 11 - .../xoo/sample/testx/ClassOneTest.xoo.measures | 7 - .../xoo/sample/testx/ClassOneTest.xoo.scm | 11 - .../xoo/sample/xources/hello/HelloJava.xoo | 8 - .../sample/xources/hello/HelloJava.xoo.measures | 2 - .../xoo/sample/xources/hello/HelloJava.xoo.scm | 8 - .../xoo/sample/xources/hello/helloscala.xoo | 6 - .../sample/xources/hello/helloscala.xoo.measures | 2 - .../sonar-checkstyle-plugin-2.8.jar | Bin 1026947 -> 0 bytes .../api_rules_list.protobuf | Bin 27390 -> 0 bytes .../batch_issues.protobuf | Bin 788 -> 0 bytes .../batch_project.json | 164 ----- .../batch_users.protobuf | 0 .../org/sonar/batch/cpd/ManyStatements.java | 11 - .../file-with-double-regexp-mess.txt | 37 -- .../file-with-double-regexp-twice.txt | 37 -- .../file-with-double-regexp-unfinished.txt | 34 - .../file-with-double-regexp-wrong-order.txt | 35 -- .../file-with-double-regexp.txt | 35 -- .../file-with-no-regexp.txt | 33 - .../file-with-single-regexp-and-double-regexp.txt | 36 -- .../file-with-single-regexp.txt | 33 - .../project.protobuf | Bin 2246 -> 0 bytes .../quality_profile_search_default | Bin 80 -> 0 bytes .../active_rule_search1.protobuf | Bin 27828 -> 0 bytes .../active_rule_search2.protobuf | Bin 14446 -> 0 bytes .../rule/DefaultRulesLoader/response.protobuf | 637 ------------------- .../batch/rule/ModuleQProfilesTest/shared.xml | 19 - .../module1/sonar-project.properties | 1 - .../module1/sources/Fake.java | 5 - .../module2/newBaseDir/src/Fake.java | 1 - .../module2/sonar-project.properties | 6 - .../sonar-project.properties | 11 - .../module1/sonar-project.properties | 4 - .../module1/sources/Fake.java | 1 - .../module2/newBaseDir/src/Fake.java | 1 - .../module2/sonar-project.properties | 6 - .../sonar-project.properties | 10 - .../any-folder/generated/any-file.properties | 5 - .../any-folder/sources/Fake.java | 1 - .../sonar-project.properties | 12 - .../any-folder/any-file.properties | 2 - .../any-folder/sources/Fake.java | 1 - .../sonar-project.properties | 12 - .../sonar-project.properties | 12 - .../module1/module11/sources/Fake.java | 1 - .../module1/module12/sources/Fake.java | 1 - .../module2/sources/Fake.java | 1 - .../sonar-project.properties | 17 - .../sonar-project.properties | 13 - .../src/main/groovy/Fake.groovy | 0 .../src/main/java/Fake.java | 1 - .../module1/sources/Fake.java | 1 - .../module2/src/Fake.java | 1 - .../sonar-project.properties | 19 - .../module1/sources/Fake.java | 1 - .../module2/src/Fake.java | 1 - .../sonar-project.properties | 19 - .../module1.feature/src/Fake.java | 1 - .../module1/sources/Fake.java | 1 - .../sonar-project.properties | 19 - .../sonar-project.properties | 12 - .../modules/module1/module1/sources/Fake.java | 1 - .../modules/module1/sources/Fake.java | 1 - .../sonar-project.properties | 17 - .../modules/module1/sources/Fake.java | 1 - .../sonar-project.properties | 14 - .../modules/module1/sources/Fake.java | 1 - .../sonar-project.properties | 14 - .../module1/src/Fake.java | 1 - .../sonar-project.properties | 9 - .../sonar-project.properties | 13 - .../module1/src/Fake.java | 1 - .../sonar-project.properties | 8 - .../shouldGetFile/foo.properties | 4 - .../shouldGetList/foo.properties | 4 - .../sonar-project.properties | 6 - .../simple-project-with-build-dir/build/report.txt | 0 .../sonar-project.properties | 8 - .../sources/Fake.java | 3 - .../simple-project-with-lib-dir/lib/Fake.class | 3 - .../sonar-project.properties | 7 - .../simple-project-with-lib-dir/sources/Fake.java | 3 - .../sonar-project.properties | 5 - .../sonar-project.properties | 7 - .../sources/Fake.java | 1 - .../sonar-project.properties | 7 - .../sources/Fake.java | 1 - .../sonar-project.properties | 6 - .../sonar-project.properties | 7 - .../sources/Fake.java | 1 - .../simple-project/libs/lib1.txt | 1 - .../simple-project/libs/lib2.txt | 1 - .../simple-project/sonar-project.properties | 7 - .../simple-project/sources/Fake.java | 1 - .../report-without-resolved-issues.json | 28 - .../batch/scan/report/JSONReportTest/report.json | 64 -- .../batch/source/CodeColorizersTest/Person.java | 12 - .../batch/source/CodeColorizersTest/Person.js | 8 - .../batch/source/CodeColorizersTest/package.html | 1 - .../src/org/.dirPrefixedWithDot/Excluded.java | 1 - .../src/org/.sonar/Excluded2.java | 1 - .../src/org/sonar/Included.java | 3 - .../main_and_test_files/src/main/java/Foo.java | 1 - .../main_and_test_files/src/main/java/Hello.java | 1 - .../main_and_test_files/src/test/java/FooTest.java | 1 - .../src/test/java/HelloTest.java | 1 - 633 files changed, 51182 deletions(-) delete mode 100644 sonar-batch/pom.xml delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/DefaultFileLinesContext.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/DefaultFileLinesContextFactory.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/DefaultProjectTree.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/analysis/AnalysisProperties.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/analysis/AnalysisTempFolderProvider.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/analysis/AnalysisWSLoaderProvider.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/analysis/DefaultAnalysisMode.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/analysis/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/bootstrap/AbstractAnalysisMode.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionDictionnary.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginInstaller.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginJarExploder.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginPredicate.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchWsClient.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchWsClientProvider.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/bootstrap/DroppedPropertyChecker.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionInstaller.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionMatcher.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionUtils.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/bootstrap/FileCacheProvider.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalMode.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalProperties.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalSettings.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalTempFolderProvider.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/bootstrap/MetricProvider.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/bootstrap/PluginInstaller.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/bootstrap/Slf4jLogger.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/bootstrap/UserProperties.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/bootstrap/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Batch.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/bootstrapper/EnvironmentInformation.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/bootstrapper/IssueListener.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/bootstrapper/LogCallbackAppender.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/bootstrapper/LogOutput.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/bootstrapper/LoggingConfiguration.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/bootstrapper/LoggingConfigurator.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/bootstrapper/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/cache/DefaultProjectCacheStatus.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/cache/GlobalPersistentCacheProvider.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/cache/NonAssociatedCacheSynchronizer.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/cache/ProjectCacheStatus.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/cache/ProjectCacheSynchronizer.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/cache/ProjectKeySupplier.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/cache/ProjectPersistentCacheProvider.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/cache/ProjectSyncContainer.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/cache/StrategyWSLoaderProvider.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/cache/WSLoader.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/cache/WSLoaderResult.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/cache/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/cpd/CpdComponents.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/cpd/CpdExecutor.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/cpd/CpdIndexer.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/cpd/CpdMappings.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/cpd/CpdSensor.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/cpd/DefaultCpdBlockIndexer.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/cpd/DuplicationPredicates.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/cpd/JavaCpdBlockIndexer.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/cpd/index/SonarCpdBlockIndex.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/cpd/index/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/cpd/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/deprecated/DeprecatedSensorContext.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/deprecated/InputFileComponent.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/deprecated/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/BatchPerspectives.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/PerspectiveBuilder.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/PerspectiveNotFoundException.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/events/BatchEvent.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/events/BatchStepEvent.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/events/BatchStepHandler.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/events/EventBus.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/events/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/index/BatchComponent.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/index/BatchComponentCache.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/index/Bucket.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/index/Cache.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/index/Caches.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/index/CachesManager.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/index/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/DefaultFilterableIssue.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssuable.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssueCallback.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssueFilterChain.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/DefaultProjectIssues.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueAdapterForFilter.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueBuilderWrapper.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueFilterChain.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueWrapper.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/IssuableFactory.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/IssueCache.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/IssueCallback.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/IssueFilters.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/IssueTransformer.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/TrackedIssueAdapter.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/ignore/EnforceIssuesFilter.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/ignore/IgnoreIssuesFilter.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/ignore/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/ignore/pattern/AbstractPatternInitializer.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/ignore/pattern/IssueExclusionPatternInitializer.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/ignore/pattern/IssueInclusionPatternInitializer.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/ignore/pattern/IssuePattern.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/ignore/pattern/LineRange.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/ignore/pattern/PatternDecoder.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/ignore/pattern/PatternMatcher.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/ignore/pattern/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/ignore/scanner/IssueExclusionsLoader.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/ignore/scanner/IssueExclusionsRegexpScanner.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/ignore/scanner/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/tracking/DefaultServerLineHashesLoader.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/tracking/FileHashes.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTrackingInput.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTransition.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/tracking/LocalIssueTracking.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/tracking/RollingFileHashes.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerIssueFromWs.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerIssueRepository.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerIssueValueCoder.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerLineHashesLoader.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/tracking/SourceHashHolder.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/tracking/TrackedIssue.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/issue/tracking/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/mediumtest/FakePluginInstaller.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/mediumtest/ScanTaskObserver.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/mediumtest/ScanTaskObservers.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/mediumtest/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/phases/AbstractPhaseEvent.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/phases/AbstractPhaseExecutor.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/phases/InitializerExecutionEvent.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/phases/InitializersExecutor.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/phases/InitializersPhaseEvent.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/phases/IssuesPhaseExecutor.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/phases/PhasesTimeProfiler.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/phases/PostJobExecutionEvent.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/phases/PostJobPhaseEvent.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/phases/PostJobsExecutor.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/phases/ProjectAnalysisEvent.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/phases/ProjectInitializer.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/phases/PublishPhaseExecutor.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/phases/SensorExecutionEvent.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/phases/SensorsExecutor.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/phases/SensorsPhaseEvent.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/phases/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/platform/DefaultServer.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/platform/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/postjob/DefaultPostJobContext.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/postjob/PostJobOptimizer.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/postjob/PostJobWrapper.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/postjob/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/profiling/AbstractTimeProfiling.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/profiling/ItemProfiling.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/profiling/ModuleProfiling.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/profiling/Phase.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/profiling/PhaseProfiling.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/profiling/PhasesSumUpTimeProfiler.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/profiling/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/report/ActiveRulesPublisher.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/report/AnalysisContextReportPublisher.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/report/BatchReportUtils.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/report/ComponentsPublisher.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/report/CoveragePublisher.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/report/MeasuresPublisher.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/report/MetadataPublisher.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/report/ReportPublisher.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/report/ReportPublisherStep.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/report/SourcePublisher.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/report/TestExecutionAndCoveragePublisher.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/report/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/repository/DefaultGlobalRepositoriesLoader.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/repository/DefaultQualityProfileLoader.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/repository/DefaultServerIssuesLoader.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/repository/FileData.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/repository/GlobalRepositoriesLoader.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/repository/GlobalRepositoriesProvider.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/repository/ProjectRepositories.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/repository/ProjectRepositoriesLoader.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/repository/ProjectRepositoriesProvider.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/repository/QualityProfileLoader.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/repository/QualityProfileProvider.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/repository/ServerIssuesLoader.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/repository/language/DefaultLanguagesRepository.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/repository/language/Language.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/repository/language/LanguagesRepository.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/repository/language/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/repository/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/repository/user/UserRepositoryLoader.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/repository/user/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesLoader.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/rule/DefaultActiveRulesLoader.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/rule/DefaultRulesLoader.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/rule/LoadedActiveRule.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/rule/ModuleQProfiles.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/rule/QProfile.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/rule/QProfileSensor.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/rule/QProfileVerifier.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/rule/RuleFinderCompatibility.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/rule/RulesLoader.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/rule/RulesProfileProvider.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/rule/RulesProfileWrapper.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/rule/UsedQProfiles.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/rule/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/ImmutableProjectReactor.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/ImmutableProjectReactorProvider.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/LanguageVerifier.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/ModuleSettings.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/MutableProjectReactorProvider.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/ProjectBuildersExecutor.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/ProjectExclusions.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/ProjectLock.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorValidator.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/ProjectSettings.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/WorkDirectoryCleaner.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/AdditionalFilePredicates.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DeprecatedFileFilters.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ExclusionFilters.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileIndexer.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileSystemLogger.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputFileBuilder.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputFileBuilderFactory.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputPathCache.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/LanguageDetection.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/LanguageDetectionFactory.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ModuleFileSystemInitializer.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ModuleInputFileCache.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/StatusDetection.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/StatusDetectionFactory.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/measure/DefaultMetricFinder.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/measure/DeprecatedMetricFinder.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/measure/MeasureCache.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/measure/MeasureValueCoder.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/measure/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/report/ConsoleReport.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/report/HtmlReport.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/report/IssueVariation.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReport.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReportBuilder.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReports.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/report/JSONReport.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/report/ReportRuleKey.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/report/ReportSummary.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/report/Reporter.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/report/ResourceReport.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/report/RuleNameProvider.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/report/RuleReport.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/report/RuleReportComparator.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/report/SourceProvider.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scan/report/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scm/DefaultBlameInput.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scm/DefaultBlameOutput.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scm/ScmConfiguration.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/scm/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/sensor/SensorOptimizer.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/sensor/SensorWrapper.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/sensor/coverage/CoverageConstants.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/sensor/coverage/CoverageExclusions.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/sensor/coverage/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/sensor/noop/NoOpNewCpdTokens.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/sensor/noop/NoOpNewHighlighting.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/sensor/noop/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/sensor/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/source/CodeColorizerSensor.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/source/CodeColorizers.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/source/DefaultHighlightable.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbol.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolTable.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolizable.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/source/HighlightableBuilder.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/source/HighlightingCodeBuilder.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/source/HighlightingRenderer.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/source/LinesSensor.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/source/SymbolizableBuilder.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/source/ZeroCoverageSensor.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/source/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/task/ListTask.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/task/ScanTask.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/task/TaskContainer.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/task/TaskProperties.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/task/Tasks.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/task/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/test/DefaultCoverageBlock.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestCase.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestPlan.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestable.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/test/TestPlanBuilder.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/test/TestableBuilder.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/test/package-info.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/util/BatchUtils.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/util/ProgressReport.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/util/package-info.java delete mode 100644 sonar-batch/src/main/resources/org/sonar/batch/bootstrapper/logback.xml delete mode 100644 sonar-batch/src/main/resources/org/sonar/batch/logback.xml delete mode 100644 sonar-batch/src/main/resources/org/sonar/batch/scan/report/issuesreport.ftl delete mode 100644 sonar-batch/src/main/resources/org/sonar/batch/scan/report/issuesreport_files/DIR.png delete mode 100644 sonar-batch/src/main/resources/org/sonar/batch/scan/report/issuesreport_files/FIL.png delete mode 100644 sonar-batch/src/main/resources/org/sonar/batch/scan/report/issuesreport_files/PRJ.png delete mode 100644 sonar-batch/src/main/resources/org/sonar/batch/scan/report/issuesreport_files/favicon.ico delete mode 100644 sonar-batch/src/main/resources/org/sonar/batch/scan/report/issuesreport_files/jquery.min.js delete mode 100644 sonar-batch/src/main/resources/org/sonar/batch/scan/report/issuesreport_files/sep12.png delete mode 100644 sonar-batch/src/main/resources/org/sonar/batch/scan/report/issuesreport_files/sonar.css delete mode 100755 sonar-batch/src/main/resources/org/sonar/batch/scan/report/issuesreport_files/sonar.eot delete mode 100755 sonar-batch/src/main/resources/org/sonar/batch/scan/report/issuesreport_files/sonar.svg delete mode 100755 sonar-batch/src/main/resources/org/sonar/batch/scan/report/issuesreport_files/sonar.ttf delete mode 100755 sonar-batch/src/main/resources/org/sonar/batch/scan/report/issuesreport_files/sonar.woff delete mode 100644 sonar-batch/src/main/resources/org/sonar/batch/scan/report/issuesreport_files/sonarqube-24x100.png delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/DefaultFileLinesContextTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/ProjectConfiguratorTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/analysis/AnalysisTempFolderProviderTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/analysis/AnalysisWSLoaderProviderTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/analysis/DefaultAnalysisModeTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionDictionnaryTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginInstallerTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginJarExploderTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginPredicateTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchWsClientProviderTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchWsClientTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/bootstrap/DroppedPropertyCheckerTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionInstallerTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionUtilsTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/bootstrap/FileCacheProviderTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/bootstrap/GlobalContainerTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/bootstrap/GlobalModeTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/bootstrap/GlobalPropertiesTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/bootstrap/GlobalSettingsTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/bootstrap/GlobalTempFolderProviderTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/bootstrap/MetricProviderTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/bootstrap/MockHttpServer.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/bootstrapper/BatchTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/bootstrapper/EnvironmentInformationTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/bootstrapper/LogCallbackAppenderTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/bootstrapper/LoggingConfigurationTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/bootstrapper/LoggingConfiguratorTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/cache/DefaultProjectCacheStatusTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/cache/GlobalPersistentCacheProviderTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/cache/NonAssociatedCacheSynchronizerTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/cache/ProjectCacheSynchronizerTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/cache/ProjectPersistentCacheProviderTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/cache/ProjectSyncContainerTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/cache/StrategyWSLoaderProviderTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/cache/WSLoaderTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/cpd/CpdComponentsTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/cpd/CpdExecutorTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/cpd/CpdSensorTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/cpd/DefaultCpdBlockIndexerTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/cpd/DuplicationPredicatesTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/cpd/JavaCpdBlockIndexerTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/deprecated/perspectives/PerspectiveBuilderTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/events/BatchStepEventTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/events/EventBusTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/index/AbstractCachesTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/index/BatchComponentCacheTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/index/BucketTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/index/CacheTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/index/CachesManagerTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/index/CachesTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/issue/DefaultFilterableIssueTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/issue/DefaultIssueCallbackTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/issue/DefaultIssueFilterChainTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/issue/DefaultProjectIssuesTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/issue/DeprecatedIssueAdapterForFilterTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/issue/DeprecatedIssueFilterChainTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/issue/IssueCacheTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/issue/TrackedIssueAdapterTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/issue/ignore/EnforceIssuesFilterTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/issue/ignore/IgnoreIssuesFilterTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/issue/ignore/pattern/IssueExclusionPatternInitializerTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/issue/ignore/pattern/IssueInclusionPatternInitializerTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/issue/ignore/pattern/IssuePatternTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/issue/ignore/pattern/LineRangeTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/issue/ignore/pattern/PatternDecoderTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/issue/ignore/pattern/PatternMatcherTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/issue/ignore/scanner/IssueExclusionsLoaderTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/issue/ignore/scanner/IssueExclusionsRegexpScannerTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/issue/tracking/DefaultServerLineHashesLoaderTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/issue/tracking/RollingFileHashesTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/issue/tracking/SourceHashHolderTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/issue/tracking/TrackedIssueTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/mediumtest/BatchMediumTester.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/mediumtest/LogOutputRecorder.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/mediumtest/cache/CacheSyncTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/mediumtest/coverage/CoverageMediumTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/mediumtest/cpd/CpdMediumTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/mediumtest/deprecated/DeprecatedApiMediumTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/FileSystemMediumTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/NoLanguagesPluginsMediumTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/ProjectBuilderMediumTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/mediumtest/highlighting/HighlightingMediumTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/ChecksMediumTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesIssuesModeMediumTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesMediumTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesOnDirMediumTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesOnModuleMediumTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/MultilineIssuesMediumTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/mediumtest/issuesmode/EmptyFileTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/mediumtest/issuesmode/IssueModeAndReportsMediumTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/mediumtest/issuesmode/NoPreviousAnalysisTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/mediumtest/issuesmode/NonAssociatedProject.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/mediumtest/issuesmode/ScanOnlyChangedTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/mediumtest/log/ExceptionHandlingMediumTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/mediumtest/log/LogListenerTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/mediumtest/scm/ScmMediumTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/mediumtest/symbol/SymbolMediumTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/mediumtest/tasks/TasksMediumTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/mediumtest/tests/CoveragePerTestMediumTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/mediumtest/tests/TestExecutionMediumTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/phases/PostJobsExecutorTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/platform/DefaultServerTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/postjob/DefaultPostJobContextTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/postjob/PostJobOptimizerTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/profiling/PhasesSumUpTimeProfilerTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/report/ActiveRulesPublisherTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/report/AnalysisContextReportPublisherTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/report/CoveragePublisherTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/report/MeasuresPublisherTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/report/MetadataPublisherTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/report/ReportPublisherTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/report/SourcePublisherTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/repository/DefaultGlobalRepositoriesLoaderTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/repository/DefaultQualityProfileLoaderTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/repository/DefaultServerIssuesLoaderTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/repository/ProjectRepositoriesProviderTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/repository/QualityProfileProviderTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/repository/user/UserRepositoryLoaderTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/rule/ActiveRulesProviderTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/rule/DefaultActiveRulesLoaderTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/rule/DefaultRulesLoaderTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/rule/QProfileSensorTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/rule/QProfileVerifierTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/rule/RuleFinderCompatibilityTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/rule/RulesProfileProviderTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/rule/RulesProviderTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/rule/UsedQProfilesTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/scan/LanguageVerifierTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/scan/ModuleSettingsTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/scan/ProjectExclusionsTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/scan/ProjectLockTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/scan/ProjectReactorBuilderTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/scan/ProjectReactorValidatorTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/scan/ProjectScanContainerTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/scan/ProjectSettingsTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/scan/WorkDirectoryCleanerTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/AdditionalFilePredicatesTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ComponentIndexerTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystemTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DeprecatedFileFiltersTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ExclusionFiltersTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileBuilderFactoryTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileBuilderTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputPathCacheTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/LanguageDetectionFactoryTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/LanguageDetectionTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ModuleFileSystemInitializerTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/StatusDetectionFactoryTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/StatusDetectionTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/scan/measure/MeasureCacheTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/scan/report/ConsoleReportTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/scan/report/JSONReportTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/scan/report/RuleNameProviderTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/scm/DefaultBlameOutputTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorContextTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorStorageTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/sensor/SensorOptimizerTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/sensor/coverage/CoverageExclusionsTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/source/CodeColorizersTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/source/DefaultHighlightableTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/source/DefaultSymbolTableTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/source/DefaultSymbolizableTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/source/HighlightableBuilderTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/source/SymbolizableBuilderTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/task/ListTaskTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/task/TasksTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/util/BatchUtilsTest.java delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/util/ProgressReportTest.java delete mode 100644 sonar-batch/src/test/resources/logback-test.xml delete mode 100644 sonar-batch/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/module_a/module_a1/src/main/xoo/com/sonar/it/samples/modules/a1/HelloA1.xoo delete mode 100644 sonar-batch/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/module_a/module_a2/src/main/xoo/com/sonar/it/samples/modules/a2/HelloA2.xoo delete mode 100644 sonar-batch/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/module_b/module_b1/src/main/xoo/com/sonar/it/samples/modules/b1/HelloB1.xoo delete mode 100644 sonar-batch/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/module_b/module_b2/src/main/xoo/com/sonar/it/samples/modules/b2/HelloB2.xoo delete mode 100644 sonar-batch/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/mediumtest/xoo/multi-modules-sample/module_a/module_a1/.sonar/sonar-report.json delete mode 100644 sonar-batch/src/test/resources/mediumtest/xoo/multi-modules-sample/module_a/module_a1/src/main/xoo/com/sonar/it/samples/modules/a1/HelloA1.xoo delete mode 100644 sonar-batch/src/test/resources/mediumtest/xoo/multi-modules-sample/module_a/module_a2/src/main/xoo/com/sonar/it/samples/modules/a2/HelloA2.xoo delete mode 100644 sonar-batch/src/test/resources/mediumtest/xoo/multi-modules-sample/module_b/module_b1/src/main/xoo/com/sonar/it/samples/modules/b1/HelloB1.xoo delete mode 100644 sonar-batch/src/test/resources/mediumtest/xoo/multi-modules-sample/module_b/module_b2/src/main/xoo/com/sonar/it/samples/modules/b2/HelloB2.xoo delete mode 100644 sonar-batch/src/test/resources/mediumtest/xoo/multi-modules-sample/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/Multiline.xoo delete mode 100644 sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/Multiple.xoo delete mode 100644 sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/Single.xoo delete mode 100644 sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/WithFlow.xoo delete mode 100644 sonar-batch/src/test/resources/mediumtest/xoo/sample-with-empty-file/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/mediumtest/xoo/sample-with-empty-file/xources/hello/Empty.xoo delete mode 100644 sonar-batch/src/test/resources/mediumtest/xoo/sample-with-empty-file/xources/hello/HelloJava.xoo delete mode 100644 sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/.gitignore delete mode 100644 sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/sonar-project.properties delete mode 120000 sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/testx delete mode 120000 sonar-batch/src/test/resources/mediumtest/xoo/sample-with-symlink/xources delete mode 100644 sonar-batch/src/test/resources/mediumtest/xoo/sample/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/mediumtest/xoo/sample/testx/ClassOneTest.xoo delete mode 100644 sonar-batch/src/test/resources/mediumtest/xoo/sample/testx/ClassOneTest.xoo.measures delete mode 100644 sonar-batch/src/test/resources/mediumtest/xoo/sample/testx/ClassOneTest.xoo.scm delete mode 100644 sonar-batch/src/test/resources/mediumtest/xoo/sample/xources/hello/HelloJava.xoo delete mode 100644 sonar-batch/src/test/resources/mediumtest/xoo/sample/xources/hello/HelloJava.xoo.measures delete mode 100644 sonar-batch/src/test/resources/mediumtest/xoo/sample/xources/hello/HelloJava.xoo.scm delete mode 100644 sonar-batch/src/test/resources/mediumtest/xoo/sample/xources/hello/helloscala.xoo delete mode 100644 sonar-batch/src/test/resources/mediumtest/xoo/sample/xources/hello/helloscala.xoo.measures delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/bootstrap/BatchPluginJarExploderTest/sonar-checkstyle-plugin-2.8.jar delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/api_rules_list.protobuf delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/batch_issues.protobuf delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/batch_project.json delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/batch_users.protobuf delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/cpd/ManyStatements.java delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/issue/ignore/scanner/IssueExclusionsRegexpScannerTest/file-with-double-regexp-mess.txt delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/issue/ignore/scanner/IssueExclusionsRegexpScannerTest/file-with-double-regexp-twice.txt delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/issue/ignore/scanner/IssueExclusionsRegexpScannerTest/file-with-double-regexp-unfinished.txt delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/issue/ignore/scanner/IssueExclusionsRegexpScannerTest/file-with-double-regexp-wrong-order.txt delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/issue/ignore/scanner/IssueExclusionsRegexpScannerTest/file-with-double-regexp.txt delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/issue/ignore/scanner/IssueExclusionsRegexpScannerTest/file-with-no-regexp.txt delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/issue/ignore/scanner/IssueExclusionsRegexpScannerTest/file-with-single-regexp-and-double-regexp.txt delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/issue/ignore/scanner/IssueExclusionsRegexpScannerTest/file-with-single-regexp.txt delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest/project.protobuf delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/repository/DefaultQualityProfileLoaderTest/quality_profile_search_default delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/rule/DefaultActiveRulesLoaderTest/active_rule_search1.protobuf delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/rule/DefaultActiveRulesLoaderTest/active_rule_search2.protobuf delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/rule/DefaultRulesLoader/response.protobuf delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/rule/ModuleQProfilesTest/shared.xml delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-definitions-in-each-module-inherited/module1/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-definitions-in-each-module-inherited/module1/sources/Fake.java delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-definitions-in-each-module-inherited/module2/newBaseDir/src/Fake.java delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-definitions-in-each-module-inherited/module2/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-definitions-in-each-module-inherited/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-definitions-in-each-module/module1/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-definitions-in-each-module/module1/sources/Fake.java delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-definitions-in-each-module/module2/newBaseDir/src/Fake.java delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-definitions-in-each-module/module2/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-definitions-in-each-module/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-with-configfile-and-overwritten-basedir/any-folder/generated/any-file.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-with-configfile-and-overwritten-basedir/any-folder/sources/Fake.java delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-with-configfile-and-overwritten-basedir/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-with-configfile/any-folder/any-file.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-with-configfile/any-folder/sources/Fake.java delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-with-configfile/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest/multi-module-with-unexisting-file/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/big-multi-module-definitions-all-in-root/module1/module11/sources/Fake.java delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/big-multi-module-definitions-all-in-root/module1/module12/sources/Fake.java delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/big-multi-module-definitions-all-in-root/module2/sources/Fake.java delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/big-multi-module-definitions-all-in-root/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-language-definitions-all-in-root/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-language-definitions-all-in-root/src/main/groovy/Fake.groovy delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-language-definitions-all-in-root/src/main/java/Fake.java delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-all-in-root/module1/sources/Fake.java delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-all-in-root/module2/src/Fake.java delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-all-in-root/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-moduleKey/module1/sources/Fake.java delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-moduleKey/module2/src/Fake.java delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-moduleKey/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-same-prefix/module1.feature/src/Fake.java delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-same-prefix/module1/sources/Fake.java delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-same-prefix/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-duplicate-id/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-repeated-id/modules/module1/module1/sources/Fake.java delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-repeated-id/modules/module1/sources/Fake.java delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-repeated-id/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-basedir-not-associated/modules/module1/sources/Fake.java delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-basedir-not-associated/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-basedir/modules/module1/sources/Fake.java delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-basedir/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-explicit-unexisting-test-dir/module1/src/Fake.java delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-explicit-unexisting-test-dir/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-unexisting-basedir/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-unexisting-source-dir/module1/src/Fake.java delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-unexisting-source-dir/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/shouldGetFile/foo.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/shouldGetList/foo.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-blank-source-dir/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-build-dir/build/report.txt delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-build-dir/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-build-dir/sources/Fake.java delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-lib-dir/lib/Fake.class delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-lib-dir/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-lib-dir/sources/Fake.java delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-missing-source-dir/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-unexisting-binary/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-unexisting-binary/sources/Fake.java delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-unexisting-lib/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-unexisting-lib/sources/Fake.java delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-unexisting-source-dir/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-unexisting-test-dir/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-unexisting-test-dir/sources/Fake.java delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project/libs/lib1.txt delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project/libs/lib2.txt delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project/sources/Fake.java delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/report/JSONReportTest/report-without-resolved-issues.json delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/report/JSONReportTest/report.json delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/source/CodeColorizersTest/Person.java delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/source/CodeColorizersTest/Person.js delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/source/CodeColorizersTest/package.html delete mode 100644 sonar-batch/test-resources/DefaultModuleFileSystemTest/exclude_dir_starting_with_dot/src/org/.dirPrefixedWithDot/Excluded.java delete mode 100644 sonar-batch/test-resources/DefaultModuleFileSystemTest/exclude_dir_starting_with_dot/src/org/.sonar/Excluded2.java delete mode 100644 sonar-batch/test-resources/DefaultModuleFileSystemTest/exclude_dir_starting_with_dot/src/org/sonar/Included.java delete mode 100644 sonar-batch/test-resources/DefaultModuleFileSystemTest/main_and_test_files/src/main/java/Foo.java delete mode 100644 sonar-batch/test-resources/DefaultModuleFileSystemTest/main_and_test_files/src/main/java/Hello.java delete mode 100644 sonar-batch/test-resources/DefaultModuleFileSystemTest/main_and_test_files/src/test/java/FooTest.java delete mode 100644 sonar-batch/test-resources/DefaultModuleFileSystemTest/main_and_test_files/src/test/java/HelloTest.java (limited to 'sonar-batch') diff --git a/sonar-batch/pom.xml b/sonar-batch/pom.xml deleted file mode 100644 index 8fdc1483bb5..00000000000 --- a/sonar-batch/pom.xml +++ /dev/null @@ -1,170 +0,0 @@ - - - 4.0.0 - - org.sonarsource.sonarqube - sonarqube - 5.5-SNAPSHOT - - - sonar-batch - SonarQube :: Batch - - - false - - - - - commons-beanutils - commons-beanutils - - - com.google.code.findbugs - jsr305 - provided - - - org.sonarsource - sonar-persistit - - - com.google.guava - guava - - - ${project.groupId} - sonar-core - - - ${project.groupId} - sonar-batch-protocol - - - ${project.groupId} - sonar-ws - - - ${project.groupId} - sonar-home - - - ${project.groupId} - sonar-plugin-api - - - org.slf4j - slf4j-api - - - org.slf4j - jcl-over-slf4j - - - org.slf4j - log4j-over-slf4j - - - org.slf4j - jul-to-slf4j - - - commons-lang - commons-lang - - - commons-codec - commons-codec - - - com.google.code.gson - gson - - - - org.freemarker - freemarker - - - - - junit - junit - test - - - org.assertj - assertj-core - test - - - net.javacrumbs.json-unit - json-unit-assertj - 0.0.15 - test - - - org.mockito - mockito-core - test - - - org.hamcrest - hamcrest-all - test - - - ${project.groupId} - sonar-plugin-api - test-jar - test - ${project.version} - - - com.google.code.bean-matchers - bean-matchers - test - - - org.eclipse.jetty - jetty-server - test - - - javax.servlet - javax.servlet-api - test - - - ${project.groupId} - sonar-xoo-plugin - test - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - ${skipBatchTests} - - - - - - - - runBenchmarks - - - runBenchmarks - - - - true - - - - diff --git a/sonar-batch/src/main/java/org/sonar/batch/DefaultFileLinesContext.java b/sonar-batch/src/main/java/org/sonar/batch/DefaultFileLinesContext.java deleted file mode 100644 index a4045f18ce0..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/DefaultFileLinesContext.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch; - -import com.google.common.base.Objects; -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; -import java.util.Map; -import org.sonar.api.batch.SonarIndex; -import org.sonar.api.measures.FileLinesContext; -import org.sonar.api.measures.Measure; -import org.sonar.api.measures.Metric; -import org.sonar.api.measures.PersistenceMode; -import org.sonar.api.resources.Resource; -import org.sonar.api.resources.ResourceUtils; -import org.sonar.api.utils.KeyValueFormat; -import org.sonar.api.utils.KeyValueFormat.Converter; - -public class DefaultFileLinesContext implements FileLinesContext { - - private final SonarIndex index; - private final Resource resource; - - /** - * metric key -> line -> value - */ - private final Map> map = Maps.newHashMap(); - - public DefaultFileLinesContext(SonarIndex index, Resource resource) { - Preconditions.checkNotNull(index); - Preconditions.checkArgument(ResourceUtils.isFile(resource)); - this.index = index; - this.resource = resource; - } - - @Override - public void setIntValue(String metricKey, int line, int value) { - Preconditions.checkNotNull(metricKey); - Preconditions.checkArgument(line > 0); - - setValue(metricKey, line, value); - } - - @Override - public Integer getIntValue(String metricKey, int line) { - Preconditions.checkNotNull(metricKey); - Preconditions.checkArgument(line > 0); - - Map lines = map.get(metricKey); - if (lines == null) { - // not in memory, so load - lines = loadData(metricKey, KeyValueFormat.newIntegerConverter()); - map.put(metricKey, lines); - } - return (Integer) lines.get(line); - } - - @Override - public void setStringValue(String metricKey, int line, String value) { - Preconditions.checkNotNull(metricKey); - Preconditions.checkArgument(line > 0); - Preconditions.checkNotNull(value); - - setValue(metricKey, line, value); - } - - @Override - public String getStringValue(String metricKey, int line) { - Preconditions.checkNotNull(metricKey); - Preconditions.checkArgument(line > 0); - - Map lines = map.get(metricKey); - if (lines == null) { - // not in memory, so load - lines = loadData(metricKey, KeyValueFormat.newStringConverter()); - map.put(metricKey, lines); - } - return (String) lines.get(line); - } - - private Map getOrCreateLines(String metricKey) { - Map lines = map.get(metricKey); - if (lines == null) { - lines = Maps.newHashMap(); - map.put(metricKey, lines); - } - return lines; - } - - private void setValue(String metricKey, int line, Object value) { - getOrCreateLines(metricKey).put(line, value); - } - - @Override - public void save() { - for (Map.Entry> entry : map.entrySet()) { - String metricKey = entry.getKey(); - Map lines = entry.getValue(); - if (shouldSave(lines)) { - String data = KeyValueFormat.format(lines); - Measure measure = new Measure(metricKey) - .setPersistenceMode(PersistenceMode.DATABASE) - .setData(data); - index.addMeasure(resource, measure); - entry.setValue(ImmutableMap.copyOf(lines)); - } - } - } - - private Map loadData(String metricKey, Converter converter) { - // FIXME no way to load measure only by key - Measure measure = index.getMeasure(resource, new Metric(metricKey)); - String data = measure != null ? measure.getData() : null; - if (data != null) { - return ImmutableMap.copyOf(KeyValueFormat.parse(data, KeyValueFormat.newIntegerConverter(), converter)); - } - // no such measure - return ImmutableMap.of(); - } - - /** - * Checks that measure was not saved. - * - * @see #loadData(String, Converter) - * @see #save() - */ - private static boolean shouldSave(Map lines) { - return !(lines instanceof ImmutableMap); - } - - @Override - public String toString() { - return Objects.toStringHelper(this) - .add("map", map) - .toString(); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/DefaultFileLinesContextFactory.java b/sonar-batch/src/main/java/org/sonar/batch/DefaultFileLinesContextFactory.java deleted file mode 100644 index 922f101f085..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/DefaultFileLinesContextFactory.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch; - -import org.sonar.api.batch.SonarIndex; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.measures.FileLinesContext; -import org.sonar.api.measures.FileLinesContextFactory; -import org.sonar.api.resources.File; -import org.sonar.api.resources.Resource; - -public class DefaultFileLinesContextFactory implements FileLinesContextFactory { - - private final SonarIndex index; - - public DefaultFileLinesContextFactory(SonarIndex index) { - this.index = index; - } - - @Override - public FileLinesContext createFor(Resource model) { - // Reload resource in case it use deprecated key - Resource resource = index.getResource(model); - return new DefaultFileLinesContext(index, resource); - } - - @Override - public FileLinesContext createFor(InputFile inputFile) { - File sonarFile = File.create(inputFile.relativePath()); - // Reload resource from index - sonarFile = index.getResource(sonarFile); - return new DefaultFileLinesContext(index, sonarFile); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/DefaultProjectTree.java b/sonar-batch/src/main/java/org/sonar/batch/DefaultProjectTree.java deleted file mode 100644 index 5b56f27154c..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/DefaultProjectTree.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch; - -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import org.apache.commons.lang.ObjectUtils; -import org.picocontainer.Startable; -import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.api.resources.Project; -import org.sonar.batch.scan.ImmutableProjectReactor; - -public class DefaultProjectTree implements Startable { - - private final ProjectConfigurator configurator; - private final ImmutableProjectReactor projectReactor; - - private List projects; - private Map projectsByDef; - - public DefaultProjectTree(ImmutableProjectReactor projectReactor, ProjectConfigurator projectConfigurator) { - this.projectReactor = projectReactor; - this.configurator = projectConfigurator; - } - - @Override - public void start() { - doStart(projectReactor.getProjects()); - } - - @Override - public void stop() { - // Nothing to do - } - - void doStart(Collection definitions) { - projects = Lists.newArrayList(); - projectsByDef = Maps.newHashMap(); - - for (ProjectDefinition def : definitions) { - Project project = configurator.create(def); - projectsByDef.put(def, project); - projects.add(project); - } - - for (Map.Entry entry : projectsByDef.entrySet()) { - ProjectDefinition def = entry.getKey(); - Project project = entry.getValue(); - for (ProjectDefinition module : def.getSubProjects()) { - projectsByDef.get(module).setParent(project); - } - } - - // Configure - for (Project project : projects) { - configurator.configure(project); - } - } - - public List getProjects() { - return projects; - } - - public Project getRootProject() { - for (Project project : projects) { - if (project.getParent() == null) { - return project; - } - } - throw new IllegalStateException("Can not find the root project from the list of Maven modules"); - } - - public ProjectDefinition getProjectDefinition(Project project) { - for (Map.Entry entry : projectsByDef.entrySet()) { - if (ObjectUtils.equals(entry.getValue(), project)) { - return entry.getKey(); - } - } - throw new IllegalStateException("Can not find ProjectDefinition for " + project); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java b/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java deleted file mode 100644 index 997cae744f2..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch; - -import java.util.Date; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.CoreProperties; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.api.config.Settings; -import org.sonar.api.resources.Project; -import org.sonar.api.utils.SonarException; -import org.sonar.api.utils.System2; - -/** - * Used by views !! - * - */ -@BatchSide -public class ProjectConfigurator { - - private static final Logger LOG = LoggerFactory.getLogger(ProjectConfigurator.class); - private final System2 system2; - private Settings settings; - - public ProjectConfigurator(Settings settings, System2 system2) { - this.settings = settings; - this.system2 = system2; - } - - public Project create(ProjectDefinition definition) { - Project project = new Project(definition.getKey(), definition.getBranch(), definition.getName()); - project.setDescription(StringUtils.defaultString(definition.getDescription())); - return project; - } - - public ProjectConfigurator configure(Project project) { - Date analysisDate = loadAnalysisDate(); - project - .setAnalysisDate(analysisDate) - .setAnalysisVersion(loadAnalysisVersion()) - .setAnalysisType(loadAnalysisType()); - return this; - } - - private Date loadAnalysisDate() { - Date date; - try { - // sonar.projectDate may have been specified as a time - date = settings.getDateTime(CoreProperties.PROJECT_DATE_PROPERTY); - } catch (SonarException e) { - // this is probably just a date - date = settings.getDate(CoreProperties.PROJECT_DATE_PROPERTY); - } - if (date == null) { - date = new Date(system2.now()); - settings.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, date, true); - } - return date; - } - - private Project.AnalysisType loadAnalysisType() { - String value = settings.getString(CoreProperties.DYNAMIC_ANALYSIS_PROPERTY); - if (value == null) { - return Project.AnalysisType.DYNAMIC; - } - - LOG.warn("'sonar.dynamicAnalysis' is deprecated since version 4.3 and should no longer be used."); - if ("true".equals(value)) { - return Project.AnalysisType.DYNAMIC; - } - if ("reuseReports".equals(value)) { - return Project.AnalysisType.REUSE_REPORTS; - } - return Project.AnalysisType.STATIC; - } - - private String loadAnalysisVersion() { - return settings.getString(CoreProperties.PROJECT_VERSION_PROPERTY); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/analysis/AnalysisProperties.java b/sonar-batch/src/main/java/org/sonar/batch/analysis/AnalysisProperties.java deleted file mode 100644 index e3be61067e6..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/analysis/AnalysisProperties.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.analysis; - -import java.util.Map; -import javax.annotation.Nullable; -import org.sonar.batch.bootstrap.UserProperties; - -/** - * Batch properties that are specific to an analysis (for example - * coming from sonar-project.properties). - */ -public class AnalysisProperties extends UserProperties { - public AnalysisProperties(Map properties) { - this(properties, null); - - } - - public AnalysisProperties(Map properties, @Nullable String pathToSecretKey) { - super(properties, pathToSecretKey); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/analysis/AnalysisTempFolderProvider.java b/sonar-batch/src/main/java/org/sonar/batch/analysis/AnalysisTempFolderProvider.java deleted file mode 100644 index 68c2608b864..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/analysis/AnalysisTempFolderProvider.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.analysis; - -import org.sonar.api.batch.bootstrap.ProjectReactor; -import org.picocontainer.PicoContainer; -import org.picocontainer.ComponentLifecycle; -import org.picocontainer.injectors.ProviderAdapter; -import org.sonar.api.utils.TempFolder; -import org.sonar.api.utils.internal.DefaultTempFolder; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; - -public class AnalysisTempFolderProvider extends ProviderAdapter implements ComponentLifecycle { - static final String TMP_NAME = ".sonartmp"; - private DefaultTempFolder projectTempFolder; - private boolean started = false; - - public TempFolder provide(ProjectReactor projectReactor) { - if (projectTempFolder == null) { - Path workingDir = projectReactor.getRoot().getWorkDir().toPath(); - Path tempDir = workingDir.normalize().resolve(TMP_NAME); - try { - Files.deleteIfExists(tempDir); - Files.createDirectories(tempDir); - } catch (IOException e) { - throw new IllegalStateException("Unable to create root temp directory " + tempDir, e); - } - - projectTempFolder = new DefaultTempFolder(tempDir.toFile(), true); - } - return projectTempFolder; - } - - @Override - public void start(PicoContainer container) { - started = true; - } - - @Override - public void stop(PicoContainer container) { - if (projectTempFolder != null) { - projectTempFolder.stop(); - } - } - - @Override - public void dispose(PicoContainer container) { - //nothing to do - } - - @Override - public boolean componentHasLifecycle() { - return true; - } - - @Override - public boolean isStarted() { - return started; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/analysis/AnalysisWSLoaderProvider.java b/sonar-batch/src/main/java/org/sonar/batch/analysis/AnalysisWSLoaderProvider.java deleted file mode 100644 index 54ce6e112a3..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/analysis/AnalysisWSLoaderProvider.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.analysis; - -import org.picocontainer.injectors.ProviderAdapter; -import org.sonar.api.batch.AnalysisMode; -import org.sonar.batch.bootstrap.BatchWsClient; -import org.sonar.batch.cache.WSLoader; -import org.sonar.batch.cache.WSLoader.LoadStrategy; -import org.sonar.home.cache.PersistentCache; - -public class AnalysisWSLoaderProvider extends ProviderAdapter { - static final String SONAR_USE_WS_CACHE = "sonar.useWsCache"; - private WSLoader wsLoader; - - public WSLoader provide(AnalysisMode mode, PersistentCache cache, BatchWsClient client, AnalysisProperties props) { - if (wsLoader == null) { - // recreate cache directory if needed for this analysis - cache.reconfigure(); - wsLoader = new WSLoader(getStrategy(mode, props), cache, client); - } - return wsLoader; - } - - private static LoadStrategy getStrategy(AnalysisMode mode, AnalysisProperties props) { - if (mode.isIssues() && "true".equals(props.property(SONAR_USE_WS_CACHE))) { - return LoadStrategy.CACHE_ONLY; - } - - return LoadStrategy.SERVER_ONLY; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/analysis/DefaultAnalysisMode.java b/sonar-batch/src/main/java/org/sonar/batch/analysis/DefaultAnalysisMode.java deleted file mode 100644 index bd27cf81ca0..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/analysis/DefaultAnalysisMode.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.analysis; - -import java.util.Map; -import javax.annotation.CheckForNull; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.CoreProperties; -import org.sonar.api.batch.AnalysisMode; -import org.sonar.batch.bootstrap.AbstractAnalysisMode; -import org.sonar.batch.bootstrap.GlobalProperties; -import org.sonar.batch.mediumtest.FakePluginInstaller; - -/** - * @since 4.0 - */ -public class DefaultAnalysisMode extends AbstractAnalysisMode implements AnalysisMode { - - private static final Logger LOG = LoggerFactory.getLogger(DefaultAnalysisMode.class); - private static final String KEY_SCAN_ALL = "sonar.scanAllFiles"; - - private boolean mediumTestMode; - private boolean notAssociated; - private boolean scanAllFiles; - - public DefaultAnalysisMode(GlobalProperties globalProps, AnalysisProperties props) { - init(globalProps.properties(), props.properties()); - } - - public boolean isMediumTest() { - return mediumTestMode; - } - - public boolean isNotAssociated() { - return notAssociated; - } - - public boolean scanAllFiles() { - return scanAllFiles; - } - - private void init(Map globalProps, Map analysisProps) { - // make sure analysis is consistent with global properties - boolean globalPreview = isIssues(globalProps); - boolean analysisPreview = isIssues(analysisProps); - - if (!globalPreview && analysisPreview) { - throw new IllegalStateException("Inconsistent properties: global properties doesn't enable issues mode while analysis properties enables it"); - } - - load(globalProps, analysisProps); - } - - private void load(Map globalProps, Map analysisProps) { - String mode = getPropertyWithFallback(analysisProps, globalProps, CoreProperties.ANALYSIS_MODE); - validate(mode); - issues = CoreProperties.ANALYSIS_MODE_ISSUES.equals(mode) || CoreProperties.ANALYSIS_MODE_PREVIEW.equals(mode); - mediumTestMode = "true".equals(getPropertyWithFallback(analysisProps, globalProps, FakePluginInstaller.MEDIUM_TEST_ENABLED)); - notAssociated = issues && rootProjectKeyMissing(analysisProps); - String scanAllStr = getPropertyWithFallback(analysisProps, globalProps, KEY_SCAN_ALL); - scanAllFiles = !issues || "true".equals(scanAllStr); - } - - public void printMode() { - if (preview) { - LOG.info("Preview mode"); - } else if (issues) { - LOG.info("Issues mode"); - } else { - LOG.info("Publish mode"); - } - if (mediumTestMode) { - LOG.info("Medium test mode"); - } - if (notAssociated) { - LOG.info("Local analysis"); - } - if (!scanAllFiles) { - LOG.info("Scanning only changed files"); - } - } - - @CheckForNull - private static String getPropertyWithFallback(Map props1, Map props2, String key) { - if (props1.containsKey(key)) { - return props1.get(key); - } - - return props2.get(key); - } - - private static boolean isIssues(Map props) { - String mode = props.get(CoreProperties.ANALYSIS_MODE); - - return CoreProperties.ANALYSIS_MODE_ISSUES.equals(mode); - } - - private static boolean rootProjectKeyMissing(Map props) { - // ProjectReactorBuilder depends on this class, so it will only create this property later - return !props.containsKey(CoreProperties.PROJECT_KEY_PROPERTY); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/analysis/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/analysis/package-info.java deleted file mode 100644 index be39545404c..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/analysis/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.batch.analysis; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/AbstractAnalysisMode.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/AbstractAnalysisMode.java deleted file mode 100644 index 2944accbd27..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/AbstractAnalysisMode.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.bootstrap; - -import org.apache.commons.lang.StringUtils; -import org.sonar.api.CoreProperties; - -import java.util.Arrays; - -import org.sonar.api.batch.AnalysisMode; - -public abstract class AbstractAnalysisMode implements AnalysisMode { - private static final String[] VALID_MODES = {CoreProperties.ANALYSIS_MODE_PREVIEW, CoreProperties.ANALYSIS_MODE_PUBLISH, CoreProperties.ANALYSIS_MODE_ISSUES}; - - protected boolean preview; - protected boolean issues; - - protected AbstractAnalysisMode() { - } - - @Override - public boolean isPreview() { - return preview; - } - - @Override - public boolean isIssues() { - return issues; - } - - @Override - public boolean isPublish() { - return !preview && !issues; - } - - protected static void validate(String mode) { - if (StringUtils.isEmpty(mode)) { - return; - } - - if (CoreProperties.ANALYSIS_MODE_INCREMENTAL.equals(mode)) { - throw new IllegalStateException("Invalid analysis mode: " + mode + ". This mode was removed in SonarQube 5.2. Valid modes are: " + Arrays.toString(VALID_MODES)); - } - - if (!Arrays.asList(VALID_MODES).contains(mode)) { - throw new IllegalStateException("Invalid analysis mode: " + mode + ". Valid modes are: " + Arrays.toString(VALID_MODES)); - } - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java deleted file mode 100644 index 0a2ec661d73..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.bootstrap; - -import com.google.common.collect.Lists; -import java.util.Collection; -import java.util.List; -import org.sonar.api.batch.AnalysisMode; -import org.sonar.batch.cpd.CpdComponents; -import org.sonar.batch.issue.tracking.ServerIssueFromWs; -import org.sonar.batch.issue.tracking.TrackedIssue; -import org.sonar.batch.scan.report.ConsoleReport; -import org.sonar.batch.scan.report.HtmlReport; -import org.sonar.batch.scan.report.IssuesReportBuilder; -import org.sonar.batch.scan.report.JSONReport; -import org.sonar.batch.scan.report.RuleNameProvider; -import org.sonar.batch.scan.report.SourceProvider; -import org.sonar.batch.scm.ScmConfiguration; -import org.sonar.batch.scm.ScmSensor; -import org.sonar.batch.source.CodeColorizerSensor; -import org.sonar.batch.source.LinesSensor; -import org.sonar.batch.source.ZeroCoverageSensor; -import org.sonar.batch.task.ListTask; -import org.sonar.batch.task.ScanTask; -import org.sonar.batch.task.Tasks; -import org.sonar.core.component.DefaultResourceTypes; -import org.sonar.core.config.CorePropertyDefinitions; -import org.sonar.core.issue.tracking.Tracker; -import org.sonar.core.platform.SonarQubeVersionProvider; - -public class BatchComponents { - private BatchComponents() { - // only static stuff - } - - public static Collection all(AnalysisMode analysisMode) { - List components = Lists.newArrayList( - new SonarQubeVersionProvider(), - DefaultResourceTypes.get(), - - // Tasks - Tasks.class, - ListTask.DEFINITION, - ListTask.class, - ScanTask.DEFINITION, - ScanTask.class); - components.addAll(CorePropertyDefinitions.all()); - if (!analysisMode.isIssues()) { - // SCM - components.add(ScmConfiguration.class); - components.add(ScmSensor.class); - - components.add(LinesSensor.class); - components.add(ZeroCoverageSensor.class); - components.add(CodeColorizerSensor.class); - - // CPD - components.addAll(CpdComponents.all()); - } else { - // Issues tracking - components.add(new Tracker()); - - // Issues report - components.add(ConsoleReport.class); - components.add(JSONReport.class); - components.add(HtmlReport.class); - components.add(IssuesReportBuilder.class); - components.add(SourceProvider.class); - components.add(RuleNameProvider.class); - } - return components; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionDictionnary.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionDictionnary.java deleted file mode 100644 index cfebad6cbb5..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionDictionnary.java +++ /dev/null @@ -1,264 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.bootstrap; - -import com.google.common.base.Predicates; -import com.google.common.collect.Collections2; -import com.google.common.collect.Lists; -import java.lang.annotation.Annotation; -import java.lang.reflect.Array; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import javax.annotation.Nullable; -import org.apache.commons.lang.ClassUtils; -import org.sonar.api.batch.CheckProject; -import org.sonar.api.batch.DependedUpon; -import org.sonar.api.batch.DependsUpon; -import org.sonar.api.batch.Phase; -import org.sonar.api.batch.postjob.PostJob; -import org.sonar.api.batch.postjob.PostJobContext; -import org.sonar.api.batch.sensor.Sensor; -import org.sonar.api.batch.sensor.SensorContext; -import org.sonar.api.resources.Project; -import org.sonar.api.utils.AnnotationUtils; -import org.sonar.api.utils.dag.DirectAcyclicGraph; -import org.sonar.batch.postjob.PostJobOptimizer; -import org.sonar.batch.postjob.PostJobWrapper; -import org.sonar.batch.sensor.DefaultSensorContext; -import org.sonar.batch.sensor.SensorOptimizer; -import org.sonar.batch.sensor.SensorWrapper; -import org.sonar.core.platform.ComponentContainer; - -/** - * @since 2.6 - */ -public class BatchExtensionDictionnary { - - private final ComponentContainer componentContainer; - private final SensorContext sensorContext; - private final SensorOptimizer sensorOptimizer; - private final PostJobContext postJobContext; - private final PostJobOptimizer postJobOptimizer; - - public BatchExtensionDictionnary(ComponentContainer componentContainer, DefaultSensorContext sensorContext, SensorOptimizer sensorOptimizer, PostJobContext postJobContext, - PostJobOptimizer postJobOptimizer) { - this.componentContainer = componentContainer; - this.sensorContext = sensorContext; - this.sensorOptimizer = sensorOptimizer; - this.postJobContext = postJobContext; - this.postJobOptimizer = postJobOptimizer; - } - - public Collection select(Class type, @Nullable Project project, boolean sort, @Nullable ExtensionMatcher matcher) { - List result = getFilteredExtensions(type, project, matcher); - if (sort) { - return sort(result); - } - return result; - } - - private static Phase.Name evaluatePhase(Object extension) { - Object extensionToEvaluate; - if (extension instanceof SensorWrapper) { - extensionToEvaluate = ((SensorWrapper) extension).wrappedSensor(); - } else { - extensionToEvaluate = extension; - } - Phase phaseAnnotation = AnnotationUtils.getAnnotation(extensionToEvaluate, Phase.class); - if (phaseAnnotation != null) { - return phaseAnnotation.name(); - } - return Phase.Name.DEFAULT; - } - - private List getFilteredExtensions(Class type, @Nullable Project project, @Nullable ExtensionMatcher matcher) { - List result = Lists.newArrayList(); - for (Object extension : getExtensions(type)) { - if (org.sonar.api.batch.Sensor.class.equals(type) && extension instanceof Sensor) { - extension = new SensorWrapper((Sensor) extension, sensorContext, sensorOptimizer); - } - if (shouldKeep(type, extension, project, matcher)) { - result.add((T) extension); - } - } - if (org.sonar.api.batch.Sensor.class.equals(type)) { - // Retrieve new Sensors and wrap then in SensorWrapper - for (Object extension : getExtensions(Sensor.class)) { - extension = new SensorWrapper((Sensor) extension, sensorContext, sensorOptimizer); - if (shouldKeep(type, extension, project, matcher)) { - result.add((T) extension); - } - } - } - if (org.sonar.api.batch.PostJob.class.equals(type)) { - // Retrieve new PostJob and wrap then in PostJobWrapper - for (Object extension : getExtensions(PostJob.class)) { - extension = new PostJobWrapper((PostJob) extension, postJobContext, postJobOptimizer); - if (shouldKeep(type, extension, project, matcher)) { - result.add((T) extension); - } - } - } - return result; - } - - protected List getExtensions(Class type) { - List extensions = Lists.newArrayList(); - completeBatchExtensions(componentContainer, extensions, type); - return extensions; - } - - private static void completeBatchExtensions(ComponentContainer container, List extensions, Class type) { - if (container != null) { - extensions.addAll(container.getComponentsByType(type)); - completeBatchExtensions(container.getParent(), extensions, type); - } - } - - public Collection sort(Collection extensions) { - DirectAcyclicGraph dag = new DirectAcyclicGraph(); - - for (T extension : extensions) { - dag.add(extension); - for (Object dependency : getDependencies(extension)) { - dag.add(extension, dependency); - } - for (Object generates : getDependents(extension)) { - dag.add(generates, extension); - } - completePhaseDependencies(dag, extension); - } - List sortedList = dag.sort(); - - return Collections2.filter(sortedList, Predicates.in(extensions)); - } - - /** - * Extension dependencies - */ - private List getDependencies(T extension) { - List result = new ArrayList<>(); - result.addAll(evaluateAnnotatedClasses(extension, DependsUpon.class)); - return result; - } - - /** - * Objects that depend upon this extension. - */ - public List getDependents(T extension) { - List result = new ArrayList<>(); - result.addAll(evaluateAnnotatedClasses(extension, DependedUpon.class)); - return result; - } - - private static void completePhaseDependencies(DirectAcyclicGraph dag, Object extension) { - Phase.Name phase = evaluatePhase(extension); - dag.add(extension, phase); - for (Phase.Name name : Phase.Name.values()) { - if (phase.compareTo(name) < 0) { - dag.add(name, extension); - } else if (phase.compareTo(name) > 0) { - dag.add(extension, name); - } - } - } - - protected List evaluateAnnotatedClasses(Object extension, Class annotation) { - List results = Lists.newArrayList(); - Class aClass = extension.getClass(); - while (aClass != null) { - evaluateClass(aClass, annotation, results); - - for (Method method : aClass.getDeclaredMethods()) { - if (method.getAnnotation(annotation) != null) { - checkAnnotatedMethod(method); - evaluateMethod(extension, method, results); - } - } - aClass = aClass.getSuperclass(); - } - - return results; - } - - private static void evaluateClass(Class extensionClass, Class annotationClass, List results) { - Annotation annotation = extensionClass.getAnnotation(annotationClass); - if (annotation != null) { - if (annotation.annotationType().isAssignableFrom(DependsUpon.class)) { - results.addAll(Arrays.asList(((DependsUpon) annotation).value())); - - } else if (annotation.annotationType().isAssignableFrom(DependedUpon.class)) { - results.addAll(Arrays.asList(((DependedUpon) annotation).value())); - } - } - - Class[] interfaces = extensionClass.getInterfaces(); - for (Class anInterface : interfaces) { - evaluateClass(anInterface, annotationClass, results); - } - } - - private void evaluateMethod(Object extension, Method method, List results) { - try { - Object result = method.invoke(extension); - if (result != null) { - if (result instanceof Class) { - results.addAll(componentContainer.getComponentsByType((Class) result)); - - } else if (result instanceof Collection) { - results.addAll((Collection) result); - - } else if (result.getClass().isArray()) { - for (int i = 0; i < Array.getLength(result); i++) { - results.add(Array.get(result, i)); - } - - } else { - results.add(result); - } - } - } catch (Exception e) { - throw new IllegalStateException("Can not invoke method " + method, e); - } - } - - private static void checkAnnotatedMethod(Method method) { - if (!Modifier.isPublic(method.getModifiers())) { - throw new IllegalStateException("Annotated method must be public:" + method); - } - if (method.getParameterTypes().length > 0) { - throw new IllegalStateException("Annotated method must not have parameters:" + method); - } - } - - private static boolean shouldKeep(Class type, Object extension, @Nullable Project project, @Nullable ExtensionMatcher matcher) { - boolean keep = (ClassUtils.isAssignable(extension.getClass(), type) - || (org.sonar.api.batch.Sensor.class.equals(type) && ClassUtils.isAssignable(extension.getClass(), Sensor.class))) - && (matcher == null || matcher.accept(extension)); - if (keep && project != null && ClassUtils.isAssignable(extension.getClass(), CheckProject.class)) { - keep = ((CheckProject) extension).shouldExecuteOnProject(project); - } - return keep; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginInstaller.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginInstaller.java deleted file mode 100644 index 1c1ee8e1fc4..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginInstaller.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.bootstrap; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.Lists; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang.CharUtils; -import org.apache.commons.lang.StringUtils; -import org.sonar.api.SonarPlugin; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; -import org.sonar.api.utils.log.Profiler; -import org.sonar.batch.cache.WSLoader; -import org.sonar.batch.cache.WSLoaderResult; -import org.sonar.core.platform.PluginInfo; -import org.sonar.core.platform.RemotePlugin; -import org.sonar.core.platform.RemotePluginFile; -import org.sonar.home.cache.FileCache; -import org.sonarqube.ws.client.GetRequest; -import org.sonarqube.ws.client.WsResponse; - -import static java.lang.String.format; - -/** - * Downloads the plugins installed on server and stores them in a local user cache - * (see {@link FileCacheProvider}). - */ -public class BatchPluginInstaller implements PluginInstaller { - - private static final Logger LOG = Loggers.get(BatchPluginInstaller.class); - private static final String PLUGINS_INDEX_URL = "/deploy/plugins/index.txt"; - - private final WSLoader wsLoader; - private final FileCache fileCache; - private final BatchPluginPredicate pluginPredicate; - private final BatchWsClient wsClient; - - public BatchPluginInstaller(WSLoader wsLoader, BatchWsClient wsClient, FileCache fileCache, BatchPluginPredicate pluginPredicate) { - this.wsLoader = wsLoader; - this.fileCache = fileCache; - this.pluginPredicate = pluginPredicate; - this.wsClient = wsClient; - } - - @Override - public Map installRemotes() { - return loadPlugins(listRemotePlugins()); - } - - private Map loadPlugins(List remotePlugins) { - Map infosByKey = new HashMap<>(); - - Profiler profiler = Profiler.create(LOG).startDebug("Load plugins"); - - for (RemotePlugin remotePlugin : remotePlugins) { - if (pluginPredicate.apply(remotePlugin.getKey())) { - File jarFile = download(remotePlugin); - PluginInfo info = PluginInfo.create(jarFile); - infosByKey.put(info.getKey(), info); - } - } - - profiler.stopDebug(); - return infosByKey; - } - - /** - * Returns empty on purpose. This method is used only by tests. - * @see org.sonar.batch.mediumtest.BatchMediumTester - */ - @Override - public Map installLocals() { - return Collections.emptyMap(); - } - - @VisibleForTesting - File download(final RemotePlugin remote) { - try { - final RemotePluginFile file = remote.file(); - return fileCache.get(file.getFilename(), file.getHash(), new FileDownloader(remote.getKey())); - } catch (Exception e) { - throw new IllegalStateException("Fail to download plugin: " + remote.getKey(), e); - } - } - - /** - * Gets information about the plugins installed on server (filename, checksum) - */ - @VisibleForTesting - List listRemotePlugins() { - try { - String pluginIndex = loadPluginIndex(); - String[] rows = StringUtils.split(pluginIndex, CharUtils.LF); - List result = Lists.newArrayList(); - for (String row : rows) { - result.add(RemotePlugin.unmarshal(row)); - } - return result; - - } catch (Exception e) { - throw new IllegalStateException("Fail to load plugin index: " + PLUGINS_INDEX_URL, e); - } - } - - private String loadPluginIndex() { - Profiler profiler = Profiler.create(LOG).startInfo("Load plugins index"); - WSLoaderResult wsResult = wsLoader.loadString(PLUGINS_INDEX_URL); - profiler.stopInfo(wsResult.isFromCache()); - return wsResult.get(); - } - - private class FileDownloader implements FileCache.Downloader { - private String key; - - FileDownloader(String key) { - this.key = key; - } - - @Override - public void download(String filename, File toFile) throws IOException { - String url = format("/deploy/plugins/%s/%s", key, filename); - if (LOG.isDebugEnabled()) { - LOG.debug("Download plugin {} to {}", filename, toFile); - } else { - LOG.info("Download {}", filename); - } - - WsResponse response = wsClient.call(new GetRequest(url)); - try (InputStream stream = response.contentStream()) { - FileUtils.copyInputStreamToFile(stream, toFile); - } - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginJarExploder.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginJarExploder.java deleted file mode 100644 index a91a6b38cbc..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginJarExploder.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.bootstrap; - -import org.apache.commons.io.FileUtils; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.utils.ZipUtils; -import org.sonar.core.platform.ExplodedPlugin; -import org.sonar.core.platform.PluginJarExploder; -import org.sonar.core.platform.PluginInfo; -import org.sonar.home.cache.FileCache; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; - -import static org.sonar.core.util.FileUtils.deleteQuietly; - -@BatchSide -public class BatchPluginJarExploder extends PluginJarExploder { - - private final FileCache fileCache; - - public BatchPluginJarExploder(FileCache fileCache) { - this.fileCache = fileCache; - } - - @Override - public ExplodedPlugin explode(PluginInfo info) { - try { - File dir = unzipFile(info.getNonNullJarFile()); - return explodeFromUnzippedDir(info.getKey(), info.getNonNullJarFile(), dir); - } catch (Exception e) { - throw new IllegalStateException(String.format("Fail to open plugin [%s]: %s", info.getKey(), info.getNonNullJarFile().getAbsolutePath()), e); - } - } - - private File unzipFile(File cachedFile) throws IOException { - String filename = cachedFile.getName(); - File destDir = new File(cachedFile.getParentFile(), filename + "_unzip"); - File lockFile = new File(cachedFile.getParentFile(), filename + "_unzip.lock"); - if (!destDir.exists()) { - FileOutputStream out = new FileOutputStream(lockFile); - try { - java.nio.channels.FileLock lock = out.getChannel().lock(); - try { - // Recheck in case of concurrent processes - if (!destDir.exists()) { - File tempDir = fileCache.createTempDir(); - ZipUtils.unzip(cachedFile, tempDir, newLibFilter()); - FileUtils.moveDirectory(tempDir, destDir); - } - } finally { - lock.release(); - } - } finally { - out.close(); - deleteQuietly(lockFile); - } - } - return destDir; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginPredicate.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginPredicate.java deleted file mode 100644 index ea4380c44da..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginPredicate.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.bootstrap; - -import com.google.common.base.Joiner; -import com.google.common.base.Predicate; -import com.google.common.base.Splitter; -import com.google.common.collect.Lists; - -import java.util.List; -import java.util.Set; - -import javax.annotation.Nonnull; - -import org.apache.commons.lang.StringUtils; -import org.sonar.api.CoreProperties; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.config.Settings; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; -import static com.google.common.collect.Sets.newHashSet; - -/** - * Filters the plugins to be enabled during analysis - */ -@BatchSide -public class BatchPluginPredicate implements Predicate { - - private static final Logger LOG = Loggers.get(BatchPluginPredicate.class); - - private static final String BUILDBREAKER_PLUGIN_KEY = "buildbreaker"; - private static final Joiner COMMA_JOINER = Joiner.on(", "); - - private final Set whites = newHashSet(); - private final Set blacks = newHashSet(); - private final GlobalMode mode; - - public BatchPluginPredicate(Settings settings, GlobalMode mode) { - this.mode = mode; - if (mode.isPreview() || mode.isIssues()) { - // These default values are not supported by Settings because the class CorePlugin - // is not loaded yet. - whites.addAll(propertyValues(settings, - CoreProperties.PREVIEW_INCLUDE_PLUGINS, CoreProperties.PREVIEW_INCLUDE_PLUGINS_DEFAULT_VALUE)); - blacks.addAll(propertyValues(settings, - CoreProperties.PREVIEW_EXCLUDE_PLUGINS, CoreProperties.PREVIEW_EXCLUDE_PLUGINS_DEFAULT_VALUE)); - } - if (!whites.isEmpty()) { - LOG.info("Include plugins: " + COMMA_JOINER.join(whites)); - } - if (!blacks.isEmpty()) { - LOG.info("Exclude plugins: " + COMMA_JOINER.join(blacks)); - } - } - - @Override - public boolean apply(@Nonnull String pluginKey) { - if (BUILDBREAKER_PLUGIN_KEY.equals(pluginKey) && mode.isPreview()) { - LOG.info("Build Breaker plugin is no more supported in preview mode"); - return false; - } - - if (whites.isEmpty()) { - return blacks.isEmpty() || !blacks.contains(pluginKey); - } - return whites.contains(pluginKey); - } - - Set getWhites() { - return whites; - } - - Set getBlacks() { - return blacks; - } - - private static List propertyValues(Settings settings, String key, String defaultValue) { - String s = StringUtils.defaultIfEmpty(settings.getString(key), defaultValue); - return Lists.newArrayList(Splitter.on(",").trimResults().omitEmptyStrings().split(s)); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java deleted file mode 100644 index 4d0d0c46c2d..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.bootstrap; - -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; - -import com.google.common.base.Preconditions; -import com.google.common.collect.Maps; -import java.util.Collection; -import java.util.Map; -import org.picocontainer.Startable; -import org.sonar.api.SonarPlugin; -import org.sonar.core.platform.PluginInfo; -import org.sonar.core.platform.PluginLoader; -import org.sonar.core.platform.PluginRepository; - -/** - * Orchestrates the installation and loading of plugins - */ -public class BatchPluginRepository implements PluginRepository, Startable { - private static final Logger LOG = Loggers.get(BatchPluginRepository.class); - - private final PluginInstaller installer; - private final PluginLoader loader; - - private Map pluginInstancesByKeys; - private Map infosByKeys; - - public BatchPluginRepository(PluginInstaller installer, PluginLoader loader) { - this.installer = installer; - this.loader = loader; - } - - @Override - public void start() { - infosByKeys = Maps.newHashMap(installer.installRemotes()); - pluginInstancesByKeys = Maps.newHashMap(loader.load(infosByKeys)); - - // this part is only used by tests - for (Map.Entry entry : installer.installLocals().entrySet()) { - String pluginKey = entry.getKey(); - infosByKeys.put(pluginKey, new PluginInfo(pluginKey)); - pluginInstancesByKeys.put(pluginKey, entry.getValue()); - } - - logPlugins(); - } - - private void logPlugins() { - if (infosByKeys.isEmpty()) { - LOG.debug("No plugins loaded"); - } else { - LOG.debug("Plugins:"); - for (PluginInfo p : infosByKeys.values()) { - LOG.debug(" * {} {} ({})", p.getName(), p.getVersion(), p.getKey()); - } - } - } - - @Override - public void stop() { - // close plugin classloaders - loader.unload(pluginInstancesByKeys.values()); - - pluginInstancesByKeys.clear(); - infosByKeys.clear(); - } - - @Override - public Collection getPluginInfos() { - return infosByKeys.values(); - } - - @Override - public PluginInfo getPluginInfo(String key) { - PluginInfo info = infosByKeys.get(key); - Preconditions.checkState(info != null, String.format("Plugin [%s] does not exist", key)); - return info; - } - - @Override - public SonarPlugin getPluginInstance(String key) { - SonarPlugin instance = pluginInstancesByKeys.get(key); - Preconditions.checkState(instance != null, String.format("Plugin [%s] does not exist", key)); - return instance; - } - - @Override - public boolean hasPlugin(String key) { - return infosByKeys.containsKey(key); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchWsClient.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchWsClient.java deleted file mode 100644 index d77670a6c86..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchWsClient.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.bootstrap; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Joiner; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import java.net.HttpURLConnection; -import java.util.ArrayList; -import java.util.List; -import org.sonar.api.CoreProperties; -import org.sonar.api.utils.MessageException; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; -import org.sonar.api.utils.log.Profiler; -import org.sonarqube.ws.client.HttpException; -import org.sonarqube.ws.client.WsClient; -import org.sonarqube.ws.client.WsConnector; -import org.sonarqube.ws.client.WsRequest; -import org.sonarqube.ws.client.WsResponse; - -import static java.lang.String.format; - -public class BatchWsClient { - - private static final Logger LOG = Loggers.get(BatchWsClient.class); - - private final WsClient target; - private final boolean hasCredentials; - - public BatchWsClient(WsClient target, boolean hasCredentials) { - this.target = target; - this.hasCredentials = hasCredentials; - } - - /** - * @throws IllegalStateException if the request could not be executed due to - * a connectivity problem or timeout. Because networks can - * fail during an exchange, it is possible that the remote server - * accepted the request before the failure - * @throws HttpException if the response code is not in range [200..300) - */ - public WsResponse call(WsRequest request) { - Profiler profiler = Profiler.createIfDebug(LOG).start(); - WsResponse response = target.wsConnector().call(request); - profiler.stopDebug(format("%s %d %s", request.getMethod(), response.code(), response.requestUrl())); - failIfUnauthorized(response); - return response; - } - - public String baseUrl() { - return target.wsConnector().baseUrl(); - } - - @VisibleForTesting - WsConnector wsConnector() { - return target.wsConnector(); - } - - private void failIfUnauthorized(WsResponse response) { - if (response.code() == HttpURLConnection.HTTP_UNAUTHORIZED) { - if (hasCredentials) { - // credentials are not valid - throw MessageException.of(format("Not authorized. Please check the properties %s and %s.", - CoreProperties.LOGIN, CoreProperties.PASSWORD)); - } - // not authenticated - see https://jira.sonarsource.com/browse/SONAR-4048 - throw MessageException.of(format("Not authorized. Analyzing this project requires to be authenticated. " + - "Please provide the values of the properties %s and %s.", CoreProperties.LOGIN, CoreProperties.PASSWORD)); - - } - if (response.code() == HttpURLConnection.HTTP_FORBIDDEN) { - // SONAR-4397 Details are in response content - throw MessageException.of(tryParseAsJsonError(response.content())); - } - response.failIfNotSuccessful(); - } - - private static String tryParseAsJsonError(String responseContent) { - try { - JsonParser parser = new JsonParser(); - JsonObject obj = parser.parse(responseContent).getAsJsonObject(); - JsonArray errors = obj.getAsJsonArray("errors"); - List errorMessages = new ArrayList<>(); - for (JsonElement e : errors) { - errorMessages.add(e.getAsJsonObject().get("msg").getAsString()); - } - return Joiner.on(", ").join(errorMessages); - } catch (Exception e) { - return responseContent; - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchWsClientProvider.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchWsClientProvider.java deleted file mode 100644 index d33baf821e5..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchWsClientProvider.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.bootstrap; - -import org.picocontainer.injectors.ProviderAdapter; -import org.sonar.api.CoreProperties; -import org.sonar.api.batch.BatchSide; -import org.sonar.batch.bootstrapper.EnvironmentInformation; -import org.sonarqube.ws.client.HttpConnector; -import org.sonarqube.ws.client.HttpWsClient; - -import static java.lang.Integer.parseInt; -import static java.lang.String.valueOf; -import static org.apache.commons.lang.StringUtils.defaultIfBlank; - -@BatchSide -public class BatchWsClientProvider extends ProviderAdapter { - - static final int CONNECT_TIMEOUT_MS = 5_000; - static final String READ_TIMEOUT_SEC_PROPERTY = "sonar.ws.timeout"; - static final int DEFAULT_READ_TIMEOUT_SEC = 60; - - private BatchWsClient wsClient; - - public synchronized BatchWsClient provide(final GlobalProperties settings, final EnvironmentInformation env) { - if (wsClient == null) { - String url = defaultIfBlank(settings.property("sonar.host.url"), CoreProperties.SERVER_BASE_URL_DEFAULT_VALUE); - HttpConnector.Builder builder = new HttpConnector.Builder(); - - // TODO proxy - - String timeoutSec = defaultIfBlank(settings.property(READ_TIMEOUT_SEC_PROPERTY), valueOf(DEFAULT_READ_TIMEOUT_SEC)); - String login = defaultIfBlank(settings.property(CoreProperties.LOGIN), null); - builder - .readTimeoutMilliseconds(parseInt(timeoutSec) * 1_000) - .connectTimeoutMilliseconds(CONNECT_TIMEOUT_MS) - .userAgent(env.toString()) - .url(url) - .credentials(login, settings.property(CoreProperties.PASSWORD)); - - wsClient = new BatchWsClient(new HttpWsClient(builder.build()), login != null); - } - return wsClient; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DroppedPropertyChecker.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DroppedPropertyChecker.java deleted file mode 100644 index 72b34d613ea..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DroppedPropertyChecker.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.bootstrap; - -import java.util.Map; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; - -import static java.util.Objects.requireNonNull; - -public class DroppedPropertyChecker { - - private static final Logger LOG = Loggers.get(DroppedPropertyChecker.class); - - private final Map settings; - private final Map properties; - - public DroppedPropertyChecker(Map properties, Map droppedPropertiesAndMsg) { - this.settings = requireNonNull(properties); - this.properties = requireNonNull(droppedPropertiesAndMsg); - } - - public void checkDroppedProperties() { - for (Map.Entry entry : properties.entrySet()) { - if (settings.containsKey(entry.getKey())) { - LOG.warn("Property '{}' is not supported any more. {}", entry.getKey(), entry.getValue()); - } - } - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionInstaller.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionInstaller.java deleted file mode 100644 index ff610139032..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionInstaller.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.bootstrap; - -import java.util.List; -import javax.annotation.Nullable; -import org.sonar.api.ExtensionProvider; -import org.sonar.api.SonarPlugin; -import org.sonar.api.batch.AnalysisMode; -import org.sonar.core.platform.ComponentContainer; -import org.sonar.core.platform.PluginInfo; -import org.sonar.core.platform.PluginRepository; - -public class ExtensionInstaller { - - private final PluginRepository pluginRepository; - private final AnalysisMode analysisMode; - - public ExtensionInstaller(PluginRepository pluginRepository, AnalysisMode analysisMode) { - this.pluginRepository = pluginRepository; - this.analysisMode = analysisMode; - } - - public ExtensionInstaller install(ComponentContainer container, ExtensionMatcher matcher) { - - // core components - for (Object o : BatchComponents.all(analysisMode)) { - doInstall(container, matcher, null, o); - } - - // plugin extensions - for (PluginInfo pluginInfo : pluginRepository.getPluginInfos()) { - SonarPlugin plugin = pluginRepository.getPluginInstance(pluginInfo.getKey()); - for (Object extension : plugin.getExtensions()) { - doInstall(container, matcher, pluginInfo, extension); - } - } - List providers = container.getComponentsByType(ExtensionProvider.class); - for (ExtensionProvider provider : providers) { - Object object = provider.provide(); - if (object instanceof Iterable) { - for (Object extension : (Iterable) object) { - doInstall(container, matcher, null, extension); - } - } else { - doInstall(container, matcher, null, object); - } - } - return this; - } - - private static void doInstall(ComponentContainer container, ExtensionMatcher matcher, @Nullable PluginInfo pluginInfo, Object extension) { - if (matcher.accept(extension)) { - container.addExtension(pluginInfo, extension); - } else { - container.declareExtension(pluginInfo, extension); - } - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionMatcher.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionMatcher.java deleted file mode 100644 index d38581f572d..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionMatcher.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.bootstrap; - -import org.sonar.api.batch.BatchSide; - -/** - * @since 3.6 - */ -@BatchSide -public interface ExtensionMatcher { - boolean accept(Object extension); -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionUtils.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionUtils.java deleted file mode 100644 index adf16a40315..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionUtils.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.bootstrap; - -import org.sonar.api.batch.BatchSide; -import org.sonar.api.batch.InstantiationStrategy; -import org.sonar.api.utils.AnnotationUtils; - -public class ExtensionUtils { - - private ExtensionUtils() { - // only static methods - } - - public static boolean isInstantiationStrategy(Object extension, String strategy) { - InstantiationStrategy annotation = AnnotationUtils.getAnnotation(extension, InstantiationStrategy.class); - if (annotation != null) { - return strategy.equals(annotation.value()); - } - return InstantiationStrategy.PER_PROJECT.equals(strategy); - } - - public static boolean isBatchSide(Object extension) { - return AnnotationUtils.getAnnotation(extension, BatchSide.class) != null; - } - - public static boolean isType(Object extension, Class extensionClass) { - Class clazz = extension instanceof Class ? (Class) extension : extension.getClass(); - return extensionClass.isAssignableFrom(clazz); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/FileCacheProvider.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/FileCacheProvider.java deleted file mode 100644 index 9880c7de23b..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/FileCacheProvider.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.bootstrap; - -import org.picocontainer.injectors.ProviderAdapter; -import org.sonar.api.config.Settings; -import org.sonar.home.cache.FileCache; -import org.sonar.home.cache.FileCacheBuilder; - -public class FileCacheProvider extends ProviderAdapter { - private FileCache cache; - - public FileCache provide(Settings settings) { - if (cache == null) { - String home = settings.getString("sonar.userHome"); - cache = new FileCacheBuilder(new Slf4jLogger()).setUserHome(home).build(); - } - return cache; - } -} 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 deleted file mode 100644 index 8ac69fd6258..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.bootstrap; - -import java.util.List; -import java.util.Map; -import org.sonar.api.SonarPlugin; -import org.sonar.api.utils.System2; -import org.sonar.api.utils.UriReader; -import org.sonar.batch.cache.GlobalPersistentCacheProvider; -import org.sonar.batch.cache.ProjectSyncContainer; -import org.sonar.batch.cache.StrategyWSLoaderProvider; -import org.sonar.batch.cache.WSLoader.LoadStrategy; -import org.sonar.batch.index.CachesManager; -import org.sonar.batch.platform.DefaultServer; -import org.sonar.batch.repository.DefaultGlobalRepositoriesLoader; -import org.sonar.batch.repository.GlobalRepositoriesLoader; -import org.sonar.batch.repository.GlobalRepositoriesProvider; -import org.sonar.batch.task.TaskContainer; -import org.sonar.core.platform.ComponentContainer; -import org.sonar.core.platform.PluginClassloaderFactory; -import org.sonar.core.platform.PluginInfo; -import org.sonar.core.platform.PluginLoader; -import org.sonar.core.platform.PluginRepository; -import org.sonar.core.util.DefaultHttpDownloader; -import org.sonar.core.util.UuidFactoryImpl; - -public class GlobalContainer extends ComponentContainer { - - private final Map bootstrapProperties; - private boolean preferCache; - - private GlobalContainer(Map bootstrapProperties, boolean preferCache) { - super(); - this.bootstrapProperties = bootstrapProperties; - this.preferCache = preferCache; - } - - public static GlobalContainer create(Map bootstrapProperties, List extensions, boolean preferCache) { - GlobalContainer container = new GlobalContainer(bootstrapProperties, preferCache); - container.add(extensions); - return container; - } - - @Override - protected void doBeforeStart() { - GlobalProperties bootstrapProps = new GlobalProperties(bootstrapProperties); - GlobalMode globalMode = new GlobalMode(bootstrapProps); - LoadStrategy strategy = getDataLoadingStrategy(globalMode, preferCache); - StrategyWSLoaderProvider wsLoaderProvider = new StrategyWSLoaderProvider(strategy); - add(wsLoaderProvider); - add(bootstrapProps); - add(globalMode); - addBootstrapComponents(); - } - - private static LoadStrategy getDataLoadingStrategy(GlobalMode mode, boolean preferCache) { - if (!mode.isIssues()) { - return LoadStrategy.SERVER_ONLY; - } - - return preferCache ? LoadStrategy.CACHE_FIRST : LoadStrategy.SERVER_FIRST; - } - - private void addBootstrapComponents() { - add( - // plugins - BatchPluginRepository.class, - PluginLoader.class, - PluginClassloaderFactory.class, - BatchPluginJarExploder.class, - BatchPluginPredicate.class, - ExtensionInstaller.class, - - CachesManager.class, - GlobalSettings.class, - new BatchWsClientProvider(), - DefaultServer.class, - new GlobalTempFolderProvider(), - DefaultHttpDownloader.class, - UriReader.class, - new FileCacheProvider(), - new GlobalPersistentCacheProvider(), - System2.INSTANCE, - new GlobalRepositoriesProvider(), - UuidFactoryImpl.INSTANCE); - addIfMissing(BatchPluginInstaller.class, PluginInstaller.class); - addIfMissing(DefaultGlobalRepositoriesLoader.class, GlobalRepositoriesLoader.class); - } - - @Override - protected void doAfterStart() { - installPlugins(); - } - - private void installPlugins() { - PluginRepository pluginRepository = getComponentByType(PluginRepository.class); - for (PluginInfo pluginInfo : pluginRepository.getPluginInfos()) { - SonarPlugin instance = pluginRepository.getPluginInstance(pluginInfo.getKey()); - addExtension(pluginInfo, instance); - } - } - - public void executeTask(Map taskProperties, Object... components) { - new TaskContainer(this, taskProperties, components).execute(); - } - - public void syncProject(String projectKey, boolean force) { - new ProjectSyncContainer(this, projectKey, force).execute(); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalMode.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalMode.java deleted file mode 100644 index 774dac71361..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalMode.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.bootstrap; - -import org.sonar.api.CoreProperties; - -import org.sonar.api.batch.AnalysisMode; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class GlobalMode extends AbstractAnalysisMode implements AnalysisMode { - private static final Logger LOG = LoggerFactory.getLogger(GlobalMode.class); - - public GlobalMode(GlobalProperties props) { - String mode = props.property(CoreProperties.ANALYSIS_MODE); - validate(mode); - issues = CoreProperties.ANALYSIS_MODE_ISSUES.equals(mode) || CoreProperties.ANALYSIS_MODE_PREVIEW.equals(mode); - - if (preview) { - LOG.debug("Preview global mode"); - } else if (issues) { - LOG.debug("Issues global mode"); - } else { - LOG.debug("Publish global mode"); - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalProperties.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalProperties.java deleted file mode 100644 index 62bc070080e..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalProperties.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.bootstrap; - -import org.sonar.api.CoreProperties; - -import java.util.Map; - -/** - * Immutable batch properties that are not specific to a task (for example - * coming from global configuration file of sonar-runner). - */ -public class GlobalProperties extends UserProperties { - - public GlobalProperties(Map properties) { - super(properties, properties.get(CoreProperties.ENCRYPTION_SECRET_KEY_PATH)); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalSettings.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalSettings.java deleted file mode 100644 index 4e5ebdd9c98..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalSettings.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.bootstrap; - -import com.google.common.collect.ImmutableMap; -import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.CoreProperties; -import org.sonar.api.config.PropertyDefinitions; -import org.sonar.api.config.Settings; -import org.sonar.api.utils.MessageException; -import org.sonar.batch.protocol.input.GlobalRepositories; - -public class GlobalSettings extends Settings { - - private static final Logger LOG = LoggerFactory.getLogger(GlobalSettings.class); - - private static final String JDBC_SPECIFIC_MESSAGE = "It will be ignored. There is no longer any DB connection to the SQ database."; - /** - * A map of dropped properties as key and specific message to display for that property - * (what will happen, what should the user do, ...) as a value - */ - private static final Map DROPPED_PROPERTIES = ImmutableMap.of( - "sonar.jdbc.url", JDBC_SPECIFIC_MESSAGE, - "sonar.jdbc.username", JDBC_SPECIFIC_MESSAGE, - "sonar.jdbc.password", JDBC_SPECIFIC_MESSAGE); - - private final GlobalProperties bootstrapProps; - private final GlobalRepositories globalReferentials; - private final GlobalMode mode; - - public GlobalSettings(GlobalProperties bootstrapProps, PropertyDefinitions propertyDefinitions, - GlobalRepositories globalReferentials, GlobalMode mode) { - - super(propertyDefinitions); - this.mode = mode; - getEncryption().setPathToSecretKey(bootstrapProps.property(CoreProperties.ENCRYPTION_SECRET_KEY_PATH)); - this.bootstrapProps = bootstrapProps; - this.globalReferentials = globalReferentials; - init(); - new DroppedPropertyChecker(this.getProperties(), DROPPED_PROPERTIES).checkDroppedProperties(); - } - - private void init() { - addProperties(globalReferentials.globalSettings()); - addProperties(bootstrapProps.properties()); - - if (hasKey(CoreProperties.PERMANENT_SERVER_ID)) { - LOG.info("Server id: " + getString(CoreProperties.PERMANENT_SERVER_ID)); - } - } - - @Override - protected void doOnGetProperties(String key) { - if (mode.isIssues() && key.endsWith(".secured") && !key.contains(".license")) { - throw MessageException.of("Access to the secured property '" + key - + "' is not possible in issues mode. The SonarQube plugin which requires this property must be deactivated in issues mode."); - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalTempFolderProvider.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalTempFolderProvider.java deleted file mode 100644 index 2ea3bff55a3..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalTempFolderProvider.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.bootstrap; - -import java.io.IOException; -import java.nio.file.DirectoryStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.concurrent.TimeUnit; -import org.apache.commons.lang.StringUtils; -import org.picocontainer.ComponentLifecycle; -import org.picocontainer.PicoContainer; -import org.picocontainer.injectors.ProviderAdapter; -import org.sonar.api.CoreProperties; -import org.sonar.api.utils.System2; -import org.sonar.api.utils.TempFolder; -import org.sonar.api.utils.internal.DefaultTempFolder; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; - -import static org.sonar.core.util.FileUtils.deleteQuietly; - -public class GlobalTempFolderProvider extends ProviderAdapter implements ComponentLifecycle { - private static final Logger LOG = Loggers.get(GlobalTempFolderProvider.class); - private static final long CLEAN_MAX_AGE = TimeUnit.DAYS.toMillis(21); - static final String TMP_NAME_PREFIX = ".sonartmp_"; - private boolean started = false; - - private System2 system; - private DefaultTempFolder tempFolder; - - public GlobalTempFolderProvider() { - this(new System2()); - } - - GlobalTempFolderProvider(System2 system) { - this.system = system; - } - - public TempFolder provide(GlobalProperties bootstrapProps) { - if (tempFolder == null) { - - String workingPathName = StringUtils.defaultIfBlank(bootstrapProps.property(CoreProperties.GLOBAL_WORKING_DIRECTORY), CoreProperties.GLOBAL_WORKING_DIRECTORY_DEFAULT_VALUE); - Path workingPath = Paths.get(workingPathName); - - if (!workingPath.isAbsolute()) { - Path home = findSonarHome(bootstrapProps); - workingPath = home.resolve(workingPath).normalize(); - } - - try { - cleanTempFolders(workingPath); - } catch (IOException e) { - LOG.error(String.format("failed to clean global working directory: %s", workingPath), e); - } - Path tempDir = createTempFolder(workingPath); - tempFolder = new DefaultTempFolder(tempDir.toFile(), true); - } - return tempFolder; - } - - private static Path createTempFolder(Path workingPath) { - try { - Files.createDirectories(workingPath); - } catch (IOException e) { - throw new IllegalStateException("Failed to create working path: " + workingPath, e); - } - - try { - return Files.createTempDirectory(workingPath, TMP_NAME_PREFIX); - } catch (IOException e) { - throw new IllegalStateException("Failed to create temporary folder in " + workingPath, e); - } - } - - private Path findSonarHome(GlobalProperties props) { - String home = props.property("sonar.userHome"); - if (home != null) { - return Paths.get(home).toAbsolutePath(); - } - - home = system.envVariable("SONAR_USER_HOME"); - - if (home != null) { - return Paths.get(home).toAbsolutePath(); - } - - home = system.property("user.home"); - return Paths.get(home, ".sonar").toAbsolutePath(); - } - - private static void cleanTempFolders(Path path) throws IOException { - if (Files.exists(path)) { - try (DirectoryStream stream = Files.newDirectoryStream(path, new CleanFilter())) { - for (Path p : stream) { - deleteQuietly(p.toFile()); - } - } - } - } - - private static class CleanFilter implements DirectoryStream.Filter { - @Override - public boolean accept(Path path) throws IOException { - if (!Files.isDirectory(path)) { - return false; - } - - if (!path.getFileName().toString().startsWith(TMP_NAME_PREFIX)) { - return false; - } - - long threshold = System.currentTimeMillis() - CLEAN_MAX_AGE; - - // we could also check the timestamp in the name, instead - BasicFileAttributes attrs; - - try { - attrs = Files.readAttributes(path, BasicFileAttributes.class); - } catch (IOException ioe) { - LOG.error(String.format("Couldn't read file attributes for %s : ", path), ioe); - return false; - } - - long creationTime = attrs.creationTime().toMillis(); - return creationTime < threshold; - } - } - - @Override - public void start(PicoContainer container) { - started = true; - } - - @Override - public void stop(PicoContainer container) { - if (tempFolder != null) { - tempFolder.stop(); - } - } - - @Override - public void dispose(PicoContainer container) { - //nothing to do - } - - @Override - public boolean componentHasLifecycle() { - return true; - } - - @Override - public boolean isStarted() { - return started; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/MetricProvider.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/MetricProvider.java deleted file mode 100644 index 1735ab4a79b..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/MetricProvider.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.bootstrap; - -import com.google.common.collect.Lists; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.ExtensionProvider; -import org.sonar.api.batch.InstantiationStrategy; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.Metric; -import org.sonar.api.measures.Metrics; - -import java.util.List; - -@BatchSide -@InstantiationStrategy(InstantiationStrategy.PER_BATCH) -public class MetricProvider extends ExtensionProvider { - - private Metrics[] factories; - - public MetricProvider(Metrics[] factories) { - this.factories = factories; - } - - public MetricProvider() { - this.factories = new Metrics[0]; - } - - @Override - public List provide() { - List metrics = Lists.newArrayList(CoreMetrics.getMetrics()); - for (Metrics factory : factories) { - metrics.addAll(factory.getMetrics()); - } - return metrics; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/PluginInstaller.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/PluginInstaller.java deleted file mode 100644 index 64f923bd9a5..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/PluginInstaller.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.bootstrap; - -import java.util.Map; -import org.sonar.api.SonarPlugin; -import org.sonar.api.batch.BatchSide; -import org.sonar.core.platform.PluginInfo; - -@BatchSide -public interface PluginInstaller { - - /** - * Gets the list of plugins installed on server and downloads them if not - * already in local cache. - * @return information about all installed plugins, grouped by key - */ - Map installRemotes(); - - /** - * Used only by tests. - * @see org.sonar.batch.mediumtest.BatchMediumTester - */ - Map installLocals(); -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/Slf4jLogger.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/Slf4jLogger.java deleted file mode 100644 index 270bc10fe0d..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/Slf4jLogger.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.bootstrap; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class Slf4jLogger implements org.sonar.home.cache.Logger { - - private static final Logger LOG = LoggerFactory.getLogger(Slf4jLogger.class); - - @Override - public void debug(String msg) { - LOG.debug(msg); - } - - @Override - public void info(String msg) { - LOG.info(msg); - } - - @Override - public void warn(String msg) { - LOG.warn(msg); - } - - @Override - public void error(String msg, Throwable t) { - LOG.error(msg, t); - } - - @Override - public void error(String msg) { - LOG.error(msg); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/UserProperties.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/UserProperties.java deleted file mode 100644 index d16f8e72d27..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/UserProperties.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.bootstrap; - -import com.google.common.collect.Maps; -import org.sonar.api.config.Encryption; - -import javax.annotation.Nullable; - -import java.util.Map; - -/** - * Properties that are coming from bootstrapper. - */ -public abstract class UserProperties { - - private final Map properties; - private final Encryption encryption; - - public UserProperties(Map properties, @Nullable String pathToSecretKey) { - encryption = new Encryption(pathToSecretKey); - Map decryptedProps = Maps.newHashMap(); - for (Map.Entry entry : properties.entrySet()) { - String value = entry.getValue(); - if (value != null && encryption.isEncrypted(value)) { - try { - value = encryption.decrypt(value); - } catch (Exception e) { - throw new IllegalStateException("Fail to decrypt the property " + entry.getKey() + ". Please check your secret key.", e); - } - } - decryptedProps.put(entry.getKey(), value); - } - this.properties = Maps.newHashMap(decryptedProps); - } - - public Map properties() { - return properties; - } - - public String property(String key) { - return properties.get(key); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/package-info.java deleted file mode 100644 index 0efbab080ec..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.batch.bootstrap; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Batch.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Batch.java deleted file mode 100644 index d5d3da13087..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Batch.java +++ /dev/null @@ -1,274 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.bootstrapper; - -import org.sonar.api.utils.MessageException; - -import com.google.common.base.Throwables; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; - -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import org.picocontainer.annotations.Nullable; -import org.sonar.batch.bootstrap.GlobalContainer; - -/** - * Entry point for sonar-runner 2.1. - * - * @since 2.14 - */ -public final class Batch { - - private boolean started = false; - private LoggingConfiguration loggingConfig; - private List components; - private Map bootstrapProperties = Maps.newHashMap(); - private GlobalContainer bootstrapContainer; - - private Batch(Builder builder) { - components = Lists.newArrayList(); - components.addAll(builder.components); - if (builder.environment != null) { - components.add(builder.environment); - } - if (builder.bootstrapProperties != null) { - bootstrapProperties.putAll(builder.bootstrapProperties); - } - if (builder.isEnableLoggingConfiguration()) { - loggingConfig = new LoggingConfiguration(builder.environment).setProperties(bootstrapProperties); - - if (builder.logOutput != null) { - loggingConfig.setLogOutput(builder.logOutput); - } - } - } - - public LoggingConfiguration getLoggingConfiguration() { - return loggingConfig; - } - - /** - * @deprecated since 4.4 use {@link #start()}, {@link #executeTask(Map)} and then {@link #stop()} - */ - @Deprecated - public synchronized Batch execute() { - configureLogging(); - start(); - boolean threw = true; - try { - executeTask(bootstrapProperties); - threw = false; - } finally { - doStop(threw); - } - - return this; - } - - /** - * @since 4.4 - */ - public synchronized Batch start() { - return start(false); - } - - public synchronized Batch start(boolean preferCache) { - if (started) { - throw new IllegalStateException("Batch is already started"); - } - - configureLogging(); - try { - bootstrapContainer = GlobalContainer.create(bootstrapProperties, components, preferCache); - bootstrapContainer.startComponents(); - } catch (RuntimeException e) { - throw handleException(e); - } - this.started = true; - - return this; - } - - /** - * @since 4.4 - */ - public Batch executeTask(Map analysisProperties, Object... components) { - checkStarted(); - configureTaskLogging(analysisProperties); - try { - bootstrapContainer.executeTask(analysisProperties, components); - } catch (RuntimeException e) { - throw handleException(e); - } - return this; - } - - /** - * @since 5.2 - */ - public Batch executeTask(Map analysisProperties, IssueListener issueListener) { - checkStarted(); - configureTaskLogging(analysisProperties); - try { - bootstrapContainer.executeTask(analysisProperties, components, issueListener); - } catch (RuntimeException e) { - throw handleException(e); - } - return this; - } - - private void checkStarted() { - if (!started) { - throw new IllegalStateException("Batch is not started. Unable to execute task."); - } - } - - private RuntimeException handleException(RuntimeException t) { - if (loggingConfig.isVerbose()) { - return t; - } - - for (Throwable y : Throwables.getCausalChain(t)) { - if (y instanceof MessageException) { - return (MessageException) y; - } - } - - return t; - } - - /** - * @since 5.2 - */ - public Batch syncProject(String projectKey) { - checkStarted(); - bootstrapContainer.syncProject(projectKey, true); - return this; - } - - /** - * @since 4.4 - */ - public synchronized void stop() { - doStop(false); - } - - private void doStop(boolean swallowException) { - checkStarted(); - configureLogging(); - try { - bootstrapContainer.stopComponents(swallowException); - } catch (RuntimeException e) { - throw handleException(e); - } - this.started = false; - } - - private void configureLogging() { - if (loggingConfig != null) { - loggingConfig.setProperties(bootstrapProperties); - LoggingConfigurator.apply(loggingConfig); - } - } - - private void configureTaskLogging(Map taskProperties) { - if (loggingConfig != null) { - loggingConfig.setProperties(taskProperties, bootstrapProperties); - LoggingConfigurator.apply(loggingConfig); - } - } - - public static Builder builder() { - return new Builder(); - } - - public static final class Builder { - private Map bootstrapProperties; - private EnvironmentInformation environment; - private List components = Lists.newArrayList(); - private boolean enableLoggingConfiguration = true; - private LogOutput logOutput; - - private Builder() { - } - - public Builder setEnvironment(EnvironmentInformation env) { - this.environment = env; - return this; - } - - public Builder setComponents(List l) { - this.components = l; - return this; - } - - public Builder setLogOutput(@Nullable LogOutput logOutput) { - this.logOutput = logOutput; - return this; - } - - /** - * @deprecated since 3.7 use {@link #setBootstrapProperties(Map)} - */ - @Deprecated - public Builder setGlobalProperties(Map globalProperties) { - this.bootstrapProperties = globalProperties; - return this; - } - - public Builder setBootstrapProperties(Map bootstrapProperties) { - this.bootstrapProperties = bootstrapProperties; - return this; - } - - public Builder addComponents(Object... components) { - Collections.addAll(this.components, components); - return this; - } - - public Builder addComponent(Object component) { - this.components.add(component); - return this; - } - - public boolean isEnableLoggingConfiguration() { - return enableLoggingConfiguration; - } - - /** - * Logback is configured by default. It can be disabled, but n this case the batch bootstrapper must provide its - * own implementation of SLF4J. - */ - public Builder setEnableLoggingConfiguration(boolean b) { - this.enableLoggingConfiguration = b; - return this; - } - - public Batch build() { - if (components == null) { - throw new IllegalStateException("Batch components are not set"); - } - return new Batch(this); - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/EnvironmentInformation.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/EnvironmentInformation.java deleted file mode 100644 index a04da9df40a..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/EnvironmentInformation.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.bootstrapper; - -import org.sonar.api.batch.BatchSide; - -/** - * Describes execution environment. - * - * @since 2.6 - */ -@BatchSide -public class EnvironmentInformation { - - private String key; - private String version; - - public EnvironmentInformation(String key, String version) { - this.key = key; - this.version = version; - } - - /** - * @return unique key of environment, for example - "maven", "ant" - */ - public String getKey() { - return key; - } - - /** - * @return version of environment, for example Maven can have "2.2.1" or "3.0.2", - * but there is no guarantees about format - it's just a string. - */ - public String getVersion() { - return version; - } - - @Override - public String toString() { - return String.format("%s/%s", key, version); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/IssueListener.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/IssueListener.java deleted file mode 100644 index bf3f399142a..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/IssueListener.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.bootstrapper; - -public interface IssueListener { - void handle(Issue issue); - - class Issue { - /** @since 5.3 */ - private Integer startLine; - /** @since 5.3 */ - private Integer startLineOffset; - /** @since 5.3 */ - private Integer endLine; - /** @since 5.3 */ - private Integer endLineOffset; - - private String key; - private String componentKey; - private String message; - private String ruleKey; - private String ruleName; - private String status; - private String resolution; - private boolean isNew; - private String assigneeLogin; - private String assigneeName; - private String severity; - - public String getSeverity() { - return severity; - } - - public void setSeverity(String severity) { - this.severity = severity; - } - - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - - public String getComponentKey() { - return componentKey; - } - - public void setComponentKey(String componentKey) { - this.componentKey = componentKey; - } - - public Integer getStartLine() { - return startLine; - } - - public void setStartLine(Integer startLine) { - this.startLine = startLine; - } - - public Integer getStartLineOffset() { - return startLineOffset; - } - - public void setStartLineOffset(Integer startLineOffset) { - this.startLineOffset = startLineOffset; - } - - public Integer getEndLine() { - return endLine; - } - - public void setEndLine(Integer endLine) { - this.endLine = endLine; - } - - public Integer getEndLineOffset() { - return endLineOffset; - } - - public void setEndLineOffset(Integer endLineOffset) { - this.endLineOffset = endLineOffset; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public String getRuleKey() { - return ruleKey; - } - - public void setRuleKey(String ruleKey) { - this.ruleKey = ruleKey; - } - - public String getRuleName() { - return ruleName; - } - - public void setRuleName(String ruleName) { - this.ruleName = ruleName; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - public String getResolution() { - return resolution; - } - - public void setResolution(String resolution) { - this.resolution = resolution; - } - - public boolean isNew() { - return isNew; - } - - public void setNew(boolean isNew) { - this.isNew = isNew; - } - - public String getAssigneeLogin() { - return assigneeLogin; - } - - public void setAssigneeLogin(String assigneeLogin) { - this.assigneeLogin = assigneeLogin; - } - - public String getAssigneeName() { - return assigneeName; - } - - public void setAssigneeName(String assigneeName) { - this.assigneeName = assigneeName; - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/LogCallbackAppender.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/LogCallbackAppender.java deleted file mode 100644 index 183cd378711..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/LogCallbackAppender.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.bootstrapper; - -import ch.qos.logback.classic.Level; -import ch.qos.logback.classic.spi.ILoggingEvent; -import ch.qos.logback.core.UnsynchronizedAppenderBase; - -public class LogCallbackAppender extends UnsynchronizedAppenderBase { - protected LogOutput target; - - public LogCallbackAppender(LogOutput target) { - setTarget(target); - } - - public void setTarget(LogOutput target) { - this.target = target; - } - - @Override - protected void append(ILoggingEvent event) { - target.log(event.getFormattedMessage(), translate(event.getLevel())); - } - - private static LogOutput.Level translate(Level level) { - switch (level.toInt()) { - case Level.ERROR_INT: - return LogOutput.Level.ERROR; - case Level.WARN_INT: - return LogOutput.Level.WARN; - case Level.INFO_INT: - return LogOutput.Level.INFO; - case Level.TRACE_INT: - return LogOutput.Level.TRACE; - case Level.DEBUG_INT: - default: - return LogOutput.Level.DEBUG; - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/LogOutput.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/LogOutput.java deleted file mode 100644 index b69c405d931..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/LogOutput.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.bootstrapper; - -/** - * Allow to redirect batch logs to a custom output. By defaults logs are written to System.out - * @since 5.2 - */ -public interface LogOutput { - - void log(String formattedMessage, Level level); - - enum Level { - ERROR, WARN, INFO, DEBUG, TRACE; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/LoggingConfiguration.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/LoggingConfiguration.java deleted file mode 100644 index 41a741bbd08..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/LoggingConfiguration.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.bootstrapper; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.Maps; - -import java.util.Map; - -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; - -import org.apache.commons.lang.StringUtils; - -/** - * @since 2.14 - */ -public final class LoggingConfiguration { - - public static final String PROPERTY_ROOT_LOGGER_LEVEL = "ROOT_LOGGER_LEVEL"; - public static final String PROPERTY_SQL_LOGGER_LEVEL = "SQL_LOGGER_LEVEL"; - - public static final String PROPERTY_FORMAT = "FORMAT"; - - public static final String LEVEL_ROOT_VERBOSE = "DEBUG"; - public static final String LEVEL_ROOT_DEFAULT = "INFO"; - - @VisibleForTesting - static final String FORMAT_DEFAULT = "%d{HH:mm:ss.SSS} %-5level - %msg%n"; - @VisibleForTesting - static final String FORMAT_MAVEN = "[%level] [%d{HH:mm:ss.SSS}] %msg%n"; - - private Map substitutionVariables = Maps.newHashMap(); - private LogOutput logOutput = null; - private boolean verbose; - - public LoggingConfiguration() { - this(null); - } - - public LoggingConfiguration(@Nullable EnvironmentInformation environment) { - setVerbose(false); - if (environment != null && "maven".equalsIgnoreCase(environment.getKey())) { - setFormat(FORMAT_MAVEN); - } else { - setFormat(FORMAT_DEFAULT); - } - } - - public LoggingConfiguration setProperties(Map properties) { - setShowSql(properties, null); - setVerbose(properties, null); - return this; - } - - public LoggingConfiguration setProperties(Map properties, @Nullable Map fallback) { - setShowSql(properties, fallback); - setVerbose(properties, fallback); - return this; - } - - public LoggingConfiguration setLogOutput(@Nullable LogOutput listener) { - this.logOutput = listener; - return this; - } - - public LoggingConfiguration setVerbose(boolean verbose) { - return setRootLevel(verbose ? LEVEL_ROOT_VERBOSE : LEVEL_ROOT_DEFAULT); - } - - public boolean isVerbose() { - return verbose; - } - - public LoggingConfiguration setVerbose(Map props, @Nullable Map fallback) { - String logLevel = getFallback("sonar.log.level", props, fallback); - String deprecatedProfilingLevel = getFallback("sonar.log.profilingLevel", props, fallback); - verbose = "true".equals(getFallback("sonar.verbose", props, fallback)) || - "DEBUG".equals(logLevel) || "TRACE".equals(logLevel) || - "BASIC".equals(deprecatedProfilingLevel) || "FULL".equals(deprecatedProfilingLevel); - - return setVerbose(verbose); - } - - @CheckForNull - private static String getFallback(String key, Map properties, @Nullable Map fallback) { - if (properties.containsKey(key)) { - return properties.get(key); - } - - if (fallback != null) { - return fallback.get(key); - } - - return null; - } - - public LoggingConfiguration setRootLevel(String level) { - return addSubstitutionVariable(PROPERTY_ROOT_LOGGER_LEVEL, level); - } - - public LoggingConfiguration setShowSql(boolean showSql) { - return addSubstitutionVariable(PROPERTY_SQL_LOGGER_LEVEL, showSql ? "TRACE" : "WARN"); - } - - public LoggingConfiguration setShowSql(Map properties, @Nullable Map fallback) { - String logLevel = getFallback("sonar.log.level", properties, fallback); - String deprecatedProfilingLevel = getFallback("sonar.log.profilingLevel", properties, fallback); - boolean sql = "TRACE".equals(logLevel) || "FULL".equals(deprecatedProfilingLevel); - - return setShowSql(sql); - } - - @VisibleForTesting - LoggingConfiguration setFormat(String format) { - return addSubstitutionVariable(PROPERTY_FORMAT, StringUtils.defaultIfBlank(format, FORMAT_DEFAULT)); - } - - public LoggingConfiguration addSubstitutionVariable(String key, String value) { - substitutionVariables.put(key, value); - return this; - } - - @VisibleForTesting - String getSubstitutionVariable(String key) { - return substitutionVariables.get(key); - } - - Map getSubstitutionVariables() { - return substitutionVariables; - } - - LogOutput getLogOutput() { - return logOutput; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/LoggingConfigurator.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/LoggingConfigurator.java deleted file mode 100644 index f7f45b1c6fe..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/LoggingConfigurator.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.bootstrapper; - -import ch.qos.logback.classic.Level; -import ch.qos.logback.classic.Logger; -import ch.qos.logback.classic.spi.ILoggingEvent; -import ch.qos.logback.core.Appender; -import java.io.File; -import org.apache.commons.lang.StringUtils; -import org.slf4j.LoggerFactory; -import org.sonar.core.config.Logback; - -public class LoggingConfigurator { - private static final String CUSTOM_APPENDER_NAME = "custom_stream"; - - private LoggingConfigurator() { - } - - public static void apply(LoggingConfiguration conf, File logbackFile) { - Logback.configure(logbackFile, conf.getSubstitutionVariables()); - - if (conf.getLogOutput() != null) { - setCustomRootAppender(conf); - } - } - - public static void apply(LoggingConfiguration conf) { - apply(conf, "/org/sonar/batch/bootstrapper/logback.xml"); - } - - public static void apply(LoggingConfiguration conf, String classloaderPath) { - Logback.configure(classloaderPath, conf.getSubstitutionVariables()); - - // if not set, keep default behavior (configured to stdout through the file in classpath) - if (conf.getLogOutput() != null) { - setCustomRootAppender(conf); - } - } - - private static void setCustomRootAppender(LoggingConfiguration conf) { - Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); - String level = StringUtils.defaultIfBlank(conf.getSubstitutionVariables().get(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL), LoggingConfiguration.LEVEL_ROOT_DEFAULT); - - if (logger.getAppender(CUSTOM_APPENDER_NAME) == null) { - logger.detachAndStopAllAppenders(); - logger.addAppender(createAppender(conf.getLogOutput())); - } - logger.setLevel(Level.toLevel(level)); - } - - private static Appender createAppender(LogOutput target) { - LogCallbackAppender appender = new LogCallbackAppender(target); - appender.setName(CUSTOM_APPENDER_NAME); - appender.start(); - - return appender; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/package-info.java deleted file mode 100644 index 645b8d7dfe2..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/package-info.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -/** - * This package is a part of bootstrap process, so we should take care about backward compatibility. - */ -@ParametersAreNonnullByDefault -package org.sonar.batch.bootstrapper; - -import javax.annotation.ParametersAreNonnullByDefault; - diff --git a/sonar-batch/src/main/java/org/sonar/batch/cache/DefaultProjectCacheStatus.java b/sonar-batch/src/main/java/org/sonar/batch/cache/DefaultProjectCacheStatus.java deleted file mode 100644 index 45baaecacc8..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/cache/DefaultProjectCacheStatus.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.cache; - -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Date; -import org.sonar.home.cache.PersistentCache; - -import static org.sonar.core.util.FileUtils.deleteQuietly; - -public class DefaultProjectCacheStatus implements ProjectCacheStatus { - private static final String STATUS_FILENAME = "cache-sync-status"; - private PersistentCache cache; - - public DefaultProjectCacheStatus(PersistentCache cache) { - this.cache = cache; - } - - @Override - public void save() { - Date now = new Date(); - - try { - try (ObjectOutputStream objOutput = new ObjectOutputStream(new FileOutputStream(getStatusFilePath().toFile()))) { - objOutput.writeObject(now); - } - } catch (IOException e) { - throw new IllegalStateException("Failed to write cache sync status", e); - } - } - - @Override - public void delete() { - cache.clear(); - deleteQuietly(getStatusFilePath().toFile()); - } - - @Override - public Date getSyncStatus() { - Path p = getStatusFilePath(); - try { - if (!Files.isRegularFile(p)) { - return null; - } - try (ObjectInputStream objInput = new ObjectInputStream(new FileInputStream(p.toFile()))) { - return (Date) objInput.readObject(); - } - } catch (IOException | ClassNotFoundException e) { - deleteQuietly(p.toFile()); - throw new IllegalStateException("Failed to read cache sync status", e); - } - } - - private Path getStatusFilePath() { - return cache.getDirectory().resolve(STATUS_FILENAME); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/cache/GlobalPersistentCacheProvider.java b/sonar-batch/src/main/java/org/sonar/batch/cache/GlobalPersistentCacheProvider.java deleted file mode 100644 index 6b8677e2ada..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/cache/GlobalPersistentCacheProvider.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.cache; - -import org.apache.commons.lang.StringUtils; -import org.sonar.batch.bootstrap.Slf4jLogger; -import org.sonar.home.cache.PersistentCacheBuilder; - -import java.nio.file.Paths; - -import org.sonar.batch.bootstrap.GlobalProperties; -import org.sonar.home.cache.PersistentCache; -import org.picocontainer.injectors.ProviderAdapter; - -public class GlobalPersistentCacheProvider extends ProviderAdapter { - private PersistentCache cache; - - public PersistentCache provide(GlobalProperties props) { - if (cache == null) { - PersistentCacheBuilder builder = new PersistentCacheBuilder(new Slf4jLogger()); - String home = props.property("sonar.userHome"); - String serverUrl = getServerUrl(props); - - if (home != null) { - builder.setSonarHome(Paths.get(home)); - } - - builder.setAreaForGlobal(serverUrl); - cache = builder.build(); - } - - return cache; - } - - private static String getServerUrl(GlobalProperties props) { - return StringUtils.removeEnd(StringUtils.defaultIfBlank(props.property("sonar.host.url"), "http://localhost:9000"), "/"); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/cache/NonAssociatedCacheSynchronizer.java b/sonar-batch/src/main/java/org/sonar/batch/cache/NonAssociatedCacheSynchronizer.java deleted file mode 100644 index 9287c268634..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/cache/NonAssociatedCacheSynchronizer.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.cache; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.List; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.utils.log.Loggers; -import org.sonar.api.utils.log.Profiler; -import org.sonar.batch.repository.QualityProfileLoader; -import org.sonar.batch.rule.ActiveRulesLoader; -import org.sonar.batch.rule.RulesLoader; -import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile; - -public class NonAssociatedCacheSynchronizer { - private static final Logger LOG = LoggerFactory.getLogger(NonAssociatedCacheSynchronizer.class); - - private final ProjectCacheStatus cacheStatus; - private final QualityProfileLoader qualityProfileLoader; - private final ActiveRulesLoader activeRulesLoader; - private final RulesLoader rulesLoader; - - public NonAssociatedCacheSynchronizer(RulesLoader rulesLoader, QualityProfileLoader qualityProfileLoader, ActiveRulesLoader activeRulesLoader, ProjectCacheStatus cacheStatus) { - this.rulesLoader = rulesLoader; - this.qualityProfileLoader = qualityProfileLoader; - this.activeRulesLoader = activeRulesLoader; - this.cacheStatus = cacheStatus; - } - - public void execute(boolean force) { - Date lastSync = cacheStatus.getSyncStatus(); - - if (lastSync != null) { - if (!force) { - LOG.info("Found cache [{}]", lastSync); - return; - } else { - LOG.info("-- Found cache [{}], synchronizing data..", lastSync); - } - } else { - LOG.info("-- Cache not found, synchronizing data.."); - } - - loadData(); - cacheStatus.save(); - LOG.info("-- Succesfully synchronized cache"); - } - - private static Collection getKeys(Collection qProfiles) { - List list = new ArrayList<>(qProfiles.size()); - for (QualityProfile qp : qProfiles) { - list.add(qp.getKey()); - } - - return list; - } - - private void loadData() { - Profiler profiler = Profiler.create(Loggers.get(ProjectCacheSynchronizer.class)); - - profiler.startInfo("Load rules"); - rulesLoader.load(null); - profiler.stopInfo(); - - profiler.startInfo("Load default quality profiles"); - Collection qProfiles = qualityProfileLoader.loadDefault(null, null); - profiler.stopInfo(); - - profiler.startInfo("Load default active rules"); - Collection keys = getKeys(qProfiles); - for (String k : keys) { - activeRulesLoader.load(k, null); - } - profiler.stopInfo(); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/cache/ProjectCacheStatus.java b/sonar-batch/src/main/java/org/sonar/batch/cache/ProjectCacheStatus.java deleted file mode 100644 index ef5fd9754a1..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/cache/ProjectCacheStatus.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.cache; - -import java.util.Date; - -public interface ProjectCacheStatus { - void save(); - - void delete(); - - Date getSyncStatus(); -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/cache/ProjectCacheSynchronizer.java b/sonar-batch/src/main/java/org/sonar/batch/cache/ProjectCacheSynchronizer.java deleted file mode 100644 index 9272d279aad..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/cache/ProjectCacheSynchronizer.java +++ /dev/null @@ -1,185 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.cache; - -import com.google.common.base.Function; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collection; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.utils.log.Loggers; -import org.sonar.api.utils.log.Profiler; -import org.sonar.batch.protocol.input.BatchInput.ServerIssue; -import org.sonar.batch.repository.ProjectRepositories; -import org.sonar.batch.repository.ProjectRepositoriesLoader; -import org.sonar.batch.repository.QualityProfileLoader; -import org.sonar.batch.repository.ServerIssuesLoader; -import org.sonar.batch.repository.user.UserRepositoryLoader; -import org.sonar.batch.rule.ActiveRulesLoader; -import org.sonar.batch.rule.RulesLoader; -import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile; - -public class ProjectCacheSynchronizer { - private static final Logger LOG = LoggerFactory.getLogger(ProjectCacheSynchronizer.class); - - private final ServerIssuesLoader issuesLoader; - private final UserRepositoryLoader userRepository; - private final ProjectCacheStatus cacheStatus; - private final QualityProfileLoader qualityProfileLoader; - private final ProjectRepositoriesLoader projectRepositoriesLoader; - private final ActiveRulesLoader activeRulesLoader; - private final RulesLoader rulesLoader; - - public ProjectCacheSynchronizer(RulesLoader rulesLoader, QualityProfileLoader qualityProfileLoader, ProjectRepositoriesLoader projectSettingsLoader, - ActiveRulesLoader activeRulesLoader, ServerIssuesLoader issuesLoader, - UserRepositoryLoader userRepository, ProjectCacheStatus cacheStatus) { - this.rulesLoader = rulesLoader; - this.qualityProfileLoader = qualityProfileLoader; - this.projectRepositoriesLoader = projectSettingsLoader; - this.activeRulesLoader = activeRulesLoader; - this.issuesLoader = issuesLoader; - this.userRepository = userRepository; - this.cacheStatus = cacheStatus; - } - - private static boolean isToday(Date d) { - Calendar c1 = Calendar.getInstance(); - Calendar c2 = Calendar.getInstance(); - c2.setTime(d); - - return c1.get(Calendar.DAY_OF_YEAR) == c2.get(Calendar.DAY_OF_YEAR) && - c1.get(Calendar.YEAR) == c2.get(Calendar.YEAR); - } - - private static boolean shouldUpdate(Date lastUpdate) { - return !isToday(lastUpdate); - } - - public void load(String projectKey, boolean force) { - Date lastSync = cacheStatus.getSyncStatus(); - boolean failOnError = true; - - if (lastSync != null) { - if (force) { - LOG.info("-- Found project [{}] cache [{}], synchronizing data (forced)..", projectKey, lastSync); - } else if (shouldUpdate(lastSync)) { - LOG.info("-- Found project [{}] cache [{}], synchronizing data..", projectKey, lastSync); - failOnError = false; - } else { - LOG.info("Found project [{}] cache [{}]", projectKey, lastSync); - return; - } - } else { - LOG.info("-- Cache for project [{}] not found, synchronizing data..", projectKey); - } - - try { - loadData(projectKey); - } catch (Exception e) { - if (failOnError) { - throw e; - } - - LOG.warn("-- Cache update for project [{}] failed, continuing from cache..", projectKey, e); - return; - } - - saveStatus(); - } - - private void saveStatus() { - cacheStatus.save(); - LOG.info("-- Successfully synchronized project cache"); - } - - private void loadData(String projectKey) { - Profiler profiler = Profiler.create(Loggers.get(ProjectCacheSynchronizer.class)); - - profiler.startInfo("Load rules"); - rulesLoader.load(null); - profiler.stopInfo(); - - profiler.startInfo("Load project settings"); - ProjectRepositories projectRepo = projectRepositoriesLoader.load(projectKey, true, null); - - if (!projectRepo.exists()) { - LOG.debug("Project doesn't exist in the server"); - } else if (projectRepo.lastAnalysisDate() == null) { - LOG.debug("No previous analysis found"); - } - profiler.stopInfo(); - - profiler.startInfo("Load project quality profiles"); - Collection qProfiles; - if (projectRepo.exists()) { - qProfiles = qualityProfileLoader.load(projectKey, null, null); - } else { - qProfiles = qualityProfileLoader.loadDefault(null, null); - } - profiler.stopInfo(); - - profiler.startInfo("Load project active rules"); - Collection keys = getKeys(qProfiles); - for (String k : keys) { - activeRulesLoader.load(k, null); - } - profiler.stopInfo(); - - if (projectRepo.lastAnalysisDate() != null) { - profiler.startInfo("Load server issues"); - UserLoginAccumulator consumer = new UserLoginAccumulator(); - issuesLoader.load(projectKey, consumer); - profiler.stopInfo(); - - profiler.startInfo("Load user information"); - for (String login : consumer.loginSet) { - userRepository.load(login, null); - } - profiler.stopInfo("Load user information"); - } - } - - private static Collection getKeys(Collection qProfiles) { - List list = new ArrayList<>(qProfiles.size()); - for (QualityProfile qp : qProfiles) { - list.add(qp.getKey()); - } - - return list; - } - - private static class UserLoginAccumulator implements Function { - Set loginSet = new HashSet<>(); - - @Override - public Void apply(ServerIssue input) { - if (!StringUtils.isEmpty(input.getAssigneeLogin())) { - loginSet.add(input.getAssigneeLogin()); - } - return null; - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/cache/ProjectKeySupplier.java b/sonar-batch/src/main/java/org/sonar/batch/cache/ProjectKeySupplier.java deleted file mode 100644 index abbd8a69485..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/cache/ProjectKeySupplier.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.cache; - -import org.sonar.api.batch.bootstrap.ProjectKey; - -public class ProjectKeySupplier implements ProjectKey { - private final String key; - - ProjectKeySupplier(String key) { - this.key = key; - } - - @Override - public String get() { - return key; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/cache/ProjectPersistentCacheProvider.java b/sonar-batch/src/main/java/org/sonar/batch/cache/ProjectPersistentCacheProvider.java deleted file mode 100644 index 2594a006543..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/cache/ProjectPersistentCacheProvider.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.cache; - -import org.sonar.api.batch.bootstrap.ProjectKey; - -import org.sonar.batch.util.BatchUtils; -import org.apache.commons.lang.StringUtils; -import org.sonar.batch.bootstrap.GlobalProperties; -import com.google.common.base.Preconditions; -import org.sonar.batch.analysis.DefaultAnalysisMode; -import org.sonar.batch.bootstrap.Slf4jLogger; - -import java.nio.file.Paths; - -import org.picocontainer.injectors.ProviderAdapter; -import org.sonar.home.cache.PersistentCache; -import org.sonar.home.cache.PersistentCacheBuilder; - -public class ProjectPersistentCacheProvider extends ProviderAdapter { - private PersistentCache cache; - - public PersistentCache provide(GlobalProperties props, DefaultAnalysisMode mode, ProjectKey key) { - if (cache == null) { - PersistentCacheBuilder builder = new PersistentCacheBuilder(new Slf4jLogger()); - String projectKey = key.get(); - String home = props.property("sonar.userHome"); - String serverUrl = getServerUrl(props); - - if (home != null) { - builder.setSonarHome(Paths.get(home)); - } - - if (mode.isNotAssociated()) { - builder.setAreaForLocalProject(serverUrl, BatchUtils.getServerVersion()); - } else { - Preconditions.checkNotNull(projectKey); - builder.setAreaForProject(serverUrl, BatchUtils.getServerVersion(), projectKey); - } - - cache = builder.build(); - } - - return cache; - } - - private static String getServerUrl(GlobalProperties props) { - return StringUtils.removeEnd(StringUtils.defaultIfBlank(props.property("sonar.host.url"), "http://localhost:9000"), "/"); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/cache/ProjectSyncContainer.java b/sonar-batch/src/main/java/org/sonar/batch/cache/ProjectSyncContainer.java deleted file mode 100644 index 816091786b3..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/cache/ProjectSyncContainer.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.cache; - -import java.util.HashMap; -import java.util.Map; -import javax.annotation.Nullable; -import org.sonar.api.CoreProperties; -import org.sonar.batch.analysis.AnalysisProperties; -import org.sonar.batch.analysis.DefaultAnalysisMode; -import org.sonar.batch.bootstrap.GlobalProperties; -import org.sonar.batch.cache.WSLoader.LoadStrategy; -import org.sonar.batch.repository.DefaultProjectRepositoriesLoader; -import org.sonar.batch.repository.DefaultQualityProfileLoader; -import org.sonar.batch.repository.DefaultServerIssuesLoader; -import org.sonar.batch.repository.ProjectRepositoriesLoader; -import org.sonar.batch.repository.QualityProfileLoader; -import org.sonar.batch.repository.ServerIssuesLoader; -import org.sonar.batch.repository.user.UserRepositoryLoader; -import org.sonar.batch.rule.ActiveRulesLoader; -import org.sonar.batch.rule.DefaultActiveRulesLoader; -import org.sonar.batch.rule.DefaultRulesLoader; -import org.sonar.batch.rule.RulesLoader; -import org.sonar.core.platform.ComponentContainer; - -public class ProjectSyncContainer extends ComponentContainer { - private final boolean force; - private final String projectKey; - - public ProjectSyncContainer(ComponentContainer globalContainer, @Nullable String projectKey, boolean force) { - super(globalContainer); - this.projectKey = projectKey; - this.force = force; - } - - @Override - public void doBeforeStart() { - addComponents(); - } - - @Override - public void doAfterStart() { - if (projectKey != null) { - getComponentByType(ProjectCacheSynchronizer.class).load(projectKey, force); - } else { - getComponentByType(NonAssociatedCacheSynchronizer.class).execute(force); - } - } - - private static DefaultAnalysisMode createIssuesAnalysisMode(@Nullable String projectKey) { - Map props = new HashMap<>(); - props.put(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES); - if (projectKey != null) { - props.put(CoreProperties.PROJECT_KEY_PROPERTY, projectKey); - } - GlobalProperties globalProps = new GlobalProperties(props); - AnalysisProperties analysisProps = new AnalysisProperties(props); - return new DefaultAnalysisMode(globalProps, analysisProps); - } - - private void addComponents() { - add(new StrategyWSLoaderProvider(LoadStrategy.SERVER_ONLY), - new ProjectKeySupplier(projectKey), - projectKey != null ? ProjectCacheSynchronizer.class : NonAssociatedCacheSynchronizer.class, - UserRepositoryLoader.class, - new ProjectPersistentCacheProvider(), - createIssuesAnalysisMode(projectKey)); - - addIfMissing(DefaultProjectCacheStatus.class, ProjectCacheStatus.class); - addIfMissing(DefaultProjectRepositoriesLoader.class, ProjectRepositoriesLoader.class); - addIfMissing(DefaultServerIssuesLoader.class, ServerIssuesLoader.class); - addIfMissing(DefaultQualityProfileLoader.class, QualityProfileLoader.class); - addIfMissing(DefaultRulesLoader.class, RulesLoader.class); - addIfMissing(DefaultActiveRulesLoader.class, ActiveRulesLoader.class); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/cache/StrategyWSLoaderProvider.java b/sonar-batch/src/main/java/org/sonar/batch/cache/StrategyWSLoaderProvider.java deleted file mode 100644 index d89de5ba448..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/cache/StrategyWSLoaderProvider.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.cache; - -import org.picocontainer.injectors.ProviderAdapter; -import org.sonar.batch.bootstrap.BatchWsClient; -import org.sonar.batch.cache.WSLoader.LoadStrategy; -import org.sonar.home.cache.PersistentCache; - -public class StrategyWSLoaderProvider extends ProviderAdapter { - private final LoadStrategy strategy; - private WSLoader wsLoader; - - public StrategyWSLoaderProvider(LoadStrategy strategy) { - this.strategy = strategy; - } - - public WSLoader provide(PersistentCache cache, BatchWsClient client) { - if (wsLoader == null) { - wsLoader = new WSLoader(strategy, cache, client); - } - return wsLoader; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/cache/WSLoader.java b/sonar-batch/src/main/java/org/sonar/batch/cache/WSLoader.java deleted file mode 100644 index 328480e68bf..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/cache/WSLoader.java +++ /dev/null @@ -1,240 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.cache; - -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; -import java.nio.charset.StandardCharsets; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import org.apache.commons.io.IOUtils; -import org.sonar.api.utils.MessageException; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; -import org.sonar.batch.bootstrap.BatchWsClient; -import org.sonar.home.cache.PersistentCache; -import org.sonarqube.ws.client.GetRequest; -import org.sonarqube.ws.client.HttpException; - -import static org.sonar.batch.cache.WSLoader.ServerStatus.ACCESSIBLE; -import static org.sonar.batch.cache.WSLoader.ServerStatus.NOT_ACCESSIBLE; -import static org.sonar.batch.cache.WSLoader.ServerStatus.UNKNOWN; - -public class WSLoader { - private static final Logger LOG = Loggers.get(WSLoader.class); - private static final String FAIL_MSG = "Server is not accessible and data is not cached"; - - public enum ServerStatus { - UNKNOWN, ACCESSIBLE, NOT_ACCESSIBLE - } - - public enum LoadStrategy { - SERVER_FIRST, CACHE_FIRST, SERVER_ONLY, CACHE_ONLY - } - - private final LoadStrategy defautLoadStrategy; - private final BatchWsClient wsClient; - private final PersistentCache cache; - private ServerStatus serverStatus; - - private DataLoader stringServerLoader = new DataLoader() { - @Override - public String load(String id) throws IOException { - GetRequest getRequest = new GetRequest(id); - try (Reader reader = wsClient.call(getRequest).contentReader()) { - String str = IOUtils.toString(reader); - try { - cache.put(id, str.getBytes(StandardCharsets.UTF_8)); - } catch (IOException e) { - throw new IllegalStateException("Error saving to WS cache", e); - } - return str; - } - } - }; - - private DataLoader stringCacheLoader = new DataLoader() { - @Override - public String load(String id) throws IOException { - return cache.getString(id); - } - }; - - private DataLoader streamServerLoader = new DataLoader() { - @Override - public InputStream load(String id) throws IOException { - GetRequest getRequest = new GetRequest(id); - try (InputStream is = wsClient.call(getRequest).contentStream()) { - try { - cache.put(id, is); - } catch (IOException e) { - throw new IllegalStateException("Error saving to WS cache", e); - } - } - return cache.getStream(id); - } - }; - - private DataLoader streamCacheLoader = new DataLoader() { - @Override - public InputStream load(String id) throws IOException { - return cache.getStream(id); - } - }; - - private static class NotAvailableException extends Exception { - private static final long serialVersionUID = 1L; - - public NotAvailableException(String message) { - super(message); - } - - public NotAvailableException(Throwable cause) { - super(cause); - } - } - - public WSLoader(LoadStrategy strategy, PersistentCache cache, BatchWsClient wsClient) { - this.defautLoadStrategy = strategy; - this.serverStatus = UNKNOWN; - this.cache = cache; - this.wsClient = wsClient; - } - - @Nonnull - public WSLoaderResult loadStream(String id) { - return load(id, defautLoadStrategy, streamServerLoader, streamCacheLoader); - } - - @Nonnull - public WSLoaderResult loadString(String id) { - return loadString(id, defautLoadStrategy); - } - - @Nonnull - public WSLoaderResult loadString(String id, WSLoader.LoadStrategy strategy) { - return load(id, strategy, stringServerLoader, stringCacheLoader); - } - - @Nonnull - private WSLoaderResult load(String id, WSLoader.LoadStrategy strategy, DataLoader serverLoader, DataLoader cacheLoader) { - switch (strategy) { - case CACHE_FIRST: - return loadFromCacheFirst(id, cacheLoader, serverLoader); - case CACHE_ONLY: - return loadFromCacheFirst(id, cacheLoader, null); - case SERVER_FIRST: - return loadFromServerFirst(id, serverLoader, cacheLoader); - case SERVER_ONLY: - default: - return loadFromServerFirst(id, serverLoader, null); - } - } - - public LoadStrategy getDefaultStrategy() { - return this.defautLoadStrategy; - } - - private void switchToOffline() { - LOG.debug("server not available - switching to offline mode"); - serverStatus = NOT_ACCESSIBLE; - } - - private void switchToOnline() { - serverStatus = ACCESSIBLE; - } - - private boolean isOffline() { - return serverStatus == NOT_ACCESSIBLE; - } - - @Nonnull - private WSLoaderResult loadFromCacheFirst(String id, DataLoader cacheLoader, @Nullable DataLoader serverLoader) { - try { - return loadFromCache(id, cacheLoader); - } catch (NotAvailableException cacheNotAvailable) { - if (serverLoader != null) { - try { - return loadFromServer(id, serverLoader); - } catch (NotAvailableException serverNotAvailable) { - throw new IllegalStateException(FAIL_MSG, serverNotAvailable.getCause()); - } - } - throw new IllegalStateException("Data is not cached", cacheNotAvailable.getCause()); - } - } - - @Nonnull - private WSLoaderResult loadFromServerFirst(String id, DataLoader serverLoader, @Nullable DataLoader cacheLoader) { - try { - return loadFromServer(id, serverLoader); - } catch (NotAvailableException serverNotAvailable) { - if (cacheLoader != null) { - try { - return loadFromCache(id, cacheLoader); - } catch (NotAvailableException cacheNotAvailable) { - throw new IllegalStateException(FAIL_MSG, serverNotAvailable.getCause()); - } - } - throw new IllegalStateException("Server is not available: " + wsClient.baseUrl(), serverNotAvailable.getCause()); - } - } - - interface DataLoader { - T load(String id) throws IOException; - } - - private WSLoaderResult loadFromCache(String id, DataLoader loader) throws NotAvailableException { - T result; - - try { - result = loader.load(id); - } catch (IOException e) { - // any exception on the cache should fail fast - throw new IllegalStateException(e); - } - if (result == null) { - throw new NotAvailableException("resource not cached"); - } - return new WSLoaderResult<>(result, true); - } - - private WSLoaderResult loadFromServer(String id, DataLoader loader) throws NotAvailableException { - if (isOffline()) { - throw new NotAvailableException("Server not available"); - } - try { - T t = loader.load(id); - switchToOnline(); - return new WSLoaderResult<>(t, false); - } catch (HttpException | MessageException e) { - // fail fast if it could connect but there was a application-level error - throw e; - } catch (IllegalStateException e) { - switchToOffline(); - throw new NotAvailableException(e); - } catch (Exception e) { - // fail fast - throw new IllegalStateException(e); - } - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/cache/WSLoaderResult.java b/sonar-batch/src/main/java/org/sonar/batch/cache/WSLoaderResult.java deleted file mode 100644 index 29db0bcb3a7..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/cache/WSLoaderResult.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.cache; - -import javax.annotation.Nonnull; - -public class WSLoaderResult { - private T result; - private boolean fromCache; - - public WSLoaderResult(T result, boolean fromCache) { - this.result = result; - this.fromCache = fromCache; - } - - @Nonnull - public T get() { - return result; - } - - public boolean isFromCache() { - return fromCache; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/cache/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/cache/package-info.java deleted file mode 100644 index 3f72a2d38b6..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/cache/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.batch.cache; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-batch/src/main/java/org/sonar/batch/cpd/CpdComponents.java b/sonar-batch/src/main/java/org/sonar/batch/cpd/CpdComponents.java deleted file mode 100644 index 30f4863783d..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/cpd/CpdComponents.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.cpd; - -import com.google.common.collect.ImmutableList; -import java.util.List; - -public final class CpdComponents { - - private CpdComponents() { - } - - public static List> all() { - return ImmutableList.of( - CpdSensor.class, - CpdMappings.class, - JavaCpdBlockIndexer.class, - DefaultCpdBlockIndexer.class); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/cpd/CpdExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/cpd/CpdExecutor.java deleted file mode 100644 index 38cee8c127c..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/cpd/CpdExecutor.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.cpd; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Function; -import com.google.common.base.Predicate; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.config.Settings; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; -import org.sonar.batch.cpd.index.SonarCpdBlockIndex; -import org.sonar.batch.index.BatchComponent; -import org.sonar.batch.index.BatchComponentCache; -import org.sonar.batch.protocol.output.BatchReport; -import org.sonar.batch.protocol.output.BatchReport.Duplicate; -import org.sonar.batch.protocol.output.BatchReport.Duplication; -import org.sonar.batch.report.ReportPublisher; -import org.sonar.batch.util.ProgressReport; -import org.sonar.duplications.block.Block; -import org.sonar.duplications.detector.suffixtree.SuffixTreeCloneDetectionAlgorithm; -import org.sonar.duplications.index.CloneGroup; -import org.sonar.duplications.index.ClonePart; -import org.sonar.duplications.index.PackedMemoryCloneIndex.ResourceBlocks; - -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -import static com.google.common.collect.FluentIterable.from; - -/** - * Runs on the root module, at the end of the project analysis. - * It executes copy paste detection involving all files of all modules, which were indexed during sensors execution for each module - * by {@link CpdSensor). The sensor is responsible for handling exclusions and block sizes. - */ -public class CpdExecutor { - private static final Logger LOG = Loggers.get(CpdExecutor.class); - // timeout for the computation of duplicates in a file (seconds) - private static final int TIMEOUT = 5 * 60; - static final int MAX_CLONE_GROUP_PER_FILE = 100; - static final int MAX_CLONE_PART_PER_GROUP = 100; - - private final SonarCpdBlockIndex index; - private final ReportPublisher publisher; - private final BatchComponentCache batchComponentCache; - private final Settings settings; - private final ExecutorService executorService; - private final ProgressReport progressReport; - private int count; - private int total; - - public CpdExecutor(Settings settings, SonarCpdBlockIndex index, ReportPublisher publisher, BatchComponentCache batchComponentCache) { - this.settings = settings; - this.index = index; - this.publisher = publisher; - this.batchComponentCache = batchComponentCache; - this.executorService = Executors.newSingleThreadExecutor(); - this.progressReport = new ProgressReport("CPD computation", TimeUnit.SECONDS.toMillis(10)); - } - - public void execute() { - total = index.noResources(); - progressReport.start(String.format("Calculating CPD for %d files", total)); - try { - Iterator it = index.iterator(); - - while (it.hasNext()) { - ResourceBlocks resourceBlocks = it.next(); - runCpdAnalysis(resourceBlocks.resourceId(), resourceBlocks.blocks()); - count++; - } - progressReport.stop("CPD calculation finished"); - } catch (Exception e) { - progressReport.stop(""); - throw e; - } - } - - private void runCpdAnalysis(String resource, final Collection fileBlocks) { - LOG.debug("Detection of duplications for {}", resource); - - BatchComponent component = batchComponentCache.get(resource); - if (component == null) { - LOG.error("Resource not found in component cache: {}. Skipping CPD computation for it", resource); - return; - } - - InputFile inputFile = (InputFile) component.inputComponent(); - progressReport.message(String.format("%d/%d - current file: %s", count, total, inputFile.absolutePath())); - - List duplications; - Future> futureResult = null; - try { - futureResult = executorService.submit(new Callable>() { - @Override - public List call() throws Exception { - return SuffixTreeCloneDetectionAlgorithm.detect(index, fileBlocks); - } - }); - duplications = futureResult.get(TIMEOUT, TimeUnit.SECONDS); - } catch (TimeoutException e) { - LOG.warn("Timeout during detection of duplications for " + inputFile.absolutePath()); - if (futureResult != null) { - futureResult.cancel(true); - } - return; - } catch (Exception e) { - throw new IllegalStateException("Fail during detection of duplication for " + inputFile.absolutePath(), e); - } - - List filtered; - if (!"java".equalsIgnoreCase(inputFile.language())) { - Predicate minimumTokensPredicate = DuplicationPredicates.numberOfUnitsNotLessThan(getMinimumTokens(inputFile.language())); - filtered = from(duplications).filter(minimumTokensPredicate).toList(); - } else { - filtered = duplications; - } - - saveDuplications(component, filtered); - } - - @VisibleForTesting - /** - * Not applicable to Java, as the {@link BlockChunker} that it uses does not record start and end units of each block. - * Also, it uses statements instead of tokens. - * @param languageKey - * @return - */ - int getMinimumTokens(String languageKey) { - int minimumTokens = settings.getInt("sonar.cpd." + languageKey + ".minimumTokens"); - if (minimumTokens == 0) { - minimumTokens = 100; - } - - return minimumTokens; - } - - @VisibleForTesting - final void saveDuplications(final BatchComponent component, List duplications) { - if (duplications.size() > MAX_CLONE_GROUP_PER_FILE) { - LOG.warn("Too many duplication groups on file " + component.inputComponent() + ". Keep only the first " + MAX_CLONE_GROUP_PER_FILE + - " groups."); - } - Iterable reportDuplications = from(duplications) - .limit(MAX_CLONE_GROUP_PER_FILE) - .transform( - new Function() { - private final BatchReport.Duplication.Builder dupBuilder = BatchReport.Duplication.newBuilder(); - private final BatchReport.Duplicate.Builder blockBuilder = BatchReport.Duplicate.newBuilder(); - - @Override - public BatchReport.Duplication apply(CloneGroup input) { - return toReportDuplication(component, dupBuilder, blockBuilder, input); - } - - }); - publisher.getWriter().writeComponentDuplications(component.batchId(), reportDuplications); - } - - private Duplication toReportDuplication(BatchComponent component, Duplication.Builder dupBuilder, Duplicate.Builder blockBuilder, CloneGroup input) { - dupBuilder.clear(); - ClonePart originBlock = input.getOriginPart(); - blockBuilder.clear(); - dupBuilder.setOriginPosition(BatchReport.TextRange.newBuilder() - .setStartLine(originBlock.getStartLine()) - .setEndLine(originBlock.getEndLine()) - .build()); - int clonePartCount = 0; - for (ClonePart duplicate : input.getCloneParts()) { - if (!duplicate.equals(originBlock)) { - clonePartCount++; - if (clonePartCount > MAX_CLONE_PART_PER_GROUP) { - LOG.warn("Too many duplication references on file " + component.inputComponent() + " for block at line " + - originBlock.getStartLine() + ". Keep only the first " - + MAX_CLONE_PART_PER_GROUP + " references."); - break; - } - blockBuilder.clear(); - String componentKey = duplicate.getResourceId(); - if (!component.key().equals(componentKey)) { - BatchComponent sameProjectComponent = batchComponentCache.get(componentKey); - blockBuilder.setOtherFileRef(sameProjectComponent.batchId()); - } - dupBuilder.addDuplicate(blockBuilder - .setRange(BatchReport.TextRange.newBuilder() - .setStartLine(duplicate.getStartLine()) - .setEndLine(duplicate.getEndLine()) - .build()) - .build()); - } - } - return dupBuilder.build(); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/cpd/CpdIndexer.java b/sonar-batch/src/main/java/org/sonar/batch/cpd/CpdIndexer.java deleted file mode 100644 index 9ebf80c88a7..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/cpd/CpdIndexer.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.cpd; - -import org.slf4j.Logger; -import org.sonar.api.batch.BatchSide; - -@BatchSide -public abstract class CpdIndexer { - - abstract boolean isLanguageSupported(String language); - - abstract void index(String language); - - protected void logExclusions(String[] exclusions, Logger logger) { - if (exclusions.length > 0) { - StringBuilder message = new StringBuilder("Copy-paste detection exclusions:"); - for (String exclusion : exclusions) { - message.append("\n "); - message.append(exclusion); - } - - logger.info(message.toString()); - } - } - - @Override - public String toString() { - return getClass().getSimpleName(); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/cpd/CpdMappings.java b/sonar-batch/src/main/java/org/sonar/batch/cpd/CpdMappings.java deleted file mode 100644 index 9a930d62fb5..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/cpd/CpdMappings.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.cpd; - -import org.sonar.api.batch.BatchSide; -import org.sonar.api.batch.CpdMapping; - -import javax.annotation.CheckForNull; - -@BatchSide -public class CpdMappings { - - private final CpdMapping[] mappings; - - public CpdMappings(CpdMapping[] mappings) { - this.mappings = mappings; - } - - public CpdMappings() { - this(new CpdMapping[0]); - } - - @CheckForNull - public CpdMapping getMapping(String language) { - if (mappings != null) { - for (CpdMapping cpdMapping : mappings) { - if (cpdMapping.getLanguage().getKey().equals(language)) { - return cpdMapping; - } - } - } - return null; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/cpd/CpdSensor.java b/sonar-batch/src/main/java/org/sonar/batch/cpd/CpdSensor.java deleted file mode 100644 index 9ea1bac9254..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/cpd/CpdSensor.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.cpd; - -import com.google.common.annotations.VisibleForTesting; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.CoreProperties; -import org.sonar.api.batch.Phase; -import org.sonar.api.batch.fs.FileSystem; -import org.sonar.api.batch.sensor.Sensor; -import org.sonar.api.batch.sensor.SensorContext; -import org.sonar.api.batch.sensor.SensorDescriptor; -import org.sonar.api.config.Settings; - -@Phase(name = Phase.Name.POST) -public class CpdSensor implements Sensor { - - private static final Logger LOG = LoggerFactory.getLogger(CpdSensor.class); - - private CpdIndexer sonarEngine; - private CpdIndexer sonarBridgeEngine; - private Settings settings; - private FileSystem fs; - - public CpdSensor(JavaCpdBlockIndexer sonarEngine, DefaultCpdBlockIndexer sonarBridgeEngine, Settings settings, FileSystem fs) { - this.sonarEngine = sonarEngine; - this.sonarBridgeEngine = sonarBridgeEngine; - this.settings = settings; - this.fs = fs; - } - - @Override - public void describe(SensorDescriptor descriptor) { - descriptor.name("CPD Sensor"); - } - - @VisibleForTesting - CpdIndexer getEngine(String language) { - if (sonarEngine.isLanguageSupported(language)) { - return sonarEngine; - } - return sonarBridgeEngine; - } - - @VisibleForTesting - boolean isSkipped(String language) { - String key = "sonar.cpd." + language + ".skip"; - if (settings.hasKey(key)) { - return settings.getBoolean(key); - } - return settings.getBoolean(CoreProperties.CPD_SKIP_PROPERTY); - } - - @Override - public void execute(SensorContext context) { - if (settings.hasKey(CoreProperties.CPD_SKIP_PROPERTY)) { - LOG.warn("\"sonar.cpd.skip\" property is deprecated and will be removed. Please set \"sonar.cpd.exclusions=**\" instead to disable duplication mechanism."); - } - - for (String language : fs.languages()) { - if (settings.hasKey("sonar.cpd." + language + ".skip")) { - LOG - .warn("\"sonar.cpd." + language + ".skip\" property is deprecated and will be removed. Please set \"sonar.cpd.exclusions=**\" instead to disable duplication mechanism."); - } - - if (isSkipped(language)) { - LOG.info("Detection of duplicated code is skipped for {}", language); - continue; - } - - CpdIndexer engine = getEngine(language); - if (!engine.isLanguageSupported(language)) { - LOG.debug("Detection of duplicated code is not supported for {}", language); - continue; - } - LOG.info("{} is used for {}", engine, language); - engine.index(language); - } - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/cpd/DefaultCpdBlockIndexer.java b/sonar-batch/src/main/java/org/sonar/batch/cpd/DefaultCpdBlockIndexer.java deleted file mode 100644 index 33b2f269595..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/cpd/DefaultCpdBlockIndexer.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.cpd; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.Lists; -import java.util.List; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.CoreProperties; -import org.sonar.api.batch.CpdMapping; -import org.sonar.api.batch.fs.FilePredicates; -import org.sonar.api.batch.fs.FileSystem; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.config.Settings; -import org.sonar.batch.cpd.index.SonarCpdBlockIndex; -import org.sonar.duplications.block.Block; -import org.sonar.duplications.internal.pmd.TokenizerBridge; - -public class DefaultCpdBlockIndexer extends CpdIndexer { - - private static final Logger LOG = LoggerFactory.getLogger(DefaultCpdBlockIndexer.class); - - private final CpdMappings mappings; - private final FileSystem fs; - private final Settings settings; - private final SonarCpdBlockIndex index; - - public DefaultCpdBlockIndexer(CpdMappings mappings, FileSystem fs, Settings settings, SonarCpdBlockIndex index) { - this.mappings = mappings; - this.fs = fs; - this.settings = settings; - this.index = index; - } - - @Override - public boolean isLanguageSupported(String language) { - return true; - } - - @Override - public void index(String languageKey) { - CpdMapping mapping = mappings.getMapping(languageKey); - if (mapping == null) { - LOG.debug("No CpdMapping for language " + languageKey); - return; - } - - String[] cpdExclusions = settings.getStringArray(CoreProperties.CPD_EXCLUSIONS); - logExclusions(cpdExclusions, LOG); - FilePredicates p = fs.predicates(); - List sourceFiles = Lists.newArrayList(fs.inputFiles(p.and( - p.hasType(InputFile.Type.MAIN), - p.hasLanguage(languageKey), - p.doesNotMatchPathPatterns(cpdExclusions)))); - if (sourceFiles.isEmpty()) { - return; - } - - // Create index - populateIndex(languageKey, sourceFiles, mapping); - } - - private void populateIndex(String languageKey, List sourceFiles, CpdMapping mapping) { - TokenizerBridge bridge = new TokenizerBridge(mapping.getTokenizer(), fs.encoding().name(), getBlockSize(languageKey)); - for (InputFile inputFile : sourceFiles) { - if (!index.isIndexed(inputFile)) { - LOG.debug("Populating index from {}", inputFile); - String resourceEffectiveKey = ((DefaultInputFile) inputFile).key(); - List blocks = bridge.chunk(resourceEffectiveKey, inputFile.file()); - index.insert(inputFile, blocks); - } - } - } - - @VisibleForTesting - int getBlockSize(String languageKey) { - int blockSize = settings.getInt("sonar.cpd." + languageKey + ".minimumLines"); - if (blockSize == 0) { - blockSize = getDefaultBlockSize(languageKey); - } - return blockSize; - } - - @VisibleForTesting - public static int getDefaultBlockSize(String languageKey) { - if ("cobol".equals(languageKey)) { - return 30; - } else if ("abap".equals(languageKey)) { - return 20; - } else { - return 10; - } - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/cpd/DuplicationPredicates.java b/sonar-batch/src/main/java/org/sonar/batch/cpd/DuplicationPredicates.java deleted file mode 100644 index e016ae6f970..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/cpd/DuplicationPredicates.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.cpd; - -import com.google.common.base.Predicate; -import org.sonar.duplications.index.CloneGroup; - -import javax.annotation.Nullable; - -public final class DuplicationPredicates { - - private DuplicationPredicates() { - } - - public static Predicate numberOfUnitsNotLessThan(int min) { - return new NumberOfUnitsNotLessThan(min); - } - - private static class NumberOfUnitsNotLessThan implements Predicate { - private final int min; - - public NumberOfUnitsNotLessThan(int min) { - this.min = min; - } - - @Override - public boolean apply(@Nullable CloneGroup input) { - return input != null && input.getLengthInUnits() >= min; - } - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/cpd/JavaCpdBlockIndexer.java b/sonar-batch/src/main/java/org/sonar/batch/cpd/JavaCpdBlockIndexer.java deleted file mode 100644 index a2dde817c74..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/cpd/JavaCpdBlockIndexer.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.cpd; - -import com.google.common.collect.Lists; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.Reader; -import java.util.List; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.CoreProperties; -import org.sonar.api.batch.fs.FilePredicates; -import org.sonar.api.batch.fs.FileSystem; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.config.Settings; -import org.sonar.batch.cpd.index.SonarCpdBlockIndex; -import org.sonar.duplications.block.Block; -import org.sonar.duplications.block.BlockChunker; -import org.sonar.duplications.java.JavaStatementBuilder; -import org.sonar.duplications.java.JavaTokenProducer; -import org.sonar.duplications.statement.Statement; -import org.sonar.duplications.statement.StatementChunker; -import org.sonar.duplications.token.TokenChunker; - -public class JavaCpdBlockIndexer extends CpdIndexer { - - private static final Logger LOG = LoggerFactory.getLogger(JavaCpdBlockIndexer.class); - - private static final int BLOCK_SIZE = 10; - - private final FileSystem fs; - private final Settings settings; - private final SonarCpdBlockIndex index; - - public JavaCpdBlockIndexer(FileSystem fs, Settings settings, SonarCpdBlockIndex index) { - this.fs = fs; - this.settings = settings; - this.index = index; - } - - @Override - public boolean isLanguageSupported(String language) { - return "java".equals(language); - } - - @Override - public void index(String languageKey) { - String[] cpdExclusions = settings.getStringArray(CoreProperties.CPD_EXCLUSIONS); - logExclusions(cpdExclusions, LOG); - FilePredicates p = fs.predicates(); - List sourceFiles = Lists.newArrayList(fs.inputFiles(p.and( - p.hasType(InputFile.Type.MAIN), - p.hasLanguage(languageKey), - p.doesNotMatchPathPatterns(cpdExclusions)))); - if (sourceFiles.isEmpty()) { - return; - } - createIndex(sourceFiles); - } - - private void createIndex(Iterable sourceFiles) { - TokenChunker tokenChunker = JavaTokenProducer.build(); - StatementChunker statementChunker = JavaStatementBuilder.build(); - BlockChunker blockChunker = new BlockChunker(BLOCK_SIZE); - - for (InputFile inputFile : sourceFiles) { - LOG.debug("Populating index from {}", inputFile); - String resourceEffectiveKey = ((DefaultInputFile) inputFile).key(); - - List statements; - - try(Reader reader = new InputStreamReader(new FileInputStream(inputFile.file()), fs.encoding())) { - statements = statementChunker.chunk(tokenChunker.chunk(reader)); - } catch (FileNotFoundException e) { - throw new IllegalStateException("Cannot find file " + inputFile.file(), e); - } catch (IOException e ) { - throw new IllegalStateException("Exception hnadling file: " + inputFile.file(), e); - } - - List blocks = blockChunker.chunk(resourceEffectiveKey, statements); - index.insert(inputFile, blocks); - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/cpd/index/SonarCpdBlockIndex.java b/sonar-batch/src/main/java/org/sonar/batch/cpd/index/SonarCpdBlockIndex.java deleted file mode 100644 index 48ee611ffaf..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/cpd/index/SonarCpdBlockIndex.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.cpd.index; - -import com.google.common.base.Function; -import com.google.common.collect.Iterables; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; -import org.apache.commons.lang.StringUtils; -import org.sonar.api.CoreProperties; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.config.Settings; -import org.sonar.batch.index.BatchComponentCache; -import org.sonar.batch.protocol.output.BatchReport; -import org.sonar.batch.report.ReportPublisher; -import org.sonar.duplications.block.Block; -import org.sonar.duplications.block.ByteArray; -import org.sonar.duplications.index.AbstractCloneIndex; -import org.sonar.duplications.index.CloneIndex; -import org.sonar.duplications.index.PackedMemoryCloneIndex; -import org.sonar.duplications.index.PackedMemoryCloneIndex.ResourceBlocks; - -public class SonarCpdBlockIndex extends AbstractCloneIndex { - - private final CloneIndex mem = new PackedMemoryCloneIndex(); - private final ReportPublisher publisher; - private final BatchComponentCache batchComponentCache; - private final Settings settings; - // Files already tokenized - private final Set indexedFiles = new HashSet<>(); - - public SonarCpdBlockIndex(ReportPublisher publisher, BatchComponentCache batchComponentCache, Settings settings) { - this.publisher = publisher; - this.batchComponentCache = batchComponentCache; - this.settings = settings; - } - - public void insert(InputFile inputFile, Collection blocks) { - if (isCrossProjectDuplicationEnabled(settings)) { - int id = batchComponentCache.get(inputFile).batchId(); - final BatchReport.CpdTextBlock.Builder builder = BatchReport.CpdTextBlock.newBuilder(); - publisher.getWriter().writeCpdTextBlocks(id, Iterables.transform(blocks, new Function() { - @Override - public BatchReport.CpdTextBlock apply(Block input) { - builder.clear(); - builder.setStartLine(input.getStartLine()); - builder.setEndLine(input.getEndLine()); - builder.setStartTokenIndex(input.getStartUnit()); - builder.setEndTokenIndex(input.getEndUnit()); - builder.setHash(input.getBlockHash().toHexString()); - return builder.build(); - } - })); - } - for (Block block : blocks) { - mem.insert(block); - } - indexedFiles.add(inputFile); - } - - public boolean isIndexed(InputFile inputFile) { - return indexedFiles.contains(inputFile); - } - - public static boolean isCrossProjectDuplicationEnabled(Settings settings) { - return settings.getBoolean(CoreProperties.CPD_CROSS_PROJECT) - // No cross project duplication for branches - && StringUtils.isBlank(settings.getString(CoreProperties.PROJECT_BRANCH_PROPERTY)); - } - - public Collection getByInputFile(String resourceKey) { - return mem.getByResourceId(resourceKey); - } - - @Override - public Collection getBySequenceHash(ByteArray hash) { - return mem.getBySequenceHash(hash); - } - - @Override - public Collection getByResourceId(String resourceId) { - throw new UnsupportedOperationException(); - } - - @Override - public void insert(Block block) { - throw new UnsupportedOperationException(); - } - - @Override - public Iterator iterator() { - return mem.iterator(); - } - - @Override - public int noResources() { - return mem.noResources(); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/cpd/index/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/cpd/index/package-info.java deleted file mode 100644 index 86431b3a529..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/cpd/index/package-info.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.batch.cpd.index; - -import javax.annotation.ParametersAreNonnullByDefault; - diff --git a/sonar-batch/src/main/java/org/sonar/batch/cpd/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/cpd/package-info.java deleted file mode 100644 index c4205b6d38e..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/cpd/package-info.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.batch.cpd; - -import javax.annotation.ParametersAreNonnullByDefault; - diff --git a/sonar-batch/src/main/java/org/sonar/batch/deprecated/DeprecatedSensorContext.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/DeprecatedSensorContext.java deleted file mode 100644 index 33a56f3e5ee..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/deprecated/DeprecatedSensorContext.java +++ /dev/null @@ -1,221 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.deprecated; - -import java.io.Serializable; -import java.util.Collection; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.batch.AnalysisMode; -import org.sonar.api.batch.SensorContext; -import org.sonar.api.batch.SonarIndex; -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.InputModule; -import org.sonar.api.batch.fs.InputPath; -import org.sonar.api.batch.rule.ActiveRules; -import org.sonar.api.batch.sensor.internal.SensorStorage; -import org.sonar.api.config.Settings; -import org.sonar.api.design.Dependency; -import org.sonar.api.measures.Measure; -import org.sonar.api.measures.MeasuresFilter; -import org.sonar.api.measures.Metric; -import org.sonar.api.resources.Directory; -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.sensor.DefaultSensorContext; -import org.sonar.batch.sensor.coverage.CoverageExclusions; - -public class DeprecatedSensorContext extends DefaultSensorContext implements SensorContext { - - private static final Logger LOG = LoggerFactory.getLogger(DeprecatedSensorContext.class); - - private final SonarIndex index; - private final Project project; - private final CoverageExclusions coverageFilter; - - public DeprecatedSensorContext(InputModule module, SonarIndex index, Project project, Settings settings, FileSystem fs, ActiveRules activeRules, - AnalysisMode analysisMode, CoverageExclusions coverageFilter, - SensorStorage sensorStorage) { - super(module, settings, fs, activeRules, analysisMode, sensorStorage); - this.index = index; - this.project = project; - this.coverageFilter = coverageFilter; - - } - - public Project getProject() { - return project; - } - - @Override - public boolean index(Resource resource) { - // SONAR-5006 - logWarning(); - return true; - } - - @Override - public boolean index(Resource resource, Resource parentReference) { - // SONAR-5006 - logWarning(); - return true; - } - - private static void logWarning() { - if (LOG.isDebugEnabled()) { - LOG.debug("Plugins are no more responsible for indexing physical resources like directories and files. This is now handled by the platform.", new SonarException( - "Plugin should not index physical resources")); - } - } - - @Override - public boolean isExcluded(Resource reference) { - return index.isExcluded(reference); - } - - @Override - public boolean isIndexed(Resource reference, boolean acceptExcluded) { - return index.isIndexed(reference, acceptExcluded); - } - - @Override - public Resource getParent(Resource reference) { - return index.getParent(reference); - } - - @Override - public Collection getChildren(Resource reference) { - return index.getChildren(reference); - } - - @Override - public Measure getMeasure(Metric metric) { - return index.getMeasure(project, metric); - } - - @Override - public M getMeasures(MeasuresFilter filter) { - return index.getMeasures(project, filter); - } - - @Override - public Measure saveMeasure(Measure measure) { - return index.addMeasure(project, measure); - } - - @Override - public Measure saveMeasure(Metric metric, Double value) { - return index.addMeasure(project, new Measure(metric, value)); - } - - @Override - public Measure getMeasure(Resource resource, Metric metric) { - return index.getMeasure(resource, metric); - } - - @Override - public String saveResource(Resource resource) { - Resource persistedResource = index.addResource(resource); - if (persistedResource != null) { - return persistedResource.getEffectiveKey(); - } - return null; - } - - public boolean saveResource(Resource resource, Resource parentReference) { - return index.index(resource, parentReference); - } - - @Override - public Resource getResource(Resource resource) { - return index.getResource(resource); - } - - @Override - public M getMeasures(Resource resource, MeasuresFilter filter) { - return index.getMeasures(resource, filter); - } - - @Override - public Measure saveMeasure(Resource resource, Metric metric, Double value) { - Measure measure = new Measure(metric, value); - coverageFilter.validate(measure, resource.getPath()); - return saveMeasure(resource, measure); - } - - @Override - public Measure saveMeasure(Resource resource, Measure measure) { - Resource resourceOrProject = resourceOrProject(resource); - - if (coverageFilter.accept(resourceOrProject, measure)) { - return index.addMeasure(resourceOrProject, measure); - } else { - return measure; - } - } - - @Override - public Dependency saveDependency(Dependency dependency) { - return null; - } - - @Override - public void saveSource(Resource reference, String source) { - // useless since 4.2. - } - - private Resource resourceOrProject(Resource resource) { - if (resource == null) { - return project; - } - Resource indexedResource = getResource(resource); - return indexedResource != null ? indexedResource : resource; - } - - @Override - public Measure saveMeasure(InputFile inputFile, Metric metric, Double value) { - Measure measure = new Measure(metric, value); - coverageFilter.validate(measure, inputFile); - return saveMeasure(getResource(inputFile), measure); - } - - @Override - public Measure saveMeasure(InputFile inputFile, Measure measure) { - coverageFilter.validate(measure, inputFile); - return saveMeasure(getResource(inputFile), measure); - } - - @Override - public Resource getResource(InputPath inputPath) { - Resource r; - if (inputPath instanceof InputDir) { - r = Directory.create(((InputDir) inputPath).relativePath()); - } else if (inputPath instanceof InputFile) { - r = File.create(((InputFile) inputPath).relativePath()); - } else { - throw new IllegalArgumentException("Unknow input path type: " + inputPath); - } - return getResource(r); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/deprecated/InputFileComponent.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/InputFileComponent.java deleted file mode 100644 index e8dcc72cb32..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/deprecated/InputFileComponent.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.deprecated; - -import org.sonar.api.batch.fs.InputFile.Type; -import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.component.Component; -import org.sonar.api.resources.Qualifiers; - -public class InputFileComponent implements Component { - - private final DefaultInputFile inputFile; - - public InputFileComponent(DefaultInputFile inputFile) { - this.inputFile = inputFile; - } - - @Override - public String key() { - return inputFile.key(); - } - - @Override - public String path() { - return inputFile.relativePath(); - } - - @Override - public String name() { - return inputFile.file().getName(); - } - - @Override - public String longName() { - return inputFile.relativePath(); - } - - @Override - public String qualifier() { - return inputFile.type() == Type.MAIN ? Qualifiers.FILE : Qualifiers.UNIT_TEST_FILE; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/deprecated/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/package-info.java deleted file mode 100644 index 9ec5890816a..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/deprecated/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.batch.deprecated; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/BatchPerspectives.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/BatchPerspectives.java deleted file mode 100644 index ebc8465b0d3..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/BatchPerspectives.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.deprecated.perspectives; - -import com.google.common.collect.Maps; -import java.util.Map; -import javax.annotation.CheckForNull; -import org.sonar.api.batch.SonarIndex; -import org.sonar.api.batch.fs.InputPath; -import org.sonar.api.component.Perspective; -import org.sonar.api.component.ResourcePerspectives; -import org.sonar.api.resources.Resource; -import org.sonar.batch.index.BatchComponentCache; - -public class BatchPerspectives implements ResourcePerspectives { - - private final Map, PerspectiveBuilder> builders = Maps.newHashMap(); - private final SonarIndex resourceIndex; - private final BatchComponentCache componentCache; - - public BatchPerspectives(PerspectiveBuilder[] builders, SonarIndex resourceIndex, BatchComponentCache componentCache) { - this.resourceIndex = resourceIndex; - this.componentCache = componentCache; - for (PerspectiveBuilder builder : builders) { - this.builders.put(builder.getPerspectiveClass(), builder); - } - } - - @Override - @CheckForNull - public

P as(Class

perspectiveClass, Resource resource) { - Resource indexedResource = resource; - if (resource.getEffectiveKey() == null) { - indexedResource = resourceIndex.getResource(resource); - } - if (indexedResource != null) { - PerspectiveBuilder

builder = builderFor(perspectiveClass); - return builder.loadPerspective(perspectiveClass, componentCache.get(indexedResource)); - } - return null; - } - - @Override - public

P as(Class

perspectiveClass, InputPath inputPath) { - PerspectiveBuilder

builder = builderFor(perspectiveClass); - return builder.loadPerspective(perspectiveClass, componentCache.get(inputPath)); - } - - private PerspectiveBuilder builderFor(Class clazz) { - PerspectiveBuilder builder = (PerspectiveBuilder) builders.get(clazz); - if (builder == null) { - throw new PerspectiveNotFoundException("Perspective class is not registered: " + clazz); - } - return builder; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/PerspectiveBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/PerspectiveBuilder.java deleted file mode 100644 index 0f38dc2ed41..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/PerspectiveBuilder.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.deprecated.perspectives; - -import javax.annotation.CheckForNull; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.component.Perspective; -import org.sonar.batch.index.BatchComponent; - -@BatchSide -public abstract class PerspectiveBuilder { - - private final Class perspectiveClass; - - protected PerspectiveBuilder(Class perspectiveClass) { - this.perspectiveClass = perspectiveClass; - } - - public Class getPerspectiveClass() { - return perspectiveClass; - } - - @CheckForNull - public abstract T loadPerspective(Class perspectiveClass, BatchComponent component); -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/PerspectiveNotFoundException.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/PerspectiveNotFoundException.java deleted file mode 100644 index 76dcaf532eb..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/PerspectiveNotFoundException.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.deprecated.perspectives; - -public class PerspectiveNotFoundException extends RuntimeException { - public PerspectiveNotFoundException(String message) { - super(message); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/package-info.java deleted file mode 100644 index 1496e020dd6..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/deprecated/perspectives/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.batch.deprecated.perspectives; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-batch/src/main/java/org/sonar/batch/events/BatchEvent.java b/sonar-batch/src/main/java/org/sonar/batch/events/BatchEvent.java deleted file mode 100644 index f168bb4cd7e..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/events/BatchEvent.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.events; - -import org.sonar.api.batch.events.EventHandler; - -/** - * Root of all Sonar Batch events. - * - * @param handler type - */ -public abstract class BatchEvent { - - protected BatchEvent() { - } - - /** - * Do not call directly - should be called only by {@link EventBus}. - * Typically should be implemented as following: handler.onEvent(this) - */ - protected abstract void dispatch(H handler); - - /** - * Returns class of associated handler. Used by {@link EventBus} to dispatch events to the correct handlers. - */ - protected abstract Class getType(); - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/events/BatchStepEvent.java b/sonar-batch/src/main/java/org/sonar/batch/events/BatchStepEvent.java deleted file mode 100644 index cfa628edbf0..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/events/BatchStepEvent.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.events; - -import org.sonar.batch.phases.AbstractPhaseEvent; - -/** - * Generic event for some steps of project scan. - * @since 3.7 - * - */ -public class BatchStepEvent extends AbstractPhaseEvent - implements BatchStepHandler.BatchStepEvent { - - private String stepName; - - public BatchStepEvent(String stepName, boolean start) { - super(start); - this.stepName = stepName; - } - - @Override - public String stepName() { - return stepName; - } - - @Override - protected void dispatch(BatchStepHandler handler) { - handler.onBatchStep(this); - } - - @Override - protected Class getType() { - return BatchStepHandler.class; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/events/BatchStepHandler.java b/sonar-batch/src/main/java/org/sonar/batch/events/BatchStepHandler.java deleted file mode 100644 index 9d2cc5e54ba..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/events/BatchStepHandler.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.events; - -import org.sonar.api.batch.events.EventHandler; - -/** - * @since 3.7 - */ -public interface BatchStepHandler extends EventHandler { - - /** - * This interface is not intended to be implemented by clients. - */ - interface BatchStepEvent { - - String stepName(); - - boolean isStart(); - - boolean isEnd(); - - } - - /** - * Called before and after execution of each final step of project analysis - */ - void onBatchStep(BatchStepEvent event); - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/events/EventBus.java b/sonar-batch/src/main/java/org/sonar/batch/events/EventBus.java deleted file mode 100644 index 4b1629f1444..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/events/EventBus.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.events; - -import com.google.common.collect.Lists; -import org.sonar.api.batch.events.EventHandler; - -import java.util.List; - -/** - * Dispatches {@link BatchEvent}s. Eases decoupling by allowing objects to interact without having direct dependencies upon one another, and - * without requiring event sources to deal with maintaining handler lists. - */ -public class EventBus { - - private EventHandler[] registeredHandlers; - - public EventBus(EventHandler[] handlers) { - this.registeredHandlers = handlers; - } - - /** - * Fires the given event. - */ - public void fireEvent(BatchEvent event) { - doFireEvent(event); - } - - private void doFireEvent(BatchEvent event) { - List handlers = getDispatchList(event.getType()); - for (EventHandler handler : handlers) { - event.dispatch(handler); - } - } - - private List getDispatchList(Class handlerType) { - List result = Lists.newArrayList(); - for (EventHandler handler : registeredHandlers) { - if (handlerType.isAssignableFrom(handler.getClass())) { - result.add(handler); - } - } - return result; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/events/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/events/package-info.java deleted file mode 100644 index 922fe861be7..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/events/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.batch.events; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/BatchComponent.java b/sonar-batch/src/main/java/org/sonar/batch/index/BatchComponent.java deleted file mode 100644 index 9690c833b1e..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/index/BatchComponent.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.index; - -import java.util.ArrayList; -import java.util.Collection; -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; -import org.sonar.api.batch.fs.InputComponent; -import org.sonar.api.resources.Resource; -import org.sonar.api.resources.ResourceUtils; - -public class BatchComponent { - - private final int batchId; - private final Resource r; - private final BatchComponent parent; - private final Collection children = new ArrayList<>(); - private InputComponent inputComponent; - - public BatchComponent(int batchId, Resource r, @Nullable BatchComponent parent) { - this.batchId = batchId; - this.r = r; - this.parent = parent; - if (parent != null) { - parent.children.add(this); - } - } - - public String key() { - return r.getEffectiveKey(); - } - - public int batchId() { - return batchId; - } - - public Resource resource() { - return r; - } - - @CheckForNull - public BatchComponent parent() { - return parent; - } - - public Collection children() { - return children; - } - - public boolean isFile() { - return this.inputComponent.isFile(); - } - - public BatchComponent setInputComponent(InputComponent inputComponent) { - this.inputComponent = inputComponent; - return this; - } - - public InputComponent inputComponent() { - return inputComponent; - } - - public boolean isProjectOrModule() { - return ResourceUtils.isProject(r); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/BatchComponentCache.java b/sonar-batch/src/main/java/org/sonar/batch/index/BatchComponentCache.java deleted file mode 100644 index 68c29f69c95..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/index/BatchComponentCache.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.index; - -import com.google.common.base.Preconditions; -import com.google.common.base.Strings; -import com.google.common.collect.Maps; -import java.util.Collection; -import java.util.Map; -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.batch.fs.InputComponent; -import org.sonar.api.resources.Resource; - -@BatchSide -public class BatchComponentCache { - // components by key - private final Map components = Maps.newLinkedHashMap(); - - private BatchComponent root; - - @CheckForNull - public BatchComponent get(String componentKey) { - return components.get(componentKey); - } - - public BatchComponent get(Resource resource) { - return components.get(resource.getEffectiveKey()); - } - - public BatchComponent get(InputComponent inputComponent) { - return components.get(inputComponent.key()); - } - - public BatchComponent add(Resource resource, @Nullable Resource parentResource) { - String componentKey = resource.getEffectiveKey(); - Preconditions.checkState(!Strings.isNullOrEmpty(componentKey), "Missing resource effective key"); - BatchComponent parent = parentResource != null ? get(parentResource.getEffectiveKey()) : null; - BatchComponent batchComponent = new BatchComponent(components.size() + 1, resource, parent); - components.put(componentKey, batchComponent); - if (parent == null) { - root = batchComponent; - } - return batchComponent; - } - - public Collection all() { - return components.values(); - } - - public BatchComponent getRoot() { - return root; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/Bucket.java b/sonar-batch/src/main/java/org/sonar/batch/index/Bucket.java deleted file mode 100644 index 5fde268c097..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/index/Bucket.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.index; - -import com.google.common.collect.Lists; -import org.sonar.api.resources.Resource; - -import javax.annotation.Nullable; - -import java.util.Collections; -import java.util.List; - -public final class Bucket { - - private Resource resource; - - private Bucket parent; - private List children; - - public Bucket(Resource resource) { - this.resource = resource; - } - - public Resource getResource() { - return resource; - } - - public Bucket setParent(@Nullable Bucket parent) { - this.parent = parent; - if (parent != null) { - parent.addChild(this); - } - return this; - } - - private Bucket addChild(Bucket child) { - if (children == null) { - children = Lists.newArrayList(); - } - children.add(child); - return this; - } - - private void removeChild(Bucket child) { - if (children != null) { - children.remove(child); - } - } - - public List getChildren() { - return children == null ? Collections.emptyList() : children; - } - - public Bucket getParent() { - return parent; - } - - public void clear() { - children = null; - if (parent != null) { - parent.removeChild(this); - parent = null; - } - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - Bucket that = (Bucket) o; - return resource.equals(that.resource); - } - - @Override - public int hashCode() { - return resource.hashCode(); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/Cache.java b/sonar-batch/src/main/java/org/sonar/batch/index/Cache.java deleted file mode 100644 index ad194c3aad0..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/index/Cache.java +++ /dev/null @@ -1,505 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.index; - -import com.google.common.collect.Sets; -import com.persistit.Exchange; -import com.persistit.Key; -import com.persistit.KeyFilter; -import com.persistit.exception.PersistitException; -import org.apache.commons.lang.builder.ToStringBuilder; - -import javax.annotation.CheckForNull; - -import java.util.Iterator; -import java.util.NoSuchElementException; -import java.util.Set; - -/** - *

- * This cache is not thread-safe, due to direct usage of {@link com.persistit.Exchange} - *

- */ -public class Cache { - - private final String name; - private final Exchange exchange; - - Cache(String name, Exchange exchange) { - this.name = name; - this.exchange = exchange; - } - - public Cache put(Object key, V value) { - resetKey(key); - return doPut(value); - } - - public Cache put(Object firstKey, Object secondKey, V value) { - resetKey(firstKey, secondKey); - return doPut(value); - } - - public Cache put(Object firstKey, Object secondKey, Object thirdKey, V value) { - resetKey(firstKey, secondKey, thirdKey); - return doPut(value); - } - - public Cache put(Object[] key, V value) { - resetKey(key); - return doPut(value); - } - - private Cache doPut(V value) { - try { - exchange.getValue().put(value); - exchange.store(); - return this; - } catch (Exception e) { - throw new IllegalStateException("Fail to put element in the cache " + name, e); - } - } - - /** - * Returns the value object associated with keys, or null if not found. - */ - public V get(Object key) { - resetKey(key); - return doGet(); - } - - /** - * Returns the value object associated with keys, or null if not found. - */ - @CheckForNull - public V get(Object firstKey, Object secondKey) { - resetKey(firstKey, secondKey); - return doGet(); - } - - /** - * Returns the value object associated with keys, or null if not found. - */ - @CheckForNull - public V get(Object firstKey, Object secondKey, Object thirdKey) { - resetKey(firstKey, secondKey, thirdKey); - return doGet(); - } - - /** - * Returns the value object associated with keys, or null if not found. - */ - @CheckForNull - public V get(Object[] key) { - resetKey(key); - return doGet(); - } - - @SuppressWarnings("unchecked") - @CheckForNull - private V doGet() { - try { - exchange.fetch(); - if (!exchange.getValue().isDefined()) { - return null; - } - return (V) exchange.getValue().get(); - } catch (Exception e) { - // TODO add parameters to message - throw new IllegalStateException("Fail to get element from cache " + name, e); - } - } - - public boolean containsKey(Object key) { - resetKey(key); - return doContainsKey(); - } - - public boolean containsKey(Object firstKey, Object secondKey) { - resetKey(firstKey, secondKey); - return doContainsKey(); - } - - public boolean containsKey(Object firstKey, Object secondKey, Object thirdKey) { - resetKey(firstKey, secondKey, thirdKey); - return doContainsKey(); - } - - public boolean containsKey(Object[] key) { - resetKey(key); - return doContainsKey(); - } - - private boolean doContainsKey() { - try { - exchange.fetch(); - return exchange.isValueDefined(); - } catch (Exception e) { - // TODO add parameters to message - throw new IllegalStateException("Fail to check if element is in cache " + name, e); - } - } - - public boolean remove(Object key) { - resetKey(key); - return doRemove(); - } - - public boolean remove(Object firstKey, Object secondKey) { - resetKey(firstKey, secondKey); - return doRemove(); - } - - public boolean remove(Object firstKey, Object secondKey, Object thirdKey) { - resetKey(firstKey, secondKey, thirdKey); - return doRemove(); - } - - public boolean remove(Object[] key) { - resetKey(key); - return doRemove(); - } - - private boolean doRemove() { - try { - return exchange.remove(); - } catch (Exception e) { - // TODO add parameters to message - throw new IllegalStateException("Fail to get element from cache " + name, e); - } - } - - /** - * Removes everything in the specified group. - * - * @param group The group name. - */ - public Cache clear(Object key) { - resetKey(key); - return doClear(); - } - - public Cache clear(Object firstKey, Object secondKey) { - resetKey(firstKey, secondKey); - return doClear(); - } - - public Cache clear(Object firstKey, Object secondKey, Object thirdKey) { - resetKey(firstKey, secondKey, thirdKey); - return doClear(); - } - - public Cache clear(Object[] key) { - resetKey(key); - return doClear(); - } - - private Cache doClear() { - try { - Key to = new Key(exchange.getKey()); - to.append(Key.AFTER); - exchange.removeKeyRange(exchange.getKey(), to); - return this; - } catch (Exception e) { - throw new IllegalStateException("Fail to clear values from cache " + name, e); - } - } - - /** - * Clears the default as well as all group caches. - */ - public void clear() { - try { - exchange.clear(); - exchange.removeAll(); - } catch (Exception e) { - throw new IllegalStateException("Fail to clear cache", e); - } - } - - /** - * Returns the set of cache keys associated with this group. - * TODO implement a lazy-loading equivalent with Iterator/Iterable - * - * @param group The group. - * @return The set of cache keys for this group. - */ - @SuppressWarnings("rawtypes") - public Set keySet(Object key) { - try { - Set keys = Sets.newLinkedHashSet(); - exchange.clear(); - Exchange iteratorExchange = new Exchange(exchange); - iteratorExchange.append(key); - iteratorExchange.append(Key.BEFORE); - while (iteratorExchange.next(false)) { - keys.add(iteratorExchange.getKey().indexTo(-1).decode()); - } - return keys; - } catch (Exception e) { - throw new IllegalStateException("Fail to get keys from cache " + name, e); - } - } - - @SuppressWarnings("rawtypes") - public Set keySet(Object firstKey, Object secondKey) { - try { - Set keys = Sets.newLinkedHashSet(); - exchange.clear(); - Exchange iteratorExchange = new Exchange(exchange); - iteratorExchange.append(firstKey); - iteratorExchange.append(secondKey); - iteratorExchange.append(Key.BEFORE); - while (iteratorExchange.next(false)) { - keys.add(iteratorExchange.getKey().indexTo(-1).decode()); - } - return keys; - } catch (Exception e) { - throw new IllegalStateException("Fail to get keys from cache " + name, e); - } - } - - /** - * Returns the set of keys associated with this cache. - * - * @return The set containing the keys for this cache. - */ - public Set keySet() { - try { - Set keys = Sets.newLinkedHashSet(); - exchange.clear(); - Exchange iteratorExchange = new Exchange(exchange); - iteratorExchange.append(Key.BEFORE); - while (iteratorExchange.next(false)) { - keys.add(iteratorExchange.getKey().indexTo(-1).decode()); - } - return keys; - } catch (Exception e) { - throw new IllegalStateException("Fail to get keys from cache " + name, e); - } - } - - /** - * Lazy-loading values for given keys - */ - public Iterable values(Object firstKey, Object secondKey) { - return new ValueIterable<>(exchange, firstKey, secondKey); - } - - /** - * Lazy-loading values for a given key - */ - public Iterable values(Object firstKey) { - return new ValueIterable<>(exchange, firstKey); - } - - /** - * Lazy-loading values - */ - public Iterable values() { - return new ValueIterable<>(exchange); - } - - public Iterable> entries() { - return new EntryIterable<>(exchange); - } - - public Iterable> entries(Object firstKey) { - return new EntryIterable<>(exchange, firstKey); - } - - private void resetKey(Object key) { - exchange.clear(); - exchange.append(key); - } - - private void resetKey(Object first, Object second) { - exchange.clear(); - exchange.append(first).append(second); - } - - private void resetKey(Object first, Object second, Object third) { - exchange.clear(); - exchange.append(first).append(second).append(third); - } - - private void resetKey(Object[] keys) { - exchange.clear(); - for (Object o : keys) { - exchange.append(o); - } - } - - // - // LAZY ITERATORS AND ITERABLES - // - - private static class ValueIterable implements Iterable { - private final Exchange originExchange; - private final Object[] keys; - - private ValueIterable(Exchange originExchange, Object... keys) { - this.originExchange = originExchange; - this.keys = keys; - } - - @Override - public Iterator iterator() { - originExchange.clear(); - KeyFilter filter = new KeyFilter(); - for (Object key : keys) { - originExchange.append(key); - filter = filter.append(KeyFilter.simpleTerm(key)); - } - originExchange.append(Key.BEFORE); - Exchange iteratorExchange = new Exchange(originExchange); - return new ValueIterator<>(iteratorExchange, filter); - } - } - - private static class ValueIterator implements Iterator { - private final Exchange exchange; - private final KeyFilter keyFilter; - - private ValueIterator(Exchange exchange, KeyFilter keyFilter) { - this.exchange = exchange; - this.keyFilter = keyFilter; - } - - @Override - public boolean hasNext() { - try { - return exchange.hasNext(keyFilter); - } catch (PersistitException e) { - throw new IllegalStateException(e); - } - } - - @SuppressWarnings("unchecked") - @Override - public T next() { - try { - exchange.next(keyFilter); - } catch (PersistitException e) { - throw new IllegalStateException(e); - } - if (exchange.getValue().isDefined()) { - return (T) exchange.getValue().get(); - } - throw new NoSuchElementException(); - } - - @Override - public void remove() { - throw new UnsupportedOperationException("Removing an item is not supported"); - } - } - - private static class EntryIterable implements Iterable> { - private final Exchange originExchange; - private final Object[] keys; - - private EntryIterable(Exchange originExchange, Object... keys) { - this.originExchange = originExchange; - this.keys = keys; - } - - @Override - public Iterator> iterator() { - originExchange.clear(); - KeyFilter filter = new KeyFilter(); - for (Object key : keys) { - originExchange.append(key); - filter = filter.append(KeyFilter.simpleTerm(key)); - } - originExchange.append(Key.BEFORE); - Exchange iteratorExchange = new Exchange(originExchange); - return new EntryIterator<>(iteratorExchange, filter); - } - } - - private static class EntryIterator implements Iterator> { - private final Exchange exchange; - private final KeyFilter keyFilter; - - private EntryIterator(Exchange exchange, KeyFilter keyFilter) { - this.exchange = exchange; - this.keyFilter = keyFilter; - } - - @Override - public boolean hasNext() { - try { - return exchange.hasNext(keyFilter); - } catch (PersistitException e) { - throw new IllegalStateException(e); - } - } - - @SuppressWarnings("unchecked") - @Override - public Entry next() { - try { - exchange.next(keyFilter); - } catch (PersistitException e) { - throw new IllegalStateException(e); - } - if (exchange.getValue().isDefined()) { - T value = (T) exchange.getValue().get(); - Key key = exchange.getKey(); - Object[] array = new Object[key.getDepth()]; - for (int i = 0; i < key.getDepth(); i++) { - array[i] = key.indexTo(i - key.getDepth()).decode(); - } - return new Entry<>(array, value); - } - throw new NoSuchElementException(); - } - - @Override - public void remove() { - throw new UnsupportedOperationException("Removing an item is not supported"); - } - } - - public static class Entry { - private final Object[] key; - private final V value; - - Entry(Object[] key, V value) { - this.key = key; - this.value = value; - } - - public Object[] key() { - return key; - } - - public V value() { - return value; - } - - @Override - public String toString() { - return ToStringBuilder.reflectionToString(this); - } - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/Caches.java b/sonar-batch/src/main/java/org/sonar/batch/index/Caches.java deleted file mode 100644 index ddddb271dfd..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/index/Caches.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.index; - -import com.google.common.collect.Maps; - -import java.util.Map; -import java.util.Map.Entry; - -import com.google.common.base.Preconditions; -import com.persistit.Exchange; -import com.persistit.Value; -import com.persistit.encoding.CoderManager; -import com.persistit.Persistit; -import com.persistit.encoding.ValueCoder; -import com.persistit.exception.PersistitException; -import com.persistit.Volume; -import org.picocontainer.Startable; -import org.sonar.api.batch.BatchSide; - -@BatchSide -public class Caches implements Startable { - private final Map cacheMap = Maps.newHashMap(); - private Persistit persistit; - private Volume volume; - - public Caches(CachesManager caches) { - persistit = caches.persistit(); - doStart(); - } - - @Override - public void start() { - // done in constructor - } - - private void doStart() { - try { - persistit.flush(); - volume = persistit.createTemporaryVolume(); - } catch (Exception e) { - throw new IllegalStateException("Fail to create a cache volume", e); - } - } - - public void registerValueCoder(Class clazz, ValueCoder coder) { - CoderManager cm = persistit.getCoderManager(); - cm.registerValueCoder(clazz, coder); - } - - public Cache createCache(String cacheName) { - Preconditions.checkState(volume != null && volume.isOpened(), "Caches are not initialized"); - Preconditions.checkState(!cacheMap.containsKey(cacheName), "Cache is already created: " + cacheName); - try { - Exchange exchange = persistit.getExchange(volume, cacheName, true); - exchange.setMaximumValueSize(Value.MAXIMUM_SIZE); - Cache cache = new Cache<>(cacheName, exchange); - cacheMap.put(cacheName, exchange); - return cache; - } catch (Exception e) { - throw new IllegalStateException("Fail to create cache: " + cacheName, e); - } - } - - @Override - public void stop() { - for (Entry e : cacheMap.entrySet()) { - persistit.releaseExchange(e.getValue()); - } - - cacheMap.clear(); - - if (volume != null) { - try { - volume.close(); - volume.delete(); - } catch (PersistitException e) { - throw new IllegalStateException("Fail to close caches", e); - } - volume = null; - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/CachesManager.java b/sonar-batch/src/main/java/org/sonar/batch/index/CachesManager.java deleted file mode 100644 index 010375a84eb..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/index/CachesManager.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.index; - -import com.persistit.Persistit; -import com.persistit.exception.PersistitException; -import com.persistit.logging.Slf4jAdapter; -import java.io.File; -import java.util.Properties; -import org.picocontainer.Startable; -import org.slf4j.LoggerFactory; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.utils.TempFolder; - -import static org.sonar.core.util.FileUtils.deleteQuietly; - -/** - * Factory of caches - * - * @since 3.6 - */ -@BatchSide -public class CachesManager implements Startable { - private File tempDir; - private Persistit persistit; - private final TempFolder tempFolder; - - public CachesManager(TempFolder tempFolder) { - this.tempFolder = tempFolder; - initPersistit(); - } - - private void initPersistit() { - try { - tempDir = tempFolder.newDir("caches"); - persistit = new Persistit(); - persistit.setPersistitLogger(new Slf4jAdapter(LoggerFactory.getLogger("PERSISTIT"))); - Properties props = new Properties(); - props.setProperty("datapath", tempDir.getAbsolutePath()); - props.setProperty("logpath", "${datapath}/log"); - props.setProperty("logfile", "${logpath}/persistit_${timestamp}.log"); - props.setProperty("buffer.count.8192", "10"); - props.setProperty("journalpath", "${datapath}/journal"); - props.setProperty("tmpvoldir", "${datapath}"); - props.setProperty("volume.1", "${datapath}/persistit,create,pageSize:8192,initialPages:10,extensionPages:100,maximumPages:25000"); - props.setProperty("jmx", "false"); - persistit.setProperties(props); - persistit.initialize(); - - } catch (Exception e) { - throw new IllegalStateException("Fail to start caches", e); - } - } - - @Override - public void start() { - // already started in constructor - } - - @Override - public void stop() { - if (persistit != null) { - try { - persistit.close(false); - persistit = null; - } catch (PersistitException e) { - throw new IllegalStateException("Fail to close caches", e); - } - } - deleteQuietly(tempDir); - tempDir = null; - } - - File tempDir() { - return tempDir; - } - - Persistit persistit() { - return persistit; - } -} 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 deleted file mode 100644 index d5f1a561729..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java +++ /dev/null @@ -1,353 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.index; - -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang.ObjectUtils; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.batch.SonarIndex; -import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.api.batch.fs.internal.DefaultInputModule; -import org.sonar.api.design.Dependency; -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.Qualifiers; -import org.sonar.api.resources.Resource; -import org.sonar.api.resources.ResourceUtils; -import org.sonar.api.scan.filesystem.PathResolver; -import org.sonar.batch.DefaultProjectTree; -import org.sonar.batch.scan.measure.MeasureCache; -import org.sonar.batch.sensor.DefaultSensorStorage; -import org.sonar.core.component.ComponentKeys; - -public class DefaultIndex extends SonarIndex { - - private static final Logger LOG = LoggerFactory.getLogger(DefaultIndex.class); - - private final BatchComponentCache componentCache; - private final MeasureCache measureCache; - private final PathResolver pathResolver; - private final DefaultProjectTree projectTree; - // caches - private DefaultSensorStorage sensorStorage; - private Project currentProject; - private Map buckets = Maps.newLinkedHashMap(); - - public DefaultIndex(BatchComponentCache componentCache, DefaultProjectTree projectTree, MeasureCache measureCache, PathResolver pathResolver) { - this.componentCache = componentCache; - this.projectTree = projectTree; - this.measureCache = measureCache; - this.pathResolver = pathResolver; - } - - public void start() { - Project rootProject = projectTree.getRootProject(); - if (StringUtils.isNotBlank(rootProject.getKey())) { - doStart(rootProject); - } - } - - void doStart(Project rootProject) { - Bucket bucket = new Bucket(rootProject); - addBucket(rootProject, bucket); - BatchComponent component = componentCache.add(rootProject, null); - component.setInputComponent(new DefaultInputModule(rootProject.getEffectiveKey())); - currentProject = rootProject; - - for (Project module : rootProject.getModules()) { - addModule(rootProject, module); - } - } - - private void addBucket(Resource resource, Bucket bucket) { - buckets.put(resource, bucket); - } - - private void addModule(Project parent, Project module) { - ProjectDefinition parentDefinition = projectTree.getProjectDefinition(parent); - java.io.File parentBaseDir = parentDefinition.getBaseDir(); - ProjectDefinition moduleDefinition = projectTree.getProjectDefinition(module); - java.io.File moduleBaseDir = moduleDefinition.getBaseDir(); - module.setPath(new PathResolver().relativePath(parentBaseDir, moduleBaseDir)); - addResource(module); - for (Project submodule : module.getModules()) { - addModule(module, submodule); - } - } - - @Override - public Project getProject() { - return currentProject; - } - - public void setCurrentProject(Project project, DefaultSensorStorage sensorStorage) { - this.currentProject = project; - - // the following components depend on the current module, so they need to be reloaded. - this.sensorStorage = sensorStorage; - } - - /** - * Keep only project stuff - */ - public void clear() { - Iterator> it = buckets.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry entry = it.next(); - Resource resource = entry.getKey(); - if (!ResourceUtils.isSet(resource)) { - entry.getValue().clear(); - it.remove(); - } - - } - } - - @CheckForNull - @Override - public Measure getMeasure(Resource resource, org.sonar.api.batch.measure.Metric metric) { - return getMeasures(resource, MeasuresFilters.metric(metric)); - } - - @CheckForNull - @Override - public M getMeasures(Resource resource, MeasuresFilter filter) { - // Reload resource so that effective key is populated - Resource indexedResource = getResource(resource); - if (indexedResource == null) { - return null; - } - Collection unfiltered = new ArrayList<>(); - if (filter instanceof MeasuresFilters.MetricFilter) { - // optimization - Measure byMetric = measureCache.byMetric(indexedResource, ((MeasuresFilters.MetricFilter) filter).filterOnMetricKey()); - if (byMetric != null) { - unfiltered.add(byMetric); - } - } else { - for (Measure measure : measureCache.byResource(indexedResource)) { - unfiltered.add(measure); - } - } - return filter.filter(unfiltered); - } - - @Override - public Measure addMeasure(Resource resource, Measure measure) { - Bucket bucket = getBucket(resource); - if (bucket != null) { - return sensorStorage.saveMeasure(resource, measure); - } - return measure; - } - - @Override - public Dependency addDependency(Dependency dependency) { - return dependency; - } - - @Override - public Set getResources() { - return buckets.keySet(); - } - - @Override - public String getSource(Resource reference) { - Resource resource = getResource(reference); - if (resource instanceof File) { - File file = (File) resource; - Project module = currentProject; - ProjectDefinition def = projectTree.getProjectDefinition(module); - try { - return FileUtils.readFileToString(new java.io.File(def.getBaseDir(), file.getPath())); - } catch (IOException e) { - throw new IllegalStateException("Unable to read file content " + reference, e); - } - } - return null; - } - - /** - * Does nothing if the resource is already registered. - */ - @Override - public Resource addResource(Resource resource) { - Bucket bucket = doIndex(resource); - return bucket != null ? bucket.getResource() : null; - } - - @Override - @CheckForNull - public R getResource(@Nullable R reference) { - Bucket bucket = getBucket(reference); - if (bucket != null) { - return (R) bucket.getResource(); - } - return null; - } - - @Override - public List getChildren(Resource resource) { - List children = Lists.newLinkedList(); - Bucket bucket = getBucket(resource); - if (bucket != null) { - for (Bucket childBucket : bucket.getChildren()) { - children.add(childBucket.getResource()); - } - } - return children; - } - - @Override - public Resource getParent(Resource resource) { - Bucket bucket = getBucket(resource); - if (bucket != null && bucket.getParent() != null) { - return bucket.getParent().getResource(); - } - return null; - } - - @Override - public boolean index(Resource resource) { - Bucket bucket = doIndex(resource); - return bucket != null; - } - - private Bucket doIndex(Resource resource) { - if (resource.getParent() != null) { - doIndex(resource.getParent()); - } - return doIndex(resource, resource.getParent()); - } - - @Override - public boolean index(Resource resource, Resource parentReference) { - Bucket bucket = doIndex(resource, parentReference); - return bucket != null; - } - - private Bucket doIndex(Resource resource, @Nullable Resource parentReference) { - Bucket bucket = getBucket(resource); - if (bucket != null) { - return bucket; - } - - if (StringUtils.isBlank(resource.getKey())) { - LOG.warn("Unable to index a resource without key " + resource); - return null; - } - - Resource parent = (Resource) ObjectUtils.defaultIfNull(parentReference, currentProject); - - Bucket parentBucket = getBucket(parent); - if (parentBucket == null && parent != null) { - LOG.warn("Resource ignored, parent is not indexed: " + resource); - return null; - } - - if (ResourceUtils.isProject(resource) || /* For technical projects */ResourceUtils.isRootProject(resource)) { - resource.setEffectiveKey(resource.getKey()); - } else { - resource.setEffectiveKey(ComponentKeys.createEffectiveKey(currentProject, resource)); - } - bucket = new Bucket(resource).setParent(parentBucket); - addBucket(resource, bucket); - - Resource parentResource = parentBucket != null ? parentBucket.getResource() : null; - BatchComponent component = componentCache.add(resource, parentResource); - if (ResourceUtils.isProject(resource)) { - component.setInputComponent(new DefaultInputModule(resource.getEffectiveKey())); - } - - return bucket; - } - - @Override - public boolean isExcluded(@Nullable Resource reference) { - return false; - } - - @Override - public boolean isIndexed(@Nullable Resource reference, boolean acceptExcluded) { - return getBucket(reference) != null; - } - - private Bucket getBucket(@Nullable Resource reference) { - if (reference == null) { - return null; - } - if (StringUtils.isNotBlank(reference.getKey())) { - return buckets.get(reference); - } - String relativePathFromSourceDir = null; - boolean isTest = false; - boolean isDir = false; - if (reference instanceof File) { - File referenceFile = (File) reference; - isTest = Qualifiers.UNIT_TEST_FILE.equals(referenceFile.getQualifier()); - relativePathFromSourceDir = referenceFile.relativePathFromSourceDir(); - } else if (reference instanceof Directory) { - isDir = true; - Directory referenceDir = (Directory) reference; - relativePathFromSourceDir = referenceDir.relativePathFromSourceDir(); - if (Directory.ROOT.equals(relativePathFromSourceDir)) { - relativePathFromSourceDir = ""; - } - } - if (relativePathFromSourceDir != null) { - // Resolve using deprecated key - List dirs; - ProjectDefinition projectDef = projectTree.getProjectDefinition(getProject()); - if (isTest) { - dirs = projectDef.getTestDirs(); - } else { - dirs = projectDef.getSourceDirs(); - } - for (String src : dirs) { - java.io.File dirOrFile = pathResolver.relativeFile(projectDef.getBaseDir(), src); - java.io.File abs = new java.io.File(dirOrFile, relativePathFromSourceDir); - Bucket b = getBucket(isDir ? Directory.fromIOFile(abs, getProject()) : File.fromIOFile(abs, getProject())); - if (b != null) { - return b; - } - } - - } - return null; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/index/package-info.java deleted file mode 100644 index 6fc80086043..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/index/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.batch.index; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultFilterableIssue.java b/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultFilterableIssue.java deleted file mode 100644 index a7f28e5bfa4..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultFilterableIssue.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue; - -import java.util.Date; -import org.apache.commons.lang.builder.ToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; -import org.sonar.api.resources.Project; -import org.sonar.api.rule.RuleKey; -import org.sonar.api.scan.issue.filter.FilterableIssue; -import org.sonar.batch.protocol.output.BatchReport.Issue; - -public class DefaultFilterableIssue implements FilterableIssue { - private final Issue rawIssue; - private final Project project; - private final String componentKey; - - public DefaultFilterableIssue(Project project, Issue rawIssue, String componentKey) { - this.project = project; - this.rawIssue = rawIssue; - this.componentKey = componentKey; - - } - - @Override - public String componentKey() { - return componentKey; - } - - @Override - public RuleKey ruleKey() { - return RuleKey.of(rawIssue.getRuleRepository(), rawIssue.getRuleKey()); - } - - @Override - public String severity() { - return rawIssue.getSeverity().name(); - } - - @Override - public String message() { - return rawIssue.getMsg(); - } - - @Override - public Integer line() { - return rawIssue.hasLine() ? rawIssue.getLine() : null; - } - - @Override - public Double gap() { - return rawIssue.hasGap() ? rawIssue.getGap() : null; - } - - @Override - public Double effortToFix() { - return gap(); - } - - @Override - public Date creationDate() { - return project.getAnalysisDate(); - } - - @Override - public String projectKey() { - return project.getEffectiveKey(); - } - - @Override - public String toString() { - return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssuable.java b/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssuable.java deleted file mode 100644 index 291fb7bb2ee..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssuable.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue; - -import java.util.Collections; -import java.util.List; -import org.sonar.api.batch.sensor.SensorContext; -import org.sonar.api.batch.sensor.issue.internal.DefaultIssue; -import org.sonar.api.issue.Issuable; -import org.sonar.api.issue.Issue; -import org.sonar.batch.index.BatchComponent; - -/** - * @since 3.6 - */ -public class DefaultIssuable implements Issuable { - - private final BatchComponent component; - private final SensorContext sensorContext; - - DefaultIssuable(BatchComponent component, SensorContext sensorContext) { - this.component = component; - this.sensorContext = sensorContext; - } - - @Override - public IssueBuilder newIssueBuilder() { - DefaultIssue newIssue = (DefaultIssue) sensorContext.newIssue(); - return new DeprecatedIssueBuilderWrapper(component.inputComponent(), newIssue); - } - - @Override - public boolean addIssue(Issue issue) { - ((DeprecatedIssueWrapper) issue).wrapped().save(); - return true; - } - - @Override - public List resolvedIssues() { - return Collections.emptyList(); - } - - @Override - public List issues() { - return Collections.emptyList(); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssueCallback.java b/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssueCallback.java deleted file mode 100644 index e021cc02884..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssueCallback.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue; - -import org.sonar.batch.issue.tracking.TrackedIssue; - -import org.apache.commons.lang.StringUtils; -import org.sonar.api.rule.RuleKey; -import org.sonar.api.batch.rule.Rule; -import org.sonar.api.batch.rule.Rules; -import org.sonar.batch.protocol.input.BatchInput.User; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.sonar.batch.repository.user.UserRepositoryLoader; -import org.sonar.batch.bootstrapper.IssueListener; - -public class DefaultIssueCallback implements IssueCallback { - private final IssueCache issues; - private final IssueListener listener; - private final UserRepositoryLoader userRepository; - private final Rules rules; - - private Set userLoginNames = new HashSet<>(); - private Map userMap = new HashMap<>(); - private Set ruleKeys = new HashSet<>(); - - public DefaultIssueCallback(IssueCache issues, IssueListener listener, UserRepositoryLoader userRepository, Rules rules) { - this.issues = issues; - this.listener = listener; - this.userRepository = userRepository; - this.rules = rules; - } - - /** - * If no listener exists, this constructor will be used by pico. - */ - public DefaultIssueCallback(IssueCache issues, UserRepositoryLoader userRepository, Rules rules) { - this(issues, null, userRepository, rules); - } - - @Override - public void execute() { - if (listener == null) { - return; - } - - for (TrackedIssue issue : issues.all()) { - collectInfo(issue); - } - - getUsers(); - - for (TrackedIssue issue : issues.all()) { - IssueListener.Issue newIssue = new IssueListener.Issue(); - newIssue.setAssigneeLogin(issue.assignee()); - newIssue.setAssigneeName(getAssigneeName(issue.assignee())); - newIssue.setComponentKey(issue.componentKey()); - newIssue.setKey(issue.key()); - newIssue.setMessage(issue.getMessage()); - newIssue.setNew(issue.isNew()); - newIssue.setResolution(issue.resolution()); - newIssue.setRuleKey(issue.getRuleKey().toString()); - newIssue.setRuleName(getRuleName(issue.getRuleKey())); - newIssue.setSeverity(issue.severity()); - newIssue.setStatus(issue.status()); - newIssue.setStartLine(issue.startLine()); - newIssue.setStartLineOffset(issue.startLineOffset()); - newIssue.setEndLine(issue.endLine()); - newIssue.setEndLineOffset(issue.endLineOffset()); - - listener.handle(newIssue); - } - } - - private void collectInfo(TrackedIssue issue) { - if (!StringUtils.isEmpty(issue.assignee())) { - userLoginNames.add(issue.assignee()); - } - if (issue.getRuleKey() != null) { - ruleKeys.add(issue.getRuleKey()); - } - } - - private String getAssigneeName(String login) { - return userMap.get(login); - } - - private void getUsers() { - for (String loginName : userLoginNames) { - User user = userRepository.load(loginName); - if (user != null) { - userMap.put(user.getLogin(), user.getName()); - } - } - } - - private String getRuleName(RuleKey ruleKey) { - Rule rule = rules.find(ruleKey); - return rule != null ? rule.name() : null; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssueFilterChain.java b/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssueFilterChain.java deleted file mode 100644 index 2d9b86ad4a8..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssueFilterChain.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue; - -import com.google.common.collect.ImmutableList; -import org.sonar.api.scan.issue.filter.IssueFilter; - -import java.util.List; - -import org.sonar.api.scan.issue.filter.FilterableIssue; -import org.sonar.api.scan.issue.filter.IssueFilterChain; - -public class DefaultIssueFilterChain implements IssueFilterChain { - private final List filters; - - public DefaultIssueFilterChain(IssueFilter... filters) { - this.filters = ImmutableList.copyOf(filters); - } - - public DefaultIssueFilterChain() { - this.filters = ImmutableList.of(); - } - - private DefaultIssueFilterChain(List filters) { - this.filters = filters; - } - - @Override - public boolean accept(FilterableIssue issue) { - if (filters.isEmpty()) { - return true; - } else { - return filters.get(0).accept(issue, new DefaultIssueFilterChain(filters.subList(1, filters.size()))); - } - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultProjectIssues.java b/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultProjectIssues.java deleted file mode 100644 index be81a1a2a53..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultProjectIssues.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue; - -import com.google.common.base.Function; -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; -import org.sonar.api.issue.Issue; -import org.sonar.api.issue.ProjectIssues; -import org.sonar.batch.issue.tracking.TrackedIssue; - -import javax.annotation.Nullable; - -/** - * Expose list of issues for the current project - * @since 4.0 - */ -public class DefaultProjectIssues implements ProjectIssues { - - private final IssueCache cache; - - public DefaultProjectIssues(IssueCache cache) { - this.cache = cache; - } - - @Override - public Iterable issues() { - return Iterables.transform( - Iterables.filter(cache.all(), new ResolvedPredicate(false)), - new IssueTransformer()); - } - - @Override - public Iterable resolvedIssues() { - return Iterables.transform( - Iterables.filter(cache.all(), new ResolvedPredicate(true)), - new IssueTransformer()); - } - - private static class ResolvedPredicate implements Predicate { - private final boolean resolved; - - private ResolvedPredicate(boolean resolved) { - this.resolved = resolved; - } - - @Override - public boolean apply(@Nullable TrackedIssue issue) { - if (issue != null) { - return resolved ? (issue.resolution() != null) : (issue.resolution() == null); - } - return false; - } - } - - private static class IssueTransformer implements Function { - @Override - public Issue apply(TrackedIssue issue) { - return new TrackedIssueAdapter(issue); - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueAdapterForFilter.java b/sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueAdapterForFilter.java deleted file mode 100644 index f6df0fdbd39..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueAdapterForFilter.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue; - -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.Map; -import org.sonar.api.issue.Issue; -import org.sonar.api.issue.IssueComment; -import org.sonar.api.resources.Project; -import org.sonar.api.rule.RuleKey; -import org.sonar.api.utils.Duration; - -/** - * @deprecated since 5.3 - */ -@Deprecated -class DeprecatedIssueAdapterForFilter implements Issue { - private final Project project; - private final org.sonar.batch.protocol.output.BatchReport.Issue rawIssue; - private final String componentKey; - - DeprecatedIssueAdapterForFilter(Project project, org.sonar.batch.protocol.output.BatchReport.Issue rawIssue, String componentKey) { - this.project = project; - this.rawIssue = rawIssue; - this.componentKey = componentKey; - } - - @Override - public String key() { - throw unsupported(); - } - - @Override - public String componentKey() { - return componentKey; - } - - @Override - public RuleKey ruleKey() { - return RuleKey.of(rawIssue.getRuleRepository(), rawIssue.getRuleKey()); - } - - @Override - public String language() { - throw unsupported(); - } - - @Override - public String severity() { - return rawIssue.getSeverity().name(); - } - - @Override - public String message() { - return rawIssue.getMsg(); - } - - @Override - public Integer line() { - return rawIssue.hasLine() ? rawIssue.getLine() : null; - } - - @Override - @Deprecated - public Double effortToFix() { - return gap(); - } - - @Override - public Double gap() { - return rawIssue.hasGap() ? rawIssue.getGap() : null; - } - - @Override - public String status() { - return Issue.STATUS_OPEN; - } - - @Override - public String resolution() { - return null; - } - - @Override - public String reporter() { - throw unsupported(); - } - - @Override - public String assignee() { - return null; - } - - @Override - public Date creationDate() { - return project.getAnalysisDate(); - } - - @Override - public Date updateDate() { - return null; - } - - @Override - public Date closeDate() { - return null; - } - - @Override - public String attribute(String key) { - return attributes().get(key); - } - - @Override - public Map attributes() { - return Collections.emptyMap(); - } - - @Override - public String authorLogin() { - throw unsupported(); - } - - @Override - public String actionPlanKey() { - throw unsupported(); - } - - @Override - public List comments() { - throw unsupported(); - } - - @Override - public boolean isNew() { - throw unsupported(); - } - - @Deprecated - @Override - public Duration debt() { - return effort(); - } - - @Override - public Duration effort() { - throw unsupported(); - } - - @Override - public String projectKey() { - return project.getEffectiveKey(); - } - - @Override - public String projectUuid() { - throw unsupported(); - } - - @Override - public String componentUuid() { - throw unsupported(); - } - - @Override - public Collection tags() { - throw unsupported(); - } - - private static UnsupportedOperationException unsupported() { - return new UnsupportedOperationException("Not available for issues filters"); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueBuilderWrapper.java b/sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueBuilderWrapper.java deleted file mode 100644 index 0ebef7b6c73..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueBuilderWrapper.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue; - -import com.google.common.base.Preconditions; -import javax.annotation.Nullable; -import org.sonar.api.batch.fs.InputComponent; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.TextRange; -import org.sonar.api.batch.rule.Severity; -import org.sonar.api.batch.sensor.issue.NewIssueLocation; -import org.sonar.api.batch.sensor.issue.internal.DefaultIssue; -import org.sonar.api.batch.sensor.issue.internal.DefaultIssueLocation; -import org.sonar.api.issue.Issuable; -import org.sonar.api.issue.Issuable.IssueBuilder; -import org.sonar.api.issue.Issue; -import org.sonar.api.rule.RuleKey; - -public class DeprecatedIssueBuilderWrapper implements Issuable.IssueBuilder { - - private final DefaultIssue newIssue; - private final InputComponent primaryComponent; - private TextRange primaryRange = null; - private String primaryMessage = null; - - public DeprecatedIssueBuilderWrapper(InputComponent primaryComponent, DefaultIssue newIssue) { - this.primaryComponent = primaryComponent; - this.newIssue = newIssue; - } - - @Override - public IssueBuilder ruleKey(RuleKey ruleKey) { - newIssue.forRule(ruleKey); - return this; - } - - @Override - public IssueBuilder line(@Nullable Integer line) { - Preconditions.checkState(newIssue.primaryLocation() == null, "Do not use line() and at() for the same issue"); - if (primaryComponent.isFile()) { - if (line != null) { - this.primaryRange = ((InputFile) primaryComponent).selectLine(line.intValue()); - } - return this; - } else { - throw new IllegalArgumentException("Unable to set line for issues on project or directory"); - } - } - - @Override - public IssueBuilder message(String message) { - Preconditions.checkState(newIssue.primaryLocation() == null, "Do not use message() and at() for the same issue"); - this.primaryMessage = message; - return this; - } - - @Override - public NewIssueLocation newLocation() { - return new DefaultIssueLocation(); - } - - @Override - public IssueBuilder at(NewIssueLocation primaryLocation) { - Preconditions.checkState(primaryMessage == null && primaryRange == null, "Do not use message() or line() and at() for the same issue"); - newIssue.at(primaryLocation); - return this; - } - - @Override - public IssueBuilder addLocation(NewIssueLocation secondaryLocation) { - newIssue.addLocation(secondaryLocation); - return this; - } - - @Override - public IssueBuilder addFlow(Iterable flowLocations) { - newIssue.addFlow(flowLocations); - return this; - } - - @Override - public IssueBuilder severity(String severity) { - newIssue.overrideSeverity(Severity.valueOf(severity)); - return this; - } - - @Override - public IssueBuilder reporter(String reporter) { - throw new UnsupportedOperationException("Not supported during sensor phase"); - } - - @Override - public IssueBuilder effortToFix(Double d) { - newIssue.effortToFix(d); - return this; - } - - @Override - public IssueBuilder attribute(String key, String value) { - throw new UnsupportedOperationException("Not supported during sensor phase"); - } - - @Override - public Issue build() { - if (newIssue.primaryLocation() == null) { - NewIssueLocation newLocation = newIssue.newLocation().on(primaryComponent); - if (primaryMessage != null) { - newLocation.message(primaryMessage); - } - if (primaryComponent.isFile() && primaryRange != null) { - newLocation.at(primaryRange); - } - newIssue.at(newLocation); - } - return new DeprecatedIssueWrapper(newIssue); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueFilterChain.java b/sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueFilterChain.java deleted file mode 100644 index 83994cfb49d..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueFilterChain.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue; - -import com.google.common.collect.ImmutableList; -import org.sonar.api.issue.Issue; -import org.sonar.api.issue.batch.IssueFilter; -import org.sonar.api.issue.batch.IssueFilterChain; - -import java.util.List; - -/** - * @deprecated since 5.3 - */ -@Deprecated -public class DeprecatedIssueFilterChain implements IssueFilterChain { - - private final List filters; - - public DeprecatedIssueFilterChain(IssueFilter... filters) { - this.filters = ImmutableList.copyOf(filters); - } - - public DeprecatedIssueFilterChain() { - this.filters = ImmutableList.of(); - } - - private DeprecatedIssueFilterChain(List filters) { - this.filters = filters; - } - - @Override - public boolean accept(Issue issue) { - if (filters.isEmpty()) { - return true; - } else { - return filters.get(0).accept(issue, new DeprecatedIssueFilterChain(filters.subList(1, filters.size()))); - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueWrapper.java b/sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueWrapper.java deleted file mode 100644 index 61e215cc931..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueWrapper.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue; - -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.Map; -import org.sonar.api.batch.fs.TextRange; -import org.sonar.api.batch.rule.Severity; -import org.sonar.api.batch.sensor.issue.internal.DefaultIssue; -import org.sonar.api.issue.Issue; -import org.sonar.api.issue.IssueComment; -import org.sonar.api.rule.RuleKey; -import org.sonar.api.utils.Duration; - -public class DeprecatedIssueWrapper implements Issue { - - private final DefaultIssue newIssue; - - public DeprecatedIssueWrapper(DefaultIssue newIssue) { - this.newIssue = newIssue; - } - - public DefaultIssue wrapped() { - return newIssue; - } - - @Override - public String key() { - return null; - } - - @Override - public String componentKey() { - return null; - } - - @Override - public RuleKey ruleKey() { - return newIssue.ruleKey(); - } - - @Override - public String language() { - return null; - } - - @Override - public String severity() { - Severity overridenSeverity = newIssue.overriddenSeverity(); - return overridenSeverity != null ? overridenSeverity.name() : null; - } - - @Override - public String message() { - return newIssue.primaryLocation().message(); - } - - @Override - public Integer line() { - TextRange textRange = newIssue.primaryLocation().textRange(); - return textRange != null ? textRange.start().line() : null; - } - - /** - * @deprecated since 5.5, replaced by {@link #gap()} - */ - @Override - @Deprecated - public Double effortToFix() { - return gap(); - } - - @Override - public Double gap() { - return newIssue.effortToFix(); - } - - @Override - public String status() { - return null; - } - - @Override - public String resolution() { - return null; - } - - @Override - public String reporter() { - return null; - } - - @Override - public String assignee() { - return null; - } - - @Override - public Date creationDate() { - return null; - } - - @Override - public Date updateDate() { - return null; - } - - @Override - public Date closeDate() { - return null; - } - - @Override - public String attribute(String key) { - return null; - } - - @Override - public Map attributes() { - return Collections.emptyMap(); - } - - @Override - public String authorLogin() { - return null; - } - - @Override - public String actionPlanKey() { - return null; - } - - @Override - public List comments() { - return Collections.emptyList(); - } - - @Override - public boolean isNew() { - return false; - } - - @Override - public Duration debt() { - return null; - } - - @Override - public Duration effort() { - return null; - } - - @Override - public String projectKey() { - return null; - } - - @Override - public String projectUuid() { - return null; - } - - @Override - public String componentUuid() { - return null; - } - - @Override - public Collection tags() { - return Collections.emptyList(); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/IssuableFactory.java b/sonar-batch/src/main/java/org/sonar/batch/issue/IssuableFactory.java deleted file mode 100644 index a2c7afc9c59..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/IssuableFactory.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue; - -import org.sonar.api.batch.sensor.SensorContext; -import org.sonar.api.issue.Issuable; -import org.sonar.batch.deprecated.perspectives.PerspectiveBuilder; -import org.sonar.batch.index.BatchComponent; -import org.sonar.batch.sensor.DefaultSensorContext; - -/** - * Create the perspective {@link Issuable} on components. - * @since 3.6 - */ -public class IssuableFactory extends PerspectiveBuilder { - - private final SensorContext sensorContext; - - public IssuableFactory(DefaultSensorContext sensorContext) { - super(Issuable.class); - this.sensorContext = sensorContext; - } - - @Override - public Issuable loadPerspective(Class perspectiveClass, BatchComponent component) { - return new DefaultIssuable(component, sensorContext); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/IssueCache.java b/sonar-batch/src/main/java/org/sonar/batch/issue/IssueCache.java deleted file mode 100644 index ac1bc6826a5..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/IssueCache.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue; - -import org.sonar.batch.issue.tracking.TrackedIssue; - -import org.sonar.api.batch.BatchSide; -import org.sonar.batch.index.Cache; -import org.sonar.batch.index.Caches; - -import java.util.Collection; - -/** - * Shared issues among all project modules - */ -@BatchSide -public class IssueCache { - - // component key -> issue key -> issue - private final Cache cache; - - public IssueCache(Caches caches) { - cache = caches.createCache("issues"); - } - - public Iterable byComponent(String componentKey) { - return cache.values(componentKey); - } - - public Iterable all() { - return cache.values(); - } - - public Collection componentKeys() { - return cache.keySet(); - } - - public IssueCache put(TrackedIssue issue) { - cache.put(issue.componentKey(), issue.key(), issue); - return this; - } - - public void clear(String componentKey) { - cache.clear(componentKey); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/IssueCallback.java b/sonar-batch/src/main/java/org/sonar/batch/issue/IssueCallback.java deleted file mode 100644 index b27b7887045..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/IssueCallback.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue; - -public interface IssueCallback { - void execute(); -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/IssueFilters.java b/sonar-batch/src/main/java/org/sonar/batch/issue/IssueFilters.java deleted file mode 100644 index b84352da6df..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/IssueFilters.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue; - -import org.sonar.api.scan.issue.filter.FilterableIssue; - -import org.sonar.api.scan.issue.filter.IssueFilterChain; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.issue.Issue; -import org.sonar.api.scan.issue.filter.IssueFilter; -import org.sonar.api.resources.Project; -import org.sonar.batch.protocol.output.BatchReport; - -@BatchSide -public class IssueFilters { - private final IssueFilter[] filters; - private final org.sonar.api.issue.batch.IssueFilter[] deprecatedFilters; - private final Project project; - - public IssueFilters(Project project, IssueFilter[] exclusionFilters, org.sonar.api.issue.batch.IssueFilter[] filters) { - this.project = project; - this.filters = exclusionFilters; - this.deprecatedFilters = filters; - } - - public IssueFilters(Project project, IssueFilter[] filters) { - this(project, filters, new org.sonar.api.issue.batch.IssueFilter[0]); - } - - public IssueFilters(Project project, org.sonar.api.issue.batch.IssueFilter[] deprecatedFilters) { - this(project, new IssueFilter[0], deprecatedFilters); - } - - public IssueFilters(Project project) { - this(project, new IssueFilter[0], new org.sonar.api.issue.batch.IssueFilter[0]); - } - - public boolean accept(String componentKey, BatchReport.Issue rawIssue) { - IssueFilterChain filterChain = new DefaultIssueFilterChain(filters); - FilterableIssue fIssue = new DefaultFilterableIssue(project, rawIssue, componentKey); - if (filterChain.accept(fIssue)) { - return acceptDeprecated(componentKey, rawIssue); - } - - return false; - } - - public boolean acceptDeprecated(String componentKey, BatchReport.Issue rawIssue) { - Issue issue = new DeprecatedIssueAdapterForFilter(project, rawIssue, componentKey); - return new DeprecatedIssueFilterChain(deprecatedFilters).accept(issue); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/IssueTransformer.java b/sonar-batch/src/main/java/org/sonar/batch/issue/IssueTransformer.java deleted file mode 100644 index b606854be93..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/IssueTransformer.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue; - -import com.google.common.base.Preconditions; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.List; -import javax.annotation.Nullable; -import org.sonar.api.issue.Issue; -import org.sonar.api.rule.RuleKey; -import org.sonar.batch.index.BatchComponent; -import org.sonar.batch.issue.tracking.SourceHashHolder; -import org.sonar.batch.issue.tracking.TrackedIssue; -import org.sonar.batch.protocol.input.BatchInput.ServerIssue; -import org.sonar.batch.protocol.output.BatchReport; -import org.sonar.batch.protocol.output.BatchReport.TextRange; -import org.sonar.core.component.ComponentKeys; -import org.sonar.core.util.Uuids; - -public class IssueTransformer { - private IssueTransformer() { - // static only - } - - public static TrackedIssue toTrackedIssue(ServerIssue serverIssue) { - TrackedIssue issue = new TrackedIssue(); - issue.setKey(serverIssue.getKey()); - issue.setStatus(serverIssue.getStatus()); - issue.setResolution(serverIssue.hasResolution() ? serverIssue.getResolution() : null); - issue.setMessage(serverIssue.hasMsg() ? serverIssue.getMsg() : null); - issue.setStartLine(serverIssue.hasLine() ? serverIssue.getLine() : null); - issue.setEndLine(serverIssue.hasLine() ? serverIssue.getLine() : null); - issue.setSeverity(serverIssue.getSeverity().name()); - issue.setAssignee(serverIssue.hasAssigneeLogin() ? serverIssue.getAssigneeLogin() : null); - issue.setComponentKey(ComponentKeys.createEffectiveKey(serverIssue.getModuleKey(), serverIssue.hasPath() ? serverIssue.getPath() : null)); - issue.setCreationDate(new Date(serverIssue.getCreationDate())); - issue.setRuleKey(RuleKey.of(serverIssue.getRuleRepository(), serverIssue.getRuleKey())); - issue.setNew(false); - return issue; - } - - public static void close(TrackedIssue issue) { - issue.setStatus(Issue.STATUS_CLOSED); - issue.setStartLine(null); - issue.setEndLine(null); - issue.setResolution(Issue.RESOLUTION_FIXED); - } - - public static void resolveRemove(TrackedIssue issue) { - issue.setStatus(Issue.STATUS_CLOSED); - issue.setStartLine(null); - issue.setEndLine(null); - issue.setResolution(Issue.RESOLUTION_REMOVED); - } - - public static Collection toTrackedIssue(BatchComponent component, Collection rawIssues, @Nullable SourceHashHolder hashes) { - List issues = new ArrayList<>(rawIssues.size()); - - for (BatchReport.Issue issue : rawIssues) { - issues.add(toTrackedIssue(component, issue, hashes)); - } - - return issues; - } - - public static TrackedIssue toTrackedIssue(BatchComponent component, BatchReport.Issue rawIssue, @Nullable SourceHashHolder hashes) { - RuleKey ruleKey = RuleKey.of(rawIssue.getRuleRepository(), rawIssue.getRuleKey()); - - Preconditions.checkNotNull(component.key(), "Component key must be set"); - Preconditions.checkNotNull(ruleKey, "Rule key must be set"); - - TrackedIssue issue = new TrackedIssue(hashes != null ? hashes.getHashedSource() : null); - - issue.setKey(Uuids.createFast()); - issue.setComponentKey(component.key()); - issue.setRuleKey(ruleKey); - issue.setGap(rawIssue.hasGap() ? rawIssue.getGap() : null); - issue.setSeverity(rawIssue.getSeverity().name()); - issue.setMessage(rawIssue.hasMsg() ? rawIssue.getMsg() : null); - issue.setResolution(null); - issue.setStatus(Issue.STATUS_OPEN); - issue.setNew(true); - - if (rawIssue.hasTextRange()) { - TextRange r = rawIssue.getTextRange(); - - issue.setStartLine(r.hasStartLine() ? rawIssue.getTextRange().getStartLine() : null); - issue.setStartLineOffset(r.hasStartOffset() ? r.getStartOffset() : null); - issue.setEndLine(r.hasEndLine() ? r.getEndLine() : issue.startLine()); - issue.setEndLineOffset(r.hasEndOffset() ? r.getEndOffset() : null); - } - - return issue; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java b/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java deleted file mode 100644 index fb798fd563b..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue; - -import com.google.common.base.Strings; -import org.sonar.api.batch.fs.InputComponent; -import org.sonar.api.batch.fs.TextRange; -import org.sonar.api.batch.rule.ActiveRule; -import org.sonar.api.batch.rule.ActiveRules; -import org.sonar.api.batch.rule.Rule; -import org.sonar.api.batch.rule.Rules; -import org.sonar.api.batch.sensor.issue.Issue; -import org.sonar.api.batch.sensor.issue.Issue.Flow; -import org.sonar.api.rule.RuleKey; -import org.sonar.api.utils.MessageException; -import org.sonar.batch.index.BatchComponent; -import org.sonar.batch.index.BatchComponentCache; -import org.sonar.batch.protocol.Constants.Severity; -import org.sonar.batch.protocol.output.BatchReport; -import org.sonar.batch.protocol.output.BatchReport.IssueLocation; -import org.sonar.batch.protocol.output.BatchReport.IssueLocation.Builder; -import org.sonar.batch.report.ReportPublisher; - -/** - * Initialize the issues raised during scan. - */ -public class ModuleIssues { - - private final ActiveRules activeRules; - private final Rules rules; - private final IssueFilters filters; - private final ReportPublisher reportPublisher; - private final BatchComponentCache componentCache; - private final BatchReport.Issue.Builder builder = BatchReport.Issue.newBuilder(); - private final Builder locationBuilder = IssueLocation.newBuilder(); - private final org.sonar.batch.protocol.output.BatchReport.TextRange.Builder textRangeBuilder = org.sonar.batch.protocol.output.BatchReport.TextRange.newBuilder(); - private final BatchReport.Flow.Builder flowBuilder = BatchReport.Flow.newBuilder(); - - public ModuleIssues(ActiveRules activeRules, Rules rules, IssueFilters filters, ReportPublisher reportPublisher, BatchComponentCache componentCache) { - this.activeRules = activeRules; - this.rules = rules; - this.filters = filters; - this.reportPublisher = reportPublisher; - this.componentCache = componentCache; - } - - public boolean initAndAddIssue(Issue issue) { - InputComponent inputComponent = issue.primaryLocation().inputComponent(); - BatchComponent component = componentCache.get(inputComponent); - - Rule rule = validateRule(issue); - ActiveRule activeRule = activeRules.find(issue.ruleKey()); - if (activeRule == null) { - // rule does not exist or is not enabled -> ignore the issue - return false; - } - - String primaryMessage = Strings.isNullOrEmpty(issue.primaryLocation().message()) ? rule.name() : issue.primaryLocation().message(); - org.sonar.api.batch.rule.Severity overriddenSeverity = issue.overriddenSeverity(); - Severity severity = overriddenSeverity != null ? Severity.valueOf(overriddenSeverity.name()) : Severity.valueOf(activeRule.severity()); - - builder.clear(); - locationBuilder.clear(); - // non-null fields - builder.setSeverity(severity); - builder.setRuleRepository(issue.ruleKey().repository()); - builder.setRuleKey(issue.ruleKey().rule()); - builder.setMsg(primaryMessage); - locationBuilder.setMsg(primaryMessage); - - locationBuilder.setComponentRef(component.batchId()); - TextRange primaryTextRange = issue.primaryLocation().textRange(); - if (primaryTextRange != null) { - builder.setLine(primaryTextRange.start().line()); - builder.setTextRange(toProtobufTextRange(primaryTextRange)); - } - Double gap = issue.gap(); - if (gap != null) { - builder.setGap(gap); - } - applyFlows(issue); - BatchReport.Issue rawIssue = builder.build(); - - if (filters.accept(inputComponent.key(), rawIssue)) { - write(component, rawIssue); - return true; - } - return false; - } - - private void applyFlows(Issue issue) { - for (Flow flow : issue.flows()) { - if (!flow.locations().isEmpty()) { - flowBuilder.clear(); - for (org.sonar.api.batch.sensor.issue.IssueLocation location : flow.locations()) { - locationBuilder.clear(); - locationBuilder.setComponentRef(componentCache.get(location.inputComponent()).batchId()); - String message = location.message(); - if (message != null) { - locationBuilder.setMsg(message); - } - TextRange textRange = location.textRange(); - if (textRange != null) { - locationBuilder.setTextRange(toProtobufTextRange(textRange)); - } - flowBuilder.addLocation(locationBuilder.build()); - } - builder.addFlow(flowBuilder.build()); - } - } - } - - private org.sonar.batch.protocol.output.BatchReport.TextRange toProtobufTextRange(TextRange primaryTextRange) { - textRangeBuilder.clear(); - textRangeBuilder.setStartLine(primaryTextRange.start().line()); - textRangeBuilder.setStartOffset(primaryTextRange.start().lineOffset()); - textRangeBuilder.setEndLine(primaryTextRange.end().line()); - textRangeBuilder.setEndOffset(primaryTextRange.end().lineOffset()); - return textRangeBuilder.build(); - } - - private Rule validateRule(Issue issue) { - RuleKey ruleKey = issue.ruleKey(); - Rule rule = rules.find(ruleKey); - if (rule == null) { - throw MessageException.of(String.format("The rule '%s' does not exist.", ruleKey)); - } - if (Strings.isNullOrEmpty(rule.name()) && Strings.isNullOrEmpty(issue.primaryLocation().message())) { - throw MessageException.of(String.format("The rule '%s' has no name and the related issue has no message.", ruleKey)); - } - return rule; - } - - public void write(BatchComponent component, BatchReport.Issue rawIssue) { - reportPublisher.getWriter().appendComponentIssue(component.batchId(), rawIssue); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/TrackedIssueAdapter.java b/sonar-batch/src/main/java/org/sonar/batch/issue/TrackedIssueAdapter.java deleted file mode 100644 index 19027847d9d..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/TrackedIssueAdapter.java +++ /dev/null @@ -1,202 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.sonar.api.issue.Issue; -import org.sonar.api.issue.IssueComment; -import org.sonar.api.rule.RuleKey; -import org.sonar.api.utils.Duration; -import org.sonar.batch.issue.tracking.TrackedIssue; - -public class TrackedIssueAdapter implements Issue { - private TrackedIssue issue; - - public TrackedIssueAdapter(TrackedIssue issue) { - this.issue = issue; - } - - @Override - public String key() { - return issue.key(); - } - - @Override - public String componentKey() { - return issue.componentKey(); - } - - @Override - public RuleKey ruleKey() { - return issue.getRuleKey(); - } - - @Override - public String severity() { - return issue.severity(); - } - - @Override - public String message() { - return issue.getMessage(); - } - - @Override - public Integer line() { - return issue.startLine(); - } - - /** - * @deprecated since 5.5, replaced by {@link #gap()} - */ - @Override - @Deprecated - public Double effortToFix() { - return gap(); - } - - @Override - public Double gap() { - return issue.gap(); - } - - @Override - public String status() { - return issue.status(); - } - - @Override - public String resolution() { - return issue.resolution(); - } - - @Override - public String reporter() { - return issue.reporter(); - } - - @Override - public String assignee() { - return issue.assignee(); - } - - @Override - public boolean isNew() { - return issue.isNew(); - } - - @Override - public Map attributes() { - return new HashMap<>(); - } - - @Override - public Date creationDate() { - return issue.getCreationDate(); - } - - @Override - public String language() { - return null; - } - - @Override - public Date updateDate() { - return null; - } - - @Override - public Date closeDate() { - return null; - } - - @Override - public String attribute(String key) { - return attributes().get(key); - } - - @Override - public String authorLogin() { - return null; - } - - @Override - public String actionPlanKey() { - return null; - } - - @Override - public List comments() { - return new ArrayList<>(); - } - - /** - * @deprecated since 5.5, replaced by {@link #effort()} - */ - @Override - @Deprecated - public Duration debt() { - return null; - } - - @Override - public Duration effort() { - return null; - } - - @Override - public String projectKey() { - return null; - } - - @Override - public String projectUuid() { - return null; - } - - @Override - public String componentUuid() { - return null; - } - - @Override - public Collection tags() { - return new ArrayList<>(); - } - - @Override - public boolean equals(Object o) { - if (o == null || !(o instanceof Issue)) { - return false; - } - Issue that = (Issue) o; - return !(issue.key() != null ? !issue.key().equals(that.key()) : (that.key() != null)); - } - - @Override - public int hashCode() { - return issue.key() != null ? issue.key().hashCode() : 0; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/EnforceIssuesFilter.java b/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/EnforceIssuesFilter.java deleted file mode 100644 index de4920a1f06..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/EnforceIssuesFilter.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue.ignore; - -import org.sonar.api.scan.issue.filter.FilterableIssue; - -import org.sonar.batch.issue.ignore.pattern.IssueInclusionPatternInitializer; -import org.sonar.batch.issue.ignore.pattern.IssuePattern; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.scan.issue.filter.IssueFilter; -import org.sonar.api.scan.issue.filter.IssueFilterChain; - -public class EnforceIssuesFilter implements IssueFilter { - - private IssueInclusionPatternInitializer patternInitializer; - - private static final Logger LOG = LoggerFactory.getLogger(EnforceIssuesFilter.class); - - public EnforceIssuesFilter(IssueInclusionPatternInitializer patternInitializer) { - this.patternInitializer = patternInitializer; - } - - @Override - public boolean accept(FilterableIssue issue, IssueFilterChain chain) { - boolean atLeastOneRuleMatched = false; - boolean atLeastOnePatternFullyMatched = false; - IssuePattern matchingPattern = null; - - for (IssuePattern pattern : patternInitializer.getMulticriteriaPatterns()) { - if (pattern.getRulePattern().match(issue.ruleKey().toString())) { - atLeastOneRuleMatched = true; - String pathForComponent = patternInitializer.getPathForComponent(issue.componentKey()); - if (pathForComponent != null && pattern.getResourcePattern().match(pathForComponent)) { - atLeastOnePatternFullyMatched = true; - matchingPattern = pattern; - } - } - } - - if (atLeastOneRuleMatched) { - if (atLeastOnePatternFullyMatched) { - LOG.debug("Issue {} enforced by pattern {}", issue, matchingPattern); - } - return atLeastOnePatternFullyMatched; - } else { - return chain.accept(issue); - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/IgnoreIssuesFilter.java b/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/IgnoreIssuesFilter.java deleted file mode 100644 index 99a716148c6..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/IgnoreIssuesFilter.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue.ignore; - -import org.sonar.api.scan.issue.filter.FilterableIssue; - -import org.sonar.batch.issue.ignore.pattern.IssueExclusionPatternInitializer; -import org.sonar.batch.issue.ignore.pattern.IssuePattern; -import org.sonar.batch.issue.ignore.pattern.PatternMatcher; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.scan.issue.filter.IssueFilter; -import org.sonar.api.scan.issue.filter.IssueFilterChain; - -public class IgnoreIssuesFilter implements IssueFilter { - - private PatternMatcher patternMatcher; - - private static final Logger LOG = LoggerFactory.getLogger(IgnoreIssuesFilter.class); - - public IgnoreIssuesFilter(IssueExclusionPatternInitializer patternInitializer) { - this.patternMatcher = patternInitializer.getPatternMatcher(); - } - - @Override - public boolean accept(FilterableIssue issue, IssueFilterChain chain) { - if (hasMatchFor(issue)) { - return false; - } else { - return chain.accept(issue); - } - } - - private boolean hasMatchFor(FilterableIssue issue) { - IssuePattern pattern = patternMatcher.getMatchingPattern(issue); - if (pattern != null) { - logExclusion(issue, pattern); - return true; - } - return false; - } - - private static void logExclusion(FilterableIssue issue, IssuePattern pattern) { - LOG.debug("Issue {} ignored by exclusion pattern {}", issue, pattern); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/package-info.java deleted file mode 100644 index ead2a62c636..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.batch.issue.ignore; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/pattern/AbstractPatternInitializer.java b/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/pattern/AbstractPatternInitializer.java deleted file mode 100644 index a3e58803a71..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/pattern/AbstractPatternInitializer.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue.ignore.pattern; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.Lists; -import org.apache.commons.lang.StringUtils; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.config.Settings; - -import java.util.List; - -import static com.google.common.base.Objects.firstNonNull; - -@BatchSide -public abstract class AbstractPatternInitializer { - - private Settings settings; - - private List multicriteriaPatterns; - - protected AbstractPatternInitializer(Settings settings) { - this.settings = settings; - initPatterns(); - } - - protected Settings getSettings() { - return settings; - } - - public List getMulticriteriaPatterns() { - return multicriteriaPatterns; - } - - public boolean hasConfiguredPatterns() { - return hasMulticriteriaPatterns(); - } - - public boolean hasMulticriteriaPatterns() { - return !multicriteriaPatterns.isEmpty(); - } - - public abstract void initializePatternsForPath(String relativePath, String componentKey); - - @VisibleForTesting - protected final void initPatterns() { - // Patterns Multicriteria - multicriteriaPatterns = Lists.newArrayList(); - String patternConf = StringUtils.defaultIfBlank(settings.getString(getMulticriteriaConfigurationKey()), ""); - for (String id : StringUtils.split(patternConf, ',')) { - String propPrefix = getMulticriteriaConfigurationKey() + "." + id + "."; - String resourceKeyPattern = settings.getString(propPrefix + "resourceKey"); - String ruleKeyPattern = settings.getString(propPrefix + "ruleKey"); - String lineRange = "*"; - String[] fields = new String[] {resourceKeyPattern, ruleKeyPattern, lineRange}; - PatternDecoder.checkRegularLineConstraints(StringUtils.join(fields, ","), fields); - IssuePattern pattern = new IssuePattern(firstNonNull(resourceKeyPattern, "*"), firstNonNull(ruleKeyPattern, "*")); - PatternDecoder.decodeRangeOfLines(pattern, firstNonNull(lineRange, "*")); - multicriteriaPatterns.add(pattern); - } - } - - protected abstract String getMulticriteriaConfigurationKey(); -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/pattern/IssueExclusionPatternInitializer.java b/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/pattern/IssueExclusionPatternInitializer.java deleted file mode 100644 index 74d80f95186..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/pattern/IssueExclusionPatternInitializer.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue.ignore.pattern; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.Lists; -import org.apache.commons.lang.StringUtils; -import org.sonar.api.config.Settings; -import org.sonar.core.config.IssueExclusionProperties; - -import java.util.List; - -import static com.google.common.base.Strings.nullToEmpty; - -public class IssueExclusionPatternInitializer extends AbstractPatternInitializer { - - private List blockPatterns; - private List allFilePatterns; - private PatternMatcher patternMatcher; - - public IssueExclusionPatternInitializer(Settings settings) { - super(settings); - patternMatcher = new PatternMatcher(); - loadFileContentPatterns(); - } - - @Override - protected String getMulticriteriaConfigurationKey() { - return "sonar.issue.ignore" + ".multicriteria"; - } - - public PatternMatcher getPatternMatcher() { - return patternMatcher; - } - - @Override - public void initializePatternsForPath(String relativePath, String componentKey) { - for (IssuePattern pattern : getMulticriteriaPatterns()) { - if (pattern.matchResource(relativePath)) { - getPatternMatcher().addPatternForComponent(componentKey, pattern); - } - } - } - - @Override - public boolean hasConfiguredPatterns() { - return hasFileContentPattern() || hasMulticriteriaPatterns(); - } - - @VisibleForTesting - protected final void loadFileContentPatterns() { - // Patterns Block - blockPatterns = Lists.newArrayList(); - String patternConf = StringUtils.defaultIfBlank(getSettings().getString(IssueExclusionProperties.PATTERNS_BLOCK_KEY), ""); - for (String id : StringUtils.split(patternConf, ',')) { - String propPrefix = IssueExclusionProperties.PATTERNS_BLOCK_KEY + "." + id + "."; - String beginBlockRegexp = getSettings().getString(propPrefix + IssueExclusionProperties.BEGIN_BLOCK_REGEXP); - String endBlockRegexp = getSettings().getString(propPrefix + IssueExclusionProperties.END_BLOCK_REGEXP); - String[] fields = new String[]{beginBlockRegexp, endBlockRegexp}; - PatternDecoder.checkDoubleRegexpLineConstraints(StringUtils.join(fields, ","), fields); - IssuePattern pattern = new IssuePattern().setBeginBlockRegexp(nullToEmpty(beginBlockRegexp)).setEndBlockRegexp(nullToEmpty(endBlockRegexp)); - blockPatterns.add(pattern); - } - - // Patterns All File - allFilePatterns = Lists.newArrayList(); - patternConf = StringUtils.defaultIfBlank(getSettings().getString(IssueExclusionProperties.PATTERNS_ALLFILE_KEY), ""); - for (String id : StringUtils.split(patternConf, ',')) { - String propPrefix = IssueExclusionProperties.PATTERNS_ALLFILE_KEY + "." + id + "."; - String allFileRegexp = getSettings().getString(propPrefix + IssueExclusionProperties.FILE_REGEXP); - PatternDecoder.checkWholeFileRegexp(allFileRegexp); - IssuePattern pattern = new IssuePattern().setAllFileRegexp(nullToEmpty(allFileRegexp)); - allFilePatterns.add(pattern); - } - } - - public List getBlockPatterns() { - return blockPatterns; - } - - public List getAllFilePatterns() { - return allFilePatterns; - } - - public boolean hasFileContentPattern() { - return !(blockPatterns.isEmpty() && allFilePatterns.isEmpty()); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/pattern/IssueInclusionPatternInitializer.java b/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/pattern/IssueInclusionPatternInitializer.java deleted file mode 100644 index 9fec33bb952..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/pattern/IssueInclusionPatternInitializer.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue.ignore.pattern; - -import com.google.common.collect.Maps; -import org.sonar.api.config.Settings; - -import java.util.Map; - -public class IssueInclusionPatternInitializer extends AbstractPatternInitializer { - - private Map pathForComponent; - - public IssueInclusionPatternInitializer(Settings settings) { - super(settings); - pathForComponent = Maps.newHashMap(); - } - - @Override - protected String getMulticriteriaConfigurationKey() { - return "sonar.issue.enforce" + ".multicriteria"; - } - - @Override - public void initializePatternsForPath(String relativePath, String componentKey) { - pathForComponent.put(componentKey, relativePath); - } - - public String getPathForComponent(String componentKey) { - return pathForComponent.get(componentKey); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/pattern/IssuePattern.java b/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/pattern/IssuePattern.java deleted file mode 100644 index 4c4cc0b4715..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/pattern/IssuePattern.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue.ignore.pattern; - -import org.sonar.api.scan.issue.filter.FilterableIssue; - -import com.google.common.collect.Sets; -import org.apache.commons.lang.builder.ToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; -import org.sonar.api.rule.RuleKey; -import org.sonar.api.utils.WildcardPattern; - -import java.util.Set; - -public class IssuePattern { - - private WildcardPattern resourcePattern; - private WildcardPattern rulePattern; - private Set lines = Sets.newLinkedHashSet(); - private Set lineRanges = Sets.newLinkedHashSet(); - private String beginBlockRegexp; - private String endBlockRegexp; - private String allFileRegexp; - private boolean checkLines = true; - - public IssuePattern() { - } - - public IssuePattern(String resourcePattern, String rulePattern) { - this.resourcePattern = WildcardPattern.create(resourcePattern); - this.rulePattern = WildcardPattern.create(rulePattern); - } - - public IssuePattern(String resourcePattern, String rulePattern, Set lineRanges) { - this(resourcePattern, rulePattern); - this.lineRanges = lineRanges; - } - - public WildcardPattern getResourcePattern() { - return resourcePattern; - } - - public WildcardPattern getRulePattern() { - return rulePattern; - } - - public String getBeginBlockRegexp() { - return beginBlockRegexp; - } - - public String getEndBlockRegexp() { - return endBlockRegexp; - } - - public String getAllFileRegexp() { - return allFileRegexp; - } - - IssuePattern addLineRange(int fromLineId, int toLineId) { - lineRanges.add(new LineRange(fromLineId, toLineId)); - return this; - } - - IssuePattern addLine(int lineId) { - lines.add(lineId); - return this; - } - - boolean isCheckLines() { - return checkLines; - } - - IssuePattern setCheckLines(boolean b) { - this.checkLines = b; - return this; - } - - IssuePattern setBeginBlockRegexp(String beginBlockRegexp) { - this.beginBlockRegexp = beginBlockRegexp; - return this; - } - - IssuePattern setEndBlockRegexp(String endBlockRegexp) { - this.endBlockRegexp = endBlockRegexp; - return this; - } - - IssuePattern setAllFileRegexp(String allFileRegexp) { - this.allFileRegexp = allFileRegexp; - return this; - } - - Set getAllLines() { - Set allLines = Sets.newLinkedHashSet(lines); - for (LineRange lineRange : lineRanges) { - allLines.addAll(lineRange.toLines()); - } - return allLines; - } - - public boolean match(FilterableIssue issue) { - boolean match = matchResource(issue.componentKey()) - && matchRule(issue.ruleKey()); - if (checkLines) { - Integer line = issue.line(); - if (line == null) { - match = false; - } else { - match = match && matchLine(line); - } - } - return match; - } - - boolean matchLine(int lineId) { - if (lines.contains(lineId)) { - return true; - } - - for (LineRange range : lineRanges) { - if (range.in(lineId)) { - return true; - } - } - - return false; - } - - boolean matchRule(RuleKey rule) { - if (rule == null) { - return false; - } - - String key = new StringBuilder().append(rule.repository()).append(':').append(rule.rule()).toString(); - return rulePattern.match(key); - } - - boolean matchResource(String resource) { - return resource != null && resourcePattern.match(resource); - } - - public IssuePattern forResource(String resource) { - return new IssuePattern(resource, rulePattern.toString(), lineRanges).setCheckLines(isCheckLines()); - } - - @Override - public String toString() { - return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/pattern/LineRange.java b/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/pattern/LineRange.java deleted file mode 100644 index 72d43f5f216..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/pattern/LineRange.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue.ignore.pattern; - -import com.google.common.base.Preconditions; -import com.google.common.collect.Sets; - -import java.util.Set; - -public class LineRange { - private int from; - private int to; - - public LineRange(int from, int to) { - Preconditions.checkArgument(from <= to, "Line range is not valid: %s must be greater than %s", from, to); - - this.from = from; - this.to = to; - } - - public boolean in(int lineId) { - return from <= lineId && lineId <= to; - } - - public Set toLines() { - Set lines = Sets.newLinkedHashSet(); - for (int index = from; index <= to; index++) { - lines.add(index); - } - return lines; - } - - @Override - public String toString() { - return "[" + from + "-" + to + "]"; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + from; - result = prime * result + to; - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - if (fieldsDiffer((LineRange) obj)) { - return false; - } - return true; - } - - private boolean fieldsDiffer(LineRange other) { - if (from != other.from) { - return true; - } - if (to != other.to) { - return true; - } - return false; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/pattern/PatternDecoder.java b/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/pattern/PatternDecoder.java deleted file mode 100644 index 11dc501cac4..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/pattern/PatternDecoder.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue.ignore.pattern; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.Lists; -import org.apache.commons.lang.StringUtils; -import org.sonar.api.utils.SonarException; - -import java.util.List; - -public class PatternDecoder { - - private static final int THREE_FIELDS_PER_LINE = 3; - private static final String LINE_RANGE_REGEXP = "\\[((\\d+|\\d+-\\d+),?)*\\]"; - private static final String CONFIG_FORMAT_ERROR_PREFIX = "Exclusions > Issues : Invalid format. "; - - public List decode(String patternsList) { - List patterns = Lists.newLinkedList(); - String[] patternsLines = StringUtils.split(patternsList, "\n"); - for (String patternLine : patternsLines) { - IssuePattern pattern = decodeLine(patternLine.trim()); - if (pattern != null) { - patterns.add(pattern); - } - } - return patterns; - } - - /** - * Main method that decodes a line which defines a pattern - */ - public IssuePattern decodeLine(String line) { - if (isBlankOrComment(line)) { - return null; - } - - String[] fields = StringUtils.splitPreserveAllTokens(line, ';'); - if (fields.length > THREE_FIELDS_PER_LINE) { - throw new SonarException(CONFIG_FORMAT_ERROR_PREFIX + "The following line has more than 3 fields separated by comma: " + line); - } - - IssuePattern pattern; - if (fields.length == THREE_FIELDS_PER_LINE) { - checkRegularLineConstraints(line, fields); - pattern = new IssuePattern(StringUtils.trim(fields[0]), StringUtils.trim(fields[1])); - decodeRangeOfLines(pattern, fields[2]); - } else if (fields.length == 2) { - checkDoubleRegexpLineConstraints(line, fields); - pattern = new IssuePattern().setBeginBlockRegexp(fields[0]).setEndBlockRegexp(fields[1]); - } else { - checkWholeFileRegexp(fields[0]); - pattern = new IssuePattern().setAllFileRegexp(fields[0]); - } - - return pattern; - } - - static void checkRegularLineConstraints(String line, String[] fields) { - if (!isResource(fields[0])) { - throw new SonarException(CONFIG_FORMAT_ERROR_PREFIX + "The first field does not define a resource pattern: " + line); - } - if (!isRule(fields[1])) { - throw new SonarException(CONFIG_FORMAT_ERROR_PREFIX + "The second field does not define a rule pattern: " + line); - } - if (!isLinesRange(fields[2])) { - throw new SonarException(CONFIG_FORMAT_ERROR_PREFIX + "The third field does not define a range of lines: " + line); - } - } - - static void checkDoubleRegexpLineConstraints(String line, String[] fields) { - if (!isRegexp(fields[0])) { - throw new SonarException(CONFIG_FORMAT_ERROR_PREFIX + "The first field does not define a regular expression: " + line); - } - // As per configuration help, missing second field means: from start regexp to EOF - } - - static void checkWholeFileRegexp(String regexp) { - if (!isRegexp(regexp)) { - throw new SonarException(CONFIG_FORMAT_ERROR_PREFIX + "The field does not define a regular expression: " + regexp); - } - } - - public static void decodeRangeOfLines(IssuePattern pattern, String field) { - if (StringUtils.equals(field, "*")) { - pattern.setCheckLines(false); - } else { - pattern.setCheckLines(true); - String s = StringUtils.substringBetween(StringUtils.trim(field), "[", "]"); - String[] parts = StringUtils.split(s, ','); - for (String part : parts) { - if (StringUtils.contains(part, '-')) { - String[] range = StringUtils.split(part, '-'); - pattern.addLineRange(Integer.valueOf(range[0]), Integer.valueOf(range[1])); - } else { - pattern.addLine(Integer.valueOf(part)); - } - } - } - } - - @VisibleForTesting - static boolean isLinesRange(String field) { - return StringUtils.equals(field, "*") || java.util.regex.Pattern.matches(LINE_RANGE_REGEXP, field); - } - - @VisibleForTesting - static boolean isBlankOrComment(String line) { - return StringUtils.isBlank(line) ^ StringUtils.startsWith(line, "#"); - } - - @VisibleForTesting - static boolean isResource(String field) { - return StringUtils.isNotBlank(field); - } - - @VisibleForTesting - static boolean isRule(String field) { - return StringUtils.isNotBlank(field); - } - - @VisibleForTesting - static boolean isRegexp(String field) { - return StringUtils.isNotBlank(field); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/pattern/PatternMatcher.java b/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/pattern/PatternMatcher.java deleted file mode 100644 index 80b6f716cff..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/pattern/PatternMatcher.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue.ignore.pattern; - -import org.sonar.api.scan.issue.filter.FilterableIssue; - -import com.google.common.collect.LinkedHashMultimap; -import com.google.common.collect.Multimap; - -import java.util.Collection; -import java.util.Iterator; -import java.util.Set; - -public class PatternMatcher { - - private Multimap patternByComponent = LinkedHashMultimap.create(); - - public IssuePattern getMatchingPattern(FilterableIssue issue) { - IssuePattern matchingPattern = null; - Iterator patternIterator = getPatternsForComponent(issue.componentKey()).iterator(); - while(matchingPattern == null && patternIterator.hasNext()) { - IssuePattern nextPattern = patternIterator.next(); - if (nextPattern.match(issue)) { - matchingPattern = nextPattern; - } - } - return matchingPattern; - } - - public Collection getPatternsForComponent(String componentKey) { - return patternByComponent.get(componentKey); - } - - public void addPatternForComponent(String component, IssuePattern pattern) { - patternByComponent.put(component, pattern.forResource(component)); - } - - public void addPatternToExcludeResource(String resource) { - addPatternForComponent(resource, new IssuePattern(resource, "*").setCheckLines(false)); - } - - public void addPatternToExcludeLines(String resource, Set lineRanges) { - addPatternForComponent(resource, new IssuePattern(resource, "*", lineRanges).setCheckLines(true)); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/pattern/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/pattern/package-info.java deleted file mode 100644 index ebbc7b8371e..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/pattern/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.batch.issue.ignore.pattern; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/scanner/IssueExclusionsLoader.java b/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/scanner/IssueExclusionsLoader.java deleted file mode 100644 index 8622dc618eb..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/scanner/IssueExclusionsLoader.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue.ignore.scanner; - -import org.sonar.api.batch.fs.FileSystem; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.resources.Project; -import org.sonar.batch.issue.ignore.pattern.IssueExclusionPatternInitializer; -import org.sonar.batch.issue.ignore.pattern.IssueInclusionPatternInitializer; - -import java.nio.charset.Charset; - -public final class IssueExclusionsLoader { - - private final IssueExclusionsRegexpScanner regexpScanner; - private final IssueExclusionPatternInitializer exclusionPatternInitializer; - private final IssueInclusionPatternInitializer inclusionPatternInitializer; - private final FileSystem fileSystem; - - public IssueExclusionsLoader(IssueExclusionsRegexpScanner regexpScanner, IssueExclusionPatternInitializer exclusionPatternInitializer, - IssueInclusionPatternInitializer inclusionPatternInitializer, - FileSystem fileSystem) { - this.regexpScanner = regexpScanner; - this.exclusionPatternInitializer = exclusionPatternInitializer; - this.inclusionPatternInitializer = inclusionPatternInitializer; - this.fileSystem = fileSystem; - } - - public boolean shouldExecuteOnProject(Project project) { - return inclusionPatternInitializer.hasConfiguredPatterns() - || exclusionPatternInitializer.hasConfiguredPatterns(); - } - - /** - * {@inheritDoc} - */ - public void execute() { - Charset sourcesEncoding = fileSystem.encoding(); - - for (InputFile inputFile : fileSystem.inputFiles(fileSystem.predicates().all())) { - try { - String componentEffectiveKey = ((DefaultInputFile) inputFile).key(); - if (componentEffectiveKey != null) { - String path = inputFile.relativePath(); - inclusionPatternInitializer.initializePatternsForPath(path, componentEffectiveKey); - exclusionPatternInitializer.initializePatternsForPath(path, componentEffectiveKey); - if (exclusionPatternInitializer.hasFileContentPattern()) { - regexpScanner.scan(componentEffectiveKey, inputFile.file(), sourcesEncoding); - } - } - } catch (Exception e) { - throw new IllegalStateException("Unable to read the source file : '" + inputFile.absolutePath() + "' with the charset : '" - + sourcesEncoding.name() + "'.", e); - } - } - } - - @Override - public String toString() { - return "Issues Exclusions - Source Scanner"; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/scanner/IssueExclusionsRegexpScanner.java b/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/scanner/IssueExclusionsRegexpScanner.java deleted file mode 100644 index de465ad4dc5..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/scanner/IssueExclusionsRegexpScanner.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue.ignore.scanner; - -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.batch.BatchSide; -import org.sonar.batch.issue.ignore.pattern.IssueExclusionPatternInitializer; -import org.sonar.batch.issue.ignore.pattern.IssuePattern; -import org.sonar.batch.issue.ignore.pattern.LineRange; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.List; -import java.util.Set; - -@BatchSide -public class IssueExclusionsRegexpScanner { - - private static final Logger LOG = LoggerFactory.getLogger(IssueExclusionsRegexpScanner.class); - - private IssueExclusionPatternInitializer exclusionPatternInitializer; - private List allFilePatterns; - private List blockMatchers; - - // fields to be reset at every new scan - private DoubleRegexpMatcher currentMatcher; - private int fileLength; - private List lineExclusions; - private LineExclusion currentLineExclusion; - - public IssueExclusionsRegexpScanner(IssueExclusionPatternInitializer patternsInitializer) { - this.exclusionPatternInitializer = patternsInitializer; - - lineExclusions = Lists.newArrayList(); - allFilePatterns = Lists.newArrayList(); - blockMatchers = Lists.newArrayList(); - - for (IssuePattern pattern : patternsInitializer.getAllFilePatterns()) { - allFilePatterns.add(java.util.regex.Pattern.compile(pattern.getAllFileRegexp())); - } - for (IssuePattern pattern : patternsInitializer.getBlockPatterns()) { - blockMatchers.add(new DoubleRegexpMatcher( - java.util.regex.Pattern.compile(pattern.getBeginBlockRegexp()), - java.util.regex.Pattern.compile(pattern.getEndBlockRegexp()))); - } - - init(); - } - - private void init() { - currentMatcher = null; - fileLength = 0; - lineExclusions.clear(); - currentLineExclusion = null; - } - - public void scan(String resource, File file, Charset sourcesEncoding) throws IOException { - LOG.debug("Scanning {}", resource); - init(); - - List lines = FileUtils.readLines(file, sourcesEncoding.name()); - int lineIndex = 0; - for (String line : lines) { - lineIndex++; - if (line.trim().length() == 0) { - continue; - } - - // first check the single regexp patterns that can be used to totally exclude a file - for (java.util.regex.Pattern pattern : allFilePatterns) { - if (pattern.matcher(line).find()) { - exclusionPatternInitializer.getPatternMatcher().addPatternToExcludeResource(resource); - // nothing more to do on this file - LOG.debug("- Exclusion pattern '{}': every violation in this file will be ignored.", pattern); - return; - } - } - - // then check the double regexps if we're still here - checkDoubleRegexps(line, lineIndex); - } - - if (currentMatcher != null && !currentMatcher.hasSecondPattern()) { - // this will happen when there is a start block regexp but no end block regexp - endExclusion(lineIndex + 1); - } - - // now create the new line-based pattern for this file if there are exclusions - fileLength = lineIndex; - if (!lineExclusions.isEmpty()) { - Set lineRanges = convertLineExclusionsToLineRanges(); - LOG.debug("- Line exclusions found: {}", lineRanges); - exclusionPatternInitializer.getPatternMatcher().addPatternToExcludeLines(resource, lineRanges); - } - } - - private Set convertLineExclusionsToLineRanges() { - Set lineRanges = Sets.newHashSet(); - for (LineExclusion lineExclusion : lineExclusions) { - lineRanges.add(lineExclusion.toLineRange()); - } - return lineRanges; - } - - private void checkDoubleRegexps(String line, int lineIndex) { - if (currentMatcher == null) { - for (DoubleRegexpMatcher matcher : blockMatchers) { - if (matcher.matchesFirstPattern(line)) { - startExclusion(lineIndex); - currentMatcher = matcher; - break; - } - } - } else { - if (currentMatcher.matchesSecondPattern(line)) { - endExclusion(lineIndex); - currentMatcher = null; - } - } - } - - private void startExclusion(int lineIndex) { - currentLineExclusion = new LineExclusion(lineIndex); - lineExclusions.add(currentLineExclusion); - } - - private void endExclusion(int lineIndex) { - currentLineExclusion.setEnd(lineIndex); - currentLineExclusion = null; - } - - private class LineExclusion { - - private int start; - private int end; - - LineExclusion(int start) { - this.start = start; - this.end = -1; - } - - void setEnd(int end) { - this.end = end; - } - - public LineRange toLineRange() { - return new LineRange(start, end == -1 ? fileLength : end); - } - - } - - private static class DoubleRegexpMatcher { - - private java.util.regex.Pattern firstPattern; - private java.util.regex.Pattern secondPattern; - - DoubleRegexpMatcher(java.util.regex.Pattern firstPattern, java.util.regex.Pattern secondPattern) { - this.firstPattern = firstPattern; - this.secondPattern = secondPattern; - } - - boolean matchesFirstPattern(String line) { - return firstPattern.matcher(line).find(); - } - - boolean matchesSecondPattern(String line) { - return hasSecondPattern() && secondPattern.matcher(line).find(); - } - - boolean hasSecondPattern() { - return StringUtils.isNotEmpty(secondPattern.toString()); - } - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/scanner/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/scanner/package-info.java deleted file mode 100644 index 3beb574f061..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/ignore/scanner/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.batch.issue.ignore.scanner; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/issue/package-info.java deleted file mode 100644 index 75db5554d7f..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.batch.issue; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/DefaultServerLineHashesLoader.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/DefaultServerLineHashesLoader.java deleted file mode 100644 index 954997466fe..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/DefaultServerLineHashesLoader.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue.tracking; - -import org.sonar.batch.cache.WSLoader.LoadStrategy; - -import org.sonar.batch.cache.WSLoaderResult; -import org.sonar.batch.cache.WSLoader; -import org.apache.commons.lang.mutable.MutableBoolean; - -import javax.annotation.Nullable; - -import org.sonar.batch.util.BatchUtils; -import com.google.common.base.Splitter; -import com.google.common.collect.Iterators; -import org.sonar.api.utils.log.Loggers; -import org.sonar.api.utils.log.Profiler; - -public class DefaultServerLineHashesLoader implements ServerLineHashesLoader { - - private final WSLoader wsLoader; - - public DefaultServerLineHashesLoader(WSLoader wsLoader) { - this.wsLoader = wsLoader; - } - - @Override - public String[] getLineHashes(String fileKey, @Nullable MutableBoolean fromCache) { - String hashesFromWs = loadHashesFromWs(fileKey, fromCache); - return Iterators.toArray(Splitter.on('\n').split(hashesFromWs).iterator(), String.class); - } - - private String loadHashesFromWs(String fileKey, @Nullable MutableBoolean fromCache) { - Profiler profiler = Profiler.createIfDebug(Loggers.get(getClass())) - .addContext("file", fileKey) - .startDebug("Load line hashes"); - WSLoaderResult result = wsLoader.loadString("/api/sources/hash?key=" + BatchUtils.encodeForUrl(fileKey), LoadStrategy.CACHE_FIRST); - try { - if (fromCache != null) { - fromCache.setValue(result.isFromCache()); - } - return result.get(); - } finally { - if (result.isFromCache()) { - profiler.stopDebug("Load line hashes (done from cache)"); - } else { - profiler.stopDebug(); - } - } - } -} 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 deleted file mode 100644 index 3284b5a681b..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/FileHashes.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue.tracking; - -import org.sonar.api.batch.fs.internal.FileMetadata; -import org.sonar.api.batch.fs.internal.FileMetadata.LineHashConsumer; - -import com.google.common.collect.LinkedHashMultimap; -import com.google.common.collect.Multimap; -import org.apache.commons.codec.binary.Hex; -import org.apache.commons.lang.ObjectUtils; -import org.sonar.api.batch.fs.internal.DefaultInputFile; - -import javax.annotation.Nullable; - -import java.util.Collection; - -/** - * Wraps a {@link Sequence} to assign hash codes to elements. - */ -public final class FileHashes { - - private final String[] hashes; - private final Multimap linesByHash; - - private FileHashes(String[] hashes, Multimap linesByHash) { - this.hashes = hashes; - this.linesByHash = linesByHash; - } - - public static FileHashes create(String[] hashes) { - int size = hashes.length; - Multimap linesByHash = LinkedHashMultimap.create(); - for (int i = 0; i < size; i++) { - // indices in array are shifted one line before - linesByHash.put(hashes[i], i + 1); - } - return new FileHashes(hashes, linesByHash); - } - - public static FileHashes create(DefaultInputFile f) { - final byte[][] hashes = new byte[f.lines()][]; - FileMetadata.computeLineHashesForIssueTracking(f, new LineHashConsumer() { - - @Override - public void consume(int lineIdx, @Nullable byte[] hash) { - hashes[lineIdx - 1] = hash; - } - }); - - int size = hashes.length; - Multimap linesByHash = LinkedHashMultimap.create(); - String[] hexHashes = new String[size]; - for (int i = 0; i < size; i++) { - String hash = hashes[i] != null ? Hex.encodeHexString(hashes[i]) : ""; - hexHashes[i] = hash; - // indices in array are shifted one line before - linesByHash.put(hash, i + 1); - } - return new FileHashes(hexHashes, linesByHash); - } - - public int length() { - return hashes.length; - } - - public Collection getLinesForHash(String hash) { - return linesByHash.get(hash); - } - - public String[] hashes() { - return hashes; - } - - public String getHash(int line) { - // indices in array are shifted one line before - return (String) ObjectUtils.defaultIfNull(hashes[line - 1], ""); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTrackingInput.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTrackingInput.java deleted file mode 100644 index 031396b54d7..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTrackingInput.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue.tracking; - -import org.sonar.core.issue.tracking.Trackable; -import org.sonar.core.issue.tracking.BlockHashSequence; -import org.sonar.core.issue.tracking.LineHashSequence; - -import java.util.Collection; -import java.util.List; - -import org.sonar.core.issue.tracking.Input; - -public class IssueTrackingInput implements Input { - - private final Collection issues; - private final LineHashSequence lineHashes; - private final BlockHashSequence blockHashes; - - public IssueTrackingInput(Collection issues, List hashes) { - this.issues = issues; - this.lineHashes = new LineHashSequence(hashes); - this.blockHashes = BlockHashSequence.create(lineHashes); - } - - @Override - public LineHashSequence getLineHashSequence() { - return lineHashes; - } - - @Override - public BlockHashSequence getBlockHashSequence() { - return blockHashes; - } - - @Override - public Collection getIssues() { - return issues; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTransition.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTransition.java deleted file mode 100644 index fef29bfcb39..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTransition.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue.tracking; - -import org.sonar.batch.util.ProgressReport; -import org.sonar.batch.issue.IssueTransformer; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.resources.Project; -import org.sonar.batch.index.BatchComponent; -import org.sonar.batch.index.BatchComponentCache; -import org.sonar.batch.issue.IssueCache; -import org.sonar.batch.protocol.output.BatchReport; -import org.sonar.batch.protocol.output.BatchReportReader; -import org.sonar.batch.report.ReportPublisher; -import org.sonar.core.util.CloseableIterator; - -import javax.annotation.Nullable; - -import java.util.ArrayList; -import java.util.Date; -import java.util.LinkedList; -import java.util.List; -import java.util.concurrent.TimeUnit; - -@BatchSide -public class IssueTransition { - private final IssueCache issueCache; - private final BatchComponentCache componentCache; - private final ReportPublisher reportPublisher; - private final Date analysisDate; - @Nullable - private final LocalIssueTracking localIssueTracking; - - public IssueTransition(BatchComponentCache componentCache, IssueCache issueCache, ReportPublisher reportPublisher, - @Nullable LocalIssueTracking localIssueTracking) { - this.componentCache = componentCache; - this.issueCache = issueCache; - this.reportPublisher = reportPublisher; - this.localIssueTracking = localIssueTracking; - this.analysisDate = ((Project) componentCache.getRoot().resource()).getAnalysisDate(); - } - - public IssueTransition(BatchComponentCache componentCache, IssueCache issueCache, ReportPublisher reportPublisher) { - this(componentCache, issueCache, reportPublisher, null); - } - - public void execute() { - if (localIssueTracking != null) { - localIssueTracking.init(); - } - - BatchReportReader reader = new BatchReportReader(reportPublisher.getReportDir()); - int nbComponents = componentCache.all().size(); - - if (nbComponents == 0) { - return; - } - - ProgressReport progressReport = new ProgressReport("issue-tracking-report", TimeUnit.SECONDS.toMillis(10)); - progressReport.start("Performing issue tracking"); - int count = 0; - - try { - for (BatchComponent component : componentCache.all()) { - trackIssues(reader, component); - count++; - progressReport.message(count + "/" + nbComponents + " components tracked"); - } - } finally { - progressReport.stop(count + "/" + nbComponents + " components tracked"); - } - } - - public void trackIssues(BatchReportReader reader, BatchComponent component) { - // raw issues = all the issues created by rule engines during this module scan and not excluded by filters - List rawIssues = new LinkedList<>(); - try (CloseableIterator it = reader.readComponentIssues(component.batchId())) { - while (it.hasNext()) { - rawIssues.add(it.next()); - } - } catch (Exception e) { - throw new IllegalStateException("Can't read issues for " + component.key(), e); - } - - List trackedIssues; - if (localIssueTracking != null) { - trackedIssues = localIssueTracking.trackIssues(component, rawIssues, analysisDate); - } else { - trackedIssues = doTransition(rawIssues, component); - } - - for (TrackedIssue issue : trackedIssues) { - issueCache.put(issue); - } - } - - private static List doTransition(List rawIssues, BatchComponent component) { - List issues = new ArrayList<>(rawIssues.size()); - - for (BatchReport.Issue issue : rawIssues) { - issues.add(IssueTransformer.toTrackedIssue(component, issue, null)); - } - - return issues; - } - -} 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 deleted file mode 100644 index 5a6c739b956..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/LocalIssueTracking.java +++ /dev/null @@ -1,266 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue.tracking; - -import org.sonar.core.issue.tracking.Tracking; -import org.sonar.core.issue.tracking.Input; -import org.sonar.core.issue.tracking.Tracker; -import org.sonar.batch.issue.IssueTransformer; -import org.sonar.api.batch.fs.InputFile.Status; -import org.sonar.batch.analysis.DefaultAnalysisMode; -import com.google.common.annotations.VisibleForTesting; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Date; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; - -import org.sonar.api.batch.BatchSide; -import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.batch.rule.ActiveRule; -import org.sonar.api.batch.rule.ActiveRules; -import org.sonar.api.issue.Issue; -import org.sonar.api.resources.ResourceUtils; -import org.sonar.batch.index.BatchComponent; -import org.sonar.batch.protocol.output.BatchReport; -import org.sonar.batch.repository.ProjectRepositories; - -@BatchSide -public class LocalIssueTracking { - private final Tracker tracker; - private final ServerLineHashesLoader lastLineHashes; - private final ActiveRules activeRules; - private final ServerIssueRepository serverIssueRepository; - private final DefaultAnalysisMode mode; - - private boolean hasServerAnalysis; - - public LocalIssueTracking(Tracker tracker, ServerLineHashesLoader lastLineHashes, - ActiveRules activeRules, ServerIssueRepository serverIssueRepository, ProjectRepositories projectRepositories, DefaultAnalysisMode mode) { - this.tracker = tracker; - this.lastLineHashes = lastLineHashes; - this.serverIssueRepository = serverIssueRepository; - this.mode = mode; - this.activeRules = activeRules; - this.hasServerAnalysis = projectRepositories.lastAnalysisDate() != null; - } - - public void init() { - if (hasServerAnalysis) { - serverIssueRepository.load(); - } - } - - public List trackIssues(BatchComponent component, Collection reportIssues, Date analysisDate) { - List trackedIssues = new LinkedList<>(); - if (hasServerAnalysis) { - // all the issues that are not closed in db before starting this module scan, including manual issues - Collection serverIssues = loadServerIssues(component); - - if (shouldCopyServerIssues(component)) { - // raw issues should be empty, we just need to deal with server issues (SONAR-6931) - copyServerIssues(serverIssues, trackedIssues); - } else { - - SourceHashHolder sourceHashHolder = loadSourceHashes(component); - Collection rIssues = IssueTransformer.toTrackedIssue(component, reportIssues, sourceHashHolder); - - Input baseIssues = createBaseInput(serverIssues, sourceHashHolder); - Input rawIssues = createRawInput(rIssues, sourceHashHolder); - - Tracking track = tracker.track(rawIssues, baseIssues); - - addUnmatchedFromServer(track.getUnmatchedBases(), sourceHashHolder, trackedIssues); - addUnmatchedFromServer(track.getOpenManualIssuesByLine().values(), sourceHashHolder, trackedIssues); - mergeMatched(track, trackedIssues, rIssues); - addUnmatchedFromReport(track.getUnmatchedRaws(), trackedIssues, analysisDate); - } - } - - if (hasServerAnalysis && ResourceUtils.isRootProject(component.resource())) { - // issues that relate to deleted components - addIssuesOnDeletedComponents(trackedIssues); - } - - return trackedIssues; - } - - private static Input createBaseInput(Collection serverIssues, @Nullable SourceHashHolder sourceHashHolder) { - List refHashes; - - if (sourceHashHolder != null && sourceHashHolder.getHashedReference() != null) { - refHashes = Arrays.asList(sourceHashHolder.getHashedReference().hashes()); - } else { - refHashes = new ArrayList<>(0); - } - - return new IssueTrackingInput<>(serverIssues, refHashes); - } - - private static Input createRawInput(Collection rIssues, @Nullable SourceHashHolder sourceHashHolder) { - List baseHashes; - if (sourceHashHolder != null && sourceHashHolder.getHashedSource() != null) { - baseHashes = Arrays.asList(sourceHashHolder.getHashedSource().hashes()); - } else { - baseHashes = new ArrayList<>(0); - } - - return new IssueTrackingInput<>(rIssues, baseHashes); - } - - private boolean shouldCopyServerIssues(BatchComponent component) { - if (!mode.scanAllFiles() && component.isFile()) { - DefaultInputFile inputFile = (DefaultInputFile) component.inputComponent(); - if (inputFile.status() == Status.SAME) { - return true; - } - } - return false; - } - - private void copyServerIssues(Collection serverIssues, List trackedIssues) { - for (ServerIssueFromWs serverIssue : serverIssues) { - org.sonar.batch.protocol.input.BatchInput.ServerIssue unmatchedPreviousIssue = serverIssue.getDto(); - TrackedIssue unmatched = IssueTransformer.toTrackedIssue(unmatchedPreviousIssue); - - ActiveRule activeRule = activeRules.find(unmatched.getRuleKey()); - unmatched.setNew(false); - - if (activeRule == null) { - // rule removed - IssueTransformer.resolveRemove(unmatched); - } - - trackedIssues.add(unmatched); - } - } - - @CheckForNull - private SourceHashHolder loadSourceHashes(BatchComponent component) { - SourceHashHolder sourceHashHolder = null; - if (component.isFile()) { - DefaultInputFile file = (DefaultInputFile) component.inputComponent(); - if (file == null) { - throw new IllegalStateException("Resource " + component.resource() + " was not found in InputPath cache"); - } - sourceHashHolder = new SourceHashHolder(file, lastLineHashes); - } - return sourceHashHolder; - } - - private Collection loadServerIssues(BatchComponent component) { - Collection serverIssues = new ArrayList<>(); - for (org.sonar.batch.protocol.input.BatchInput.ServerIssue previousIssue : serverIssueRepository.byComponent(component)) { - serverIssues.add(new ServerIssueFromWs(previousIssue)); - } - return serverIssues; - } - - @VisibleForTesting - protected void mergeMatched(Tracking result, Collection mergeTo, Collection rawIssues) { - for (Map.Entry e : result.getMatchedRaws().entrySet()) { - org.sonar.batch.protocol.input.BatchInput.ServerIssue dto = e.getValue().getDto(); - TrackedIssue tracked = e.getKey(); - - // invariant fields - tracked.setKey(dto.getKey()); - - // non-persisted fields - tracked.setNew(false); - - // fields to update with old values - tracked.setResolution(dto.hasResolution() ? dto.getResolution() : null); - tracked.setStatus(dto.getStatus()); - tracked.setAssignee(dto.hasAssigneeLogin() ? dto.getAssigneeLogin() : null); - tracked.setCreationDate(new Date(dto.getCreationDate())); - - if (dto.getManualSeverity()) { - // Severity overriden by user - tracked.setSeverity(dto.getSeverity().name()); - } - mergeTo.add(tracked); - } - } - - private void addUnmatchedFromServer(Iterable unmatchedIssues, SourceHashHolder sourceHashHolder, Collection mergeTo) { - for (ServerIssueFromWs unmatchedIssue : unmatchedIssues) { - org.sonar.batch.protocol.input.BatchInput.ServerIssue unmatchedPreviousIssue = unmatchedIssue.getDto(); - TrackedIssue unmatched = IssueTransformer.toTrackedIssue(unmatchedPreviousIssue); - if (unmatchedIssue.getRuleKey().isManual() && !Issue.STATUS_CLOSED.equals(unmatchedPreviousIssue.getStatus())) { - relocateManualIssue(unmatched, unmatchedIssue, sourceHashHolder); - } - updateUnmatchedIssue(unmatched, false /* manual issues can be kept open */); - mergeTo.add(unmatched); - } - } - - private static void addUnmatchedFromReport(Iterable rawIssues, Collection trackedIssues, Date analysisDate) { - for (TrackedIssue rawIssue : rawIssues) { - rawIssue.setCreationDate(analysisDate); - trackedIssues.add(rawIssue); - } - } - - private void addIssuesOnDeletedComponents(Collection issues) { - for (org.sonar.batch.protocol.input.BatchInput.ServerIssue previous : serverIssueRepository.issuesOnMissingComponents()) { - TrackedIssue dead = IssueTransformer.toTrackedIssue(previous); - updateUnmatchedIssue(dead, true); - issues.add(dead); - } - } - - private void updateUnmatchedIssue(TrackedIssue issue, boolean forceEndOfLife) { - ActiveRule activeRule = activeRules.find(issue.getRuleKey()); - issue.setNew(false); - - boolean manualIssue = issue.getRuleKey().isManual(); - boolean isRemovedRule = activeRule == null; - - if (isRemovedRule) { - IssueTransformer.resolveRemove(issue); - } else if (forceEndOfLife || !manualIssue) { - IssueTransformer.close(issue); - } - } - - private static void relocateManualIssue(TrackedIssue newIssue, ServerIssueFromWs oldIssue, SourceHashHolder sourceHashHolder) { - Integer previousLine = oldIssue.getLine(); - if (previousLine == null) { - return; - } - - Collection newLinesWithSameHash = sourceHashHolder.getNewLinesMatching(previousLine); - if (newLinesWithSameHash.isEmpty()) { - if (previousLine > sourceHashHolder.getHashedSource().length()) { - IssueTransformer.resolveRemove(newIssue); - } - } else if (newLinesWithSameHash.size() == 1) { - Integer newLine = newLinesWithSameHash.iterator().next(); - newIssue.setStartLine(newLine); - newIssue.setEndLine(newLine); - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/RollingFileHashes.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/RollingFileHashes.java deleted file mode 100644 index aaf2ba7bdf5..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/RollingFileHashes.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue.tracking; - -/** - * Compute hashes of block around each line - */ -public class RollingFileHashes { - - final int[] rollingHashes; - - private RollingFileHashes(int[] hashes) { - this.rollingHashes = hashes; - } - - public static RollingFileHashes create(FileHashes hashes, int halfBlockSize) { - int size = hashes.length(); - int[] rollingHashes = new int[size]; - - RollingHashCalculator hashCalulator = new RollingHashCalculator(halfBlockSize * 2 + 1); - for (int i = 1; i <= Math.min(size, halfBlockSize + 1); i++) { - hashCalulator.add(hashes.getHash(i).hashCode()); - } - for (int i = 1; i <= size; i++) { - rollingHashes[i - 1] = hashCalulator.getHash(); - if (i - halfBlockSize > 0) { - hashCalulator.remove(hashes.getHash(i - halfBlockSize).hashCode()); - } - if (i + 1 + halfBlockSize <= size) { - hashCalulator.add(hashes.getHash(i + 1 + halfBlockSize).hashCode()); - } else { - hashCalulator.add(0); - } - } - - return new RollingFileHashes(rollingHashes); - } - - public int getHash(int line) { - return rollingHashes[line - 1]; - } - - private static class RollingHashCalculator { - - private static final int PRIME_BASE = 31; - - private final int power; - private int hash; - - public RollingHashCalculator(int size) { - int pow = 1; - for (int i = 0; i < size - 1; i++) { - pow = pow * PRIME_BASE; - } - this.power = pow; - } - - public void add(int value) { - hash = hash * PRIME_BASE + value; - } - - public void remove(int value) { - hash = hash - power * value; - } - - public int getHash() { - return hash; - } - - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerIssueFromWs.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerIssueFromWs.java deleted file mode 100644 index bbc68cb1455..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerIssueFromWs.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue.tracking; - -import javax.annotation.CheckForNull; - -import org.sonar.core.issue.tracking.Trackable; -import org.sonar.api.rule.RuleKey; - -public class ServerIssueFromWs implements Trackable { - - private org.sonar.batch.protocol.input.BatchInput.ServerIssue dto; - - public ServerIssueFromWs(org.sonar.batch.protocol.input.BatchInput.ServerIssue dto) { - this.dto = dto; - } - - public org.sonar.batch.protocol.input.BatchInput.ServerIssue getDto() { - return dto; - } - - public String key() { - return dto.getKey(); - } - - @Override - public RuleKey getRuleKey() { - return RuleKey.of(dto.getRuleRepository(), dto.getRuleKey()); - } - - @Override - @CheckForNull - public String getLineHash() { - return dto.hasChecksum() ? dto.getChecksum() : null; - } - - @Override - @CheckForNull - public Integer getLine() { - return dto.hasLine() ? dto.getLine() : null; - } - - @Override - public String getMessage() { - return dto.hasMsg() ? dto.getMsg() : ""; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerIssueRepository.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerIssueRepository.java deleted file mode 100644 index eb864b04c61..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerIssueRepository.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue.tracking; - -import com.google.common.base.Function; -import javax.annotation.Nullable; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.batch.InstantiationStrategy; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; -import org.sonar.api.utils.log.Profiler; -import org.sonar.batch.index.BatchComponent; -import org.sonar.batch.index.BatchComponentCache; -import org.sonar.batch.index.Cache; -import org.sonar.batch.index.Caches; -import org.sonar.batch.protocol.input.BatchInput.ServerIssue; -import org.sonar.batch.repository.ServerIssuesLoader; -import org.sonar.batch.scan.ImmutableProjectReactor; -import org.sonar.core.component.ComponentKeys; - -@InstantiationStrategy(InstantiationStrategy.PER_BATCH) -@BatchSide -public class ServerIssueRepository { - - private static final Logger LOG = Loggers.get(ServerIssueRepository.class); - private static final String LOG_MSG = "Load server issues"; - - private final Caches caches; - private Cache issuesCache; - private final ServerIssuesLoader previousIssuesLoader; - private final ImmutableProjectReactor reactor; - private final BatchComponentCache resourceCache; - - public ServerIssueRepository(Caches caches, ServerIssuesLoader previousIssuesLoader, ImmutableProjectReactor reactor, BatchComponentCache resourceCache) { - this.caches = caches; - this.previousIssuesLoader = previousIssuesLoader; - this.reactor = reactor; - this.resourceCache = resourceCache; - } - - public void load() { - Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG); - this.issuesCache = caches.createCache("previousIssues"); - caches.registerValueCoder(ServerIssue.class, new ServerIssueValueCoder()); - boolean fromCache = previousIssuesLoader.load(reactor.getRoot().getKeyWithBranch(), new SaveIssueConsumer()); - profiler.stopInfo(fromCache); - } - - public Iterable byComponent(BatchComponent component) { - return issuesCache.values(component.batchId()); - } - - private class SaveIssueConsumer implements Function { - - @Override - public Void apply(@Nullable ServerIssue issue) { - if (issue == null) { - return null; - } - String componentKey = ComponentKeys.createEffectiveKey(issue.getModuleKey(), issue.hasPath() ? issue.getPath() : null); - BatchComponent r = resourceCache.get(componentKey); - if (r == null) { - // Deleted resource - issuesCache.put(0, issue.getKey(), issue); - } else { - issuesCache.put(r.batchId(), issue.getKey(), issue); - } - return null; - } - } - - public Iterable issuesOnMissingComponents() { - return issuesCache.values(0); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerIssueValueCoder.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerIssueValueCoder.java deleted file mode 100644 index c3c6f26b451..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerIssueValueCoder.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue.tracking; - -import com.persistit.Value; -import com.persistit.encoding.CoderContext; -import com.persistit.encoding.ValueCoder; -import org.sonar.batch.protocol.input.BatchInput.ServerIssue; - -import java.io.IOException; - -public class ServerIssueValueCoder implements ValueCoder { - - @Override - public void put(Value value, Object object, CoderContext context) { - ServerIssue issue = (ServerIssue) object; - value.putByteArray(issue.toByteArray()); - } - - @Override - public Object get(Value value, Class clazz, CoderContext context) { - try { - return ServerIssue.parseFrom(value.getByteArray()); - } catch (IOException e) { - throw new IllegalStateException("Unable to read issue from cache", e); - } - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerLineHashesLoader.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerLineHashesLoader.java deleted file mode 100644 index fb0b32d0d2b..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerLineHashesLoader.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue.tracking; - -import org.apache.commons.lang.mutable.MutableBoolean; - -import javax.annotation.Nullable; - -import org.sonar.api.batch.BatchSide; - -@BatchSide -public interface ServerLineHashesLoader { - - String[] getLineHashes(String fileKey, @Nullable MutableBoolean fromCache); -} 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 deleted file mode 100644 index 583a92f0b9d..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/SourceHashHolder.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue.tracking; - -import com.google.common.collect.ImmutableSet; -import org.sonar.api.batch.fs.InputFile.Status; -import org.sonar.api.batch.fs.internal.DefaultInputFile; - -import javax.annotation.CheckForNull; - -import java.util.Collection; - -public class SourceHashHolder { - - private final ServerLineHashesLoader lastSnapshots; - - private FileHashes hashedReference; - private FileHashes hashedSource; - private DefaultInputFile inputFile; - - public SourceHashHolder(DefaultInputFile inputFile, ServerLineHashesLoader lastSnapshots) { - this.inputFile = inputFile; - this.lastSnapshots = lastSnapshots; - } - - private void initHashes() { - if (hashedSource == null) { - hashedSource = FileHashes.create(inputFile); - Status status = inputFile.status(); - if (status == Status.ADDED) { - hashedReference = null; - } else if (status == Status.SAME) { - hashedReference = hashedSource; - } else { - String[] lineHashes = lastSnapshots.getLineHashes(inputFile.key(), null); - hashedReference = lineHashes != null ? FileHashes.create(lineHashes) : null; - } - } - } - - @CheckForNull - public FileHashes getHashedReference() { - initHashes(); - return hashedReference; - } - - public FileHashes getHashedSource() { - initHashes(); - return hashedSource; - } - - public Collection getNewLinesMatching(Integer originLine) { - FileHashes reference = getHashedReference(); - if (reference == null) { - return ImmutableSet.of(); - } else { - return getHashedSource().getLinesForHash(reference.getHash(originLine)); - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/TrackedIssue.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/TrackedIssue.java deleted file mode 100644 index ea303bf6a4f..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/TrackedIssue.java +++ /dev/null @@ -1,262 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.issue.tracking; - -import com.google.common.base.Preconditions; -import java.io.Serializable; -import java.util.Date; -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; -import org.apache.commons.lang.builder.ToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; -import org.sonar.api.rule.RuleKey; -import org.sonar.core.issue.tracking.Trackable; - -public class TrackedIssue implements Trackable, Serializable { - private static final long serialVersionUID = -1755017079070964287L; - - private RuleKey ruleKey; - private String key; - private String severity; - private Integer startLine; - private Integer startLineOffset; - private Integer endLine; - private Integer endLineOffset; - private Double gap; - private boolean isNew; - private Date creationDate; - private String resolution; - private String status; - private String assignee; - private String reporter; - private String componentKey; - private String message; - - private transient FileHashes hashes; - - public TrackedIssue() { - hashes = null; - } - - public TrackedIssue(@Nullable FileHashes hashes) { - this.hashes = hashes; - } - - @Override - @CheckForNull - public String getLineHash() { - if (getLine() == null || hashes == null) { - return null; - } - - int line = getLine(); - Preconditions.checkState(line <= hashes.length(), "Invalid line number for issue %s. File has only %s line(s)", this, hashes.length()); - - return hashes.getHash(line); - } - - @Override - public String getMessage() { - return message; - } - - public TrackedIssue setMessage(String message) { - this.message = message; - return this; - } - - public String componentKey() { - return componentKey; - } - - public TrackedIssue setComponentKey(String componentKey) { - this.componentKey = componentKey; - return this; - } - - public String key() { - return key; - } - - public Integer startLine() { - return startLine; - } - - @Override - public Integer getLine() { - return startLine; - } - - public TrackedIssue setStartLine(Integer startLine) { - this.startLine = startLine; - return this; - } - - public Integer startLineOffset() { - return startLineOffset; - } - - public TrackedIssue setStartLineOffset(Integer startLineOffset) { - this.startLineOffset = startLineOffset; - return this; - } - - public Integer endLine() { - return endLine; - } - - public TrackedIssue setEndLine(Integer endLine) { - this.endLine = endLine; - return this; - } - - public Integer endLineOffset() { - return endLineOffset; - } - - public TrackedIssue setEndLineOffset(Integer endLineOffset) { - this.endLineOffset = endLineOffset; - return this; - } - - public TrackedIssue setKey(String key) { - this.key = key; - return this; - } - - public String assignee() { - return assignee; - } - - public TrackedIssue setAssignee(String assignee) { - this.assignee = assignee; - return this; - } - - public String reporter() { - return reporter; - } - - public TrackedIssue setReporter(String reporter) { - this.reporter = reporter; - return this; - } - - public String resolution() { - return resolution; - } - - public TrackedIssue setResolution(String resolution) { - this.resolution = resolution; - return this; - } - - public String status() { - return status; - } - - public TrackedIssue setStatus(String status) { - this.status = status; - return this; - } - - @Override - public RuleKey getRuleKey() { - return ruleKey; - } - - public String severity() { - return severity; - } - - public Double gap() { - return gap; - } - - public Date getCreationDate() { - return creationDate; - } - - public boolean isNew() { - return isNew; - } - - public TrackedIssue setNew(boolean isNew) { - this.isNew = isNew; - return this; - } - - public Date creationDate() { - return creationDate; - } - - public TrackedIssue setCreationDate(Date creationDate) { - this.creationDate = creationDate; - return this; - } - - public TrackedIssue setRuleKey(RuleKey ruleKey) { - this.ruleKey = ruleKey; - return this; - } - - public TrackedIssue setSeverity(String severity) { - this.severity = severity; - return this; - } - - public TrackedIssue setGap(Double gap) { - this.gap = gap; - return this; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((key == null) ? 0 : key.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - TrackedIssue other = (TrackedIssue) obj; - if (key == null) { - if (other.key != null) { - return false; - } - } else if (!key.equals(other.key)) { - return false; - } - return true; - } - - @Override - public String toString() { - return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/package-info.java deleted file mode 100644 index 148dc77f0f4..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.batch.issue.tracking; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/FakePluginInstaller.java b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/FakePluginInstaller.java deleted file mode 100644 index 71205c7b08d..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/FakePluginInstaller.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.mediumtest; - -import java.io.File; -import java.util.HashMap; -import java.util.Map; -import org.sonar.api.SonarPlugin; -import org.sonar.batch.bootstrap.PluginInstaller; -import org.sonar.core.platform.PluginInfo; - -public class FakePluginInstaller implements PluginInstaller { - public static final String MEDIUM_TEST_ENABLED = "sonar.mediumTest.enabled"; - - private final Map infosByKeys = new HashMap<>(); - private final Map instancesByKeys = new HashMap<>(); - - public FakePluginInstaller add(String pluginKey, File jarFile) { - infosByKeys.put(pluginKey, PluginInfo.create(jarFile)); - return this; - } - - public FakePluginInstaller add(String pluginKey, SonarPlugin instance) { - instancesByKeys.put(pluginKey, instance); - return this; - } - - @Override - public Map installRemotes() { - return infosByKeys; - } - - @Override - public Map installLocals() { - return instancesByKeys; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/ScanTaskObserver.java b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/ScanTaskObserver.java deleted file mode 100644 index 05b9f338eef..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/ScanTaskObserver.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.mediumtest; - -import org.sonar.api.batch.BatchSide; -import org.sonar.api.ExtensionPoint; -import org.sonar.batch.scan.ProjectScanContainer; - -@BatchSide -@ExtensionPoint -public interface ScanTaskObserver { - - void scanTaskCompleted(ProjectScanContainer container); - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/ScanTaskObservers.java b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/ScanTaskObservers.java deleted file mode 100644 index 90e092cad77..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/ScanTaskObservers.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.mediumtest; - -import org.sonar.batch.scan.ProjectScanContainer; - -public class ScanTaskObservers { - - private ScanTaskObserver[] observers; - private ProjectScanContainer projectScanContainer; - - public ScanTaskObservers(ProjectScanContainer projectScanContainer, ScanTaskObserver... observers) { - this.projectScanContainer = projectScanContainer; - this.observers = observers; - } - - public ScanTaskObservers(ProjectScanContainer projectScanContainer) { - this(projectScanContainer, new ScanTaskObserver[0]); - } - - public void notifyEndOfScanTask() { - for (ScanTaskObserver scanTaskObserver : observers) { - scanTaskObserver.scanTaskCompleted(projectScanContainer); - } - } - -} 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 deleted file mode 100644 index 04d2b8843e7..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java +++ /dev/null @@ -1,292 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.mediumtest; - -import com.google.common.collect.Iterators; -import com.google.common.collect.Lists; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; -import org.apache.commons.io.FileUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.batch.AnalysisMode; -import org.sonar.api.batch.fs.InputComponent; -import org.sonar.api.batch.fs.InputDir; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.TextPointer; -import org.sonar.api.batch.fs.TextRange; -import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.batch.sensor.highlighting.TypeOfText; -import org.sonar.batch.issue.IssueCache; -import org.sonar.batch.issue.tracking.TrackedIssue; -import org.sonar.batch.protocol.output.BatchReport; -import org.sonar.batch.protocol.output.BatchReport.Component; -import org.sonar.batch.protocol.output.BatchReport.Metadata; -import org.sonar.batch.protocol.output.BatchReport.Symbol; -import org.sonar.batch.protocol.output.BatchReportReader; -import org.sonar.batch.report.BatchReportUtils; -import org.sonar.batch.report.ReportPublisher; -import org.sonar.batch.scan.ProjectScanContainer; -import org.sonar.batch.scan.filesystem.InputPathCache; -import org.sonar.core.util.CloseableIterator; - -public class TaskResult implements org.sonar.batch.mediumtest.ScanTaskObserver { - - private static final Logger LOG = LoggerFactory.getLogger(TaskResult.class); - - private List issues = new ArrayList<>(); - private Map inputFiles = new HashMap<>(); - private Map reportComponents = new HashMap<>(); - private Map inputDirs = new HashMap<>(); - private BatchReportReader reader; - - @Override - public void scanTaskCompleted(ProjectScanContainer container) { - LOG.info("Store analysis results in memory for later assertions in medium test"); - for (TrackedIssue issue : container.getComponentByType(IssueCache.class).all()) { - issues.add(issue); - } - - ReportPublisher reportPublisher = container.getComponentByType(ReportPublisher.class); - reader = new BatchReportReader(reportPublisher.getReportDir()); - if (!container.getComponentByType(AnalysisMode.class).isIssues()) { - Metadata readMetadata = getReportReader().readMetadata(); - int rootComponentRef = readMetadata.getRootComponentRef(); - storeReportComponents(rootComponentRef, null, readMetadata.hasBranch() ? readMetadata.getBranch() : null); - } - - storeFs(container); - - } - - private void storeReportComponents(int componentRef, String parentModuleKey, @Nullable String branch) { - Component component = getReportReader().readComponent(componentRef); - if (component.hasKey()) { - reportComponents.put(component.getKey() + (branch != null ? ":" + branch : ""), component); - } else { - reportComponents.put(parentModuleKey + (branch != null ? ":" + branch : "") + ":" + component.getPath(), component); - } - for (int childId : component.getChildRefList()) { - storeReportComponents(childId, component.hasKey() ? component.getKey() : parentModuleKey, branch); - } - - } - - public BatchReportReader getReportReader() { - return reader; - } - - private void storeFs(ProjectScanContainer container) { - InputPathCache inputFileCache = container.getComponentByType(InputPathCache.class); - for (InputFile inputPath : inputFileCache.allFiles()) { - inputFiles.put(inputPath.relativePath(), inputPath); - } - for (InputDir inputPath : inputFileCache.allDirs()) { - inputDirs.put(inputPath.relativePath(), inputPath); - } - } - - public List trackedIssues() { - return issues; - } - - public Component getReportComponent(String key) { - return reportComponents.get(key); - } - - public List issuesFor(InputComponent inputComponent) { - int ref = reportComponents.get(inputComponent.key()).getRef(); - return issuesFor(ref); - } - - public List issuesFor(Component reportComponent) { - int ref = reportComponent.getRef(); - return issuesFor(ref); - } - - private List issuesFor(int ref) { - List result = Lists.newArrayList(); - try (CloseableIterator it = reader.readComponentIssues(ref)) { - while (it.hasNext()) { - result.add(it.next()); - } - } - return result; - } - - public Collection inputFiles() { - return inputFiles.values(); - } - - @CheckForNull - public InputFile inputFile(String relativePath) { - return inputFiles.get(relativePath); - } - - public Collection inputDirs() { - return inputDirs.values(); - } - - @CheckForNull - public InputDir inputDir(String relativePath) { - return inputDirs.get(relativePath); - } - - public Map> allMeasures() { - Map> result = new HashMap<>(); - for (Map.Entry component : reportComponents.entrySet()) { - List measures = new ArrayList<>(); - try (CloseableIterator it = reader.readComponentMeasures(component.getValue().getRef())) { - Iterators.addAll(measures, it); - } - result.put(component.getKey(), measures); - } - return result; - } - - /** - * Get highlighting types at a given position in an inputfile - * @param lineOffset 0-based offset in file - */ - public List highlightingTypeFor(InputFile file, int line, int lineOffset) { - int ref = reportComponents.get(((DefaultInputFile) file).key()).getRef(); - if (!reader.hasSyntaxHighlighting(ref)) { - return Collections.emptyList(); - } - TextPointer pointer = file.newPointer(line, lineOffset); - List result = new ArrayList<>(); - try (CloseableIterator it = reader.readComponentSyntaxHighlighting(ref)) { - while (it.hasNext()) { - BatchReport.SyntaxHighlighting rule = it.next(); - TextRange ruleRange = toRange(file, rule.getRange()); - if (ruleRange.start().compareTo(pointer) <= 0 && ruleRange.end().compareTo(pointer) > 0) { - result.add(BatchReportUtils.toBatchType(rule.getType())); - } - } - } catch (Exception e) { - throw new IllegalStateException("Can't read syntax highlighting for " + file.absolutePath(), e); - } - return result; - } - - private static TextRange toRange(InputFile file, BatchReport.TextRange reportRange) { - return file.newRange(file.newPointer(reportRange.getStartLine(), reportRange.getStartOffset()), file.newPointer(reportRange.getEndLine(), reportRange.getEndOffset())); - } - - /** - * Get list of all start positions of a symbol in an inputfile - * @param symbolStartLine 0-based start offset for the symbol in file - * @param symbolStartLineOffset 0-based end offset for the symbol in file - */ - @CheckForNull - public List symbolReferencesFor(InputFile file, int symbolStartLine, int symbolStartLineOffset) { - int ref = reportComponents.get(((DefaultInputFile) file).key()).getRef(); - try (CloseableIterator symbols = getReportReader().readComponentSymbols(ref)) { - while (symbols.hasNext()) { - Symbol symbol = symbols.next(); - if (symbol.getDeclaration().getStartLine() == symbolStartLine && symbol.getDeclaration().getStartOffset() == symbolStartLineOffset) { - return symbol.getReferenceList(); - } - } - } - return Collections.emptyList(); - } - - public List duplicationsFor(InputFile file) { - List result = new ArrayList<>(); - int ref = reportComponents.get(((DefaultInputFile) file).key()).getRef(); - try (CloseableIterator it = getReportReader().readComponentDuplications(ref)) { - while (it.hasNext()) { - result.add(it.next()); - } - } catch (Exception e) { - throw new IllegalStateException(e); - } - return result; - } - - public List duplicationBlocksFor(InputFile file) { - List result = new ArrayList<>(); - int ref = reportComponents.get(((DefaultInputFile) file).key()).getRef(); - try (CloseableIterator it = getReportReader().readCpdTextBlocks(ref)) { - while (it.hasNext()) { - result.add(it.next()); - } - } catch (Exception e) { - throw new IllegalStateException(e); - } - return result; - } - - @CheckForNull - public BatchReport.Coverage coverageFor(InputFile file, int line) { - int ref = reportComponents.get(((DefaultInputFile) file).key()).getRef(); - try (CloseableIterator it = getReportReader().readComponentCoverage(ref)) { - while (it.hasNext()) { - BatchReport.Coverage coverage = it.next(); - if (coverage.getLine() == line) { - return coverage; - } - } - } catch (Exception e) { - throw new IllegalStateException(e); - } - return null; - } - - public BatchReport.Test testExecutionFor(InputFile testFile, String testName) { - int ref = reportComponents.get(((DefaultInputFile) testFile).key()).getRef(); - try (InputStream inputStream = FileUtils.openInputStream(getReportReader().readTests(ref))) { - BatchReport.Test test = BatchReport.Test.PARSER.parseDelimitedFrom(inputStream); - while (test != null) { - if (test.getName().equals(testName)) { - return test; - } - test = BatchReport.Test.PARSER.parseDelimitedFrom(inputStream); - } - } catch (Exception e) { - throw new IllegalStateException(e); - } - return null; - } - - public BatchReport.CoverageDetail coveragePerTestFor(InputFile testFile, String testName) { - int ref = reportComponents.get(((DefaultInputFile) testFile).key()).getRef(); - try (InputStream inputStream = FileUtils.openInputStream(getReportReader().readCoverageDetails(ref))) { - BatchReport.CoverageDetail details = BatchReport.CoverageDetail.PARSER.parseDelimitedFrom(inputStream); - while (details != null) { - if (details.getTestName().equals(testName)) { - return details; - } - details = BatchReport.CoverageDetail.PARSER.parseDelimitedFrom(inputStream); - } - } catch (Exception e) { - throw new IllegalStateException(e); - } - return null; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/package-info.java deleted file mode 100644 index 2cc10ab66ff..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.batch.mediumtest; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-batch/src/main/java/org/sonar/batch/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/package-info.java deleted file mode 100644 index 408dd9f93a6..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.batch; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/AbstractPhaseEvent.java b/sonar-batch/src/main/java/org/sonar/batch/phases/AbstractPhaseEvent.java deleted file mode 100644 index df8bc690534..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/AbstractPhaseEvent.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.phases; - -import org.sonar.api.batch.events.EventHandler; -import org.sonar.batch.events.BatchEvent; - -public abstract class AbstractPhaseEvent extends BatchEvent { - - private final boolean start; - - public AbstractPhaseEvent(boolean start) { - this.start = start; - } - - public final boolean isStart() { - return start; - } - - public final boolean isEnd() { - return !start; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/AbstractPhaseExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/phases/AbstractPhaseExecutor.java deleted file mode 100644 index c388b75f1f3..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/AbstractPhaseExecutor.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.phases; - -import org.sonar.api.batch.SensorContext; -import org.sonar.api.resources.Project; -import org.sonar.batch.events.BatchStepEvent; -import org.sonar.batch.events.EventBus; -import org.sonar.batch.index.DefaultIndex; -import org.sonar.batch.issue.ignore.scanner.IssueExclusionsLoader; -import org.sonar.batch.rule.QProfileVerifier; -import org.sonar.batch.scan.filesystem.DefaultModuleFileSystem; -import org.sonar.batch.scan.filesystem.FileSystemLogger; - -public abstract class AbstractPhaseExecutor { - - private final EventBus eventBus; - private final PostJobsExecutor postJobsExecutor; - private final InitializersExecutor initializersExecutor; - private final SensorsExecutor sensorsExecutor; - private final SensorContext sensorContext; - private final DefaultIndex index; - private final ProjectInitializer pi; - private final FileSystemLogger fsLogger; - private final DefaultModuleFileSystem fs; - private final QProfileVerifier profileVerifier; - private final IssueExclusionsLoader issueExclusionsLoader; - - public AbstractPhaseExecutor(InitializersExecutor initializersExecutor, PostJobsExecutor postJobsExecutor, SensorsExecutor sensorsExecutor, - SensorContext sensorContext, DefaultIndex index, - EventBus eventBus, ProjectInitializer pi, - FileSystemLogger fsLogger, DefaultModuleFileSystem fs, QProfileVerifier profileVerifier, - IssueExclusionsLoader issueExclusionsLoader) { - this.postJobsExecutor = postJobsExecutor; - this.initializersExecutor = initializersExecutor; - this.sensorsExecutor = sensorsExecutor; - this.sensorContext = sensorContext; - this.index = index; - this.eventBus = eventBus; - this.pi = pi; - this.fsLogger = fsLogger; - this.fs = fs; - this.profileVerifier = profileVerifier; - this.issueExclusionsLoader = issueExclusionsLoader; - } - - /** - * Executed on each module - */ - public final void execute(Project module) { - pi.execute(module); - - eventBus.fireEvent(new ProjectAnalysisEvent(module, true)); - - executeInitializersPhase(); - - // Index and lock the filesystem - indexFs(); - - // Log detected languages and their profiles after FS is indexed and languages detected - profileVerifier.execute(); - - // Initialize issue exclusions - initIssueExclusions(); - - sensorsExecutor.execute(sensorContext); - - if (module.isRoot()) { - executeOnRoot(); - postJobsExecutor.execute(sensorContext); - } - cleanMemory(); - eventBus.fireEvent(new ProjectAnalysisEvent(module, false)); - } - - protected abstract void executeOnRoot(); - - private void initIssueExclusions() { - String stepName = "Init issue exclusions"; - eventBus.fireEvent(new BatchStepEvent(stepName, true)); - issueExclusionsLoader.execute(); - eventBus.fireEvent(new BatchStepEvent(stepName, false)); - } - - private void indexFs() { - String stepName = "Index filesystem"; - eventBus.fireEvent(new BatchStepEvent(stepName, true)); - fs.index(); - eventBus.fireEvent(new BatchStepEvent(stepName, false)); - } - - private void executeInitializersPhase() { - initializersExecutor.execute(); - fsLogger.log(); - } - - private void cleanMemory() { - String cleanMemory = "Clean memory"; - eventBus.fireEvent(new BatchStepEvent(cleanMemory, true)); - index.clear(); - eventBus.fireEvent(new BatchStepEvent(cleanMemory, false)); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/InitializerExecutionEvent.java b/sonar-batch/src/main/java/org/sonar/batch/phases/InitializerExecutionEvent.java deleted file mode 100644 index 9a8bdc92706..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/InitializerExecutionEvent.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.phases; - -import org.sonar.api.batch.Initializer; -import org.sonar.api.batch.events.InitializerExecutionHandler; - -class InitializerExecutionEvent extends AbstractPhaseEvent - implements org.sonar.api.batch.events.InitializerExecutionHandler.InitializerExecutionEvent { - - private final Initializer initializer; - - InitializerExecutionEvent(Initializer initializer, boolean start) { - super(start); - this.initializer = initializer; - } - - @Override - public Initializer getInitializer() { - return initializer; - } - - @Override - public void dispatch(InitializerExecutionHandler handler) { - handler.onInitializerExecution(this); - } - - @Override - public Class getType() { - return InitializerExecutionHandler.class; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/InitializersExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/phases/InitializersExecutor.java deleted file mode 100644 index 591969ea1b0..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/InitializersExecutor.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.phases; - -import com.google.common.collect.Lists; -import org.apache.commons.lang.StringUtils; -import org.sonar.api.batch.Initializer; -import org.sonar.api.resources.Project; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; -import org.sonar.api.utils.log.Profiler; -import org.sonar.batch.bootstrap.BatchExtensionDictionnary; -import org.sonar.batch.events.EventBus; - -import java.util.Collection; - -public class InitializersExecutor { - - private static final Logger LOG = Loggers.get(SensorsExecutor.class); - - private Project project; - private BatchExtensionDictionnary selector; - private EventBus eventBus; - - public InitializersExecutor(BatchExtensionDictionnary selector, Project project, EventBus eventBus) { - this.selector = selector; - this.project = project; - this.eventBus = eventBus; - } - - public void execute() { - Collection initializers = selector.select(Initializer.class, project, true, null); - eventBus.fireEvent(new InitializersPhaseEvent(Lists.newArrayList(initializers), true)); - if (LOG.isDebugEnabled()) { - LOG.debug("Initializers : {}", StringUtils.join(initializers, " -> ")); - } - - for (Initializer initializer : initializers) { - eventBus.fireEvent(new InitializerExecutionEvent(initializer, true)); - - Profiler profiler = Profiler.create(LOG).startInfo("Initializer " + initializer); - initializer.execute(project); - profiler.stopInfo(); - eventBus.fireEvent(new InitializerExecutionEvent(initializer, false)); - } - - eventBus.fireEvent(new InitializersPhaseEvent(Lists.newArrayList(initializers), false)); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/InitializersPhaseEvent.java b/sonar-batch/src/main/java/org/sonar/batch/phases/InitializersPhaseEvent.java deleted file mode 100644 index 5e109625da6..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/InitializersPhaseEvent.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.phases; - -import org.sonar.api.batch.Initializer; -import org.sonar.api.batch.events.InitializersPhaseHandler; - -import java.util.List; - -class InitializersPhaseEvent extends AbstractPhaseEvent - implements org.sonar.api.batch.events.InitializersPhaseHandler.InitializersPhaseEvent { - - private final List initializers; - - InitializersPhaseEvent(List initializers, boolean start) { - super(start); - this.initializers = initializers; - } - - @Override - public List getInitializers() { - return initializers; - } - - @Override - protected void dispatch(InitializersPhaseHandler handler) { - handler.onInitializersPhase(this); - } - - @Override - protected Class getType() { - return InitializersPhaseHandler.class; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/IssuesPhaseExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/phases/IssuesPhaseExecutor.java deleted file mode 100644 index ba9a155962e..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/IssuesPhaseExecutor.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.phases; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.batch.SensorContext; -import org.sonar.batch.events.BatchStepEvent; -import org.sonar.batch.events.EventBus; -import org.sonar.batch.index.DefaultIndex; -import org.sonar.batch.issue.IssueCallback; -import org.sonar.batch.issue.ignore.scanner.IssueExclusionsLoader; -import org.sonar.batch.issue.tracking.IssueTransition; -import org.sonar.batch.rule.QProfileVerifier; -import org.sonar.batch.scan.filesystem.DefaultModuleFileSystem; -import org.sonar.batch.scan.filesystem.FileSystemLogger; -import org.sonar.batch.scan.report.IssuesReports; - -public final class IssuesPhaseExecutor extends AbstractPhaseExecutor { - - private static final Logger LOG = LoggerFactory.getLogger(IssuesPhaseExecutor.class); - - private final EventBus eventBus; - private final IssuesReports issuesReport; - private final IssueTransition localIssueTracking; - private final IssueCallback issueCallback; - - public IssuesPhaseExecutor(InitializersExecutor initializersExecutor, PostJobsExecutor postJobsExecutor, SensorsExecutor sensorsExecutor, SensorContext sensorContext, - DefaultIndex index, EventBus eventBus, ProjectInitializer pi, FileSystemLogger fsLogger, IssuesReports jsonReport, DefaultModuleFileSystem fs, QProfileVerifier profileVerifier, - IssueExclusionsLoader issueExclusionsLoader, IssueTransition localIssueTracking, IssueCallback issueCallback) { - super(initializersExecutor, postJobsExecutor, sensorsExecutor, sensorContext, index, eventBus, pi, fsLogger, fs, profileVerifier, issueExclusionsLoader); - this.eventBus = eventBus; - this.issuesReport = jsonReport; - this.localIssueTracking = localIssueTracking; - this.issueCallback = issueCallback; - } - - @Override - protected void executeOnRoot() { - localIssueTracking(); - issuesCallback(); - issuesReport(); - LOG.info("ANALYSIS SUCCESSFUL"); - } - - private void localIssueTracking() { - String stepName = "Local Issue Tracking"; - eventBus.fireEvent(new BatchStepEvent(stepName, true)); - localIssueTracking.execute(); - eventBus.fireEvent(new BatchStepEvent(stepName, false)); - } - - private void issuesCallback() { - String stepName = "Issues Callback"; - eventBus.fireEvent(new BatchStepEvent(stepName, true)); - issueCallback.execute(); - eventBus.fireEvent(new BatchStepEvent(stepName, false)); - } - - private void issuesReport() { - String stepName = "Issues Reports"; - eventBus.fireEvent(new BatchStepEvent(stepName, true)); - issuesReport.execute(); - eventBus.fireEvent(new BatchStepEvent(stepName, false)); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/PhasesTimeProfiler.java b/sonar-batch/src/main/java/org/sonar/batch/phases/PhasesTimeProfiler.java deleted file mode 100644 index ba8c7c498d0..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/PhasesTimeProfiler.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.phases; - - -import org.sonar.batch.util.BatchUtils; -import org.apache.commons.lang.StringUtils; -import org.sonar.api.batch.events.SensorExecutionHandler; -import org.sonar.api.batch.events.SensorsPhaseHandler; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; -import org.sonar.api.utils.log.Profiler; - -public class PhasesTimeProfiler implements SensorExecutionHandler, SensorsPhaseHandler { - - private static final Logger LOG = Loggers.get(PhasesTimeProfiler.class); - - private Profiler profiler = Profiler.create(LOG); - - @Override - public void onSensorsPhase(SensorsPhaseEvent event) { - if (event.isStart()) { - LOG.debug("Sensors : {}", StringUtils.join(event.getSensors(), " -> ")); - } - } - - @Override - public void onSensorExecution(SensorExecutionEvent event) { - if (event.isStart()) { - profiler.startInfo("Sensor " + BatchUtils.describe(event.getSensor())); - } else { - profiler.stopInfo(); - } - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/PostJobExecutionEvent.java b/sonar-batch/src/main/java/org/sonar/batch/phases/PostJobExecutionEvent.java deleted file mode 100644 index b7cd92a217b..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/PostJobExecutionEvent.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.phases; - -import org.sonar.api.batch.PostJob; -import org.sonar.api.batch.events.PostJobExecutionHandler; - -class PostJobExecutionEvent extends AbstractPhaseEvent - implements org.sonar.api.batch.events.PostJobExecutionHandler.PostJobExecutionEvent { - - private final PostJob postJob; - - PostJobExecutionEvent(PostJob postJob, boolean start) { - super(start); - this.postJob = postJob; - } - - @Override - public PostJob getPostJob() { - return postJob; - } - - @Override - public void dispatch(PostJobExecutionHandler handler) { - handler.onPostJobExecution(this); - } - - @Override - public Class getType() { - return PostJobExecutionHandler.class; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/PostJobPhaseEvent.java b/sonar-batch/src/main/java/org/sonar/batch/phases/PostJobPhaseEvent.java deleted file mode 100644 index 860d7cc938d..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/PostJobPhaseEvent.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.phases; - -import org.sonar.api.batch.PostJob; -import org.sonar.api.batch.events.PostJobsPhaseHandler; - -import java.util.List; - -class PostJobPhaseEvent extends AbstractPhaseEvent - implements org.sonar.api.batch.events.PostJobsPhaseHandler.PostJobsPhaseEvent { - - private final List postJobs; - - PostJobPhaseEvent(List postJobs, boolean start) { - super(start); - this.postJobs = postJobs; - } - - @Override - public List getPostJobs() { - return postJobs; - } - - @Override - protected void dispatch(PostJobsPhaseHandler handler) { - handler.onPostJobsPhase(this); - } - - @Override - protected Class getType() { - return PostJobsPhaseHandler.class; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/PostJobsExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/phases/PostJobsExecutor.java deleted file mode 100644 index 277b45b8d3c..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/PostJobsExecutor.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.phases; - -import org.sonar.batch.util.BatchUtils; - -import com.google.common.collect.Lists; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.batch.PostJob; -import org.sonar.api.batch.SensorContext; -import org.sonar.api.resources.Project; -import org.sonar.batch.bootstrap.BatchExtensionDictionnary; -import org.sonar.batch.events.EventBus; - -import java.util.Collection; - -@BatchSide -public class PostJobsExecutor { - private static final Logger LOG = LoggerFactory.getLogger(PostJobsExecutor.class); - - private final BatchExtensionDictionnary selector; - private final Project project; - private final EventBus eventBus; - - public PostJobsExecutor(BatchExtensionDictionnary selector, Project project, EventBus eventBus) { - this.selector = selector; - this.project = project; - this.eventBus = eventBus; - } - - public void execute(SensorContext context) { - Collection postJobs = selector.select(PostJob.class, project, true, null); - - eventBus.fireEvent(new PostJobPhaseEvent(Lists.newArrayList(postJobs), true)); - execute(context, postJobs); - eventBus.fireEvent(new PostJobPhaseEvent(Lists.newArrayList(postJobs), false)); - } - - private void execute(SensorContext context, Collection postJobs) { - logPostJobs(postJobs); - - for (PostJob postJob : postJobs) { - LOG.info("Executing post-job {}", BatchUtils.describe(postJob)); - eventBus.fireEvent(new PostJobExecutionEvent(postJob, true)); - postJob.executeOn(project, context); - eventBus.fireEvent(new PostJobExecutionEvent(postJob, false)); - } - } - - private static void logPostJobs(Collection postJobs) { - if (LOG.isDebugEnabled()) { - LOG.debug("Post-jobs : {}", StringUtils.join(postJobs, " -> ")); - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/ProjectAnalysisEvent.java b/sonar-batch/src/main/java/org/sonar/batch/phases/ProjectAnalysisEvent.java deleted file mode 100644 index 428774acd82..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/ProjectAnalysisEvent.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.phases; - -import org.sonar.api.batch.events.ProjectAnalysisHandler; -import org.sonar.api.resources.Project; - -class ProjectAnalysisEvent extends AbstractPhaseEvent - implements org.sonar.api.batch.events.ProjectAnalysisHandler.ProjectAnalysisEvent { - - private final Project project; - - ProjectAnalysisEvent(Project project, boolean start) { - super(start); - this.project = project; - } - - @Override - public Project getProject() { - return project; - } - - @Override - protected void dispatch(ProjectAnalysisHandler handler) { - handler.onProjectAnalysis(this); - } - - @Override - protected Class getType() { - return ProjectAnalysisHandler.class; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/ProjectInitializer.java b/sonar-batch/src/main/java/org/sonar/batch/phases/ProjectInitializer.java deleted file mode 100644 index 8dac11520e5..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/ProjectInitializer.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.phases; - -import org.sonar.api.batch.BatchSide; -import org.apache.commons.lang.StringUtils; -import org.sonar.api.CoreProperties; -import org.sonar.api.config.Settings; -import org.sonar.api.resources.Language; -import org.sonar.api.resources.Languages; -import org.sonar.api.resources.Project; -import org.sonar.api.utils.MessageException; - -/** - * Should be dropped when org.sonar.api.resources.Project is fully refactored. - */ -@BatchSide -public class ProjectInitializer { - - private Languages languages; - private Settings settings; - - public ProjectInitializer(Settings settings, Languages languages) { - this.settings = settings; - this.languages = languages; - } - - public void execute(Project project) { - if (project.getLanguage() == null) { - initDeprecatedLanguage(project); - } - } - - private void initDeprecatedLanguage(Project project) { - String languageKey = settings.getString(CoreProperties.PROJECT_LANGUAGE_PROPERTY); - if (StringUtils.isNotBlank(languageKey)) { - Language language = languages.get(languageKey); - if (language == null) { - throw MessageException.of("Language with key '" + languageKey + "' not found"); - } - project.setLanguage(language); - } else { - project.setLanguage(Project.NONE_LANGUAGE); - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/PublishPhaseExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/phases/PublishPhaseExecutor.java deleted file mode 100644 index 33073a110b3..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/PublishPhaseExecutor.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.phases; - -import org.sonar.api.batch.SensorContext; -import org.sonar.batch.cpd.CpdExecutor; -import org.sonar.batch.events.BatchStepEvent; -import org.sonar.batch.events.EventBus; -import org.sonar.batch.index.DefaultIndex; -import org.sonar.batch.issue.ignore.scanner.IssueExclusionsLoader; -import org.sonar.batch.report.ReportPublisher; -import org.sonar.batch.rule.QProfileVerifier; -import org.sonar.batch.scan.filesystem.DefaultModuleFileSystem; -import org.sonar.batch.scan.filesystem.FileSystemLogger; - -public final class PublishPhaseExecutor extends AbstractPhaseExecutor { - - private final EventBus eventBus; - private final ReportPublisher reportPublisher; - private final CpdExecutor cpdExecutor; - - public PublishPhaseExecutor(InitializersExecutor initializersExecutor, PostJobsExecutor postJobsExecutor, SensorsExecutor sensorsExecutor, SensorContext sensorContext, - DefaultIndex index, EventBus eventBus, ReportPublisher reportPublisher, ProjectInitializer pi, FileSystemLogger fsLogger, DefaultModuleFileSystem fs, - QProfileVerifier profileVerifier, IssueExclusionsLoader issueExclusionsLoader, CpdExecutor cpdExecutor) { - super(initializersExecutor, postJobsExecutor, sensorsExecutor, sensorContext, index, eventBus, pi, fsLogger, fs, profileVerifier, issueExclusionsLoader); - this.eventBus = eventBus; - this.reportPublisher = reportPublisher; - this.cpdExecutor = cpdExecutor; - } - - @Override - protected void executeOnRoot() { - computeDuplications(); - publishReportJob(); - } - - private void computeDuplications() { - String stepName = "Computing duplications"; - eventBus.fireEvent(new BatchStepEvent(stepName, true)); - cpdExecutor.execute(); - eventBus.fireEvent(new BatchStepEvent(stepName, false)); - } - - private void publishReportJob() { - String stepName = "Publish report"; - eventBus.fireEvent(new BatchStepEvent(stepName, true)); - this.reportPublisher.execute(); - eventBus.fireEvent(new BatchStepEvent(stepName, false)); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/SensorExecutionEvent.java b/sonar-batch/src/main/java/org/sonar/batch/phases/SensorExecutionEvent.java deleted file mode 100644 index 22cbd25aadb..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/SensorExecutionEvent.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.phases; - -import org.sonar.api.batch.Sensor; -import org.sonar.api.batch.events.SensorExecutionHandler; - -class SensorExecutionEvent extends AbstractPhaseEvent - implements org.sonar.api.batch.events.SensorExecutionHandler.SensorExecutionEvent { - - private final Sensor sensor; - - SensorExecutionEvent(Sensor sensor, boolean start) { - super(start); - this.sensor = sensor; - } - - @Override - public Sensor getSensor() { - return sensor; - } - - @Override - public void dispatch(SensorExecutionHandler handler) { - handler.onSensorExecution(this); - } - - @Override - public Class getType() { - return SensorExecutionHandler.class; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/SensorsExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/phases/SensorsExecutor.java deleted file mode 100644 index 3af1cf2b6ee..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/SensorsExecutor.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.phases; - -import com.google.common.collect.Lists; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.batch.Sensor; -import org.sonar.api.batch.SensorContext; -import org.sonar.api.resources.Project; -import org.sonar.batch.bootstrap.BatchExtensionDictionnary; -import org.sonar.batch.events.EventBus; - -import java.util.Collection; - -@BatchSide -public class SensorsExecutor { - - private EventBus eventBus; - private Project module; - private BatchExtensionDictionnary selector; - - public SensorsExecutor(BatchExtensionDictionnary selector, Project project, EventBus eventBus) { - this.selector = selector; - this.eventBus = eventBus; - this.module = project; - } - - public void execute(SensorContext context) { - Collection sensors = selector.select(Sensor.class, module, true, null); - eventBus.fireEvent(new SensorsPhaseEvent(Lists.newArrayList(sensors), true)); - - for (Sensor sensor : sensors) { - executeSensor(context, sensor); - } - - eventBus.fireEvent(new SensorsPhaseEvent(Lists.newArrayList(sensors), false)); - } - - private void executeSensor(SensorContext context, Sensor sensor) { - eventBus.fireEvent(new SensorExecutionEvent(sensor, true)); - sensor.analyse(module, context); - eventBus.fireEvent(new SensorExecutionEvent(sensor, false)); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/SensorsPhaseEvent.java b/sonar-batch/src/main/java/org/sonar/batch/phases/SensorsPhaseEvent.java deleted file mode 100644 index a1f658efa1e..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/SensorsPhaseEvent.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.phases; - -import org.sonar.api.batch.Sensor; -import org.sonar.api.batch.events.SensorsPhaseHandler; - -import java.util.List; - -class SensorsPhaseEvent extends AbstractPhaseEvent - implements org.sonar.api.batch.events.SensorsPhaseHandler.SensorsPhaseEvent { - - private final List sensors; - - SensorsPhaseEvent(List sensors, boolean start) { - super(start); - this.sensors = sensors; - } - - @Override - public List getSensors() { - return sensors; - } - - @Override - protected void dispatch(SensorsPhaseHandler handler) { - handler.onSensorsPhase(this); - } - - @Override - protected Class getType() { - return SensorsPhaseHandler.class; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/phases/package-info.java deleted file mode 100644 index f4cd97fca3c..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.batch.phases; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-batch/src/main/java/org/sonar/batch/platform/DefaultServer.java b/sonar-batch/src/main/java/org/sonar/batch/platform/DefaultServer.java deleted file mode 100644 index 3136f4a3112..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/platform/DefaultServer.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.platform; - -import java.io.File; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import javax.annotation.CheckForNull; -import org.apache.commons.lang.StringUtils; -import org.slf4j.LoggerFactory; -import org.sonar.api.CoreProperties; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.config.Settings; -import org.sonar.api.platform.Server; -import org.sonar.batch.bootstrap.GlobalProperties; - -@BatchSide -public class DefaultServer extends Server { - - private Settings settings; - private GlobalProperties props; - - public DefaultServer(Settings settings, GlobalProperties props) { - this.settings = settings; - this.props = props; - } - - @Override - public String getId() { - return settings.getString(CoreProperties.SERVER_ID); - } - - @Override - public String getVersion() { - return settings.getString(CoreProperties.SERVER_VERSION); - } - - @Override - public Date getStartedAt() { - String dateString = settings.getString(CoreProperties.SERVER_STARTTIME); - if (dateString != null) { - try { - return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").parse(dateString); - - } catch (ParseException e) { - LoggerFactory.getLogger(getClass()).error("The property " + CoreProperties.SERVER_STARTTIME + " is badly formatted.", e); - } - } - return null; - } - - @Override - public File getRootDir() { - return null; - } - - @Override - @CheckForNull - public File getDeployDir() { - return null; - } - - @Override - public String getContextPath() { - return ""; - } - - @Override - public String getPublicRootUrl() { - return null; - } - - @Override - public boolean isDev() { - return false; - } - - @Override - public boolean isSecured() { - return false; - } - - @Override - public String getURL() { - return StringUtils.removeEnd(StringUtils.defaultIfBlank(props.property("sonar.host.url"), "http://localhost:9000"), "/"); - } - - @Override - public String getPermanentServerId() { - return settings.getString(CoreProperties.PERMANENT_SERVER_ID); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/platform/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/platform/package-info.java deleted file mode 100644 index cb2793702b0..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/platform/package-info.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.batch.platform; - -import javax.annotation.ParametersAreNonnullByDefault; - diff --git a/sonar-batch/src/main/java/org/sonar/batch/postjob/DefaultPostJobContext.java b/sonar-batch/src/main/java/org/sonar/batch/postjob/DefaultPostJobContext.java deleted file mode 100644 index 02b1582b999..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/postjob/DefaultPostJobContext.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.postjob; - -import org.sonar.batch.issue.tracking.TrackedIssue; - -import com.google.common.base.Function; -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; - -import javax.annotation.Nullable; - -import org.sonar.api.batch.AnalysisMode; -import org.sonar.api.batch.fs.InputComponent; -import org.sonar.api.batch.postjob.PostJobContext; -import org.sonar.api.batch.postjob.issue.Issue; -import org.sonar.api.batch.rule.Severity; -import org.sonar.api.config.Settings; -import org.sonar.api.rule.RuleKey; -import org.sonar.batch.index.BatchComponent; -import org.sonar.batch.index.BatchComponentCache; -import org.sonar.batch.issue.IssueCache; - -public class DefaultPostJobContext implements PostJobContext { - - private final Settings settings; - private final AnalysisMode analysisMode; - private final IssueCache cache; - private final BatchComponentCache resourceCache; - - public DefaultPostJobContext(Settings settings, AnalysisMode analysisMode, IssueCache cache, BatchComponentCache resourceCache) { - this.settings = settings; - this.analysisMode = analysisMode; - this.cache = cache; - this.resourceCache = resourceCache; - } - - @Override - public Settings settings() { - return settings; - } - - @Override - public AnalysisMode analysisMode() { - return analysisMode; - } - - @Override - public Iterable issues() { - return Iterables.transform(Iterables.filter(cache.all(), new ResolvedPredicate(false)), new IssueTransformer()); - } - - @Override - public Iterable resolvedIssues() { - return Iterables.transform(Iterables.filter(cache.all(), new ResolvedPredicate(true)), new IssueTransformer()); - } - - private class DefaultIssueWrapper implements Issue { - - private final TrackedIssue wrapped; - - public DefaultIssueWrapper(TrackedIssue wrapped) { - this.wrapped = wrapped; - } - - @Override - public String key() { - return wrapped.key(); - } - - @Override - public RuleKey ruleKey() { - return wrapped.getRuleKey(); - } - - @Override - public String componentKey() { - return wrapped.componentKey(); - } - - @Override - public InputComponent inputComponent() { - BatchComponent component = resourceCache.get(wrapped.componentKey()); - return component != null ? component.inputComponent() : null; - } - - @Override - public Integer line() { - return wrapped.startLine(); - } - - @Override - public Double effortToFix() { - return wrapped.gap(); - } - - @Override - public String message() { - return wrapped.getMessage(); - } - - @Override - public Severity severity() { - String severity = wrapped.severity(); - return severity != null ? Severity.valueOf(severity) : null; - } - - @Override - public boolean isNew() { - return wrapped.isNew(); - } - } - - private class IssueTransformer implements Function { - @Override - public Issue apply(TrackedIssue input) { - return new DefaultIssueWrapper(input); - } - } - - private static class ResolvedPredicate implements Predicate { - private final boolean resolved; - - private ResolvedPredicate(boolean resolved) { - this.resolved = resolved; - } - - @Override - public boolean apply(@Nullable TrackedIssue issue) { - if (issue != null) { - return resolved ? issue.resolution() != null : issue.resolution() == null; - } - return false; - } - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/postjob/PostJobOptimizer.java b/sonar-batch/src/main/java/org/sonar/batch/postjob/PostJobOptimizer.java deleted file mode 100644 index b27e89e87f8..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/postjob/PostJobOptimizer.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.postjob; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.batch.AnalysisMode; -import org.sonar.api.batch.postjob.internal.DefaultPostJobDescriptor; -import org.sonar.api.config.Settings; - -@BatchSide -public class PostJobOptimizer { - - private static final Logger LOG = LoggerFactory.getLogger(PostJobOptimizer.class); - - private final Settings settings; - private final AnalysisMode analysisMode; - - public PostJobOptimizer(Settings settings, AnalysisMode analysisMode) { - this.settings = settings; - this.analysisMode = analysisMode; - } - - /** - * Decide if the given PostJob should be executed. - */ - public boolean shouldExecute(DefaultPostJobDescriptor descriptor) { - if (!settingsCondition(descriptor)) { - LOG.debug("'{}' skipped because one of the required properties is missing", descriptor.name()); - return false; - } - if (descriptor.isDisabledInIssues() && analysisMode.isIssues()) { - LOG.debug("'{}' skipped in issues mode", descriptor.name()); - return false; - } - return true; - } - - private boolean settingsCondition(DefaultPostJobDescriptor descriptor) { - if (!descriptor.properties().isEmpty()) { - for (String propertyKey : descriptor.properties()) { - if (!settings.hasKey(propertyKey)) { - return false; - } - } - } - return true; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/postjob/PostJobWrapper.java b/sonar-batch/src/main/java/org/sonar/batch/postjob/PostJobWrapper.java deleted file mode 100644 index c5ba661637c..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/postjob/PostJobWrapper.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.postjob; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.batch.CheckProject; -import org.sonar.api.batch.postjob.PostJob; -import org.sonar.api.batch.postjob.PostJobContext; -import org.sonar.api.batch.postjob.internal.DefaultPostJobDescriptor; -import org.sonar.api.resources.Project; - -public class PostJobWrapper implements org.sonar.api.batch.PostJob, CheckProject { - - private static final Logger LOG = LoggerFactory.getLogger(PostJobWrapper.class); - - private PostJob wrappedPostJob; - private PostJobContext adaptor; - private DefaultPostJobDescriptor descriptor; - private PostJobOptimizer optimizer; - - public PostJobWrapper(PostJob newPostJob, PostJobContext adaptor, PostJobOptimizer optimizer) { - this.wrappedPostJob = newPostJob; - this.optimizer = optimizer; - this.descriptor = new DefaultPostJobDescriptor(); - newPostJob.describe(descriptor); - this.adaptor = adaptor; - } - - public PostJob wrappedPostJob() { - return wrappedPostJob; - } - - @Override - public boolean shouldExecuteOnProject(Project project) { - return optimizer.shouldExecute(descriptor); - } - - @Override - public void executeOn(Project project, org.sonar.api.batch.SensorContext context) { - wrappedPostJob.execute(adaptor); - } - - @Override - public String toString() { - return descriptor.name() + (LOG.isDebugEnabled() ? " (wrapped)" : ""); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/postjob/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/postjob/package-info.java deleted file mode 100644 index 0e8cb6ac72d..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/postjob/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@javax.annotation.ParametersAreNonnullByDefault -package org.sonar.batch.postjob; diff --git a/sonar-batch/src/main/java/org/sonar/batch/profiling/AbstractTimeProfiling.java b/sonar-batch/src/main/java/org/sonar/batch/profiling/AbstractTimeProfiling.java deleted file mode 100644 index 6e204596616..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/profiling/AbstractTimeProfiling.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.profiling; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import javax.annotation.Nullable; -import org.sonar.api.utils.System2; -import org.sonar.api.utils.TimeUtils; - -public abstract class AbstractTimeProfiling { - - private final long startTime; - - private long totalTime; - - private System2 system; - - public AbstractTimeProfiling(System2 system) { - this.system = system; - this.startTime = system.now(); - } - - protected System2 system() { - return system; - } - - public long startTime() { - return startTime; - } - - public void stop() { - this.totalTime = system.now() - startTime; - } - - public long totalTime() { - return totalTime; - } - - public String totalTimeAsString() { - return TimeUtils.formatDuration(totalTime); - } - - public void setTotalTime(long totalTime) { - this.totalTime = totalTime; - } - - protected void add(AbstractTimeProfiling other) { - this.setTotalTime(this.totalTime() + other.totalTime()); - } - - static Map sortByDescendingTotalTime(Map unsorted) { - List> entries = - new ArrayList>(unsorted.entrySet()); - Collections.sort(entries, new Comparator>() { - @Override - public int compare(Map.Entry o1, Map.Entry o2) { - return Long.valueOf(o2.getValue().totalTime()).compareTo(o1.getValue().totalTime()); - } - }); - Map sortedMap = new LinkedHashMap<>(); - for (Map.Entry entry : entries) { - sortedMap.put(entry.getKey(), entry.getValue()); - } - return sortedMap; - } - - static List truncate(Collection sortedList) { - int maxSize = 10; - List result = new ArrayList<>(maxSize); - int i = 0; - for (G item : sortedList) { - if (i >= maxSize || item.totalTime() == 0) { - return result; - } - i++; - result.add(item); - } - return result; - } - - protected void println(String msg) { - PhasesSumUpTimeProfiler.println(msg); - } - - protected void println(String text, @Nullable Double percent, AbstractTimeProfiling phaseProfiling) { - PhasesSumUpTimeProfiler.println(text, percent, phaseProfiling); - } - - protected void println(String text, AbstractTimeProfiling phaseProfiling) { - println(text, null, phaseProfiling); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/profiling/ItemProfiling.java b/sonar-batch/src/main/java/org/sonar/batch/profiling/ItemProfiling.java deleted file mode 100644 index abbb11ccbcb..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/profiling/ItemProfiling.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.profiling; - -import org.sonar.api.utils.System2; - -public class ItemProfiling extends AbstractTimeProfiling { - - private final String itemName; - - public ItemProfiling(System2 system, String itemName) { - super(system); - this.itemName = itemName; - } - - public String itemName() { - return itemName; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/profiling/ModuleProfiling.java b/sonar-batch/src/main/java/org/sonar/batch/profiling/ModuleProfiling.java deleted file mode 100644 index 7c04dcff55e..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/profiling/ModuleProfiling.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.profiling; - -import com.google.common.collect.Maps; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Properties; -import javax.annotation.Nullable; -import org.sonar.api.resources.Project; -import org.sonar.api.utils.System2; - -public class ModuleProfiling extends AbstractTimeProfiling { - - private Map profilingPerPhase = new HashMap<>(); - private Map profilingPerBatchStep = new LinkedHashMap<>(); - private final Project module; - - public ModuleProfiling(@Nullable Project module, System2 system) { - super(system); - this.module = module; - } - - public String moduleName() { - if (module != null) { - return module.getName(); - } - return null; - } - - public PhaseProfiling getProfilingPerPhase(Phase phase) { - return profilingPerPhase.get(phase); - } - - public ItemProfiling getProfilingPerBatchStep(String stepName) { - return profilingPerBatchStep.get(stepName); - } - - public void addPhaseProfiling(Phase phase) { - profilingPerPhase.put(phase, PhaseProfiling.create(system(), phase)); - } - - public void addBatchStepProfiling(String stepName) { - profilingPerBatchStep.put(stepName, new ItemProfiling(system(), stepName)); - } - - public void dump(Properties props) { - double percent = this.totalTime() / 100.0; - Map categories = Maps.newLinkedHashMap(); - categories.putAll(profilingPerPhase); - categories.putAll(profilingPerBatchStep); - - for (Map.Entry batchStep : categories.entrySet()) { - props.setProperty(batchStep.getKey().toString(), Long.toString(batchStep.getValue().totalTime())); - } - - for (Map.Entry batchStep : sortByDescendingTotalTime(categories).entrySet()) { - println(" * " + batchStep.getKey() + " execution time: ", percent, batchStep.getValue()); - } - // Breakdown per phase - for (Phase phase : Phase.values()) { - if (profilingPerPhase.containsKey(phase) && getProfilingPerPhase(phase).hasItems()) { - println(""); - println(" * " + phase + " execution time breakdown: ", getProfilingPerPhase(phase)); - getProfilingPerPhase(phase).dump(props); - } - } - } - - public void merge(ModuleProfiling other) { - super.add(other); - for (Entry entry : other.profilingPerPhase.entrySet()) { - if (!this.profilingPerPhase.containsKey(entry.getKey())) { - this.addPhaseProfiling(entry.getKey()); - } - this.getProfilingPerPhase(entry.getKey()).merge(entry.getValue()); - } - for (Map.Entry entry : other.profilingPerBatchStep.entrySet()) { - if (!this.profilingPerBatchStep.containsKey(entry.getKey())) { - profilingPerBatchStep.put(entry.getKey(), new ItemProfiling(system(), entry.getKey())); - } - this.getProfilingPerBatchStep(entry.getKey()).add(entry.getValue()); - } - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/profiling/Phase.java b/sonar-batch/src/main/java/org/sonar/batch/profiling/Phase.java deleted file mode 100644 index f00496f9644..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/profiling/Phase.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.profiling; - -public enum Phase { - - INIT("Initializers"), SENSOR("Sensors"), DECORATOR("Decorators"), PERSISTER("Persisters"), POSTJOB("Post-Jobs"); - - private final String label; - - private Phase(String label) { - this.label = label; - } - - @Override - public String toString() { - return label; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/profiling/PhaseProfiling.java b/sonar-batch/src/main/java/org/sonar/batch/profiling/PhaseProfiling.java deleted file mode 100644 index 5b13f1d4ee1..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/profiling/PhaseProfiling.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.profiling; - -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Properties; -import org.sonar.api.utils.System2; - -public class PhaseProfiling extends AbstractTimeProfiling { - - private final Phase phase; - - private Map profilingPerItem = new HashMap<>(); - - PhaseProfiling(System2 system, Phase phase) { - super(system); - this.phase = phase; - } - - public static PhaseProfiling create(System2 system, Phase phase) { - return new PhaseProfiling(system, phase); - } - - public Phase phase() { - return phase; - } - - public boolean hasItems() { - return !profilingPerItem.isEmpty(); - } - - public ItemProfiling getProfilingPerItem(Object item) { - String stringOrSimpleName = toStringOrSimpleName(item); - return profilingPerItem.get(stringOrSimpleName); - } - - public void newItemProfiling(Object item) { - String stringOrSimpleName = toStringOrSimpleName(item); - profilingPerItem.put(stringOrSimpleName, new ItemProfiling(system(), stringOrSimpleName)); - } - - public void newItemProfiling(String itemName) { - profilingPerItem.put(itemName, new ItemProfiling(system(), itemName)); - } - - public void merge(PhaseProfiling other) { - super.add(other); - for (Entry entry : other.profilingPerItem.entrySet()) { - if (!this.profilingPerItem.containsKey(entry.getKey())) { - newItemProfiling(entry.getKey()); - } - this.getProfilingPerItem(entry.getKey()).add(entry.getValue()); - } - } - - public void dump(Properties props) { - double percent = this.totalTime() / 100.0; - for (ItemProfiling itemProfiling : profilingPerItem.values()) { - props.setProperty(itemProfiling.itemName(), Long.toString(itemProfiling.totalTime())); - } - for (ItemProfiling itemProfiling : truncate(sortByDescendingTotalTime(profilingPerItem).values())) { - println(" o " + itemProfiling.itemName() + ": ", percent, itemProfiling); - } - } - - /** - * Try to use toString if it is not the default {@link Object#toString()}. Else use {@link Class#getSimpleName()} - * @param o - * @return - */ - private static String toStringOrSimpleName(Object o) { - String toString = o.toString(); - if (toString == null || toString.startsWith(o.getClass().getName())) { - return o.getClass().getSimpleName(); - } - return toString; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/profiling/PhasesSumUpTimeProfiler.java b/sonar-batch/src/main/java/org/sonar/batch/profiling/PhasesSumUpTimeProfiler.java deleted file mode 100644 index f03b84caaac..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/profiling/PhasesSumUpTimeProfiler.java +++ /dev/null @@ -1,278 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.profiling; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.Lists; -import java.io.File; -import java.io.FileOutputStream; -import java.util.HashMap; -import java.util.IdentityHashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import javax.annotation.Nullable; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.CoreProperties; -import org.sonar.api.batch.Decorator; -import org.sonar.api.batch.events.DecoratorExecutionHandler; -import org.sonar.api.batch.events.DecoratorsPhaseHandler; -import org.sonar.api.batch.events.InitializerExecutionHandler; -import org.sonar.api.batch.events.InitializersPhaseHandler; -import org.sonar.api.batch.events.PostJobExecutionHandler; -import org.sonar.api.batch.events.PostJobsPhaseHandler; -import org.sonar.api.batch.events.ProjectAnalysisHandler; -import org.sonar.api.batch.events.SensorExecutionHandler; -import org.sonar.api.batch.events.SensorsPhaseHandler; -import org.sonar.api.resources.Project; -import org.sonar.api.utils.System2; -import org.sonar.api.utils.TimeUtils; -import org.sonar.batch.bootstrap.GlobalProperties; -import org.sonar.batch.events.BatchStepHandler; -import org.sonar.batch.util.BatchUtils; - -import static org.sonar.batch.profiling.AbstractTimeProfiling.sortByDescendingTotalTime; -import static org.sonar.batch.profiling.AbstractTimeProfiling.truncate; - -public class PhasesSumUpTimeProfiler implements ProjectAnalysisHandler, SensorExecutionHandler, DecoratorExecutionHandler, PostJobExecutionHandler, DecoratorsPhaseHandler, - SensorsPhaseHandler, PostJobsPhaseHandler, InitializersPhaseHandler, InitializerExecutionHandler, BatchStepHandler { - - static final Logger LOG = LoggerFactory.getLogger(PhasesSumUpTimeProfiler.class); - private static final int TEXT_RIGHT_PAD = 60; - private static final int TIME_LEFT_PAD = 10; - - @VisibleForTesting - ModuleProfiling currentModuleProfiling; - - @VisibleForTesting - ModuleProfiling totalProfiling; - - private Map modulesProfilings = new HashMap<>(); - private DecoratorsProfiler decoratorsProfiler; - - private final System2 system; - private final File out; - - public PhasesSumUpTimeProfiler(System2 system, GlobalProperties bootstrapProps) { - String workingDirPath = StringUtils.defaultIfBlank(bootstrapProps.property(CoreProperties.WORKING_DIRECTORY), CoreProperties.WORKING_DIRECTORY_DEFAULT_VALUE); - File workingDir = new File(workingDirPath).getAbsoluteFile(); - this.out = new File(workingDir, "profiling"); - this.out.mkdirs(); - this.totalProfiling = new ModuleProfiling(null, system); - this.system = system; - } - - static void println(String msg) { - LOG.info(msg); - } - - static void println(String text, @Nullable Double percent, AbstractTimeProfiling phaseProfiling) { - StringBuilder sb = new StringBuilder(); - sb.append(StringUtils.rightPad(text, TEXT_RIGHT_PAD)).append(StringUtils.leftPad(phaseProfiling.totalTimeAsString(), TIME_LEFT_PAD)); - if (percent != null) { - sb.append(" (").append((int) (phaseProfiling.totalTime() / percent)).append("%)"); - } - println(sb.toString()); - } - - @Override - public void onProjectAnalysis(ProjectAnalysisEvent event) { - Project module = event.getProject(); - if (event.isStart()) { - decoratorsProfiler = new DecoratorsProfiler(); - currentModuleProfiling = new ModuleProfiling(module, system); - } else { - currentModuleProfiling.stop(); - modulesProfilings.put(module, currentModuleProfiling); - long moduleTotalTime = currentModuleProfiling.totalTime(); - println(""); - println(" -------- Profiling of module " + module.getName() + ": " + TimeUtils.formatDuration(moduleTotalTime) + " --------"); - println(""); - Properties props = new Properties(); - currentModuleProfiling.dump(props); - println(""); - println(" -------- End of profiling of module " + module.getName() + " --------"); - println(""); - String fileName = module.getKey() + "-profiler.properties"; - dumpToFile(props, BatchUtils.cleanKeyForFilename(fileName)); - totalProfiling.merge(currentModuleProfiling); - if (module.isRoot() && !module.getModules().isEmpty()) { - dumpTotalExecutionSummary(); - } - } - } - - private void dumpTotalExecutionSummary() { - totalProfiling.stop(); - long totalTime = totalProfiling.totalTime(); - println(""); - println(" ======== Profiling of total execution: " + TimeUtils.formatDuration(totalTime) + " ========"); - println(""); - println(" * Module execution time breakdown: "); - double percent = totalTime / 100.0; - for (ModuleProfiling modulesProfiling : truncate(sortByDescendingTotalTime(modulesProfilings).values())) { - println(" o " + modulesProfiling.moduleName() + " execution time: ", percent, modulesProfiling); - } - println(""); - Properties props = new Properties(); - totalProfiling.dump(props); - println(""); - println(" ======== End of profiling of total execution ========"); - println(""); - String fileName = "total-execution-profiler.properties"; - dumpToFile(props, fileName); - } - - private void dumpToFile(Properties props, String fileName) { - File file = new File(out, fileName); - try (FileOutputStream fos = new FileOutputStream(file)) { - props.store(fos, "SonarQube"); - println("Profiling data stored in " + file.getAbsolutePath()); - } catch (Exception e) { - throw new IllegalStateException("Unable to store profiler output: " + file, e); - } - } - - @Override - public void onSensorsPhase(SensorsPhaseEvent event) { - if (event.isStart()) { - currentModuleProfiling.addPhaseProfiling(Phase.SENSOR); - } else { - currentModuleProfiling.getProfilingPerPhase(Phase.SENSOR).stop(); - } - } - - @Override - public void onSensorExecution(SensorExecutionEvent event) { - PhaseProfiling profiling = currentModuleProfiling.getProfilingPerPhase(Phase.SENSOR); - if (event.isStart()) { - profiling.newItemProfiling(event.getSensor()); - } else { - profiling.getProfilingPerItem(event.getSensor()).stop(); - } - } - - @Override - public void onDecoratorExecution(DecoratorExecutionEvent event) { - PhaseProfiling profiling = currentModuleProfiling.getProfilingPerPhase(Phase.DECORATOR); - if (event.isStart()) { - if (profiling.getProfilingPerItem(event.getDecorator()) == null) { - profiling.newItemProfiling(event.getDecorator()); - } - decoratorsProfiler.start(event.getDecorator()); - } else { - decoratorsProfiler.stop(); - } - } - - @Override - public void onDecoratorsPhase(DecoratorsPhaseEvent event) { - if (event.isStart()) { - currentModuleProfiling.addPhaseProfiling(Phase.DECORATOR); - } else { - for (Decorator decorator : decoratorsProfiler.getDurations().keySet()) { - currentModuleProfiling.getProfilingPerPhase(Phase.DECORATOR) - .getProfilingPerItem(decorator).setTotalTime(decoratorsProfiler.getDurations().get(decorator)); - } - currentModuleProfiling.getProfilingPerPhase(Phase.DECORATOR).stop(); - } - } - - @Override - public void onPostJobsPhase(PostJobsPhaseEvent event) { - if (event.isStart()) { - currentModuleProfiling.addPhaseProfiling(Phase.POSTJOB); - } else { - currentModuleProfiling.getProfilingPerPhase(Phase.POSTJOB).stop(); - } - } - - @Override - public void onPostJobExecution(PostJobExecutionEvent event) { - PhaseProfiling profiling = currentModuleProfiling.getProfilingPerPhase(Phase.POSTJOB); - if (event.isStart()) { - profiling.newItemProfiling(event.getPostJob()); - } else { - profiling.getProfilingPerItem(event.getPostJob()).stop(); - } - } - - @Override - public void onInitializersPhase(InitializersPhaseEvent event) { - if (event.isStart()) { - currentModuleProfiling.addPhaseProfiling(Phase.INIT); - } else { - currentModuleProfiling.getProfilingPerPhase(Phase.INIT).stop(); - } - } - - @Override - public void onInitializerExecution(InitializerExecutionEvent event) { - PhaseProfiling profiling = currentModuleProfiling.getProfilingPerPhase(Phase.INIT); - if (event.isStart()) { - profiling.newItemProfiling(event.getInitializer()); - } else { - profiling.getProfilingPerItem(event.getInitializer()).stop(); - } - } - - @Override - public void onBatchStep(BatchStepEvent event) { - if (event.isStart()) { - currentModuleProfiling.addBatchStepProfiling(event.stepName()); - } else { - currentModuleProfiling.getProfilingPerBatchStep(event.stepName()).stop(); - } - } - - class DecoratorsProfiler { - private List decorators = Lists.newArrayList(); - private Map durations = new IdentityHashMap<>(); - private long startTime; - private Decorator currentDecorator; - - DecoratorsProfiler() { - } - - void start(Decorator decorator) { - this.startTime = system.now(); - this.currentDecorator = decorator; - } - - void stop() { - final Long cumulatedDuration; - if (durations.containsKey(currentDecorator)) { - cumulatedDuration = durations.get(currentDecorator); - } else { - decorators.add(currentDecorator); - cumulatedDuration = 0L; - } - durations.put(currentDecorator, cumulatedDuration + (system.now() - startTime)); - } - - public Map getDurations() { - return durations; - } - - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/profiling/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/profiling/package-info.java deleted file mode 100644 index 8f57dd4e4c7..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/profiling/package-info.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.batch.profiling; - -import javax.annotation.ParametersAreNonnullByDefault; - diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/ActiveRulesPublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/ActiveRulesPublisher.java deleted file mode 100644 index f7d059c3d83..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/report/ActiveRulesPublisher.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.report; - -import com.google.common.base.Function; -import com.google.common.collect.FluentIterable; -import java.util.Map; -import javax.annotation.Nonnull; -import org.sonar.api.batch.rule.ActiveRule; -import org.sonar.api.batch.rule.ActiveRules; -import org.sonar.batch.protocol.Constants; -import org.sonar.batch.protocol.output.BatchReport; -import org.sonar.batch.protocol.output.BatchReportWriter; - -public class ActiveRulesPublisher implements ReportPublisherStep { - - private final ActiveRules activeRules; - - public ActiveRulesPublisher(ActiveRules activeRules) { - this.activeRules = activeRules; - } - - @Override - public void publish(BatchReportWriter writer) { - Iterable activeRuleMessages = FluentIterable.from(activeRules.findAll()).transform(new ToMessage()); - writer.writeActiveRules(activeRuleMessages); - } - - private static class ToMessage implements Function { - private final BatchReport.ActiveRule.Builder builder = BatchReport.ActiveRule.newBuilder(); - - @Override - public BatchReport.ActiveRule apply(@Nonnull ActiveRule input) { - builder.clear(); - builder.setRuleRepository(input.ruleKey().repository()); - builder.setRuleKey(input.ruleKey().rule()); - builder.setSeverity(Constants.Severity.valueOf(input.severity())); - for (Map.Entry entry : input.params().entrySet()) { - builder.addParamBuilder().setKey(entry.getKey()).setValue(entry.getValue()).build(); - - } - return builder.build(); - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/AnalysisContextReportPublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/AnalysisContextReportPublisher.java deleted file mode 100644 index a15cb2b2ed6..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/report/AnalysisContextReportPublisher.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.report; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.StandardOpenOption; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; -import java.util.TreeSet; -import org.sonar.api.batch.AnalysisMode; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.api.utils.System2; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; -import org.sonar.batch.bootstrap.BatchPluginRepository; -import org.sonar.batch.protocol.output.BatchReportWriter; -import org.sonar.batch.repository.ProjectRepositories; -import org.sonar.core.platform.PluginInfo; - -@BatchSide -public class AnalysisContextReportPublisher { - - private static final Logger LOG = Loggers.get(AnalysisContextReportPublisher.class); - - private static final String ENV_PROP_PREFIX = "env."; - private static final String SONAR_PROP_PREFIX = "sonar."; - private final BatchPluginRepository pluginRepo; - private final AnalysisMode mode; - private final System2 system; - private final ProjectRepositories projectRepos; - - private BatchReportWriter writer; - - public AnalysisContextReportPublisher(AnalysisMode mode, BatchPluginRepository pluginRepo, System2 system, ProjectRepositories projectRepos) { - this.mode = mode; - this.pluginRepo = pluginRepo; - this.system = system; - this.projectRepos = projectRepos; - } - - public void init(BatchReportWriter writer) { - if (mode.isIssues()) { - return; - } - this.writer = writer; - File analysisLog = writer.getFileStructure().analysisLog(); - try (BufferedWriter fileWriter = Files.newBufferedWriter(analysisLog.toPath(), StandardCharsets.UTF_8)) { - if (LOG.isDebugEnabled()) { - writeEnvVariables(fileWriter); - writeSystemProps(fileWriter); - } - writePlugins(fileWriter); - } catch (IOException e) { - throw new IllegalStateException("Unable to write analysis log", e); - } - } - - private void writePlugins(BufferedWriter fileWriter) throws IOException { - fileWriter.write("SonarQube plugins:\n"); - for (PluginInfo p : pluginRepo.getPluginInfos()) { - fileWriter.append(String.format(" - %s %s (%s)", p.getName(), p.getVersion(), p.getKey())).append('\n'); - } - } - - private void writeSystemProps(BufferedWriter fileWriter) throws IOException { - fileWriter.write("System properties:\n"); - Properties sysProps = system.properties(); - for (String prop : new TreeSet<>(sysProps.stringPropertyNames())) { - if (prop.startsWith(SONAR_PROP_PREFIX)) { - continue; - } - fileWriter.append(String.format(" - %s=%s", prop, sysProps.getProperty(prop))).append('\n'); - } - } - - private void writeEnvVariables(BufferedWriter fileWriter) throws IOException { - fileWriter.append("Environment variables:\n"); - Map envVariables = system.envVariables(); - for (String env : new TreeSet<>(envVariables.keySet())) { - fileWriter.append(String.format(" - %s=%s", env, envVariables.get(env))).append('\n'); - } - } - - public void dumpSettings(ProjectDefinition moduleDefinition) { - if (mode.isIssues()) { - return; - } - - File analysisLog = writer.getFileStructure().analysisLog(); - try (BufferedWriter fileWriter = Files.newBufferedWriter(analysisLog.toPath(), StandardCharsets.UTF_8, StandardOpenOption.WRITE, StandardOpenOption.APPEND)) { - Map moduleSpecificProps = collectModuleSpecificProps(moduleDefinition); - fileWriter.append(String.format("Settings for module: %s", moduleDefinition.getKey())).append('\n'); - for (String prop : new TreeSet<>(moduleSpecificProps.keySet())) { - if (isSystemProp(prop) || isEnvVariable(prop) || !isSqProp(prop)) { - continue; - } - fileWriter.append(String.format(" - %s=%s", prop, sensitive(prop) ? "******" : moduleSpecificProps.get(prop))).append('\n'); - } - } catch (IOException e) { - throw new IllegalStateException("Unable to write analysis log", e); - } - } - - /** - * Only keep props that are not in parent - */ - private Map collectModuleSpecificProps(ProjectDefinition moduleDefinition) { - Map moduleSpecificProps = new HashMap<>(); - if (projectRepos.moduleExists(moduleDefinition.getKeyWithBranch())) { - moduleSpecificProps.putAll(projectRepos.settings(moduleDefinition.getKeyWithBranch())); - } - ProjectDefinition parent = moduleDefinition.getParent(); - if (parent == null) { - moduleSpecificProps.putAll(moduleDefinition.properties()); - } else { - Map parentProps = parent.properties(); - for (Map.Entry entry : moduleDefinition.properties().entrySet()) { - if (!parentProps.containsKey(entry.getKey()) || !parentProps.get(entry.getKey()).equals(entry.getValue())) { - moduleSpecificProps.put(entry.getKey(), entry.getValue()); - } - } - } - return moduleSpecificProps; - } - - private static boolean isSqProp(String propKey) { - return propKey.startsWith(SONAR_PROP_PREFIX); - } - - private boolean isSystemProp(String propKey) { - return system.properties().containsKey(propKey) && !propKey.startsWith(SONAR_PROP_PREFIX); - } - - private boolean isEnvVariable(String propKey) { - return propKey.startsWith(ENV_PROP_PREFIX) && system.envVariables().containsKey(propKey.substring(ENV_PROP_PREFIX.length())); - } - - private static boolean sensitive(String key) { - return key.contains(".password") || key.contains(".secured"); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/BatchReportUtils.java b/sonar-batch/src/main/java/org/sonar/batch/report/BatchReportUtils.java deleted file mode 100644 index 9ba54f164ab..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/report/BatchReportUtils.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.report; - -import org.sonar.api.batch.sensor.highlighting.TypeOfText; -import org.sonar.batch.protocol.Constants.HighlightingType; - -public class BatchReportUtils { - - private BatchReportUtils() { - } - - public static HighlightingType toProtocolType(TypeOfText textType) { - switch (textType) { - case ANNOTATION: - return HighlightingType.ANNOTATION; - case COMMENT: - return HighlightingType.COMMENT; - case CONSTANT: - return HighlightingType.CONSTANT; - case CPP_DOC: - return HighlightingType.CPP_DOC; - case KEYWORD: - return HighlightingType.KEYWORD; - case KEYWORD_LIGHT: - return HighlightingType.KEYWORD_LIGHT; - case PREPROCESS_DIRECTIVE: - return HighlightingType.PREPROCESS_DIRECTIVE; - case STRING: - return HighlightingType.HIGHLIGHTING_STRING; - case STRUCTURED_COMMENT: - return HighlightingType.STRUCTURED_COMMENT; - default: - throw new IllegalArgumentException("Unknow highlighting type: " + textType); - } - } - - public static TypeOfText toBatchType(HighlightingType type) { - switch (type) { - case ANNOTATION: - return TypeOfText.ANNOTATION; - case COMMENT: - return TypeOfText.COMMENT; - case CONSTANT: - return TypeOfText.CONSTANT; - case CPP_DOC: - return TypeOfText.CPP_DOC; - case HIGHLIGHTING_STRING: - return TypeOfText.STRING; - case KEYWORD: - return TypeOfText.KEYWORD; - case KEYWORD_LIGHT: - return TypeOfText.KEYWORD_LIGHT; - case PREPROCESS_DIRECTIVE: - return TypeOfText.PREPROCESS_DIRECTIVE; - case STRUCTURED_COMMENT: - return TypeOfText.STRUCTURED_COMMENT; - default: - throw new IllegalArgumentException(type + " is not a valid type"); - } - } - - public static String toCssClass(HighlightingType type) { - return toBatchType(type).cssClass(); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/ComponentsPublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/ComponentsPublisher.java deleted file mode 100644 index e576c3f8393..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/report/ComponentsPublisher.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.report; - -import javax.annotation.CheckForNull; -import org.apache.commons.lang.StringUtils; -import org.sonar.api.CoreProperties; -import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.resources.Language; -import org.sonar.api.resources.Resource; -import org.sonar.api.resources.ResourceUtils; -import org.sonar.batch.index.BatchComponent; -import org.sonar.batch.index.BatchComponentCache; -import org.sonar.batch.protocol.Constants; -import org.sonar.batch.protocol.Constants.ComponentLinkType; -import org.sonar.batch.protocol.output.BatchReport; -import org.sonar.batch.protocol.output.BatchReport.ComponentLink; -import org.sonar.batch.protocol.output.BatchReportWriter; -import org.sonar.batch.scan.ImmutableProjectReactor; - -/** - * Adds components and analysis metadata to output report - */ -public class ComponentsPublisher implements ReportPublisherStep { - - private final BatchComponentCache resourceCache; - private final ImmutableProjectReactor reactor; - - public ComponentsPublisher(ImmutableProjectReactor reactor, BatchComponentCache resourceCache) { - this.reactor = reactor; - this.resourceCache = resourceCache; - } - - @Override - public void publish(BatchReportWriter writer) { - BatchComponent rootProject = resourceCache.get(reactor.getRoot().getKeyWithBranch()); - recursiveWriteComponent(rootProject, writer); - } - - private void recursiveWriteComponent(BatchComponent batchComponent, BatchReportWriter writer) { - Resource r = batchComponent.resource(); - BatchReport.Component.Builder builder = BatchReport.Component.newBuilder(); - - // non-null fields - builder.setRef(batchComponent.batchId()); - builder.setType(getType(r)); - - // Don't set key on directories and files to save space since it can be deduced from path - if (batchComponent.isProjectOrModule()) { - // Here we want key without branch - ProjectDefinition def = reactor.getProjectDefinition(batchComponent.key()); - builder.setKey(def.getKey()); - } - - // protocol buffers does not accept null values - - if (batchComponent.isFile()) { - builder.setIsTest(ResourceUtils.isUnitTestFile(r)); - builder.setLines(((InputFile) batchComponent.inputComponent()).lines()); - } - String name = getName(r); - if (name != null) { - builder.setName(name); - } - String description = getDescription(r); - if (description != null) { - builder.setDescription(description); - } - String path = r.getPath(); - if (path != null) { - builder.setPath(path); - } - String lang = getLanguageKey(r); - if (lang != null) { - builder.setLanguage(lang); - } - for (BatchComponent child : batchComponent.children()) { - builder.addChildRef(child.batchId()); - } - writeLinks(batchComponent, builder); - writeVersion(batchComponent, builder); - writer.writeComponent(builder.build()); - - for (BatchComponent child : batchComponent.children()) { - recursiveWriteComponent(child, writer); - } - } - - private void writeVersion(BatchComponent c, BatchReport.Component.Builder builder) { - if (c.isProjectOrModule()) { - ProjectDefinition def = reactor.getProjectDefinition(c.key()); - String version = getVersion(def); - builder.setVersion(version); - } - } - - private static String getVersion(ProjectDefinition def) { - String version = def.getVersion(); - return StringUtils.isNotBlank(version) ? version : getVersion(def.getParent()); - } - - private void writeLinks(BatchComponent c, BatchReport.Component.Builder builder) { - if (c.isProjectOrModule()) { - ProjectDefinition def = reactor.getProjectDefinition(c.key()); - ComponentLink.Builder linkBuilder = ComponentLink.newBuilder(); - - writeProjectLink(builder, def, linkBuilder, CoreProperties.LINKS_HOME_PAGE, ComponentLinkType.HOME); - writeProjectLink(builder, def, linkBuilder, CoreProperties.LINKS_CI, ComponentLinkType.CI); - writeProjectLink(builder, def, linkBuilder, CoreProperties.LINKS_ISSUE_TRACKER, ComponentLinkType.ISSUE); - writeProjectLink(builder, def, linkBuilder, CoreProperties.LINKS_SOURCES, ComponentLinkType.SCM); - writeProjectLink(builder, def, linkBuilder, CoreProperties.LINKS_SOURCES_DEV, ComponentLinkType.SCM_DEV); - } - } - - private static void writeProjectLink(BatchReport.Component.Builder componentBuilder, ProjectDefinition def, ComponentLink.Builder linkBuilder, String linkProp, - ComponentLinkType linkType) { - String link = def.properties().get(linkProp); - if (StringUtils.isNotBlank(link)) { - linkBuilder.setType(linkType); - linkBuilder.setHref(link); - componentBuilder.addLink(linkBuilder.build()); - linkBuilder.clear(); - } - } - - @CheckForNull - private static String getLanguageKey(Resource r) { - Language language = r.getLanguage(); - return ResourceUtils.isFile(r) && language != null ? language.getKey() : null; - } - - @CheckForNull - private static String getName(Resource r) { - // Don't return name for directories and files since it can be guessed from the path - return (ResourceUtils.isFile(r) || ResourceUtils.isDirectory(r)) ? null : r.getName(); - } - - @CheckForNull - private static String getDescription(Resource r) { - // Only for projets and modules - return ResourceUtils.isProject(r) ? r.getDescription() : null; - } - - private Constants.ComponentType getType(Resource r) { - if (ResourceUtils.isFile(r)) { - return Constants.ComponentType.FILE; - } else if (ResourceUtils.isDirectory(r)) { - return Constants.ComponentType.DIRECTORY; - } else if (ResourceUtils.isModuleProject(r)) { - return Constants.ComponentType.MODULE; - } else if (ResourceUtils.isRootProject(r)) { - return Constants.ComponentType.PROJECT; - } - throw new IllegalArgumentException("Unknown resource type: " + r); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/CoveragePublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/CoveragePublisher.java deleted file mode 100644 index 921c37f5a83..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/report/CoveragePublisher.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.report; - -import com.google.common.base.Function; -import com.google.common.collect.Iterables; -import java.util.LinkedHashMap; -import java.util.Map; -import javax.annotation.Nonnull; -import org.apache.commons.lang.StringUtils; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.Measure; -import org.sonar.api.utils.KeyValueFormat; -import org.sonar.batch.index.BatchComponent; -import org.sonar.batch.index.BatchComponentCache; -import org.sonar.batch.protocol.output.BatchReport.Coverage; -import org.sonar.batch.protocol.output.BatchReport.Coverage.Builder; -import org.sonar.batch.protocol.output.BatchReportWriter; -import org.sonar.batch.scan.measure.MeasureCache; - -public class CoveragePublisher implements ReportPublisherStep { - - private final BatchComponentCache resourceCache; - private final MeasureCache measureCache; - - public CoveragePublisher(BatchComponentCache resourceCache, MeasureCache measureCache) { - this.resourceCache = resourceCache; - this.measureCache = measureCache; - } - - @Override - public void publish(BatchReportWriter writer) { - for (final BatchComponent resource : resourceCache.all()) { - if (!resource.isFile()) { - continue; - } - Map coveragePerLine = new LinkedHashMap<>(); - - int lineCount = ((InputFile) resource.inputComponent()).lines(); - applyLineMeasure(resource.key(), lineCount, CoreMetrics.COVERAGE_LINE_HITS_DATA_KEY, coveragePerLine, - new MeasureOperation() { - @Override - public void apply(String value, Coverage.Builder builder) { - builder.setUtHits(Integer.parseInt(value) > 0); - } - }); - applyLineMeasure(resource.key(), lineCount, CoreMetrics.CONDITIONS_BY_LINE_KEY, coveragePerLine, - new MeasureOperation() { - @Override - public void apply(String value, Coverage.Builder builder) { - builder.setConditions(Integer.parseInt(value)); - } - }); - applyLineMeasure(resource.key(), lineCount, CoreMetrics.COVERED_CONDITIONS_BY_LINE_KEY, coveragePerLine, - new MeasureOperation() { - @Override - public void apply(String value, Coverage.Builder builder) { - builder.setUtCoveredConditions(Integer.parseInt(value)); - } - }); - applyLineMeasure(resource.key(), lineCount, CoreMetrics.IT_COVERAGE_LINE_HITS_DATA_KEY, coveragePerLine, - new MeasureOperation() { - @Override - public void apply(String value, Coverage.Builder builder) { - builder.setItHits(Integer.parseInt(value) > 0); - } - }); - applyLineMeasure(resource.key(), lineCount, CoreMetrics.IT_COVERED_CONDITIONS_BY_LINE_KEY, coveragePerLine, - new MeasureOperation() { - @Override - public void apply(String value, Coverage.Builder builder) { - builder.setItCoveredConditions(Integer.parseInt(value)); - } - }); - applyLineMeasure(resource.key(), lineCount, CoreMetrics.OVERALL_COVERED_CONDITIONS_BY_LINE_KEY, coveragePerLine, - new MeasureOperation() { - @Override - public void apply(String value, Coverage.Builder builder) { - builder.setOverallCoveredConditions(Integer.parseInt(value)); - } - }); - writer.writeComponentCoverage(resource.batchId(), Iterables.transform(coveragePerLine.values(), BuildCoverage.INSTANCE)); - } - } - - void applyLineMeasure(String inputFileKey, int lineCount, String metricKey, Map coveragePerLine, MeasureOperation op) { - Measure measure = measureCache.byMetric(inputFileKey, metricKey); - if (measure != null) { - Map lineMeasures = KeyValueFormat.parseIntString((String) measure.value()); - for (Map.Entry lineMeasure : lineMeasures.entrySet()) { - int lineIdx = lineMeasure.getKey(); - if (lineIdx <= lineCount) { - String value = lineMeasure.getValue(); - if (StringUtils.isNotEmpty(value)) { - Coverage.Builder coverageBuilder = coveragePerLine.get(lineIdx); - if (coverageBuilder == null) { - coverageBuilder = Coverage.newBuilder(); - coverageBuilder.setLine(lineIdx); - coveragePerLine.put(lineIdx, coverageBuilder); - } - op.apply(value, coverageBuilder); - } - } - } - } - } - - interface MeasureOperation { - void apply(String value, Coverage.Builder builder); - } - - private enum BuildCoverage implements Function { - INSTANCE; - - @Override - public Coverage apply(@Nonnull Builder input) { - return input.build(); - } - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/MeasuresPublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/MeasuresPublisher.java deleted file mode 100644 index e19b590610f..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/report/MeasuresPublisher.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.report; - -import com.google.common.base.Function; -import com.google.common.base.Predicate; -import java.io.Serializable; -import java.util.Set; -import javax.annotation.Nonnull; -import org.sonar.api.batch.measure.Metric; -import org.sonar.api.measures.Measure; -import org.sonar.api.measures.Metric.ValueType; -import org.sonar.batch.index.BatchComponent; -import org.sonar.batch.index.BatchComponentCache; -import org.sonar.batch.protocol.Constants.MeasureValueType; -import org.sonar.batch.protocol.output.BatchReport; -import org.sonar.batch.protocol.output.BatchReportWriter; -import org.sonar.batch.scan.measure.MeasureCache; -import org.sonar.core.metric.BatchMetrics; - -import static com.google.common.collect.Iterables.filter; -import static com.google.common.collect.Iterables.transform; -import static com.google.common.collect.Sets.newHashSet; - -public class MeasuresPublisher implements ReportPublisherStep { - - private static final class MeasureToReportMeasure implements Function { - private final BatchComponent resource; - private final BatchReport.Measure.Builder builder = BatchReport.Measure.newBuilder(); - - private MeasureToReportMeasure(BatchComponent resource) { - this.resource = resource; - } - - @Override - public BatchReport.Measure apply(@Nonnull Measure input) { - validateMeasure(input, resource.key()); - return toReportMeasure(builder, input); - } - - private static void validateMeasure(Measure measure, String componentKey) { - if (measure.getValue() == null && measure.getData() == null) { - throw new IllegalArgumentException(String.format("Measure on metric '%s' and component '%s' has no value, but it's not allowed", measure.getMetricKey(), componentKey)); - } - } - - private BatchReport.Measure toReportMeasure(BatchReport.Measure.Builder builder, Measure measure) { - builder.clear(); - - builder.setValueType(getMeasureValueType(measure.getMetric().getType())); - setValueAccordingToType(builder, measure); - // Because some numeric measures also have a data (like maintainability rating) - String data = measure.getData(); - if (data != null) { - builder.setStringValue(data); - } - builder.setMetricKey(measure.getMetricKey()); - return builder.build(); - } - - private void setValueAccordingToType(BatchReport.Measure.Builder builder, Measure measure) { - Serializable value = measure.value(); - switch (builder.getValueType()) { - case BOOLEAN: - builder.setBooleanValue((Boolean) value); - break; - case DOUBLE: - builder.setDoubleValue(((Number) value).doubleValue()); - break; - case INT: - builder.setIntValue(((Number) value).intValue()); - break; - case LONG: - builder.setLongValue(((Number) value).longValue()); - break; - case STRING: - builder.setStringValue((String) value); - break; - default: - throw new IllegalStateException("Unknown value type: " + builder.getValueType()); - } - } - - private MeasureValueType getMeasureValueType(ValueType type) { - switch (type) { - case INT: - case RATING: - return MeasureValueType.INT; - case FLOAT: - case PERCENT: - return MeasureValueType.DOUBLE; - case BOOL: - return MeasureValueType.BOOLEAN; - case STRING: - case DATA: - case LEVEL: - case DISTRIB: - return MeasureValueType.STRING; - case WORK_DUR: - case MILLISEC: - return MeasureValueType.LONG; - default: - throw new IllegalStateException("Unknown value type: " + type); - } - } - - } - - private static final class IsMetricAllowed implements Predicate { - private final Set allowedMetricKeys; - - private IsMetricAllowed(Set allowedMetricKeys) { - this.allowedMetricKeys = allowedMetricKeys; - } - - @Override - public boolean apply(Measure input) { - return allowedMetricKeys.contains(input.getMetricKey()); - } - } - - private static final class MetricToKey implements Function { - @Override - public String apply(Metric input) { - return input.key(); - } - } - - private final BatchComponentCache resourceCache; - private final MeasureCache measureCache; - private final BatchMetrics batchMetrics; - - public MeasuresPublisher(BatchComponentCache resourceCache, MeasureCache measureCache, BatchMetrics batchMetrics) { - this.resourceCache = resourceCache; - this.measureCache = measureCache; - this.batchMetrics = batchMetrics; - } - - @Override - public void publish(BatchReportWriter writer) { - final Set allowedMetricKeys = newHashSet(transform(batchMetrics.getMetrics(), new MetricToKey())); - for (final BatchComponent resource : resourceCache.all()) { - Iterable batchMeasures = measureCache.byResource(resource.resource()); - Iterable reportMeasures = transform( - filter(batchMeasures, new IsMetricAllowed(allowedMetricKeys)), - new MeasureToReportMeasure(resource)); - writer.writeComponentMeasures(resource.batchId(), reportMeasures); - } - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/MetadataPublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/MetadataPublisher.java deleted file mode 100644 index eac42e0ad7d..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/report/MetadataPublisher.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.report; - -import org.sonar.api.CoreProperties; -import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.api.config.Settings; -import org.sonar.api.resources.Project; -import org.sonar.batch.cpd.index.SonarCpdBlockIndex; -import org.sonar.batch.index.BatchComponent; -import org.sonar.batch.index.BatchComponentCache; -import org.sonar.batch.protocol.output.BatchReport; -import org.sonar.batch.protocol.output.BatchReportWriter; -import org.sonar.batch.scan.ImmutableProjectReactor; - -public class MetadataPublisher implements ReportPublisherStep { - - private final BatchComponentCache componentCache; - private final ImmutableProjectReactor reactor; - private final Settings settings; - - public MetadataPublisher(BatchComponentCache componentCache, ImmutableProjectReactor reactor, Settings settings) { - this.componentCache = componentCache; - this.reactor = reactor; - this.settings = settings; - } - - @Override - public void publish(BatchReportWriter writer) { - ProjectDefinition root = reactor.getRoot(); - BatchComponent rootProject = componentCache.getRoot(); - BatchReport.Metadata.Builder builder = BatchReport.Metadata.newBuilder() - .setAnalysisDate(((Project) rootProject.resource()).getAnalysisDate().getTime()) - // Here we want key without branch - .setProjectKey(root.getKey()) - .setCrossProjectDuplicationActivated(SonarCpdBlockIndex.isCrossProjectDuplicationEnabled(settings)) - .setRootComponentRef(rootProject.batchId()); - String branch = root.properties().get(CoreProperties.PROJECT_BRANCH_PROPERTY); - if (branch != null) { - builder.setBranch(branch); - } - writer.writeMetadata(builder.build()); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/ReportPublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/ReportPublisher.java deleted file mode 100644 index 4654892fb57..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/report/ReportPublisher.java +++ /dev/null @@ -1,242 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.report; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Throwables; -import com.google.common.io.Files; -import com.squareup.okhttp.HttpUrl; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.Writer; -import java.net.URL; -import java.nio.charset.StandardCharsets; -import java.util.LinkedHashMap; -import java.util.Map; -import javax.annotation.Nullable; -import org.apache.commons.io.FileUtils; -import org.picocontainer.Startable; -import org.sonar.api.CoreProperties; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.api.config.Settings; -import org.sonar.api.utils.MessageException; -import org.sonar.api.utils.TempFolder; -import org.sonar.api.utils.ZipUtils; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; -import org.sonar.batch.analysis.DefaultAnalysisMode; -import org.sonar.batch.bootstrap.BatchWsClient; -import org.sonar.batch.protocol.output.BatchReportWriter; -import org.sonar.batch.scan.ImmutableProjectReactor; -import org.sonarqube.ws.MediaTypes; -import org.sonarqube.ws.WsCe; -import org.sonarqube.ws.client.PostRequest; -import org.sonarqube.ws.client.WsResponse; - -import static org.apache.commons.lang.StringUtils.trimToEmpty; -import static org.sonar.core.util.FileUtils.deleteQuietly; - -@BatchSide -public class ReportPublisher implements Startable { - - private static final Logger LOG = Loggers.get(ReportPublisher.class); - - public static final String KEEP_REPORT_PROP_KEY = "sonar.batch.keepReport"; - public static final String VERBOSE_KEY = "sonar.verbose"; - public static final String METADATA_DUMP_FILENAME = "report-task.txt"; - - private final Settings settings; - private final BatchWsClient wsClient; - private final AnalysisContextReportPublisher contextPublisher; - private final ImmutableProjectReactor projectReactor; - private final DefaultAnalysisMode analysisMode; - private final TempFolder temp; - private final ReportPublisherStep[] publishers; - - private File reportDir; - private BatchReportWriter writer; - - public ReportPublisher(Settings settings, BatchWsClient wsClient, AnalysisContextReportPublisher contextPublisher, - ImmutableProjectReactor projectReactor, DefaultAnalysisMode analysisMode, TempFolder temp, ReportPublisherStep[] publishers) { - this.settings = settings; - this.wsClient = wsClient; - this.contextPublisher = contextPublisher; - this.projectReactor = projectReactor; - this.analysisMode = analysisMode; - this.temp = temp; - this.publishers = publishers; - } - - @Override - public void start() { - reportDir = new File(projectReactor.getRoot().getWorkDir(), "batch-report"); - writer = new BatchReportWriter(reportDir); - contextPublisher.init(writer); - - if (!analysisMode.isIssues() && !analysisMode.isMediumTest()) { - String publicUrl = publicUrl(); - if (HttpUrl.parse(publicUrl) == null) { - throw MessageException.of("Failed to parse public URL set in SonarQube server: " + publicUrl); - } - } - } - - @Override - public void stop() { - if (!settings.getBoolean(KEEP_REPORT_PROP_KEY) && !settings.getBoolean(VERBOSE_KEY)) { - deleteQuietly(reportDir); - } else { - LOG.info("Analysis report generated in " + reportDir); - } - } - - public File getReportDir() { - return reportDir; - } - - public BatchReportWriter getWriter() { - return writer; - } - - public void execute() { - // If this is a issues mode analysis then we should not upload reports - String taskId = null; - if (!analysisMode.isIssues()) { - File report = generateReportFile(); - if (!analysisMode.isMediumTest()) { - taskId = upload(report); - } - } - logSuccess(taskId); - } - - private File generateReportFile() { - try { - long startTime = System.currentTimeMillis(); - for (ReportPublisherStep publisher : publishers) { - publisher.publish(writer); - } - long stopTime = System.currentTimeMillis(); - LOG.info("Analysis report generated in {}ms, dir size={}", stopTime - startTime, FileUtils.byteCountToDisplaySize(FileUtils.sizeOfDirectory(reportDir))); - - startTime = System.currentTimeMillis(); - File reportZip = temp.newFile("batch-report", ".zip"); - ZipUtils.zipDir(reportDir, reportZip); - stopTime = System.currentTimeMillis(); - LOG.info("Analysis reports compressed in {}ms, zip size={}", stopTime - startTime, FileUtils.byteCountToDisplaySize(FileUtils.sizeOf(reportZip))); - return reportZip; - } catch (IOException e) { - throw new IllegalStateException("Unable to prepare analysis report", e); - } - } - - /** - * Uploads the report file to server and returns the generated task id - */ - @VisibleForTesting - String upload(File report) { - LOG.debug("Upload report"); - long startTime = System.currentTimeMillis(); - ProjectDefinition projectDefinition = projectReactor.getRoot(); - PostRequest.Part filePart = new PostRequest.Part(MediaTypes.ZIP, report); - PostRequest post = new PostRequest("api/ce/submit") - .setMediaType(MediaTypes.PROTOBUF) - .setParam("projectKey", projectDefinition.getKey()) - .setParam("projectName", projectDefinition.getName()) - .setParam("projectBranch", projectDefinition.getBranch()) - .setPart("report", filePart); - WsResponse response = wsClient.call(post).failIfNotSuccessful(); - try (InputStream protobuf = response.contentStream()) { - return WsCe.SubmitResponse.parser().parseFrom(protobuf).getTaskId(); - } catch (Exception e) { - throw Throwables.propagate(e); - } finally { - long stopTime = System.currentTimeMillis(); - LOG.info("Analysis report uploaded in " + (stopTime - startTime) + "ms"); - } - } - - @VisibleForTesting - void logSuccess(@Nullable String taskId) { - if (taskId == null) { - LOG.info("ANALYSIS SUCCESSFUL"); - } else { - String publicUrl = publicUrl(); - HttpUrl httpUrl = HttpUrl.parse(publicUrl); - - Map metadata = new LinkedHashMap<>(); - String effectiveKey = projectReactor.getRoot().getKeyWithBranch(); - metadata.put("projectKey", effectiveKey); - metadata.put("serverUrl", publicUrl); - - URL dashboardUrl = httpUrl.newBuilder() - .addPathSegment("dashboard").addPathSegment("index").addPathSegment(effectiveKey) - .build() - .url(); - metadata.put("dashboardUrl", dashboardUrl.toExternalForm()); - - URL taskUrl = HttpUrl.parse(publicUrl).newBuilder() - .addPathSegment("api").addPathSegment("ce").addPathSegment("task") - .addQueryParameter("id", taskId) - .build() - .url(); - metadata.put("ceTaskId", taskId); - metadata.put("ceTaskUrl", taskUrl.toExternalForm()); - - LOG.info("ANALYSIS SUCCESSFUL, you can browse {}", dashboardUrl); - LOG.info("Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report"); - LOG.info("More about the report processing at {}", taskUrl); - - dumpMetadata(metadata); - } - } - - private void dumpMetadata(Map metadata) { - File file = new File(projectReactor.getRoot().getWorkDir(), METADATA_DUMP_FILENAME); - try (Writer output = Files.newWriter(file, StandardCharsets.UTF_8)) { - for (Map.Entry entry : metadata.entrySet()) { - output.write(entry.getKey()); - output.write("="); - output.write(entry.getValue()); - output.write("\n"); - } - - LOG.debug("Report metadata written to {}", file); - } catch (IOException e) { - throw new IllegalStateException("Unable to dump " + file, e); - } - } - - /** - * The public URL is optionally configured on server. If not, then the regular URL is returned. - * See https://jira.sonarsource.com/browse/SONAR-4239 - */ - private String publicUrl() { - String baseUrl = trimToEmpty(settings.getString(CoreProperties.SERVER_BASE_URL)); - if (baseUrl.equals(settings.getDefaultValue(CoreProperties.SERVER_BASE_URL))) { - // crap workaround for https://jira.sonarsource.com/browse/SONAR-7109 - // If server base URL was not configured in Sonar server then is is better to take URL configured on batch side - baseUrl = wsClient.baseUrl(); - } - return baseUrl.replaceAll("(/)+$", ""); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/ReportPublisherStep.java b/sonar-batch/src/main/java/org/sonar/batch/report/ReportPublisherStep.java deleted file mode 100644 index 873e95a5683..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/report/ReportPublisherStep.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.report; - -import org.sonar.batch.protocol.output.BatchReportWriter; - -/** - * Adds a sub-part of data to output report - */ -public interface ReportPublisherStep { - - void publish(BatchReportWriter writer); - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/SourcePublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/SourcePublisher.java deleted file mode 100644 index 02fe7449038..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/report/SourcePublisher.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.report; - -import org.apache.commons.io.ByteOrderMark; -import org.apache.commons.io.IOUtils; -import org.apache.commons.io.input.BOMInputStream; -import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.batch.index.BatchComponent; -import org.sonar.batch.index.BatchComponentCache; -import org.sonar.batch.protocol.output.BatchReportWriter; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; - -public class SourcePublisher implements ReportPublisherStep { - - private final BatchComponentCache resourceCache; - - public SourcePublisher(BatchComponentCache resourceCache) { - this.resourceCache = resourceCache; - } - - @Override - public void publish(BatchReportWriter writer) { - for (final BatchComponent resource : resourceCache.all()) { - if (!resource.isFile()) { - continue; - } - - DefaultInputFile inputFile = (DefaultInputFile) resource.inputComponent(); - File iofile = writer.getSourceFile(resource.batchId()); - int line = 0; - try (FileOutputStream output = new FileOutputStream(iofile); BOMInputStream bomIn = new BOMInputStream(new FileInputStream(inputFile.file()), - ByteOrderMark.UTF_8, ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_16BE, ByteOrderMark.UTF_32LE, ByteOrderMark.UTF_32BE); - BufferedReader reader = new BufferedReader(new InputStreamReader(bomIn, inputFile.charset()))) { - String lineStr = reader.readLine(); - while (lineStr != null) { - IOUtils.write(lineStr, output, StandardCharsets.UTF_8); - line++; - if (line < inputFile.lines()) { - IOUtils.write("\n", output, StandardCharsets.UTF_8); - } - lineStr = reader.readLine(); - } - } catch (IOException e) { - throw new IllegalStateException("Unable to store file source in the report", e); - } - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/TestExecutionAndCoveragePublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/TestExecutionAndCoveragePublisher.java deleted file mode 100644 index 22513bdc9d9..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/report/TestExecutionAndCoveragePublisher.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.report; - -import com.google.common.base.Function; -import com.google.common.collect.Iterables; -import java.util.HashSet; -import java.util.Set; -import javax.annotation.Nonnull; -import org.sonar.api.batch.fs.InputFile.Type; -import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.test.CoverageBlock; -import org.sonar.api.test.MutableTestCase; -import org.sonar.api.test.MutableTestPlan; -import org.sonar.api.test.TestCase; -import org.sonar.batch.index.BatchComponent; -import org.sonar.batch.index.BatchComponentCache; -import org.sonar.batch.protocol.Constants.TestStatus; -import org.sonar.batch.protocol.output.BatchReport; -import org.sonar.batch.protocol.output.BatchReport.CoverageDetail; -import org.sonar.batch.protocol.output.BatchReport.Test; -import org.sonar.batch.protocol.output.BatchReportWriter; -import org.sonar.batch.test.DefaultTestable; -import org.sonar.batch.test.TestPlanBuilder; - -public class TestExecutionAndCoveragePublisher implements ReportPublisherStep { - - private static final class TestConverter implements Function { - private final Set testNamesWithCoverage; - private BatchReport.Test.Builder builder = BatchReport.Test.newBuilder(); - - private TestConverter(Set testNamesWithCoverage) { - this.testNamesWithCoverage = testNamesWithCoverage; - } - - @Override - public Test apply(@Nonnull MutableTestCase testCase) { - builder.clear(); - builder.setName(testCase.name()); - if (testCase.doesCover()) { - testNamesWithCoverage.add(testCase.name()); - } - Long durationInMs = testCase.durationInMs(); - if (durationInMs != null) { - builder.setDurationInMs(durationInMs); - } - String msg = testCase.message(); - if (msg != null) { - builder.setMsg(msg); - } - String stack = testCase.stackTrace(); - if (stack != null) { - builder.setStacktrace(stack); - } - TestCase.Status status = testCase.status(); - if (status != null) { - builder.setStatus(TestStatus.valueOf(status.name())); - } - return builder.build(); - } - } - - private final class TestCoverageConverter implements Function { - private final MutableTestPlan testPlan; - private BatchReport.CoverageDetail.Builder builder = BatchReport.CoverageDetail.newBuilder(); - private BatchReport.CoverageDetail.CoveredFile.Builder coveredBuilder = BatchReport.CoverageDetail.CoveredFile.newBuilder(); - - private TestCoverageConverter(MutableTestPlan testPlan) { - this.testPlan = testPlan; - } - - @Override - public CoverageDetail apply(@Nonnull String testName) { - // Take first test with provided name - MutableTestCase testCase = testPlan.testCasesByName(testName).iterator().next(); - builder.clear(); - builder.setTestName(testName); - for (CoverageBlock block : testCase.coverageBlocks()) { - coveredBuilder.clear(); - coveredBuilder.setFileRef(componentCache.get(((DefaultTestable) block.testable()).inputFile().key()).batchId()); - for (int line : block.lines()) { - coveredBuilder.addCoveredLine(line); - } - builder.addCoveredFile(coveredBuilder.build()); - } - return builder.build(); - } - } - - private final BatchComponentCache componentCache; - private final TestPlanBuilder testPlanBuilder; - - public TestExecutionAndCoveragePublisher(BatchComponentCache resourceCache, TestPlanBuilder testPlanBuilder) { - this.componentCache = resourceCache; - this.testPlanBuilder = testPlanBuilder; - } - - @Override - public void publish(BatchReportWriter writer) { - for (final BatchComponent component : componentCache.all()) { - if (!component.isFile()) { - continue; - } - - DefaultInputFile inputFile = (DefaultInputFile) component.inputComponent(); - if (inputFile.type() != Type.TEST) { - continue; - } - - final MutableTestPlan testPlan = testPlanBuilder.loadPerspective(MutableTestPlan.class, component); - if (testPlan == null || Iterables.isEmpty(testPlan.testCases())) { - continue; - } - - final Set testNamesWithCoverage = new HashSet<>(); - - writer.writeTests(component.batchId(), Iterables.transform(testPlan.testCases(), new TestConverter(testNamesWithCoverage))); - - writer.writeCoverageDetails(component.batchId(), Iterables.transform(testNamesWithCoverage, new TestCoverageConverter(testPlan))); - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/report/package-info.java deleted file mode 100644 index f4b3d8e51a9..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/report/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.batch.report; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultGlobalRepositoriesLoader.java b/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultGlobalRepositoriesLoader.java deleted file mode 100644 index 630b49a0bba..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultGlobalRepositoriesLoader.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.repository; - -import org.sonar.batch.cache.WSLoaderResult; - -import org.sonar.batch.cache.WSLoader; - -import javax.annotation.Nullable; - -import org.apache.commons.lang.mutable.MutableBoolean; -import org.sonar.batch.protocol.input.GlobalRepositories; - -public class DefaultGlobalRepositoriesLoader implements GlobalRepositoriesLoader { - - private static final String BATCH_GLOBAL_URL = "/batch/global"; - - private final WSLoader wsLoader; - - public DefaultGlobalRepositoriesLoader(WSLoader wsLoader) { - this.wsLoader = wsLoader; - } - - @Override - public GlobalRepositories load(@Nullable MutableBoolean fromCache) { - WSLoaderResult result = wsLoader.loadString(BATCH_GLOBAL_URL); - if (fromCache != null) { - fromCache.setValue(result.isFromCache()); - } - return GlobalRepositories.fromJson(result.get()); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java b/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java deleted file mode 100644 index 0e8a0904b57..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.repository; - -import com.google.common.base.Throwables; - -import com.google.common.collect.HashBasedTable; -import com.google.common.collect.Table; - -import java.io.IOException; -import java.io.InputStream; -import java.net.HttpURLConnection; -import java.util.Date; -import java.util.Map; - -import javax.annotation.Nullable; - -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang.mutable.MutableBoolean; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.utils.MessageException; -import org.sonar.batch.cache.WSLoader; -import org.sonar.batch.cache.WSLoaderResult; -import org.sonar.batch.util.BatchUtils; -import org.sonarqube.ws.WsBatch.WsProjectResponse; -import org.sonarqube.ws.WsBatch.WsProjectResponse.FileDataByPath; -import org.sonarqube.ws.WsBatch.WsProjectResponse.Settings; -import org.sonarqube.ws.client.HttpException; - -public class DefaultProjectRepositoriesLoader implements ProjectRepositoriesLoader { - private static final Logger LOG = LoggerFactory.getLogger(DefaultProjectRepositoriesLoader.class); - private static final String BATCH_PROJECT_URL = "/batch/project.protobuf"; - private final WSLoader loader; - - public DefaultProjectRepositoriesLoader(WSLoader loader) { - this.loader = loader; - } - - @Override - public ProjectRepositories load(String projectKey, boolean issuesMode, @Nullable MutableBoolean fromCache) { - try { - WSLoaderResult result = loader.loadStream(getUrl(projectKey, issuesMode)); - if (fromCache != null) { - fromCache.setValue(result.isFromCache()); - } - return processStream(result.get(), projectKey); - } catch (RuntimeException e) { - if (shouldThrow(e)) { - throw e; - } - - LOG.debug("Project repository not available - continuing without it", e); - return new ProjectRepositories(); - } - } - - private static String getUrl(String projectKey, boolean issuesMode) { - StringBuilder builder = new StringBuilder(); - - builder.append(BATCH_PROJECT_URL) - .append("?key=").append(BatchUtils.encodeForUrl(projectKey)); - if (issuesMode) { - builder.append("&issues_mode=true"); - } - return builder.toString(); - } - - private static boolean shouldThrow(Exception e) { - for (Throwable t : Throwables.getCausalChain(e)) { - if (t instanceof HttpException) { - HttpException http = (HttpException) t; - return http.code() != HttpURLConnection.HTTP_NOT_FOUND; - } - if (t instanceof MessageException) { - return true; - } - } - - return false; - } - - private static ProjectRepositories processStream(InputStream is, String projectKey) { - try { - WsProjectResponse response = WsProjectResponse.parseFrom(is); - - Table fileDataTable = HashBasedTable.create(); - Table settings = HashBasedTable.create(); - - Map settingsByModule = response.getSettingsByModule(); - for (Map.Entry e1 : settingsByModule.entrySet()) { - for (Map.Entry e2 : e1.getValue().getSettings().entrySet()) { - settings.put(e1.getKey(), e2.getKey(), e2.getValue()); - } - } - - Map fileDataByModuleAndPath = response.getFileDataByModuleAndPath(); - for (Map.Entry e1 : fileDataByModuleAndPath.entrySet()) { - for (Map.Entry e2 : e1.getValue().getFileDataByPath().entrySet()) { - FileData fd = new FileData(e2.getValue().getHash(), e2.getValue().getRevision()); - fileDataTable.put(e1.getKey(), e2.getKey(), fd); - } - } - - return new ProjectRepositories(settings, fileDataTable, new Date(response.getLastAnalysisDate())); - } catch (IOException e) { - throw new IllegalStateException("Couldn't load project repository for " + projectKey, e); - } finally { - IOUtils.closeQuietly(is); - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultQualityProfileLoader.java b/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultQualityProfileLoader.java deleted file mode 100644 index 524e6f6856d..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultQualityProfileLoader.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.repository; - -import org.sonar.api.utils.MessageException; - -import org.sonarqube.ws.QualityProfiles.SearchWsResponse; -import org.sonar.batch.util.BatchUtils; -import org.apache.commons.io.IOUtils; -import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile; -import org.apache.commons.lang.mutable.MutableBoolean; -import org.sonar.batch.cache.WSLoaderResult; -import org.sonar.batch.cache.WSLoader; - -import javax.annotation.Nullable; - -import java.io.IOException; -import java.io.InputStream; -import java.util.List; - -public class DefaultQualityProfileLoader implements QualityProfileLoader { - private static final String WS_URL = "/api/qualityprofiles/search.protobuf"; - - private WSLoader wsLoader; - - public DefaultQualityProfileLoader(WSLoader wsLoader) { - this.wsLoader = wsLoader; - } - - @Override - public List loadDefault(@Nullable String profileName, @Nullable MutableBoolean fromCache) { - String url = WS_URL + "?defaults=true"; - if (profileName != null) { - url += "&profileName=" + BatchUtils.encodeForUrl(profileName); - } - return loadResource(url, fromCache); - } - - @Override - public List load(String projectKey, @Nullable String profileName, @Nullable MutableBoolean fromCache) { - String url = WS_URL + "?projectKey=" + BatchUtils.encodeForUrl(projectKey); - if (profileName != null) { - url += "&profileName=" + BatchUtils.encodeForUrl(profileName); - } - return loadResource(url, fromCache); - } - - private List loadResource(String url, @Nullable MutableBoolean fromCache) { - WSLoaderResult result = wsLoader.loadStream(url); - if (fromCache != null) { - fromCache.setValue(result.isFromCache()); - } - InputStream is = result.get(); - SearchWsResponse profiles = null; - - try { - profiles = SearchWsResponse.parseFrom(is); - } catch (IOException e) { - throw new IllegalStateException("Failed to load quality profiles", e); - } finally { - IOUtils.closeQuietly(is); - } - - List profilesList = profiles.getProfilesList(); - if (profilesList == null || profilesList.isEmpty()) { - throw MessageException.of("No quality profiles have been found, you probably don't have any language plugin installed."); - } - return profilesList; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultServerIssuesLoader.java b/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultServerIssuesLoader.java deleted file mode 100644 index 853b4ae20db..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultServerIssuesLoader.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.repository; - -import com.google.common.base.Function; -import java.io.IOException; -import java.io.InputStream; -import org.apache.commons.io.IOUtils; -import org.sonar.batch.cache.WSLoader; -import org.sonar.batch.cache.WSLoaderResult; -import org.sonar.batch.protocol.input.BatchInput.ServerIssue; -import org.sonar.batch.util.BatchUtils; - -public class DefaultServerIssuesLoader implements ServerIssuesLoader { - - private final WSLoader wsLoader; - - public DefaultServerIssuesLoader(WSLoader wsLoader) { - this.wsLoader = wsLoader; - } - - @Override - public boolean load(String componentKey, Function consumer) { - WSLoaderResult result = wsLoader.loadStream("/batch/issues.protobuf?key=" + BatchUtils.encodeForUrl(componentKey)); - parseIssues(result.get(), consumer); - return result.isFromCache(); - } - - private static void parseIssues(InputStream is, Function consumer) { - try { - ServerIssue previousIssue = ServerIssue.parseDelimitedFrom(is); - while (previousIssue != null) { - consumer.apply(previousIssue); - previousIssue = ServerIssue.parseDelimitedFrom(is); - } - } catch (IOException e) { - throw new IllegalStateException("Unable to get previous issues", e); - } finally { - IOUtils.closeQuietly(is); - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/FileData.java b/sonar-batch/src/main/java/org/sonar/batch/repository/FileData.java deleted file mode 100644 index bcf470e8986..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/repository/FileData.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.repository; - -import javax.annotation.concurrent.Immutable; - -@Immutable -public class FileData { - private final String hash; - private final String revision; - - public FileData(String hash, String revision) { - this.hash = hash; - this.revision = revision; - } - - public String hash() { - return hash; - } - - public String revision() { - return revision; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/GlobalRepositoriesLoader.java b/sonar-batch/src/main/java/org/sonar/batch/repository/GlobalRepositoriesLoader.java deleted file mode 100644 index 7c32e2bf484..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/repository/GlobalRepositoriesLoader.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.repository; - -import org.apache.commons.lang.mutable.MutableBoolean; - -import javax.annotation.Nullable; - -import org.sonar.batch.protocol.input.GlobalRepositories; - -public interface GlobalRepositoriesLoader { - - GlobalRepositories load(@Nullable MutableBoolean fromCache); - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/GlobalRepositoriesProvider.java b/sonar-batch/src/main/java/org/sonar/batch/repository/GlobalRepositoriesProvider.java deleted file mode 100644 index 56f741a6c74..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/repository/GlobalRepositoriesProvider.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.repository; - -import org.apache.commons.lang.mutable.MutableBoolean; - -import org.picocontainer.injectors.ProviderAdapter; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; -import org.sonar.api.utils.log.Profiler; -import org.sonar.batch.protocol.input.GlobalRepositories; - -public class GlobalRepositoriesProvider extends ProviderAdapter { - - private static final Logger LOG = Loggers.get(GlobalRepositoriesProvider.class); - private static final String LOG_MSG = "Load global repositories"; - private GlobalRepositories globalReferentials; - - public GlobalRepositories provide(GlobalRepositoriesLoader loader) { - if (globalReferentials == null) { - Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG); - MutableBoolean fromCache = new MutableBoolean(); - globalReferentials = loader.load(fromCache); - profiler.stopInfo(fromCache.booleanValue()); - } - return globalReferentials; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/ProjectRepositories.java b/sonar-batch/src/main/java/org/sonar/batch/repository/ProjectRepositories.java deleted file mode 100644 index baba0c52396..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/repository/ProjectRepositories.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.repository; - -import com.google.common.collect.HashBasedTable; -import com.google.common.collect.Table; -import java.util.Date; -import java.util.Map; -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; - -public class ProjectRepositories { - private final Table settingsByModule; - private final Table fileDataByModuleAndPath; - private final Date lastAnalysisDate; - private final boolean exists; - - public ProjectRepositories() { - this.exists = false; - this.settingsByModule = HashBasedTable.create(); - this.fileDataByModuleAndPath = HashBasedTable.create(); - this.lastAnalysisDate = null; - } - - public ProjectRepositories(Table settingsByModule, Table fileDataByModuleAndPath, - @Nullable Date lastAnalysisDate) { - this.settingsByModule = settingsByModule; - this.fileDataByModuleAndPath = fileDataByModuleAndPath; - this.lastAnalysisDate = lastAnalysisDate; - this.exists = true; - } - - public boolean exists() { - return exists; - } - - public Map fileDataByPath(String moduleKey) { - return fileDataByModuleAndPath.row(moduleKey); - } - - public Table fileDataByModuleAndPath() { - return fileDataByModuleAndPath; - } - - public boolean moduleExists(String moduleKey) { - return settingsByModule.containsRow(moduleKey); - } - - public Map settings(String moduleKey) { - return settingsByModule.row(moduleKey); - } - - @CheckForNull - public FileData fileData(String projectKey, String path) { - return fileDataByModuleAndPath.get(projectKey, path); - } - - @CheckForNull - public Date lastAnalysisDate() { - return lastAnalysisDate; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/ProjectRepositoriesLoader.java b/sonar-batch/src/main/java/org/sonar/batch/repository/ProjectRepositoriesLoader.java deleted file mode 100644 index 53de4805324..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/repository/ProjectRepositoriesLoader.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.repository; - -import javax.annotation.Nullable; - -import org.apache.commons.lang.mutable.MutableBoolean; - -public interface ProjectRepositoriesLoader { - ProjectRepositories load(String projectKeyWithBranch, boolean issuesMode, @Nullable MutableBoolean fromCache); -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/ProjectRepositoriesProvider.java b/sonar-batch/src/main/java/org/sonar/batch/repository/ProjectRepositoriesProvider.java deleted file mode 100644 index 1e0469651d5..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/repository/ProjectRepositoriesProvider.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.repository; - -import org.sonar.api.utils.log.Profiler; - -import org.sonar.api.batch.bootstrap.ProjectKey; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; - -import org.sonar.batch.analysis.DefaultAnalysisMode; -import org.apache.commons.lang.mutable.MutableBoolean; -import org.picocontainer.injectors.ProviderAdapter; - -public class ProjectRepositoriesProvider extends ProviderAdapter { - private static final Logger LOG = Loggers.get(ProjectRepositoriesProvider.class); - private static final String LOG_MSG = "Load project repositories"; - private ProjectRepositories project = null; - - public ProjectRepositories provide(ProjectRepositoriesLoader loader, ProjectKey projectKey, DefaultAnalysisMode mode) { - if (project == null) { - MutableBoolean fromCache = new MutableBoolean(false); - Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG); - if (mode.isNotAssociated()) { - project = createNonAssociatedProjectRepositories(); - profiler.stopInfo(); - } else { - project = loader.load(projectKey.get(), mode.isIssues(), fromCache); - checkProject(mode); - profiler.stopInfo(fromCache.booleanValue()); - } - - } - - return project; - } - - private void checkProject(DefaultAnalysisMode mode) { - if (mode.isIssues()) { - if (!project.exists()) { - LOG.warn("Project doesn't exist on the server. All issues will be marked as 'new'."); - } else if (project.lastAnalysisDate() == null && !mode.isNotAssociated()) { - LOG.warn("No analysis has been found on the server for this project. All issues will be marked as 'new'."); - } - } - } - - private static ProjectRepositories createNonAssociatedProjectRepositories() { - return new ProjectRepositories(); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/QualityProfileLoader.java b/sonar-batch/src/main/java/org/sonar/batch/repository/QualityProfileLoader.java deleted file mode 100644 index a93bea66b11..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/repository/QualityProfileLoader.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.repository; - -import org.apache.commons.lang.mutable.MutableBoolean; -import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile; - -import javax.annotation.Nullable; - -import java.util.List; - -public interface QualityProfileLoader { - List load(String projectKey, @Nullable String profileName, @Nullable MutableBoolean fromCache); - - List loadDefault(@Nullable String profileName, @Nullable MutableBoolean fromCache); -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/QualityProfileProvider.java b/sonar-batch/src/main/java/org/sonar/batch/repository/QualityProfileProvider.java deleted file mode 100644 index 6878d21ecfb..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/repository/QualityProfileProvider.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.repository; - -import java.util.List; -import javax.annotation.CheckForNull; -import org.apache.commons.lang.mutable.MutableBoolean; -import org.picocontainer.injectors.ProviderAdapter; -import org.sonar.api.batch.bootstrap.ProjectKey; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; -import org.sonar.api.utils.log.Profiler; -import org.sonar.batch.analysis.AnalysisProperties; -import org.sonar.batch.analysis.DefaultAnalysisMode; -import org.sonar.batch.rule.ModuleQProfiles; -import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile; - -public class QualityProfileProvider extends ProviderAdapter { - private static final Logger LOG = Loggers.get(QualityProfileProvider.class); - private static final String LOG_MSG = "Load quality profiles"; - private ModuleQProfiles profiles = null; - - public ModuleQProfiles provide(ProjectKey projectKey, QualityProfileLoader loader, ProjectRepositories projectRepositories, AnalysisProperties props, DefaultAnalysisMode mode) { - if (this.profiles == null) { - List profileList; - MutableBoolean fromCache = new MutableBoolean(); - - Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG); - if (mode.isNotAssociated() || !projectRepositories.exists()) { - profileList = loader.loadDefault(getSonarProfile(props, mode), fromCache); - } else { - profileList = loader.load(projectKey.get(), getSonarProfile(props, mode), fromCache); - } - profiler.stopInfo(fromCache.booleanValue()); - profiles = new ModuleQProfiles(profileList); - } - - return profiles; - } - - @CheckForNull - private static String getSonarProfile(AnalysisProperties props, DefaultAnalysisMode mode) { - String profile = null; - if (!mode.isIssues() && props.properties().containsKey(ModuleQProfiles.SONAR_PROFILE_PROP)) { - profile = props.property(ModuleQProfiles.SONAR_PROFILE_PROP); - LOG.warn("Ability to set quality profile from command line using '" + ModuleQProfiles.SONAR_PROFILE_PROP - + "' is deprecated and will be dropped in a future SonarQube version. Please configure quality profile used by your project on SonarQube server."); - } - return profile; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/ServerIssuesLoader.java b/sonar-batch/src/main/java/org/sonar/batch/repository/ServerIssuesLoader.java deleted file mode 100644 index 7f9154a54ad..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/repository/ServerIssuesLoader.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.repository; - -import com.google.common.base.Function; -import org.sonar.batch.protocol.input.BatchInput.ServerIssue; - -public interface ServerIssuesLoader { - - boolean load(String componentKey, Function consumer); - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/language/DefaultLanguagesRepository.java b/sonar-batch/src/main/java/org/sonar/batch/repository/language/DefaultLanguagesRepository.java deleted file mode 100644 index 4f891e64f3d..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/repository/language/DefaultLanguagesRepository.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.repository.language; - -import org.picocontainer.Startable; - -import org.sonar.api.resources.Languages; - -import javax.annotation.CheckForNull; - -import java.util.ArrayList; -import java.util.Collection; - -/** - * Languages repository using {@link Languages} - * @since 4.4 - */ -public class DefaultLanguagesRepository implements LanguagesRepository, Startable { - - private Languages languages; - - public DefaultLanguagesRepository(Languages languages) { - this.languages = languages; - } - - @Override - public void start() { - if (languages.all().length == 0) { - throw new IllegalStateException("No language plugins are installed."); - } - } - - /** - * Get language. - */ - @Override - @CheckForNull - public Language get(String languageKey) { - org.sonar.api.resources.Language language = languages.get(languageKey); - return language != null ? new Language(language.getKey(), language.getName(), language.getFileSuffixes()) : null; - } - - /** - * Get list of all supported languages. - */ - @Override - public Collection all() { - org.sonar.api.resources.Language[] all = languages.all(); - Collection result = new ArrayList<>(all.length); - for (org.sonar.api.resources.Language language : all) { - result.add(new Language(language.getKey(), language.getName(), language.getFileSuffixes())); - } - return result; - } - - @Override - public void stop() { - // nothing to do - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/language/Language.java b/sonar-batch/src/main/java/org/sonar/batch/repository/language/Language.java deleted file mode 100644 index 1a9ae783536..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/repository/language/Language.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.repository.language; - -import java.util.Arrays; -import java.util.Collection; - -public final class Language { - - private final String key; - private final String name; - private final String[] fileSuffixes; - - public Language(String key, String name, String... fileSuffixes) { - this.key = key; - this.name = name; - this.fileSuffixes = fileSuffixes; - } - - /** - * For example "java". - */ - public String key() { - return key; - } - - /** - * For example "Java" - */ - public String name() { - return name; - } - - /** - * For example ["jav", "java"]. - */ - public Collection fileSuffixes() { - return Arrays.asList(fileSuffixes); - } - - @Override - public String toString() { - return name; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/language/LanguagesRepository.java b/sonar-batch/src/main/java/org/sonar/batch/repository/language/LanguagesRepository.java deleted file mode 100644 index da1bab7993f..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/repository/language/LanguagesRepository.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.repository.language; - -import org.sonar.api.batch.BatchSide; - -import javax.annotation.CheckForNull; - -import java.util.Collection; - -/** - * Languages repository - * @since 4.4 - */ -@BatchSide -public interface LanguagesRepository { - - /** - * Get language. - */ - @CheckForNull - Language get(String languageKey); - - /** - * Get list of all supported languages. - */ - Collection all(); - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/language/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/repository/language/package-info.java deleted file mode 100644 index 03b2bf5f676..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/repository/language/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@javax.annotation.ParametersAreNonnullByDefault -package org.sonar.batch.repository.language; diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/repository/package-info.java deleted file mode 100644 index 3679d1bfbb1..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/repository/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.batch.repository; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/user/UserRepositoryLoader.java b/sonar-batch/src/main/java/org/sonar/batch/repository/user/UserRepositoryLoader.java deleted file mode 100644 index 6a5ad2e06a0..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/repository/user/UserRepositoryLoader.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.repository.user; - -import org.apache.commons.io.IOUtils; - -import org.sonar.batch.cache.WSLoaderResult; -import org.sonar.batch.cache.WSLoader; - -import javax.annotation.Nullable; - -import org.apache.commons.lang.mutable.MutableBoolean; -import com.google.common.collect.Lists; -import com.google.common.base.Joiner; -import org.sonar.batch.util.BatchUtils; -import com.google.common.base.Function; -import org.sonar.batch.protocol.input.BatchInput; - -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -public class UserRepositoryLoader { - private final WSLoader wsLoader; - - public UserRepositoryLoader(WSLoader wsLoader) { - this.wsLoader = wsLoader; - } - - public BatchInput.User load(String userLogin) { - return load(userLogin, null); - } - - public BatchInput.User load(String userLogin, @Nullable MutableBoolean fromCache) { - InputStream is = loadQuery(new UserEncodingFunction().apply(userLogin), fromCache); - return parseUser(is); - } - - public Collection load(List userLogins) { - return load(userLogins, null); - } - - /** - * Not cache friendly. Should not be used if a cache hit is expected. - */ - public Collection load(List userLogins, @Nullable MutableBoolean fromCache) { - if (userLogins.isEmpty()) { - return Collections.emptyList(); - } - InputStream is = loadQuery(Joiner.on(',').join(Lists.transform(userLogins, new UserEncodingFunction())), fromCache); - - return parseUsers(is); - } - - private InputStream loadQuery(String loginsQuery, @Nullable MutableBoolean fromCache) { - WSLoaderResult result = wsLoader.loadStream("/batch/users?logins=" + loginsQuery); - if (fromCache != null) { - fromCache.setValue(result.isFromCache()); - } - return result.get(); - } - - private static class UserEncodingFunction implements Function { - @Override - public String apply(String input) { - return BatchUtils.encodeForUrl(input); - } - } - - private static BatchInput.User parseUser(InputStream is) { - try { - return BatchInput.User.parseDelimitedFrom(is); - } catch (IOException e) { - throw new IllegalStateException("Unable to get user details from server", e); - } finally { - IOUtils.closeQuietly(is); - } - } - - private static Collection parseUsers(InputStream is) { - List users = new ArrayList<>(); - - try { - BatchInput.User user = BatchInput.User.parseDelimitedFrom(is); - while (user != null) { - users.add(user); - user = BatchInput.User.parseDelimitedFrom(is); - } - } catch (IOException e) { - throw new IllegalStateException("Unable to get user details from server", e); - } finally { - IOUtils.closeQuietly(is); - } - - return users; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/user/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/repository/user/package-info.java deleted file mode 100644 index 6462fb00b8a..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/repository/user/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.batch.repository.user; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesLoader.java b/sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesLoader.java deleted file mode 100644 index 028929bd141..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesLoader.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.rule; - -import org.apache.commons.lang.mutable.MutableBoolean; - -import javax.annotation.Nullable; - -import java.util.List; - -public interface ActiveRulesLoader { - List load(String qualityProfileKey, @Nullable MutableBoolean fromCache); -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java b/sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java deleted file mode 100644 index 83034e22132..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.rule; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.apache.commons.lang.mutable.MutableBoolean; -import org.picocontainer.injectors.ProviderAdapter; -import org.sonar.api.batch.rule.ActiveRules; -import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; -import org.sonar.api.batch.rule.internal.NewActiveRule; -import org.sonar.api.rule.RuleKey; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; -import org.sonar.api.utils.log.Profiler; - -/** - * Loads the rules that are activated on the Quality profiles - * used by the current project and builds {@link org.sonar.api.batch.rule.ActiveRules}. - */ -public class ActiveRulesProvider extends ProviderAdapter { - private static final Logger LOG = Loggers.get(ActiveRulesProvider.class); - private static final String LOG_MSG = "Load active rules"; - private ActiveRules singleton = null; - - public ActiveRules provide(ActiveRulesLoader loader, ModuleQProfiles qProfiles) { - if (singleton == null) { - Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG); - MutableBoolean fromCache = new MutableBoolean(); - singleton = load(loader, qProfiles, fromCache); - profiler.stopInfo(fromCache.booleanValue()); - } - return singleton; - } - - private static ActiveRules load(ActiveRulesLoader loader, ModuleQProfiles qProfiles, MutableBoolean fromCache) { - - Collection qProfileKeys = getKeys(qProfiles); - Map loadedRulesByKey = new HashMap<>(); - - try { - for (String qProfileKey : qProfileKeys) { - Collection qProfileRules; - qProfileRules = load(loader, qProfileKey, fromCache); - - for (LoadedActiveRule r : qProfileRules) { - if (!loadedRulesByKey.containsKey(r.getRuleKey())) { - loadedRulesByKey.put(r.getRuleKey(), r); - } - } - } - } catch (IOException e) { - throw new IllegalStateException("Error loading active rules", e); - } - - return transform(loadedRulesByKey.values()); - } - - private static ActiveRules transform(Collection loadedRules) { - ActiveRulesBuilder builder = new ActiveRulesBuilder(); - - for (LoadedActiveRule activeRule : loadedRules) { - NewActiveRule newActiveRule = builder.create(activeRule.getRuleKey()); - newActiveRule.setName(activeRule.getName()); - newActiveRule.setSeverity(activeRule.getSeverity()); - newActiveRule.setLanguage(activeRule.getLanguage()); - newActiveRule.setInternalKey(activeRule.getInternalKey()); - newActiveRule.setTemplateRuleKey(activeRule.getTemplateRuleKey()); - - // load parameters - if (activeRule.getParams() != null) { - for (Map.Entry params : activeRule.getParams().entrySet()) { - newActiveRule.setParam(params.getKey(), params.getValue()); - } - } - - newActiveRule.activate(); - } - return builder.build(); - } - - private static List load(ActiveRulesLoader loader, String qProfileKey, MutableBoolean fromCache) throws IOException { - return loader.load(qProfileKey, fromCache); - } - - private static Collection getKeys(ModuleQProfiles qProfiles) { - List keys = new ArrayList<>(qProfiles.findAll().size()); - - for (QProfile qp : qProfiles.findAll()) { - keys.add(qp.getKey()); - } - - return keys; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/DefaultActiveRulesLoader.java b/sonar-batch/src/main/java/org/sonar/batch/rule/DefaultActiveRulesLoader.java deleted file mode 100644 index 9485d99e1cb..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/DefaultActiveRulesLoader.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.rule; - -import org.sonar.batch.util.BatchUtils; - -import java.io.IOException; -import java.io.InputStream; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import javax.annotation.Nullable; - -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang.mutable.MutableBoolean; -import org.sonar.api.rule.RuleKey; -import org.sonar.batch.cache.WSLoader; -import org.sonar.batch.cache.WSLoaderResult; -import org.sonarqube.ws.Rules.Active; -import org.sonarqube.ws.Rules.Active.Param; -import org.sonarqube.ws.Rules.ActiveList; -import org.sonarqube.ws.Rules.Rule; -import org.sonarqube.ws.Rules.SearchResponse; - -public class DefaultActiveRulesLoader implements ActiveRulesLoader { - private static final String RULES_SEARCH_URL = "/api/rules/search.protobuf?f=repo,name,severity,lang,internalKey,templateKey,params,actives&activation=true"; - - private final WSLoader wsLoader; - - public DefaultActiveRulesLoader(WSLoader wsLoader) { - this.wsLoader = wsLoader; - } - - @Override - public List load(String qualityProfileKey, @Nullable MutableBoolean fromCache) { - List ruleList = new LinkedList<>(); - int page = 1; - int pageSize = 500; - int loaded = 0; - - while (true) { - WSLoaderResult result = wsLoader.loadStream(getUrl(qualityProfileKey, page, pageSize)); - SearchResponse response = loadFromStream(result.get()); - List pageRules = readPage(response); - ruleList.addAll(pageRules); - loaded += response.getPs(); - - if (response.getTotal() <= loaded) { - break; - } - page++; - if (fromCache != null) { - fromCache.setValue(result.isFromCache()); - } - } - - return ruleList; - } - - private static String getUrl(String qualityProfileKey, int page, int pageSize) { - StringBuilder builder = new StringBuilder(1024); - builder.append(RULES_SEARCH_URL); - builder.append("&qprofile=").append(BatchUtils.encodeForUrl(qualityProfileKey)); - builder.append("&p=").append(page); - builder.append("&ps=").append(pageSize); - return builder.toString(); - } - - private static SearchResponse loadFromStream(InputStream is) { - try { - return SearchResponse.parseFrom(is); - } catch (IOException e) { - throw new IllegalStateException("Failed to load quality profiles", e); - } finally { - IOUtils.closeQuietly(is); - } - } - - private static List readPage(SearchResponse response) { - List loadedRules = new LinkedList<>(); - - List rulesList = response.getRulesList(); - Map actives = response.getActives().getActives(); - - for (Rule r : rulesList) { - ActiveList activeList = actives.get(r.getKey()); - Active active = activeList.getActiveList(0); - - LoadedActiveRule loadedRule = new LoadedActiveRule(); - - loadedRule.setRuleKey(RuleKey.parse(r.getKey())); - loadedRule.setName(r.getName()); - loadedRule.setSeverity(active.getSeverity()); - loadedRule.setLanguage(r.getLang()); - loadedRule.setInternalKey(r.getInternalKey()); - if (r.hasTemplateKey()) { - RuleKey templateRuleKey = RuleKey.parse(r.getTemplateKey()); - loadedRule.setTemplateRuleKey(templateRuleKey.rule()); - } - - Map params = new HashMap<>(); - - for (org.sonarqube.ws.Rules.Rule.Param param : r.getParams().getParamsList()) { - params.put(param.getKey(), param.getDefaultValue()); - } - - // overrides defaultValue if the key is the same - for (Param param : active.getParamsList()) { - params.put(param.getKey(), param.getValue()); - } - loadedRule.setParams(params); - loadedRules.add(loadedRule); - } - - return loadedRules; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/DefaultRulesLoader.java b/sonar-batch/src/main/java/org/sonar/batch/rule/DefaultRulesLoader.java deleted file mode 100644 index 62292b4581b..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/DefaultRulesLoader.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.rule; - -import org.apache.commons.io.IOUtils; - -import org.sonar.batch.cache.WSLoaderResult; -import org.sonar.batch.cache.WSLoader; - -import javax.annotation.Nullable; - -import org.apache.commons.lang.mutable.MutableBoolean; -import org.sonarqube.ws.Rules.ListResponse.Rule; -import org.sonarqube.ws.Rules.ListResponse; - -import java.io.IOException; -import java.io.InputStream; -import java.util.List; - -public class DefaultRulesLoader implements RulesLoader { - private static final String RULES_SEARCH_URL = "/api/rules/list.protobuf"; - - private final WSLoader wsLoader; - - public DefaultRulesLoader(WSLoader wsLoader) { - this.wsLoader = wsLoader; - } - - @Override - public List load(@Nullable MutableBoolean fromCache) { - WSLoaderResult result = wsLoader.loadStream(RULES_SEARCH_URL); - ListResponse list = loadFromStream(result.get()); - if (fromCache != null) { - fromCache.setValue(result.isFromCache()); - } - return list.getRulesList(); - } - - private static ListResponse loadFromStream(InputStream is) { - try { - return ListResponse.parseFrom(is); - } catch (IOException e) { - throw new IllegalStateException("Unable to get rules", e); - } finally { - IOUtils.closeQuietly(is); - } - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/LoadedActiveRule.java b/sonar-batch/src/main/java/org/sonar/batch/rule/LoadedActiveRule.java deleted file mode 100644 index 31e5919220f..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/LoadedActiveRule.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.rule; - -import java.util.Map; -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; -import org.sonar.api.rule.RuleKey; - -public class LoadedActiveRule { - private RuleKey ruleKey; - private String severity; - private String name; - private String language; - private Map params; - private String templateRuleKey; - private String internalKey; - - public RuleKey getRuleKey() { - return ruleKey; - } - - public void setRuleKey(RuleKey ruleKey) { - this.ruleKey = ruleKey; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getSeverity() { - return severity; - } - - public void setSeverity(String severity) { - this.severity = severity; - } - - public String getLanguage() { - return language; - } - - public void setLanguage(String language) { - this.language = language; - } - - public Map getParams() { - return params; - } - - public void setParams(Map params) { - this.params = params; - } - - @CheckForNull - public String getTemplateRuleKey() { - return templateRuleKey; - } - - public void setTemplateRuleKey(@Nullable String templateRuleKey) { - this.templateRuleKey = templateRuleKey; - } - - public String getInternalKey() { - return internalKey; - } - - public void setInternalKey(String internalKey) { - this.internalKey = internalKey; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/ModuleQProfiles.java b/sonar-batch/src/main/java/org/sonar/batch/rule/ModuleQProfiles.java deleted file mode 100644 index 5a671de840f..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/ModuleQProfiles.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.rule; - -import org.sonar.api.utils.DateUtils; - -import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile; -import com.google.common.collect.ImmutableMap; -import org.sonar.api.batch.BatchSide; - -import javax.annotation.CheckForNull; - -import java.util.Collection; -import java.util.Map; - -/** - * Lists the Quality profiles enabled on the current module. - */ -@BatchSide -public class ModuleQProfiles { - - public static final String SONAR_PROFILE_PROP = "sonar.profile"; - private final Map byLanguage; - - public ModuleQProfiles(Collection profiles) { - ImmutableMap.Builder builder = ImmutableMap.builder(); - - for (QualityProfile qProfile : profiles) { - builder.put(qProfile.getLanguage(), - new QProfile() - .setKey(qProfile.getKey()) - .setName(qProfile.getName()) - .setLanguage(qProfile.getLanguage()) - .setRulesUpdatedAt(DateUtils.parseDateTime(qProfile.getRulesUpdatedAt()))); - } - byLanguage = builder.build(); - } - - public Collection findAll() { - return byLanguage.values(); - } - - @CheckForNull - public QProfile findByLanguage(String language) { - return byLanguage.get(language); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/QProfile.java b/sonar-batch/src/main/java/org/sonar/batch/rule/QProfile.java deleted file mode 100644 index 5abc9955c7d..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/QProfile.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.rule; - -import com.google.common.base.Objects; - -import java.util.Date; - -public class QProfile { - - private String key; - private String name; - private String language; - private Date rulesUpdatedAt; - - public String getKey() { - return key; - } - - public QProfile setKey(String key) { - this.key = key; - return this; - } - - public String getName() { - return name; - } - - public QProfile setName(String name) { - this.name = name; - return this; - } - - public String getLanguage() { - return language; - } - - public QProfile setLanguage(String language) { - this.language = language; - return this; - } - - public Date getRulesUpdatedAt() { - return rulesUpdatedAt; - } - - public QProfile setRulesUpdatedAt(Date d) { - this.rulesUpdatedAt = d; - return this; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - QProfile qProfile = (QProfile) o; - return key.equals(qProfile.key); - } - - @Override - public int hashCode() { - return key.hashCode(); - } - - @Override - public String toString() { - return Objects.toStringHelper(this) - .add("key", key) - .add("name", name) - .add("language", language) - .add("rulesUpdatedAt", rulesUpdatedAt) - .toString(); - } -} 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 deleted file mode 100644 index 758851dafc4..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileSensor.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.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; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.Measure; -import org.sonar.api.resources.Project; - -/** - * Stores which Quality profiles have been used on the current module. - * - * TODO This information should not be stored as a measure but should be send as metadata in the {@link org.sonar.batch.protocol.output.BatchReport} - */ -public class QProfileSensor implements Sensor { - - private final ModuleQProfiles moduleQProfiles; - private final FileSystem fs; - private final AnalysisMode analysisMode; - - 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() - // Useless in issues mode - && !analysisMode.isIssues(); - } - - @Override - public void analyse(Project project, SensorContext context) { - UsedQProfiles used = new UsedQProfiles(); - for (String language : fs.languages()) { - QProfile profile = moduleQProfiles.findByLanguage(language); - if (profile != null) { - used.add(profile); - } - } - Measure detailsMeasure = new Measure<>(CoreMetrics.QUALITY_PROFILES, used.toJson()); - context.saveMeasure(detailsMeasure); - } - - @Override - public String toString() { - return getClass().getSimpleName(); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileVerifier.java b/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileVerifier.java deleted file mode 100644 index 6206a289f17..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileVerifier.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.rule; - -import com.google.common.annotations.VisibleForTesting; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.batch.fs.FileSystem; -import org.sonar.api.config.Settings; -import org.sonar.api.utils.MessageException; - -import static org.apache.commons.lang.StringUtils.isNotEmpty; - -@BatchSide -public class QProfileVerifier { - - private static final Logger LOG = LoggerFactory.getLogger(QProfileVerifier.class); - - private final Settings settings; - private final FileSystem fs; - private final ModuleQProfiles profiles; - - public QProfileVerifier(Settings settings, FileSystem fs, ModuleQProfiles profiles) { - this.settings = settings; - this.fs = fs; - this.profiles = profiles; - } - - public void execute() { - execute(LOG); - } - - @VisibleForTesting - void execute(Logger logger) { - String defaultName = settings.getString(ModuleQProfiles.SONAR_PROFILE_PROP); - boolean defaultNameUsed = StringUtils.isBlank(defaultName); - for (String lang : fs.languages()) { - QProfile profile = profiles.findByLanguage(lang); - if (profile == null) { - logger.warn("No Quality profile found for language " + lang); - } else { - logger.info("Quality profile for {}: {}", lang, profile.getName()); - if (isNotEmpty(defaultName) && defaultName.equals(profile.getName())) { - defaultNameUsed = true; - } - } - } - if (!defaultNameUsed && !fs.languages().isEmpty()) { - throw MessageException.of("sonar.profile was set to '" + defaultName + "' but didn't match any profile for any language. Please check your configuration."); - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/RuleFinderCompatibility.java b/sonar-batch/src/main/java/org/sonar/batch/rule/RuleFinderCompatibility.java deleted file mode 100644 index fe763f873bd..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/RuleFinderCompatibility.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.rule; - -import org.sonar.api.batch.rule.Rules; - -import com.google.common.base.Function; -import com.google.common.collect.Collections2; -import org.apache.commons.lang.builder.ReflectionToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; -import org.sonar.api.rule.RuleKey; -import org.sonar.api.rules.Rule; -import org.sonar.api.rules.RuleFinder; -import org.sonar.api.rules.RuleQuery; - -import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; - -/** - * FIXME Waiting for the list of all server rules on batch side this is implemented by redirecting on ActiveRules. This is not correct - * since there is a difference between a rule that doesn't exists and a rule that is not activated in project quality profile. - * - */ -public class RuleFinderCompatibility implements RuleFinder { - - private final Rules rules; - private static Function ruleTransformer = new Function() { - @Override - public Rule apply(@Nonnull org.sonar.api.batch.rule.Rule input) { - return toRule(input); - } - }; - - public RuleFinderCompatibility(Rules rules) { - this.rules = rules; - } - - @Override - public Rule findById(int ruleId) { - throw new UnsupportedOperationException("Unable to find rule by id"); - } - - @Override - public Rule findByKey(String repositoryKey, String key) { - return findByKey(RuleKey.of(repositoryKey, key)); - } - - @Override - public Rule findByKey(RuleKey key) { - return toRule(rules.find(key)); - } - - @Override - public Rule find(RuleQuery query) { - Collection all = findAll(query); - if (all.size() > 1) { - throw new IllegalArgumentException("Non unique result for rule query: " + ReflectionToStringBuilder.toString(query, ToStringStyle.SHORT_PREFIX_STYLE)); - } else if (all.isEmpty()) { - return null; - } else { - return all.iterator().next(); - } - } - - @Override - public Collection findAll(RuleQuery query) { - if (query.getConfigKey() != null) { - if (query.getRepositoryKey() != null && query.getKey() == null) { - return byInternalKey(query); - } - } else if (query.getRepositoryKey() != null) { - if (query.getKey() != null) { - return byKey(query); - } else { - return byRepository(query); - } - } - throw new UnsupportedOperationException("Unable to find rule by query"); - } - - private Collection byRepository(RuleQuery query) { - return Collections2.transform(rules.findByRepository(query.getRepositoryKey()), ruleTransformer); - } - - - - private Collection byKey(RuleQuery query) { - Rule rule = toRule(rules.find(RuleKey.of(query.getRepositoryKey(), query.getKey()))); - return rule != null ? Arrays.asList(rule) : Collections.emptyList(); - } - - private Collection byInternalKey(RuleQuery query) { - return Collections2.transform(rules.findByInternalKey(query.getRepositoryKey(), query.getConfigKey()), ruleTransformer); - } - - @CheckForNull - private static Rule toRule(@Nullable org.sonar.api.batch.rule.Rule ar) { - return ar == null ? null : Rule.create(ar.key().repository(), ar.key().rule()).setName(ar.name()).setConfigKey(ar.internalKey()); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/RulesLoader.java b/sonar-batch/src/main/java/org/sonar/batch/rule/RulesLoader.java deleted file mode 100644 index 9572f628f2d..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/RulesLoader.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.rule; - -import java.util.List; -import javax.annotation.Nullable; -import org.apache.commons.lang.mutable.MutableBoolean; -import org.sonarqube.ws.Rules.ListResponse.Rule; - -public interface RulesLoader { - List load(@Nullable MutableBoolean fromCache); -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProfileProvider.java b/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProfileProvider.java deleted file mode 100644 index de29cc352fc..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProfileProvider.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.rule; - -import com.google.common.collect.Lists; -import java.util.Collection; -import java.util.Map; -import org.apache.commons.lang.StringUtils; -import org.picocontainer.injectors.ProviderAdapter; -import org.sonar.api.CoreProperties; -import org.sonar.api.batch.rule.ActiveRules; -import org.sonar.api.config.Settings; -import org.sonar.api.profiles.RulesProfile; -import org.sonar.api.rules.ActiveRule; -import org.sonar.api.rules.Rule; -import org.sonar.api.rules.RulePriority; - -/** - * Ensures backward-compatibility with extensions that use {@link org.sonar.api.profiles.RulesProfile}. - */ -public class RulesProfileProvider extends ProviderAdapter { - - private RulesProfile singleton = null; - - public RulesProfile provide(ModuleQProfiles qProfiles, ActiveRules activeRules, Settings settings) { - if (singleton == null) { - String lang = settings.getString(CoreProperties.PROJECT_LANGUAGE_PROPERTY); - if (StringUtils.isNotBlank(lang)) { - // Backward-compatibility with single-language modules - singleton = loadSingleLanguageProfile(qProfiles, activeRules, lang); - } else { - singleton = loadProfiles(qProfiles, activeRules); - } - } - return singleton; - } - - private static RulesProfile loadSingleLanguageProfile(ModuleQProfiles qProfiles, ActiveRules activeRules, String language) { - QProfile qProfile = qProfiles.findByLanguage(language); - if (qProfile != null) { - return new RulesProfileWrapper(select(qProfile, activeRules)); - } - return new RulesProfileWrapper(Lists.newArrayList()); - } - - private static RulesProfile loadProfiles(ModuleQProfiles qProfiles, ActiveRules activeRules) { - Collection dtos = Lists.newArrayList(); - for (QProfile qProfile : qProfiles.findAll()) { - dtos.add(select(qProfile, activeRules)); - } - return new RulesProfileWrapper(dtos); - } - - private static RulesProfile select(QProfile qProfile, ActiveRules activeRules) { - RulesProfile deprecatedProfile = new RulesProfile(); - // TODO deprecatedProfile.setVersion(qProfile.version()); - deprecatedProfile.setName(qProfile.getName()); - deprecatedProfile.setLanguage(qProfile.getLanguage()); - for (org.sonar.api.batch.rule.ActiveRule activeRule : activeRules.findByLanguage(qProfile.getLanguage())) { - Rule rule = Rule.create(activeRule.ruleKey().repository(), activeRule.ruleKey().rule()); - rule.setConfigKey(activeRule.internalKey()); - - // SONAR-6706 - if (activeRule.templateRuleKey() != null) { - rule.setTemplate(Rule.create(activeRule.ruleKey().repository(), activeRule.templateRuleKey())); - } - - ActiveRule deprecatedActiveRule = deprecatedProfile.activateRule(rule, - RulePriority.valueOf(activeRule.severity())); - for (Map.Entry param : activeRule.params().entrySet()) { - rule.createParameter(param.getKey()); - deprecatedActiveRule.setParameter(param.getKey(), param.getValue()); - } - } - return deprecatedProfile; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProfileWrapper.java b/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProfileWrapper.java deleted file mode 100644 index 327c141ea34..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProfileWrapper.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.rule; - -import com.google.common.collect.Lists; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.profiles.RulesProfile; -import org.sonar.api.rules.ActiveRule; -import org.sonar.api.rules.Rule; -import org.sonar.api.utils.SonarException; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -/** - * This wrapper is used to try to preserve backward compatibility for plugins that used to - * depends on {@link org.sonar.api.profiles.RulesProfile} - * - * @since 4.2 - */ -public class RulesProfileWrapper extends RulesProfile { - - private static final Logger LOG = LoggerFactory.getLogger(RulesProfileWrapper.class); - private static final String DEPRECATED_USAGE_MESSAGE = "Please update your plugin to support multi-language analysis"; - - private final Collection profiles; - private final RulesProfile singleLanguageProfile; - - public RulesProfileWrapper(Collection profiles) { - this.profiles = profiles; - this.singleLanguageProfile = null; - } - - public RulesProfileWrapper(RulesProfile profile) { - this.profiles = Lists.newArrayList(profile); - this.singleLanguageProfile = profile; - } - - @Override - public Integer getId() { - return getSingleProfileOrFail().getId(); - } - - private RulesProfile getSingleProfileOrFail() { - if (singleLanguageProfile == null) { - throw new IllegalStateException(DEPRECATED_USAGE_MESSAGE); - } - return singleLanguageProfile; - } - - @Override - public String getName() { - return singleLanguageProfile != null ? singleLanguageProfile.getName() : "SonarQube"; - } - - @Override - public String getLanguage() { - if (singleLanguageProfile == null) { - // Multi-languages module - // This is a hack for CommonChecksDecorator that call this method in its constructor - LOG.debug(DEPRECATED_USAGE_MESSAGE, new SonarException(DEPRECATED_USAGE_MESSAGE)); - return ""; - } - return singleLanguageProfile.getLanguage(); - } - - @Override - public List getActiveRules() { - List activeRules = new ArrayList<>(); - for (RulesProfile profile : profiles) { - activeRules.addAll(profile.getActiveRules()); - } - return activeRules; - } - - @Override - public ActiveRule getActiveRule(String repositoryKey, String ruleKey) { - for (RulesProfile profile : profiles) { - ActiveRule activeRule = profile.getActiveRule(repositoryKey, ruleKey); - if (activeRule != null) { - return activeRule; - } - } - return null; - } - - @Override - public List getActiveRulesByRepository(String repositoryKey) { - List activeRules = new ArrayList<>(); - for (RulesProfile profile : profiles) { - activeRules.addAll(profile.getActiveRulesByRepository(repositoryKey)); - } - return activeRules; - } - - @Override - public List getActiveRules(boolean acceptDisabledRules) { - List activeRules = new ArrayList<>(); - for (RulesProfile profile : profiles) { - activeRules.addAll(profile.getActiveRules(acceptDisabledRules)); - } - return activeRules; - } - - @Override - public ActiveRule getActiveRule(Rule rule) { - for (RulesProfile profile : profiles) { - ActiveRule activeRule = profile.getActiveRule(rule); - if (activeRule != null) { - return activeRule; - } - } - return null; - } - - @Override - public Boolean getDefaultProfile() { - return getSingleProfileOrFail().getDefaultProfile(); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java b/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java deleted file mode 100644 index 7a3e0ea34f0..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.rule; - -import org.apache.commons.lang.mutable.MutableBoolean; - -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; -import org.sonar.api.utils.log.Profiler; - -import java.util.List; - -import org.sonarqube.ws.Rules.ListResponse.Rule; -import org.picocontainer.injectors.ProviderAdapter; -import org.sonar.api.rule.RuleKey; -import org.sonar.api.batch.rule.internal.RulesBuilder; -import org.sonar.api.batch.rule.internal.NewRule; -import org.sonar.api.batch.rule.Rules; - -public class RulesProvider extends ProviderAdapter { - private static final Logger LOG = Loggers.get(RulesProvider.class); - private static final String LOG_MSG = "Load server rules"; - private Rules singleton = null; - - public Rules provide(RulesLoader ref) { - if (singleton == null) { - singleton = load(ref); - } - return singleton; - } - - private static Rules load(RulesLoader ref) { - Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG); - MutableBoolean fromCache = new MutableBoolean(); - List loadedRules = ref.load(fromCache); - RulesBuilder builder = new RulesBuilder(); - - for (Rule r : loadedRules) { - NewRule newRule = builder.add(RuleKey.of(r.getRepository(), r.getKey())); - newRule.setName(r.getName()); - newRule.setInternalKey(r.getInternalKey()); - } - - profiler.stopInfo(fromCache.booleanValue()); - - return builder.build(); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/UsedQProfiles.java b/sonar-batch/src/main/java/org/sonar/batch/rule/UsedQProfiles.java deleted file mode 100644 index 72186a5e959..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/UsedQProfiles.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.rule; - -import com.google.common.collect.Sets; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import org.sonar.api.utils.text.JsonWriter; -import org.sonar.core.util.UtcDateUtils; - -import javax.annotation.concurrent.Immutable; - -import java.io.StringWriter; -import java.util.Collection; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Map; -import java.util.SortedSet; - -@Immutable -public class UsedQProfiles { - - private final SortedSet profiles = Sets.newTreeSet(new Comparator() { - @Override - public int compare(QProfile o1, QProfile o2) { - int c = o1.getLanguage().compareTo(o2.getLanguage()); - if (c == 0) { - c = o1.getName().compareTo(o2.getName()); - } - return c; - } - }); - - public static UsedQProfiles fromJson(String json) { - UsedQProfiles result = new UsedQProfiles(); - JsonArray jsonRoot = new JsonParser().parse(json).getAsJsonArray(); - for (JsonElement jsonElt : jsonRoot) { - JsonObject jsonProfile = jsonElt.getAsJsonObject(); - QProfile profile = new QProfile(); - profile.setKey(jsonProfile.get("key").getAsString()); - profile.setName(jsonProfile.get("name").getAsString()); - profile.setLanguage(jsonProfile.get("language").getAsString()); - profile.setRulesUpdatedAt(UtcDateUtils.parseDateTime(jsonProfile.get("rulesUpdatedAt").getAsString())); - result.add(profile); - } - return result; - } - - public String toJson() { - StringWriter json = new StringWriter(); - JsonWriter writer = JsonWriter.of(json); - writer.beginArray(); - for (QProfile profile : profiles) { - writer - .beginObject() - .prop("key", profile.getKey()) - .prop("language", profile.getLanguage()) - .prop("name", profile.getName()) - .prop("rulesUpdatedAt", UtcDateUtils.formatDateTime(profile.getRulesUpdatedAt())) - .endObject(); - } - writer.endArray(); - writer.close(); - return json.toString(); - } - - public UsedQProfiles add(UsedQProfiles other) { - addAll(other.profiles); - return this; - } - - public UsedQProfiles add(QProfile profile) { - profiles.add(profile); - return this; - } - - public UsedQProfiles addAll(Collection profiles) { - this.profiles.addAll(profiles); - return this; - } - - public SortedSet profiles() { - return profiles; - } - - public Map profilesByKey() { - Map map = new HashMap<>(); - for (QProfile profile : profiles) { - map.put(profile.getKey(), profile); - } - return map; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/rule/package-info.java deleted file mode 100644 index 1bdc402f399..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.batch.rule; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ImmutableProjectReactor.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ImmutableProjectReactor.java deleted file mode 100644 index 4bfa99c6da2..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ImmutableProjectReactor.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan; - -import java.util.Collection; -import java.util.LinkedHashMap; -import java.util.Map; -import javax.annotation.CheckForNull; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.batch.bootstrap.ProjectDefinition; - -/** - * Immutable copy of project reactor after all modifications have been applied (see {@link ImmutableProjectReactorProvider}). - */ -@BatchSide -public class ImmutableProjectReactor { - - private ProjectDefinition root; - private Map byKey = new LinkedHashMap<>(); - - public ImmutableProjectReactor(ProjectDefinition root) { - if (root.getParent() != null) { - throw new IllegalArgumentException("Not a root project: " + root); - } - this.root = root; - collectProjects(root); - } - - public Collection getProjects() { - return byKey.values(); - } - - /** - * Populates list of projects from hierarchy. - */ - private void collectProjects(ProjectDefinition def) { - if (byKey.containsKey(def.getKeyWithBranch())) { - throw new IllegalStateException("Duplicate module key in reactor: " + def.getKeyWithBranch()); - } - byKey.put(def.getKeyWithBranch(), def); - for (ProjectDefinition child : def.getSubProjects()) { - collectProjects(child); - } - } - - public ProjectDefinition getRoot() { - return root; - } - - @CheckForNull - public ProjectDefinition getProjectDefinition(String keyWithBranch) { - return byKey.get(keyWithBranch); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ImmutableProjectReactorProvider.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ImmutableProjectReactorProvider.java deleted file mode 100644 index ecf58a88482..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ImmutableProjectReactorProvider.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan; - -import org.picocontainer.injectors.ProviderAdapter; -import org.sonar.api.batch.bootstrap.ProjectReactor; - -public class ImmutableProjectReactorProvider extends ProviderAdapter { - - private ImmutableProjectReactor singleton; - - public ImmutableProjectReactor provide(ProjectReactor reactor, ProjectBuildersExecutor projectBuildersExecutor, ProjectExclusions exclusions, ProjectReactorValidator validator) { - if (singleton == null) { - // 1 Apply project builders - projectBuildersExecutor.execute(reactor); - - // 2 Apply project exclusions - exclusions.apply(reactor); - - // 3 Validate final reactor - validator.validate(reactor); - - singleton = new ImmutableProjectReactor(reactor.getRoot()); - } - return singleton; - } -} 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 deleted file mode 100644 index 83e27324e64..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/LanguageVerifier.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan; - -import org.sonar.batch.repository.language.Language; -import org.sonar.batch.repository.language.LanguagesRepository; -import org.apache.commons.lang.StringUtils; -import org.picocontainer.Startable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -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; - -/** - * Verifies that the property sonar.language is valid - */ -public class LanguageVerifier implements Startable { - - private static final Logger LOG = LoggerFactory.getLogger(LanguageVerifier.class); - - private final Settings settings; - private final LanguagesRepository languages; - private final DefaultFileSystem fs; - - public LanguageVerifier(Settings settings, LanguagesRepository languages, DefaultFileSystem fs) { - this.settings = settings; - this.languages = languages; - this.fs = fs; - } - - @Override - public void start() { - String languageKey = settings.getString(CoreProperties.PROJECT_LANGUAGE_PROPERTY); - if (StringUtils.isNotBlank(languageKey)) { - LOG.info("Language is forced to {}", languageKey); - Language language = languages.get(languageKey); - if (language == null) { - throw MessageException.of("You must install a plugin that supports the language '" + languageKey + "'"); - } - - // force the registration of the language, even if there are no related source files - fs.addLanguages(languageKey); - } - } - - @Override - public void stop() { - // nothing to do - } -} 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 deleted file mode 100644 index 56da7fd624d..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.batch.AnalysisMode; -import org.sonar.api.batch.InstantiationStrategy; -import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.api.batch.fs.internal.FileMetadata; -import org.sonar.api.batch.rule.CheckFactory; -import org.sonar.api.resources.Project; -import org.sonar.api.scan.filesystem.FileExclusions; -import org.sonar.batch.DefaultProjectTree; -import org.sonar.batch.bootstrap.BatchExtensionDictionnary; -import org.sonar.batch.bootstrap.ExtensionInstaller; -import org.sonar.batch.bootstrap.ExtensionMatcher; -import org.sonar.batch.bootstrap.ExtensionUtils; -import org.sonar.batch.deprecated.DeprecatedSensorContext; -import org.sonar.batch.deprecated.perspectives.BatchPerspectives; -import org.sonar.batch.events.EventBus; -import org.sonar.batch.index.BatchComponentCache; -import org.sonar.batch.index.DefaultIndex; -import org.sonar.batch.issue.IssuableFactory; -import org.sonar.batch.issue.IssueFilters; -import org.sonar.batch.issue.ModuleIssues; -import org.sonar.batch.issue.ignore.EnforceIssuesFilter; -import org.sonar.batch.issue.ignore.IgnoreIssuesFilter; -import org.sonar.batch.issue.ignore.pattern.IssueExclusionPatternInitializer; -import org.sonar.batch.issue.ignore.pattern.IssueInclusionPatternInitializer; -import org.sonar.batch.issue.ignore.scanner.IssueExclusionsLoader; -import org.sonar.batch.issue.ignore.scanner.IssueExclusionsRegexpScanner; -import org.sonar.batch.phases.AbstractPhaseExecutor; -import org.sonar.batch.phases.InitializersExecutor; -import org.sonar.batch.phases.IssuesPhaseExecutor; -import org.sonar.batch.phases.PostJobsExecutor; -import org.sonar.batch.phases.ProjectInitializer; -import org.sonar.batch.phases.PublishPhaseExecutor; -import org.sonar.batch.phases.SensorsExecutor; -import org.sonar.batch.postjob.DefaultPostJobContext; -import org.sonar.batch.postjob.PostJobOptimizer; -import org.sonar.batch.rule.QProfileSensor; -import org.sonar.batch.rule.QProfileVerifier; -import org.sonar.batch.rule.RuleFinderCompatibility; -import org.sonar.batch.rule.RulesProfileProvider; -import org.sonar.batch.scan.filesystem.ComponentIndexer; -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.FileSystemLogger; -import org.sonar.batch.scan.filesystem.InputFileBuilderFactory; -import org.sonar.batch.scan.filesystem.LanguageDetectionFactory; -import org.sonar.batch.scan.filesystem.ModuleFileSystemInitializer; -import org.sonar.batch.scan.filesystem.ModuleInputFileCache; -import org.sonar.batch.scan.filesystem.StatusDetectionFactory; -import org.sonar.batch.scan.report.IssuesReports; -import org.sonar.batch.sensor.DefaultSensorStorage; -import org.sonar.batch.sensor.SensorOptimizer; -import org.sonar.batch.sensor.coverage.CoverageExclusions; -import org.sonar.batch.source.HighlightableBuilder; -import org.sonar.batch.source.SymbolizableBuilder; -import org.sonar.core.platform.ComponentContainer; - -public class ModuleScanContainer extends ComponentContainer { - private static final Logger LOG = LoggerFactory.getLogger(ModuleScanContainer.class); - private final Project module; - - public ModuleScanContainer(ProjectScanContainer parent, Project module) { - super(parent); - this.module = module; - } - - @Override - protected void doBeforeStart() { - LOG.info("------------- Scan {}", module.getName()); - addCoreComponents(); - addExtensions(); - } - - private void addCoreComponents() { - ProjectDefinition moduleDefinition = getComponentByType(DefaultProjectTree.class).getProjectDefinition(module); - add( - moduleDefinition, - module, - getComponentByType(BatchComponentCache.class).get(module).inputComponent(), - ModuleSettings.class); - - // hack to initialize settings before ExtensionProviders - ModuleSettings moduleSettings = getComponentByType(ModuleSettings.class); - module.setSettings(moduleSettings); - - if (getComponentByType(AnalysisMode.class).isIssues()) { - add(IssuesPhaseExecutor.class, - IssuesReports.class); - } else { - add(PublishPhaseExecutor.class); - } - - add( - EventBus.class, - RuleFinderCompatibility.class, - PostJobsExecutor.class, - SensorsExecutor.class, - InitializersExecutor.class, - ProjectInitializer.class, - - // file system - ModuleInputFileCache.class, - FileExclusions.class, - ExclusionFilters.class, - DeprecatedFileFilters.class, - InputFileBuilderFactory.class, - FileMetadata.class, - StatusDetectionFactory.class, - LanguageDetectionFactory.class, - FileIndexer.class, - ComponentIndexer.class, - LanguageVerifier.class, - FileSystemLogger.class, - DefaultModuleFileSystem.class, - ModuleFileSystemInitializer.class, - QProfileVerifier.class, - - SensorOptimizer.class, - PostJobOptimizer.class, - - DefaultPostJobContext.class, - DefaultSensorStorage.class, - DeprecatedSensorContext.class, - BatchExtensionDictionnary.class, - IssueFilters.class, - CoverageExclusions.class, - - // rules - new RulesProfileProvider(), - QProfileSensor.class, - CheckFactory.class, - - // issues - IssuableFactory.class, - ModuleIssues.class, - org.sonar.api.issue.NoSonarFilter.class, - - // issue exclusions - IssueInclusionPatternInitializer.class, - IssueExclusionPatternInitializer.class, - IssueExclusionsRegexpScanner.class, - IssueExclusionsLoader.class, - EnforceIssuesFilter.class, - IgnoreIssuesFilter.class, - - // Perspectives - BatchPerspectives.class, - HighlightableBuilder.class, - SymbolizableBuilder.class); - } - - private void addExtensions() { - ExtensionInstaller installer = getComponentByType(ExtensionInstaller.class); - installer.install(this, new ExtensionMatcher() { - @Override - public boolean accept(Object extension) { - return ExtensionUtils.isBatchSide(extension) && ExtensionUtils.isInstantiationStrategy(extension, InstantiationStrategy.PER_PROJECT); - } - }); - } - - @Override - protected void doAfterStart() { - DefaultIndex index = getComponentByType(DefaultIndex.class); - index.setCurrentProject(module, getComponentByType(DefaultSensorStorage.class)); - - getComponentByType(AbstractPhaseExecutor.class).execute(module); - - // Free memory since module settings are no more used - module.setSettings(null); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleSettings.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleSettings.java deleted file mode 100644 index 2176ad347fe..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleSettings.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan; - -import com.google.common.collect.Lists; -import java.util.List; -import org.sonar.api.CoreProperties; -import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.api.config.Settings; -import org.sonar.api.utils.MessageException; -import org.sonar.batch.analysis.DefaultAnalysisMode; -import org.sonar.batch.bootstrap.GlobalSettings; -import org.sonar.batch.report.AnalysisContextReportPublisher; -import org.sonar.batch.repository.ProjectRepositories; - -/** - * @since 2.12 - */ -public class ModuleSettings extends Settings { - - private final ProjectRepositories projectRepos; - private final DefaultAnalysisMode analysisMode; - - public ModuleSettings(GlobalSettings batchSettings, ProjectDefinition moduleDefinition, ProjectRepositories projectSettingsRepo, - DefaultAnalysisMode analysisMode, AnalysisContextReportPublisher contextReportPublisher) { - super(batchSettings.getDefinitions()); - this.projectRepos = projectSettingsRepo; - this.analysisMode = analysisMode; - getEncryption().setPathToSecretKey(batchSettings.getString(CoreProperties.ENCRYPTION_SECRET_KEY_PATH)); - - init(moduleDefinition, batchSettings); - contextReportPublisher.dumpSettings(moduleDefinition); - } - - private ModuleSettings init(ProjectDefinition moduleDefinition, GlobalSettings batchSettings) { - addProjectProperties(moduleDefinition, batchSettings); - addBuildProperties(moduleDefinition); - return this; - } - - private void addProjectProperties(ProjectDefinition def, GlobalSettings batchSettings) { - addProperties(batchSettings.getProperties()); - do { - if (projectRepos.moduleExists(def.getKeyWithBranch())) { - addProperties(projectRepos.settings(def.getKeyWithBranch())); - break; - } - def = def.getParent(); - } while (def != null); - } - - private void addBuildProperties(ProjectDefinition project) { - List orderedProjects = getTopDownParentProjects(project); - for (ProjectDefinition p : orderedProjects) { - addProperties(p.properties()); - } - } - - /** - * From root to given project - */ - static List getTopDownParentProjects(ProjectDefinition project) { - List result = Lists.newArrayList(); - ProjectDefinition p = project; - while (p != null) { - result.add(0, p); - p = p.getParent(); - } - return result; - } - - @Override - protected void doOnGetProperties(String key) { - if (analysisMode.isIssues() && key.endsWith(".secured") && !key.contains(".license")) { - throw MessageException.of("Access to the secured property '" + key - + "' is not possible in issues mode. The SonarQube plugin which requires this property must be deactivated in issues mode."); - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/MutableProjectReactorProvider.java b/sonar-batch/src/main/java/org/sonar/batch/scan/MutableProjectReactorProvider.java deleted file mode 100644 index afde1e18c4d..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/MutableProjectReactorProvider.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan; - -import org.picocontainer.injectors.ProviderAdapter; -import org.sonar.api.batch.bootstrap.ProjectReactor; - -public class MutableProjectReactorProvider extends ProviderAdapter { - private ProjectReactor reactor = null; - - public ProjectReactor provide(ProjectReactorBuilder builder) { - if (reactor == null) { - reactor = builder.execute(); - } - return reactor; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectBuildersExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectBuildersExecutor.java deleted file mode 100644 index 505a80bc117..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectBuildersExecutor.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan; - -import org.sonar.api.batch.bootstrap.ProjectBuilder; -import org.sonar.api.batch.bootstrap.ProjectReactor; -import org.sonar.api.batch.bootstrap.internal.ProjectBuilderContext; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; -import org.sonar.api.utils.log.Profiler; - -public class ProjectBuildersExecutor { - - private static final Logger LOG = Loggers.get(ProjectBuildersExecutor.class); - - private final ProjectBuilder[] projectBuilders; - - public ProjectBuildersExecutor(ProjectBuilder... projectBuilders) { - this.projectBuilders = projectBuilders; - } - - public ProjectBuildersExecutor() { - this(new ProjectBuilder[0]); - } - - public void execute(ProjectReactor reactor) { - if (projectBuilders.length > 0) { - Profiler profiler = Profiler.create(LOG).startInfo("Execute project builders"); - ProjectBuilderContext context = new ProjectBuilderContext(reactor); - - for (ProjectBuilder projectBuilder : projectBuilders) { - projectBuilder.build(context); - } - profiler.stopInfo(); - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectExclusions.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectExclusions.java deleted file mode 100644 index 0bea9a81309..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectExclusions.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan; - -import org.apache.commons.lang.ArrayUtils; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.CoreProperties; -import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.api.batch.bootstrap.ProjectReactor; -import org.sonar.api.config.Settings; - -/** - * Exclude the sub-projects as defined by the properties sonar.skippedModules and sonar.includedModules - * - * @since 2.12 - */ -public class ProjectExclusions { - - private static final Logger LOG = LoggerFactory.getLogger(ProjectExclusions.class); - - private Settings settings; - - public ProjectExclusions(Settings settings) { - this.settings = settings; - } - - public void apply(ProjectReactor reactor) { - if (!reactor.getProjects().isEmpty() && StringUtils.isNotBlank(reactor.getProjects().get(0).getKey())) { - LOG.info("Apply project exclusions"); - - if (settings.hasKey(CoreProperties.CORE_INCLUDED_MODULES_PROPERTY)) { - LOG.warn("'sonar.includedModules' property is deprecated since version 4.3 and should not be used anymore."); - } - if (settings.hasKey(CoreProperties.CORE_SKIPPED_MODULES_PROPERTY)) { - LOG.warn("'sonar.skippedModules' property is deprecated since version 4.3 and should not be used anymore."); - } - - for (ProjectDefinition project : reactor.getProjects()) { - if (isExcluded(key(project), project == reactor.getRoot())) { - exclude(project); - } - } - } - } - - private boolean isExcluded(String projectKey, boolean isRoot) { - String[] includedKeys = settings.getStringArray(CoreProperties.CORE_INCLUDED_MODULES_PROPERTY); - boolean excluded = false; - if (!isRoot && includedKeys.length > 0) { - excluded = !ArrayUtils.contains(includedKeys, projectKey); - } - String skippedModulesProperty = CoreProperties.CORE_SKIPPED_MODULES_PROPERTY; - if (!excluded) { - String[] excludedKeys = settings.getStringArray(skippedModulesProperty); - excluded = ArrayUtils.contains(excludedKeys, projectKey); - } - if (excluded && isRoot) { - throw new IllegalArgumentException("The root project can't be excluded. Please check the parameters " + skippedModulesProperty + " and sonar.includedModules."); - } - return excluded; - } - - private void exclude(ProjectDefinition project) { - LOG.info(String.format("Exclude project: %s [%s]", project.getName(), project.getKey())); - project.remove(); - } - - static String key(ProjectDefinition project) { - String key = project.getKey(); - if (key.contains(":")) { - return StringUtils.substringAfter(key, ":"); - } - return key; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectLock.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectLock.java deleted file mode 100644 index d52f49cfd88..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectLock.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan; - -import org.sonar.batch.bootstrap.Slf4jLogger; -import org.sonar.home.cache.DirectoryLock; -import org.picocontainer.Startable; -import org.sonar.api.batch.bootstrap.ProjectReactor; - -import java.io.IOException; -import java.nio.channels.OverlappingFileLockException; -import java.nio.file.Files; -import java.nio.file.Path; - -public class ProjectLock implements Startable { - private final DirectoryLock lock; - - public ProjectLock(ProjectReactor projectReactor) { - Path directory = projectReactor.getRoot().getWorkDir().toPath(); - try { - if (!Files.exists(directory)) { - Files.createDirectories(directory); - } - } catch (IOException e) { - throw new IllegalStateException("Failed to create work directory", e); - } - this.lock = new DirectoryLock(directory.toAbsolutePath(), new Slf4jLogger()); - } - - public void tryLock() { - try { - if (!lock.tryLock()) { - failAlreadyInProgress(null); - } - } catch (OverlappingFileLockException e) { - failAlreadyInProgress(e); - } - } - - private static void failAlreadyInProgress(Exception e) { - throw new IllegalStateException("Another SonarQube analysis is already in progress for this project", e); - } - - @Override - public void stop() { - lock.unlock(); - } - - @Override - public void start() { - // nothing to do - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java deleted file mode 100644 index 2d7e453cfaf..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java +++ /dev/null @@ -1,423 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Lists; -import java.io.File; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.text.MessageFormat; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; -import org.apache.commons.lang.ArrayUtils; -import org.apache.commons.lang.ObjectUtils; -import org.apache.commons.lang.StringUtils; -import org.sonar.api.CoreProperties; -import org.sonar.api.batch.AnalysisMode; -import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.api.batch.bootstrap.ProjectReactor; -import org.sonar.api.utils.MessageException; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; -import org.sonar.api.utils.log.Profiler; -import org.sonar.batch.analysis.AnalysisProperties; -import org.sonar.batch.bootstrap.DroppedPropertyChecker; -import org.sonar.batch.util.BatchUtils; - -/** - * Class that creates a project definition based on a set of properties. - */ -public class ProjectReactorBuilder { - - private static final String INVALID_VALUE_OF_X_FOR_Y = "Invalid value of {0} for {1}"; - - /** - * A map of dropped properties as key and specific message to display for that property - * (what will happen, what should the user do, ...) as a value - */ - private static final Map DROPPED_PROPERTIES = ImmutableMap.of( - "sonar.qualitygate", "It will be ignored."); - - private static final Logger LOG = Loggers.get(ProjectReactorBuilder.class); - - /** - * @since 4.1 but not yet exposed in {@link CoreProperties} - */ - private static final String MODULE_KEY_PROPERTY = "sonar.moduleKey"; - - protected static final String PROPERTY_PROJECT_BASEDIR = "sonar.projectBaseDir"; - private static final String PROPERTY_PROJECT_BUILDDIR = "sonar.projectBuildDir"; - private static final String PROPERTY_MODULES = "sonar.modules"; - - /** - * New properties, to be consistent with Sonar naming conventions - * - * @since 1.5 - */ - private static final String PROPERTY_SOURCES = "sonar.sources"; - private static final String PROPERTY_TESTS = "sonar.tests"; - - /** - * Array of all mandatory properties required for a project without child. - */ - private static final String[] MANDATORY_PROPERTIES_FOR_SIMPLE_PROJECT = { - PROPERTY_PROJECT_BASEDIR, CoreProperties.PROJECT_KEY_PROPERTY, CoreProperties.PROJECT_NAME_PROPERTY, - CoreProperties.PROJECT_VERSION_PROPERTY, PROPERTY_SOURCES - }; - - /** - * Array of all mandatory properties required for a project with children. - */ - private static final String[] MANDATORY_PROPERTIES_FOR_MULTIMODULE_PROJECT = {PROPERTY_PROJECT_BASEDIR, CoreProperties.PROJECT_KEY_PROPERTY, - CoreProperties.PROJECT_NAME_PROPERTY, CoreProperties.PROJECT_VERSION_PROPERTY}; - - /** - * Array of all mandatory properties required for a child project before its properties get merged with its parent ones. - */ - private static final String[] MANDATORY_PROPERTIES_FOR_CHILD = {MODULE_KEY_PROPERTY, CoreProperties.PROJECT_NAME_PROPERTY}; - - /** - * Properties that must not be passed from the parent project to its children. - */ - private static final List NON_HERITED_PROPERTIES_FOR_CHILD = Lists.newArrayList(PROPERTY_PROJECT_BASEDIR, CoreProperties.WORKING_DIRECTORY, PROPERTY_MODULES, - CoreProperties.PROJECT_DESCRIPTION_PROPERTY); - - private static final String NON_ASSOCIATED_PROJECT_KEY = "project"; - - private final AnalysisProperties analysisProps; - private final AnalysisMode analysisMode; - private File rootProjectWorkDir; - - public ProjectReactorBuilder(AnalysisProperties props, AnalysisMode analysisMode) { - this.analysisProps = props; - this.analysisMode = analysisMode; - } - - public ProjectReactor execute() { - Profiler profiler = Profiler.create(LOG).startInfo("Process project properties"); - new DroppedPropertyChecker(analysisProps.properties(), DROPPED_PROPERTIES).checkDroppedProperties(); - Map> propertiesByModuleIdPath = new HashMap<>(); - extractPropertiesByModule(propertiesByModuleIdPath, "", "", analysisProps.properties()); - ProjectDefinition rootProject = defineRootProject(propertiesByModuleIdPath.get(""), null); - rootProjectWorkDir = rootProject.getWorkDir(); - defineChildren(rootProject, propertiesByModuleIdPath, ""); - cleanAndCheckProjectDefinitions(rootProject); - // Since task properties are now empty we should add root module properties - analysisProps.properties().putAll(propertiesByModuleIdPath.get("")); - profiler.stopDebug(); - return new ProjectReactor(rootProject); - } - - private static void extractPropertiesByModule(Map> propertiesByModuleIdPath, String currentModuleId, String currentModuleIdPath, - Map parentProperties) { - if (propertiesByModuleIdPath.containsKey(currentModuleIdPath)) { - throw MessageException.of(String.format("Two modules have the same id: '%s'. Each module must have a unique id.", currentModuleId)); - } - - Map currentModuleProperties = new HashMap<>(); - String prefix = !currentModuleId.isEmpty() ? (currentModuleId + ".") : ""; - int prefixLength = prefix.length(); - - // By default all properties starting with module prefix belong to current module - Iterator> it = parentProperties.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry e = it.next(); - String key = e.getKey(); - if (key.startsWith(prefix)) { - currentModuleProperties.put(key.substring(prefixLength), e.getValue()); - it.remove(); - } - } - String[] moduleIds = getListFromProperty(currentModuleProperties, PROPERTY_MODULES); - // Sort module by reverse lexicographic order to avoid issue when one module id is a prefix of another one - Arrays.sort(moduleIds); - ArrayUtils.reverse(moduleIds); - - propertiesByModuleIdPath.put(currentModuleIdPath, currentModuleProperties); - - for (String moduleId : moduleIds) { - String subModuleIdPath = currentModuleIdPath.isEmpty() ? moduleId : (currentModuleIdPath + "." + moduleId); - extractPropertiesByModule(propertiesByModuleIdPath, moduleId, subModuleIdPath, currentModuleProperties); - } - } - - private static void prepareNonAssociatedProject(Map props, AnalysisMode mode) { - if (mode.isIssues() && !props.containsKey(CoreProperties.PROJECT_KEY_PROPERTY)) { - props.put(CoreProperties.PROJECT_KEY_PROPERTY, NON_ASSOCIATED_PROJECT_KEY); - } - } - - protected ProjectDefinition defineRootProject(Map rootProperties, @Nullable ProjectDefinition parent) { - prepareNonAssociatedProject(rootProperties, analysisMode); - - if (rootProperties.containsKey(PROPERTY_MODULES)) { - checkMandatoryProperties(rootProperties, MANDATORY_PROPERTIES_FOR_MULTIMODULE_PROJECT); - } else { - checkMandatoryProperties(rootProperties, MANDATORY_PROPERTIES_FOR_SIMPLE_PROJECT); - } - File baseDir = new File(rootProperties.get(PROPERTY_PROJECT_BASEDIR)); - final String projectKey = rootProperties.get(CoreProperties.PROJECT_KEY_PROPERTY); - File workDir; - if (parent == null) { - validateDirectories(rootProperties, baseDir, projectKey); - workDir = initRootProjectWorkDir(baseDir, rootProperties); - } else { - workDir = initModuleWorkDir(baseDir, rootProperties); - } - - return ProjectDefinition.create().setProperties(rootProperties) - .setBaseDir(baseDir) - .setWorkDir(workDir) - .setBuildDir(initModuleBuildDir(baseDir, rootProperties)); - } - - @VisibleForTesting - protected File initRootProjectWorkDir(File baseDir, Map rootProperties) { - String workDir = rootProperties.get(CoreProperties.WORKING_DIRECTORY); - if (StringUtils.isBlank(workDir)) { - return new File(baseDir, CoreProperties.WORKING_DIRECTORY_DEFAULT_VALUE); - } - - File customWorkDir = new File(workDir); - if (customWorkDir.isAbsolute()) { - return customWorkDir; - } - return new File(baseDir, customWorkDir.getPath()); - } - - @VisibleForTesting - protected File initModuleWorkDir(File moduleBaseDir, Map moduleProperties) { - String workDir = moduleProperties.get(CoreProperties.WORKING_DIRECTORY); - if (StringUtils.isBlank(workDir)) { - return new File(rootProjectWorkDir, BatchUtils.cleanKeyForFilename(moduleProperties.get(CoreProperties.PROJECT_KEY_PROPERTY))); - } - - File customWorkDir = new File(workDir); - if (customWorkDir.isAbsolute()) { - return customWorkDir; - } - return new File(moduleBaseDir, customWorkDir.getPath()); - } - - @CheckForNull - private static File initModuleBuildDir(File moduleBaseDir, Map moduleProperties) { - String buildDir = moduleProperties.get(PROPERTY_PROJECT_BUILDDIR); - if (StringUtils.isBlank(buildDir)) { - return null; - } - - File customBuildDir = new File(buildDir); - if (customBuildDir.isAbsolute()) { - return customBuildDir; - } - return new File(moduleBaseDir, customBuildDir.getPath()); - } - - private void defineChildren(ProjectDefinition parentProject, Map> propertiesByModuleIdPath, String parentModuleIdPath) { - Map parentProps = parentProject.properties(); - if (parentProps.containsKey(PROPERTY_MODULES)) { - for (String moduleId : getListFromProperty(parentProps, PROPERTY_MODULES)) { - String moduleIdPath = parentModuleIdPath.isEmpty() ? moduleId : (parentModuleIdPath + "." + moduleId); - Map moduleProps = propertiesByModuleIdPath.get(moduleIdPath); - ProjectDefinition childProject = loadChildProject(parentProject, moduleProps, moduleId); - // check the uniqueness of the child key - checkUniquenessOfChildKey(childProject, parentProject); - // the child project may have children as well - defineChildren(childProject, propertiesByModuleIdPath, moduleIdPath); - // and finally add this child project to its parent - parentProject.addSubProject(childProject); - } - } - } - - protected ProjectDefinition loadChildProject(ProjectDefinition parentProject, Map moduleProps, String moduleId) { - final File baseDir; - if (moduleProps.containsKey(PROPERTY_PROJECT_BASEDIR)) { - baseDir = resolvePath(parentProject.getBaseDir(), moduleProps.get(PROPERTY_PROJECT_BASEDIR)); - setProjectBaseDir(baseDir, moduleProps, moduleId); - } else { - baseDir = new File(parentProject.getBaseDir(), moduleId); - setProjectBaseDir(baseDir, moduleProps, moduleId); - } - - setModuleKeyAndNameIfNotDefined(moduleProps, moduleId, parentProject.getKey()); - - // and finish - checkMandatoryProperties(moduleProps, MANDATORY_PROPERTIES_FOR_CHILD); - validateDirectories(moduleProps, baseDir, moduleId); - - mergeParentProperties(moduleProps, parentProject.properties()); - - return defineRootProject(moduleProps, parentProject); - } - - @VisibleForTesting - protected static void setModuleKeyAndNameIfNotDefined(Map childProps, String moduleId, String parentKey) { - if (!childProps.containsKey(MODULE_KEY_PROPERTY)) { - if (!childProps.containsKey(CoreProperties.PROJECT_KEY_PROPERTY)) { - childProps.put(MODULE_KEY_PROPERTY, parentKey + ":" + moduleId); - } else { - String childKey = childProps.get(CoreProperties.PROJECT_KEY_PROPERTY); - childProps.put(MODULE_KEY_PROPERTY, parentKey + ":" + childKey); - } - } - if (!childProps.containsKey(CoreProperties.PROJECT_NAME_PROPERTY)) { - childProps.put(CoreProperties.PROJECT_NAME_PROPERTY, moduleId); - } - // For backward compatibility with ProjectDefinition - childProps.put(CoreProperties.PROJECT_KEY_PROPERTY, childProps.get(MODULE_KEY_PROPERTY)); - } - - @VisibleForTesting - protected static void checkUniquenessOfChildKey(ProjectDefinition childProject, ProjectDefinition parentProject) { - for (ProjectDefinition definition : parentProject.getSubProjects()) { - if (definition.getKey().equals(childProject.getKey())) { - throw MessageException.of("Project '" + parentProject.getKey() + "' can't have 2 modules with the following key: " + childProject.getKey()); - } - } - } - - protected static void setProjectBaseDir(File baseDir, Map childProps, String moduleId) { - if (!baseDir.isDirectory()) { - throw MessageException.of("The base directory of the module '" + moduleId + "' does not exist: " + baseDir.getAbsolutePath()); - } - childProps.put(PROPERTY_PROJECT_BASEDIR, baseDir.getAbsolutePath()); - } - - @VisibleForTesting - protected static void checkMandatoryProperties(Map props, String[] mandatoryProps) { - StringBuilder missing = new StringBuilder(); - for (String mandatoryProperty : mandatoryProps) { - if (!props.containsKey(mandatoryProperty)) { - if (missing.length() > 0) { - missing.append(", "); - } - missing.append(mandatoryProperty); - } - } - String moduleKey = StringUtils.defaultIfBlank(props.get(MODULE_KEY_PROPERTY), props.get(CoreProperties.PROJECT_KEY_PROPERTY)); - if (missing.length() != 0) { - throw MessageException.of("You must define the following mandatory properties for '" + (moduleKey == null ? "Unknown" : moduleKey) + "': " + missing); - } - } - - protected static void validateDirectories(Map props, File baseDir, String projectId) { - if (!props.containsKey(PROPERTY_MODULES)) { - // SONARPLUGINS-2285 Not an aggregator project so we can validate that paths are correct if defined - - // Check sonar.tests - String[] testPaths = getListFromProperty(props, PROPERTY_TESTS); - checkExistenceOfPaths(projectId, baseDir, testPaths, PROPERTY_TESTS); - } - } - - @VisibleForTesting - protected static void cleanAndCheckProjectDefinitions(ProjectDefinition project) { - if (project.getSubProjects().isEmpty()) { - cleanAndCheckModuleProperties(project); - } else { - cleanAndCheckAggregatorProjectProperties(project); - - // clean modules properties as well - for (ProjectDefinition module : project.getSubProjects()) { - cleanAndCheckProjectDefinitions(module); - } - } - } - - @VisibleForTesting - protected static void cleanAndCheckModuleProperties(ProjectDefinition project) { - Map properties = project.properties(); - - // We need to check the existence of source directories - String[] sourcePaths = getListFromProperty(properties, PROPERTY_SOURCES); - checkExistenceOfPaths(project.getKey(), project.getBaseDir(), sourcePaths, PROPERTY_SOURCES); - } - - @VisibleForTesting - protected static void cleanAndCheckAggregatorProjectProperties(ProjectDefinition project) { - Map properties = project.properties(); - - // SONARPLUGINS-2295 - String[] sourceDirs = getListFromProperty(properties, PROPERTY_SOURCES); - for (String path : sourceDirs) { - File sourceFolder = resolvePath(project.getBaseDir(), path); - if (sourceFolder.isDirectory()) { - LOG.warn("/!\\ A multi-module project can't have source folders, so '{}' won't be used for the analysis. " + - "If you want to analyse files of this folder, you should create another sub-module and move them inside it.", - sourceFolder.toString()); - } - } - - // "aggregator" project must not have the following properties: - properties.remove(PROPERTY_SOURCES); - properties.remove(PROPERTY_TESTS); - } - - @VisibleForTesting - protected static void mergeParentProperties(Map childProps, Map parentProps) { - for (Map.Entry entry : parentProps.entrySet()) { - String key = entry.getKey(); - if ((!childProps.containsKey(key) || childProps.get(key).equals(entry.getValue())) - && !NON_HERITED_PROPERTIES_FOR_CHILD.contains(key)) { - childProps.put(entry.getKey(), entry.getValue()); - } - } - } - - @VisibleForTesting - protected static void checkExistenceOfPaths(String moduleRef, File baseDir, String[] paths, String propName) { - for (String path : paths) { - File sourceFolder = resolvePath(baseDir, path); - if (!sourceFolder.exists()) { - LOG.error(MessageFormat.format(INVALID_VALUE_OF_X_FOR_Y, propName, moduleRef)); - throw MessageException.of("The folder '" + path + "' does not exist for '" + moduleRef + - "' (base directory = " + baseDir.getAbsolutePath() + ")"); - } - } - } - - protected static File resolvePath(File baseDir, String path) { - Path filePath = Paths.get(path); - if (!filePath.isAbsolute()) { - filePath = baseDir.toPath().resolve(path); - } - return filePath.normalize().toFile(); - } - - /** - * Transforms a comma-separated list String property in to a array of trimmed strings. - * - * This works even if they are separated by whitespace characters (space char, EOL, ...) - * - */ - static String[] getListFromProperty(Map properties, String key) { - return (String[]) ObjectUtils.defaultIfNull(StringUtils.stripAll(StringUtils.split(properties.get(key), ',')), new String[0]); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorValidator.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorValidator.java deleted file mode 100644 index 7e36ab54958..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorValidator.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan; - -import org.sonar.api.utils.MessageException; - -import org.sonar.batch.analysis.DefaultAnalysisMode; -import com.google.common.base.Joiner; - -import java.util.ArrayList; -import java.util.List; - -import javax.annotation.Nullable; - -import org.apache.commons.lang.StringUtils; -import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.api.batch.bootstrap.ProjectReactor; -import org.sonar.api.config.Settings; -import org.sonar.core.component.ComponentKeys; - -/** - * This class aims at validating project reactor - * @since 3.6 - */ -public class ProjectReactorValidator { - - private static final String SONAR_PHASE = "sonar.phase"; - private final Settings settings; - private final DefaultAnalysisMode mode; - - public ProjectReactorValidator(Settings settings, DefaultAnalysisMode mode) { - this.settings = settings; - this.mode = mode; - } - - public void validate(ProjectReactor reactor) { - String branch = reactor.getRoot().getBranch(); - - List validationMessages = new ArrayList<>(); - checkDeprecatedProperties(validationMessages); - - for (ProjectDefinition moduleDef : reactor.getProjects()) { - if (mode.isIssues()) { - validateModuleIssuesMode(moduleDef, validationMessages); - } else { - validateModule(moduleDef, validationMessages); - } - } - - validateBranch(validationMessages, branch); - - if (!validationMessages.isEmpty()) { - throw MessageException.of("Validation of project reactor failed:\n o " + Joiner.on("\n o ").join(validationMessages)); - } - } - - private static void validateModuleIssuesMode(ProjectDefinition moduleDef, List validationMessages) { - if (!ComponentKeys.isValidModuleKeyIssuesMode(moduleDef.getKey())) { - validationMessages.add(String.format("\"%s\" is not a valid project or module key. " - + "Allowed characters in issues mode are alphanumeric, '-', '_', '.', '/' and ':', with at least one non-digit.", moduleDef.getKey())); - } - } - - private static void validateModule(ProjectDefinition moduleDef, List validationMessages) { - if (!ComponentKeys.isValidModuleKey(moduleDef.getKey())) { - validationMessages.add(String.format("\"%s\" is not a valid project or module key. " - + "Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.", moduleDef.getKey())); - } - } - - private void checkDeprecatedProperties(List validationMessages) { - if (settings.getString(SONAR_PHASE) != null) { - validationMessages.add(String.format("Property \"%s\" is deprecated. Please remove it from your configuration.", SONAR_PHASE)); - } - } - - private static void validateBranch(List validationMessages, @Nullable String branch) { - if (StringUtils.isNotEmpty(branch) && !ComponentKeys.isValidBranch(branch)) { - validationMessages.add(String.format("\"%s\" is not a valid branch name. " - + "Allowed characters are alphanumeric, '-', '_', '.' and '/'.", branch)); - } - } - -} 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 deleted file mode 100644 index ff8108e4871..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java +++ /dev/null @@ -1,277 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan; - -import com.google.common.annotations.VisibleForTesting; -import org.sonar.api.CoreProperties; -import org.sonar.api.batch.InstantiationStrategy; -import org.sonar.api.config.Settings; -import org.sonar.api.resources.Languages; -import org.sonar.api.resources.Project; -import org.sonar.api.resources.ResourceTypes; -import org.sonar.api.scan.filesystem.PathResolver; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; -import org.sonar.batch.DefaultFileLinesContextFactory; -import org.sonar.batch.DefaultProjectTree; -import org.sonar.batch.ProjectConfigurator; -import org.sonar.batch.analysis.AnalysisProperties; -import org.sonar.batch.analysis.AnalysisTempFolderProvider; -import org.sonar.batch.analysis.AnalysisWSLoaderProvider; -import org.sonar.batch.analysis.DefaultAnalysisMode; -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.cache.ProjectPersistentCacheProvider; -import org.sonar.batch.cpd.CpdExecutor; -import org.sonar.batch.cpd.index.SonarCpdBlockIndex; -import org.sonar.batch.events.EventBus; -import org.sonar.batch.index.BatchComponentCache; -import org.sonar.batch.index.Caches; -import org.sonar.batch.index.DefaultIndex; -import org.sonar.batch.issue.DefaultIssueCallback; -import org.sonar.batch.issue.DefaultProjectIssues; -import org.sonar.batch.issue.IssueCache; -import org.sonar.batch.issue.tracking.DefaultServerLineHashesLoader; -import org.sonar.batch.issue.tracking.IssueTransition; -import org.sonar.batch.issue.tracking.LocalIssueTracking; -import org.sonar.batch.issue.tracking.ServerIssueRepository; -import org.sonar.batch.issue.tracking.ServerLineHashesLoader; -import org.sonar.batch.mediumtest.ScanTaskObservers; -import org.sonar.batch.phases.PhasesTimeProfiler; -import org.sonar.batch.profiling.PhasesSumUpTimeProfiler; -import org.sonar.batch.report.ActiveRulesPublisher; -import org.sonar.batch.report.AnalysisContextReportPublisher; -import org.sonar.batch.report.ComponentsPublisher; -import org.sonar.batch.report.CoveragePublisher; -import org.sonar.batch.report.MeasuresPublisher; -import org.sonar.batch.report.MetadataPublisher; -import org.sonar.batch.report.ReportPublisher; -import org.sonar.batch.report.SourcePublisher; -import org.sonar.batch.report.TestExecutionAndCoveragePublisher; -import org.sonar.batch.repository.DefaultProjectRepositoriesLoader; -import org.sonar.batch.repository.DefaultQualityProfileLoader; -import org.sonar.batch.repository.DefaultServerIssuesLoader; -import org.sonar.batch.repository.ProjectRepositories; -import org.sonar.batch.repository.ProjectRepositoriesLoader; -import org.sonar.batch.repository.ProjectRepositoriesProvider; -import org.sonar.batch.repository.QualityProfileLoader; -import org.sonar.batch.repository.QualityProfileProvider; -import org.sonar.batch.repository.ServerIssuesLoader; -import org.sonar.batch.repository.language.DefaultLanguagesRepository; -import org.sonar.batch.repository.user.UserRepositoryLoader; -import org.sonar.batch.rule.ActiveRulesLoader; -import org.sonar.batch.rule.ActiveRulesProvider; -import org.sonar.batch.rule.DefaultActiveRulesLoader; -import org.sonar.batch.rule.DefaultRulesLoader; -import org.sonar.batch.rule.RulesLoader; -import org.sonar.batch.rule.RulesProvider; -import org.sonar.batch.scan.filesystem.InputPathCache; -import org.sonar.batch.scan.measure.DefaultMetricFinder; -import org.sonar.batch.scan.measure.DeprecatedMetricFinder; -import org.sonar.batch.scan.measure.MeasureCache; -import org.sonar.batch.source.CodeColorizers; -import org.sonar.batch.test.TestPlanBuilder; -import org.sonar.batch.test.TestableBuilder; -import org.sonar.core.metric.BatchMetrics; -import org.sonar.core.platform.ComponentContainer; - -public class ProjectScanContainer extends ComponentContainer { - - private static final Logger LOG = Loggers.get(ProjectScanContainer.class); - - private final AnalysisProperties props; - private ProjectLock lock; - - public ProjectScanContainer(ComponentContainer globalContainer, AnalysisProperties props) { - super(globalContainer); - this.props = props; - } - - @Override - protected void doBeforeStart() { - addBatchComponents(); - lock = getComponentByType(ProjectLock.class); - lock.tryLock(); - getComponentByType(WorkDirectoryCleaner.class).execute(); - addBatchExtensions(); - Settings settings = getComponentByType(Settings.class); - if (settings != null && settings.getBoolean(CoreProperties.PROFILING_LOG_PROPERTY)) { - add(PhasesSumUpTimeProfiler.class); - } - if (isTherePreviousAnalysis()) { - addIssueTrackingComponents(); - } - } - - @Override - public ComponentContainer startComponents() { - try { - return super.startComponents(); - } catch (Exception e) { - // ensure that lock is released - if (lock != null) { - lock.stop(); - } - throw e; - } - } - - private void addBatchComponents() { - add( - props, - DefaultAnalysisMode.class, - ProjectReactorBuilder.class, - WorkDirectoryCleaner.class, - new MutableProjectReactorProvider(), - new ImmutableProjectReactorProvider(), - ProjectBuildersExecutor.class, - ProjectLock.class, - EventBus.class, - PhasesTimeProfiler.class, - ResourceTypes.class, - DefaultProjectTree.class, - ProjectExclusions.class, - ProjectReactorValidator.class, - new AnalysisWSLoaderProvider(), - CodeColorizers.class, - MetricProvider.class, - ProjectConfigurator.class, - DefaultIndex.class, - DefaultFileLinesContextFactory.class, - Caches.class, - BatchComponentCache.class, - DefaultIssueCallback.class, - new RulesProvider(), - new ProjectRepositoriesProvider(), - new ProjectPersistentCacheProvider(), - - // temp - new AnalysisTempFolderProvider(), - - // file system - InputPathCache.class, - PathResolver.class, - - // rules - new ActiveRulesProvider(), - new QualityProfileProvider(), - - // issues - IssueCache.class, - DefaultProjectIssues.class, - IssueTransition.class, - - // metrics - DefaultMetricFinder.class, - DeprecatedMetricFinder.class, - - // tests - TestPlanBuilder.class, - TestableBuilder.class, - - // lang - Languages.class, - DefaultLanguagesRepository.class, - - // Measures - MeasureCache.class, - - ProjectSettings.class, - - // Report - BatchMetrics.class, - ReportPublisher.class, - AnalysisContextReportPublisher.class, - MetadataPublisher.class, - ActiveRulesPublisher.class, - ComponentsPublisher.class, - MeasuresPublisher.class, - CoveragePublisher.class, - SourcePublisher.class, - TestExecutionAndCoveragePublisher.class, - - // Cpd - CpdExecutor.class, - SonarCpdBlockIndex.class, - - ScanTaskObservers.class, - UserRepositoryLoader.class); - - addIfMissing(DefaultRulesLoader.class, RulesLoader.class); - addIfMissing(DefaultActiveRulesLoader.class, ActiveRulesLoader.class); - addIfMissing(DefaultQualityProfileLoader.class, QualityProfileLoader.class); - addIfMissing(DefaultProjectRepositoriesLoader.class, ProjectRepositoriesLoader.class); - } - - private void addIssueTrackingComponents() { - add( - LocalIssueTracking.class, - ServerIssueRepository.class); - addIfMissing(DefaultServerIssuesLoader.class, ServerIssuesLoader.class); - addIfMissing(DefaultServerLineHashesLoader.class, ServerLineHashesLoader.class); - } - - private boolean isTherePreviousAnalysis() { - if (getComponentByType(DefaultAnalysisMode.class).isNotAssociated()) { - return false; - } - - return getComponentByType(ProjectRepositories.class).lastAnalysisDate() != null; - } - - private void addBatchExtensions() { - getComponentByType(ExtensionInstaller.class).install(this, new BatchExtensionFilter()); - } - - @Override - protected void doAfterStart() { - DefaultAnalysisMode analysisMode = getComponentByType(DefaultAnalysisMode.class); - analysisMode.printMode(); - LOG.debug("Start recursive analysis of project modules"); - DefaultProjectTree tree = getComponentByType(DefaultProjectTree.class); - scanRecursively(tree.getRootProject()); - if (analysisMode.isMediumTest()) { - getComponentByType(ScanTaskObservers.class).notifyEndOfScanTask(); - } - } - - private void scanRecursively(Project module) { - for (Project subModules : module.getModules()) { - scanRecursively(subModules); - } - scan(module); - } - - @VisibleForTesting - void scan(Project module) { - new ModuleScanContainer(this, module).execute(); - } - - static class BatchExtensionFilter implements ExtensionMatcher { - @Override - public boolean accept(Object extension) { - return ExtensionUtils.isBatchSide(extension) - && ExtensionUtils.isInstantiationStrategy(extension, InstantiationStrategy.PER_BATCH); - } - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectSettings.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectSettings.java deleted file mode 100644 index 382d02424a3..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectSettings.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan; - -import org.sonar.api.CoreProperties; -import org.sonar.api.batch.bootstrap.ProjectReactor; -import org.sonar.api.config.PropertyDefinitions; -import org.sonar.api.config.Settings; -import org.sonar.api.utils.MessageException; -import org.sonar.batch.analysis.DefaultAnalysisMode; -import org.sonar.batch.bootstrap.GlobalSettings; -import org.sonar.batch.repository.ProjectRepositories; - -public class ProjectSettings extends Settings { - - private final GlobalSettings globalSettings; - private final ProjectRepositories projectRepositories; - private final DefaultAnalysisMode mode; - - public ProjectSettings(ProjectReactor reactor, GlobalSettings globalSettings, PropertyDefinitions propertyDefinitions, - ProjectRepositories projectRepositories, DefaultAnalysisMode mode) { - super(propertyDefinitions); - this.mode = mode; - getEncryption().setPathToSecretKey(globalSettings.getString(CoreProperties.ENCRYPTION_SECRET_KEY_PATH)); - this.globalSettings = globalSettings; - this.projectRepositories = projectRepositories; - init(reactor); - } - - private void init(ProjectReactor reactor) { - addProperties(globalSettings.getProperties()); - - addProperties(projectRepositories.settings(reactor.getRoot().getKeyWithBranch())); - - addProperties(reactor.getRoot().properties()); - } - - @Override - protected void doOnGetProperties(String key) { - if (mode.isIssues() && key.endsWith(".secured") && !key.contains(".license")) { - throw MessageException.of("Access to the secured property '" + key - + "' is not possible in issues mode. The SonarQube plugin which requires this property must be deactivated in issues mode."); - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/WorkDirectoryCleaner.java b/sonar-batch/src/main/java/org/sonar/batch/scan/WorkDirectoryCleaner.java deleted file mode 100644 index b4857bf6afb..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/WorkDirectoryCleaner.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan; - -import org.sonar.api.batch.bootstrap.ProjectReactor; -import org.sonar.core.util.FileUtils; -import org.sonar.home.cache.DirectoryLock; - -import java.io.IOException; -import java.nio.file.DirectoryStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Iterator; - -public class WorkDirectoryCleaner { - private Path workDir; - - public WorkDirectoryCleaner(ProjectReactor projectReactor) { - workDir = projectReactor.getRoot().getWorkDir().toPath(); - } - - public void execute() { - if (!Files.exists(workDir)) { - return; - } - - try (DirectoryStream stream = list()) { - - Iterator it = stream.iterator(); - while (it.hasNext()) { - FileUtils.deleteQuietly(it.next().toFile()); - } - } catch (IOException e) { - throw new IllegalStateException("Failed to clean working directory: " + workDir.toString(), e); - } - } - - private DirectoryStream list() throws IOException { - return Files.newDirectoryStream(workDir, new DirectoryStream.Filter() { - @Override - public boolean accept(Path entry) throws IOException { - return !DirectoryLock.LOCK_FILE_NAME.equals(entry.getFileName().toString()); - } - }); - } -} 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 deleted file mode 100644 index b68b6a3625a..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/AdditionalFilePredicates.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.filesystem; - -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.internal.AbstractFilePredicate; -import org.sonar.api.batch.fs.internal.DefaultInputFile; - -/** - * Additional {@link org.sonar.api.batch.fs.FilePredicate}s that are - * not published in public API - */ -class AdditionalFilePredicates { - - private AdditionalFilePredicates() { - // only static inner classes - } - - static class KeyPredicate extends AbstractFilePredicate { - private final String key; - - KeyPredicate(String key) { - this.key = key; - } - - @Override - public boolean apply(InputFile f) { - return key.equals(((DefaultInputFile) f).key()); - } - } - -} 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 deleted file mode 100644 index 761f6d15823..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.filesystem; - -import org.sonar.api.batch.BatchSide; -import org.sonar.api.batch.SonarIndex; -import org.sonar.api.batch.fs.InputDir; -import org.sonar.api.batch.fs.InputFile; -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.BatchComponent; -import org.sonar.batch.index.BatchComponentCache; - -/** - * Index all files/directories of the module in SQ database and importing source code. - * - * @since 4.2 - */ -@BatchSide -public class ComponentIndexer { - - private final Languages languages; - private final SonarIndex sonarIndex; - private final Project module; - private final BatchComponentCache componentCache; - - public ComponentIndexer(Project module, Languages languages, SonarIndex sonarIndex, BatchComponentCache componentCache) { - this.module = module; - this.languages = languages; - this.sonarIndex = sonarIndex; - this.componentCache = componentCache; - } - - public void execute(DefaultModuleFileSystem fs) { - module.setBaseDir(fs.baseDir()); - - for (InputFile inputFile : fs.inputFiles()) { - String languageKey = inputFile.language(); - boolean unitTest = InputFile.Type.TEST == inputFile.type(); - Resource sonarFile = File.create(inputFile.relativePath(), languages.get(languageKey), unitTest); - sonarIndex.index(sonarFile); - BatchComponent file = componentCache.get(sonarFile); - file.setInputComponent(inputFile); - Resource sonarDir = file.parent().resource(); - InputDir inputDir = fs.inputDir(inputFile.file().getParentFile()); - componentCache.get(sonarDir).setInputComponent(inputDir); - } - } -} 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 deleted file mode 100644 index 125a73d0078..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java +++ /dev/null @@ -1,285 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.filesystem; - -import org.sonar.api.batch.fs.InputFile.Status; - -import org.sonar.batch.analysis.DefaultAnalysisMode; -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 java.io.File; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; - -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; - -import org.apache.commons.lang.StringUtils; -import org.sonar.api.CoreProperties; -import org.sonar.api.batch.fs.FilePredicate; -import org.sonar.api.batch.fs.internal.DefaultFileSystem; -import org.sonar.api.config.Settings; -import org.sonar.api.resources.Project; -import org.sonar.api.scan.filesystem.FileQuery; -import org.sonar.api.scan.filesystem.ModuleFileSystem; -import org.sonar.api.utils.MessageException; - -/** - * @since 3.5 - */ -public class DefaultModuleFileSystem extends DefaultFileSystem implements ModuleFileSystem { - - private String moduleKey; - private FileIndexer indexer; - private Settings settings; - - private File buildDir; - private List sourceDirsOrFiles = Lists.newArrayList(); - private List testDirsOrFiles = Lists.newArrayList(); - private List binaryDirs = Lists.newArrayList(); - private ComponentIndexer componentIndexer; - private boolean initialized; - - public DefaultModuleFileSystem(ModuleInputFileCache moduleInputFileCache, Project project, - Settings settings, FileIndexer indexer, ModuleFileSystemInitializer initializer, ComponentIndexer componentIndexer, DefaultAnalysisMode mode) { - super(initializer.baseDir(), moduleInputFileCache); - setFields(project, settings, indexer, initializer, componentIndexer, mode); - } - - @VisibleForTesting - public DefaultModuleFileSystem(Project project, - Settings settings, FileIndexer indexer, ModuleFileSystemInitializer initializer, ComponentIndexer componentIndexer, DefaultAnalysisMode mode) { - super(initializer.baseDir().toPath()); - setFields(project, settings, indexer, initializer, componentIndexer, mode); - } - - private void setFields(Project project, - Settings settings, FileIndexer indexer, ModuleFileSystemInitializer initializer, ComponentIndexer componentIndexer, DefaultAnalysisMode mode) { - 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(); - - // filter the files sensors have access to - if (!mode.scanAllFiles()) { - setDefaultPredicate(predicates.not(predicates.hasStatus(Status.SAME))); - } - } - - public boolean isInitialized() { - return initialized; - } - - public String moduleKey() { - return moduleKey; - } - - @Override - @CheckForNull - public File buildDir() { - return buildDir; - } - - @Override - public List sourceDirs() { - return keepOnlyDirs(sourceDirsOrFiles); - } - - public List sources() { - return sourceDirsOrFiles; - } - - @Override - public List testDirs() { - return keepOnlyDirs(testDirsOrFiles); - } - - public List tests() { - return testDirsOrFiles; - } - - private static List keepOnlyDirs(List dirsOrFiles) { - List result = new ArrayList<>(); - for (File f : dirsOrFiles) { - if (f.isDirectory()) { - result.add(f); - } - } - return result; - } - - @Override - public List binaryDirs() { - return binaryDirs; - } - - @Override - public Charset encoding() { - final Charset charset; - String encoding = settings.getString(CoreProperties.ENCODING_PROPERTY); - if (StringUtils.isNotEmpty(encoding)) { - charset = Charset.forName(StringUtils.trim(encoding)); - } else { - charset = Charset.defaultCharset(); - } - return charset; - } - - @Override - public boolean isDefaultJvmEncoding() { - return !settings.hasKey(CoreProperties.ENCODING_PROPERTY); - } - - /** - * Should not be used - only for old plugins - * - * @deprecated since 4.0 - */ - @Deprecated - void addSourceDir(File dir) { - throw modificationNotPermitted(); - } - - /** - * Should not be used - only for old plugins - * - * @deprecated since 4.0 - */ - @Deprecated - void addTestDir(File dir) { - throw modificationNotPermitted(); - } - - private static UnsupportedOperationException modificationNotPermitted() { - return new UnsupportedOperationException("Modifications of the file system are not permitted"); - } - - /** - * @return - * @deprecated in 4.2. Replaced by {@link #encoding()} - */ - @Override - @Deprecated - public Charset sourceCharset() { - return encoding(); - } - - /** - * @deprecated in 4.2. Replaced by {@link #workDir()} - */ - @Deprecated - @Override - public File workingDir() { - return workDir(); - } - - @Override - public List files(FileQuery query) { - doPreloadFiles(); - Collection predicates = Lists.newArrayList(); - for (Map.Entry> entry : query.attributes().entrySet()) { - predicates.add(fromDeprecatedAttribute(entry.getKey(), entry.getValue())); - } - return ImmutableList.copyOf(files(predicates().and(predicates))); - } - - @Override - protected void doPreloadFiles() { - if (!initialized) { - throw MessageException.of("Accessing the filesystem before the Sensor phase is not supported. Please update your plugin."); - } - } - - public void index() { - if (initialized) { - throw MessageException.of("Module filesystem can only be indexed once"); - } - initialized = true; - indexer.index(this); - if (componentIndexer != null) { - componentIndexer.execute(this); - } - } - - private FilePredicate fromDeprecatedAttribute(String key, Collection value) { - if ("TYPE".equals(key)) { - return predicates().or(Collections2.transform(value, new Function() { - @Override - public FilePredicate apply(@Nullable String s) { - return s == null ? predicates().all() : predicates().hasType(org.sonar.api.batch.fs.InputFile.Type.valueOf(s)); - } - })); - } - if ("STATUS".equals(key)) { - return predicates().or(Collections2.transform(value, new Function() { - @Override - public FilePredicate apply(@Nullable String s) { - return s == null ? predicates().all() : predicates().hasStatus(org.sonar.api.batch.fs.InputFile.Status.valueOf(s)); - } - })); - } - if ("LANG".equals(key)) { - return predicates().or(Collections2.transform(value, new Function() { - @Override - public FilePredicate apply(@Nullable String s) { - return s == null ? predicates().all() : predicates().hasLanguage(s); - } - })); - } - if ("CMP_KEY".equals(key)) { - return predicates().or(Collections2.transform(value, new Function() { - @Override - public FilePredicate apply(@Nullable String s) { - return s == null ? predicates().all() : new AdditionalFilePredicates.KeyPredicate(s); - } - })); - } - throw new IllegalArgumentException("Unsupported file attribute: " + key); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - DefaultModuleFileSystem that = (DefaultModuleFileSystem) o; - return moduleKey.equals(that.moduleKey); - } - - @Override - public int hashCode() { - return moduleKey.hashCode(); - } -} 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 deleted file mode 100644 index 29968e7e102..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DeprecatedFileFilters.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.filesystem; - -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.InputFileFilter; -import org.sonar.api.scan.filesystem.FileSystemFilter; -import org.sonar.api.scan.filesystem.FileType; -import org.sonar.api.scan.filesystem.ModuleFileSystem; - -public class DeprecatedFileFilters implements InputFileFilter { - private final FileSystemFilter[] filters; - - public DeprecatedFileFilters(FileSystemFilter[] filters) { - this.filters = filters; - } - - public DeprecatedFileFilters() { - this(new FileSystemFilter[0]); - } - - @Override - public boolean accept(InputFile inputFile) { - if (filters.length > 0) { - DeprecatedContext context = new DeprecatedContext(inputFile); - for (FileSystemFilter filter : filters) { - if (!filter.accept(inputFile.file(), context)) { - return false; - } - } - } - return true; - } - - static class DeprecatedContext implements FileSystemFilter.Context { - private final InputFile inputFile; - - DeprecatedContext(InputFile inputFile) { - this.inputFile = inputFile; - } - - @Override - public ModuleFileSystem fileSystem() { - throw new UnsupportedOperationException("Not supported since 4.0"); - } - - @Override - public FileType type() { - String type = inputFile.type().name(); - return FileType.valueOf(type); - } - - @Override - public String relativePath() { - return inputFile.relativePath(); - } - - @Override - public String canonicalPath() { - return inputFile.absolutePath(); - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ExclusionFilters.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ExclusionFilters.java deleted file mode 100644 index 2a2952884f5..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ExclusionFilters.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.filesystem; - -import org.apache.commons.lang.ArrayUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.internal.PathPattern; -import org.sonar.api.scan.filesystem.FileExclusions; - -@BatchSide -public class ExclusionFilters { - - private static final Logger LOG = LoggerFactory.getLogger(ExclusionFilters.class); - - private final FileExclusions exclusionSettings; - - private PathPattern[] mainInclusions; - private PathPattern[] mainExclusions; - private PathPattern[] testInclusions; - private PathPattern[] testExclusions; - - public ExclusionFilters(FileExclusions exclusions) { - this.exclusionSettings = exclusions; - } - - public void prepare() { - mainInclusions = prepareMainInclusions(); - mainExclusions = prepareMainExclusions(); - testInclusions = prepareTestInclusions(); - testExclusions = prepareTestExclusions(); - log("Included sources: ", mainInclusions); - log("Excluded sources: ", mainExclusions); - log("Included tests: ", testInclusions); - log("Excluded tests: ", testExclusions); - } - - public boolean hasPattern() { - return mainInclusions.length > 0 || mainExclusions.length > 0 || testInclusions.length > 0 || testExclusions.length > 0; - } - - private void log(String title, PathPattern[] patterns) { - if (patterns.length > 0) { - LOG.info(title); - for (PathPattern pattern : patterns) { - LOG.info(" " + pattern); - } - } - } - - public boolean accept(InputFile inputFile, InputFile.Type type) { - PathPattern[] inclusionPatterns; - PathPattern[] exclusionPatterns; - if (InputFile.Type.MAIN == type) { - inclusionPatterns = mainInclusions; - exclusionPatterns = mainExclusions; - } else if (InputFile.Type.TEST == type) { - inclusionPatterns = testInclusions; - exclusionPatterns = testExclusions; - } else { - throw new IllegalArgumentException("Unknown file type: " + type); - } - - if (inclusionPatterns.length > 0) { - boolean matchInclusion = false; - for (PathPattern pattern : inclusionPatterns) { - matchInclusion |= pattern.match(inputFile); - } - if (!matchInclusion) { - return false; - } - } - if (exclusionPatterns.length > 0) { - for (PathPattern pattern : exclusionPatterns) { - if (pattern.match(inputFile)) { - return false; - } - } - } - return true; - } - - PathPattern[] prepareMainInclusions() { - if (exclusionSettings.sourceInclusions().length > 0) { - // User defined params - return PathPattern.create(exclusionSettings.sourceInclusions()); - } - return new PathPattern[0]; - } - - PathPattern[] prepareTestInclusions() { - return PathPattern.create(computeTestInclusions()); - } - - private String[] computeTestInclusions() { - if (exclusionSettings.testInclusions().length > 0) { - // User defined params - return exclusionSettings.testInclusions(); - } - return ArrayUtils.EMPTY_STRING_ARRAY; - } - - PathPattern[] prepareMainExclusions() { - String[] patterns = (String[]) ArrayUtils.addAll( - exclusionSettings.sourceExclusions(), computeTestInclusions()); - return PathPattern.create(patterns); - } - - PathPattern[] prepareTestExclusions() { - return PathPattern.create(exclusionSettings.testExclusions()); - } -} 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 deleted file mode 100644 index 9ebf91886a0..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileIndexer.java +++ /dev/null @@ -1,268 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.filesystem; - -import com.google.common.util.concurrent.ThreadFactoryBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.InputFile.Type; -import org.sonar.api.batch.fs.InputFileFilter; -import org.sonar.api.batch.fs.internal.DefaultInputDir; -import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.scan.filesystem.PathResolver; -import org.sonar.api.utils.MessageException; -import org.sonar.batch.util.ProgressReport; -import org.sonar.home.cache.DirectoryLock; - -import java.io.File; -import java.io.IOException; -import java.nio.file.FileSystemLoopException; -import java.nio.file.FileVisitOption; -import java.nio.file.FileVisitResult; -import java.nio.file.FileVisitor; -import java.nio.file.Files; -import java.nio.file.LinkOption; -import java.nio.file.Path; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.concurrent.Callable; -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}. - */ -@BatchSide -public class FileIndexer { - - private static final Logger LOG = LoggerFactory.getLogger(FileIndexer.class); - private final List filters; - private final boolean isAggregator; - private final ExclusionFilters exclusionFilters; - private final InputFileBuilderFactory inputFileBuilderFactory; - - private ProgressReport progressReport; - private ExecutorService executorService; - private List> tasks; - - public FileIndexer(List filters, ExclusionFilters exclusionFilters, InputFileBuilderFactory inputFileBuilderFactory, - ProjectDefinition def) { - this.filters = filters; - this.exclusionFilters = exclusionFilters; - this.inputFileBuilderFactory = inputFileBuilderFactory; - this.isAggregator = !def.getSubProjects().isEmpty(); - } - - void index(DefaultModuleFileSystem fileSystem) { - if (isAggregator) { - // No indexing for an aggregator module - return; - } - 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); - int threads = Math.max(1, Runtime.getRuntime().availableProcessors() - 1); - executorService = Executors.newFixedThreadPool(threads, new ThreadFactoryBuilder().setNameFormat("FileIndexer-%d").build()); - tasks = new ArrayList<>(); - indexFiles(fileSystem, progress, inputFileBuilder, fileSystem.sources(), InputFile.Type.MAIN); - indexFiles(fileSystem, progress, inputFileBuilder, fileSystem.tests(), InputFile.Type.TEST); - - waitForTasksToComplete(); - - progressReport.stop(progress.count() + " files indexed"); - - if (exclusionFilters.hasPattern()) { - LOG.info(progress.excludedByPatternsCount() + " files ignored because of inclusion/exclusion patterns"); - } - } - - private void waitForTasksToComplete() { - executorService.shutdown(); - for (Future 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); - } - } - } - - private void indexFiles(DefaultModuleFileSystem fileSystem, Progress progress, InputFileBuilder inputFileBuilder, List sources, InputFile.Type type) { - try { - for (File dirOrFile : sources) { - if (dirOrFile.isDirectory()) { - indexDirectory(inputFileBuilder, fileSystem, progress, dirOrFile, type); - } else { - indexFile(inputFileBuilder, fileSystem, progress, dirOrFile.toPath(), type); - } - } - } catch (IOException e) { - throw new IllegalStateException("Failed to index files", e); - } - } - - private void indexDirectory(final InputFileBuilder inputFileBuilder, final DefaultModuleFileSystem fileSystem, final Progress status, - final File dirToIndex, final InputFile.Type type) throws IOException { - Files.walkFileTree(dirToIndex.toPath().normalize(), Collections.singleton(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, - new IndexFileVisitor(inputFileBuilder, fileSystem, status, type)); - } - - private void indexFile(InputFileBuilder inputFileBuilder, DefaultModuleFileSystem fileSystem, Progress progress, Path sourceFile, InputFile.Type type) throws IOException { - // get case of real file without resolving link - Path realFile = sourceFile.toRealPath(LinkOption.NOFOLLOW_LINKS); - DefaultInputFile inputFile = inputFileBuilder.create(realFile.toFile()); - if (inputFile != null) { - // Set basedir on input file prior to adding it to the FS since exclusions filters may require the absolute path - inputFile.setModuleBaseDir(fileSystem.baseDirPath()); - if (exclusionFilters.accept(inputFile, type)) { - indexFile(inputFileBuilder, fileSystem, progress, inputFile, type); - } else { - progress.increaseExcludedByPatternsCount(); - } - } - } - - private void indexFile(final InputFileBuilder inputFileBuilder, final DefaultModuleFileSystem fs, - final Progress status, final DefaultInputFile inputFile, final InputFile.Type type) { - - tasks.add(executorService.submit(new Callable() { - @Override - public Void call() { - DefaultInputFile completedInputFile = inputFileBuilder.completeAndComputeMetadata(inputFile, type); - if (completedInputFile != null && accept(completedInputFile)) { - fs.add(completedInputFile); - status.markAsIndexed(completedInputFile); - File parentDir = completedInputFile.file().getParentFile(); - String relativePath = new PathResolver().relativePath(fs.baseDir(), parentDir); - if (relativePath != null) { - DefaultInputDir inputDir = new DefaultInputDir(fs.moduleKey(), relativePath); - fs.add(inputDir); - } - } - return null; - } - })); - - } - - private boolean accept(InputFile inputFile) { - // InputFileFilter extensions - for (InputFileFilter filter : filters) { - if (!filter.accept(inputFile)) { - return false; - } - } - return true; - } - - private class IndexFileVisitor implements FileVisitor { - private InputFileBuilder inputFileBuilder; - private DefaultModuleFileSystem fileSystem; - private Progress status; - private Type type; - - IndexFileVisitor(InputFileBuilder inputFileBuilder, DefaultModuleFileSystem fileSystem, Progress status, InputFile.Type type) { - this.inputFileBuilder = inputFileBuilder; - this.fileSystem = fileSystem; - this.status = status; - this.type = type; - } - - @Override - public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { - Path fileName = dir.getFileName(); - - if (fileName != null && fileName.toString().length() > 1 && fileName.toString().charAt(0) == '.') { - return FileVisitResult.SKIP_SUBTREE; - } - if (Files.isHidden(dir)) { - return FileVisitResult.SKIP_SUBTREE; - } - return FileVisitResult.CONTINUE; - } - - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - if (!Files.isHidden(file) && !DirectoryLock.LOCK_FILE_NAME.equals(file.getFileName().toString())) { - indexFile(inputFileBuilder, fileSystem, status, file, type); - } - return FileVisitResult.CONTINUE; - } - - @Override - public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { - if (exc != null && exc instanceof FileSystemLoopException) { - LOG.warn("Not indexing due to symlink loop: {}", file.toFile()); - return FileVisitResult.CONTINUE; - } - - throw exc; - } - - @Override - public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { - return FileVisitResult.CONTINUE; - } - } - - private class Progress { - private final Set indexed = new HashSet<>(); - private int excludedByPatternsCount = 0; - - synchronized void markAsIndexed(InputFile 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.path()); - progressReport.message(indexed.size() + " files indexed... (last one was " + inputFile.relativePath() + ")"); - } - - void increaseExcludedByPatternsCount() { - excludedByPatternsCount++; - } - - public int excludedByPatternsCount() { - return excludedByPatternsCount; - } - - int count() { - return indexed.size(); - } - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileSystemLogger.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileSystemLogger.java deleted file mode 100644 index 0d717301283..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileSystemLogger.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.filesystem; - -import com.google.common.annotations.VisibleForTesting; -import java.io.File; -import java.nio.charset.Charset; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.scan.filesystem.PathResolver; - -@BatchSide -public class FileSystemLogger { - - private final DefaultModuleFileSystem fs; - - public FileSystemLogger(DefaultModuleFileSystem fs) { - this.fs = fs; - } - - public void log() { - doLog(LoggerFactory.getLogger(getClass())); - } - - @VisibleForTesting - void doLog(Logger logger) { - logDir(logger, "Base dir: ", fs.baseDir()); - logDir(logger, "Working dir: ", fs.workDir()); - logPaths(logger, "Source paths: ", fs.baseDir(), fs.sources()); - logPaths(logger, "Test paths: ", fs.baseDir(), fs.tests()); - logPaths(logger, "Binary dirs: ", fs.baseDir(), fs.binaryDirs()); - logEncoding(logger, fs.encoding()); - } - - private void logEncoding(Logger logger, Charset charset) { - if (!fs.isDefaultJvmEncoding()) { - logger.info("Source encoding: " + charset.displayName() + ", default locale: " + Locale.getDefault()); - } else { - logger.warn("Source encoding is platform dependent (" + charset.displayName() + "), default locale: " + Locale.getDefault()); - } - } - - private static void logPaths(Logger logger, String label, File baseDir, List paths) { - if (!paths.isEmpty()) { - PathResolver resolver = new PathResolver(); - StringBuilder sb = new StringBuilder(label); - for (Iterator it = paths.iterator(); it.hasNext();) { - File file = it.next(); - String relativePathToBaseDir = resolver.relativePath(baseDir, file); - if (relativePathToBaseDir == null) { - sb.append(file); - } else if (StringUtils.isBlank(relativePathToBaseDir)) { - sb.append("."); - } else { - sb.append(relativePathToBaseDir); - } - if (it.hasNext()) { - sb.append(", "); - } - } - logger.info(sb.toString()); - } - } - - private void logDir(Logger logger, String label, File dir) { - if (dir != null) { - logger.info(label + dir.getAbsolutePath()); - } - } -} 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 deleted file mode 100644 index 49cbd423cf9..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputFileBuilder.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.filesystem; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.CoreProperties; -import org.sonar.api.batch.fs.FileSystem; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.batch.fs.internal.FileMetadata; -import org.sonar.api.config.Settings; -import org.sonar.api.scan.filesystem.PathResolver; - -import javax.annotation.CheckForNull; - -import java.io.File; - -class InputFileBuilder { - - private static final Logger LOG = LoggerFactory.getLogger(InputFileBuilder.class); - - private final String moduleKey; - private final PathResolver pathResolver; - private final LanguageDetection langDetection; - private final StatusDetection statusDetection; - private final DefaultModuleFileSystem fs; - private final Settings settings; - private final FileMetadata fileMetadata; - - InputFileBuilder(String moduleKey, PathResolver pathResolver, LanguageDetection langDetection, - StatusDetection statusDetection, DefaultModuleFileSystem fs, Settings settings, FileMetadata fileMetadata) { - this.moduleKey = moduleKey; - this.pathResolver = pathResolver; - this.langDetection = langDetection; - this.statusDetection = statusDetection; - this.fs = fs; - this.settings = settings; - this.fileMetadata = fileMetadata; - } - - String moduleKey() { - return moduleKey; - } - - PathResolver pathResolver() { - return pathResolver; - } - - LanguageDetection langDetection() { - return langDetection; - } - - StatusDetection statusDetection() { - return statusDetection; - } - - FileSystem fs() { - return fs; - } - - @CheckForNull - DefaultInputFile create(File file) { - String relativePath = pathResolver.relativePath(fs.baseDir(), file); - if (relativePath == null) { - LOG.warn("File '{}' is ignored. It is not located in module basedir '{}'.", file.getAbsolutePath(), fs.baseDir()); - return null; - } - return new DefaultInputFile(moduleKey, relativePath); - } - - /** - * Optimization to not compute InputFile metadata if the file is excluded from analysis. - */ - @CheckForNull - DefaultInputFile completeAndComputeMetadata(DefaultInputFile inputFile, InputFile.Type type) { - inputFile.setType(type); - inputFile.setModuleBaseDir(fs.baseDir().toPath()); - inputFile.setCharset(fs.encoding()); - - String lang = langDetection.language(inputFile); - if (lang == null && !settings.getBoolean(CoreProperties.IMPORT_UNKNOWN_FILES_KEY)) { - return null; - } - inputFile.setLanguage(lang); - - inputFile.initMetadata(fileMetadata.readMetadata(inputFile.file(), fs.encoding())); - - inputFile.setStatus(statusDetection.status(inputFile.moduleKey(), inputFile.relativePath(), inputFile.hash())); - - return inputFile; - } - -} 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 deleted file mode 100644 index 46dc2b2fbcd..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputFileBuilderFactory.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.filesystem; - -import org.sonar.api.batch.BatchSide; -import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.api.batch.fs.internal.FileMetadata; -import org.sonar.api.config.Settings; -import org.sonar.api.scan.filesystem.PathResolver; - -@BatchSide -public class InputFileBuilderFactory { - - private final String moduleKey; - private final PathResolver pathResolver; - private final LanguageDetectionFactory langDetectionFactory; - private final StatusDetectionFactory statusDetectionFactory; - private final Settings settings; - private final FileMetadata fileMetadata; - - public InputFileBuilderFactory(ProjectDefinition def, PathResolver pathResolver, LanguageDetectionFactory langDetectionFactory, - StatusDetectionFactory statusDetectionFactory, Settings settings, FileMetadata fileMetadata) { - this.fileMetadata = fileMetadata; - this.moduleKey = def.getKeyWithBranch(); - this.pathResolver = pathResolver; - this.langDetectionFactory = langDetectionFactory; - this.statusDetectionFactory = statusDetectionFactory; - this.settings = settings; - } - - InputFileBuilder create(DefaultModuleFileSystem fs) { - return new InputFileBuilder(moduleKey, pathResolver, langDetectionFactory.create(), statusDetectionFactory.create(), fs, settings, fileMetadata); - } -} 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 deleted file mode 100644 index 3375f92c7ff..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputPathCache.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.filesystem; - -import com.google.common.collect.Table; -import com.google.common.collect.TreeBasedTable; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.batch.fs.InputDir; -import org.sonar.api.batch.fs.InputFile; - -import javax.annotation.CheckForNull; - -/** - * Cache of all files and dirs. This cache is shared amongst all project modules. Inclusion and - * exclusion patterns are already applied. - */ -@BatchSide -public class InputPathCache { - - private final Table inputFileCache = TreeBasedTable.create(); - private final Table inputDirCache = TreeBasedTable.create(); - - public Iterable allFiles() { - return inputFileCache.values(); - } - - public Iterable allDirs() { - return inputDirCache.values(); - } - - public Iterable filesByModule(String moduleKey) { - return inputFileCache.row(moduleKey).values(); - } - - public Iterable dirsByModule(String moduleKey) { - return inputDirCache.row(moduleKey).values(); - } - - public InputPathCache removeModule(String moduleKey) { - inputFileCache.row(moduleKey).clear(); - inputDirCache.row(moduleKey).clear(); - return this; - } - - public InputPathCache remove(String moduleKey, InputFile inputFile) { - inputFileCache.remove(moduleKey, inputFile.relativePath()); - return this; - } - - public InputPathCache remove(String moduleKey, InputDir inputDir) { - inputDirCache.remove(moduleKey, inputDir.relativePath()); - return this; - } - - public InputPathCache put(String moduleKey, InputFile inputFile) { - inputFileCache.put(moduleKey, inputFile.relativePath(), inputFile); - return this; - } - - public InputPathCache put(String moduleKey, InputDir inputDir) { - inputDirCache.put(moduleKey, inputDir.relativePath(), inputDir); - return this; - } - - @CheckForNull - public InputFile getFile(String moduleKey, String relativePath) { - return inputFileCache.get(moduleKey, relativePath); - } - - @CheckForNull - public InputDir getDir(String moduleKey, String relativePath) { - return inputDirCache.get(moduleKey, relativePath); - } - -} 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 deleted file mode 100644 index db1300e2a97..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/LanguageDetection.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.filesystem; - -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; -import com.google.common.collect.Maps; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.CoreProperties; -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 javax.annotation.CheckForNull; - -import java.text.MessageFormat; -import java.util.List; -import java.util.Map; - -/** - * Detect language of a source file based on its suffix and configured patterns. - */ -class LanguageDetection { - - private static final Logger LOG = LoggerFactory.getLogger(LanguageDetection.class); - - /** - * Lower-case extension -> languages - */ - private final Map patternsByLanguage = Maps.newLinkedHashMap(); - private final List languagesToConsider = Lists.newArrayList(); - private final String forcedLanguage; - - LanguageDetection(Settings settings, LanguagesRepository languages) { - for (Language language : languages.all()) { - String[] filePatterns = settings.getStringArray(getFileLangPatternPropKey(language.key())); - PathPattern[] pathPatterns = PathPattern.create(filePatterns); - if (pathPatterns.length > 0) { - patternsByLanguage.put(language.key(), pathPatterns); - } else { - // If no custom language pattern is defined then fallback to suffixes declared by language - String[] patterns = language.fileSuffixes().toArray(new String[language.fileSuffixes().size()]); - for (int i = 0; i < patterns.length; i++) { - String suffix = patterns[i]; - String extension = sanitizeExtension(suffix); - patterns[i] = new StringBuilder().append("**/*.").append(extension).toString(); - } - PathPattern[] defaultLanguagePatterns = PathPattern.create(patterns); - patternsByLanguage.put(language.key(), defaultLanguagePatterns); - LOG.debug("Declared extensions of language " + language + " were converted to " + getDetails(language.key())); - } - } - - forcedLanguage = StringUtils.defaultIfBlank(settings.getString(CoreProperties.PROJECT_LANGUAGE_PROPERTY), null); - // First try with lang patterns - if (forcedLanguage != null) { - if (!patternsByLanguage.containsKey(forcedLanguage)) { - throw MessageException.of("No language is installed with key '" + forcedLanguage + "'. Please update property '" + CoreProperties.PROJECT_LANGUAGE_PROPERTY + "'"); - } - languagesToConsider.add(forcedLanguage); - } else { - languagesToConsider.addAll(patternsByLanguage.keySet()); - } - } - - Map patternsByLanguage() { - return patternsByLanguage; - } - - @CheckForNull - String language(InputFile inputFile) { - String detectedLanguage = null; - for (String languageKey : languagesToConsider) { - if (isCandidateForLanguage(inputFile, languageKey)) { - if (detectedLanguage == null) { - detectedLanguage = languageKey; - } else { - // Language was already forced by another pattern - throw MessageException.of(MessageFormat.format("Language of file ''{0}'' can not be decided as the file matches patterns of both {1} and {2}", - inputFile.relativePath(), getDetails(detectedLanguage), getDetails(languageKey))); - } - } - } - if (detectedLanguage != null) { - LOG.debug(String.format("Language of file '%s' is detected to be '%s'", inputFile.relativePath(), detectedLanguage)); - return detectedLanguage; - } - - // Check if deprecated sonar.language is used and we are on a language without declared extensions. - // Languages without declared suffixes match everything. - if (forcedLanguage != null && patternsByLanguage.get(forcedLanguage).length == 0) { - return forcedLanguage; - } - return null; - } - - private boolean isCandidateForLanguage(InputFile inputFile, String languageKey) { - PathPattern[] patterns = patternsByLanguage.get(languageKey); - if (patterns != null) { - for (PathPattern pathPattern : patterns) { - if (pathPattern.match(inputFile, false)) { - return true; - } - } - } - return false; - } - - private String getFileLangPatternPropKey(String languageKey) { - return "sonar.lang.patterns." + languageKey; - } - - private String getDetails(String detectedLanguage) { - return getFileLangPatternPropKey(detectedLanguage) + " : " + Joiner.on(",").join(patternsByLanguage.get(detectedLanguage)); - } - - static String sanitizeExtension(String suffix) { - return StringUtils.lowerCase(StringUtils.removeStart(suffix, ".")); - } -} 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 deleted file mode 100644 index b25a0038c64..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/LanguageDetectionFactory.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.filesystem; - -import org.sonar.api.batch.BatchSide; -import org.sonar.api.config.Settings; -import org.sonar.batch.repository.language.LanguagesRepository; - -@BatchSide -public class LanguageDetectionFactory { - private final Settings settings; - private final LanguagesRepository languages; - - public LanguageDetectionFactory(Settings settings, LanguagesRepository languages) { - this.settings = settings; - this.languages = languages; - } - - public LanguageDetection create() { - return new LanguageDetection(settings, languages); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ModuleFileSystemInitializer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ModuleFileSystemInitializer.java deleted file mode 100644 index faab666579a..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ModuleFileSystemInitializer.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.filesystem; - -import com.google.common.collect.Lists; -import org.apache.commons.io.FileUtils; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.api.scan.filesystem.PathResolver; -import org.sonar.api.utils.TempFolder; - -import javax.annotation.CheckForNull; - -import java.io.File; -import java.util.List; - -/** - * @since 3.5 - */ -@BatchSide -public class ModuleFileSystemInitializer { - - private File baseDir; - private File workingDir; - private File buildDir; - private List sourceDirsOrFiles = Lists.newArrayList(); - private List testDirsOrFiles = Lists.newArrayList(); - private List binaryDirs = Lists.newArrayList(); - - public ModuleFileSystemInitializer(ProjectDefinition module, TempFolder tempUtils, PathResolver pathResolver) { - baseDir = module.getBaseDir(); - buildDir = module.getBuildDir(); - initWorkingDir(module, tempUtils); - initBinaryDirs(module, pathResolver); - initSources(module, pathResolver); - initTests(module, pathResolver); - } - - private void initWorkingDir(ProjectDefinition module, TempFolder tempUtils) { - workingDir = module.getWorkDir(); - if (workingDir == null) { - workingDir = tempUtils.newDir("work"); - } else { - try { - FileUtils.forceMkdir(workingDir); - } catch (Exception e) { - throw new IllegalStateException("Fail to create working dir: " + workingDir.getAbsolutePath(), e); - } - } - } - - private void initSources(ProjectDefinition module, PathResolver pathResolver) { - for (String sourcePath : module.sources()) { - File dirOrFile = pathResolver.relativeFile(module.getBaseDir(), sourcePath); - if (dirOrFile.exists()) { - sourceDirsOrFiles.add(dirOrFile); - } - } - } - - private void initTests(ProjectDefinition module, PathResolver pathResolver) { - for (String testPath : module.tests()) { - File dirOrFile = pathResolver.relativeFile(module.getBaseDir(), testPath); - if (dirOrFile.exists()) { - testDirsOrFiles.add(dirOrFile); - } - } - } - - private void initBinaryDirs(ProjectDefinition module, PathResolver pathResolver) { - for (String path : module.getBinaries()) { - File dir = pathResolver.relativeFile(module.getBaseDir(), path); - binaryDirs.add(dir); - } - } - - File baseDir() { - return baseDir; - } - - File workingDir() { - return workingDir; - } - - @CheckForNull - File buildDir() { - return buildDir; - } - - List sources() { - return sourceDirsOrFiles; - } - - List tests() { - return testDirsOrFiles; - } - - /** - * @deprecated since 4.5.1 use SonarQube Java specific API - */ - @Deprecated - List binaryDirs() { - return binaryDirs; - } -} 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 deleted file mode 100644 index 5326b3fda4b..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ModuleInputFileCache.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.filesystem; - -import org.sonar.api.batch.BatchSide; -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.internal.DefaultFileSystem; - -@BatchSide -public class ModuleInputFileCache extends DefaultFileSystem.Cache { - - private final String moduleKey; - private final InputPathCache inputPathCache; - - public ModuleInputFileCache(ProjectDefinition projectDef, InputPathCache projectCache) { - this.moduleKey = projectDef.getKeyWithBranch(); - this.inputPathCache = projectCache; - } - - @Override - public Iterable inputFiles() { - return inputPathCache.filesByModule(moduleKey); - } - - @Override - public InputFile inputFile(String relativePath) { - return inputPathCache.getFile(moduleKey, relativePath); - } - - @Override - public InputDir inputDir(String relativePath) { - return inputPathCache.getDir(moduleKey, relativePath); - } - - @Override - protected void doAdd(InputFile inputFile) { - inputPathCache.put(moduleKey, inputFile); - } - - @Override - protected void doAdd(InputDir inputDir) { - inputPathCache.put(moduleKey, inputDir); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/StatusDetection.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/StatusDetection.java deleted file mode 100644 index bd63a81dfe2..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/StatusDetection.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.filesystem; - -import org.sonar.batch.repository.FileData; - -import org.sonar.batch.repository.ProjectRepositories; -import org.apache.commons.lang.StringUtils; -import org.sonar.api.batch.fs.InputFile; - -class StatusDetection { - - private final ProjectRepositories projectSettings; - - StatusDetection(ProjectRepositories projectSettings) { - this.projectSettings = projectSettings; - } - - InputFile.Status status(String projectKey, String relativePath, String hash) { - FileData fileDataPerPath = projectSettings.fileData(projectKey, relativePath); - if (fileDataPerPath == null) { - return InputFile.Status.ADDED; - } - String previousHash = fileDataPerPath.hash(); - if (StringUtils.equals(hash, previousHash)) { - return InputFile.Status.SAME; - } - if (StringUtils.isEmpty(previousHash)) { - return InputFile.Status.ADDED; - } - return InputFile.Status.CHANGED; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/StatusDetectionFactory.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/StatusDetectionFactory.java deleted file mode 100644 index b1a75c228c0..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/StatusDetectionFactory.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.filesystem; - -import org.sonar.batch.repository.ProjectRepositories; - -import org.sonar.api.batch.BatchSide; - -@BatchSide -public class StatusDetectionFactory { - - private final ProjectRepositories projectReferentials; - - public StatusDetectionFactory(ProjectRepositories projectReferentials) { - this.projectReferentials = projectReferentials; - } - - StatusDetection create() { - return new StatusDetection(projectReferentials); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/package-info.java deleted file mode 100644 index d5f662e81ea..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/package-info.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -/** - * This package is a part of bootstrap process, so we should take care about backward compatibility. - */ -@ParametersAreNonnullByDefault -package org.sonar.batch.scan.filesystem; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/measure/DefaultMetricFinder.java b/sonar-batch/src/main/java/org/sonar/batch/scan/measure/DefaultMetricFinder.java deleted file mode 100644 index 295e74aa2e2..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/measure/DefaultMetricFinder.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.measure; - -import com.google.common.collect.Lists; -import org.sonar.api.batch.measure.Metric; -import org.sonar.api.batch.measure.MetricFinder; -import org.sonar.api.measures.Metric.ValueType; -import org.sonar.batch.protocol.input.GlobalRepositories; - -import java.util.Collection; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -public class DefaultMetricFinder implements MetricFinder { - - private Map metricsByKey = new LinkedHashMap<>(); - - public DefaultMetricFinder(GlobalRepositories globalReferentials) { - for (org.sonar.batch.protocol.input.Metric metric : globalReferentials.metrics()) { - metricsByKey.put(metric.key(), new org.sonar.api.measures.Metric.Builder(metric.key(), metric.key(), ValueType.valueOf(metric.valueType())).create()); - } - } - - @Override - public Metric findByKey(String key) { - return metricsByKey.get(key); - } - - @Override - public Collection findAll(List metricKeys) { - List result = Lists.newLinkedList(); - for (String metricKey : metricKeys) { - Metric metric = findByKey(metricKey); - if (metric != null) { - result.add(metric); - } - } - return result; - } - - @Override - public Collection findAll() { - return metricsByKey.values(); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/measure/DeprecatedMetricFinder.java b/sonar-batch/src/main/java/org/sonar/batch/scan/measure/DeprecatedMetricFinder.java deleted file mode 100644 index f866972fd78..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/measure/DeprecatedMetricFinder.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.measure; - -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import org.sonar.api.measures.Metric; -import org.sonar.api.measures.Metric.ValueType; -import org.sonar.api.measures.MetricFinder; -import org.sonar.batch.protocol.input.GlobalRepositories; - -import java.util.Collection; -import java.util.List; -import java.util.Map; - -public final class DeprecatedMetricFinder implements MetricFinder { - - private Map metricsByKey = Maps.newLinkedHashMap(); - private Map metricsById = Maps.newLinkedHashMap(); - - public DeprecatedMetricFinder(GlobalRepositories globalReferentials) { - for (org.sonar.batch.protocol.input.Metric metric : globalReferentials.metrics()) { - Metric hibernateMetric = new org.sonar.api.measures.Metric.Builder(metric.key(), metric.name(), ValueType.valueOf(metric.valueType())) - .create() - .setDirection(metric.direction()) - .setQualitative(metric.isQualitative()) - .setUserManaged(metric.isUserManaged()) - .setDescription(metric.description()) - .setOptimizedBestValue(metric.isOptimizedBestValue()) - .setBestValue(metric.bestValue()) - .setWorstValue(metric.worstValue()) - .setId(metric.id()); - metricsByKey.put(metric.key(), hibernateMetric); - metricsById.put(metric.id(), new org.sonar.api.measures.Metric.Builder(metric.key(), metric.key(), ValueType.valueOf(metric.valueType())).create().setId(metric.id())); - } - } - - @Override - public Metric findById(int metricId) { - return metricsById.get(metricId); - } - - @Override - public Metric findByKey(String key) { - return metricsByKey.get(key); - } - - @Override - public Collection findAll(List metricKeys) { - List result = Lists.newLinkedList(); - for (String metricKey : metricKeys) { - Metric metric = findByKey(metricKey); - if (metric != null) { - result.add(metric); - } - } - return result; - } - - @Override - public Collection findAll() { - return metricsByKey.values(); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/measure/MeasureCache.java b/sonar-batch/src/main/java/org/sonar/batch/scan/measure/MeasureCache.java deleted file mode 100644 index 963f7e14b91..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/measure/MeasureCache.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.measure; - -import com.google.common.base.Preconditions; -import javax.annotation.CheckForNull; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.batch.measure.MetricFinder; -import org.sonar.api.measures.Measure; -import org.sonar.api.resources.Resource; -import org.sonar.batch.index.Cache; -import org.sonar.batch.index.Cache.Entry; -import org.sonar.batch.index.Caches; - -/** - * Cache of all measures. This cache is shared amongst all project modules. - */ -@BatchSide -public class MeasureCache { - - private final Cache cache; - - public MeasureCache(Caches caches, MetricFinder metricFinder) { - caches.registerValueCoder(Measure.class, new MeasureValueCoder(metricFinder)); - cache = caches.createCache("measures"); - } - - public Iterable> entries() { - return cache.entries(); - } - - public Iterable all() { - return cache.values(); - } - - public Iterable byResource(Resource r) { - return byComponentKey(r.getEffectiveKey()); - } - - public Iterable byComponentKey(String effectiveKey) { - return cache.values(effectiveKey); - } - - @CheckForNull - public Measure byMetric(Resource r, String metricKey) { - return byMetric(r.getEffectiveKey(), metricKey); - } - - @CheckForNull - public Measure byMetric(String resourceKey, String metricKey) { - return cache.get(resourceKey, metricKey); - } - - public MeasureCache put(Resource resource, Measure measure) { - Preconditions.checkNotNull(resource.getEffectiveKey()); - Preconditions.checkNotNull(measure.getMetricKey()); - cache.put(resource.getEffectiveKey(), measure.getMetricKey(), measure); - return this; - } - - public boolean contains(Resource resource, Measure measure) { - Preconditions.checkNotNull(resource.getEffectiveKey()); - Preconditions.checkNotNull(measure.getMetricKey()); - return cache.containsKey(resource.getEffectiveKey(), measure.getMetricKey()); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/measure/MeasureValueCoder.java b/sonar-batch/src/main/java/org/sonar/batch/scan/measure/MeasureValueCoder.java deleted file mode 100644 index 019410fd06b..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/measure/MeasureValueCoder.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.measure; - -import com.persistit.Value; -import com.persistit.encoding.CoderContext; -import com.persistit.encoding.ValueCoder; -import javax.annotation.Nullable; -import org.sonar.api.batch.measure.MetricFinder; -import org.sonar.api.measures.Measure; -import org.sonar.api.measures.Metric; -import org.sonar.api.measures.PersistenceMode; - -class MeasureValueCoder implements ValueCoder { - - private final MetricFinder metricFinder; - - public MeasureValueCoder(MetricFinder metricFinder) { - this.metricFinder = metricFinder; - } - - @Override - public void put(Value value, Object object, CoderContext context) { - Measure m = (Measure) object; - value.putUTF(m.getMetricKey()); - value.put(m.getValue()); - putUTFOrNull(value, m.getData()); - putUTFOrNull(value, m.getDescription()); - value.putString(m.getAlertStatus() != null ? m.getAlertStatus().name() : null); - putUTFOrNull(value, m.getAlertText()); - value.putDate(m.getDate()); - value.put(m.getVariation1()); - value.put(m.getVariation2()); - value.put(m.getVariation3()); - value.put(m.getVariation4()); - value.put(m.getVariation5()); - putUTFOrNull(value, m.getUrl()); - Integer personId = m.getPersonId(); - value.put(personId != null ? personId.intValue() : null); - PersistenceMode persistenceMode = m.getPersistenceMode(); - value.putString(persistenceMode != null ? persistenceMode.name() : null); - } - - private static 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) { - Measure m = new Measure(); - String metricKey = value.getString(); - org.sonar.api.batch.measure.Metric metric = metricFinder.findByKey(metricKey); - if (metric == null) { - throw new IllegalStateException("Unknow metric with key " + metricKey); - } - m.setMetric((org.sonar.api.measures.Metric) metric); - m.setRawValue(value.isNull(true) ? null : value.getDouble()); - m.setData(value.getString()); - m.setDescription(value.getString()); - m.setAlertStatus(value.isNull(true) ? null : Metric.Level.valueOf(value.getString())); - m.setAlertText(value.getString()); - m.setDate(value.getDate()); - m.setVariation1(value.isNull(true) ? null : value.getDouble()); - m.setVariation2(value.isNull(true) ? null : value.getDouble()); - m.setVariation3(value.isNull(true) ? null : value.getDouble()); - m.setVariation4(value.isNull(true) ? null : value.getDouble()); - m.setVariation5(value.isNull(true) ? null : value.getDouble()); - m.setUrl(value.getString()); - m.setPersonId(value.isNull(true) ? null : value.getInt()); - m.setPersistenceMode(value.isNull(true) ? null : PersistenceMode.valueOf(value.getString())); - return m; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/measure/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/scan/measure/package-info.java deleted file mode 100644 index f35eb86c95c..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/measure/package-info.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -/** - * This package is a part of bootstrap process, so we should take care about backward compatibility. - */ -@ParametersAreNonnullByDefault -package org.sonar.batch.scan.measure; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/scan/package-info.java deleted file mode 100644 index af539896111..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.batch.scan; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/ConsoleReport.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/ConsoleReport.java deleted file mode 100644 index 7e37b789c71..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/ConsoleReport.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.report; - -import com.google.common.annotations.VisibleForTesting; -import org.apache.commons.lang.StringUtils; -import org.sonar.api.Properties; -import org.sonar.api.Property; -import org.sonar.api.PropertyType; -import org.sonar.api.config.Settings; -import org.sonar.api.rule.Severity; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; -import org.sonar.batch.issue.IssueCache; -import org.sonar.batch.issue.tracking.TrackedIssue; -import org.sonar.batch.scan.filesystem.InputPathCache; - -@Properties({ - @Property(key = ConsoleReport.CONSOLE_REPORT_ENABLED_KEY, defaultValue = "false", name = "Enable console report", - description = "Set this to true to generate a report in console output", type = PropertyType.BOOLEAN)}) -public class ConsoleReport implements Reporter { - - @VisibleForTesting - public static final String HEADER = "------------- Issues Report -------------"; - - private static final Logger LOG = Loggers.get(ConsoleReport.class); - - public static final String CONSOLE_REPORT_ENABLED_KEY = "sonar.issuesReport.console.enable"; - private static final int LEFT_PAD = 10; - - private Settings settings; - private IssueCache issueCache; - private InputPathCache inputPathCache; - - @VisibleForTesting - public ConsoleReport(Settings settings, IssueCache issueCache, InputPathCache inputPathCache) { - this.settings = settings; - this.issueCache = issueCache; - this.inputPathCache = inputPathCache; - } - - private static class Report { - boolean noFile = false; - int totalNewIssues = 0; - int newBlockerIssues = 0; - int newCriticalIssues = 0; - int newMajorIssues = 0; - int newMinorIssues = 0; - int newInfoIssues = 0; - - public void process(TrackedIssue issue) { - if (issue.isNew()) { - totalNewIssues++; - switch (issue.severity()) { - case Severity.BLOCKER: - newBlockerIssues++; - break; - case Severity.CRITICAL: - newCriticalIssues++; - break; - case Severity.MAJOR: - newMajorIssues++; - break; - case Severity.MINOR: - newMinorIssues++; - break; - case Severity.INFO: - newInfoIssues++; - break; - default: - throw new IllegalStateException("Unknow severity: " + issue.severity()); - } - } - } - - public void setNoFile(boolean value) { - this.noFile = value; - } - } - - @Override - public void execute() { - if (settings.getBoolean(CONSOLE_REPORT_ENABLED_KEY)) { - Report r = new Report(); - r.setNoFile(!inputPathCache.allFiles().iterator().hasNext()); - for (TrackedIssue issue : issueCache.all()) { - r.process(issue); - } - printReport(r); - } - } - - public void printReport(Report r) { - StringBuilder sb = new StringBuilder(); - - sb.append("\n\n" + HEADER + "\n\n"); - if (r.noFile) { - sb.append(" No file analyzed\n"); - } else { - printNewIssues(r, sb); - } - sb.append("\n-------------------------------------------\n\n"); - - LOG.info(sb.toString()); - } - - private static void printNewIssues(Report r, StringBuilder sb) { - int newIssues = r.totalNewIssues; - if (newIssues > 0) { - sb.append(StringUtils.leftPad("+" + newIssues, LEFT_PAD)).append(" issue" + (newIssues > 1 ? "s" : "")).append("\n\n"); - printNewIssues(sb, r.newBlockerIssues, Severity.BLOCKER, "blocker"); - printNewIssues(sb, r.newCriticalIssues, Severity.CRITICAL, "critical"); - printNewIssues(sb, r.newMajorIssues, Severity.MAJOR, "major"); - printNewIssues(sb, r.newMinorIssues, Severity.MINOR, "minor"); - printNewIssues(sb, r.newInfoIssues, Severity.INFO, "info"); - } else { - sb.append(" No new issue").append("\n"); - } - } - - private static void printNewIssues(StringBuilder sb, int issueCount, String severity, String severityLabel) { - if (issueCount > 0) { - sb.append(StringUtils.leftPad("+" + issueCount, LEFT_PAD)).append(" ").append(severityLabel).append("\n"); - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/HtmlReport.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/HtmlReport.java deleted file mode 100644 index 8111abd467e..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/HtmlReport.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.report; - -import com.google.common.collect.Maps; -import freemarker.template.Template; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.Writer; -import java.net.URISyntaxException; -import java.util.Map; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.Properties; -import org.sonar.api.Property; -import org.sonar.api.PropertyType; -import org.sonar.api.batch.fs.FileSystem; -import org.sonar.api.config.Settings; - -@Properties({ - @Property(key = HtmlReport.HTML_REPORT_ENABLED_KEY, defaultValue = "false", name = "Enable HTML report", description = "Set this to true to generate an HTML report", - type = PropertyType.BOOLEAN), - @Property(key = HtmlReport.HTML_REPORT_LOCATION_KEY, defaultValue = HtmlReport.HTML_REPORT_LOCATION_DEFAULT, name = "HTML Report location", - description = "Location of the generated report. Can be absolute or relative to working directory", project = false, global = false, type = PropertyType.STRING), - @Property(key = HtmlReport.HTML_REPORT_NAME_KEY, defaultValue = HtmlReport.HTML_REPORT_NAME_DEFAULT, name = "HTML Report name", - description = "Name of the generated report. Will be suffixed by .html or -light.html", project = false, global = false, type = PropertyType.STRING), - @Property(key = HtmlReport.HTML_REPORT_LIGHTMODE_ONLY, defaultValue = "false", name = "Html report in light mode only", - description = "Set this to true to only generate the new issues report (light report)", project = true, type = PropertyType.BOOLEAN)}) -public class HtmlReport implements Reporter { - private static final Logger LOG = LoggerFactory.getLogger(HtmlReport.class); - - public static final String HTML_REPORT_ENABLED_KEY = "sonar.issuesReport.html.enable"; - public static final String HTML_REPORT_LOCATION_KEY = "sonar.issuesReport.html.location"; - public static final String HTML_REPORT_LOCATION_DEFAULT = "issues-report"; - public static final String HTML_REPORT_NAME_KEY = "sonar.issuesReport.html.name"; - public static final String HTML_REPORT_NAME_DEFAULT = "issues-report"; - public static final String HTML_REPORT_LIGHTMODE_ONLY = "sonar.issuesReport.lightModeOnly"; - - private final Settings settings; - private final FileSystem fs; - private final IssuesReportBuilder builder; - private final SourceProvider sourceProvider; - private final RuleNameProvider ruleNameProvider; - - public HtmlReport(Settings settings, FileSystem fs, IssuesReportBuilder builder, SourceProvider sourceProvider, RuleNameProvider ruleNameProvider) { - this.settings = settings; - this.fs = fs; - this.builder = builder; - this.sourceProvider = sourceProvider; - this.ruleNameProvider = ruleNameProvider; - } - - @Override - public void execute() { - if (settings.getBoolean(HTML_REPORT_ENABLED_KEY)) { - IssuesReport report = builder.buildReport(); - print(report); - } - } - - public void print(IssuesReport report) { - File reportFileDir = getReportFileDir(); - String reportName = settings.getString(HTML_REPORT_NAME_KEY); - if (!isLightModeOnly()) { - File reportFile = new File(reportFileDir, reportName + ".html"); - LOG.debug("Generating HTML Report to: " + reportFile.getAbsolutePath()); - writeToFile(report, reportFile, true); - LOG.info("HTML Issues Report generated: " + reportFile.getAbsolutePath()); - } - File lightReportFile = new File(reportFileDir, reportName + "-light.html"); - LOG.debug("Generating Light HTML Report to: " + lightReportFile.getAbsolutePath()); - writeToFile(report, lightReportFile, false); - LOG.info("Light HTML Issues Report generated: " + lightReportFile.getAbsolutePath()); - try { - copyDependencies(reportFileDir); - } catch (Exception e) { - throw new IllegalStateException("Fail to copy HTML report resources to: " + reportFileDir, e); - } - } - - private File getReportFileDir() { - String reportFileDirStr = settings.getString(HTML_REPORT_LOCATION_KEY); - File reportFileDir = new File(reportFileDirStr); - if (!reportFileDir.isAbsolute()) { - reportFileDir = new File(fs.workDir(), reportFileDirStr); - } - if (StringUtils.endsWith(reportFileDirStr, ".html")) { - LOG.warn(HTML_REPORT_LOCATION_KEY + " should indicate a directory. Using parent folder."); - reportFileDir = reportFileDir.getParentFile(); - } - try { - FileUtils.forceMkdir(reportFileDir); - } catch (IOException e) { - throw new IllegalStateException("Fail to create the directory " + reportFileDirStr, e); - } - return reportFileDir; - } - - public void writeToFile(IssuesReport report, File toFile, boolean complete) { - try { - freemarker.log.Logger.selectLoggerLibrary(freemarker.log.Logger.LIBRARY_NONE); - freemarker.template.Configuration cfg = new freemarker.template.Configuration(); - cfg.setClassForTemplateLoading(HtmlReport.class, ""); - - Map root = Maps.newHashMap(); - root.put("report", report); - root.put("ruleNameProvider", ruleNameProvider); - root.put("sourceProvider", sourceProvider); - root.put("complete", complete); - - Template template = cfg.getTemplate("issuesreport.ftl"); - - try (FileOutputStream fos = new FileOutputStream(toFile); Writer writer = new OutputStreamWriter(fos, fs.encoding())) { - template.process(root, writer); - writer.flush(); - } - } catch (Exception e) { - throw new IllegalStateException("Fail to generate HTML Issues Report to: " + toFile, e); - - } - } - - void copyDependencies(File toDir) throws URISyntaxException, IOException { - File target = new File(toDir, "issuesreport_files"); - FileUtils.forceMkdir(target); - - // I don't know how to extract a directory from classpath, that's why an exhaustive list of files - // is provided here : - copyDependency(target, "sonar.eot"); - copyDependency(target, "sonar.svg"); - copyDependency(target, "sonar.ttf"); - copyDependency(target, "sonar.woff"); - copyDependency(target, "favicon.ico"); - copyDependency(target, "PRJ.png"); - copyDependency(target, "DIR.png"); - copyDependency(target, "FIL.png"); - copyDependency(target, "jquery.min.js"); - copyDependency(target, "sep12.png"); - copyDependency(target, "sonar.css"); - copyDependency(target, "sonarqube-24x100.png"); - } - - private void copyDependency(File target, String filename) { - try (InputStream input = getClass().getResourceAsStream("/org/sonar/batch/scan/report/issuesreport_files/" + filename); - OutputStream output = new FileOutputStream(new File(target, filename))) { - IOUtils.copy(input, output); - } catch (IOException e) { - throw new IllegalStateException("Fail to copy file " + filename + " to " + target, e); - } - } - - public boolean isLightModeOnly() { - return settings.getBoolean(HTML_REPORT_LIGHTMODE_ONLY); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssueVariation.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssueVariation.java deleted file mode 100644 index 23ca58e7d8c..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssueVariation.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.report; - -import org.apache.commons.lang.builder.ToStringBuilder; - -public class IssueVariation { - - private int countInCurrentAnalysis; - private int newIssuesCount; - private int resolvedIssuesCount; - - public int getCountInCurrentAnalysis() { - return countInCurrentAnalysis; - } - - public void incrementCountInCurrentAnalysis() { - this.countInCurrentAnalysis++; - } - - public int getNewIssuesCount() { - return newIssuesCount; - } - - public void incrementNewIssuesCount() { - this.newIssuesCount++; - } - - public int getResolvedIssuesCount() { - return resolvedIssuesCount; - } - - public void incrementResolvedIssuesCount() { - this.resolvedIssuesCount++; - } - - @Override - public String toString() { - return new ToStringBuilder(this). - append("countInCurrentAnalysis", countInCurrentAnalysis). - append("newIssuesCount", newIssuesCount). - append("resolvedIssuesCount", resolvedIssuesCount). - toString(); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReport.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReport.java deleted file mode 100644 index cede7a81d1c..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReport.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.report; - -import org.sonar.batch.issue.tracking.TrackedIssue; - -import com.google.common.collect.Maps; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Map; - -import org.sonar.api.batch.rule.Rule; -import org.sonar.api.rules.RulePriority; -import org.sonar.batch.index.BatchComponent; - -public class IssuesReport { - - public static final int TOO_MANY_ISSUES_THRESHOLD = 1000; - private String title; - private Date date; - private boolean noFile; - private final ReportSummary summary = new ReportSummary(); - private final Map resourceReportsByResource = Maps.newLinkedHashMap(); - - public ReportSummary getSummary() { - return summary; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public Date getDate() { - return date; - } - - public void setDate(Date date) { - this.date = date; - } - - public boolean isNoFile() { - return noFile; - } - - public void setNoFile(boolean noFile) { - this.noFile = noFile; - } - - public Map getResourceReportsByResource() { - return resourceReportsByResource; - } - - public List getResourceReports() { - return new ArrayList<>(resourceReportsByResource.values()); - } - - public List getResourcesWithReport() { - return new ArrayList<>(resourceReportsByResource.keySet()); - } - - public void addIssueOnResource(BatchComponent resource, TrackedIssue issue, Rule rule, RulePriority severity) { - addResource(resource); - getSummary().addIssue(issue, rule, severity); - resourceReportsByResource.get(resource).addIssue(issue, rule, RulePriority.valueOf(issue.severity())); - } - - public void addResolvedIssueOnResource(BatchComponent resource, TrackedIssue issue, Rule rule, RulePriority severity) { - addResource(resource); - getSummary().addResolvedIssue(issue, rule, severity); - resourceReportsByResource.get(resource).addResolvedIssue(rule, RulePriority.valueOf(issue.severity())); - } - - private void addResource(BatchComponent resource) { - if (!resourceReportsByResource.containsKey(resource)) { - resourceReportsByResource.put(resource, new ResourceReport(resource)); - } - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReportBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReportBuilder.java deleted file mode 100644 index 079dabc2ceb..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReportBuilder.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.report; - -import org.sonar.batch.issue.tracking.TrackedIssue; - -import javax.annotation.CheckForNull; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.batch.rule.Rule; -import org.sonar.api.batch.rule.Rules; -import org.sonar.api.resources.Project; -import org.sonar.api.rules.RulePriority; -import org.sonar.batch.DefaultProjectTree; -import org.sonar.batch.index.BatchComponent; -import org.sonar.batch.index.BatchComponentCache; -import org.sonar.batch.issue.IssueCache; -import org.sonar.batch.scan.filesystem.InputPathCache; - -@BatchSide -public class IssuesReportBuilder { - - private static final Logger LOG = LoggerFactory.getLogger(IssuesReportBuilder.class); - - private final IssueCache issueCache; - private final Rules rules; - private final BatchComponentCache resourceCache; - private final DefaultProjectTree projectTree; - private final InputPathCache inputPathCache; - - public IssuesReportBuilder(IssueCache issueCache, Rules rules, BatchComponentCache resourceCache, DefaultProjectTree projectTree, InputPathCache inputPathCache) { - this.issueCache = issueCache; - this.rules = rules; - this.resourceCache = resourceCache; - this.projectTree = projectTree; - this.inputPathCache = inputPathCache; - } - - public IssuesReport buildReport() { - Project project = projectTree.getRootProject(); - IssuesReport issuesReport = new IssuesReport(); - issuesReport.setNoFile(!inputPathCache.allFiles().iterator().hasNext()); - issuesReport.setTitle(project.getName()); - issuesReport.setDate(project.getAnalysisDate()); - - processIssues(issuesReport, issueCache.all()); - - return issuesReport; - } - - private void processIssues(IssuesReport issuesReport, Iterable issues) { - for (TrackedIssue issue : issues) { - Rule rule = findRule(issue); - RulePriority severity = RulePriority.valueOf(issue.severity()); - BatchComponent resource = resourceCache.get(issue.componentKey()); - if (!validate(issue, rule, resource)) { - continue; - } - if (issue.resolution() != null) { - issuesReport.addResolvedIssueOnResource(resource, issue, rule, severity); - } else { - issuesReport.addIssueOnResource(resource, issue, rule, severity); - } - } - } - - private static boolean validate(TrackedIssue issue, Rule rule, BatchComponent resource) { - if (rule == null) { - LOG.warn("Unknow rule for issue {}", issue); - return false; - } - if (resource == null) { - LOG.debug("Unknow resource with key {}", issue.componentKey()); - return false; - } - return true; - } - - @CheckForNull - private Rule findRule(TrackedIssue issue) { - return rules.find(issue.getRuleKey()); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReports.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReports.java deleted file mode 100644 index ac4a5abb375..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReports.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.report; - -import org.sonar.api.batch.BatchSide; - -@BatchSide -public class IssuesReports { - - private final Reporter[] reporters; - - public IssuesReports(Reporter... reporters) { - this.reporters = reporters; - } - - public void execute() { - for (Reporter reporter : reporters) { - reporter.execute(); - } - } -} 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 deleted file mode 100644 index f0c2e2b6da7..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/JSONReport.java +++ /dev/null @@ -1,247 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.report; - -import com.google.common.annotations.VisibleForTesting; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.io.Writer; -import java.nio.charset.StandardCharsets; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.Properties; -import org.sonar.api.Property; -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.internal.DefaultInputDir; -import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.batch.rule.Rule; -import org.sonar.api.batch.rule.Rules; -import org.sonar.api.config.Settings; -import org.sonar.api.platform.Server; -import org.sonar.api.resources.Project; -import org.sonar.api.rule.RuleKey; -import org.sonar.api.utils.text.JsonWriter; -import org.sonar.batch.issue.IssueCache; -import org.sonar.batch.issue.tracking.TrackedIssue; -import org.sonar.batch.protocol.input.BatchInput; -import org.sonar.batch.protocol.input.BatchInput.User; -import org.sonar.batch.repository.user.UserRepositoryLoader; -import org.sonar.batch.scan.filesystem.InputPathCache; - -@Properties({ - @Property( - key = JSONReport.SONAR_REPORT_EXPORT_PATH, - name = "Report Results Export File", - type = PropertyType.STRING, - global = false, project = false)}) -public class JSONReport implements Reporter { - - static final String SONAR_REPORT_EXPORT_PATH = "sonar.report.export.path"; - private static final Logger LOG = LoggerFactory.getLogger(JSONReport.class); - private final Settings settings; - private final FileSystem fileSystem; - private final Server server; - private final Rules rules; - private final IssueCache issueCache; - private final InputPathCache fileCache; - private final Project rootModule; - private final UserRepositoryLoader userRepository; - - public JSONReport(Settings settings, FileSystem fileSystem, Server server, Rules rules, IssueCache issueCache, - Project rootModule, InputPathCache fileCache, UserRepositoryLoader userRepository) { - this.settings = settings; - this.fileSystem = fileSystem; - this.server = server; - this.rules = rules; - this.issueCache = issueCache; - this.rootModule = rootModule; - this.fileCache = fileCache; - this.userRepository = userRepository; - } - - @Override - public void execute() { - String exportPath = settings.getString(SONAR_REPORT_EXPORT_PATH); - if (exportPath != null) { - exportResults(exportPath); - } - } - - private void exportResults(String exportPath) { - File exportFile = new File(fileSystem.workDir(), exportPath); - - LOG.info("Export issues to {}", exportFile.getAbsolutePath()); - try (Writer output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(exportFile), StandardCharsets.UTF_8))) { - writeJson(output); - - } catch (IOException e) { - throw new IllegalStateException("Unable to write report results in file " + exportFile.getAbsolutePath(), e); - } - } - - @VisibleForTesting - void writeJson(Writer writer) { - try { - JsonWriter json = JsonWriter.of(writer); - json.beginObject(); - json.prop("version", server.getVersion()); - - Set ruleKeys = new LinkedHashSet<>(); - Set userLogins = new LinkedHashSet<>(); - writeJsonIssues(json, ruleKeys, userLogins); - writeJsonComponents(json); - writeJsonRules(json, ruleKeys); - writeUsers(json, userLogins); - json.endObject().close(); - - } catch (IOException e) { - throw new IllegalStateException("Unable to write JSON report", e); - } - } - - private void writeJsonIssues(JsonWriter json, Set ruleKeys, Set logins) throws IOException { - json.name("issues").beginArray(); - for (TrackedIssue issue : getIssues()) { - if (issue.resolution() == null) { - json - .beginObject() - .prop("key", issue.key()) - .prop("component", issue.componentKey()) - .prop("line", issue.startLine()) - .prop("startLine", issue.startLine()) - .prop("startOffset", issue.startLineOffset()) - .prop("endLine", issue.endLine()) - .prop("endOffset", issue.endLineOffset()) - .prop("message", issue.getMessage()) - .prop("severity", issue.severity()) - .prop("rule", issue.getRuleKey().toString()) - .prop("status", issue.status()) - .prop("resolution", issue.resolution()) - .prop("isNew", issue.isNew()) - .prop("assignee", issue.assignee()) - .prop("effortToFix", issue.gap()) - .propDateTime("creationDate", issue.creationDate()); - if (!StringUtils.isEmpty(issue.reporter())) { - logins.add(issue.reporter()); - } - if (!StringUtils.isEmpty(issue.assignee())) { - logins.add(issue.assignee()); - } - json.endObject(); - ruleKeys.add(issue.getRuleKey()); - } - } - json.endArray(); - } - - private void writeJsonComponents(JsonWriter json) throws IOException { - json.name("components").beginArray(); - // Dump modules - writeJsonModuleComponents(json, rootModule); - 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(); - } - - private static void writeJsonModuleComponents(JsonWriter json, Project module) { - json - .beginObject() - .prop("key", module.getEffectiveKey()) - .prop("path", module.getPath()) - .endObject(); - for (Project subModule : module.getModules()) { - writeJsonModuleComponents(json, subModule); - } - } - - private void writeJsonRules(JsonWriter json, Set ruleKeys) throws IOException { - json.name("rules").beginArray(); - for (RuleKey ruleKey : ruleKeys) { - json - .beginObject() - .prop("key", ruleKey.toString()) - .prop("rule", ruleKey.rule()) - .prop("repository", ruleKey.repository()) - .prop("name", getRuleName(ruleKey)) - .endObject(); - } - json.endArray(); - } - - private void writeUsers(JsonWriter json, Collection userLogins) throws IOException { - List users = new LinkedList<>(); - for (String userLogin : userLogins) { - User user = userRepository.load(userLogin); - if (user != null) { - users.add(user); - } - } - - json.name("users").beginArray(); - for (BatchInput.User user : users) { - json - .beginObject() - .prop("login", user.getLogin()) - .prop("name", user.getName()) - .endObject(); - } - json.endArray(); - } - - private String getRuleName(RuleKey ruleKey) { - Rule rule = rules.find(ruleKey); - return rule != null ? rule.name() : null; - } - - @VisibleForTesting - Iterable getIssues() { - return issueCache.all(); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/ReportRuleKey.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/ReportRuleKey.java deleted file mode 100644 index 1061d3c3238..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/ReportRuleKey.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.report; - -import org.sonar.api.batch.rule.Rule; - -import org.apache.commons.lang.ObjectUtils; -import org.apache.commons.lang.builder.ToStringBuilder; -import org.sonar.api.rules.RulePriority; - -/** - * A same rule can be present with different severity if severity was manually changed so we need this special key that - * include severity. - * - */ -public class ReportRuleKey implements Comparable { - private final Rule rule; - private final RulePriority severity; - - public ReportRuleKey(Rule rule, RulePriority severity) { - this.rule = rule; - this.severity = severity; - } - - public Rule getRule() { - return rule; - } - - public RulePriority getSeverity() { - return severity; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - ReportRuleKey that = (ReportRuleKey) o; - return ObjectUtils.equals(rule, that.rule) && ObjectUtils.equals(severity, that.severity); - } - - @Override - public int hashCode() { - int result = rule.hashCode(); - result = 31 * result + severity.hashCode(); - return result; - } - - @Override - public int compareTo(ReportRuleKey o) { - if (severity == o.getSeverity()) { - return getRule().key().toString().compareTo(o.getRule().key().toString()); - } - return o.getSeverity().compareTo(severity); - } - - @Override - public String toString() { - return new ToStringBuilder(this). - append("rule", rule). - append("severity", severity). - toString(); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/ReportSummary.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/ReportSummary.java deleted file mode 100644 index 435aee37450..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/ReportSummary.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.report; - -import com.google.common.collect.Maps; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import org.sonar.api.batch.rule.Rule; -import org.sonar.api.rules.RulePriority; -import org.sonar.batch.issue.tracking.TrackedIssue; - -public class ReportSummary { - - private final IssueVariation total = new IssueVariation(); - - private final Map ruleReportByRuleKey = Maps.newLinkedHashMap(); - private final Map totalByRuleKey = Maps.newLinkedHashMap(); - private final Map totalBySeverity = Maps.newLinkedHashMap(); - - public IssueVariation getTotal() { - return total; - } - - public void addIssue(TrackedIssue issue, Rule rule, RulePriority severity) { - ReportRuleKey reportRuleKey = new ReportRuleKey(rule, severity); - initMaps(reportRuleKey); - ruleReportByRuleKey.get(reportRuleKey).getTotal().incrementCountInCurrentAnalysis(); - total.incrementCountInCurrentAnalysis(); - totalByRuleKey.get(rule.key().toString()).incrementCountInCurrentAnalysis(); - totalBySeverity.get(severity.toString()).incrementCountInCurrentAnalysis(); - if (issue.isNew()) { - total.incrementNewIssuesCount(); - ruleReportByRuleKey.get(reportRuleKey).getTotal().incrementNewIssuesCount(); - totalByRuleKey.get(rule.key().toString()).incrementNewIssuesCount(); - totalBySeverity.get(severity.toString()).incrementNewIssuesCount(); - } - } - - public Map getTotalBySeverity() { - return totalBySeverity; - } - - public Map getTotalByRuleKey() { - return totalByRuleKey; - } - - public void addResolvedIssue(TrackedIssue issue, Rule rule, RulePriority severity) { - ReportRuleKey reportRuleKey = new ReportRuleKey(rule, severity); - initMaps(reportRuleKey); - total.incrementResolvedIssuesCount(); - ruleReportByRuleKey.get(reportRuleKey).getTotal().incrementResolvedIssuesCount(); - totalByRuleKey.get(rule.key().toString()).incrementResolvedIssuesCount(); - totalBySeverity.get(severity.toString()).incrementResolvedIssuesCount(); - } - - private void initMaps(ReportRuleKey reportRuleKey) { - if (!ruleReportByRuleKey.containsKey(reportRuleKey)) { - ruleReportByRuleKey.put(reportRuleKey, new RuleReport(reportRuleKey)); - } - if (!totalByRuleKey.containsKey(reportRuleKey.getRule().key().toString())) { - totalByRuleKey.put(reportRuleKey.getRule().key().toString(), new IssueVariation()); - } - if (!totalBySeverity.containsKey(reportRuleKey.getSeverity().toString())) { - totalBySeverity.put(reportRuleKey.getSeverity().toString(), new IssueVariation()); - } - } - - public List getRuleReports() { - List result = new ArrayList<>(ruleReportByRuleKey.values()); - Collections.sort(result, new RuleReportComparator()); - return result; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/Reporter.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/Reporter.java deleted file mode 100644 index 9cb91dc2fad..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/Reporter.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.report; - -import org.sonar.api.batch.BatchSide; - -@BatchSide -public interface Reporter { - - void execute(); - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/ResourceReport.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/ResourceReport.java deleted file mode 100644 index 6267335baf0..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/ResourceReport.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.report; - -import org.sonar.batch.issue.tracking.TrackedIssue; - -import org.sonar.api.batch.rule.Rule; -import com.google.common.collect.Maps; -import org.sonar.api.rules.RulePriority; -import org.sonar.batch.index.BatchComponent; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.concurrent.atomic.AtomicInteger; - -public final class ResourceReport { - private final BatchComponent resource; - private final IssueVariation total = new IssueVariation(); - private final Map ruleReportByRuleKey = Maps.newHashMap(); - - private List issues = new ArrayList<>(); - private Map> issuesPerLine = Maps.newHashMap(); - private Map> newIssuesPerLine = Maps.newHashMap(); - private Map issuesByRule = Maps.newHashMap(); - private Map issuesBySeverity = Maps.newHashMap(); - - public ResourceReport(BatchComponent resource) { - this.resource = resource; - } - - public BatchComponent getResourceNode() { - return resource; - } - - public String getName() { - return resource.resource().getName(); - } - - public String getType() { - return resource.resource().getScope(); - } - - public IssueVariation getTotal() { - return total; - } - - public List getIssues() { - return issues; - } - - public Map> getIssuesPerLine() { - return issuesPerLine; - } - - public List getIssuesAtLine(int lineId, boolean all) { - if (all) { - if (issuesPerLine.containsKey(lineId)) { - return issuesPerLine.get(lineId); - } - } else if (newIssuesPerLine.containsKey(lineId)) { - return newIssuesPerLine.get(lineId); - } - return Collections.emptyList(); - } - - public void addIssue(TrackedIssue issue, Rule rule, RulePriority severity) { - ReportRuleKey reportRuleKey = new ReportRuleKey(rule, severity); - initMaps(reportRuleKey); - issues.add(issue); - Integer line = issue.startLine(); - line = line != null ? line : 0; - if (!issuesPerLine.containsKey(line)) { - issuesPerLine.put(line, new ArrayList()); - } - issuesPerLine.get(line).add(issue); - if (!issuesByRule.containsKey(rule)) { - issuesByRule.put(rule, new AtomicInteger()); - } - issuesByRule.get(rule).incrementAndGet(); - if (!issuesBySeverity.containsKey(severity)) { - issuesBySeverity.put(severity, new AtomicInteger()); - } - issuesBySeverity.get(severity).incrementAndGet(); - ruleReportByRuleKey.get(reportRuleKey).getTotal().incrementCountInCurrentAnalysis(); - total.incrementCountInCurrentAnalysis(); - if (issue.isNew()) { - if (!newIssuesPerLine.containsKey(line)) { - newIssuesPerLine.put(line, new ArrayList()); - } - newIssuesPerLine.get(line).add(issue); - total.incrementNewIssuesCount(); - ruleReportByRuleKey.get(reportRuleKey).getTotal().incrementNewIssuesCount(); - } - } - - public void addResolvedIssue(Rule rule, RulePriority severity) { - ReportRuleKey reportRuleKey = new ReportRuleKey(rule, severity); - initMaps(reportRuleKey); - total.incrementResolvedIssuesCount(); - ruleReportByRuleKey.get(reportRuleKey).getTotal().incrementResolvedIssuesCount(); - } - - private void initMaps(ReportRuleKey reportRuleKey) { - if (!ruleReportByRuleKey.containsKey(reportRuleKey)) { - ruleReportByRuleKey.put(reportRuleKey, new RuleReport(reportRuleKey)); - } - } - - public boolean isDisplayableLine(Integer lineNumber, boolean all) { - if (lineNumber == null || lineNumber < 1) { - return false; - } - for (int i = lineNumber - 2; i <= lineNumber + 2; i++) { - if (hasIssues(i, all)) { - return true; - } - } - return false; - } - - private boolean hasIssues(Integer lineId, boolean all) { - if (all) { - List issuesAtLine = issuesPerLine.get(lineId); - return issuesAtLine != null && !issuesAtLine.isEmpty(); - } - List newIssuesAtLine = newIssuesPerLine.get(lineId); - return newIssuesAtLine != null && !newIssuesAtLine.isEmpty(); - } - - public List getRuleReports() { - List result = new ArrayList<>(ruleReportByRuleKey.values()); - Collections.sort(result, new RuleReportComparator()); - return result; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/RuleNameProvider.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/RuleNameProvider.java deleted file mode 100644 index 90981fea342..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/RuleNameProvider.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.report; - -import org.sonar.api.batch.rule.Rule; - -import org.sonar.api.batch.rule.Rules; -import org.apache.commons.lang.StringEscapeUtils; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.rule.RuleKey; - -import javax.annotation.CheckForNull; - -@BatchSide -public class RuleNameProvider { - private Rules rules; - - public RuleNameProvider(Rules rules) { - this.rules = rules; - } - - @CheckForNull - private String nameFromDB(RuleKey ruleKey) { - Rule r = rules.find(ruleKey); - return r != null ? r.name() : null; - } - - public String nameForHTML(RuleKey ruleKey) { - String name = nameFromDB(ruleKey); - return StringEscapeUtils.escapeHtml(name != null ? name : ruleKey.toString()); - } - - public String nameForJS(String ruleKey) { - String name = nameFromDB(RuleKey.parse(ruleKey)); - return StringEscapeUtils.escapeJavaScript(name != null ? name : ruleKey); - } - - public String nameForHTML(Rule rule) { - return StringEscapeUtils.escapeHtml(rule.name()); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/RuleReport.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/RuleReport.java deleted file mode 100644 index 4026ed387ab..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/RuleReport.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.report; - -import org.sonar.api.batch.rule.Rule; - -import org.apache.commons.lang.builder.ToStringBuilder; - -public final class RuleReport { - private final ReportRuleKey reportRuleKey; - private final IssueVariation total = new IssueVariation(); - - public RuleReport(ReportRuleKey reportRuleKey) { - this.reportRuleKey = reportRuleKey; - } - - public IssueVariation getTotal() { - return total; - } - - public ReportRuleKey getReportRuleKey() { - return reportRuleKey; - } - - public String getSeverity() { - return reportRuleKey.getSeverity().toString(); - } - - public Rule getRule() { - return reportRuleKey.getRule(); - } - - @Override - public String toString() { - return new ToStringBuilder(this). - append("reportRuleKey", reportRuleKey). - append("total", total). - toString(); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/RuleReportComparator.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/RuleReportComparator.java deleted file mode 100644 index b779537e8fd..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/RuleReportComparator.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.report; - -import java.io.Serializable; -import java.util.Comparator; - -public class RuleReportComparator implements Comparator, Serializable { - @Override - public int compare(RuleReport o1, RuleReport o2) { - if (bothHaveNoNewIssue(o1, o2)) { - return compareByRuleSeverityAndName(o1, o2); - } else if (bothHaveNewIssues(o1, o2)) { - if (sameSeverity(o1, o2) && !sameNewIssueCount(o1, o2)) { - return compareNewIssueCount(o1, o2); - } else { - return compareByRuleSeverityAndName(o1, o2); - } - } else { - return compareNewIssueCount(o1, o2); - } - } - - private static int compareByRuleSeverityAndName(RuleReport o1, RuleReport o2) { - return o1.getReportRuleKey().compareTo(o2.getReportRuleKey()); - } - - private static boolean sameNewIssueCount(RuleReport o1, RuleReport o2) { - return o2.getTotal().getNewIssuesCount() == o1.getTotal().getNewIssuesCount(); - } - - private static boolean sameSeverity(RuleReport o1, RuleReport o2) { - return o1.getSeverity().equals(o2.getSeverity()); - } - - private static int compareNewIssueCount(RuleReport o1, RuleReport o2) { - return o2.getTotal().getNewIssuesCount() - o1.getTotal().getNewIssuesCount(); - } - - private static boolean bothHaveNewIssues(RuleReport o1, RuleReport o2) { - return o1.getTotal().getNewIssuesCount() > 0 && o2.getTotal().getNewIssuesCount() > 0; - } - - private static boolean bothHaveNoNewIssue(RuleReport o1, RuleReport o2) { - return o1.getTotal().getNewIssuesCount() == 0 && o2.getTotal().getNewIssuesCount() == 0; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/SourceProvider.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/SourceProvider.java deleted file mode 100644 index 8017dbd753e..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/SourceProvider.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.report; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang.StringEscapeUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.batch.fs.FileSystem; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.batch.index.BatchComponent; - -@BatchSide -public class SourceProvider { - - private static final Logger LOG = LoggerFactory.getLogger(SourceProvider.class); - private final FileSystem fs; - - public SourceProvider(FileSystem fs) { - this.fs = fs; - } - - public List getEscapedSource(BatchComponent component) { - if (!component.isFile()) { - // Folder - return Collections.emptyList(); - } - try { - InputFile inputFile = (InputFile) component.inputComponent(); - List lines = FileUtils.readLines(inputFile.file(), fs.encoding()); - List escapedLines = new ArrayList<>(lines.size()); - for (String line : lines) { - escapedLines.add(StringEscapeUtils.escapeHtml(line)); - } - return escapedLines; - } catch (IOException e) { - LOG.warn("Unable to read source code of resource {}", component, e); - return Collections.emptyList(); - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/package-info.java deleted file mode 100644 index d6dacad1b54..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.batch.scan.report; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-batch/src/main/java/org/sonar/batch/scm/DefaultBlameInput.java b/sonar-batch/src/main/java/org/sonar/batch/scm/DefaultBlameInput.java deleted file mode 100644 index a85c6536c92..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scm/DefaultBlameInput.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scm; - -import org.sonar.api.batch.fs.FileSystem; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.scm.BlameCommand.BlameInput; - -class DefaultBlameInput implements BlameInput { - - private FileSystem fs; - private Iterable filesToBlame; - - DefaultBlameInput(FileSystem fs, Iterable filesToBlame) { - this.fs = fs; - this.filesToBlame = filesToBlame; - } - - @Override - public FileSystem fileSystem() { - return fs; - } - - @Override - public Iterable filesToBlame() { - return filesToBlame; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scm/DefaultBlameOutput.java b/sonar-batch/src/main/java/org/sonar/batch/scm/DefaultBlameOutput.java deleted file mode 100644 index 9341e6fbe01..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scm/DefaultBlameOutput.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scm; - -import com.google.common.base.Preconditions; -import java.text.Normalizer; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.TimeUnit; -import java.util.regex.Pattern; -import javax.annotation.Nullable; -import org.apache.commons.lang.StringUtils; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.scm.BlameCommand.BlameOutput; -import org.sonar.api.batch.scm.BlameLine; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; -import org.sonar.batch.index.BatchComponent; -import org.sonar.batch.index.BatchComponentCache; -import org.sonar.batch.protocol.output.BatchReport; -import org.sonar.batch.protocol.output.BatchReport.Changesets.Builder; -import org.sonar.batch.protocol.output.BatchReportWriter; -import org.sonar.batch.util.ProgressReport; - -class DefaultBlameOutput implements BlameOutput { - - private static final Logger LOG = Loggers.get(DefaultBlameOutput.class); - - private static final Pattern NON_ASCII_CHARS = Pattern.compile("[^\\x00-\\x7F]"); - private static final Pattern ACCENT_CODES = Pattern.compile("\\p{InCombiningDiacriticalMarks}+"); - - private final BatchReportWriter writer; - private final BatchComponentCache componentCache; - private final Set allFilesToBlame = new HashSet<>(); - private ProgressReport progressReport; - private int count; - private int total; - - DefaultBlameOutput(BatchReportWriter writer, BatchComponentCache componentCache, List filesToBlame) { - this.writer = writer; - this.componentCache = componentCache; - this.allFilesToBlame.addAll(filesToBlame); - count = 0; - total = filesToBlame.size(); - progressReport = new ProgressReport("Report about progress of SCM blame", TimeUnit.SECONDS.toMillis(10)); - progressReport.start(total + " files to be analyzed"); - } - - @Override - public synchronized void blameResult(InputFile file, List lines) { - Preconditions.checkNotNull(file); - Preconditions.checkNotNull(lines); - Preconditions.checkArgument(allFilesToBlame.contains(file), "It was not expected to blame file %s", file.relativePath()); - - if (lines.size() != file.lines()) { - LOG.debug("Ignoring blame result since provider returned {} blame lines but file {} has {} lines", lines.size(), file.relativePath(), file.lines()); - return; - } - - BatchComponent batchComponent = componentCache.get(file); - Builder scmBuilder = BatchReport.Changesets.newBuilder(); - scmBuilder.setComponentRef(batchComponent.batchId()); - Map changesetsIdByRevision = new HashMap<>(); - - int lineId = 1; - for (BlameLine line : lines) { - validateLine(line, lineId, file); - Integer changesetId = changesetsIdByRevision.get(line.revision()); - if (changesetId == null) { - addChangeset(scmBuilder, line); - changesetId = scmBuilder.getChangesetCount() - 1; - changesetsIdByRevision.put(line.revision(), changesetId); - } - scmBuilder.addChangesetIndexByLine(changesetId); - lineId++; - } - writer.writeComponentChangesets(scmBuilder.build()); - allFilesToBlame.remove(file); - count++; - progressReport.message(count + "/" + total + " files analyzed"); - } - - private static void validateLine(BlameLine line, int lineId, InputFile file) { - Preconditions.checkArgument(StringUtils.isNotBlank(line.revision()), "Blame revision is blank for file %s at line %s", file.relativePath(), lineId); - Preconditions.checkArgument(line.date() != null, "Blame date is null for file %s at line %s", file.relativePath(), lineId); - } - - private static void addChangeset(Builder scmBuilder, BlameLine line) { - BatchReport.Changesets.Changeset.Builder changesetBuilder = BatchReport.Changesets.Changeset.newBuilder(); - changesetBuilder.setRevision(line.revision()); - changesetBuilder.setDate(line.date().getTime()); - if (StringUtils.isNotBlank(line.author())) { - changesetBuilder.setAuthor(normalizeString(line.author())); - } - - scmBuilder.addChangeset(changesetBuilder.build()); - } - - private static String normalizeString(@Nullable String inputString) { - if (inputString == null) { - return ""; - } - String lowerCasedString = inputString.toLowerCase(); - String stringWithoutAccents = removeAccents(lowerCasedString); - return removeNonAsciiCharacters(stringWithoutAccents); - } - - private static String removeAccents(String inputString) { - String unicodeDecomposedString = Normalizer.normalize(inputString, Normalizer.Form.NFD); - return ACCENT_CODES.matcher(unicodeDecomposedString).replaceAll(""); - } - - private static String removeNonAsciiCharacters(String inputString) { - return NON_ASCII_CHARS.matcher(inputString).replaceAll("_"); - } - - public void finish() { - progressReport.stop(count + "/" + total + " files analyzed"); - if (!allFilesToBlame.isEmpty()) { - LOG.warn("Missing blame information for the following files:"); - for (InputFile f : allFilesToBlame) { - LOG.warn(" * " + f.absolutePath()); - } - LOG.warn("This may lead to missing/broken features in SonarQube"); - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scm/ScmConfiguration.java b/sonar-batch/src/main/java/org/sonar/batch/scm/ScmConfiguration.java deleted file mode 100644 index f6a88bf4465..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scm/ScmConfiguration.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scm; - -import com.google.common.base.Joiner; -import java.util.LinkedHashMap; -import java.util.Map; -import org.apache.commons.lang.StringUtils; -import org.picocontainer.Startable; -import org.sonar.api.CoreProperties; -import org.sonar.api.Properties; -import org.sonar.api.Property; -import org.sonar.api.PropertyType; -import org.sonar.api.batch.AnalysisMode; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.batch.InstantiationStrategy; -import org.sonar.api.batch.scm.ScmProvider; -import org.sonar.api.config.Settings; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; -import org.sonar.batch.scan.ImmutableProjectReactor; - -@Properties({ - @Property( - key = ScmConfiguration.FORCE_RELOAD_KEY, - defaultValue = "false", - name = "Force reloading of SCM information for all files", - description = "By default only files modified since previous analysis are inspected. Set this parameter to true to force the reloading.", - category = CoreProperties.CATEGORY_SCM, - project = false, - module = false, - global = false, - type = PropertyType.BOOLEAN) -}) -@InstantiationStrategy(InstantiationStrategy.PER_BATCH) -@BatchSide -public final class ScmConfiguration implements Startable { - private static final Logger LOG = Loggers.get(ScmConfiguration.class); - - public static final String FORCE_RELOAD_KEY = "sonar.scm.forceReloadAll"; - - private final ImmutableProjectReactor projectReactor; - private final Settings settings; - private final Map providerPerKey = new LinkedHashMap<>(); - private final AnalysisMode analysisMode; - - private ScmProvider provider; - - public ScmConfiguration(ImmutableProjectReactor projectReactor, AnalysisMode analysisMode, Settings settings, ScmProvider... providers) { - this.projectReactor = projectReactor; - this.analysisMode = analysisMode; - this.settings = settings; - for (ScmProvider scmProvider : providers) { - providerPerKey.put(scmProvider.key(), scmProvider); - } - } - - public ScmConfiguration(ImmutableProjectReactor projectReactor, AnalysisMode analysisMode, Settings settings) { - this(projectReactor, analysisMode, settings, new ScmProvider[0]); - } - - @Override - public void start() { - if (analysisMode.isIssues()) { - return; - } - if (isDisabled()) { - LOG.debug("SCM Step is disabled by configuration"); - return; - } - if (settings.hasKey(CoreProperties.SCM_PROVIDER_KEY)) { - String forcedProviderKey = settings.getString(CoreProperties.SCM_PROVIDER_KEY); - setProviderIfSupported(forcedProviderKey); - } else { - autodetection(); - if (this.provider == null) { - considerOldScmUrl(); - } - if (this.provider == null) { - LOG.warn("SCM provider autodetection failed. No SCM provider claims to support this project. Please use " + CoreProperties.SCM_PROVIDER_KEY - + " to define SCM of your project."); - } - } - } - - private void setProviderIfSupported(String forcedProviderKey) { - if (providerPerKey.containsKey(forcedProviderKey)) { - this.provider = providerPerKey.get(forcedProviderKey); - } else { - String supportedProviders = providerPerKey.isEmpty() ? "No SCM provider installed" : ("Supported SCM providers are " + Joiner.on(",").join(providerPerKey.keySet())); - throw new IllegalArgumentException("SCM provider was set to \"" + forcedProviderKey + "\" but no SCM provider found for this key. " + supportedProviders); - } - } - - private void considerOldScmUrl() { - if (settings.hasKey(CoreProperties.LINKS_SOURCES_DEV)) { - String url = settings.getString(CoreProperties.LINKS_SOURCES_DEV); - if (StringUtils.startsWith(url, "scm:")) { - String[] split = url.split(":"); - if (split.length > 1) { - setProviderIfSupported(split[1]); - } - } - } - - } - - private void autodetection() { - for (ScmProvider installedProvider : providerPerKey.values()) { - if (installedProvider.supports(projectReactor.getRoot().getBaseDir())) { - if (this.provider == null) { - this.provider = installedProvider; - } else { - throw new IllegalStateException("SCM provider autodetection failed. Both " + this.provider.key() + " and " + installedProvider.key() - + " claim to support this project. Please use " + CoreProperties.SCM_PROVIDER_KEY + " to define SCM of your project."); - } - } - } - } - - public ScmProvider provider() { - return provider; - } - - public boolean isDisabled() { - return settings.getBoolean(CoreProperties.SCM_DISABLED_KEY); - } - - public boolean forceReloadAll() { - return settings.getBoolean(FORCE_RELOAD_KEY); - } - - @Override - public void stop() { - // Nothing to do - } - -} 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 deleted file mode 100644 index 078224bb6c6..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scm; - -import java.util.LinkedList; -import java.util.List; -import org.apache.commons.lang.StringUtils; -import org.sonar.api.CoreProperties; -import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.api.batch.fs.FileSystem; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.InputFile.Status; -import org.sonar.api.batch.sensor.Sensor; -import org.sonar.api.batch.sensor.SensorContext; -import org.sonar.api.batch.sensor.SensorDescriptor; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; -import org.sonar.batch.index.BatchComponentCache; -import org.sonar.batch.report.ReportPublisher; -import org.sonar.batch.repository.FileData; -import org.sonar.batch.repository.ProjectRepositories; - -public final class ScmSensor implements Sensor { - - private static final Logger LOG = Loggers.get(ScmSensor.class); - - private final ProjectDefinition projectDefinition; - private final ScmConfiguration configuration; - private final FileSystem fs; - private final ProjectRepositories projectRepositories; - private final BatchComponentCache resourceCache; - private final ReportPublisher publishReportJob; - - public ScmSensor(ProjectDefinition projectDefinition, ScmConfiguration configuration, - ProjectRepositories projectRepositories, FileSystem fs, BatchComponentCache resourceCache, ReportPublisher publishReportJob) { - this.projectDefinition = projectDefinition; - this.configuration = configuration; - this.projectRepositories = projectRepositories; - this.fs = fs; - this.resourceCache = resourceCache; - this.publishReportJob = publishReportJob; - } - - @Override - public void describe(SensorDescriptor descriptor) { - descriptor.name("SCM Sensor"); - } - - @Override - public void execute(SensorContext context) { - if (configuration.isDisabled()) { - LOG.info("SCM Publisher is disabled"); - return; - } - if (configuration.provider() == null) { - LOG.info("No SCM system was detected. You can use the '" + CoreProperties.SCM_PROVIDER_KEY + "' property to explicitly specify it."); - return; - } - - List filesToBlame = collectFilesToBlame(); - if (!filesToBlame.isEmpty()) { - String key = configuration.provider().key(); - LOG.info("SCM provider for this project is: " + key); - DefaultBlameOutput output = new DefaultBlameOutput(publishReportJob.getWriter(), resourceCache, filesToBlame); - try { - configuration.provider().blameCommand().blame(new DefaultBlameInput(fs, filesToBlame), output); - } finally { - output.finish(); - } - } - } - - private List collectFilesToBlame() { - if (configuration.forceReloadAll()) { - LOG.warn("Forced reloading of SCM data for all files."); - } - List filesToBlame = new LinkedList<>(); - for (InputFile f : fs.inputFiles(fs.predicates().all())) { - if (configuration.forceReloadAll() || f.status() != Status.SAME) { - addIfNotEmpty(filesToBlame, f); - } else { - // File status is SAME so that mean fileData exists - FileData fileData = projectRepositories.fileData(projectDefinition.getKeyWithBranch(), f.relativePath()); - if (StringUtils.isEmpty(fileData.revision())) { - addIfNotEmpty(filesToBlame, f); - } - } - } - return filesToBlame; - } - - private static void addIfNotEmpty(List filesToBlame, InputFile f) { - if (!f.isEmpty()) { - filesToBlame.add(f); - } - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scm/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/scm/package-info.java deleted file mode 100644 index 925761a7298..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scm/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.batch.scm; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java b/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java deleted file mode 100644 index 1080dab084a..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.sensor; - -import java.io.Serializable; -import org.sonar.api.batch.AnalysisMode; -import org.sonar.api.batch.fs.FileSystem; -import org.sonar.api.batch.fs.InputModule; -import org.sonar.api.batch.rule.ActiveRules; -import org.sonar.api.batch.sensor.SensorContext; -import org.sonar.api.batch.sensor.coverage.NewCoverage; -import org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage; -import org.sonar.api.batch.sensor.cpd.NewCpdTokens; -import org.sonar.api.batch.sensor.cpd.internal.DefaultCpdTokens; -import org.sonar.api.batch.sensor.highlighting.NewHighlighting; -import org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting; -import org.sonar.api.batch.sensor.internal.SensorStorage; -import org.sonar.api.batch.sensor.issue.NewIssue; -import org.sonar.api.batch.sensor.issue.internal.DefaultIssue; -import org.sonar.api.batch.sensor.measure.NewMeasure; -import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure; -import org.sonar.api.config.Settings; -import org.sonar.batch.sensor.noop.NoOpNewCpdTokens; -import org.sonar.batch.sensor.noop.NoOpNewHighlighting; - -public class DefaultSensorContext implements SensorContext { - - private static final NoOpNewHighlighting NO_OP_NEW_HIGHLIGHTING = new NoOpNewHighlighting(); - private static final NoOpNewCpdTokens NO_OP_NEW_CPD_TOKENS = new NoOpNewCpdTokens(); - - private final Settings settings; - private final FileSystem fs; - private final ActiveRules activeRules; - private final SensorStorage sensorStorage; - private final AnalysisMode analysisMode; - private final InputModule module; - - public DefaultSensorContext(InputModule module, Settings settings, FileSystem fs, ActiveRules activeRules, AnalysisMode analysisMode, SensorStorage sensorStorage) { - this.module = module; - this.settings = settings; - this.fs = fs; - this.activeRules = activeRules; - this.analysisMode = analysisMode; - this.sensorStorage = sensorStorage; - } - - @Override - public Settings settings() { - return settings; - } - - @Override - public FileSystem fileSystem() { - return fs; - } - - @Override - public ActiveRules activeRules() { - return activeRules; - } - - @Override - public InputModule module() { - return module; - } - - @Override - public NewMeasure newMeasure() { - return new DefaultMeasure<>(sensorStorage); - } - - @Override - public NewIssue newIssue() { - return new DefaultIssue(sensorStorage); - } - - @Override - public NewHighlighting newHighlighting() { - if (analysisMode.isIssues()) { - return NO_OP_NEW_HIGHLIGHTING; - } - return new DefaultHighlighting(sensorStorage); - } - - @Override - public NewCoverage newCoverage() { - return new DefaultCoverage(sensorStorage); - } - - @Override - public NewCpdTokens newCpdTokens() { - if (analysisMode.isIssues()) { - return NO_OP_NEW_CPD_TOKENS; - } - return new DefaultCpdTokens(sensorStorage); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java b/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java deleted file mode 100644 index 096a115d425..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java +++ /dev/null @@ -1,285 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.sensor; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Function; -import com.google.common.collect.Iterables; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.Set; -import javax.annotation.Nonnull; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.batch.fs.FileSystem; -import org.sonar.api.batch.fs.InputComponent; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.TextRange; -import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.batch.measure.MetricFinder; -import org.sonar.api.batch.rule.ActiveRules; -import org.sonar.api.batch.sensor.coverage.CoverageType; -import org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage; -import org.sonar.api.batch.sensor.cpd.internal.DefaultCpdTokens; -import org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting; -import org.sonar.api.batch.sensor.highlighting.internal.SyntaxHighlightingRule; -import org.sonar.api.batch.sensor.internal.SensorStorage; -import org.sonar.api.batch.sensor.issue.Issue; -import org.sonar.api.batch.sensor.measure.Measure; -import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure; -import org.sonar.api.config.Settings; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.Metric; -import org.sonar.api.resources.File; -import org.sonar.api.resources.Resource; -import org.sonar.api.source.Symbol; -import org.sonar.api.utils.KeyValueFormat; -import org.sonar.api.utils.SonarException; -import org.sonar.batch.cpd.DefaultCpdBlockIndexer; -import org.sonar.batch.cpd.index.SonarCpdBlockIndex; -import org.sonar.batch.index.BatchComponent; -import org.sonar.batch.index.BatchComponentCache; -import org.sonar.batch.issue.ModuleIssues; -import org.sonar.batch.protocol.output.BatchReport; -import org.sonar.batch.protocol.output.BatchReportWriter; -import org.sonar.batch.report.BatchReportUtils; -import org.sonar.batch.report.ReportPublisher; -import org.sonar.batch.scan.measure.MeasureCache; -import org.sonar.batch.sensor.coverage.CoverageExclusions; -import org.sonar.batch.source.DefaultSymbol; -import org.sonar.duplications.block.Block; -import org.sonar.duplications.internal.pmd.PmdBlockChunker; - -public class DefaultSensorStorage implements SensorStorage { - - private static final Logger LOG = LoggerFactory.getLogger(DefaultSensorStorage.class); - - private static final List INTERNAL_METRICS = Arrays.asList( - // Computed by LinesSensor - CoreMetrics.LINES); - - private static final List DEPRECATED_METRICS_KEYS = Arrays.asList( - CoreMetrics.DEPENDENCY_MATRIX_KEY, - CoreMetrics.DIRECTORY_CYCLES_KEY, - CoreMetrics.DIRECTORY_EDGES_WEIGHT_KEY, - CoreMetrics.DIRECTORY_FEEDBACK_EDGES_KEY, - CoreMetrics.DIRECTORY_TANGLE_INDEX_KEY, - CoreMetrics.DIRECTORY_TANGLES_KEY, - CoreMetrics.FILE_CYCLES_KEY, - CoreMetrics.FILE_EDGES_WEIGHT_KEY, - CoreMetrics.FILE_FEEDBACK_EDGES_KEY, - CoreMetrics.FILE_TANGLE_INDEX_KEY, - CoreMetrics.FILE_TANGLES_KEY, - CoreMetrics.DUPLICATIONS_DATA_KEY); - - private final MetricFinder metricFinder; - private final ModuleIssues moduleIssues; - private final CoverageExclusions coverageExclusions; - private final BatchComponentCache componentCache; - private final ReportPublisher reportPublisher; - private final MeasureCache measureCache; - private final SonarCpdBlockIndex index; - private final Settings settings; - - public DefaultSensorStorage(MetricFinder metricFinder, ModuleIssues moduleIssues, - Settings settings, FileSystem fs, ActiveRules activeRules, - CoverageExclusions coverageExclusions, BatchComponentCache componentCache, ReportPublisher reportPublisher, MeasureCache measureCache, SonarCpdBlockIndex index) { - this.metricFinder = metricFinder; - this.moduleIssues = moduleIssues; - this.settings = settings; - this.coverageExclusions = coverageExclusions; - this.componentCache = componentCache; - this.reportPublisher = reportPublisher; - this.measureCache = measureCache; - this.index = index; - } - - private Metric findMetricOrFail(String metricKey) { - Metric m = (Metric) metricFinder.findByKey(metricKey); - if (m == null) { - throw new IllegalStateException("Unknow metric with key: " + metricKey); - } - return m; - } - - @Override - public void store(Measure newMeasure) { - DefaultMeasure measure = (DefaultMeasure) newMeasure; - org.sonar.api.measures.Metric m = findMetricOrFail(measure.metric().key()); - org.sonar.api.measures.Measure measureToSave = new org.sonar.api.measures.Measure(m); - setValueAccordingToMetricType(newMeasure, m, measureToSave); - measureToSave.setFromCore(measure.isFromCore()); - InputComponent inputComponent = newMeasure.inputComponent(); - Resource resource = componentCache.get(inputComponent).resource(); - if (coverageExclusions.accept(resource, measureToSave)) { - saveMeasure(resource, measureToSave); - } - } - - public org.sonar.api.measures.Measure saveMeasure(Resource resource, org.sonar.api.measures.Measure measure) { - if (DEPRECATED_METRICS_KEYS.contains(measure.getMetricKey())) { - // Ignore deprecated metrics - return null; - } - org.sonar.api.batch.measure.Metric metric = metricFinder.findByKey(measure.getMetricKey()); - if (metric == null) { - throw new SonarException("Unknown metric: " + measure.getMetricKey()); - } - if (!measure.isFromCore() && INTERNAL_METRICS.contains(metric)) { - LOG.debug("Metric " + metric.key() + " is an internal metric computed by SonarQube. Provided value is ignored."); - return measure; - } - if (measureCache.contains(resource, measure)) { - throw new SonarException("Can not add the same measure twice on " + resource + ": " + measure); - } - measureCache.put(resource, measure); - return measure; - } - - private void setValueAccordingToMetricType(Measure measure, org.sonar.api.measures.Metric m, org.sonar.api.measures.Measure measureToSave) { - switch (m.getType()) { - case BOOL: - measureToSave.setValue(Boolean.TRUE.equals(measure.value()) ? 1.0 : 0.0); - break; - case INT: - case MILLISEC: - case WORK_DUR: - case FLOAT: - case PERCENT: - case RATING: - measureToSave.setValue(((Number) measure.value()).doubleValue()); - break; - case STRING: - case LEVEL: - case DATA: - case DISTRIB: - measureToSave.setData((String) measure.value()); - break; - default: - throw new UnsupportedOperationException("Unsupported type :" + m.getType()); - } - } - - @Override - public void store(Issue issue) { - moduleIssues.initAndAddIssue(issue); - } - - private File getFile(InputFile file) { - BatchComponent r = componentCache.get(file); - if (r == null) { - throw new IllegalStateException("Provided input file is not indexed"); - } - return (File) r.resource(); - } - - @Override - public void store(DefaultHighlighting highlighting) { - BatchReportWriter writer = reportPublisher.getWriter(); - DefaultInputFile inputFile = (DefaultInputFile) highlighting.inputFile(); - writer.writeComponentSyntaxHighlighting(componentCache.get(inputFile).batchId(), - Iterables.transform(highlighting.getSyntaxHighlightingRuleSet(), new BuildSyntaxHighlighting())); - } - - public void store(DefaultInputFile inputFile, Map> referencesBySymbol) { - BatchReportWriter writer = reportPublisher.getWriter(); - writer.writeComponentSymbols(componentCache.get(inputFile).batchId(), - Iterables.transform(referencesBySymbol.entrySet(), new Function>, BatchReport.Symbol>() { - private BatchReport.Symbol.Builder builder = BatchReport.Symbol.newBuilder(); - private BatchReport.TextRange.Builder rangeBuilder = BatchReport.TextRange.newBuilder(); - - @Override - public BatchReport.Symbol apply(Map.Entry> input) { - builder.clear(); - rangeBuilder.clear(); - DefaultSymbol symbol = (DefaultSymbol) input.getKey(); - builder.setDeclaration(rangeBuilder.setStartLine(symbol.range().start().line()) - .setStartOffset(symbol.range().start().lineOffset()) - .setEndLine(symbol.range().end().line()) - .setEndOffset(symbol.range().end().lineOffset()) - .build()); - for (TextRange reference : input.getValue()) { - builder.addReference(rangeBuilder.setStartLine(reference.start().line()) - .setStartOffset(reference.start().lineOffset()) - .setEndLine(reference.end().line()) - .setEndOffset(reference.end().lineOffset()) - .build()); - } - return builder.build(); - } - - })); - } - - @Override - public void store(DefaultCoverage defaultCoverage) { - File file = getFile(defaultCoverage.inputFile()); - if (coverageExclusions.hasMatchingPattern(file)) { - return; - } - CoverageType type = defaultCoverage.type(); - if (defaultCoverage.linesToCover() > 0) { - saveMeasure(file, new org.sonar.api.measures.Measure(type.linesToCover(), (double) defaultCoverage.linesToCover())); - saveMeasure(file, new org.sonar.api.measures.Measure(type.uncoveredLines(), (double) (defaultCoverage.linesToCover() - defaultCoverage.coveredLines()))); - saveMeasure(file, new org.sonar.api.measures.Measure(type.lineHitsData()).setData(KeyValueFormat.format(defaultCoverage.hitsByLine()))); - } - if (defaultCoverage.conditions() > 0) { - saveMeasure(file, new org.sonar.api.measures.Measure(type.conditionsToCover(), (double) defaultCoverage.conditions())); - saveMeasure(file, new org.sonar.api.measures.Measure(type.uncoveredConditions(), (double) (defaultCoverage.conditions() - defaultCoverage.coveredConditions()))); - saveMeasure(file, new org.sonar.api.measures.Measure(type.coveredConditionsByLine()).setData(KeyValueFormat.format(defaultCoverage.coveredConditionsByLine()))); - saveMeasure(file, new org.sonar.api.measures.Measure(type.conditionsByLine()).setData(KeyValueFormat.format(defaultCoverage.conditionsByLine()))); - } - } - - private static class BuildSyntaxHighlighting implements Function { - private BatchReport.SyntaxHighlighting.Builder builder = BatchReport.SyntaxHighlighting.newBuilder(); - private BatchReport.TextRange.Builder rangeBuilder = BatchReport.TextRange.newBuilder(); - - @Override - public BatchReport.SyntaxHighlighting apply(@Nonnull SyntaxHighlightingRule input) { - builder.setRange(rangeBuilder.setStartLine(input.range().start().line()) - .setStartOffset(input.range().start().lineOffset()) - .setEndLine(input.range().end().line()) - .setEndOffset(input.range().end().lineOffset()) - .build()); - builder.setType(BatchReportUtils.toProtocolType(input.getTextType())); - return builder.build(); - } - } - - @Override - public void store(DefaultCpdTokens defaultCpdTokens) { - InputFile inputFile = defaultCpdTokens.inputFile(); - PmdBlockChunker blockChunker = new PmdBlockChunker(getBlockSize(inputFile.language())); - List blocks = blockChunker.chunk(inputFile.key(), defaultCpdTokens.getTokenLines()); - index.insert(inputFile, blocks); - } - - @VisibleForTesting - int getBlockSize(String languageKey) { - int blockSize = settings.getInt("sonar.cpd." + languageKey + ".minimumLines"); - if (blockSize == 0) { - blockSize = DefaultCpdBlockIndexer.getDefaultBlockSize(languageKey); - } - return blockSize; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/sensor/SensorOptimizer.java b/sonar-batch/src/main/java/org/sonar/batch/sensor/SensorOptimizer.java deleted file mode 100644 index 7e8dd63e93a..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/sensor/SensorOptimizer.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.sensor; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.batch.fs.FilePredicate; -import org.sonar.api.batch.fs.FileSystem; -import org.sonar.api.batch.rule.ActiveRules; -import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor; -import org.sonar.api.config.Settings; - -@BatchSide -public class SensorOptimizer { - - private static final Logger LOG = LoggerFactory.getLogger(SensorOptimizer.class); - - private final FileSystem fs; - private final ActiveRules activeRules; - private final Settings settings; - - public SensorOptimizer(FileSystem fs, ActiveRules activeRules, Settings settings) { - this.fs = fs; - this.activeRules = activeRules; - this.settings = settings; - } - - /** - * Decide if the given Sensor should be executed. - */ - public boolean shouldExecute(DefaultSensorDescriptor descriptor) { - if (!fsCondition(descriptor)) { - LOG.debug("'{}' skipped because there is no related file in current project", descriptor.name()); - return false; - } - if (!activeRulesCondition(descriptor)) { - LOG.debug("'{}' skipped because there is no related rule activated in the quality profile", descriptor.name()); - return false; - } - if (!settingsCondition(descriptor)) { - LOG.debug("'{}' skipped because one of the required properties is missing", descriptor.name()); - return false; - } - return true; - } - - private boolean settingsCondition(DefaultSensorDescriptor descriptor) { - if (!descriptor.properties().isEmpty()) { - for (String propertyKey : descriptor.properties()) { - if (!settings.hasKey(propertyKey)) { - return false; - } - } - } - return true; - } - - private boolean activeRulesCondition(DefaultSensorDescriptor descriptor) { - if (!descriptor.ruleRepositories().isEmpty()) { - for (String repoKey : descriptor.ruleRepositories()) { - if (!activeRules.findByRepository(repoKey).isEmpty()) { - return true; - } - } - return false; - } - return true; - } - - private boolean fsCondition(DefaultSensorDescriptor descriptor) { - if (!descriptor.languages().isEmpty() || descriptor.type() != null) { - FilePredicate langPredicate = descriptor.languages().isEmpty() ? fs.predicates().all() : fs.predicates().hasLanguages(descriptor.languages()); - - FilePredicate typePredicate = descriptor.type() == null ? fs.predicates().all() : fs.predicates().hasType(descriptor.type()); - return fs.hasFiles(fs.predicates().and(langPredicate, typePredicate)); - } - return true; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/sensor/SensorWrapper.java b/sonar-batch/src/main/java/org/sonar/batch/sensor/SensorWrapper.java deleted file mode 100644 index 3e82a222546..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/sensor/SensorWrapper.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.sensor; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.batch.sensor.Sensor; -import org.sonar.api.batch.sensor.SensorContext; -import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor; -import org.sonar.api.resources.Project; - -public class SensorWrapper implements org.sonar.api.batch.Sensor { - - private static final Logger LOG = LoggerFactory.getLogger(SensorWrapper.class); - - private Sensor wrappedSensor; - private SensorContext adaptor; - private DefaultSensorDescriptor descriptor; - private SensorOptimizer optimizer; - - public SensorWrapper(Sensor newSensor, SensorContext adaptor, SensorOptimizer optimizer) { - this.wrappedSensor = newSensor; - this.optimizer = optimizer; - descriptor = new DefaultSensorDescriptor(); - newSensor.describe(descriptor); - this.adaptor = adaptor; - } - - public Sensor wrappedSensor() { - return wrappedSensor; - } - - @Override - public boolean shouldExecuteOnProject(Project project) { - return optimizer.shouldExecute(descriptor); - } - - @Override - public void analyse(Project module, org.sonar.api.batch.SensorContext context) { - wrappedSensor.execute(adaptor); - } - - @Override - public String toString() { - return descriptor.name() + (LOG.isDebugEnabled() ? " (wrapped)" : ""); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/sensor/coverage/CoverageConstants.java b/sonar-batch/src/main/java/org/sonar/batch/sensor/coverage/CoverageConstants.java deleted file mode 100644 index 569ac157e42..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/sensor/coverage/CoverageConstants.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.sensor.coverage; - -import com.google.common.collect.ImmutableList; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.Metric; - -import java.util.Collection; - -public class CoverageConstants { - - public static final Collection COVERAGE_METRICS = ImmutableList.of(CoreMetrics.LINES_TO_COVER, CoreMetrics.UNCOVERED_LINES, CoreMetrics.NEW_LINES_TO_COVER, - CoreMetrics.NEW_UNCOVERED_LINES, CoreMetrics.CONDITIONS_TO_COVER, CoreMetrics.UNCOVERED_CONDITIONS, - CoreMetrics.NEW_CONDITIONS_TO_COVER, CoreMetrics.NEW_UNCOVERED_CONDITIONS); - - public static final Collection LINE_COVERAGE_METRICS = ImmutableList.of(CoreMetrics.UNCOVERED_LINES, CoreMetrics.LINES_TO_COVER, CoreMetrics.NEW_UNCOVERED_LINES, - CoreMetrics.NEW_LINES_TO_COVER); - - public static final Collection BRANCH_COVERAGE_METRICS = ImmutableList.of(CoreMetrics.UNCOVERED_CONDITIONS, CoreMetrics.CONDITIONS_TO_COVER, - CoreMetrics.NEW_UNCOVERED_CONDITIONS, CoreMetrics.NEW_CONDITIONS_TO_COVER); - - private CoverageConstants() { - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/sensor/coverage/CoverageExclusions.java b/sonar-batch/src/main/java/org/sonar/batch/sensor/coverage/CoverageExclusions.java deleted file mode 100644 index 198b61141bb..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/sensor/coverage/CoverageExclusions.java +++ /dev/null @@ -1,210 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.sensor.coverage; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableList.Builder; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; -import javax.annotation.CheckForNull; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.CoreProperties; -import org.sonar.api.batch.fs.FileSystem; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.config.Settings; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.Measure; -import org.sonar.api.measures.Metric; -import org.sonar.api.resources.Resource; -import org.sonar.api.utils.KeyValueFormat; -import org.sonar.api.utils.WildcardPattern; - -public class CoverageExclusions { - - private static final Logger LOG = LoggerFactory.getLogger(CoverageExclusions.class); - - private final Settings settings; - private final Set coverageMetrics; - private final Set byLineMetrics; - private Collection resourcePatterns; - - private final FileSystem fs; - - public CoverageExclusions(Settings settings, FileSystem fs) { - this.settings = settings; - this.fs = fs; - this.coverageMetrics = new HashSet<>(); - this.byLineMetrics = new HashSet<>(); - // UT - coverageMetrics.add(CoreMetrics.COVERAGE); - coverageMetrics.add(CoreMetrics.LINE_COVERAGE); - coverageMetrics.add(CoreMetrics.BRANCH_COVERAGE); - coverageMetrics.add(CoreMetrics.UNCOVERED_LINES); - coverageMetrics.add(CoreMetrics.LINES_TO_COVER); - coverageMetrics.add(CoreMetrics.UNCOVERED_CONDITIONS); - coverageMetrics.add(CoreMetrics.CONDITIONS_TO_COVER); - coverageMetrics.add(CoreMetrics.CONDITIONS_BY_LINE); - coverageMetrics.add(CoreMetrics.COVERED_CONDITIONS_BY_LINE); - coverageMetrics.add(CoreMetrics.COVERAGE_LINE_HITS_DATA); - coverageMetrics.add(CoreMetrics.NEW_LINES_TO_COVER); - coverageMetrics.add(CoreMetrics.NEW_UNCOVERED_LINES); - coverageMetrics.add(CoreMetrics.NEW_UNCOVERED_CONDITIONS); - // IT - coverageMetrics.add(CoreMetrics.IT_COVERAGE); - coverageMetrics.add(CoreMetrics.IT_LINE_COVERAGE); - coverageMetrics.add(CoreMetrics.IT_BRANCH_COVERAGE); - coverageMetrics.add(CoreMetrics.IT_UNCOVERED_LINES); - coverageMetrics.add(CoreMetrics.IT_LINES_TO_COVER); - coverageMetrics.add(CoreMetrics.IT_UNCOVERED_CONDITIONS); - coverageMetrics.add(CoreMetrics.IT_CONDITIONS_TO_COVER); - coverageMetrics.add(CoreMetrics.IT_CONDITIONS_BY_LINE); - coverageMetrics.add(CoreMetrics.IT_COVERED_CONDITIONS_BY_LINE); - coverageMetrics.add(CoreMetrics.IT_COVERAGE_LINE_HITS_DATA); - coverageMetrics.add(CoreMetrics.NEW_IT_LINES_TO_COVER); - coverageMetrics.add(CoreMetrics.NEW_IT_UNCOVERED_LINES); - coverageMetrics.add(CoreMetrics.NEW_IT_UNCOVERED_CONDITIONS); - // OVERALL - coverageMetrics.add(CoreMetrics.OVERALL_COVERAGE); - coverageMetrics.add(CoreMetrics.OVERALL_LINE_COVERAGE); - coverageMetrics.add(CoreMetrics.OVERALL_BRANCH_COVERAGE); - coverageMetrics.add(CoreMetrics.OVERALL_UNCOVERED_LINES); - coverageMetrics.add(CoreMetrics.OVERALL_LINES_TO_COVER); - coverageMetrics.add(CoreMetrics.OVERALL_UNCOVERED_CONDITIONS); - coverageMetrics.add(CoreMetrics.OVERALL_CONDITIONS_TO_COVER); - coverageMetrics.add(CoreMetrics.OVERALL_CONDITIONS_BY_LINE); - coverageMetrics.add(CoreMetrics.OVERALL_COVERED_CONDITIONS_BY_LINE); - coverageMetrics.add(CoreMetrics.OVERALL_COVERAGE_LINE_HITS_DATA); - coverageMetrics.add(CoreMetrics.NEW_OVERALL_LINES_TO_COVER); - coverageMetrics.add(CoreMetrics.NEW_OVERALL_UNCOVERED_LINES); - coverageMetrics.add(CoreMetrics.NEW_OVERALL_UNCOVERED_CONDITIONS); - - byLineMetrics.add(CoreMetrics.OVERALL_COVERAGE_LINE_HITS_DATA); - byLineMetrics.add(CoreMetrics.OVERALL_CONDITIONS_BY_LINE); - byLineMetrics.add(CoreMetrics.OVERALL_COVERED_CONDITIONS_BY_LINE); - byLineMetrics.add(CoreMetrics.COVERAGE_LINE_HITS_DATA); - byLineMetrics.add(CoreMetrics.COVERED_CONDITIONS_BY_LINE); - byLineMetrics.add(CoreMetrics.CONDITIONS_BY_LINE); - byLineMetrics.add(CoreMetrics.IT_COVERAGE_LINE_HITS_DATA); - byLineMetrics.add(CoreMetrics.IT_CONDITIONS_BY_LINE); - byLineMetrics.add(CoreMetrics.IT_COVERED_CONDITIONS_BY_LINE); - - initPatterns(); - } - - private boolean isLineMetrics(Metric metric) { - return this.byLineMetrics.contains(metric); - } - - public void validate(Measure measure, InputFile inputFile) { - Metric metric = measure.getMetric(); - - if (!isLineMetrics(metric)) { - return; - } - - Map m = KeyValueFormat.parseIntInt(measure.getData()); - validatePositiveLine(m, inputFile.absolutePath()); - validateMaxLine(m, inputFile); - } - - @CheckForNull - private InputFile getInputFile(String filePath) { - return fs.inputFile(fs.predicates().hasRelativePath(filePath)); - } - - public void validate(Measure measure, String filePath) { - Metric metric = measure.getMetric(); - - if (!isLineMetrics(metric)) { - return; - } - - InputFile inputFile = getInputFile(filePath); - - if (inputFile == null) { - throw new IllegalStateException(String.format("Can't create measure for resource '%s': resource is not indexed as a file", filePath)); - } - - validate(measure, inputFile); - } - - private static void validateMaxLine(Map m, InputFile inputFile) { - int maxLine = inputFile.lines(); - - for (int l : m.keySet()) { - if (l > maxLine) { - throw new IllegalStateException(String.format("Can't create measure for line %d for file '%s' with %d lines", l, inputFile.absolutePath(), maxLine)); - } - } - } - - private static void validatePositiveLine(Map m, String filePath) { - for (int l : m.keySet()) { - if (l <= 0) { - throw new IllegalStateException(String.format("Measure with line %d for file '%s' must be > 0", l, filePath)); - } - } - } - - public boolean accept(Resource resource, Measure measure) { - if (isCoverageMetric(measure.getMetric())) { - return !hasMatchingPattern(resource); - } else { - return true; - } - } - - private boolean isCoverageMetric(Metric metric) { - return this.coverageMetrics.contains(metric); - } - - public boolean hasMatchingPattern(Resource resource) { - boolean found = false; - Iterator iterator = resourcePatterns.iterator(); - while (!found && iterator.hasNext()) { - found = resource.matchFilePattern(iterator.next().toString()); - } - return found; - } - - @VisibleForTesting - final void initPatterns() { - Builder builder = ImmutableList.builder(); - for (String pattern : settings.getStringArray(CoreProperties.PROJECT_COVERAGE_EXCLUSIONS_PROPERTY)) { - builder.add(WildcardPattern.create(pattern)); - } - resourcePatterns = builder.build(); - log("Excluded sources for coverage: ", resourcePatterns); - } - - private static void log(String title, Collection patterns) { - if (!patterns.isEmpty()) { - LOG.info(title); - for (WildcardPattern pattern : patterns) { - LOG.info(" " + pattern); - } - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/sensor/coverage/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/sensor/coverage/package-info.java deleted file mode 100644 index b4c6be3d144..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/sensor/coverage/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@javax.annotation.ParametersAreNonnullByDefault -package org.sonar.batch.sensor.coverage; diff --git a/sonar-batch/src/main/java/org/sonar/batch/sensor/noop/NoOpNewCpdTokens.java b/sonar-batch/src/main/java/org/sonar/batch/sensor/noop/NoOpNewCpdTokens.java deleted file mode 100644 index afd00476b2a..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/sensor/noop/NoOpNewCpdTokens.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.sensor.noop; - -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.TextRange; -import org.sonar.api.batch.sensor.cpd.NewCpdTokens; - -public class NoOpNewCpdTokens implements NewCpdTokens { - @Override - public void save() { - // Do nothing - } - - @Override - public NoOpNewCpdTokens onFile(InputFile inputFile) { - // Do nothing - return this; - } - - @Override - public NewCpdTokens addToken(TextRange range, String image) { - // Do nothing - return this; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/sensor/noop/NoOpNewHighlighting.java b/sonar-batch/src/main/java/org/sonar/batch/sensor/noop/NoOpNewHighlighting.java deleted file mode 100644 index 7ead32f7f04..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/sensor/noop/NoOpNewHighlighting.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.sensor.noop; - -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.sensor.highlighting.NewHighlighting; -import org.sonar.api.batch.sensor.highlighting.TypeOfText; - -public class NoOpNewHighlighting implements NewHighlighting { - @Override - public void save() { - // Do nothing - } - - @Override - public NewHighlighting onFile(InputFile inputFile) { - // Do nothing - return this; - } - - @Override - public NewHighlighting highlight(int startOffset, int endOffset, TypeOfText typeOfText) { - // Do nothing - return this; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/sensor/noop/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/sensor/noop/package-info.java deleted file mode 100644 index 0a654a40800..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/sensor/noop/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@javax.annotation.ParametersAreNonnullByDefault -package org.sonar.batch.sensor.noop; diff --git a/sonar-batch/src/main/java/org/sonar/batch/sensor/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/sensor/package-info.java deleted file mode 100644 index 4c9f457a97f..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/sensor/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@javax.annotation.ParametersAreNonnullByDefault -package org.sonar.batch.sensor; diff --git a/sonar-batch/src/main/java/org/sonar/batch/source/CodeColorizerSensor.java b/sonar-batch/src/main/java/org/sonar/batch/source/CodeColorizerSensor.java deleted file mode 100644 index 158e02a9777..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/source/CodeColorizerSensor.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.source; - -import org.sonar.api.batch.Phase; -import org.sonar.api.batch.fs.FileSystem; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.sensor.Sensor; -import org.sonar.api.batch.sensor.SensorContext; -import org.sonar.api.batch.sensor.SensorDescriptor; -import org.sonar.batch.index.BatchComponentCache; -import org.sonar.batch.protocol.output.BatchReportReader; -import org.sonar.batch.report.ReportPublisher; - -@Phase(name = Phase.Name.POST) -public final class CodeColorizerSensor implements Sensor { - - private final ReportPublisher reportPublisher; - private final BatchComponentCache resourceCache; - private final CodeColorizers codeColorizers; - - public CodeColorizerSensor(ReportPublisher reportPublisher, BatchComponentCache resourceCache, CodeColorizers codeColorizers) { - this.reportPublisher = reportPublisher; - this.resourceCache = resourceCache; - this.codeColorizers = codeColorizers; - } - - @Override - public void describe(SensorDescriptor descriptor) { - descriptor.name("Code Colorizer Sensor"); - } - - @Override - public void execute(final SensorContext context) { - FileSystem fs = context.fileSystem(); - for (InputFile f : fs.inputFiles(fs.predicates().all())) { - BatchReportReader reader = new BatchReportReader(reportPublisher.getReportDir()); - int batchId = resourceCache.get(f).batchId(); - String language = f.language(); - if (reader.hasSyntaxHighlighting(batchId) || language == null) { - continue; - } - codeColorizers.toSyntaxHighlighting(f.file(), fs.encoding(), language, context.newHighlighting().onFile(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 deleted file mode 100644 index 39a4a0b1c98..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/source/CodeColorizers.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.source; - -import com.google.common.collect.Lists; -import java.io.BufferedReader; -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; -import javax.annotation.CheckForNull; -import org.apache.commons.io.input.BOMInputStream; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.batch.sensor.highlighting.NewHighlighting; -import org.sonar.api.web.CodeColorizerFormat; -import org.sonar.colorizer.JavaTokenizers; -import org.sonar.colorizer.Tokenizer; - -/** - * Central point for sonar-colorizer extensions - */ -@BatchSide -public class CodeColorizers { - - private static final Logger LOG = LoggerFactory.getLogger(CodeColorizers.class); - - private final Map byLang; - - public CodeColorizers(List formats) { - byLang = new HashMap<>(); - for (CodeColorizerFormat format : formats) { - byLang.put(format.getLanguageKey(), format); - } - - LOG.debug("Code colorizer, supported languages: " + StringUtils.join(byLang.keySet(), ",")); - } - - /** - * Used when no plugin is defining some CodeColorizerFormat - */ - public CodeColorizers() { - this(Lists.newArrayList()); - } - - @CheckForNull - public void toSyntaxHighlighting(File file, Charset charset, String language, NewHighlighting highlighting) { - CodeColorizerFormat format = byLang.get(language); - List tokenizers; - if (format == null) { - // Workaround for Java test code since Java plugin only provides highlighting for main source and no colorizer - // TODO can be dropped when Java plugin embed its own CodeColorizerFormat of (better) provides highlighting for tests - // See SONARJAVA-830 - if ("java".equals(language)) { - tokenizers = JavaTokenizers.forHtml(); - } else { - return; - } - } else { - tokenizers = format.getTokenizers(); - } - try (Reader reader = new BufferedReader(new InputStreamReader(new BOMInputStream(new FileInputStream(file)), charset))) { - new HighlightingRenderer().render(reader, tokenizers, highlighting); - } catch (Exception e) { - LOG.warn("Unable to perform colorization of file " + file, e); - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/source/DefaultHighlightable.java b/sonar-batch/src/main/java/org/sonar/batch/source/DefaultHighlightable.java deleted file mode 100644 index 80403efc298..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/source/DefaultHighlightable.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.source; - -import org.sonar.api.batch.AnalysisMode; -import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.batch.sensor.highlighting.TypeOfText; -import org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting; -import org.sonar.api.batch.sensor.internal.SensorStorage; -import org.sonar.api.source.Highlightable; - -/** - * @since 3.6 - */ -public class DefaultHighlightable implements Highlightable { - - private static final HighlightingBuilder NO_OP_BUILDER = new NoOpHighlightingBuilder(); - private final DefaultInputFile inputFile; - private final SensorStorage sensorStorage; - private final AnalysisMode analysisMode; - - public DefaultHighlightable(DefaultInputFile inputFile, SensorStorage sensorStorage, AnalysisMode analysisMode) { - this.inputFile = inputFile; - this.sensorStorage = sensorStorage; - this.analysisMode = analysisMode; - } - - @Override - public HighlightingBuilder newHighlighting() { - if (analysisMode.isIssues()) { - return NO_OP_BUILDER; - } - DefaultHighlighting defaultHighlighting = new DefaultHighlighting(sensorStorage); - defaultHighlighting.onFile(inputFile); - return new DefaultHighlightingBuilder(defaultHighlighting); - } - - private static final class NoOpHighlightingBuilder implements HighlightingBuilder { - @Override - public HighlightingBuilder highlight(int startOffset, int endOffset, String typeOfText) { - // Do nothing - return this; - } - - @Override - public void done() { - // Do nothing - } - } - - private static class DefaultHighlightingBuilder implements HighlightingBuilder { - - private final DefaultHighlighting defaultHighlighting; - - public DefaultHighlightingBuilder(DefaultHighlighting defaultHighlighting) { - this.defaultHighlighting = defaultHighlighting; - } - - @Override - public HighlightingBuilder highlight(int startOffset, int endOffset, String typeOfText) { - TypeOfText type = org.sonar.api.batch.sensor.highlighting.TypeOfText.forCssClass(typeOfText); - defaultHighlighting.highlight(startOffset, endOffset, type); - return this; - } - - @Override - public void done() { - defaultHighlighting.save(); - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbol.java b/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbol.java deleted file mode 100644 index a317bfb2de8..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbol.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.source; - -import com.google.common.base.Objects; -import org.sonar.api.batch.fs.TextRange; - -import java.io.Serializable; - -public class DefaultSymbol implements org.sonar.api.source.Symbol, Serializable { - - private TextRange range; - private int length; - - public DefaultSymbol(TextRange range, int length) { - this.range = range; - this.length = length; - } - - @Override - public int getDeclarationStartOffset() { - throw new UnsupportedOperationException("getDeclarationStartOffset"); - } - - @Override - public int getDeclarationEndOffset() { - throw new UnsupportedOperationException("getDeclarationEndOffset"); - } - - @Override - public String getFullyQualifiedName() { - throw new UnsupportedOperationException("getFullyQualifiedName"); - } - - public TextRange range() { - return range; - } - - public int getLength() { - return length; - } - - @Override - public String toString() { - return Objects.toStringHelper("Symbol") - .add("range", range) - .toString(); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolTable.java b/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolTable.java deleted file mode 100644 index f4ecc8e3761..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolTable.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.source; - -import java.util.ArrayList; -import java.util.Comparator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeSet; -import org.sonar.api.batch.fs.TextRange; -import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.source.Symbol; -import org.sonar.api.source.Symbolizable; - -public class DefaultSymbolTable implements Symbolizable.SymbolTable { - - private Map> referencesBySymbol; - - private DefaultSymbolTable(Map> referencesBySymbol) { - this.referencesBySymbol = referencesBySymbol; - } - - public Map> getReferencesBySymbol() { - return referencesBySymbol; - } - - @Override - public List symbols() { - List result = new ArrayList<>(); - for (Symbol symbol : referencesBySymbol.keySet()) { - result.add((Symbol) symbol); - } - return result; - } - - @Override - public List references(Symbol symbol) { - throw new UnsupportedOperationException("references"); - } - - public static class Builder implements Symbolizable.SymbolTableBuilder { - - private static final class FakeSymbol implements Symbol { - @Override - public String getFullyQualifiedName() { - return null; - } - - @Override - public int getDeclarationStartOffset() { - return 0; - } - - @Override - public int getDeclarationEndOffset() { - return 0; - } - } - - private final Map> referencesBySymbol = new LinkedHashMap<>(); - private final DefaultInputFile inputFile; - - public Builder(DefaultInputFile inputFile) { - this.inputFile = inputFile; - } - - @Override - public Symbol newSymbol(int fromOffset, int toOffset) { - TextRange declarationRange = inputFile.newRange(fromOffset, toOffset); - DefaultSymbol symbol = new DefaultSymbol(declarationRange, toOffset - fromOffset); - referencesBySymbol.put(symbol, new TreeSet<>(new Comparator() { - @Override - public int compare(TextRange o1, TextRange o2) { - return o1.start().compareTo(o2.start()); - } - })); - return symbol; - } - - @Override - public void newReference(Symbol symbol, int fromOffset) { - newReference(symbol, fromOffset, fromOffset + ((DefaultSymbol) symbol).getLength()); - } - - @Override - public void newReference(Symbol symbol, int fromOffset, int toOffset) { - if (!referencesBySymbol.containsKey(symbol)) { - throw new UnsupportedOperationException("Cannot add reference to a symbol in another file"); - } - TextRange referenceRange = inputFile.newRange(fromOffset, toOffset); - - if (referenceRange.overlap(((DefaultSymbol) symbol).range())) { - throw new UnsupportedOperationException("Cannot add reference (" + fromOffset + ") overlapping " + symbol + " in " + inputFile.key()); - } - referencesBySymbol.get(symbol).add(referenceRange); - } - - @Override - public Symbolizable.SymbolTable build() { - return new DefaultSymbolTable(referencesBySymbol); - } - - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolizable.java b/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolizable.java deleted file mode 100644 index cddeabb9683..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolizable.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.source; - -import java.util.Collections; -import java.util.List; -import org.sonar.api.batch.AnalysisMode; -import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.source.Symbol; -import org.sonar.api.source.Symbolizable; -import org.sonar.batch.sensor.DefaultSensorStorage; - -public class DefaultSymbolizable implements Symbolizable { - - private static final NoOpSymbolTableBuilder NO_OP_SYMBOL_TABLE_BUILDER = new NoOpSymbolTableBuilder(); - private static final NoOpSymbolTable NO_OP_SYMBOL_TABLE = new NoOpSymbolTable(); - private static final NoOpSymbol NO_OP_SYMBOL = new NoOpSymbol(); - - private static final class NoOpSymbolTableBuilder implements SymbolTableBuilder { - @Override - public Symbol newSymbol(int fromOffset, int toOffset) { - return NO_OP_SYMBOL; - } - - @Override - public void newReference(Symbol symbol, int fromOffset) { - // Do nothing - } - - @Override - public void newReference(Symbol symbol, int fromOffset, int toOffset) { - // Do nothing - } - - @Override - public SymbolTable build() { - return NO_OP_SYMBOL_TABLE; - } - } - - private static final class NoOpSymbolTable implements SymbolTable { - @Override - public List symbols() { - return Collections.emptyList(); - } - - @Override - public List references(Symbol symbol) { - return Collections.emptyList(); - } - } - - private static final class NoOpSymbol implements Symbol { - @Override - public String getFullyQualifiedName() { - return null; - } - - @Override - public int getDeclarationStartOffset() { - return 0; - } - - @Override - public int getDeclarationEndOffset() { - return 0; - } - } - - private final DefaultInputFile inputFile; - private final DefaultSensorStorage sensorStorage; - private final AnalysisMode analysisMode; - - public DefaultSymbolizable(DefaultInputFile inputFile, DefaultSensorStorage sensorStorage, AnalysisMode analysisMode) { - this.inputFile = inputFile; - this.sensorStorage = sensorStorage; - this.analysisMode = analysisMode; - } - - @Override - public SymbolTableBuilder newSymbolTableBuilder() { - if (analysisMode.isIssues()) { - return NO_OP_SYMBOL_TABLE_BUILDER; - } - return new DefaultSymbolTable.Builder(inputFile); - } - - @Override - public void setSymbolTable(SymbolTable symbolTable) { - if (analysisMode.isIssues()) { - // No need for symbols in issues mode - return; - } - sensorStorage.store(inputFile, ((DefaultSymbolTable) symbolTable).getReferencesBySymbol()); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/source/HighlightableBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/source/HighlightableBuilder.java deleted file mode 100644 index d911516b984..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/source/HighlightableBuilder.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.source; - -import javax.annotation.CheckForNull; -import org.sonar.api.batch.AnalysisMode; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.batch.sensor.internal.SensorStorage; -import org.sonar.api.source.Highlightable; -import org.sonar.batch.deprecated.perspectives.PerspectiveBuilder; -import org.sonar.batch.index.BatchComponent; - -public class HighlightableBuilder extends PerspectiveBuilder { - - private final SensorStorage sensorStorage; - private final AnalysisMode analysisMode; - - public HighlightableBuilder(SensorStorage sensorStorage, AnalysisMode analysisMode) { - super(Highlightable.class); - this.sensorStorage = sensorStorage; - this.analysisMode = analysisMode; - } - - @CheckForNull - @Override - public Highlightable loadPerspective(Class perspectiveClass, BatchComponent component) { - if (component.isFile()) { - InputFile path = (InputFile) component.inputComponent(); - return new DefaultHighlightable((DefaultInputFile) path, sensorStorage, analysisMode); - } - return null; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/source/HighlightingCodeBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/source/HighlightingCodeBuilder.java deleted file mode 100644 index b807ee2d5e2..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/source/HighlightingCodeBuilder.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.source; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.batch.sensor.highlighting.NewHighlighting; -import org.sonar.api.batch.sensor.highlighting.TypeOfText; -import org.sonar.colorizer.HtmlCodeBuilder; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class HighlightingCodeBuilder extends HtmlCodeBuilder { - - private static final Logger LOG = LoggerFactory.getLogger(HighlightingCodeBuilder.class); - - private int currentOffset = 0; - private static final Pattern START_TAG_PATTERN = Pattern.compile(""); - private static final Pattern END_TAG_PATTERN = Pattern.compile(""); - private int startOffset = -1; - private String cssClass; - private final NewHighlighting highlighting; - - public HighlightingCodeBuilder(NewHighlighting highlighting) { - this.highlighting = highlighting; - } - - @Override - public Appendable append(CharSequence csq) { - for (int i = 0; i < csq.length(); i++) { - append(csq.charAt(i)); - } - return this; - } - - @Override - public Appendable append(char c) { - currentOffset++; - return this; - } - - @Override - public void appendWithoutTransforming(String htmlTag) { - if (startOffset == -1) { - Matcher startMatcher = START_TAG_PATTERN.matcher(htmlTag); - if (startMatcher.matches()) { - startOffset = currentOffset; - cssClass = startMatcher.group(1); - } else { - LOG.warn("Expected to match highlighting start html tag but was: " + htmlTag); - } - } else { - Matcher endMatcher = END_TAG_PATTERN.matcher(htmlTag); - if (endMatcher.matches()) { - highlighting.highlight(startOffset, currentOffset, TypeOfText.forCssClass(cssClass)); - startOffset = -1; - } else { - LOG.warn("Expected to match highlighting end html tag but was: " + htmlTag); - } - } - } - - @Override - public String toString() { - throw new UnsupportedOperationException(); - } - - @Override - public StringBuilder getColorizedCode() { - throw new UnsupportedOperationException(); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/source/HighlightingRenderer.java b/sonar-batch/src/main/java/org/sonar/batch/source/HighlightingRenderer.java deleted file mode 100644 index f4b9f3d399f..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/source/HighlightingRenderer.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.source; - -import org.sonar.api.batch.sensor.highlighting.NewHighlighting; -import org.sonar.channel.Channel; -import org.sonar.channel.CodeReader; -import org.sonar.colorizer.HtmlCodeBuilder; -import org.sonar.colorizer.TokenizerDispatcher; - -import java.io.Reader; -import java.util.ArrayList; -import java.util.List; - -public class HighlightingRenderer { - - public void render(Reader code, List> tokenizers, NewHighlighting highlighting) { - List> allTokenizers = new ArrayList<>(); - HighlightingCodeBuilder codeBuilder = new HighlightingCodeBuilder(highlighting); - - allTokenizers.addAll(tokenizers); - - new TokenizerDispatcher(allTokenizers).colorize(new CodeReader(code), codeBuilder); - highlighting.save(); - } -} 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 deleted file mode 100644 index d27c90953a0..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/source/LinesSensor.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.source; - -import org.sonar.api.batch.Phase; -import org.sonar.api.batch.fs.FileSystem; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.InputFile.Type; -import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.batch.sensor.Sensor; -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; - -@Phase(name = Phase.Name.PRE) -public final class LinesSensor implements Sensor { - - @Override - public void describe(SensorDescriptor descriptor) { - descriptor.name("Lines Sensor"); - } - - @Override - public void execute(final SensorContext context) { - FileSystem fs = context.fileSystem(); - for (InputFile f : fs.inputFiles(fs.predicates().hasType(Type.MAIN))) { - ((DefaultMeasure) context.newMeasure() - .on(f) - .forMetric(CoreMetrics.LINES) - .withValue(f.lines())) - .setFromCore() - .save(); - if (f.language() == null) { - // As an approximation for files with no language plugin we consider every non blank line as ncloc - ((DefaultMeasure) context.newMeasure() - .on(f) - .forMetric(CoreMetrics.NCLOC) - .withValue(((DefaultInputFile) f).nonBlankLines())) - .save(); - // No test and no coverage on those files - ((DefaultMeasure) context.newMeasure() - .on(f) - .forMetric(CoreMetrics.LINES_TO_COVER) - .withValue(0)) - .save(); - } - } - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/source/SymbolizableBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/source/SymbolizableBuilder.java deleted file mode 100644 index fda6c4c7166..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/source/SymbolizableBuilder.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.source; - -import javax.annotation.CheckForNull; -import org.sonar.api.batch.AnalysisMode; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.source.Symbolizable; -import org.sonar.batch.deprecated.perspectives.PerspectiveBuilder; -import org.sonar.batch.index.BatchComponent; -import org.sonar.batch.sensor.DefaultSensorStorage; - -public class SymbolizableBuilder extends PerspectiveBuilder { - - private final DefaultSensorStorage sensorStorage; - private final AnalysisMode analysisMode; - - public SymbolizableBuilder(DefaultSensorStorage sensorStorage, AnalysisMode analysisMode) { - super(Symbolizable.class); - this.sensorStorage = sensorStorage; - this.analysisMode = analysisMode; - } - - @CheckForNull - @Override - public Symbolizable loadPerspective(Class perspectiveClass, BatchComponent component) { - if (component.isFile()) { - InputFile path = (InputFile) component.inputComponent(); - return new DefaultSymbolizable((DefaultInputFile) path, sensorStorage, analysisMode); - } - return null; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/source/ZeroCoverageSensor.java b/sonar-batch/src/main/java/org/sonar/batch/source/ZeroCoverageSensor.java deleted file mode 100644 index f211050dabc..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/source/ZeroCoverageSensor.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.source; - -import com.google.common.base.Function; -import com.google.common.collect.Sets; -import java.util.Map; -import java.util.Set; -import org.apache.commons.lang.StringUtils; -import org.sonar.api.batch.Phase; -import org.sonar.api.batch.fs.FileSystem; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.InputFile.Type; -import org.sonar.api.batch.measure.Metric; -import org.sonar.api.batch.sensor.Sensor; -import org.sonar.api.batch.sensor.SensorContext; -import org.sonar.api.batch.sensor.SensorDescriptor; -import org.sonar.api.batch.sensor.coverage.CoverageType; -import org.sonar.api.batch.sensor.coverage.NewCoverage; -import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.Measure; -import org.sonar.api.utils.KeyValueFormat; -import org.sonar.batch.scan.measure.MeasureCache; - -import static com.google.common.collect.Iterables.concat; -import static com.google.common.collect.Iterables.transform; -import static com.google.common.collect.Sets.newHashSet; - -@Phase(name = Phase.Name.POST) -public final class ZeroCoverageSensor implements Sensor { - - private static final class MeasureToMetricKey implements Function { - @Override - public String apply(Measure input) { - return input.getMetricKey(); - } - } - - private static final class MetricToKey implements Function { - @Override - public String apply(Metric input) { - return input.key(); - } - } - - private final MeasureCache measureCache; - - public ZeroCoverageSensor(MeasureCache measureCache) { - this.measureCache = measureCache; - } - - @Override - public void describe(SensorDescriptor descriptor) { - descriptor.name("Zero Coverage Sensor"); - } - - @Override - public void execute(final SensorContext context) { - FileSystem fs = context.fileSystem(); - for (InputFile f : fs.inputFiles(fs.predicates().hasType(Type.MAIN))) { - if (!isCoverageMeasuresAlreadyDefined(f)) { - Measure execLines = measureCache.byMetric(f.key(), CoreMetrics.EXECUTABLE_LINES_DATA_KEY); - if (execLines != null) { - storeZeroCoverageForEachExecutableLine(context, f, execLines); - } - - } - } - } - - private static void storeZeroCoverageForEachExecutableLine(final SensorContext context, InputFile f, Measure execLines) { - NewCoverage newCoverage = context.newCoverage().ofType(CoverageType.UNIT).onFile(f); - Map lineMeasures = KeyValueFormat.parseIntString((String) execLines.value()); - for (Map.Entry lineMeasure : lineMeasures.entrySet()) { - int lineIdx = lineMeasure.getKey(); - if (lineIdx <= f.lines()) { - String value = lineMeasure.getValue(); - if (StringUtils.isNotEmpty(value) && Integer.parseInt(value) > 0) { - newCoverage.lineHits(lineIdx, 0); - } - } - } - newCoverage.save(); - } - - private boolean isCoverageMeasuresAlreadyDefined(InputFile f) { - Set metricKeys = newHashSet(transform(measureCache.byComponentKey(f.key()), new MeasureToMetricKey())); - Function metricToKey = new MetricToKey(); - Set allCoverageMetricKeys = newHashSet(concat(transform(CoverageType.UNIT.allMetrics(), metricToKey), - transform(CoverageType.IT.allMetrics(), metricToKey), - transform(CoverageType.OVERALL.allMetrics(), metricToKey))); - return !Sets.intersection(metricKeys, allCoverageMetricKeys).isEmpty(); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/source/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/source/package-info.java deleted file mode 100644 index c33229b0ab2..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/source/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.batch.source; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-batch/src/main/java/org/sonar/batch/task/ListTask.java b/sonar-batch/src/main/java/org/sonar/batch/task/ListTask.java deleted file mode 100644 index 7c535674d82..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/task/ListTask.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.task; - -import org.sonar.api.task.Task; -import org.sonar.api.task.TaskDefinition; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; - -public class ListTask implements Task { - - private static final Logger LOG = Loggers.get(ListTask.class); - - public static final String KEY = "list"; - - public static final TaskDefinition DEFINITION = TaskDefinition.builder() - .key(KEY) - .description("List available tasks") - .taskClass(ListTask.class) - .build(); - - private final Tasks tasks; - - public ListTask(Tasks tasks) { - this.tasks = tasks; - } - - @Override - public void execute() { - StringBuilder sb = new StringBuilder(); - sb.append("\nAvailable tasks:\n"); - for (TaskDefinition def : tasks.definitions()) { - sb.append(" - " + def.key() + ": " + def.description() + "\n"); - } - sb.append("\n"); - LOG.info(sb.toString()); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/task/ScanTask.java b/sonar-batch/src/main/java/org/sonar/batch/task/ScanTask.java deleted file mode 100644 index c5ba59c3d37..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/task/ScanTask.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.task; - -import javax.annotation.CheckForNull; -import org.sonar.api.CoreProperties; -import org.sonar.api.task.Task; -import org.sonar.api.task.TaskDefinition; -import org.sonar.batch.analysis.AnalysisProperties; -import org.sonar.batch.analysis.DefaultAnalysisMode; -import org.sonar.batch.bootstrap.GlobalProperties; -import org.sonar.batch.cache.ProjectSyncContainer; -import org.sonar.batch.scan.ProjectScanContainer; -import org.sonar.core.platform.ComponentContainer; - -public class ScanTask implements Task { - public static final TaskDefinition DEFINITION = TaskDefinition.builder() - .description("Scan project") - .key(CoreProperties.SCAN_TASK) - .taskClass(ScanTask.class) - .build(); - - private final ComponentContainer taskContainer; - private final TaskProperties taskProps; - - public ScanTask(TaskContainer taskContainer, TaskProperties taskProps) { - this.taskContainer = taskContainer; - this.taskProps = taskProps; - } - - @Override - public void execute() { - AnalysisProperties props = new AnalysisProperties(taskProps.properties(), taskProps.property(CoreProperties.ENCRYPTION_SECRET_KEY_PATH)); - if (isIssuesMode(props)) { - String projectKey = getProjectKeyWithBranch(props); - new ProjectSyncContainer(taskContainer, projectKey, false).execute(); - } - new ProjectScanContainer(taskContainer, props).execute(); - } - - @CheckForNull - private static String getProjectKeyWithBranch(AnalysisProperties props) { - String projectKey = props.property(CoreProperties.PROJECT_KEY_PROPERTY); - if (projectKey != null && props.property(CoreProperties.PROJECT_BRANCH_PROPERTY) != null) { - projectKey = projectKey + ":" + props.property(CoreProperties.PROJECT_BRANCH_PROPERTY); - } - return projectKey; - } - - private boolean isIssuesMode(AnalysisProperties props) { - DefaultAnalysisMode mode = new DefaultAnalysisMode(taskContainer.getComponentByType(GlobalProperties.class), props); - return mode.isIssues(); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/task/TaskContainer.java b/sonar-batch/src/main/java/org/sonar/batch/task/TaskContainer.java deleted file mode 100644 index eee91f63055..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/task/TaskContainer.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.task; - -import java.util.Map; -import org.apache.commons.lang.StringUtils; -import org.sonar.api.CoreProperties; -import org.sonar.api.batch.InstantiationStrategy; -import org.sonar.api.config.EmailSettings; -import org.sonar.api.task.Task; -import org.sonar.api.task.TaskDefinition; -import org.sonar.api.utils.MessageException; -import org.sonar.batch.bootstrap.ExtensionInstaller; -import org.sonar.batch.bootstrap.ExtensionMatcher; -import org.sonar.batch.bootstrap.ExtensionUtils; -import org.sonar.batch.bootstrap.GlobalProperties; -import org.sonar.core.platform.ComponentContainer; - -public class TaskContainer extends ComponentContainer { - - private final Map taskProperties; - private final Object[] components; - - public TaskContainer(ComponentContainer parent, Map taskProperties, Object... components) { - super(parent); - this.taskProperties = taskProperties; - this.components = components; - } - - @Override - protected void doBeforeStart() { - addTaskExtensions(); - addCoreComponents(); - for (Object component : components) { - add(component); - } - } - - private void addCoreComponents() { - add(new TaskProperties(taskProperties, getParent().getComponentByType(GlobalProperties.class).property(CoreProperties.ENCRYPTION_SECRET_KEY_PATH))); - add(EmailSettings.class); - } - - private void addTaskExtensions() { - getComponentByType(ExtensionInstaller.class).install(this, new TaskExtensionFilter()); - } - - static class TaskExtensionFilter implements ExtensionMatcher { - @Override - public boolean accept(Object extension) { - return ExtensionUtils.isBatchSide(extension) - && ExtensionUtils.isInstantiationStrategy(extension, InstantiationStrategy.PER_TASK); - } - } - - @Override - public void doAfterStart() { - // default value is declared in CorePlugin - String taskKey = StringUtils.defaultIfEmpty(taskProperties.get(CoreProperties.TASK), CoreProperties.SCAN_TASK); - // Release memory - taskProperties.clear(); - - TaskDefinition def = getComponentByType(Tasks.class).definition(taskKey); - if (def == null) { - throw MessageException.of("Task '" + taskKey + "' does not exist. Please use '" + ListTask.KEY + "' task to see all available tasks."); - } - Task task = getComponentByType(def.taskClass()); - if (task != null) { - task.execute(); - } else { - throw new IllegalStateException("Task " + taskKey + " is badly defined"); - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/task/TaskProperties.java b/sonar-batch/src/main/java/org/sonar/batch/task/TaskProperties.java deleted file mode 100644 index b8470ce4d00..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/task/TaskProperties.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.task; - -import java.util.Map; -import javax.annotation.Nullable; -import org.sonar.batch.bootstrap.UserProperties; - -/** - * Batch properties that are specific to a task (for example - * coming from sonar-project.properties). - */ -public class TaskProperties extends UserProperties { - - public TaskProperties(Map properties, @Nullable String pathToSecretKey) { - super(properties, pathToSecretKey); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/task/Tasks.java b/sonar-batch/src/main/java/org/sonar/batch/task/Tasks.java deleted file mode 100644 index ee68b62b1db..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/task/Tasks.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.task; - -import com.google.common.collect.ImmutableSortedMap; -import com.google.common.collect.Maps; -import java.util.Collection; -import java.util.Map; -import java.util.SortedMap; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.batch.InstantiationStrategy; -import org.sonar.api.task.Task; -import org.sonar.api.task.TaskDefinition; - -@BatchSide -@InstantiationStrategy(InstantiationStrategy.PER_TASK) -public class Tasks { - - private final SortedMap byKey; - - public Tasks(TaskDefinition[] definitions) { - SortedMap map = Maps.newTreeMap(); - for (TaskDefinition definition : definitions) { - if (map.containsKey(definition.key())) { - throw new IllegalStateException("Task '" + definition.key() + "' is declared twice"); - } - map.put(definition.key(), definition); - } - this.byKey = ImmutableSortedMap.copyOf(map); - } - - public TaskDefinition definition(String taskKey) { - return byKey.get(taskKey); - } - - public Collection definitions() { - return byKey.values(); - } - - /** - * Perform validation of task definitions - */ - public void start() { - checkDuplicatedClasses(); - } - - private void checkDuplicatedClasses() { - Map, TaskDefinition> byClass = Maps.newHashMap(); - for (TaskDefinition def : definitions()) { - TaskDefinition other = byClass.get(def.taskClass()); - if (other == null) { - byClass.put(def.taskClass(), def); - } else { - throw new IllegalStateException("Task '" + def.taskClass().getName() + "' is defined twice: first by '" + other.key() + "' and then by '" + def.key() + "'"); - } - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/task/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/task/package-info.java deleted file mode 100644 index 5787c1e27c2..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/task/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.batch.task; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-batch/src/main/java/org/sonar/batch/test/DefaultCoverageBlock.java b/sonar-batch/src/main/java/org/sonar/batch/test/DefaultCoverageBlock.java deleted file mode 100644 index 52c3ca7a76f..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/test/DefaultCoverageBlock.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.test; - -import java.util.List; -import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.test.CoverageBlock; -import org.sonar.api.test.TestCase; -import org.sonar.api.test.Testable; - -public class DefaultCoverageBlock implements CoverageBlock { - - private final TestCase testCase; - private final DefaultInputFile testable; - private final List lines; - - public DefaultCoverageBlock(TestCase testCase, DefaultInputFile testable, List lines) { - this.testCase = testCase; - this.testable = testable; - this.lines = lines; - } - - @Override - public TestCase testCase() { - return testCase; - } - - @Override - public Testable testable() { - return new DefaultTestable(testable); - } - - @Override - public List lines() { - return lines; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestCase.java b/sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestCase.java deleted file mode 100644 index 652d11a0ddb..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestCase.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.test; - -import com.google.common.base.Preconditions; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import javax.annotation.Nullable; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.InputFile.Type; -import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.test.CoverageBlock; -import org.sonar.api.test.MutableTestCase; -import org.sonar.api.test.TestPlan; -import org.sonar.api.test.Testable; -import org.sonar.api.test.exception.CoverageAlreadyExistsException; -import org.sonar.api.test.exception.IllegalDurationException; - -public class DefaultTestCase implements MutableTestCase { - - private final DefaultTestPlan testPlan; - private String type; - private Long durationInMs; - private Status status; - private String name; - private String message; - private String stackTrace; - private Map coverageBlocksByTestedFile = new LinkedHashMap<>(); - - public DefaultTestCase(DefaultTestPlan testPlan) { - this.testPlan = testPlan; - } - - @Override - public String type() { - return type; - } - - @Override - public MutableTestCase setType(@Nullable String s) { - this.type = s; - return this; - } - - @Override - public Long durationInMs() { - return durationInMs; - } - - @Override - public MutableTestCase setDurationInMs(@Nullable Long l) { - if (l != null && l < 0) { - throw new IllegalDurationException("Test duration must be positive (got: " + l + ")"); - } - this.durationInMs = l; - return this; - } - - @Override - public Status status() { - return status; - } - - @Override - public MutableTestCase setStatus(@Nullable Status s) { - this.status = s; - return this; - } - - @Override - public String name() { - return name; - } - - public MutableTestCase setName(String s) { - this.name = s; - return this; - } - - @Override - public String message() { - return message; - } - - @Override - public MutableTestCase setMessage(String s) { - this.message = s; - return this; - } - - @Override - public String stackTrace() { - return stackTrace; - } - - @Override - public MutableTestCase setStackTrace(String s) { - this.stackTrace = s; - return this; - } - - @Override - public MutableTestCase setCoverageBlock(Testable testable, List lines) { - DefaultInputFile coveredFile = ((DefaultTestable) testable).inputFile(); - return setCoverageBlock(coveredFile, lines); - } - - @Override - public MutableTestCase setCoverageBlock(InputFile mainFile, List lines) { - Preconditions.checkArgument(mainFile.type() == Type.MAIN, "Test file can only cover a main file"); - DefaultInputFile coveredFile = (DefaultInputFile) mainFile; - if (coverageBlocksByTestedFile.containsKey(coveredFile)) { - throw new CoverageAlreadyExistsException("The link between " + name() + " and " + coveredFile.key() + " already exists"); - } - coverageBlocksByTestedFile.put(coveredFile, new DefaultCoverageBlock(this, coveredFile, lines)); - return this; - } - - @Override - public TestPlan testPlan() { - return testPlan; - } - - @Override - public boolean doesCover() { - return !coverageBlocksByTestedFile.isEmpty(); - } - - @Override - public int countCoveredLines() { - throw new UnsupportedOperationException("Not supported since SQ 5.2"); - } - - @Override - public Iterable coverageBlocks() { - return coverageBlocksByTestedFile.values(); - } - - @Override - public CoverageBlock coverageBlock(final Testable testable) { - DefaultInputFile coveredFile = ((DefaultTestable) testable).inputFile(); - return coverageBlocksByTestedFile.get(coveredFile); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestPlan.java b/sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestPlan.java deleted file mode 100644 index 85b26082424..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestPlan.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.test; - -import com.google.common.collect.Lists; -import java.util.ArrayList; -import java.util.List; -import javax.annotation.CheckForNull; -import org.sonar.api.test.MutableTestCase; -import org.sonar.api.test.MutableTestPlan; - -public class DefaultTestPlan implements MutableTestPlan { - private List testCases = new ArrayList<>(); - - @Override - @CheckForNull - public Iterable testCasesByName(String name) { - List result = Lists.newArrayList(); - for (MutableTestCase testCase : testCases()) { - if (name.equals(testCase.name())) { - result.add(testCase); - } - } - return result; - } - - @Override - public MutableTestCase addTestCase(String name) { - DefaultTestCase testCase = new DefaultTestCase(this); - testCase.setName(name); - testCases.add(testCase); - return testCase; - } - - @Override - public Iterable testCases() { - return testCases; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestable.java b/sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestable.java deleted file mode 100644 index c672253920e..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestable.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.test; - -import java.util.List; -import java.util.Map; -import java.util.SortedSet; -import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.test.CoverageBlock; -import org.sonar.api.test.MutableTestable; -import org.sonar.api.test.TestCase; - -public class DefaultTestable implements MutableTestable { - - private final DefaultInputFile inputFile; - - public DefaultTestable(DefaultInputFile inputFile) { - this.inputFile = inputFile; - } - - public DefaultInputFile inputFile() { - return inputFile; - } - - @Override - public List testCases() { - throw unsupported(); - } - - @Override - public TestCase testCaseByName(final String name) { - throw unsupported(); - } - - @Override - public int countTestCasesOfLine(Integer line) { - throw unsupported(); - } - - @Override - public Map testCasesByLines() { - throw unsupported(); - } - - @Override - public List testCasesOfLine(int line) { - throw unsupported(); - } - - @Override - public SortedSet testedLines() { - throw unsupported(); - } - - @Override - public CoverageBlock coverageBlock(final TestCase testCase) { - throw unsupported(); - } - - @Override - public Iterable coverageBlocks() { - throw unsupported(); - } - - private static UnsupportedOperationException unsupported() { - return new UnsupportedOperationException("No more available since SQ 5.2"); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/test/TestPlanBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/test/TestPlanBuilder.java deleted file mode 100644 index b3bab1ee6f5..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/test/TestPlanBuilder.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.test; - -import java.util.HashMap; -import java.util.Map; -import javax.annotation.CheckForNull; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.InputFile.Type; -import org.sonar.api.test.MutableTestPlan; -import org.sonar.batch.deprecated.perspectives.PerspectiveBuilder; -import org.sonar.batch.index.BatchComponent; - -public class TestPlanBuilder extends PerspectiveBuilder { - - private Map testPlanByFile = new HashMap<>(); - - public TestPlanBuilder() { - super(MutableTestPlan.class); - } - - @CheckForNull - @Override - public MutableTestPlan loadPerspective(Class perspectiveClass, BatchComponent component) { - if (component.isFile()) { - InputFile inputFile = (InputFile) component.inputComponent(); - if (inputFile.type() == Type.TEST) { - if (!testPlanByFile.containsKey(inputFile)) { - testPlanByFile.put(inputFile, new DefaultTestPlan()); - } - return testPlanByFile.get(inputFile); - } - } - return null; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/test/TestableBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/test/TestableBuilder.java deleted file mode 100644 index 261b0b15a1d..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/test/TestableBuilder.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.test; - -import javax.annotation.CheckForNull; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.InputFile.Type; -import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.test.MutableTestable; -import org.sonar.batch.deprecated.perspectives.PerspectiveBuilder; -import org.sonar.batch.index.BatchComponent; - -public class TestableBuilder extends PerspectiveBuilder { - - public TestableBuilder() { - super(MutableTestable.class); - } - - @CheckForNull - @Override - public MutableTestable loadPerspective(Class perspectiveClass, BatchComponent component) { - if (component.isFile()) { - InputFile inputFile = (InputFile) component.inputComponent(); - if (inputFile.type() == Type.MAIN) { - return new DefaultTestable((DefaultInputFile) inputFile); - } - } - return null; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/test/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/test/package-info.java deleted file mode 100644 index cb0a2f6c3e7..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/test/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.batch.test; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-batch/src/main/java/org/sonar/batch/util/BatchUtils.java b/sonar-batch/src/main/java/org/sonar/batch/util/BatchUtils.java deleted file mode 100644 index 81eed874378..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/util/BatchUtils.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.util; - -import com.google.common.base.Strings; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.nio.charset.StandardCharsets; -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class BatchUtils { - private static final Logger LOG = LoggerFactory.getLogger(BatchUtils.class); - - private BatchUtils() { - } - - /** - * Clean provided string to remove chars that are not valid as file name. - * @param projectKey e.g. my:file - */ - public static String cleanKeyForFilename(String projectKey) { - String cleanKey = StringUtils.deleteWhitespace(projectKey); - return StringUtils.replace(cleanKey, ":", "_"); - } - - public static String encodeForUrl(@Nullable String url) { - try { - return URLEncoder.encode(Strings.nullToEmpty(url), "UTF-8"); - - } catch (UnsupportedEncodingException e) { - throw new IllegalStateException("Encoding not supported", e); - } - } - - public static String describe(Object o) { - try { - if (o.getClass().getMethod("toString").getDeclaringClass() != Object.class) { - return o.toString(); - } - } catch (Exception e) { - // fallback - } - - return o.getClass().getName(); - } - - @CheckForNull - public static String getServerVersion() { - InputStream is = BatchUtils.class.getResourceAsStream("/sq-version.txt"); - if (is == null) { - LOG.warn("Failed to get SQ version"); - return null; - } - try (BufferedReader br = IOUtils.toBufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) { - return br.readLine(); - } catch (IOException e) { - LOG.warn("Failed to get SQ version", e); - return null; - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/util/ProgressReport.java b/sonar-batch/src/main/java/org/sonar/batch/util/ProgressReport.java deleted file mode 100644 index f2ea0406a01..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/util/ProgressReport.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.util; - -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; - -public class ProgressReport implements Runnable { - - private static final Logger LOG = Loggers.get(ProgressReport.class); - private final long period; - private String message = ""; - private final Thread thread; - private String stopMessage = ""; - - public ProgressReport(String threadName, long period) { - this.period = period; - thread = new Thread(this); - thread.setName(threadName); - thread.setDaemon(true); - } - - @Override - public void run() { - while (!Thread.interrupted()) { - try { - Thread.sleep(period); - log(message); - } catch (InterruptedException e) { - break; - } - } - log(stopMessage); - } - - public void start(String startMessage) { - log(startMessage); - thread.start(); - } - - public void message(String message) { - this.message = message; - } - - public void stop(String stopMessage) { - this.stopMessage = stopMessage; - thread.interrupt(); - try { - thread.join(); - } catch (InterruptedException e) { - // Ignore - } - } - - private static void log(String message) { - synchronized (LOG) { - LOG.info(message); - LOG.notifyAll(); - } - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/util/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/util/package-info.java deleted file mode 100644 index 42cf7aa9450..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/util/package-info.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@javax.annotation.ParametersAreNonnullByDefault -package org.sonar.batch.util; - diff --git a/sonar-batch/src/main/resources/org/sonar/batch/bootstrapper/logback.xml b/sonar-batch/src/main/resources/org/sonar/batch/bootstrapper/logback.xml deleted file mode 100644 index 99f956e4b4c..00000000000 --- a/sonar-batch/src/main/resources/org/sonar/batch/bootstrapper/logback.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - - - ${FORMAT} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/sonar-batch/src/main/resources/org/sonar/batch/logback.xml b/sonar-batch/src/main/resources/org/sonar/batch/logback.xml deleted file mode 100644 index 198cd9c1bc6..00000000000 --- a/sonar-batch/src/main/resources/org/sonar/batch/logback.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - - - %d{HH:mm:ss.SSS} %-5level %20.20logger{20} - %msg%n - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/sonar-batch/src/main/resources/org/sonar/batch/scan/report/issuesreport.ftl b/sonar-batch/src/main/resources/org/sonar/batch/scan/report/issuesreport.ftl deleted file mode 100644 index c41b8067222..00000000000 --- a/sonar-batch/src/main/resources/org/sonar/batch/scan/report/issuesreport.ftl +++ /dev/null @@ -1,462 +0,0 @@ - - - - - Issues report of ${report.getTitle()?html} - - - - - - -
- -
Issues Report
-
${report.getTitle()?html} - ${report.getDate()?datetime}
-
- -<#if report.isNoFile()> -
- -
-<#else> -
- - <#if !complete> - - - -
- - - - <#if complete> - <#assign size = '33'> - <#else> - <#assign size = '50'> - - - - <#if complete> - - - - -
-

New issues

- <#if report.getSummary().getTotal().getNewIssuesCount() gt 0> - ${report.getSummary().getTotal().getNewIssuesCount()?c} - <#else> - 0 - -
-

Resolved issues

- <#if report.getSummary().getTotal().getResolvedIssuesCount() gt 0> - ${report.getSummary().getTotal().getResolvedIssuesCount()?c} - <#else> - 0 - -
-

Issues

- ${report.getSummary().getTotal().getCountInCurrentAnalysis()?c} -
- <#if complete> -
- - - - - - - - - - - <#list report.getSummary().getRuleReports() as ruleReport> - <#if complete || (ruleReport.getTotal().getNewIssuesCount() > 0)> - <#if ruleReport.getTotal().getNewIssuesCount() = 0> - <#assign trCss = 'all'> - <#else> - <#assign trCss = ''> - - - - - - - - - - - -
- Issues per Rule - New issuesResolved issuesIssues
- - - ${ruleNameProvider.nameForHTML(ruleReport.getRule())} - - <#if ruleReport.getTotal().getNewIssuesCount() gt 0> - ${ruleReport.getTotal().getNewIssuesCount()?c} - <#else> - 0 - - - <#if ruleReport.getTotal().getResolvedIssuesCount() gt 0> - ${ruleReport.getTotal().getResolvedIssuesCount()?c} - <#else> - 0 - - - ${ruleReport.getTotal().getCountInCurrentAnalysis()?c} -
- -
- -
- - - -
- <#list report.getResourceReports() as resourceReport> - <#if complete || (resourceReport.getTotal().getNewIssuesCount() > 0)> - <#assign issueId=0> - <#if resourceReport.getTotal().getNewIssuesCount() = 0> - <#assign tableCss = 'all'> - <#else> - <#assign tableCss = ''> - - - - - - - <#if complete> - - - - - - - <#if complete> - <#list resourceReport.getRuleReports() as ruleReport> - - - - - <#if complete> - - - - - - - <#if complete> - <#assign colspan = '5'> - <#else> - <#assign colspan = '3'> - - <#assign issues=resourceReport.getIssuesAtLine(0, complete)> - <#if issues?has_content> - - - - - - - - -
- - - <#if resourceReport.getTotal().getNewIssuesCount() gt 0> - ${resourceReport.getTotal().getNewIssuesCount()?c} - <#else> - 0 - -
New issues -
- <#if resourceReport.getTotal().getResolvedIssuesCount() gt 0> - ${resourceReport.getTotal().getResolvedIssuesCount()?c} - <#else> - 0 - -
Resolved issues -
- ${resourceReport.getTotal().getCountInCurrentAnalysis()?c}
Issues -
- - - ${ruleNameProvider.nameForHTML(ruleReport.getRule())} - - <#if ruleReport.getTotal().getNewIssuesCount() gt 0> - ${ruleReport.getTotal().getNewIssuesCount()?c} - <#else> - 0 - - - <#if ruleReport.getTotal().getResolvedIssuesCount() gt 0> - ${ruleReport.getTotal().getResolvedIssuesCount()?c} - <#else> - 0 - - - ${ruleReport.getTotal().getCountInCurrentAnalysis()?c} -
- <#list issues as issue> -
-
- - <#if issue.getMessage()?has_content> - ${issue.getMessage()?html} - <#else> - ${ruleNameProvider.nameForHTML(issue.getRuleKey())} - -   -   - - - <#if issue.isNew()> - NEW - <#else> - ${issue.creationDate()?date} - - -
-
- ${ruleNameProvider.nameForHTML(issue.getRuleKey())} -
-
- <#assign issueId = issueId + 1> - -
- - <#list sourceProvider.getEscapedSource(resourceReport.getResourceNode()) as line> - <#assign lineIndex=line_index+1> - <#if resourceReport.isDisplayableLine(lineIndex, complete)> - - - - - - - - <#assign issues=resourceReport.getIssuesAtLine(lineIndex, complete)> - <#if issues?has_content> - - - - - - - -
${lineIndex?c} -
${line}
-
- <#list issues as issue> -
-
- - <#if issue.getMessage()?has_content> - ${issue.getMessage()?html} - <#else> - ${ruleNameProvider.nameForHTML(issue.getRuleKey())} - -   -   - - - <#if issue.isNew()> - NEW - <#else> - ${issue.creationDate()?date} - - -   - -
-
- ${ruleNameProvider.nameForHTML(issue.getRuleKey())} -
-
- <#assign issueId = issueId + 1> - -
-
- - -
-
- - - - diff --git a/sonar-batch/src/main/resources/org/sonar/batch/scan/report/issuesreport_files/DIR.png b/sonar-batch/src/main/resources/org/sonar/batch/scan/report/issuesreport_files/DIR.png deleted file mode 100644 index b135ef92eec..00000000000 Binary files a/sonar-batch/src/main/resources/org/sonar/batch/scan/report/issuesreport_files/DIR.png and /dev/null differ diff --git a/sonar-batch/src/main/resources/org/sonar/batch/scan/report/issuesreport_files/FIL.png b/sonar-batch/src/main/resources/org/sonar/batch/scan/report/issuesreport_files/FIL.png deleted file mode 100644 index 1664e25c8b5..00000000000 Binary files a/sonar-batch/src/main/resources/org/sonar/batch/scan/report/issuesreport_files/FIL.png and /dev/null differ diff --git a/sonar-batch/src/main/resources/org/sonar/batch/scan/report/issuesreport_files/PRJ.png b/sonar-batch/src/main/resources/org/sonar/batch/scan/report/issuesreport_files/PRJ.png deleted file mode 100644 index b32e51c5f42..00000000000 Binary files a/sonar-batch/src/main/resources/org/sonar/batch/scan/report/issuesreport_files/PRJ.png and /dev/null differ diff --git a/sonar-batch/src/main/resources/org/sonar/batch/scan/report/issuesreport_files/favicon.ico b/sonar-batch/src/main/resources/org/sonar/batch/scan/report/issuesreport_files/favicon.ico deleted file mode 100644 index c6d382d9823..00000000000 Binary files a/sonar-batch/src/main/resources/org/sonar/batch/scan/report/issuesreport_files/favicon.ico and /dev/null differ diff --git a/sonar-batch/src/main/resources/org/sonar/batch/scan/report/issuesreport_files/jquery.min.js b/sonar-batch/src/main/resources/org/sonar/batch/scan/report/issuesreport_files/jquery.min.js deleted file mode 100644 index 53763631337..00000000000 --- a/sonar-batch/src/main/resources/org/sonar/batch/scan/report/issuesreport_files/jquery.min.js +++ /dev/null @@ -1,6 +0,0 @@ -/*! jQuery v1.10.1 | (c) 2005, 2013 jQuery Foundation, Inc. | jquery.org/license - //@ sourceMappingURL=jquery-1.10.1.min.map - */ -(function(e,t){var n,r,i=typeof t,o=e.location,a=e.document,s=a.documentElement,l=e.jQuery,u=e.$,c={},p=[],f="1.10.1",d=p.concat,h=p.push,g=p.slice,m=p.indexOf,y=c.toString,v=c.hasOwnProperty,b=f.trim,x=function(e,t){return new x.fn.init(e,t,r)},w=/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,T=/\S+/g,C=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,N=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,k=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,E=/^[\],:{}\s]*$/,S=/(?:^|:|,)(?:\s*\[)+/g,A=/\\(?:["\\\/bfnrt]|u[\da-fA-F]{4})/g,j=/"[^"\\\r\n]*"|true|false|null|-?(?:\d+\.|)\d+(?:[eE][+-]?\d+|)/g,D=/^-ms-/,L=/-([\da-z])/gi,H=function(e,t){return t.toUpperCase()},q=function(e){(a.addEventListener||"load"===e.type||"complete"===a.readyState)&&(_(),x.ready())},_=function(){a.addEventListener?(a.removeEventListener("DOMContentLoaded",q,!1),e.removeEventListener("load",q,!1)):(a.detachEvent("onreadystatechange",q),e.detachEvent("onload",q))};x.fn=x.prototype={jquery:f,constructor:x,init:function(e,n,r){var i,o;if(!e)return this;if("string"==typeof e){if(i="<"===e.charAt(0)&&">"===e.charAt(e.length-1)&&e.length>=3?[null,e,null]:N.exec(e),!i||!i[1]&&n)return!n||n.jquery?(n||r).find(e):this.constructor(n).find(e);if(i[1]){if(n=n instanceof x?n[0]:n,x.merge(this,x.parseHTML(i[1],n&&n.nodeType?n.ownerDocument||n:a,!0)),k.test(i[1])&&x.isPlainObject(n))for(i in n)x.isFunction(this[i])?this[i](n[i]):this.attr(i,n[i]);return this}if(o=a.getElementById(i[2]),o&&o.parentNode){if(o.id!==i[2])return r.find(e);this.length=1,this[0]=o}return this.context=a,this.selector=e,this}return e.nodeType?(this.context=this[0]=e,this.length=1,this):x.isFunction(e)?r.ready(e):(e.selector!==t&&(this.selector=e.selector,this.context=e.context),x.makeArray(e,this))},selector:"",length:0,toArray:function(){return g.call(this)},get:function(e){return null==e?this.toArray():0>e?this[this.length+e]:this[e]},pushStack:function(e){var t=x.merge(this.constructor(),e);return t.prevObject=this,t.context=this.context,t},each:function(e,t){return x.each(this,e,t)},ready:function(e){return x.ready.promise().done(e),this},slice:function(){return this.pushStack(g.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(e){var t=this.length,n=+e+(0>e?t:0);return this.pushStack(n>=0&&t>n?[this[n]]:[])},map:function(e){return this.pushStack(x.map(this,function(t,n){return e.call(t,n,t)}))},end:function(){return this.prevObject||this.constructor(null)},push:h,sort:[].sort,splice:[].splice},x.fn.init.prototype=x.fn,x.extend=x.fn.extend=function(){var e,n,r,i,o,a,s=arguments[0]||{},l=1,u=arguments.length,c=!1;for("boolean"==typeof s&&(c=s,s=arguments[1]||{},l=2),"object"==typeof s||x.isFunction(s)||(s={}),u===l&&(s=this,--l);u>l;l++)if(null!=(o=arguments[l]))for(i in o)e=s[i],r=o[i],s!==r&&(c&&r&&(x.isPlainObject(r)||(n=x.isArray(r)))?(n?(n=!1,a=e&&x.isArray(e)?e:[]):a=e&&x.isPlainObject(e)?e:{},s[i]=x.extend(c,a,r)):r!==t&&(s[i]=r));return s},x.extend({expando:"jQuery"+(f+Math.random()).replace(/\D/g,""),noConflict:function(t){return e.$===x&&(e.$=u),t&&e.jQuery===x&&(e.jQuery=l),x},isReady:!1,readyWait:1,holdReady:function(e){e?x.readyWait++:x.ready(!0)},ready:function(e){if(e===!0?!--x.readyWait:!x.isReady){if(!a.body)return setTimeout(x.ready);x.isReady=!0,e!==!0&&--x.readyWait>0||(n.resolveWith(a,[x]),x.fn.trigger&&x(a).trigger("ready").off("ready"))}},isFunction:function(e){return"function"===x.type(e)},isArray:Array.isArray||function(e){return"array"===x.type(e)},isWindow:function(e){return null!=e&&e==e.window},isNumeric:function(e){return!isNaN(parseFloat(e))&&isFinite(e)},type:function(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?c[y.call(e)]||"object":typeof e},isPlainObject:function(e){var n;if(!e||"object"!==x.type(e)||e.nodeType||x.isWindow(e))return!1;try{if(e.constructor&&!v.call(e,"constructor")&&!v.call(e.constructor.prototype,"isPrototypeOf"))return!1}catch(r){return!1}if(x.support.ownLast)for(n in e)return v.call(e,n);for(n in e);return n===t||v.call(e,n)},isEmptyObject:function(e){var t;for(t in e)return!1;return!0},error:function(e){throw Error(e)},parseHTML:function(e,t,n){if(!e||"string"!=typeof e)return null;"boolean"==typeof t&&(n=t,t=!1),t=t||a;var r=k.exec(e),i=!n&&[];return r?[t.createElement(r[1])]:(r=x.buildFragment([e],t,i),i&&x(i).remove(),x.merge([],r.childNodes))},parseJSON:function(n){return e.JSON&&e.JSON.parse?e.JSON.parse(n):null===n?n:"string"==typeof n&&(n=x.trim(n),n&&E.test(n.replace(A,"@").replace(j,"]").replace(S,"")))?Function("return "+n)():(x.error("Invalid JSON: "+n),t)},parseXML:function(n){var r,i;if(!n||"string"!=typeof n)return null;try{e.DOMParser?(i=new DOMParser,r=i.parseFromString(n,"text/xml")):(r=new ActiveXObject("Microsoft.XMLDOM"),r.async="false",r.loadXML(n))}catch(o){r=t}return r&&r.documentElement&&!r.getElementsByTagName("parsererror").length||x.error("Invalid XML: "+n),r},noop:function(){},globalEval:function(t){t&&x.trim(t)&&(e.execScript||function(t){e.eval.call(e,t)})(t)},camelCase:function(e){return e.replace(D,"ms-").replace(L,H)},nodeName:function(e,t){return e.nodeName&&e.nodeName.toLowerCase()===t.toLowerCase()},each:function(e,t,n){var r,i=0,o=e.length,a=M(e);if(n){if(a){for(;o>i;i++)if(r=t.apply(e[i],n),r===!1)break}else for(i in e)if(r=t.apply(e[i],n),r===!1)break}else if(a){for(;o>i;i++)if(r=t.call(e[i],i,e[i]),r===!1)break}else for(i in e)if(r=t.call(e[i],i,e[i]),r===!1)break;return e},trim:b&&!b.call("\ufeff\u00a0")?function(e){return null==e?"":b.call(e)}:function(e){return null==e?"":(e+"").replace(C,"")},makeArray:function(e,t){var n=t||[];return null!=e&&(M(Object(e))?x.merge(n,"string"==typeof e?[e]:e):h.call(n,e)),n},inArray:function(e,t,n){var r;if(t){if(m)return m.call(t,e,n);for(r=t.length,n=n?0>n?Math.max(0,r+n):n:0;r>n;n++)if(n in t&&t[n]===e)return n}return-1},merge:function(e,n){var r=n.length,i=e.length,o=0;if("number"==typeof r)for(;r>o;o++)e[i++]=n[o];else while(n[o]!==t)e[i++]=n[o++];return e.length=i,e},grep:function(e,t,n){var r,i=[],o=0,a=e.length;for(n=!!n;a>o;o++)r=!!t(e[o],o),n!==r&&i.push(e[o]);return i},map:function(e,t,n){var r,i=0,o=e.length,a=M(e),s=[];if(a)for(;o>i;i++)r=t(e[i],i,n),null!=r&&(s[s.length]=r);else for(i in e)r=t(e[i],i,n),null!=r&&(s[s.length]=r);return d.apply([],s)},guid:1,proxy:function(e,n){var r,i,o;return"string"==typeof n&&(o=e[n],n=e,e=o),x.isFunction(e)?(r=g.call(arguments,2),i=function(){return e.apply(n||this,r.concat(g.call(arguments)))},i.guid=e.guid=e.guid||x.guid++,i):t},access:function(e,n,r,i,o,a,s){var l=0,u=e.length,c=null==r;if("object"===x.type(r)){o=!0;for(l in r)x.access(e,n,l,r[l],!0,a,s)}else if(i!==t&&(o=!0,x.isFunction(i)||(s=!0),c&&(s?(n.call(e,i),n=null):(c=n,n=function(e,t,n){return c.call(x(e),n)})),n))for(;u>l;l++)n(e[l],r,s?i:i.call(e[l],l,n(e[l],r)));return o?e:c?n.call(e):u?n(e[0],r):a},now:function(){return(new Date).getTime()},swap:function(e,t,n,r){var i,o,a={};for(o in t)a[o]=e.style[o],e.style[o]=t[o];i=n.apply(e,r||[]);for(o in t)e.style[o]=a[o];return i}}),x.ready.promise=function(t){if(!n)if(n=x.Deferred(),"complete"===a.readyState)setTimeout(x.ready);else if(a.addEventListener)a.addEventListener("DOMContentLoaded",q,!1),e.addEventListener("load",q,!1);else{a.attachEvent("onreadystatechange",q),e.attachEvent("onload",q);var r=!1;try{r=null==e.frameElement&&a.documentElement}catch(i){}r&&r.doScroll&&function o(){if(!x.isReady){try{r.doScroll("left")}catch(e){return setTimeout(o,50)}_(),x.ready()}}()}return n.promise(t)},x.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(e,t){c["[object "+t+"]"]=t.toLowerCase()});function M(e){var t=e.length,n=x.type(e);return x.isWindow(e)?!1:1===e.nodeType&&t?!0:"array"===n||"function"!==n&&(0===t||"number"==typeof t&&t>0&&t-1 in e)}r=x(a),function(e,t){var n,r,i,o,a,s,l,u,c,p,f,d,h,g,m,y,v,b="sizzle"+-new Date,w=e.document,T=0,C=0,N=lt(),k=lt(),E=lt(),S=!1,A=function(){return 0},j=typeof t,D=1<<31,L={}.hasOwnProperty,H=[],q=H.pop,_=H.push,M=H.push,O=H.slice,F=H.indexOf||function(e){var t=0,n=this.length;for(;n>t;t++)if(this[t]===e)return t;return-1},B="checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",P="[\\x20\\t\\r\\n\\f]",R="(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",W=R.replace("w","w#"),$="\\["+P+"*("+R+")"+P+"*(?:([*^$|!~]?=)"+P+"*(?:(['\"])((?:\\\\.|[^\\\\])*?)\\3|("+W+")|)|)"+P+"*\\]",I=":("+R+")(?:\\(((['\"])((?:\\\\.|[^\\\\])*?)\\3|((?:\\\\.|[^\\\\()[\\]]|"+$.replace(3,8)+")*)|.*)\\)|)",z=RegExp("^"+P+"+|((?:^|[^\\\\])(?:\\\\.)*)"+P+"+$","g"),X=RegExp("^"+P+"*,"+P+"*"),U=RegExp("^"+P+"*([>+~]|"+P+")"+P+"*"),V=RegExp(P+"*[+~]"),Y=RegExp("="+P+"*([^\\]'\"]*)"+P+"*\\]","g"),J=RegExp(I),G=RegExp("^"+W+"$"),Q={ID:RegExp("^#("+R+")"),CLASS:RegExp("^\\.("+R+")"),TAG:RegExp("^("+R.replace("w","w*")+")"),ATTR:RegExp("^"+$),PSEUDO:RegExp("^"+I),CHILD:RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+P+"*(even|odd|(([+-]|)(\\d*)n|)"+P+"*(?:([+-]|)"+P+"*(\\d+)|))"+P+"*\\)|)","i"),bool:RegExp("^(?:"+B+")$","i"),needsContext:RegExp("^"+P+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+P+"*((?:-\\d)?\\d*)"+P+"*\\)|)(?=[^-]|$)","i")},K=/^[^{]+\{\s*\[native \w/,Z=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,et=/^(?:input|select|textarea|button)$/i,tt=/^h\d$/i,nt=/'|\\/g,rt=RegExp("\\\\([\\da-f]{1,6}"+P+"?|("+P+")|.)","ig"),it=function(e,t,n){var r="0x"+t-65536;return r!==r||n?t:0>r?String.fromCharCode(r+65536):String.fromCharCode(55296|r>>10,56320|1023&r)};try{M.apply(H=O.call(w.childNodes),w.childNodes),H[w.childNodes.length].nodeType}catch(ot){M={apply:H.length?function(e,t){_.apply(e,O.call(t))}:function(e,t){var n=e.length,r=0;while(e[n++]=t[r++]);e.length=n-1}}}function at(e,t,n,i){var o,a,s,l,u,c,d,m,y,x;if((t?t.ownerDocument||t:w)!==f&&p(t),t=t||f,n=n||[],!e||"string"!=typeof e)return n;if(1!==(l=t.nodeType)&&9!==l)return[];if(h&&!i){if(o=Z.exec(e))if(s=o[1]){if(9===l){if(a=t.getElementById(s),!a||!a.parentNode)return n;if(a.id===s)return n.push(a),n}else if(t.ownerDocument&&(a=t.ownerDocument.getElementById(s))&&v(t,a)&&a.id===s)return n.push(a),n}else{if(o[2])return M.apply(n,t.getElementsByTagName(e)),n;if((s=o[3])&&r.getElementsByClassName&&t.getElementsByClassName)return M.apply(n,t.getElementsByClassName(s)),n}if(r.qsa&&(!g||!g.test(e))){if(m=d=b,y=t,x=9===l&&e,1===l&&"object"!==t.nodeName.toLowerCase()){c=bt(e),(d=t.getAttribute("id"))?m=d.replace(nt,"\\$&"):t.setAttribute("id",m),m="[id='"+m+"'] ",u=c.length;while(u--)c[u]=m+xt(c[u]);y=V.test(e)&&t.parentNode||t,x=c.join(",")}if(x)try{return M.apply(n,y.querySelectorAll(x)),n}catch(T){}finally{d||t.removeAttribute("id")}}}return At(e.replace(z,"$1"),t,n,i)}function st(e){return K.test(e+"")}function lt(){var e=[];function t(n,r){return e.push(n+=" ")>o.cacheLength&&delete t[e.shift()],t[n]=r}return t}function ut(e){return e[b]=!0,e}function ct(e){var t=f.createElement("div");try{return!!e(t)}catch(n){return!1}finally{t.parentNode&&t.parentNode.removeChild(t),t=null}}function pt(e,t,n){e=e.split("|");var r,i=e.length,a=n?null:t;while(i--)(r=o.attrHandle[e[i]])&&r!==t||(o.attrHandle[e[i]]=a)}function ft(e,t){var n=e.getAttributeNode(t);return n&&n.specified?n.value:e[t]===!0?t.toLowerCase():null}function dt(e,t){return e.getAttribute(t,"type"===t.toLowerCase()?1:2)}function ht(e){return"input"===e.nodeName.toLowerCase()?e.defaultValue:t}function gt(e,t){var n=t&&e,r=n&&1===e.nodeType&&1===t.nodeType&&(~t.sourceIndex||D)-(~e.sourceIndex||D);if(r)return r;if(n)while(n=n.nextSibling)if(n===t)return-1;return e?1:-1}function mt(e){return function(t){var n=t.nodeName.toLowerCase();return"input"===n&&t.type===e}}function yt(e){return function(t){var n=t.nodeName.toLowerCase();return("input"===n||"button"===n)&&t.type===e}}function vt(e){return ut(function(t){return t=+t,ut(function(n,r){var i,o=e([],n.length,t),a=o.length;while(a--)n[i=o[a]]&&(n[i]=!(r[i]=n[i]))})})}s=at.isXML=function(e){var t=e&&(e.ownerDocument||e).documentElement;return t?"HTML"!==t.nodeName:!1},r=at.support={},p=at.setDocument=function(e){var n=e?e.ownerDocument||e:w,i=n.parentWindow;return n!==f&&9===n.nodeType&&n.documentElement?(f=n,d=n.documentElement,h=!s(n),i&&i.frameElement&&i.attachEvent("onbeforeunload",function(){p()}),r.attributes=ct(function(e){return e.innerHTML="",pt("type|href|height|width",dt,"#"===e.firstChild.getAttribute("href")),pt(B,ft,null==e.getAttribute("disabled")),e.className="i",!e.getAttribute("className")}),r.input=ct(function(e){return e.innerHTML="",e.firstChild.setAttribute("value",""),""===e.firstChild.getAttribute("value")}),pt("value",ht,r.attributes&&r.input),r.getElementsByTagName=ct(function(e){return e.appendChild(n.createComment("")),!e.getElementsByTagName("*").length}),r.getElementsByClassName=ct(function(e){return e.innerHTML="
",e.firstChild.className="i",2===e.getElementsByClassName("i").length}),r.getById=ct(function(e){return d.appendChild(e).id=b,!n.getElementsByName||!n.getElementsByName(b).length}),r.getById?(o.find.ID=function(e,t){if(typeof t.getElementById!==j&&h){var n=t.getElementById(e);return n&&n.parentNode?[n]:[]}},o.filter.ID=function(e){var t=e.replace(rt,it);return function(e){return e.getAttribute("id")===t}}):(delete o.find.ID,o.filter.ID=function(e){var t=e.replace(rt,it);return function(e){var n=typeof e.getAttributeNode!==j&&e.getAttributeNode("id");return n&&n.value===t}}),o.find.TAG=r.getElementsByTagName?function(e,n){return typeof n.getElementsByTagName!==j?n.getElementsByTagName(e):t}:function(e,t){var n,r=[],i=0,o=t.getElementsByTagName(e);if("*"===e){while(n=o[i++])1===n.nodeType&&r.push(n);return r}return o},o.find.CLASS=r.getElementsByClassName&&function(e,n){return typeof n.getElementsByClassName!==j&&h?n.getElementsByClassName(e):t},m=[],g=[],(r.qsa=st(n.querySelectorAll))&&(ct(function(e){e.innerHTML="",e.querySelectorAll("[selected]").length||g.push("\\["+P+"*(?:value|"+B+")"),e.querySelectorAll(":checked").length||g.push(":checked")}),ct(function(e){var t=n.createElement("input");t.setAttribute("type","hidden"),e.appendChild(t).setAttribute("t",""),e.querySelectorAll("[t^='']").length&&g.push("[*^$]="+P+"*(?:''|\"\")"),e.querySelectorAll(":enabled").length||g.push(":enabled",":disabled"),e.querySelectorAll("*,:x"),g.push(",.*:")})),(r.matchesSelector=st(y=d.webkitMatchesSelector||d.mozMatchesSelector||d.oMatchesSelector||d.msMatchesSelector))&&ct(function(e){r.disconnectedMatch=y.call(e,"div"),y.call(e,"[s!='']:x"),m.push("!=",I)}),g=g.length&&RegExp(g.join("|")),m=m.length&&RegExp(m.join("|")),v=st(d.contains)||d.compareDocumentPosition?function(e,t){var n=9===e.nodeType?e.documentElement:e,r=t&&t.parentNode;return e===r||!(!r||1!==r.nodeType||!(n.contains?n.contains(r):e.compareDocumentPosition&&16&e.compareDocumentPosition(r)))}:function(e,t){if(t)while(t=t.parentNode)if(t===e)return!0;return!1},r.sortDetached=ct(function(e){return 1&e.compareDocumentPosition(n.createElement("div"))}),A=d.compareDocumentPosition?function(e,t){if(e===t)return S=!0,0;var i=t.compareDocumentPosition&&e.compareDocumentPosition&&e.compareDocumentPosition(t);return i?1&i||!r.sortDetached&&t.compareDocumentPosition(e)===i?e===n||v(w,e)?-1:t===n||v(w,t)?1:c?F.call(c,e)-F.call(c,t):0:4&i?-1:1:e.compareDocumentPosition?-1:1}:function(e,t){var r,i=0,o=e.parentNode,a=t.parentNode,s=[e],l=[t];if(e===t)return S=!0,0;if(!o||!a)return e===n?-1:t===n?1:o?-1:a?1:c?F.call(c,e)-F.call(c,t):0;if(o===a)return gt(e,t);r=e;while(r=r.parentNode)s.unshift(r);r=t;while(r=r.parentNode)l.unshift(r);while(s[i]===l[i])i++;return i?gt(s[i],l[i]):s[i]===w?-1:l[i]===w?1:0},n):f},at.matches=function(e,t){return at(e,null,null,t)},at.matchesSelector=function(e,t){if((e.ownerDocument||e)!==f&&p(e),t=t.replace(Y,"='$1']"),!(!r.matchesSelector||!h||m&&m.test(t)||g&&g.test(t)))try{var n=y.call(e,t);if(n||r.disconnectedMatch||e.document&&11!==e.document.nodeType)return n}catch(i){}return at(t,f,null,[e]).length>0},at.contains=function(e,t){return(e.ownerDocument||e)!==f&&p(e),v(e,t)},at.attr=function(e,n){(e.ownerDocument||e)!==f&&p(e);var i=o.attrHandle[n.toLowerCase()],a=i&&L.call(o.attrHandle,n.toLowerCase())?i(e,n,!h):t;return a===t?r.attributes||!h?e.getAttribute(n):(a=e.getAttributeNode(n))&&a.specified?a.value:null:a},at.error=function(e){throw Error("Syntax error, unrecognized expression: "+e)},at.uniqueSort=function(e){var t,n=[],i=0,o=0;if(S=!r.detectDuplicates,c=!r.sortStable&&e.slice(0),e.sort(A),S){while(t=e[o++])t===e[o]&&(i=n.push(o));while(i--)e.splice(n[i],1)}return e},a=at.getText=function(e){var t,n="",r=0,i=e.nodeType;if(i){if(1===i||9===i||11===i){if("string"==typeof e.textContent)return e.textContent;for(e=e.firstChild;e;e=e.nextSibling)n+=a(e)}else if(3===i||4===i)return e.nodeValue}else for(;t=e[r];r++)n+=a(t);return n},o=at.selectors={cacheLength:50,createPseudo:ut,match:Q,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(e){return e[1]=e[1].replace(rt,it),e[3]=(e[4]||e[5]||"").replace(rt,it),"~="===e[2]&&(e[3]=" "+e[3]+" "),e.slice(0,4)},CHILD:function(e){return e[1]=e[1].toLowerCase(),"nth"===e[1].slice(0,3)?(e[3]||at.error(e[0]),e[4]=+(e[4]?e[5]+(e[6]||1):2*("even"===e[3]||"odd"===e[3])),e[5]=+(e[7]+e[8]||"odd"===e[3])):e[3]&&at.error(e[0]),e},PSEUDO:function(e){var n,r=!e[5]&&e[2];return Q.CHILD.test(e[0])?null:(e[3]&&e[4]!==t?e[2]=e[4]:r&&J.test(r)&&(n=bt(r,!0))&&(n=r.indexOf(")",r.length-n)-r.length)&&(e[0]=e[0].slice(0,n),e[2]=r.slice(0,n)),e.slice(0,3))}},filter:{TAG:function(e){var t=e.replace(rt,it).toLowerCase();return"*"===e?function(){return!0}:function(e){return e.nodeName&&e.nodeName.toLowerCase()===t}},CLASS:function(e){var t=N[e+" "];return t||(t=RegExp("(^|"+P+")"+e+"("+P+"|$)"))&&N(e,function(e){return t.test("string"==typeof e.className&&e.className||typeof e.getAttribute!==j&&e.getAttribute("class")||"")})},ATTR:function(e,t,n){return function(r){var i=at.attr(r,e);return null==i?"!="===t:t?(i+="","="===t?i===n:"!="===t?i!==n:"^="===t?n&&0===i.indexOf(n):"*="===t?n&&i.indexOf(n)>-1:"$="===t?n&&i.slice(-n.length)===n:"~="===t?(" "+i+" ").indexOf(n)>-1:"|="===t?i===n||i.slice(0,n.length+1)===n+"-":!1):!0}},CHILD:function(e,t,n,r,i){var o="nth"!==e.slice(0,3),a="last"!==e.slice(-4),s="of-type"===t;return 1===r&&0===i?function(e){return!!e.parentNode}:function(t,n,l){var u,c,p,f,d,h,g=o!==a?"nextSibling":"previousSibling",m=t.parentNode,y=s&&t.nodeName.toLowerCase(),v=!l&&!s;if(m){if(o){while(g){p=t;while(p=p[g])if(s?p.nodeName.toLowerCase()===y:1===p.nodeType)return!1;h=g="only"===e&&!h&&"nextSibling"}return!0}if(h=[a?m.firstChild:m.lastChild],a&&v){c=m[b]||(m[b]={}),u=c[e]||[],d=u[0]===T&&u[1],f=u[0]===T&&u[2],p=d&&m.childNodes[d];while(p=++d&&p&&p[g]||(f=d=0)||h.pop())if(1===p.nodeType&&++f&&p===t){c[e]=[T,d,f];break}}else if(v&&(u=(t[b]||(t[b]={}))[e])&&u[0]===T)f=u[1];else while(p=++d&&p&&p[g]||(f=d=0)||h.pop())if((s?p.nodeName.toLowerCase()===y:1===p.nodeType)&&++f&&(v&&((p[b]||(p[b]={}))[e]=[T,f]),p===t))break;return f-=i,f===r||0===f%r&&f/r>=0}}},PSEUDO:function(e,t){var n,r=o.pseudos[e]||o.setFilters[e.toLowerCase()]||at.error("unsupported pseudo: "+e);return r[b]?r(t):r.length>1?(n=[e,e,"",t],o.setFilters.hasOwnProperty(e.toLowerCase())?ut(function(e,n){var i,o=r(e,t),a=o.length;while(a--)i=F.call(e,o[a]),e[i]=!(n[i]=o[a])}):function(e){return r(e,0,n)}):r}},pseudos:{not:ut(function(e){var t=[],n=[],r=l(e.replace(z,"$1"));return r[b]?ut(function(e,t,n,i){var o,a=r(e,null,i,[]),s=e.length;while(s--)(o=a[s])&&(e[s]=!(t[s]=o))}):function(e,i,o){return t[0]=e,r(t,null,o,n),!n.pop()}}),has:ut(function(e){return function(t){return at(e,t).length>0}}),contains:ut(function(e){return function(t){return(t.textContent||t.innerText||a(t)).indexOf(e)>-1}}),lang:ut(function(e){return G.test(e||"")||at.error("unsupported lang: "+e),e=e.replace(rt,it).toLowerCase(),function(t){var n;do if(n=h?t.lang:t.getAttribute("xml:lang")||t.getAttribute("lang"))return n=n.toLowerCase(),n===e||0===n.indexOf(e+"-");while((t=t.parentNode)&&1===t.nodeType);return!1}}),target:function(t){var n=e.location&&e.location.hash;return n&&n.slice(1)===t.id},root:function(e){return e===d},focus:function(e){return e===f.activeElement&&(!f.hasFocus||f.hasFocus())&&!!(e.type||e.href||~e.tabIndex)},enabled:function(e){return e.disabled===!1},disabled:function(e){return e.disabled===!0},checked:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&!!e.checked||"option"===t&&!!e.selected},selected:function(e){return e.parentNode&&e.parentNode.selectedIndex,e.selected===!0},empty:function(e){for(e=e.firstChild;e;e=e.nextSibling)if(e.nodeName>"@"||3===e.nodeType||4===e.nodeType)return!1;return!0},parent:function(e){return!o.pseudos.empty(e)},header:function(e){return tt.test(e.nodeName)},input:function(e){return et.test(e.nodeName)},button:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&"button"===e.type||"button"===t},text:function(e){var t;return"input"===e.nodeName.toLowerCase()&&"text"===e.type&&(null==(t=e.getAttribute("type"))||t.toLowerCase()===e.type)},first:vt(function(){return[0]}),last:vt(function(e,t){return[t-1]}),eq:vt(function(e,t,n){return[0>n?n+t:n]}),even:vt(function(e,t){var n=0;for(;t>n;n+=2)e.push(n);return e}),odd:vt(function(e,t){var n=1;for(;t>n;n+=2)e.push(n);return e}),lt:vt(function(e,t,n){var r=0>n?n+t:n;for(;--r>=0;)e.push(r);return e}),gt:vt(function(e,t,n){var r=0>n?n+t:n;for(;t>++r;)e.push(r);return e})}};for(n in{radio:!0,checkbox:!0,file:!0,password:!0,image:!0})o.pseudos[n]=mt(n);for(n in{submit:!0,reset:!0})o.pseudos[n]=yt(n);function bt(e,t){var n,r,i,a,s,l,u,c=k[e+" "];if(c)return t?0:c.slice(0);s=e,l=[],u=o.preFilter;while(s){(!n||(r=X.exec(s)))&&(r&&(s=s.slice(r[0].length)||s),l.push(i=[])),n=!1,(r=U.exec(s))&&(n=r.shift(),i.push({value:n,type:r[0].replace(z," ")}),s=s.slice(n.length));for(a in o.filter)!(r=Q[a].exec(s))||u[a]&&!(r=u[a](r))||(n=r.shift(),i.push({value:n,type:a,matches:r}),s=s.slice(n.length));if(!n)break}return t?s.length:s?at.error(e):k(e,l).slice(0)}function xt(e){var t=0,n=e.length,r="";for(;n>t;t++)r+=e[t].value;return r}function wt(e,t,n){var r=t.dir,o=n&&"parentNode"===r,a=C++;return t.first?function(t,n,i){while(t=t[r])if(1===t.nodeType||o)return e(t,n,i)}:function(t,n,s){var l,u,c,p=T+" "+a;if(s){while(t=t[r])if((1===t.nodeType||o)&&e(t,n,s))return!0}else while(t=t[r])if(1===t.nodeType||o)if(c=t[b]||(t[b]={}),(u=c[r])&&u[0]===p){if((l=u[1])===!0||l===i)return l===!0}else if(u=c[r]=[p],u[1]=e(t,n,s)||i,u[1]===!0)return!0}}function Tt(e){return e.length>1?function(t,n,r){var i=e.length;while(i--)if(!e[i](t,n,r))return!1;return!0}:e[0]}function Ct(e,t,n,r,i){var o,a=[],s=0,l=e.length,u=null!=t;for(;l>s;s++)(o=e[s])&&(!n||n(o,r,i))&&(a.push(o),u&&t.push(s));return a}function Nt(e,t,n,r,i,o){return r&&!r[b]&&(r=Nt(r)),i&&!i[b]&&(i=Nt(i,o)),ut(function(o,a,s,l){var u,c,p,f=[],d=[],h=a.length,g=o||St(t||"*",s.nodeType?[s]:s,[]),m=!e||!o&&t?g:Ct(g,f,e,s,l),y=n?i||(o?e:h||r)?[]:a:m;if(n&&n(m,y,s,l),r){u=Ct(y,d),r(u,[],s,l),c=u.length;while(c--)(p=u[c])&&(y[d[c]]=!(m[d[c]]=p))}if(o){if(i||e){if(i){u=[],c=y.length;while(c--)(p=y[c])&&u.push(m[c]=p);i(null,y=[],u,l)}c=y.length;while(c--)(p=y[c])&&(u=i?F.call(o,p):f[c])>-1&&(o[u]=!(a[u]=p))}}else y=Ct(y===a?y.splice(h,y.length):y),i?i(null,a,y,l):M.apply(a,y)})}function kt(e){var t,n,r,i=e.length,a=o.relative[e[0].type],s=a||o.relative[" "],l=a?1:0,c=wt(function(e){return e===t},s,!0),p=wt(function(e){return F.call(t,e)>-1},s,!0),f=[function(e,n,r){return!a&&(r||n!==u)||((t=n).nodeType?c(e,n,r):p(e,n,r))}];for(;i>l;l++)if(n=o.relative[e[l].type])f=[wt(Tt(f),n)];else{if(n=o.filter[e[l].type].apply(null,e[l].matches),n[b]){for(r=++l;i>r;r++)if(o.relative[e[r].type])break;return Nt(l>1&&Tt(f),l>1&&xt(e.slice(0,l-1).concat({value:" "===e[l-2].type?"*":""})).replace(z,"$1"),n,r>l&&kt(e.slice(l,r)),i>r&&kt(e=e.slice(r)),i>r&&xt(e))}f.push(n)}return Tt(f)}function Et(e,t){var n=0,r=t.length>0,a=e.length>0,s=function(s,l,c,p,d){var h,g,m,y=[],v=0,b="0",x=s&&[],w=null!=d,C=u,N=s||a&&o.find.TAG("*",d&&l.parentNode||l),k=T+=null==C?1:Math.random()||.1;for(w&&(u=l!==f&&l,i=n);null!=(h=N[b]);b++){if(a&&h){g=0;while(m=e[g++])if(m(h,l,c)){p.push(h);break}w&&(T=k,i=++n)}r&&((h=!m&&h)&&v--,s&&x.push(h))}if(v+=b,r&&b!==v){g=0;while(m=t[g++])m(x,y,l,c);if(s){if(v>0)while(b--)x[b]||y[b]||(y[b]=q.call(p));y=Ct(y)}M.apply(p,y),w&&!s&&y.length>0&&v+t.length>1&&at.uniqueSort(p)}return w&&(T=k,u=C),x};return r?ut(s):s}l=at.compile=function(e,t){var n,r=[],i=[],o=E[e+" "];if(!o){t||(t=bt(e)),n=t.length;while(n--)o=kt(t[n]),o[b]?r.push(o):i.push(o);o=E(e,Et(i,r))}return o};function St(e,t,n){var r=0,i=t.length;for(;i>r;r++)at(e,t[r],n);return n}function At(e,t,n,i){var a,s,u,c,p,f=bt(e);if(!i&&1===f.length){if(s=f[0]=f[0].slice(0),s.length>2&&"ID"===(u=s[0]).type&&r.getById&&9===t.nodeType&&h&&o.relative[s[1].type]){if(t=(o.find.ID(u.matches[0].replace(rt,it),t)||[])[0],!t)return n;e=e.slice(s.shift().value.length)}a=Q.needsContext.test(e)?0:s.length;while(a--){if(u=s[a],o.relative[c=u.type])break;if((p=o.find[c])&&(i=p(u.matches[0].replace(rt,it),V.test(s[0].type)&&t.parentNode||t))){if(s.splice(a,1),e=i.length&&xt(s),!e)return M.apply(n,i),n;break}}}return l(e,f)(i,t,!h,n,V.test(e)),n}o.pseudos.nth=o.pseudos.eq;function jt(){}jt.prototype=o.filters=o.pseudos,o.setFilters=new jt,r.sortStable=b.split("").sort(A).join("")===b,p(),[0,0].sort(A),r.detectDuplicates=S,x.find=at,x.expr=at.selectors,x.expr[":"]=x.expr.pseudos,x.unique=at.uniqueSort,x.text=at.getText,x.isXMLDoc=at.isXML,x.contains=at.contains}(e);var O={};function F(e){var t=O[e]={};return x.each(e.match(T)||[],function(e,n){t[n]=!0}),t}x.Callbacks=function(e){e="string"==typeof e?O[e]||F(e):x.extend({},e);var n,r,i,o,a,s,l=[],u=!e.once&&[],c=function(t){for(r=e.memory&&t,i=!0,a=s||0,s=0,o=l.length,n=!0;l&&o>a;a++)if(l[a].apply(t[0],t[1])===!1&&e.stopOnFalse){r=!1;break}n=!1,l&&(u?u.length&&c(u.shift()):r?l=[]:p.disable())},p={add:function(){if(l){var t=l.length;(function i(t){x.each(t,function(t,n){var r=x.type(n);"function"===r?e.unique&&p.has(n)||l.push(n):n&&n.length&&"string"!==r&&i(n)})})(arguments),n?o=l.length:r&&(s=t,c(r))}return this},remove:function(){return l&&x.each(arguments,function(e,t){var r;while((r=x.inArray(t,l,r))>-1)l.splice(r,1),n&&(o>=r&&o--,a>=r&&a--)}),this},has:function(e){return e?x.inArray(e,l)>-1:!(!l||!l.length)},empty:function(){return l=[],o=0,this},disable:function(){return l=u=r=t,this},disabled:function(){return!l},lock:function(){return u=t,r||p.disable(),this},locked:function(){return!u},fireWith:function(e,t){return t=t||[],t=[e,t.slice?t.slice():t],!l||i&&!u||(n?u.push(t):c(t)),this},fire:function(){return p.fireWith(this,arguments),this},fired:function(){return!!i}};return p},x.extend({Deferred:function(e){var t=[["resolve","done",x.Callbacks("once memory"),"resolved"],["reject","fail",x.Callbacks("once memory"),"rejected"],["notify","progress",x.Callbacks("memory")]],n="pending",r={state:function(){return n},always:function(){return i.done(arguments).fail(arguments),this},then:function(){var e=arguments;return x.Deferred(function(n){x.each(t,function(t,o){var a=o[0],s=x.isFunction(e[t])&&e[t];i[o[1]](function(){var e=s&&s.apply(this,arguments);e&&x.isFunction(e.promise)?e.promise().done(n.resolve).fail(n.reject).progress(n.notify):n[a+"With"](this===r?n.promise():this,s?[e]:arguments)})}),e=null}).promise()},promise:function(e){return null!=e?x.extend(e,r):r}},i={};return r.pipe=r.then,x.each(t,function(e,o){var a=o[2],s=o[3];r[o[1]]=a.add,s&&a.add(function(){n=s},t[1^e][2].disable,t[2][2].lock),i[o[0]]=function(){return i[o[0]+"With"](this===i?r:this,arguments),this},i[o[0]+"With"]=a.fireWith}),r.promise(i),e&&e.call(i,i),i},when:function(e){var t=0,n=g.call(arguments),r=n.length,i=1!==r||e&&x.isFunction(e.promise)?r:0,o=1===i?e:x.Deferred(),a=function(e,t,n){return function(r){t[e]=this,n[e]=arguments.length>1?g.call(arguments):r,n===s?o.notifyWith(t,n):--i||o.resolveWith(t,n)}},s,l,u;if(r>1)for(s=Array(r),l=Array(r),u=Array(r);r>t;t++)n[t]&&x.isFunction(n[t].promise)?n[t].promise().done(a(t,u,n)).fail(o.reject).progress(a(t,l,s)):--i;return i||o.resolveWith(u,n),o.promise()}}),x.support=function(t){var n,r,o,s,l,u,c,p,f,d=a.createElement("div");if(d.setAttribute("className","t"),d.innerHTML="
a",n=d.getElementsByTagName("*")||[],r=d.getElementsByTagName("a")[0],!r||!r.style||!n.length)return t;s=a.createElement("select"),u=s.appendChild(a.createElement("option")),o=d.getElementsByTagName("input")[0],r.style.cssText="top:1px;float:left;opacity:.5",t.getSetAttribute="t"!==d.className,t.leadingWhitespace=3===d.firstChild.nodeType,t.tbody=!d.getElementsByTagName("tbody").length,t.htmlSerialize=!!d.getElementsByTagName("link").length,t.style=/top/.test(r.getAttribute("style")),t.hrefNormalized="/a"===r.getAttribute("href"),t.opacity=/^0.5/.test(r.style.opacity),t.cssFloat=!!r.style.cssFloat,t.checkOn=!!o.value,t.optSelected=u.selected,t.enctype=!!a.createElement("form").enctype,t.html5Clone="<:nav>"!==a.createElement("nav").cloneNode(!0).outerHTML,t.inlineBlockNeedsLayout=!1,t.shrinkWrapBlocks=!1,t.pixelPosition=!1,t.deleteExpando=!0,t.noCloneEvent=!0,t.reliableMarginRight=!0,t.boxSizingReliable=!0,o.checked=!0,t.noCloneChecked=o.cloneNode(!0).checked,s.disabled=!0,t.optDisabled=!u.disabled;try{delete d.test}catch(h){t.deleteExpando=!1}o=a.createElement("input"),o.setAttribute("value",""),t.input=""===o.getAttribute("value"),o.value="t",o.setAttribute("type","radio"),t.radioValue="t"===o.value,o.setAttribute("checked","t"),o.setAttribute("name","t"),l=a.createDocumentFragment(),l.appendChild(o),t.appendChecked=o.checked,t.checkClone=l.cloneNode(!0).cloneNode(!0).lastChild.checked,d.attachEvent&&(d.attachEvent("onclick",function(){t.noCloneEvent=!1}),d.cloneNode(!0).click());for(f in{submit:!0,change:!0,focusin:!0})d.setAttribute(c="on"+f,"t"),t[f+"Bubbles"]=c in e||d.attributes[c].expando===!1;d.style.backgroundClip="content-box",d.cloneNode(!0).style.backgroundClip="",t.clearCloneStyle="content-box"===d.style.backgroundClip;for(f in x(t))break;return t.ownLast="0"!==f,x(function(){var n,r,o,s="padding:0;margin:0;border:0;display:block;box-sizing:content-box;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;",l=a.getElementsByTagName("body")[0];l&&(n=a.createElement("div"),n.style.cssText="border:0;width:0;height:0;position:absolute;top:0;left:-9999px;margin-top:1px",l.appendChild(n).appendChild(d),d.innerHTML="
t
",o=d.getElementsByTagName("td"),o[0].style.cssText="padding:0;margin:0;border:0;display:none",p=0===o[0].offsetHeight,o[0].style.display="",o[1].style.display="none",t.reliableHiddenOffsets=p&&0===o[0].offsetHeight,d.innerHTML="",d.style.cssText="box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;padding:1px;border:1px;display:block;width:4px;margin-top:1%;position:absolute;top:1%;",x.swap(l,null!=l.style.zoom?{zoom:1}:{},function(){t.boxSizing=4===d.offsetWidth}),e.getComputedStyle&&(t.pixelPosition="1%"!==(e.getComputedStyle(d,null)||{}).top,t.boxSizingReliable="4px"===(e.getComputedStyle(d,null)||{width:"4px"}).width,r=d.appendChild(a.createElement("div")),r.style.cssText=d.style.cssText=s,r.style.marginRight=r.style.width="0",d.style.width="1px",t.reliableMarginRight=!parseFloat((e.getComputedStyle(r,null)||{}).marginRight)),typeof d.style.zoom!==i&&(d.innerHTML="",d.style.cssText=s+"width:1px;padding:1px;display:inline;zoom:1",t.inlineBlockNeedsLayout=3===d.offsetWidth,d.style.display="block",d.innerHTML="
",d.firstChild.style.width="5px",t.shrinkWrapBlocks=3!==d.offsetWidth,t.inlineBlockNeedsLayout&&(l.style.zoom=1)),l.removeChild(n),n=d=o=r=null) -}),n=s=l=u=r=o=null,t}({});var B=/(?:\{[\s\S]*\}|\[[\s\S]*\])$/,P=/([A-Z])/g;function R(e,n,r,i){if(x.acceptData(e)){var o,a,s=x.expando,l=e.nodeType,u=l?x.cache:e,c=l?e[s]:e[s]&&s;if(c&&u[c]&&(i||u[c].data)||r!==t||"string"!=typeof n)return c||(c=l?e[s]=p.pop()||x.guid++:s),u[c]||(u[c]=l?{}:{toJSON:x.noop}),("object"==typeof n||"function"==typeof n)&&(i?u[c]=x.extend(u[c],n):u[c].data=x.extend(u[c].data,n)),a=u[c],i||(a.data||(a.data={}),a=a.data),r!==t&&(a[x.camelCase(n)]=r),"string"==typeof n?(o=a[n],null==o&&(o=a[x.camelCase(n)])):o=a,o}}function W(e,t,n){if(x.acceptData(e)){var r,i,o=e.nodeType,a=o?x.cache:e,s=o?e[x.expando]:x.expando;if(a[s]){if(t&&(r=n?a[s]:a[s].data)){x.isArray(t)?t=t.concat(x.map(t,x.camelCase)):t in r?t=[t]:(t=x.camelCase(t),t=t in r?[t]:t.split(" ")),i=t.length;while(i--)delete r[t[i]];if(n?!I(r):!x.isEmptyObject(r))return}(n||(delete a[s].data,I(a[s])))&&(o?x.cleanData([e],!0):x.support.deleteExpando||a!=a.window?delete a[s]:a[s]=null)}}}x.extend({cache:{},noData:{applet:!0,embed:!0,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"},hasData:function(e){return e=e.nodeType?x.cache[e[x.expando]]:e[x.expando],!!e&&!I(e)},data:function(e,t,n){return R(e,t,n)},removeData:function(e,t){return W(e,t)},_data:function(e,t,n){return R(e,t,n,!0)},_removeData:function(e,t){return W(e,t,!0)},acceptData:function(e){if(e.nodeType&&1!==e.nodeType&&9!==e.nodeType)return!1;var t=e.nodeName&&x.noData[e.nodeName.toLowerCase()];return!t||t!==!0&&e.getAttribute("classid")===t}}),x.fn.extend({data:function(e,n){var r,i,o=null,a=0,s=this[0];if(e===t){if(this.length&&(o=x.data(s),1===s.nodeType&&!x._data(s,"parsedAttrs"))){for(r=s.attributes;r.length>a;a++)i=r[a].name,0===i.indexOf("data-")&&(i=x.camelCase(i.slice(5)),$(s,i,o[i]));x._data(s,"parsedAttrs",!0)}return o}return"object"==typeof e?this.each(function(){x.data(this,e)}):arguments.length>1?this.each(function(){x.data(this,e,n)}):s?$(s,e,x.data(s,e)):null},removeData:function(e){return this.each(function(){x.removeData(this,e)})}});function $(e,n,r){if(r===t&&1===e.nodeType){var i="data-"+n.replace(P,"-$1").toLowerCase();if(r=e.getAttribute(i),"string"==typeof r){try{r="true"===r?!0:"false"===r?!1:"null"===r?null:+r+""===r?+r:B.test(r)?x.parseJSON(r):r}catch(o){}x.data(e,n,r)}else r=t}return r}function I(e){var t;for(t in e)if(("data"!==t||!x.isEmptyObject(e[t]))&&"toJSON"!==t)return!1;return!0}x.extend({queue:function(e,n,r){var i;return e?(n=(n||"fx")+"queue",i=x._data(e,n),r&&(!i||x.isArray(r)?i=x._data(e,n,x.makeArray(r)):i.push(r)),i||[]):t},dequeue:function(e,t){t=t||"fx";var n=x.queue(e,t),r=n.length,i=n.shift(),o=x._queueHooks(e,t),a=function(){x.dequeue(e,t)};"inprogress"===i&&(i=n.shift(),r--),i&&("fx"===t&&n.unshift("inprogress"),delete o.stop,i.call(e,a,o)),!r&&o&&o.empty.fire()},_queueHooks:function(e,t){var n=t+"queueHooks";return x._data(e,n)||x._data(e,n,{empty:x.Callbacks("once memory").add(function(){x._removeData(e,t+"queue"),x._removeData(e,n)})})}}),x.fn.extend({queue:function(e,n){var r=2;return"string"!=typeof e&&(n=e,e="fx",r--),r>arguments.length?x.queue(this[0],e):n===t?this:this.each(function(){var t=x.queue(this,e,n);x._queueHooks(this,e),"fx"===e&&"inprogress"!==t[0]&&x.dequeue(this,e)})},dequeue:function(e){return this.each(function(){x.dequeue(this,e)})},delay:function(e,t){return e=x.fx?x.fx.speeds[e]||e:e,t=t||"fx",this.queue(t,function(t,n){var r=setTimeout(t,e);n.stop=function(){clearTimeout(r)}})},clearQueue:function(e){return this.queue(e||"fx",[])},promise:function(e,n){var r,i=1,o=x.Deferred(),a=this,s=this.length,l=function(){--i||o.resolveWith(a,[a])};"string"!=typeof e&&(n=e,e=t),e=e||"fx";while(s--)r=x._data(a[s],e+"queueHooks"),r&&r.empty&&(i++,r.empty.add(l));return l(),o.promise(n)}});var z,X,U=/[\t\r\n\f]/g,V=/\r/g,Y=/^(?:input|select|textarea|button|object)$/i,J=/^(?:a|area)$/i,G=/^(?:checked|selected)$/i,Q=x.support.getSetAttribute,K=x.support.input;x.fn.extend({attr:function(e,t){return x.access(this,x.attr,e,t,arguments.length>1)},removeAttr:function(e){return this.each(function(){x.removeAttr(this,e)})},prop:function(e,t){return x.access(this,x.prop,e,t,arguments.length>1)},removeProp:function(e){return e=x.propFix[e]||e,this.each(function(){try{this[e]=t,delete this[e]}catch(n){}})},addClass:function(e){var t,n,r,i,o,a=0,s=this.length,l="string"==typeof e&&e;if(x.isFunction(e))return this.each(function(t){x(this).addClass(e.call(this,t,this.className))});if(l)for(t=(e||"").match(T)||[];s>a;a++)if(n=this[a],r=1===n.nodeType&&(n.className?(" "+n.className+" ").replace(U," "):" ")){o=0;while(i=t[o++])0>r.indexOf(" "+i+" ")&&(r+=i+" ");n.className=x.trim(r)}return this},removeClass:function(e){var t,n,r,i,o,a=0,s=this.length,l=0===arguments.length||"string"==typeof e&&e;if(x.isFunction(e))return this.each(function(t){x(this).removeClass(e.call(this,t,this.className))});if(l)for(t=(e||"").match(T)||[];s>a;a++)if(n=this[a],r=1===n.nodeType&&(n.className?(" "+n.className+" ").replace(U," "):"")){o=0;while(i=t[o++])while(r.indexOf(" "+i+" ")>=0)r=r.replace(" "+i+" "," ");n.className=e?x.trim(r):""}return this},toggleClass:function(e,t){var n=typeof e,r="boolean"==typeof t;return x.isFunction(e)?this.each(function(n){x(this).toggleClass(e.call(this,n,this.className,t),t)}):this.each(function(){if("string"===n){var o,a=0,s=x(this),l=t,u=e.match(T)||[];while(o=u[a++])l=r?l:!s.hasClass(o),s[l?"addClass":"removeClass"](o)}else(n===i||"boolean"===n)&&(this.className&&x._data(this,"__className__",this.className),this.className=this.className||e===!1?"":x._data(this,"__className__")||"")})},hasClass:function(e){var t=" "+e+" ",n=0,r=this.length;for(;r>n;n++)if(1===this[n].nodeType&&(" "+this[n].className+" ").replace(U," ").indexOf(t)>=0)return!0;return!1},val:function(e){var n,r,i,o=this[0];{if(arguments.length)return i=x.isFunction(e),this.each(function(n){var o;1===this.nodeType&&(o=i?e.call(this,n,x(this).val()):e,null==o?o="":"number"==typeof o?o+="":x.isArray(o)&&(o=x.map(o,function(e){return null==e?"":e+""})),r=x.valHooks[this.type]||x.valHooks[this.nodeName.toLowerCase()],r&&"set"in r&&r.set(this,o,"value")!==t||(this.value=o))});if(o)return r=x.valHooks[o.type]||x.valHooks[o.nodeName.toLowerCase()],r&&"get"in r&&(n=r.get(o,"value"))!==t?n:(n=o.value,"string"==typeof n?n.replace(V,""):null==n?"":n)}}}),x.extend({valHooks:{option:{get:function(e){var t=x.find.attr(e,"value");return null!=t?t:e.text}},select:{get:function(e){var t,n,r=e.options,i=e.selectedIndex,o="select-one"===e.type||0>i,a=o?null:[],s=o?i+1:r.length,l=0>i?s:o?i:0;for(;s>l;l++)if(n=r[l],!(!n.selected&&l!==i||(x.support.optDisabled?n.disabled:null!==n.getAttribute("disabled"))||n.parentNode.disabled&&x.nodeName(n.parentNode,"optgroup"))){if(t=x(n).val(),o)return t;a.push(t)}return a},set:function(e,t){var n,r,i=e.options,o=x.makeArray(t),a=i.length;while(a--)r=i[a],(r.selected=x.inArray(x(r).val(),o)>=0)&&(n=!0);return n||(e.selectedIndex=-1),o}}},attr:function(e,n,r){var o,a,s=e.nodeType;if(e&&3!==s&&8!==s&&2!==s)return typeof e.getAttribute===i?x.prop(e,n,r):(1===s&&x.isXMLDoc(e)||(n=n.toLowerCase(),o=x.attrHooks[n]||(x.expr.match.bool.test(n)?X:z)),r===t?o&&"get"in o&&null!==(a=o.get(e,n))?a:(a=x.find.attr(e,n),null==a?t:a):null!==r?o&&"set"in o&&(a=o.set(e,r,n))!==t?a:(e.setAttribute(n,r+""),r):(x.removeAttr(e,n),t))},removeAttr:function(e,t){var n,r,i=0,o=t&&t.match(T);if(o&&1===e.nodeType)while(n=o[i++])r=x.propFix[n]||n,x.expr.match.bool.test(n)?K&&Q||!G.test(n)?e[r]=!1:e[x.camelCase("default-"+n)]=e[r]=!1:x.attr(e,n,""),e.removeAttribute(Q?n:r)},attrHooks:{type:{set:function(e,t){if(!x.support.radioValue&&"radio"===t&&x.nodeName(e,"input")){var n=e.value;return e.setAttribute("type",t),n&&(e.value=n),t}}}},propFix:{"for":"htmlFor","class":"className"},prop:function(e,n,r){var i,o,a,s=e.nodeType;if(e&&3!==s&&8!==s&&2!==s)return a=1!==s||!x.isXMLDoc(e),a&&(n=x.propFix[n]||n,o=x.propHooks[n]),r!==t?o&&"set"in o&&(i=o.set(e,r,n))!==t?i:e[n]=r:o&&"get"in o&&null!==(i=o.get(e,n))?i:e[n]},propHooks:{tabIndex:{get:function(e){var t=x.find.attr(e,"tabindex");return t?parseInt(t,10):Y.test(e.nodeName)||J.test(e.nodeName)&&e.href?0:-1}}}}),X={set:function(e,t,n){return t===!1?x.removeAttr(e,n):K&&Q||!G.test(n)?e.setAttribute(!Q&&x.propFix[n]||n,n):e[x.camelCase("default-"+n)]=e[n]=!0,n}},x.each(x.expr.match.bool.source.match(/\w+/g),function(e,n){var r=x.expr.attrHandle[n]||x.find.attr;x.expr.attrHandle[n]=K&&Q||!G.test(n)?function(e,n,i){var o=x.expr.attrHandle[n],a=i?t:(x.expr.attrHandle[n]=t)!=r(e,n,i)?n.toLowerCase():null;return x.expr.attrHandle[n]=o,a}:function(e,n,r){return r?t:e[x.camelCase("default-"+n)]?n.toLowerCase():null}}),K&&Q||(x.attrHooks.value={set:function(e,n,r){return x.nodeName(e,"input")?(e.defaultValue=n,t):z&&z.set(e,n,r)}}),Q||(z={set:function(e,n,r){var i=e.getAttributeNode(r);return i||e.setAttributeNode(i=e.ownerDocument.createAttribute(r)),i.value=n+="","value"===r||n===e.getAttribute(r)?n:t}},x.expr.attrHandle.id=x.expr.attrHandle.name=x.expr.attrHandle.coords=function(e,n,r){var i;return r?t:(i=e.getAttributeNode(n))&&""!==i.value?i.value:null},x.valHooks.button={get:function(e,n){var r=e.getAttributeNode(n);return r&&r.specified?r.value:t},set:z.set},x.attrHooks.contenteditable={set:function(e,t,n){z.set(e,""===t?!1:t,n)}},x.each(["width","height"],function(e,n){x.attrHooks[n]={set:function(e,r){return""===r?(e.setAttribute(n,"auto"),r):t}}})),x.support.hrefNormalized||x.each(["href","src"],function(e,t){x.propHooks[t]={get:function(e){return e.getAttribute(t,4)}}}),x.support.style||(x.attrHooks.style={get:function(e){return e.style.cssText||t},set:function(e,t){return e.style.cssText=t+""}}),x.support.optSelected||(x.propHooks.selected={get:function(e){var t=e.parentNode;return t&&(t.selectedIndex,t.parentNode&&t.parentNode.selectedIndex),null}}),x.each(["tabIndex","readOnly","maxLength","cellSpacing","cellPadding","rowSpan","colSpan","useMap","frameBorder","contentEditable"],function(){x.propFix[this.toLowerCase()]=this}),x.support.enctype||(x.propFix.enctype="encoding"),x.each(["radio","checkbox"],function(){x.valHooks[this]={set:function(e,n){return x.isArray(n)?e.checked=x.inArray(x(e).val(),n)>=0:t}},x.support.checkOn||(x.valHooks[this].get=function(e){return null===e.getAttribute("value")?"on":e.value})});var Z=/^(?:input|select|textarea)$/i,et=/^key/,tt=/^(?:mouse|contextmenu)|click/,nt=/^(?:focusinfocus|focusoutblur)$/,rt=/^([^.]*)(?:\.(.+)|)$/;function it(){return!0}function ot(){return!1}function at(){try{return a.activeElement}catch(e){}}x.event={global:{},add:function(e,n,r,o,a){var s,l,u,c,p,f,d,h,g,m,y,v=x._data(e);if(v){r.handler&&(c=r,r=c.handler,a=c.selector),r.guid||(r.guid=x.guid++),(l=v.events)||(l=v.events={}),(f=v.handle)||(f=v.handle=function(e){return typeof x===i||e&&x.event.triggered===e.type?t:x.event.dispatch.apply(f.elem,arguments)},f.elem=e),n=(n||"").match(T)||[""],u=n.length;while(u--)s=rt.exec(n[u])||[],g=y=s[1],m=(s[2]||"").split(".").sort(),g&&(p=x.event.special[g]||{},g=(a?p.delegateType:p.bindType)||g,p=x.event.special[g]||{},d=x.extend({type:g,origType:y,data:o,handler:r,guid:r.guid,selector:a,needsContext:a&&x.expr.match.needsContext.test(a),namespace:m.join(".")},c),(h=l[g])||(h=l[g]=[],h.delegateCount=0,p.setup&&p.setup.call(e,o,m,f)!==!1||(e.addEventListener?e.addEventListener(g,f,!1):e.attachEvent&&e.attachEvent("on"+g,f))),p.add&&(p.add.call(e,d),d.handler.guid||(d.handler.guid=r.guid)),a?h.splice(h.delegateCount++,0,d):h.push(d),x.event.global[g]=!0);e=null}},remove:function(e,t,n,r,i){var o,a,s,l,u,c,p,f,d,h,g,m=x.hasData(e)&&x._data(e);if(m&&(c=m.events)){t=(t||"").match(T)||[""],u=t.length;while(u--)if(s=rt.exec(t[u])||[],d=g=s[1],h=(s[2]||"").split(".").sort(),d){p=x.event.special[d]||{},d=(r?p.delegateType:p.bindType)||d,f=c[d]||[],s=s[2]&&RegExp("(^|\\.)"+h.join("\\.(?:.*\\.|)")+"(\\.|$)"),l=o=f.length;while(o--)a=f[o],!i&&g!==a.origType||n&&n.guid!==a.guid||s&&!s.test(a.namespace)||r&&r!==a.selector&&("**"!==r||!a.selector)||(f.splice(o,1),a.selector&&f.delegateCount--,p.remove&&p.remove.call(e,a));l&&!f.length&&(p.teardown&&p.teardown.call(e,h,m.handle)!==!1||x.removeEvent(e,d,m.handle),delete c[d])}else for(d in c)x.event.remove(e,d+t[u],n,r,!0);x.isEmptyObject(c)&&(delete m.handle,x._removeData(e,"events"))}},trigger:function(n,r,i,o){var s,l,u,c,p,f,d,h=[i||a],g=v.call(n,"type")?n.type:n,m=v.call(n,"namespace")?n.namespace.split("."):[];if(u=f=i=i||a,3!==i.nodeType&&8!==i.nodeType&&!nt.test(g+x.event.triggered)&&(g.indexOf(".")>=0&&(m=g.split("."),g=m.shift(),m.sort()),l=0>g.indexOf(":")&&"on"+g,n=n[x.expando]?n:new x.Event(g,"object"==typeof n&&n),n.isTrigger=o?2:3,n.namespace=m.join("."),n.namespace_re=n.namespace?RegExp("(^|\\.)"+m.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,n.result=t,n.target||(n.target=i),r=null==r?[n]:x.makeArray(r,[n]),p=x.event.special[g]||{},o||!p.trigger||p.trigger.apply(i,r)!==!1)){if(!o&&!p.noBubble&&!x.isWindow(i)){for(c=p.delegateType||g,nt.test(c+g)||(u=u.parentNode);u;u=u.parentNode)h.push(u),f=u;f===(i.ownerDocument||a)&&h.push(f.defaultView||f.parentWindow||e)}d=0;while((u=h[d++])&&!n.isPropagationStopped())n.type=d>1?c:p.bindType||g,s=(x._data(u,"events")||{})[n.type]&&x._data(u,"handle"),s&&s.apply(u,r),s=l&&u[l],s&&x.acceptData(u)&&s.apply&&s.apply(u,r)===!1&&n.preventDefault();if(n.type=g,!o&&!n.isDefaultPrevented()&&(!p._default||p._default.apply(h.pop(),r)===!1)&&x.acceptData(i)&&l&&i[g]&&!x.isWindow(i)){f=i[l],f&&(i[l]=null),x.event.triggered=g;try{i[g]()}catch(y){}x.event.triggered=t,f&&(i[l]=f)}return n.result}},dispatch:function(e){e=x.event.fix(e);var n,r,i,o,a,s=[],l=g.call(arguments),u=(x._data(this,"events")||{})[e.type]||[],c=x.event.special[e.type]||{};if(l[0]=e,e.delegateTarget=this,!c.preDispatch||c.preDispatch.call(this,e)!==!1){s=x.event.handlers.call(this,e,u),n=0;while((o=s[n++])&&!e.isPropagationStopped()){e.currentTarget=o.elem,a=0;while((i=o.handlers[a++])&&!e.isImmediatePropagationStopped())(!e.namespace_re||e.namespace_re.test(i.namespace))&&(e.handleObj=i,e.data=i.data,r=((x.event.special[i.origType]||{}).handle||i.handler).apply(o.elem,l),r!==t&&(e.result=r)===!1&&(e.preventDefault(),e.stopPropagation()))}return c.postDispatch&&c.postDispatch.call(this,e),e.result}},handlers:function(e,n){var r,i,o,a,s=[],l=n.delegateCount,u=e.target;if(l&&u.nodeType&&(!e.button||"click"!==e.type))for(;u!=this;u=u.parentNode||this)if(1===u.nodeType&&(u.disabled!==!0||"click"!==e.type)){for(o=[],a=0;l>a;a++)i=n[a],r=i.selector+" ",o[r]===t&&(o[r]=i.needsContext?x(r,this).index(u)>=0:x.find(r,this,null,[u]).length),o[r]&&o.push(i);o.length&&s.push({elem:u,handlers:o})}return n.length>l&&s.push({elem:this,handlers:n.slice(l)}),s},fix:function(e){if(e[x.expando])return e;var t,n,r,i=e.type,o=e,s=this.fixHooks[i];s||(this.fixHooks[i]=s=tt.test(i)?this.mouseHooks:et.test(i)?this.keyHooks:{}),r=s.props?this.props.concat(s.props):this.props,e=new x.Event(o),t=r.length;while(t--)n=r[t],e[n]=o[n];return e.target||(e.target=o.srcElement||a),3===e.target.nodeType&&(e.target=e.target.parentNode),e.metaKey=!!e.metaKey,s.filter?s.filter(e,o):e},props:"altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),fixHooks:{},keyHooks:{props:"char charCode key keyCode".split(" "),filter:function(e,t){return null==e.which&&(e.which=null!=t.charCode?t.charCode:t.keyCode),e}},mouseHooks:{props:"button buttons clientX clientY fromElement offsetX offsetY pageX pageY screenX screenY toElement".split(" "),filter:function(e,n){var r,i,o,s=n.button,l=n.fromElement;return null==e.pageX&&null!=n.clientX&&(i=e.target.ownerDocument||a,o=i.documentElement,r=i.body,e.pageX=n.clientX+(o&&o.scrollLeft||r&&r.scrollLeft||0)-(o&&o.clientLeft||r&&r.clientLeft||0),e.pageY=n.clientY+(o&&o.scrollTop||r&&r.scrollTop||0)-(o&&o.clientTop||r&&r.clientTop||0)),!e.relatedTarget&&l&&(e.relatedTarget=l===e.target?n.toElement:l),e.which||s===t||(e.which=1&s?1:2&s?3:4&s?2:0),e}},special:{load:{noBubble:!0},focus:{trigger:function(){if(this!==at()&&this.focus)try{return this.focus(),!1}catch(e){}},delegateType:"focusin"},blur:{trigger:function(){return this===at()&&this.blur?(this.blur(),!1):t},delegateType:"focusout"},click:{trigger:function(){return x.nodeName(this,"input")&&"checkbox"===this.type&&this.click?(this.click(),!1):t},_default:function(e){return x.nodeName(e.target,"a")}},beforeunload:{postDispatch:function(e){e.result!==t&&(e.originalEvent.returnValue=e.result)}}},simulate:function(e,t,n,r){var i=x.extend(new x.Event,n,{type:e,isSimulated:!0,originalEvent:{}});r?x.event.trigger(i,null,t):x.event.dispatch.call(t,i),i.isDefaultPrevented()&&n.preventDefault()}},x.removeEvent=a.removeEventListener?function(e,t,n){e.removeEventListener&&e.removeEventListener(t,n,!1)}:function(e,t,n){var r="on"+t;e.detachEvent&&(typeof e[r]===i&&(e[r]=null),e.detachEvent(r,n))},x.Event=function(e,n){return this instanceof x.Event?(e&&e.type?(this.originalEvent=e,this.type=e.type,this.isDefaultPrevented=e.defaultPrevented||e.returnValue===!1||e.getPreventDefault&&e.getPreventDefault()?it:ot):this.type=e,n&&x.extend(this,n),this.timeStamp=e&&e.timeStamp||x.now(),this[x.expando]=!0,t):new x.Event(e,n)},x.Event.prototype={isDefaultPrevented:ot,isPropagationStopped:ot,isImmediatePropagationStopped:ot,preventDefault:function(){var e=this.originalEvent;this.isDefaultPrevented=it,e&&(e.preventDefault?e.preventDefault():e.returnValue=!1)},stopPropagation:function(){var e=this.originalEvent;this.isPropagationStopped=it,e&&(e.stopPropagation&&e.stopPropagation(),e.cancelBubble=!0)},stopImmediatePropagation:function(){this.isImmediatePropagationStopped=it,this.stopPropagation()}},x.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(e,t){x.event.special[e]={delegateType:t,bindType:t,handle:function(e){var n,r=this,i=e.relatedTarget,o=e.handleObj;return(!i||i!==r&&!x.contains(r,i))&&(e.type=o.origType,n=o.handler.apply(this,arguments),e.type=t),n}}}),x.support.submitBubbles||(x.event.special.submit={setup:function(){return x.nodeName(this,"form")?!1:(x.event.add(this,"click._submit keypress._submit",function(e){var n=e.target,r=x.nodeName(n,"input")||x.nodeName(n,"button")?n.form:t;r&&!x._data(r,"submitBubbles")&&(x.event.add(r,"submit._submit",function(e){e._submit_bubble=!0}),x._data(r,"submitBubbles",!0))}),t)},postDispatch:function(e){e._submit_bubble&&(delete e._submit_bubble,this.parentNode&&!e.isTrigger&&x.event.simulate("submit",this.parentNode,e,!0))},teardown:function(){return x.nodeName(this,"form")?!1:(x.event.remove(this,"._submit"),t)}}),x.support.changeBubbles||(x.event.special.change={setup:function(){return Z.test(this.nodeName)?(("checkbox"===this.type||"radio"===this.type)&&(x.event.add(this,"propertychange._change",function(e){"checked"===e.originalEvent.propertyName&&(this._just_changed=!0)}),x.event.add(this,"click._change",function(e){this._just_changed&&!e.isTrigger&&(this._just_changed=!1),x.event.simulate("change",this,e,!0)})),!1):(x.event.add(this,"beforeactivate._change",function(e){var t=e.target;Z.test(t.nodeName)&&!x._data(t,"changeBubbles")&&(x.event.add(t,"change._change",function(e){!this.parentNode||e.isSimulated||e.isTrigger||x.event.simulate("change",this.parentNode,e,!0)}),x._data(t,"changeBubbles",!0))}),t)},handle:function(e){var n=e.target;return this!==n||e.isSimulated||e.isTrigger||"radio"!==n.type&&"checkbox"!==n.type?e.handleObj.handler.apply(this,arguments):t},teardown:function(){return x.event.remove(this,"._change"),!Z.test(this.nodeName)}}),x.support.focusinBubbles||x.each({focus:"focusin",blur:"focusout"},function(e,t){var n=0,r=function(e){x.event.simulate(t,e.target,x.event.fix(e),!0)};x.event.special[t]={setup:function(){0===n++&&a.addEventListener(e,r,!0)},teardown:function(){0===--n&&a.removeEventListener(e,r,!0)}}}),x.fn.extend({on:function(e,n,r,i,o){var a,s;if("object"==typeof e){"string"!=typeof n&&(r=r||n,n=t);for(a in e)this.on(a,n,r,e[a],o);return this}if(null==r&&null==i?(i=n,r=n=t):null==i&&("string"==typeof n?(i=r,r=t):(i=r,r=n,n=t)),i===!1)i=ot;else if(!i)return this;return 1===o&&(s=i,i=function(e){return x().off(e),s.apply(this,arguments)},i.guid=s.guid||(s.guid=x.guid++)),this.each(function(){x.event.add(this,e,i,r,n)})},one:function(e,t,n,r){return this.on(e,t,n,r,1)},off:function(e,n,r){var i,o;if(e&&e.preventDefault&&e.handleObj)return i=e.handleObj,x(e.delegateTarget).off(i.namespace?i.origType+"."+i.namespace:i.origType,i.selector,i.handler),this;if("object"==typeof e){for(o in e)this.off(o,n,e[o]);return this}return(n===!1||"function"==typeof n)&&(r=n,n=t),r===!1&&(r=ot),this.each(function(){x.event.remove(this,e,r,n)})},trigger:function(e,t){return this.each(function(){x.event.trigger(e,t,this)})},triggerHandler:function(e,n){var r=this[0];return r?x.event.trigger(e,n,r,!0):t}});var st=/^.[^:#\[\.,]*$/,lt=/^(?:parents|prev(?:Until|All))/,ut=x.expr.match.needsContext,ct={children:!0,contents:!0,next:!0,prev:!0};x.fn.extend({find:function(e){var t,n=[],r=this,i=r.length;if("string"!=typeof e)return this.pushStack(x(e).filter(function(){for(t=0;i>t;t++)if(x.contains(r[t],this))return!0}));for(t=0;i>t;t++)x.find(e,r[t],n);return n=this.pushStack(i>1?x.unique(n):n),n.selector=this.selector?this.selector+" "+e:e,n},has:function(e){var t,n=x(e,this),r=n.length;return this.filter(function(){for(t=0;r>t;t++)if(x.contains(this,n[t]))return!0})},not:function(e){return this.pushStack(ft(this,e||[],!0))},filter:function(e){return this.pushStack(ft(this,e||[],!1))},is:function(e){return!!ft(this,"string"==typeof e&&ut.test(e)?x(e):e||[],!1).length},closest:function(e,t){var n,r=0,i=this.length,o=[],a=ut.test(e)||"string"!=typeof e?x(e,t||this.context):0;for(;i>r;r++)for(n=this[r];n&&n!==t;n=n.parentNode)if(11>n.nodeType&&(a?a.index(n)>-1:1===n.nodeType&&x.find.matchesSelector(n,e))){n=o.push(n);break}return this.pushStack(o.length>1?x.unique(o):o)},index:function(e){return e?"string"==typeof e?x.inArray(this[0],x(e)):x.inArray(e.jquery?e[0]:e,this):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(e,t){var n="string"==typeof e?x(e,t):x.makeArray(e&&e.nodeType?[e]:e),r=x.merge(this.get(),n);return this.pushStack(x.unique(r))},addBack:function(e){return this.add(null==e?this.prevObject:this.prevObject.filter(e))}});function pt(e,t){do e=e[t];while(e&&1!==e.nodeType);return e}x.each({parent:function(e){var t=e.parentNode;return t&&11!==t.nodeType?t:null},parents:function(e){return x.dir(e,"parentNode")},parentsUntil:function(e,t,n){return x.dir(e,"parentNode",n)},next:function(e){return pt(e,"nextSibling")},prev:function(e){return pt(e,"previousSibling")},nextAll:function(e){return x.dir(e,"nextSibling")},prevAll:function(e){return x.dir(e,"previousSibling")},nextUntil:function(e,t,n){return x.dir(e,"nextSibling",n)},prevUntil:function(e,t,n){return x.dir(e,"previousSibling",n)},siblings:function(e){return x.sibling((e.parentNode||{}).firstChild,e)},children:function(e){return x.sibling(e.firstChild)},contents:function(e){return x.nodeName(e,"iframe")?e.contentDocument||e.contentWindow.document:x.merge([],e.childNodes)}},function(e,t){x.fn[e]=function(n,r){var i=x.map(this,t,n);return"Until"!==e.slice(-5)&&(r=n),r&&"string"==typeof r&&(i=x.filter(r,i)),this.length>1&&(ct[e]||(i=x.unique(i)),lt.test(e)&&(i=i.reverse())),this.pushStack(i)}}),x.extend({filter:function(e,t,n){var r=t[0];return n&&(e=":not("+e+")"),1===t.length&&1===r.nodeType?x.find.matchesSelector(r,e)?[r]:[]:x.find.matches(e,x.grep(t,function(e){return 1===e.nodeType}))},dir:function(e,n,r){var i=[],o=e[n];while(o&&9!==o.nodeType&&(r===t||1!==o.nodeType||!x(o).is(r)))1===o.nodeType&&i.push(o),o=o[n];return i},sibling:function(e,t){var n=[];for(;e;e=e.nextSibling)1===e.nodeType&&e!==t&&n.push(e);return n}});function ft(e,t,n){if(x.isFunction(t))return x.grep(e,function(e,r){return!!t.call(e,r,e)!==n});if(t.nodeType)return x.grep(e,function(e){return e===t!==n});if("string"==typeof t){if(st.test(t))return x.filter(t,e,n);t=x.filter(t,e)}return x.grep(e,function(e){return x.inArray(e,t)>=0!==n})}function dt(e){var t=ht.split("|"),n=e.createDocumentFragment();if(n.createElement)while(t.length)n.createElement(t.pop());return n}var ht="abbr|article|aside|audio|bdi|canvas|data|datalist|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",gt=/ jQuery\d+="(?:null|\d+)"/g,mt=RegExp("<(?:"+ht+")[\\s/>]","i"),yt=/^\s+/,vt=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,bt=/<([\w:]+)/,xt=/\s*$/g,At={option:[1,""],legend:[1,"
","
"],area:[1,"",""],param:[1,"",""],thead:[1,"","
"],tr:[2,"","
"],col:[2,"","
"],td:[3,"","
"],_default:x.support.htmlSerialize?[0,"",""]:[1,"X
","
"]},jt=dt(a),Dt=jt.appendChild(a.createElement("div"));At.optgroup=At.option,At.tbody=At.tfoot=At.colgroup=At.caption=At.thead,At.th=At.td,x.fn.extend({text:function(e){return x.access(this,function(e){return e===t?x.text(this):this.empty().append((this[0]&&this[0].ownerDocument||a).createTextNode(e))},null,e,arguments.length)},append:function(){return this.domManip(arguments,function(e){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var t=Lt(this,e);t.appendChild(e)}})},prepend:function(){return this.domManip(arguments,function(e){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var t=Lt(this,e);t.insertBefore(e,t.firstChild)}})},before:function(){return this.domManip(arguments,function(e){this.parentNode&&this.parentNode.insertBefore(e,this)})},after:function(){return this.domManip(arguments,function(e){this.parentNode&&this.parentNode.insertBefore(e,this.nextSibling)})},remove:function(e,t){var n,r=e?x.filter(e,this):this,i=0;for(;null!=(n=r[i]);i++)t||1!==n.nodeType||x.cleanData(Ft(n)),n.parentNode&&(t&&x.contains(n.ownerDocument,n)&&_t(Ft(n,"script")),n.parentNode.removeChild(n));return this},empty:function(){var e,t=0;for(;null!=(e=this[t]);t++){1===e.nodeType&&x.cleanData(Ft(e,!1));while(e.firstChild)e.removeChild(e.firstChild);e.options&&x.nodeName(e,"select")&&(e.options.length=0)}return this},clone:function(e,t){return e=null==e?!1:e,t=null==t?e:t,this.map(function(){return x.clone(this,e,t)})},html:function(e){return x.access(this,function(e){var n=this[0]||{},r=0,i=this.length;if(e===t)return 1===n.nodeType?n.innerHTML.replace(gt,""):t;if(!("string"!=typeof e||Tt.test(e)||!x.support.htmlSerialize&&mt.test(e)||!x.support.leadingWhitespace&&yt.test(e)||At[(bt.exec(e)||["",""])[1].toLowerCase()])){e=e.replace(vt,"<$1>");try{for(;i>r;r++)n=this[r]||{},1===n.nodeType&&(x.cleanData(Ft(n,!1)),n.innerHTML=e);n=0}catch(o){}}n&&this.empty().append(e)},null,e,arguments.length)},replaceWith:function(){var e=x.map(this,function(e){return[e.nextSibling,e.parentNode]}),t=0;return this.domManip(arguments,function(n){var r=e[t++],i=e[t++];i&&(r&&r.parentNode!==i&&(r=this.nextSibling),x(this).remove(),i.insertBefore(n,r))},!0),t?this:this.remove()},detach:function(e){return this.remove(e,!0)},domManip:function(e,t,n){e=d.apply([],e);var r,i,o,a,s,l,u=0,c=this.length,p=this,f=c-1,h=e[0],g=x.isFunction(h);if(g||!(1>=c||"string"!=typeof h||x.support.checkClone)&&Nt.test(h))return this.each(function(r){var i=p.eq(r);g&&(e[0]=h.call(this,r,i.html())),i.domManip(e,t,n)});if(c&&(l=x.buildFragment(e,this[0].ownerDocument,!1,!n&&this),r=l.firstChild,1===l.childNodes.length&&(l=r),r)){for(a=x.map(Ft(l,"script"),Ht),o=a.length;c>u;u++)i=l,u!==f&&(i=x.clone(i,!0,!0),o&&x.merge(a,Ft(i,"script"))),t.call(this[u],i,u);if(o)for(s=a[a.length-1].ownerDocument,x.map(a,qt),u=0;o>u;u++)i=a[u],kt.test(i.type||"")&&!x._data(i,"globalEval")&&x.contains(s,i)&&(i.src?x._evalUrl(i.src):x.globalEval((i.text||i.textContent||i.innerHTML||"").replace(St,"")));l=r=null}return this}});function Lt(e,t){return x.nodeName(e,"table")&&x.nodeName(1===t.nodeType?t:t.firstChild,"tr")?e.getElementsByTagName("tbody")[0]||e.appendChild(e.ownerDocument.createElement("tbody")):e}function Ht(e){return e.type=(null!==x.find.attr(e,"type"))+"/"+e.type,e}function qt(e){var t=Et.exec(e.type);return t?e.type=t[1]:e.removeAttribute("type"),e}function _t(e,t){var n,r=0;for(;null!=(n=e[r]);r++)x._data(n,"globalEval",!t||x._data(t[r],"globalEval"))}function Mt(e,t){if(1===t.nodeType&&x.hasData(e)){var n,r,i,o=x._data(e),a=x._data(t,o),s=o.events;if(s){delete a.handle,a.events={};for(n in s)for(r=0,i=s[n].length;i>r;r++)x.event.add(t,n,s[n][r])}a.data&&(a.data=x.extend({},a.data))}}function Ot(e,t){var n,r,i;if(1===t.nodeType){if(n=t.nodeName.toLowerCase(),!x.support.noCloneEvent&&t[x.expando]){i=x._data(t);for(r in i.events)x.removeEvent(t,r,i.handle);t.removeAttribute(x.expando)}"script"===n&&t.text!==e.text?(Ht(t).text=e.text,qt(t)):"object"===n?(t.parentNode&&(t.outerHTML=e.outerHTML),x.support.html5Clone&&e.innerHTML&&!x.trim(t.innerHTML)&&(t.innerHTML=e.innerHTML)):"input"===n&&Ct.test(e.type)?(t.defaultChecked=t.checked=e.checked,t.value!==e.value&&(t.value=e.value)):"option"===n?t.defaultSelected=t.selected=e.defaultSelected:("input"===n||"textarea"===n)&&(t.defaultValue=e.defaultValue)}}x.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(e,t){x.fn[e]=function(e){var n,r=0,i=[],o=x(e),a=o.length-1;for(;a>=r;r++)n=r===a?this:this.clone(!0),x(o[r])[t](n),h.apply(i,n.get());return this.pushStack(i)}});function Ft(e,n){var r,o,a=0,s=typeof e.getElementsByTagName!==i?e.getElementsByTagName(n||"*"):typeof e.querySelectorAll!==i?e.querySelectorAll(n||"*"):t;if(!s)for(s=[],r=e.childNodes||e;null!=(o=r[a]);a++)!n||x.nodeName(o,n)?s.push(o):x.merge(s,Ft(o,n));return n===t||n&&x.nodeName(e,n)?x.merge([e],s):s}function Bt(e){Ct.test(e.type)&&(e.defaultChecked=e.checked)}x.extend({clone:function(e,t,n){var r,i,o,a,s,l=x.contains(e.ownerDocument,e);if(x.support.html5Clone||x.isXMLDoc(e)||!mt.test("<"+e.nodeName+">")?o=e.cloneNode(!0):(Dt.innerHTML=e.outerHTML,Dt.removeChild(o=Dt.firstChild)),!(x.support.noCloneEvent&&x.support.noCloneChecked||1!==e.nodeType&&11!==e.nodeType||x.isXMLDoc(e)))for(r=Ft(o),s=Ft(e),a=0;null!=(i=s[a]);++a)r[a]&&Ot(i,r[a]);if(t)if(n)for(s=s||Ft(e),r=r||Ft(o),a=0;null!=(i=s[a]);a++)Mt(i,r[a]);else Mt(e,o);return r=Ft(o,"script"),r.length>0&&_t(r,!l&&Ft(e,"script")),r=s=i=null,o},buildFragment:function(e,t,n,r){var i,o,a,s,l,u,c,p=e.length,f=dt(t),d=[],h=0;for(;p>h;h++)if(o=e[h],o||0===o)if("object"===x.type(o))x.merge(d,o.nodeType?[o]:o);else if(wt.test(o)){s=s||f.appendChild(t.createElement("div")),l=(bt.exec(o)||["",""])[1].toLowerCase(),c=At[l]||At._default,s.innerHTML=c[1]+o.replace(vt,"<$1>")+c[2],i=c[0];while(i--)s=s.lastChild;if(!x.support.leadingWhitespace&&yt.test(o)&&d.push(t.createTextNode(yt.exec(o)[0])),!x.support.tbody){o="table"!==l||xt.test(o)?""!==c[1]||xt.test(o)?0:s:s.firstChild,i=o&&o.childNodes.length;while(i--)x.nodeName(u=o.childNodes[i],"tbody")&&!u.childNodes.length&&o.removeChild(u)}x.merge(d,s.childNodes),s.textContent="";while(s.firstChild)s.removeChild(s.firstChild);s=f.lastChild}else d.push(t.createTextNode(o));s&&f.removeChild(s),x.support.appendChecked||x.grep(Ft(d,"input"),Bt),h=0;while(o=d[h++])if((!r||-1===x.inArray(o,r))&&(a=x.contains(o.ownerDocument,o),s=Ft(f.appendChild(o),"script"),a&&_t(s),n)){i=0;while(o=s[i++])kt.test(o.type||"")&&n.push(o)}return s=null,f},cleanData:function(e,t){var n,r,o,a,s=0,l=x.expando,u=x.cache,c=x.support.deleteExpando,f=x.event.special;for(;null!=(n=e[s]);s++)if((t||x.acceptData(n))&&(o=n[l],a=o&&u[o])){if(a.events)for(r in a.events)f[r]?x.event.remove(n,r):x.removeEvent(n,r,a.handle); - u[o]&&(delete u[o],c?delete n[l]:typeof n.removeAttribute!==i?n.removeAttribute(l):n[l]=null,p.push(o))}},_evalUrl:function(e){return x.ajax({url:e,type:"GET",dataType:"script",async:!1,global:!1,"throws":!0})}}),x.fn.extend({wrapAll:function(e){if(x.isFunction(e))return this.each(function(t){x(this).wrapAll(e.call(this,t))});if(this[0]){var t=x(e,this[0].ownerDocument).eq(0).clone(!0);this[0].parentNode&&t.insertBefore(this[0]),t.map(function(){var e=this;while(e.firstChild&&1===e.firstChild.nodeType)e=e.firstChild;return e}).append(this)}return this},wrapInner:function(e){return x.isFunction(e)?this.each(function(t){x(this).wrapInner(e.call(this,t))}):this.each(function(){var t=x(this),n=t.contents();n.length?n.wrapAll(e):t.append(e)})},wrap:function(e){var t=x.isFunction(e);return this.each(function(n){x(this).wrapAll(t?e.call(this,n):e)})},unwrap:function(){return this.parent().each(function(){x.nodeName(this,"body")||x(this).replaceWith(this.childNodes)}).end()}});var Pt,Rt,Wt,$t=/alpha\([^)]*\)/i,It=/opacity\s*=\s*([^)]*)/,zt=/^(top|right|bottom|left)$/,Xt=/^(none|table(?!-c[ea]).+)/,Ut=/^margin/,Vt=RegExp("^("+w+")(.*)$","i"),Yt=RegExp("^("+w+")(?!px)[a-z%]+$","i"),Jt=RegExp("^([+-])=("+w+")","i"),Gt={BODY:"block"},Qt={position:"absolute",visibility:"hidden",display:"block"},Kt={letterSpacing:0,fontWeight:400},Zt=["Top","Right","Bottom","Left"],en=["Webkit","O","Moz","ms"];function tn(e,t){if(t in e)return t;var n=t.charAt(0).toUpperCase()+t.slice(1),r=t,i=en.length;while(i--)if(t=en[i]+n,t in e)return t;return r}function nn(e,t){return e=t||e,"none"===x.css(e,"display")||!x.contains(e.ownerDocument,e)}function rn(e,t){var n,r,i,o=[],a=0,s=e.length;for(;s>a;a++)r=e[a],r.style&&(o[a]=x._data(r,"olddisplay"),n=r.style.display,t?(o[a]||"none"!==n||(r.style.display=""),""===r.style.display&&nn(r)&&(o[a]=x._data(r,"olddisplay",ln(r.nodeName)))):o[a]||(i=nn(r),(n&&"none"!==n||!i)&&x._data(r,"olddisplay",i?n:x.css(r,"display"))));for(a=0;s>a;a++)r=e[a],r.style&&(t&&"none"!==r.style.display&&""!==r.style.display||(r.style.display=t?o[a]||"":"none"));return e}x.fn.extend({css:function(e,n){return x.access(this,function(e,n,r){var i,o,a={},s=0;if(x.isArray(n)){for(o=Rt(e),i=n.length;i>s;s++)a[n[s]]=x.css(e,n[s],!1,o);return a}return r!==t?x.style(e,n,r):x.css(e,n)},e,n,arguments.length>1)},show:function(){return rn(this,!0)},hide:function(){return rn(this)},toggle:function(e){var t="boolean"==typeof e;return this.each(function(){(t?e:nn(this))?x(this).show():x(this).hide()})}}),x.extend({cssHooks:{opacity:{get:function(e,t){if(t){var n=Wt(e,"opacity");return""===n?"1":n}}}},cssNumber:{columnCount:!0,fillOpacity:!0,fontWeight:!0,lineHeight:!0,opacity:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{"float":x.support.cssFloat?"cssFloat":"styleFloat"},style:function(e,n,r,i){if(e&&3!==e.nodeType&&8!==e.nodeType&&e.style){var o,a,s,l=x.camelCase(n),u=e.style;if(n=x.cssProps[l]||(x.cssProps[l]=tn(u,l)),s=x.cssHooks[n]||x.cssHooks[l],r===t)return s&&"get"in s&&(o=s.get(e,!1,i))!==t?o:u[n];if(a=typeof r,"string"===a&&(o=Jt.exec(r))&&(r=(o[1]+1)*o[2]+parseFloat(x.css(e,n)),a="number"),!(null==r||"number"===a&&isNaN(r)||("number"!==a||x.cssNumber[l]||(r+="px"),x.support.clearCloneStyle||""!==r||0!==n.indexOf("background")||(u[n]="inherit"),s&&"set"in s&&(r=s.set(e,r,i))===t)))try{u[n]=r}catch(c){}}},css:function(e,n,r,i){var o,a,s,l=x.camelCase(n);return n=x.cssProps[l]||(x.cssProps[l]=tn(e.style,l)),s=x.cssHooks[n]||x.cssHooks[l],s&&"get"in s&&(a=s.get(e,!0,r)),a===t&&(a=Wt(e,n,i)),"normal"===a&&n in Kt&&(a=Kt[n]),""===r||r?(o=parseFloat(a),r===!0||x.isNumeric(o)?o||0:a):a}}),e.getComputedStyle?(Rt=function(t){return e.getComputedStyle(t,null)},Wt=function(e,n,r){var i,o,a,s=r||Rt(e),l=s?s.getPropertyValue(n)||s[n]:t,u=e.style;return s&&(""!==l||x.contains(e.ownerDocument,e)||(l=x.style(e,n)),Yt.test(l)&&Ut.test(n)&&(i=u.width,o=u.minWidth,a=u.maxWidth,u.minWidth=u.maxWidth=u.width=l,l=s.width,u.width=i,u.minWidth=o,u.maxWidth=a)),l}):a.documentElement.currentStyle&&(Rt=function(e){return e.currentStyle},Wt=function(e,n,r){var i,o,a,s=r||Rt(e),l=s?s[n]:t,u=e.style;return null==l&&u&&u[n]&&(l=u[n]),Yt.test(l)&&!zt.test(n)&&(i=u.left,o=e.runtimeStyle,a=o&&o.left,a&&(o.left=e.currentStyle.left),u.left="fontSize"===n?"1em":l,l=u.pixelLeft+"px",u.left=i,a&&(o.left=a)),""===l?"auto":l});function on(e,t,n){var r=Vt.exec(t);return r?Math.max(0,r[1]-(n||0))+(r[2]||"px"):t}function an(e,t,n,r,i){var o=n===(r?"border":"content")?4:"width"===t?1:0,a=0;for(;4>o;o+=2)"margin"===n&&(a+=x.css(e,n+Zt[o],!0,i)),r?("content"===n&&(a-=x.css(e,"padding"+Zt[o],!0,i)),"margin"!==n&&(a-=x.css(e,"border"+Zt[o]+"Width",!0,i))):(a+=x.css(e,"padding"+Zt[o],!0,i),"padding"!==n&&(a+=x.css(e,"border"+Zt[o]+"Width",!0,i)));return a}function sn(e,t,n){var r=!0,i="width"===t?e.offsetWidth:e.offsetHeight,o=Rt(e),a=x.support.boxSizing&&"border-box"===x.css(e,"boxSizing",!1,o);if(0>=i||null==i){if(i=Wt(e,t,o),(0>i||null==i)&&(i=e.style[t]),Yt.test(i))return i;r=a&&(x.support.boxSizingReliable||i===e.style[t]),i=parseFloat(i)||0}return i+an(e,t,n||(a?"border":"content"),r,o)+"px"}function ln(e){var t=a,n=Gt[e];return n||(n=un(e,t),"none"!==n&&n||(Pt=(Pt||x("