]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11465 Deprecate InputModule and introduce InputProject
authorJulien HENRY <julien.henry@sonarsource.com>
Wed, 14 Nov 2018 21:47:35 +0000 (22:47 +0100)
committersonartech <sonartech@sonarsource.com>
Wed, 16 Jan 2019 08:43:01 +0000 (09:43 +0100)
178 files changed:
sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectKey.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectReactor.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputComponent.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputModule.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AbstractProjectOrModule.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputComponent.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputModule.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputProject.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/InputModuleHierarchy.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/TestInputFileBuilder.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/AbstractDefaultIssue.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssue.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java
sonar-plugin-api/src/main/java/org/sonar/api/scanner/fs/InputProject.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/scanner/fs/package-info.java [new file with mode: 0644]
sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputModuleTest.java [deleted file]
sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputProjectTest.java [new file with mode: 0644]
sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/TestInputFileBuilderTest.java
sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssueTest.java
sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueTest.java
sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/measure/internal/DefaultMeasureTest.java
sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/Batch.java
sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/LoggingConfiguration.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/AnalysisProperties.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/AnalysisTempFolderProvider.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/DefaultAnalysisMode.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/DroppedPropertyChecker.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalAnalysisMode.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalConfiguration.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalConfigurationProvider.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalContainer.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalProperties.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalServerSettings.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalServerSettingsProvider.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalTempFolderProvider.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/MutableGlobalSettings.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerProperties.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerWsClientProvider.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/UserProperties.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/CpdExecutor.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/CpdSettings.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/index/SonarCpdBlockIndex.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultFilterableIssue.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ModuleIssueFilters.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ModuleIssues.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/IssueTransition.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/LocalIssueTracking.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/ServerIssueRepository.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/SourceHashHolder.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/AnalysisObserver.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/AnalysisObservers.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/AnalysisResult.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/ScanTaskObserver.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/ScanTaskObservers.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/TaskResult.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/AbstractModulePhaseExecutor.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/ModuleCoverageExclusions.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/ProjectCoverageExclusions.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/SensorsExecutor.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/platform/DefaultServer.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/report/AnalysisContextReportPublisher.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ChangedLinesPublisher.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/report/CoveragePublisher.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MeasuresPublisher.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/report/SourcePublisher.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/report/TestExecutionAndCoveragePublisher.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ProjectRepositoriesProvider.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/QualityProfilesProvider.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DefaultInputModuleHierarchy.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/InputModuleHierarchyProvider.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/InputProjectProvider.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleConfigurationProvider.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleIndexer.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/MutableModuleSettings.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/MutableProjectSettings.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectConfigurationProvider.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectLock.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ScanProperties.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/BatchIdGenerator.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/DefaultModuleFileSystem.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputComponentStore.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputComponentStoreProvider.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputFileBuilder.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ModuleFileSystemInitializer.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ScannerComponentIdGenerator.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/JSONReport.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/DefaultBlameOutput.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/ScmChangedFilesProvider.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/ScmPublisher.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorContext.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorStorage.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/SensorOptimizer.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/SensorWrapper.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/task/ScanTask.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/task/TaskContainer.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/task/TaskProperties.java [deleted file]
sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrapper/LoggingConfigurationTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/analysis/AnalysisTempFolderProviderTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/analysis/DefaultAnalysisModeTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/DroppedPropertyCheckerTest.java [deleted file]
sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalAnalysisModeTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalConfigurationProviderTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalPropertiesTest.java [deleted file]
sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalTempFolderProviderTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/PluginFilesTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPropertiesTest.java [new file with mode: 0644]
sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerWsClientProviderTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerWsClientTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdExecutorTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdSettingsTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/index/AbstractCachesTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ModuleIssuesTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/branch/BranchMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/branch/DeprecatedBranchMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/coverage/CoverageMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/coverage/GenericCoverageMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/cpd/CpdMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/NoLanguagesPluginsMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/ProjectBuilderMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/highlighting/HighlightingMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/ChecksMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/ExternalIssuesMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesOnDirMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesOnModuleMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/MultilineIssuesMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issuesmode/EmptyFileTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issuesmode/IssueModeAndReportsMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issuesmode/NoPreviousAnalysisTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issuesmode/ScanOnlyChangedTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/log/ExceptionHandlingMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/log/LogListenerTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/measures/MeasuresMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/scm/ScmMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/symbol/SymbolMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tasks/TasksMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tests/CoveragePerTestMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tests/GenericTestExecutionMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tests/TestExecutionMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/ModuleCoverageExclusionsTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/ProjectCoverageExclusionsTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/report/AnalysisContextReportPublisherTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ChangedLinesPublisherTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/report/CoveragePublisherTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MeasuresPublisherTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MetadataPublisherTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/report/SourcePublisherTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/ProjectRepositoriesProviderTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/QualityProfileProviderTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/DefaultComponentTreeTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/DefaultInputModuleHierarchyTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ModuleIndexerTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/MutableModuleSettingsTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/MutableProjectSettingsTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectLockTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ScanPropertiesTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/InputComponentStoreTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/InputFileBuilderTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ModuleInputComponentStoreTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/report/JSONReportTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmChangedFilesProviderTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorContextTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorStorageTest.java

index 7307876e0e32716a7aaf6be26035919ca006c890..a846b206bc106c341d2fd9433883b23e2064955e 100644 (file)
@@ -39,7 +39,9 @@ import org.sonar.api.CoreProperties;
  * Since 6.5, plugins should no longer manipulate the project's structure.
  *
  * @since 2.9
+ * @deprecated since 7.6 use {@link org.sonar.api.scanner.fs.InputProject}
  */
+@Deprecated
 public class ProjectDefinition {
 
   public static final String SOURCES_PROPERTY = "sonar.sources";
index 9c382dd719e584fc9afee4ad27c05685780ef6e1..a1e4f2661c016836b81a205fbcdf296d1d52d3b4 100644 (file)
@@ -21,7 +21,9 @@ package org.sonar.api.batch.bootstrap;
 
 /**
  * Provides root project key with branch
+ * @deprecated since 7.6
  */
+@Deprecated
 @FunctionalInterface
 public interface ProjectKey {
   String get();
index 8bceff017497cc6a9080ea41c0cdefd501265459..4f7393cb07347ee738c08f0098a76751f4adca9a 100644 (file)
@@ -32,7 +32,7 @@ import java.util.List;
  */
 @Deprecated
 @ScannerSide
-public class ProjectReactor implements ProjectKey {
+public class ProjectReactor {
 
   private ProjectDefinition root;
 
@@ -71,7 +71,6 @@ public class ProjectReactor implements ProjectKey {
     return null;
   }
 
-  @Override
   public String get() {
     if (root != null) {
       return root.getKeyWithBranch();
index d2bf32edd8882b0a52705fe61932b548d6b41849..b6672651a81b7b7df00f82e880f1ff2a9ffb7d54 100644 (file)
@@ -26,6 +26,7 @@ package org.sonar.api.batch.fs;
  * @see InputFile
  * @see InputDir
  * @see InputModule
+ * @see org.sonar.api.scanner.fs.InputProject
  */
 public interface InputComponent {
 
index 27bf4f2d1800a451e5683cb291f29399e40057e5..3ce89d90f457bffa5e3170562b21eecf199ce2e2 100644 (file)
@@ -28,7 +28,9 @@ import org.sonar.api.batch.sensor.SensorContext;
  * Used to create issues and measures on modules. You can access InputModule using {@link SensorContext#module()}
  *
  * @since 5.2
+ * @deprecated since 7.6 modules are deprecated. Use {@link org.sonar.api.scanner.fs.InputProject} instead.
  */
+@Deprecated
 @Immutable
 public interface InputModule extends InputComponent {
 }
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AbstractProjectOrModule.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AbstractProjectOrModule.java
new file mode 100644 (file)
index 0000000..d9d59a0
--- /dev/null
@@ -0,0 +1,148 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.api.batch.fs.internal;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.LinkOption;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.CheckForNull;
+import javax.annotation.concurrent.Immutable;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
+
+@Immutable
+public abstract class AbstractProjectOrModule extends DefaultInputComponent {
+  private final Path baseDir;
+  private final Path workDir;
+  private final String name;
+  private final String version;
+  private final String originalName;
+  private final String originalVersion;
+  private final String description;
+  private final String keyWithBranch;
+  private final String branch;
+  private final Map<String, String> properties;
+
+  private final String key;
+  private final ProjectDefinition definition;
+
+  /**
+   * For testing only!
+   */
+  public AbstractProjectOrModule(ProjectDefinition definition) {
+    this(definition, TestInputFileBuilder.nextBatchId());
+  }
+
+  public AbstractProjectOrModule(ProjectDefinition definition, int scannerComponentId) {
+    super(scannerComponentId);
+    this.baseDir = initBaseDir(definition);
+    this.workDir = initWorkingDir(definition);
+    this.name = definition.getName();
+    this.originalName = definition.getOriginalName();
+    this.version = definition.getVersion();
+    this.originalVersion = definition.getOriginalVersion();
+    this.description = definition.getDescription();
+    this.keyWithBranch = definition.getKeyWithBranch();
+    this.branch = definition.getBranch();
+    this.properties = Collections.unmodifiableMap(new HashMap<>(definition.properties()));
+
+    this.definition = definition;
+    this.key = definition.getKey();
+  }
+
+  private static Path initBaseDir(ProjectDefinition module) {
+    Path result;
+    try {
+      result = module.getBaseDir().toPath().toRealPath(LinkOption.NOFOLLOW_LINKS);
+    } catch (IOException e) {
+      throw new IllegalStateException("Unable to resolve module baseDir", e);
+    }
+    return result;
+  }
+
+  private static Path initWorkingDir(ProjectDefinition module) {
+    File workingDirAsFile = module.getWorkDir();
+    return workingDirAsFile.getAbsoluteFile().toPath().normalize();
+  }
+
+  /**
+   * Module key without branch
+   */
+  @Override
+  public String key() {
+    return key;
+  }
+
+  @Override
+  public boolean isFile() {
+    return false;
+  }
+
+  public ProjectDefinition definition() {
+    return definition;
+  }
+
+  public Path getBaseDir() {
+    return baseDir;
+  }
+
+  public Path getWorkDir() {
+    return workDir;
+  }
+
+  public String getKeyWithBranch() {
+    return keyWithBranch;
+  }
+
+  @CheckForNull
+  public String getBranch() {
+    return branch;
+  }
+
+  public Map<String, String> properties() {
+    return properties;
+  }
+
+  @CheckForNull
+  public String getOriginalVersion() {
+    return originalVersion;
+  }
+
+  public String getVersion() {
+    return version;
+  }
+
+  @CheckForNull
+  public String getOriginalName() {
+    return originalName;
+  }
+
+  public String getName() {
+    return name;
+  }
+
+  public String getDescription() {
+    return description;
+  }
+  
+}
index d29d84b6d2d9d352029aaa1805bd15c87da91f03..7138f95adcc7ccbe91c0836af6eb3a49d66cb3bd 100644 (file)
@@ -44,7 +44,7 @@ public abstract class DefaultInputComponent implements InputComponent {
     return key().equals(that.key());
   }
 
-  public int batchId() {
+  public int scannerId() {
     return id;
   }
 
index f7d640a4dbbbd07f790aecb1bacf52d148d74e1e..efa7804d512f774960a8c2d1b47c1f433b4f155a 100644 (file)
@@ -66,7 +66,7 @@ public class DefaultInputFile extends DefaultInputComponent implements InputFile
 
   // For testing
   public DefaultInputFile(DefaultIndexedFile indexedFile, Consumer<DefaultInputFile> metadataGenerator, @Nullable String contents) {
-    super(indexedFile.batchId());
+    super(indexedFile.scannerId());
     this.indexedFile = indexedFile;
     this.metadataGenerator = metadataGenerator;
     this.metadata = null;
index 4b7dd8144883d6bc523fa6342da9305acf8911e0..157e5a1e25dd1aeb5f7b3870e7da793b8ac929a1 100644 (file)
  */
 package org.sonar.api.batch.fs.internal;
 
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.LinkOption;
-import java.nio.file.Path;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import javax.annotation.CheckForNull;
 import javax.annotation.concurrent.Immutable;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
 import org.sonar.api.batch.fs.InputModule;
 
-/**
- * @since 5.2
- */
 @Immutable
-public class DefaultInputModule extends DefaultInputComponent implements InputModule {
-  private final Path baseDir;
-  private final Path workDir;
-  private final String name;
-  private final String version;
-  private final String originalName;
-  private final String originalVersion;
-  private final String description;
-  private final String keyWithBranch;
-  private final String branch;
-  private final Map<String, String> properties;
-
-  private final String moduleKey;
-  private final ProjectDefinition definition;
+public class DefaultInputModule extends AbstractProjectOrModule implements InputModule {
 
-  /**
-   * For testing only!
-   */
   public DefaultInputModule(ProjectDefinition definition) {
-    this(definition, TestInputFileBuilder.nextBatchId());
-  }
-
-  public DefaultInputModule(ProjectDefinition definition, int batchId) {
-    super(batchId);
-    this.baseDir = initBaseDir(definition);
-    this.workDir = initWorkingDir(definition);
-    this.name = definition.getName();
-    this.originalName = definition.getOriginalName();
-    this.version = definition.getVersion();
-    this.originalVersion = definition.getOriginalVersion();
-    this.description = definition.getDescription();
-    this.keyWithBranch = definition.getKeyWithBranch();
-    this.branch = definition.getBranch();
-    this.properties = Collections.unmodifiableMap(new HashMap<>(definition.properties()));
-
-    this.definition = definition;
-    this.moduleKey = definition.getKey();
-  }
-
-  private static Path initBaseDir(ProjectDefinition module) {
-    Path result;
-    try {
-      result = module.getBaseDir().toPath().toRealPath(LinkOption.NOFOLLOW_LINKS);
-    } catch (IOException e) {
-      throw new IllegalStateException("Unable to resolve module baseDir", e);
-    }
-    return result;
-  }
-
-  private static Path initWorkingDir(ProjectDefinition module) {
-    File workingDirAsFile = module.getWorkDir();
-    return workingDirAsFile.getAbsoluteFile().toPath().normalize();
-  }
-
-  /**
-   * Module key without branch
-   */
-  @Override
-  public String key() {
-    return moduleKey;
-  }
-
-  @Override
-  public boolean isFile() {
-    return false;
-  }
-
-  public ProjectDefinition definition() {
-    return definition;
-  }
-
-  public Path getBaseDir() {
-    return baseDir;
+    super(definition);
   }
 
-  public Path getWorkDir() {
-    return workDir;
+  public DefaultInputModule(ProjectDefinition definition, int scannerComponentId) {
+    super(definition, scannerComponentId);
   }
-
-  public String getKeyWithBranch() {
-    return keyWithBranch;
-  }
-
-  @CheckForNull
-  public String getBranch() {
-    return branch;
-  }
-
-  public Map<String, String> properties() {
-    return properties;
-  }
-
-  @CheckForNull
-  public String getOriginalVersion() {
-    return originalVersion;
-  }
-
-  public String getVersion() {
-    return version;
-  }
-
-  @CheckForNull
-  public String getOriginalName() {
-    return originalName;
-  }
-
-  public String getName() {
-    return name;
-  }
-
-  public String getDescription() {
-    return description;
-  }
-
 }
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputProject.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputProject.java
new file mode 100644 (file)
index 0000000..b89a884
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.api.batch.fs.internal;
+
+import javax.annotation.concurrent.Immutable;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.api.scanner.fs.InputProject;
+
+@Immutable
+public class DefaultInputProject extends AbstractProjectOrModule implements InputProject {
+
+  public DefaultInputProject(ProjectDefinition definition) {
+    super(definition);
+  }
+
+  public DefaultInputProject(ProjectDefinition definition, int scannerComponentId) {
+    super(definition, scannerComponentId);
+  }
+}
index 5482e59ea7847827b8f6127b7496da3c48a6c59c..8fe58bde9dca9ee2d9c3c14d0e38eaff2f5c0035 100644 (file)
 package org.sonar.api.batch.fs.internal;
 
 import java.util.Collection;
-
 import javax.annotation.CheckForNull;
 import javax.annotation.concurrent.Immutable;
 
-import org.sonar.api.batch.fs.InputModule;
-
 @Immutable
 public interface InputModuleHierarchy {
   DefaultInputModule root();
   
-  boolean isRoot(InputModule module);
+  boolean isRoot(DefaultInputModule module);
 
-  Collection<DefaultInputModule> children(InputModule module);
+  Collection<DefaultInputModule> children(DefaultInputModule module);
 
   @CheckForNull
-  DefaultInputModule parent(InputModule module);
+  DefaultInputModule parent(DefaultInputModule module);
   
   @CheckForNull
-  String relativePath(InputModule module);
+  String relativePath(DefaultInputModule module);
 }
index b8188f0edce0e622475d996b85c0e5e3e9d06bec..d84961b76c52b959307969da3c16cd91f64df170 100644 (file)
@@ -239,20 +239,37 @@ public class TestInputFileBuilder {
     return new DefaultInputModule(projectDefinition, TestInputFileBuilder.nextBatchId());
   }
 
-  public static DefaultInputModule newDefaultInputModule(DefaultInputModule parent, String key) throws IOException {
+  public static DefaultInputModule newDefaultInputModule(AbstractProjectOrModule parent, String key) throws IOException {
     Path basedir = parent.getBaseDir().resolve(key);
     Files.createDirectory(basedir);
     return newDefaultInputModule(key, basedir.toFile());
   }
 
-  public static DefaultInputDir newDefaultInputDir(DefaultInputModule module, String relativePath) throws IOException {
+  public static DefaultInputProject newDefaultInputProject(String projectKey, File baseDir) {
+    ProjectDefinition definition = ProjectDefinition.create()
+      .setKey(projectKey)
+      .setBaseDir(baseDir)
+      .setWorkDir(new File(baseDir, ".sonar"));
+    return newDefaultInputProject(definition);
+  }
+
+  public static DefaultInputProject newDefaultInputProject(ProjectDefinition projectDefinition) {
+    return new DefaultInputProject(projectDefinition, TestInputFileBuilder.nextBatchId());
+  }
+
+  public static DefaultInputProject newDefaultInputProject(String key, Path baseDir) throws IOException {
+    Files.createDirectory(baseDir);
+    return newDefaultInputProject(key, baseDir.toFile());
+  }
+
+  public static DefaultInputDir newDefaultInputDir(AbstractProjectOrModule module, String relativePath) throws IOException {
     Path basedir = module.getBaseDir().resolve(relativePath);
     Files.createDirectory(basedir);
     return new DefaultInputDir(module.key(), relativePath)
       .setModuleBaseDir(module.getBaseDir());
   }
 
-  public static DefaultInputFile newDefaultInputFile(Path projectBaseDir, DefaultInputModule module, String relativePath) {
+  public static DefaultInputFile newDefaultInputFile(Path projectBaseDir, AbstractProjectOrModule module, String relativePath) {
     return new TestInputFileBuilder(module.key(), relativePath)
       .setStatus(InputFile.Status.SAME)
       .setProjectBaseDir(projectBaseDir)
index 806cc24277d96ae89af6ea93bda3fd576a8bf68e..f207b2680c9f01068d91d5d3fcfe93b91ec711e6 100644 (file)
@@ -42,6 +42,7 @@ import org.sonar.api.batch.sensor.rule.NewAdHocRule;
 import org.sonar.api.batch.sensor.symbol.NewSymbolTable;
 import org.sonar.api.config.Configuration;
 import org.sonar.api.config.Settings;
+import org.sonar.api.scanner.fs.InputProject;
 import org.sonar.api.utils.Version;
 
 /**
@@ -75,9 +76,17 @@ public interface SensorContext {
 
   /**
    * @since 5.5
+   * @deprecated since 7.6 modules are deprecated. Use {@link #project()} instead.
    */
+  @Deprecated
   InputModule module();
 
+  /**
+   * The current project.
+   * @since 7.6
+   */
+  InputProject project();
+
   /**
    * Version of API at runtime, not at compilation time. It's a shortcut on
    * {@code runtime().getApiVersion()} since 6.0.
index 58286e136e7030b949054a62cd4530bd5296eee5..e8cc9f81b8f47f89800ff8418e37ad3b7949b63f 100644 (file)
@@ -42,6 +42,7 @@ import org.sonar.api.batch.fs.TextRange;
 import org.sonar.api.batch.fs.internal.DefaultFileSystem;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.batch.fs.internal.DefaultTextPointer;
 import org.sonar.api.batch.rule.ActiveRules;
 import org.sonar.api.batch.rule.internal.ActiveRulesBuilder;
@@ -82,6 +83,7 @@ import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.internal.ApiVersion;
 import org.sonar.api.internal.SonarRuntimeImpl;
 import org.sonar.api.measures.Metric;
+import org.sonar.api.scanner.fs.InputProject;
 import org.sonar.api.utils.System2;
 import org.sonar.api.utils.Version;
 
@@ -89,18 +91,17 @@ import static java.util.Collections.unmodifiableMap;
 
 /**
  * Utility class to help testing {@link Sensor}. This is not an API and method signature may evolve.
- * 
+ * <p>
  * Usage: call {@link #create(File)} to create an "in memory" implementation of {@link SensorContext} with a filesystem initialized with provided baseDir.
  * <p>
  * You have to manually register inputFiles using:
  * <pre>
  *   sensorContextTester.fileSystem().add(new DefaultInputFile("myProjectKey", "src/Foo.java")
     .setLanguage("java")
     .initMetadata("public class Foo {\n}"));
* .setLanguage("java")
* .initMetadata("public class Foo {\n}"));
  * </pre>
  * <p>
  * Then pass it to your {@link Sensor}. You can then query elements provided by your sensor using methods {@link #allIssues()}, ...
- * 
  */
 public class SensorContextTester implements SensorContext {
 
@@ -108,6 +109,7 @@ public class SensorContextTester implements SensorContext {
   private DefaultFileSystem fs;
   private ActiveRules activeRules;
   private InMemorySensorStorage sensorStorage;
+  private DefaultInputProject project;
   private DefaultInputModule module;
   private SonarRuntime runtime;
   private boolean cancelled;
@@ -117,6 +119,7 @@ public class SensorContextTester implements SensorContext {
     this.fs = new DefaultFileSystem(moduleBaseDir).setEncoding(Charset.defaultCharset());
     this.activeRules = new ActiveRulesBuilder().build();
     this.sensorStorage = new InMemorySensorStorage();
+    this.project = new DefaultInputProject(ProjectDefinition.create().setKey("projectKey").setBaseDir(moduleBaseDir.toFile()).setWorkDir(moduleBaseDir.resolve(".sonar").toFile()));
     this.module = new DefaultInputModule(ProjectDefinition.create().setKey("projectKey").setBaseDir(moduleBaseDir.toFile()).setWorkDir(moduleBaseDir.resolve(".sonar").toFile()));
     this.runtime = SonarRuntimeImpl.forSonarQube(ApiVersion.load(System2.INSTANCE), SonarQubeSide.SCANNER);
   }
@@ -201,6 +204,11 @@ public class SensorContextTester implements SensorContext {
     return module;
   }
 
+  @Override
+  public InputProject project() {
+    return project;
+  }
+
   @Override
   public <G extends Serializable> NewMeasure<G> newMeasure() {
     return new DefaultMeasure<>(sensorStorage);
@@ -220,7 +228,7 @@ public class SensorContextTester implements SensorContext {
 
   @Override
   public NewIssue newIssue() {
-    return new DefaultIssue(module, sensorStorage);
+    return new DefaultIssue(project, sensorStorage);
   }
 
   public Collection<Issue> allIssues() {
@@ -229,7 +237,7 @@ public class SensorContextTester implements SensorContext {
 
   @Override
   public NewExternalIssue newExternalIssue() {
-    return new DefaultExternalIssue(module, sensorStorage);
+    return new DefaultExternalIssue(project, sensorStorage);
   }
 
   @Override
@@ -331,9 +339,10 @@ public class SensorContextTester implements SensorContext {
   /**
    * Return list of syntax highlighting applied for a given position in a file. The result is a list because in theory you
    * can apply several styles to the same range.
+   *
    * @param componentKey Key of the file like 'myProjectKey:src/foo.php'
-   * @param line Line you want to query
-   * @param lineOffset Offset you want to query.
+   * @param line         Line you want to query
+   * @param lineOffset   Offset you want to query.
    * @return List of styles applied to this position or empty list if there is no highlighting at this position.
    */
   public List<TypeOfText> highlightingTypeAt(String componentKey, int line, int lineOffset) {
@@ -353,9 +362,10 @@ public class SensorContextTester implements SensorContext {
 
   /**
    * Return list of symbol references ranges for the symbol at a given position in a file.
+   *
    * @param componentKey Key of the file like 'myProjectKey:src/foo.php'
-   * @param line Line you want to query
-   * @param lineOffset Offset you want to query.
+   * @param line         Line you want to query
+   * @param lineOffset   Offset you want to query.
    * @return List of references for the symbol (potentially empty) or null if there is no symbol at this position.
    */
   @CheckForNull
index c993ee62d07d29d0019afa5ca7c5a280d46b3606..39f01a319fca04734b82a9dea47ec1aaa7eda2c2 100644 (file)
@@ -30,6 +30,7 @@ import javax.annotation.Nullable;
 import org.sonar.api.batch.fs.InputComponent;
 import org.sonar.api.batch.fs.internal.DefaultInputDir;
 import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.batch.sensor.internal.DefaultStorable;
 import org.sonar.api.batch.sensor.internal.SensorStorage;
 import org.sonar.api.batch.sensor.issue.Issue.Flow;
@@ -45,15 +46,15 @@ import static java.util.stream.Collectors.toList;
 public abstract class AbstractDefaultIssue<T extends AbstractDefaultIssue> extends DefaultStorable {
   protected IssueLocation primaryLocation;
   protected List<List<IssueLocation>> flows = new ArrayList<>();
-  protected DefaultInputModule projectRoot;
+  protected DefaultInputProject project;
 
-  protected AbstractDefaultIssue(DefaultInputModule projectRoot) {
-    this(projectRoot, null);
+  protected AbstractDefaultIssue(DefaultInputProject project) {
+    this(project, null);
   }
 
-  public AbstractDefaultIssue(DefaultInputModule projectRoot, @Nullable SensorStorage storage) {
+  public AbstractDefaultIssue(DefaultInputProject project, @Nullable SensorStorage storage) {
     super(storage);
-    this.projectRoot = projectRoot;
+    this.project = project;
   }
 
   public IssueLocation primaryLocation() {
@@ -98,16 +99,16 @@ public abstract class AbstractDefaultIssue<T extends AbstractDefaultIssue> exten
 
     if (component instanceof DefaultInputDir) {
       DefaultInputDir dirComponent = (DefaultInputDir) component;
-      dirOrModulePath = Optional.of(projectRoot.getBaseDir().relativize(dirComponent.path()));
-    } else if (component instanceof DefaultInputModule && !Objects.equals(projectRoot.key(), component.key())) {
+      dirOrModulePath = Optional.of(project.getBaseDir().relativize(dirComponent.path()));
+    } else if (component instanceof DefaultInputModule && !Objects.equals(project.key(), component.key())) {
       DefaultInputModule moduleComponent = (DefaultInputModule) component;
-      dirOrModulePath = Optional.of(projectRoot.getBaseDir().relativize(moduleComponent.getBaseDir()));
+      dirOrModulePath = Optional.of(project.getBaseDir().relativize(moduleComponent.getBaseDir()));
     }
 
     if (dirOrModulePath.isPresent()) {
       String path = PathUtils.sanitize(dirOrModulePath.get().toString());
       DefaultIssueLocation fixedLocation = new DefaultIssueLocation();
-      fixedLocation.on(projectRoot);
+      fixedLocation.on(project);
       StringBuilder fullMessage = new StringBuilder();
       if (!isNullOrEmpty(path)) {
         fullMessage.append("[").append(path).append("] ");
index a9b9cc1051da32ffc4799213cd77921ab4d5f425..db1f22102ebf396c0673a8fef6686ed82c0594d2 100644 (file)
@@ -21,7 +21,7 @@ package org.sonar.api.batch.sensor.issue.internal;
 
 import com.google.common.base.Preconditions;
 import javax.annotation.Nullable;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.batch.rule.Severity;
 import org.sonar.api.batch.sensor.internal.SensorStorage;
 import org.sonar.api.batch.sensor.issue.ExternalIssue;
@@ -40,12 +40,12 @@ public class DefaultExternalIssue extends AbstractDefaultIssue<DefaultExternalIs
   private String engineId;
   private String ruleId;
 
-  public DefaultExternalIssue(DefaultInputModule projectRoot) {
-    this(projectRoot, null);
+  public DefaultExternalIssue(DefaultInputProject project) {
+    this(project, null);
   }
 
-  public DefaultExternalIssue(DefaultInputModule projectRoot, @Nullable SensorStorage storage) {
-    super(projectRoot, storage);
+  public DefaultExternalIssue(DefaultInputProject project, @Nullable SensorStorage storage) {
+    super(project, storage);
   }
 
   @Override
index 1b7de9d9ab0c0d1fde44e57455c831c24b3b37d3..770562eb1d20ade45a7ec71513a14dc2acea9827 100644 (file)
@@ -21,7 +21,7 @@ package org.sonar.api.batch.sensor.issue.internal;
 
 import com.google.common.base.Preconditions;
 import javax.annotation.Nullable;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.batch.rule.Severity;
 import org.sonar.api.batch.sensor.internal.SensorStorage;
 import org.sonar.api.batch.sensor.issue.Issue;
@@ -38,12 +38,12 @@ public class DefaultIssue extends AbstractDefaultIssue<DefaultIssue> implements
   private Double gap;
   private Severity overriddenSeverity;
 
-  public DefaultIssue(DefaultInputModule projectRoot) {
-    this(projectRoot, null);
+  public DefaultIssue(DefaultInputProject project) {
+    this(project, null);
   }
 
-  public DefaultIssue(DefaultInputModule projectRoot, @Nullable SensorStorage storage) {
-    super(projectRoot, storage);
+  public DefaultIssue(DefaultInputProject project, @Nullable SensorStorage storage) {
+    super(project, storage);
   }
 
   public DefaultIssue forRule(RuleKey ruleKey) {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/scanner/fs/InputProject.java b/sonar-plugin-api/src/main/java/org/sonar/api/scanner/fs/InputProject.java
new file mode 100644 (file)
index 0000000..8f9deed
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.api.scanner.fs;
+
+
+import javax.annotation.concurrent.Immutable;
+import org.sonar.api.batch.fs.InputComponent;
+import org.sonar.api.batch.sensor.SensorContext;
+
+/**
+ * Used to create issues and measures on project. You can access InputProject using {@link SensorContext#project()}
+ *
+ * @since 7.6
+ */
+@Immutable
+public interface InputProject extends InputComponent {
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/scanner/fs/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/scanner/fs/package-info.java
new file mode 100644 (file)
index 0000000..d99b143
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+@javax.annotation.ParametersAreNonnullByDefault
+package org.sonar.api.scanner.fs;
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputModuleTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputModuleTest.java
deleted file mode 100644 (file)
index 46065a5..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.api.batch.fs.internal;
-
-import java.io.File;
-import java.io.IOException;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.sonar.api.batch.bootstrap.ProjectDefinition;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class DefaultInputModuleTest {
-
-  @Rule
-  public TemporaryFolder temp = new TemporaryFolder();
-
-  @Test
-  public void testGetters() throws IOException {
-    ProjectDefinition def = ProjectDefinition.create();
-    def.setKey("projectKey");
-    def.setName("projectName");
-    File baseDir = temp.newFolder();
-    def.setBaseDir(baseDir);
-    def.setVersion("version");
-    def.setDescription("desc");
-    File workDir = temp.newFolder();
-    def.setWorkDir(workDir);
-    def.setSources("file1");
-    def.setTests("test1");
-    DefaultInputModule module = new DefaultInputModule(def);
-
-    assertThat(module.key()).isEqualTo("projectKey");
-    assertThat(module.getName()).isEqualTo("projectName");
-    assertThat(module.getOriginalName()).isEqualTo("projectName");
-    assertThat(module.definition()).isEqualTo(def);
-    assertThat(module.getBranch()).isNull();
-    assertThat(module.getBaseDir()).isEqualTo(baseDir.toPath());
-    assertThat(module.getKeyWithBranch()).isEqualTo("projectKey");
-    assertThat(module.getVersion()).isEqualTo("version");
-    assertThat(module.getOriginalVersion()).isEqualTo("version");
-    assertThat(module.getDescription()).isEqualTo("desc");
-    assertThat(module.getWorkDir()).isEqualTo(workDir.toPath());
-
-    assertThat(module.properties()).hasSize(6);
-
-    assertThat(module.isFile()).isFalse();
-  }
-
-}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputProjectTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputProjectTest.java
new file mode 100644 (file)
index 0000000..e9e54e5
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.api.batch.fs.internal;
+
+import java.io.File;
+import java.io.IOException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class DefaultInputProjectTest {
+
+  @Rule
+  public TemporaryFolder temp = new TemporaryFolder();
+
+  @Test
+  public void testGetters() throws IOException {
+    ProjectDefinition def = ProjectDefinition.create();
+    def.setKey("projectKey");
+    def.setName("projectName");
+    File baseDir = temp.newFolder();
+    def.setBaseDir(baseDir);
+    def.setVersion("version");
+    def.setDescription("desc");
+    File workDir = temp.newFolder();
+    def.setWorkDir(workDir);
+    def.setSources("file1");
+    def.setTests("test1");
+    AbstractProjectOrModule module = new DefaultInputProject(def);
+
+    assertThat(module.key()).isEqualTo("projectKey");
+    assertThat(module.getName()).isEqualTo("projectName");
+    assertThat(module.getOriginalName()).isEqualTo("projectName");
+    assertThat(module.definition()).isEqualTo(def);
+    assertThat(module.getBranch()).isNull();
+    assertThat(module.getBaseDir()).isEqualTo(baseDir.toPath());
+    assertThat(module.getKeyWithBranch()).isEqualTo("projectKey");
+    assertThat(module.getVersion()).isEqualTo("version");
+    assertThat(module.getOriginalVersion()).isEqualTo("version");
+    assertThat(module.getDescription()).isEqualTo("desc");
+    assertThat(module.getWorkDir()).isEqualTo(workDir.toPath());
+
+    assertThat(module.properties()).hasSize(6);
+
+    assertThat(module.isFile()).isFalse();
+  }
+
+}
index 702a76984f8bcd85d2c8a8527c74b48e58c04454..376536e6b7bf72d27f20ad03c52f5b9ebaef38ec 100644 (file)
@@ -65,7 +65,7 @@ public class TestInputFileBuilderTest {
   @Test
   public void testCreateInputModule() throws IOException {
     File baseDir = temp.newFolder();
-    DefaultInputModule module = TestInputFileBuilder.newDefaultInputModule("key", baseDir);
+    AbstractProjectOrModule module = TestInputFileBuilder.newDefaultInputModule("key", baseDir);
     assertThat(module.key()).isEqualTo("key");
     assertThat(module.getBaseDir()).isEqualTo(baseDir.toPath());
   }
index 6ef27d97f3cd2cd3ecf97d9dd0e4145999719da1..a2d07c75b20f562a3a3c1bde18896a8af14b1df8 100644 (file)
@@ -28,7 +28,7 @@ import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
 import org.sonar.api.batch.fs.InputComponent;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
 import org.sonar.api.batch.rule.Severity;
 import org.sonar.api.batch.sensor.internal.SensorStorage;
@@ -44,11 +44,11 @@ public class DefaultExternalIssueTest {
   @Rule
   public TemporaryFolder temp = new TemporaryFolder();
 
-  private DefaultInputModule projectRoot;
+  private DefaultInputProject project;
 
   @Before
   public void setup() throws IOException {
-    projectRoot = new DefaultInputModule(ProjectDefinition.create()
+    project = new DefaultInputProject(ProjectDefinition.create()
       .setKey("foo")
       .setBaseDir(temp.newFolder())
       .setWorkDir(temp.newFolder()));
@@ -64,7 +64,7 @@ public class DefaultExternalIssueTest {
   @Test
   public void build_file_issue() {
     SensorStorage storage = mock(SensorStorage.class);
-    DefaultExternalIssue issue = new DefaultExternalIssue(projectRoot, storage)
+    DefaultExternalIssue issue = new DefaultExternalIssue(project, storage)
       .at(new DefaultIssueLocation()
         .on(inputFile)
         .at(inputFile.selectLine(1))
@@ -92,7 +92,7 @@ public class DefaultExternalIssueTest {
   @Test
   public void fail_to_store_if_no_type() {
     SensorStorage storage = mock(SensorStorage.class);
-    DefaultExternalIssue issue = new DefaultExternalIssue(projectRoot, storage)
+    DefaultExternalIssue issue = new DefaultExternalIssue(project, storage)
       .at(new DefaultIssueLocation()
         .on(inputFile)
         .at(inputFile.selectLine(1))
@@ -109,7 +109,7 @@ public class DefaultExternalIssueTest {
   @Test
   public void fail_to_store_if_primary_location_is_not_a_file() {
     SensorStorage storage = mock(SensorStorage.class);
-    DefaultExternalIssue issue = new DefaultExternalIssue(projectRoot, storage)
+    DefaultExternalIssue issue = new DefaultExternalIssue(project, storage)
       .at(new DefaultIssueLocation()
         .on(mock(InputComponent.class))
         .message("Wrong way!"))
@@ -125,7 +125,7 @@ public class DefaultExternalIssueTest {
   @Test
   public void fail_to_store_if_primary_location_has_no_message() {
     SensorStorage storage = mock(SensorStorage.class);
-    DefaultExternalIssue issue = new DefaultExternalIssue(projectRoot, storage)
+    DefaultExternalIssue issue = new DefaultExternalIssue(project, storage)
       .at(new DefaultIssueLocation()
         .on(inputFile)
         .at(inputFile.selectLine(1)))
@@ -142,7 +142,7 @@ public class DefaultExternalIssueTest {
   @Test
   public void fail_to_store_if_no_severity() {
     SensorStorage storage = mock(SensorStorage.class);
-    DefaultExternalIssue issue = new DefaultExternalIssue(projectRoot, storage)
+    DefaultExternalIssue issue = new DefaultExternalIssue(project, storage)
       .at(new DefaultIssueLocation()
         .on(inputFile)
         .at(inputFile.selectLine(1))
index 5d36dcd2a9c88be2911232cf8c281372638755df..9fc659844326d023f2f782ef3a0291eb15acf819 100644 (file)
@@ -29,6 +29,7 @@ import org.sonar.api.batch.bootstrap.ProjectDefinition;
 import org.sonar.api.batch.fs.internal.DefaultInputDir;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
 import org.sonar.api.batch.rule.Severity;
 import org.sonar.api.batch.sensor.internal.SensorStorage;
@@ -43,7 +44,7 @@ public class DefaultIssueTest {
   @Rule
   public TemporaryFolder temp = new TemporaryFolder();
 
-  private DefaultInputModule projectRoot;
+  private DefaultInputProject project;
 
   private DefaultInputFile inputFile = new TestInputFileBuilder("foo", "src/Foo.php")
     .initMetadata("Foo\nBar\n")
@@ -51,7 +52,7 @@ public class DefaultIssueTest {
 
   @Before
   public void prepare() throws IOException {
-    projectRoot = new DefaultInputModule(ProjectDefinition.create()
+    project = new DefaultInputProject(ProjectDefinition.create()
       .setKey("foo")
       .setBaseDir(temp.newFolder())
       .setWorkDir(temp.newFolder()));
@@ -60,7 +61,7 @@ public class DefaultIssueTest {
   @Test
   public void build_file_issue() {
     SensorStorage storage = mock(SensorStorage.class);
-    DefaultIssue issue = new DefaultIssue(projectRoot, storage)
+    DefaultIssue issue = new DefaultIssue(project, storage)
       .at(new DefaultIssueLocation()
         .on(inputFile)
         .at(inputFile.selectLine(1))
@@ -82,14 +83,14 @@ public class DefaultIssueTest {
   @Test
   public void move_directory_issue_to_project_root() {
     SensorStorage storage = mock(SensorStorage.class);
-    DefaultIssue issue = new DefaultIssue(projectRoot, storage)
+    DefaultIssue issue = new DefaultIssue(project, storage)
       .at(new DefaultIssueLocation()
-        .on(new DefaultInputDir("foo", "src/main").setModuleBaseDir(projectRoot.getBaseDir()))
+        .on(new DefaultInputDir("foo", "src/main").setModuleBaseDir(project.getBaseDir()))
         .message("Wrong way!"))
       .forRule(RuleKey.of("repo", "rule"))
       .overrideSeverity(Severity.BLOCKER);
 
-    assertThat(issue.primaryLocation().inputComponent()).isEqualTo(projectRoot);
+    assertThat(issue.primaryLocation().inputComponent()).isEqualTo(project);
     assertThat(issue.ruleKey()).isEqualTo(RuleKey.of("repo", "rule"));
     assertThat(issue.primaryLocation().textRange()).isNull();
     assertThat(issue.primaryLocation().message()).isEqualTo("[src/main] Wrong way!");
@@ -102,25 +103,25 @@ public class DefaultIssueTest {
 
   @Test
   public void move_submodule_issue_to_project_root() {
-    File subModuleDirectory = new File(projectRoot.getBaseDir().toString(), "bar");
+    File subModuleDirectory = new File(project.getBaseDir().toString(), "bar");
     subModuleDirectory.mkdir();
 
     ProjectDefinition subModuleDefinition = ProjectDefinition.create()
       .setKey("foo/bar")
       .setBaseDir(subModuleDirectory)
       .setWorkDir(subModuleDirectory);
-    projectRoot.definition().addSubProject(subModuleDefinition);
+    project.definition().addSubProject(subModuleDefinition);
     DefaultInputModule subModule = new DefaultInputModule(subModuleDefinition);
 
     SensorStorage storage = mock(SensorStorage.class);
-    DefaultIssue issue = new DefaultIssue(projectRoot, storage)
+    DefaultIssue issue = new DefaultIssue(project, storage)
       .at(new DefaultIssueLocation()
         .on(subModule)
         .message("Wrong way!"))
       .forRule(RuleKey.of("repo", "rule"))
       .overrideSeverity(Severity.BLOCKER);
 
-    assertThat(issue.primaryLocation().inputComponent()).isEqualTo(projectRoot);
+    assertThat(issue.primaryLocation().inputComponent()).isEqualTo(project);
     assertThat(issue.ruleKey()).isEqualTo(RuleKey.of("repo", "rule"));
     assertThat(issue.primaryLocation().textRange()).isNull();
     assertThat(issue.primaryLocation().message()).isEqualTo("[bar] Wrong way!");
@@ -135,7 +136,7 @@ public class DefaultIssueTest {
   public void build_project_issue() throws IOException {
     SensorStorage storage = mock(SensorStorage.class);
     DefaultInputModule inputModule = new DefaultInputModule(ProjectDefinition.create().setKey("foo").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder()));
-    DefaultIssue issue = new DefaultIssue(projectRoot, storage)
+    DefaultIssue issue = new DefaultIssue(project, storage)
       .at(new DefaultIssueLocation()
         .on(inputModule)
         .message("Wrong way!"))
index 88de1ff2d517f72c76bd8108f8df82b06fd6eb27..f6133e9fd6d50cf62d15af3e1b55bf075861bc7f 100644 (file)
@@ -25,7 +25,8 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.AbstractProjectOrModule;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
 import org.sonar.api.batch.sensor.internal.SensorStorage;
 import org.sonar.api.measures.CoreMetrics;
@@ -62,7 +63,7 @@ public class DefaultMeasureTest {
   @Test
   public void build_project_measure() throws IOException {
     SensorStorage storage = mock(SensorStorage.class);
-    DefaultInputModule module = new DefaultInputModule(ProjectDefinition.create().setKey("foo").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder()));
+    AbstractProjectOrModule module = new DefaultInputProject(ProjectDefinition.create().setKey("foo").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder()));
     DefaultMeasure<Integer> newMeasure = new DefaultMeasure<Integer>(storage)
       .forMetric(CoreMetrics.LINES)
       .on(module)
@@ -82,7 +83,7 @@ public class DefaultMeasureTest {
     thrown.expect(IllegalStateException.class);
     thrown.expectMessage("on() already called");
     new DefaultMeasure<Integer>()
-      .on(new DefaultInputModule(ProjectDefinition.create().setKey("foo").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder())))
+      .on(new DefaultInputProject(ProjectDefinition.create().setKey("foo").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder())))
       .on(new TestInputFileBuilder("foo", "src/Foo.php").build())
       .withValue(3)
       .save();
index 77195937afdaad19d49b5264acf04d513eb59e1f..75c8725b8a8218053d82012f7cc807c827a72321 100644 (file)
@@ -36,10 +36,9 @@ import org.sonar.scanner.bootstrap.GlobalContainer;
  */
 public final class Batch {
 
-  private boolean started = false;
   private LoggingConfiguration loggingConfig;
   private List<Object> components;
-  private Map<String, String> globalProperties = new HashMap<>();
+  private Map<String, String> scannerProperties = new HashMap<>();
   private GlobalContainer bootstrapContainer;
 
   private Batch(Builder builder) {
@@ -48,11 +47,11 @@ public final class Batch {
     if (builder.environment != null) {
       components.add(builder.environment);
     }
-    if (builder.globalProperties != null) {
-      globalProperties.putAll(builder.globalProperties);
+    if (builder.scannerProperties != null) {
+      scannerProperties.putAll(builder.scannerProperties);
     }
     if (builder.isEnableLoggingConfiguration()) {
-      loggingConfig = new LoggingConfiguration(builder.environment).setProperties(globalProperties);
+      loggingConfig = new LoggingConfiguration(builder.environment).setProperties(scannerProperties);
 
       if (builder.logOutput != null) {
         loggingConfig.setLogOutput(builder.logOutput);
@@ -68,7 +67,7 @@ public final class Batch {
     configureLogging();
     doStart();
     try {
-      doExecuteTask(globalProperties);
+      doExecute();
     } finally {
       doStop();
     }
@@ -81,21 +80,16 @@ public final class Batch {
    */
   @Deprecated
   public synchronized Batch start() {
-    if (started) {
-      throw new IllegalStateException("Scanner Engine is already started");
-    }
-    configureLogging();
-    return doStart();
+    return this;
   }
 
   private Batch doStart() {
     try {
-      bootstrapContainer = GlobalContainer.create(globalProperties, components);
+      bootstrapContainer = GlobalContainer.create(scannerProperties, components);
       bootstrapContainer.startComponents();
     } catch (RuntimeException e) {
       throw handleException(e);
     }
-    this.started = true;
 
     return this;
   }
@@ -106,26 +100,18 @@ public final class Batch {
    */
   @Deprecated
   public Batch executeTask(Map<String, String> analysisProperties, Object... components) {
-    checkStarted();
-    configureTaskLogging(analysisProperties);
-    return doExecuteTask(analysisProperties, components);
+    return execute();
   }
 
-  private Batch doExecuteTask(Map<String, String> analysisProperties, Object... components) {
+  private Batch doExecute(Object... components) {
     try {
-      bootstrapContainer.executeTask(analysisProperties, components);
+      bootstrapContainer.executeTask(scannerProperties, components);
     } catch (RuntimeException e) {
       throw handleException(e);
     }
     return this;
   }
 
-  private void checkStarted() {
-    if (!started) {
-      throw new IllegalStateException("Scanner engine is not started. Unable to execute task.");
-    }
-  }
-
   private RuntimeException handleException(RuntimeException t) {
     if (loggingConfig.isVerbose()) {
       return t;
@@ -146,9 +132,6 @@ public final class Batch {
    */
   @Deprecated
   public synchronized void stop() {
-    checkStarted();
-    configureLogging();
-    doStop();
   }
 
   private void doStop() {
@@ -157,19 +140,11 @@ public final class Batch {
     } catch (RuntimeException e) {
       throw handleException(e);
     }
-    this.started = false;
   }
 
   private void configureLogging() {
     if (loggingConfig != null) {
-      loggingConfig.setProperties(globalProperties);
-      LoggingConfigurator.apply(loggingConfig);
-    }
-  }
-
-  private void configureTaskLogging(Map<String, String> taskProperties) {
-    if (loggingConfig != null) {
-      loggingConfig.setProperties(taskProperties, globalProperties);
+      loggingConfig.setProperties(scannerProperties);
       LoggingConfigurator.apply(loggingConfig);
     }
   }
@@ -179,7 +154,7 @@ public final class Batch {
   }
 
   public static final class Builder {
-    private Map<String, String> globalProperties;
+    private Map<String, String> scannerProperties;
     private EnvironmentInformation environment;
     private List<Object> components = new ArrayList<>();
     private boolean enableLoggingConfiguration = true;
@@ -203,17 +178,17 @@ public final class Batch {
       return this;
     }
 
-    public Builder setGlobalProperties(Map<String, String> globalProperties) {
-      this.globalProperties = globalProperties;
+    public Builder setScannerProperties(Map<String, String> scannerProperties) {
+      this.scannerProperties = scannerProperties;
       return this;
     }
 
     /**
-     * @deprecated since 6.6 use {@link #setGlobalProperties(Map)}
+     * @deprecated since 6.6 use {@link #setScannerProperties(Map)}
      */
     @Deprecated
     public Builder setBootstrapProperties(Map<String, String> bootstrapProperties) {
-      this.globalProperties = bootstrapProperties;
+      this.scannerProperties = bootstrapProperties;
       return this;
     }
 
index 08e2236cfec740e0b1c5381031fd18961a6aebf6..94c6175298d2f465a39a896a3b1f042f9d225c16 100644 (file)
@@ -66,12 +66,7 @@ public final class LoggingConfiguration {
   }
 
   public LoggingConfiguration setProperties(Map<String, String> properties) {
-    setVerbose(properties, null);
-    return this;
-  }
-
-  public LoggingConfiguration setProperties(Map<String, String> properties, @Nullable Map<String, String> fallback) {
-    setVerbose(properties, fallback);
+    setVerbose(properties);
     return this;
   }
 
@@ -88,10 +83,10 @@ public final class LoggingConfiguration {
     return verbose;
   }
 
-  public LoggingConfiguration setVerbose(Map<String, String> props, @Nullable Map<String, String> 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)) ||
+  public LoggingConfiguration setVerbose(Map<String, String> props) {
+    String logLevel = props.get("sonar.log.level");
+    String deprecatedProfilingLevel = props.get("sonar.log.profilingLevel");
+    verbose = "true".equals(props.get("sonar.verbose")) ||
       "DEBUG".equals(logLevel) || "TRACE".equals(logLevel) ||
       "BASIC".equals(deprecatedProfilingLevel) || "FULL".equals(deprecatedProfilingLevel);
 
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/AnalysisProperties.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/AnalysisProperties.java
deleted file mode 100644 (file)
index 0814ebd..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.scanner.analysis;
-
-import java.util.Map;
-import javax.annotation.Nullable;
-import org.sonar.scanner.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<String, String> properties) {
-    this(properties, null);
-
-  }
-
-  public AnalysisProperties(Map<String, String> properties, @Nullable String pathToSecretKey) {
-    super(properties, pathToSecretKey);
-  }
-
-}
index 84f8b64a2649845d3560cd888eb1236e2f7fd9cd..9d263b17667646aa016c0cce7f7c804b2e03aa91 100644 (file)
@@ -25,7 +25,7 @@ import java.nio.file.Path;
 import org.picocontainer.ComponentLifecycle;
 import org.picocontainer.PicoContainer;
 import org.picocontainer.injectors.ProviderAdapter;
-import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.utils.TempFolder;
 import org.sonar.api.utils.internal.DefaultTempFolder;
 
@@ -34,9 +34,9 @@ public class AnalysisTempFolderProvider extends ProviderAdapter implements Compo
   private DefaultTempFolder projectTempFolder;
   private boolean started = false;
 
-  public TempFolder provide(InputModuleHierarchy moduleHierarchy) {
+  public TempFolder provide(DefaultInputProject project) {
     if (projectTempFolder == null) {
-      Path workingDir = moduleHierarchy.root().getWorkDir();
+      Path workingDir = project.getWorkDir();
       Path tempDir = workingDir.normalize().resolve(TMP_NAME);
       try {
         Files.deleteIfExists(tempDir);
index fbd3dbc274016861892fd288ffd9c2cf19e1c9fe..b97e63b9ee17119221ee34a90450eda9e61c351b 100644 (file)
@@ -25,6 +25,7 @@ import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
+import org.sonar.scanner.bootstrap.ScannerProperties;
 
 @Immutable
 public class DefaultAnalysisMode implements AnalysisMode {
@@ -36,7 +37,7 @@ public class DefaultAnalysisMode implements AnalysisMode {
 
   private boolean scanAllFiles;
 
-  public DefaultAnalysisMode(AnalysisProperties props, GlobalAnalysisMode analysisMode) {
+  public DefaultAnalysisMode(ScannerProperties props, GlobalAnalysisMode analysisMode) {
     this.analysisMode = analysisMode;
     this.analysisProps = props.properties();
     load();
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/DroppedPropertyChecker.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/DroppedPropertyChecker.java
deleted file mode 100644 (file)
index 544db2e..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.scanner.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<String, String> settings;
-  private final Map<String, String> properties;
-
-  public DroppedPropertyChecker(Map<String, String> properties, Map<String, String> droppedPropertiesAndMsg) {
-    this.settings = requireNonNull(properties);
-    this.properties = requireNonNull(droppedPropertiesAndMsg);
-  }
-
-  public void checkDroppedProperties() {
-    for (Map.Entry<String, String> entry : properties.entrySet()) {
-      if (settings.containsKey(entry.getKey())) {
-        LOG.warn("Property '{}' is not supported any more. {}", entry.getKey(), entry.getValue());
-      }
-    }
-  }
-
-}
index 3e93000db2b4313c7641466eb38b07fe2b0a9f2c..202fbbcecfab6b174096b640770d0e319beb8572 100644 (file)
@@ -36,7 +36,7 @@ public class GlobalAnalysisMode {
   protected boolean issues;
   protected boolean mediumTestMode;
 
-  public GlobalAnalysisMode(GlobalProperties props) {
+  public GlobalAnalysisMode(ScannerProperties props) {
     String mode = props.property(CoreProperties.ANALYSIS_MODE);
     validate(mode);
     issues = CoreProperties.ANALYSIS_MODE_ISSUES.equals(mode) || CoreProperties.ANALYSIS_MODE_PREVIEW.equals(mode);
index 659aa4707b766d026d2a96764b8379a97e5e6e9b..eb5c23b442a1f58a78f3f453d285e16306472c24 100644 (file)
  */
 package org.sonar.scanner.bootstrap;
 
-import com.google.common.collect.ImmutableMap;
 import java.util.Map;
 import javax.annotation.concurrent.Immutable;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.sonar.api.CoreProperties;
 import org.sonar.api.config.Encryption;
 import org.sonar.api.config.PropertyDefinitions;
 import org.sonar.scanner.config.DefaultConfiguration;
@@ -34,29 +32,10 @@ public class GlobalConfiguration extends DefaultConfiguration {
 
   private static final Logger LOG = LoggerFactory.getLogger(GlobalConfiguration.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<String, String> DROPPED_PROPERTIES = ImmutableMap.of(
-    "sonar.jdbc.url", JDBC_SPECIFIC_MESSAGE,
-    "sonar.jdbc.username", JDBC_SPECIFIC_MESSAGE,
-    "sonar.jdbc.password", JDBC_SPECIFIC_MESSAGE);
-
-  private final Map<String, String> serverSideSettings;
-
   public GlobalConfiguration(PropertyDefinitions propertyDefinitions, Encryption encryption, GlobalAnalysisMode mode,
-    Map<String, String> settings, Map<String, String> serverSideSettings) {
+                             Map<String, String> settings) {
     super(propertyDefinitions, encryption, mode, settings);
-    this.serverSideSettings = unmodifiableMapWithTrimmedValues(propertyDefinitions, serverSideSettings);
-
-    get(CoreProperties.SERVER_ID).ifPresent(v -> LOG.info("Server id: {}", v));
-    new DroppedPropertyChecker(getProperties(), DROPPED_PROPERTIES).checkDroppedProperties();
   }
 
-  public Map<String, String> getServerSideSettings() {
-    return serverSideSettings;
-  }
 
 }
index 0bd13d2e459419c255fe4d231b09d6d4fa588e47..255700fd0a06bc3112450a5ab0ca7f17fbdc4bbd 100644 (file)
@@ -23,23 +23,19 @@ import java.util.LinkedHashMap;
 import java.util.Map;
 import org.picocontainer.injectors.ProviderAdapter;
 import org.sonar.api.config.PropertyDefinitions;
-import org.sonar.scanner.repository.settings.SettingsLoader;
 
 public class GlobalConfigurationProvider extends ProviderAdapter {
 
-  private GlobalConfiguration globalSettings;
+  private GlobalConfiguration globalConfig;
 
-  public GlobalConfiguration provide(SettingsLoader loader, GlobalProperties globalProps, PropertyDefinitions propertyDefinitions, GlobalAnalysisMode mode) {
-    if (globalSettings == null) {
+  public GlobalConfiguration provide(GlobalServerSettings globalServerSettings, ScannerProperties scannerProps, PropertyDefinitions propertyDefinitions, GlobalAnalysisMode mode) {
+    if (globalConfig == null) {
+      Map<String, String> mergedSettings = new LinkedHashMap<>();
+      mergedSettings.putAll(globalServerSettings.properties());
+      mergedSettings.putAll(scannerProps.properties());
 
-      Map<String, String> serverSideSettings = loader.load(null);
-
-      Map<String, String> settings = new LinkedHashMap<>();
-      settings.putAll(serverSideSettings);
-      settings.putAll(globalProps.properties());
-
-      globalSettings = new GlobalConfiguration(propertyDefinitions, globalProps.getEncryption(), mode, settings, serverSideSettings);
+      globalConfig = new GlobalConfiguration(propertyDefinitions, scannerProps.getEncryption(), mode, mergedSettings);
     }
-    return globalSettings;
+    return globalConfig;
   }
 }
index 6386b20c72047e199e9719a166bf4e820f8908ad..61e6534972c43d154ef828ef162dd938cd06db57 100644 (file)
@@ -53,24 +53,24 @@ import org.sonar.scanner.task.TaskContainer;
 
 public class GlobalContainer extends ComponentContainer {
   private static final Logger LOG = Loggers.get(GlobalContainer.class);
-  private final Map<String, String> bootstrapProperties;
+  private final Map<String, String> scannerProperties;
 
-  private GlobalContainer(Map<String, String> bootstrapProperties) {
+  private GlobalContainer(Map<String, String> scannerProperties) {
     super();
-    this.bootstrapProperties = bootstrapProperties;
+    this.scannerProperties = scannerProperties;
   }
 
-  public static GlobalContainer create(Map<String, String> bootstrapProperties, List<?> extensions) {
-    GlobalContainer container = new GlobalContainer(bootstrapProperties);
+  public static GlobalContainer create(Map<String, String> scannerProperties, List<?> extensions) {
+    GlobalContainer container = new GlobalContainer(scannerProperties);
     container.add(extensions);
     return container;
   }
 
   @Override
   protected void doBeforeStart() {
-    GlobalProperties bootstrapProps = new GlobalProperties(bootstrapProperties);
-    GlobalAnalysisMode globalMode = new GlobalAnalysisMode(bootstrapProps);
-    add(bootstrapProps);
+    ScannerProperties scannerProps = new ScannerProperties(scannerProperties);
+    GlobalAnalysisMode globalMode = new GlobalAnalysisMode(scannerProps);
+    add(scannerProps);
     add(globalMode);
     addBootstrapComponents();
   }
@@ -89,7 +89,7 @@ public class GlobalContainer extends ComponentContainer {
       new SonarQubeVersion(apiVersion),
       SonarRuntimeImpl.forSonarQube(apiVersion, SonarQubeSide.SCANNER),
       StoragesManager.class,
-      MutableGlobalSettings.class,
+      new GlobalServerSettingsProvider(),
       new GlobalConfigurationProvider(),
       new ScannerWsClientProvider(),
       DefaultServer.class,
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalProperties.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalProperties.java
deleted file mode 100644 (file)
index 4399598..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.scanner.bootstrap;
-
-import java.util.Map;
-import org.sonar.api.CoreProperties;
-
-/**
- * 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<String, String> properties) {
-    super(properties, properties.get(CoreProperties.ENCRYPTION_SECRET_KEY_PATH));
-  }
-
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalServerSettings.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalServerSettings.java
new file mode 100644 (file)
index 0000000..643fc27
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.scanner.bootstrap;
+
+import com.google.common.collect.ImmutableMap;
+import java.util.Map;
+import javax.annotation.concurrent.Immutable;
+
+/**
+ * Global properties coming from the server.
+ */
+@Immutable
+public class GlobalServerSettings {
+
+  private final Map<String, String> properties;
+
+  public GlobalServerSettings(Map<String, String> properties) {
+    this.properties = properties;
+  }
+
+  public Map<String, String> properties() {
+    return ImmutableMap.copyOf(properties);
+  }
+
+  public String property(String key) {
+    return properties.get(key);
+  }
+
+}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalServerSettingsProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalServerSettingsProvider.java
new file mode 100644 (file)
index 0000000..53cb91e
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.scanner.bootstrap;
+
+import java.util.Map;
+import java.util.Optional;
+import org.picocontainer.injectors.ProviderAdapter;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
+import org.sonar.scanner.repository.settings.SettingsLoader;
+
+public class GlobalServerSettingsProvider extends ProviderAdapter {
+
+  private static final Logger LOG = Loggers.get(GlobalServerSettingsProvider.class);
+
+  private GlobalServerSettings singleton;
+
+  public GlobalServerSettings provide(SettingsLoader loader) {
+    if (singleton == null) {
+      Map<String, String> serverSideSettings = loader.load(null);
+      singleton = new GlobalServerSettings(serverSideSettings);
+      Optional.ofNullable(serverSideSettings.get(CoreProperties.SERVER_ID)).ifPresent(v -> LOG.info("Server id: {}", v));
+    }
+    return singleton;
+  }
+}
index 839578c8b2c5586af35b9c3454cbeb97feec0b61..20b5e2014a194dbd28a41d89518893897a2e56b7 100644 (file)
@@ -56,14 +56,14 @@ public class GlobalTempFolderProvider extends ProviderAdapter implements Compone
     this.system = system;
   }
 
-  public TempFolder provide(GlobalProperties bootstrapProps) {
+  public TempFolder provide(ScannerProperties scannerProps) {
     if (tempFolder == null) {
 
-      String workingPathName = StringUtils.defaultIfBlank(bootstrapProps.property(CoreProperties.GLOBAL_WORKING_DIRECTORY), CoreProperties.GLOBAL_WORKING_DIRECTORY_DEFAULT_VALUE);
+      String workingPathName = StringUtils.defaultIfBlank(scannerProps.property(CoreProperties.GLOBAL_WORKING_DIRECTORY), CoreProperties.GLOBAL_WORKING_DIRECTORY_DEFAULT_VALUE);
       Path workingPath = Paths.get(workingPathName);
 
       if (!workingPath.isAbsolute()) {
-        Path home = findSonarHome(bootstrapProps);
+        Path home = findSonarHome(scannerProps);
         workingPath = home.resolve(workingPath).normalize();
       }
       try {
@@ -95,7 +95,7 @@ public class GlobalTempFolderProvider extends ProviderAdapter implements Compone
     }
   }
 
-  private Path findSonarHome(GlobalProperties props) {
+  private Path findSonarHome(ScannerProperties props) {
     String home = props.property("sonar.userHome");
     if (home != null) {
       return Paths.get(home).toAbsolutePath();
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/MutableGlobalSettings.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/MutableGlobalSettings.java
deleted file mode 100644 (file)
index f4935c6..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.scanner.bootstrap;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Optional;
-import org.sonar.api.config.Settings;
-import org.sonar.api.utils.MessageException;
-
-import static java.util.Objects.requireNonNull;
-
-/**
- * @deprecated since 6.5 {@link GlobalConfiguration} used to be mutable, so keep a mutable copy for backward compatibility.
- */
-@Deprecated
-public class MutableGlobalSettings extends Settings {
-
-  private final GlobalAnalysisMode mode;
-  private final Map<String, String> mutableProperties = new HashMap<>();
-
-  public MutableGlobalSettings(GlobalConfiguration globalSettings) {
-    super(globalSettings.getDefinitions(), globalSettings.getEncryption());
-    this.mutableProperties.putAll(globalSettings.getProperties());
-    this.mode = globalSettings.getMode();
-  }
-
-  @Override
-  protected Optional<String> get(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.");
-    }
-    return Optional.ofNullable(mutableProperties.get(key));
-  }
-
-  @Override
-  public Map<String, String> getProperties() {
-    return mutableProperties;
-  }
-
-  @Override
-  protected void set(String key, String value) {
-    mutableProperties.put(
-      requireNonNull(key, "key can't be null"),
-      requireNonNull(value, "value can't be null").trim());
-  }
-
-  @Override
-  protected void remove(String key) {
-    mutableProperties.remove(key);
-  }
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerProperties.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerProperties.java
new file mode 100644 (file)
index 0000000..a351765
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.scanner.bootstrap;
+
+import com.google.common.collect.ImmutableMap;
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.CheckForNull;
+import javax.annotation.concurrent.Immutable;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.batch.bootstrap.ProjectKey;
+import org.sonar.api.config.Encryption;
+
+import static org.apache.commons.lang.StringUtils.trimToNull;
+
+/**
+ * Properties that are coming from scanner.
+ */
+@Immutable
+public class ScannerProperties implements ProjectKey {
+
+  private final Map<String, String> properties;
+  private final Encryption encryption;
+
+  public ScannerProperties(Map<String, String> properties) {
+    encryption = new Encryption(properties.get(CoreProperties.ENCRYPTION_SECRET_KEY_PATH));
+    Map<String, String> decryptedProps = new HashMap<>(properties.size());
+    for (Map.Entry<String, String> 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 = decryptedProps;
+  }
+
+  public Encryption getEncryption() {
+    return encryption;
+  }
+
+  public Map<String, String> properties() {
+    return ImmutableMap.copyOf(properties);
+  }
+
+  public String property(String key) {
+    return properties.get(key);
+  }
+
+  @Override
+  public String get() {
+    return getKeyWithBranch();
+  }
+
+  private String getKey() {
+    return properties.get(CoreProperties.PROJECT_KEY_PROPERTY);
+  }
+
+  public String getKeyWithBranch() {
+    String branch = getBranch();
+    String projectKey = getKey();
+    if (branch == null) {
+      return projectKey;
+    }
+    return String.format("%s:%s", projectKey, branch);
+  }
+
+  @CheckForNull
+  private String getBranch() {
+    return trimToNull(properties.get(CoreProperties.PROJECT_BRANCH_PROPERTY));
+  }
+}
index 67fe816a83f369592ccc721be2dc1c45028be6fd..23370fdc0f37977233a8540878658100e4d37acb 100644 (file)
@@ -40,21 +40,21 @@ public class ScannerWsClientProvider extends ProviderAdapter {
 
   private ScannerWsClient wsClient;
 
-  public synchronized ScannerWsClient provide(final GlobalProperties settings, final EnvironmentInformation env,
-                                              GlobalAnalysisMode globalMode, System2 system) {
+  public synchronized ScannerWsClient provide(final ScannerProperties scannerProps, final EnvironmentInformation env,
+    GlobalAnalysisMode globalMode, System2 system) {
     if (wsClient == null) {
-      String url = defaultIfBlank(settings.property("sonar.host.url"), CoreProperties.SERVER_BASE_URL_DEFAULT_VALUE);
+      String url = defaultIfBlank(scannerProps.property("sonar.host.url"), CoreProperties.SERVER_BASE_URL_DEFAULT_VALUE);
       HttpConnector.Builder connectorBuilder = HttpConnector.newBuilder();
 
-      String timeoutSec = defaultIfBlank(settings.property(READ_TIMEOUT_SEC_PROPERTY), valueOf(DEFAULT_READ_TIMEOUT_SEC));
+      String timeoutSec = defaultIfBlank(scannerProps.property(READ_TIMEOUT_SEC_PROPERTY), valueOf(DEFAULT_READ_TIMEOUT_SEC));
       String token = defaultIfBlank(system.envVariable("SONAR_TOKEN"), null);
-      String login = defaultIfBlank(settings.property(CoreProperties.LOGIN), token);
+      String login = defaultIfBlank(scannerProps.property(CoreProperties.LOGIN), token);
       connectorBuilder
         .readTimeoutMilliseconds(parseInt(timeoutSec) * 1_000)
         .connectTimeoutMilliseconds(CONNECT_TIMEOUT_MS)
         .userAgent(env.toString())
         .url(url)
-        .credentials(login, settings.property(CoreProperties.PASSWORD));
+        .credentials(login, scannerProps.property(CoreProperties.PASSWORD));
 
       // OkHttp detect 'http.proxyHost' java property, but credentials should be filled
       final String proxyUser = System.getProperty("http.proxyUser", "");
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/UserProperties.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/UserProperties.java
deleted file mode 100644 (file)
index 2d27d61..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.scanner.bootstrap;
-
-import java.util.HashMap;
-import java.util.Map;
-import javax.annotation.Nullable;
-import org.sonar.api.config.Encryption;
-
-/**
- * Properties that are coming from bootstrapper.
- */
-public abstract class UserProperties {
-
-  private final Map<String, String> properties;
-  private final Encryption encryption;
-
-  public UserProperties(Map<String, String> properties, @Nullable String pathToSecretKey) {
-    encryption = new Encryption(pathToSecretKey);
-    Map<String, String> decryptedProps = new HashMap<>(properties.size());
-    for (Map.Entry<String, String> 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 = decryptedProps;
-  }
-
-  public Encryption getEncryption() {
-    return encryption;
-  }
-
-  public Map<String, String> properties() {
-    return properties;
-  }
-
-  public String property(String key) {
-    return properties.get(key);
-  }
-
-}
index 6db9f3ec45c8cd944697d1222e7d180b5ef6e71c..0800b49bc5e2226ef94a1b6fede2ca81d2764680 100644 (file)
@@ -177,7 +177,7 @@ public class CpdExecutor {
           }
 
         })::iterator;
-    publisher.getWriter().writeComponentDuplications(component.batchId(), reportDuplications);
+    publisher.getWriter().writeComponentDuplications(component.scannerId(), reportDuplications);
   }
 
   private Optional<FileBlocks> toFileBlocks(String componentKey, Collection<Block> fileBlocks) {
@@ -211,7 +211,7 @@ public class CpdExecutor {
         String componentKey = duplicate.getResourceId();
         if (!component.key().equals(componentKey)) {
           DefaultInputComponent sameProjectComponent = (DefaultInputComponent) componentStore.getByKey(componentKey);
-          blockBuilder.setOtherFileRef(sameProjectComponent.batchId());
+          blockBuilder.setOtherFileRef(sameProjectComponent.scannerId());
         }
         dupBuilder.addDuplicate(blockBuilder
           .setRange(ScannerReport.TextRange.newBuilder()
index ee53ea4a5168139fb590d56e16401079ab268f62..54b8307b120f195f9b1c2bf49d9acb68ca99f04a 100644 (file)
@@ -21,7 +21,7 @@ package org.sonar.scanner.cpd;
 
 import org.apache.commons.lang.StringUtils;
 import org.sonar.api.CoreProperties;
-import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.config.Configuration;
 import org.sonar.duplications.block.BlockChunker;
 
@@ -29,9 +29,9 @@ public class CpdSettings {
   private final Configuration settings;
   private final String branch;
 
-  public CpdSettings(Configuration settings, InputModuleHierarchy hierarchy) {
-    this.settings = settings;
-    this.branch = hierarchy.root().getBranch();
+  public CpdSettings(Configuration config, DefaultInputProject project) {
+    this.settings = config;
+    this.branch = project.getBranch();
   }
 
   public boolean isCrossProjectDuplicationEnabled() {
index 62b12c600f31351e25e97dd7a58578779ea71364..3816f214c8679fc37f1c19d8e42bfbe9de4cff87 100644 (file)
@@ -55,7 +55,7 @@ public class SonarCpdBlockIndex extends AbstractCloneIndex {
 
   public void insert(InputFile inputFile, Collection<Block> blocks) {
     if (settings.isCrossProjectDuplicationEnabled()) {
-      int id = ((DefaultInputFile) inputFile).batchId();
+      int id = ((DefaultInputFile) inputFile).scannerId();
       if (publisher.getWriter().hasComponentData(FileStructure.Domain.CPD_TEXT_BLOCKS, id)) {
         throw new UnsupportedOperationException("Trying to save CPD tokens twice for the same file is not supported: " + inputFile.absolutePath());
       }
index dcd3f413af282e4c12c6aebcfc617291a4eb8651..9f36a7aeec08412015679e5a674e3e4e157ba6b7 100644 (file)
@@ -27,7 +27,7 @@ import org.apache.commons.lang.builder.ToStringBuilder;
 import org.apache.commons.lang.builder.ToStringStyle;
 import org.sonar.api.batch.fs.InputModule;
 import org.sonar.api.batch.fs.TextRange;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.AbstractProjectOrModule;
 import org.sonar.api.batch.fs.internal.DefaultTextPointer;
 import org.sonar.api.batch.fs.internal.DefaultTextRange;
 import org.sonar.api.rule.RuleKey;
@@ -40,10 +40,10 @@ public class DefaultFilterableIssue implements FilterableIssue {
   private final Issue rawIssue;
   private final ProjectAnalysisInfo projectAnalysisInfo;
   private final String componentKey;
-  private DefaultInputModule module;
+  private AbstractProjectOrModule module;
 
   public DefaultFilterableIssue(InputModule module, ProjectAnalysisInfo projectAnalysisInfo, Issue rawIssue, String componentKey) {
-    this.module = (DefaultInputModule) module;
+    this.module = (AbstractProjectOrModule) module;
     this.projectAnalysisInfo = projectAnalysisInfo;
     this.rawIssue = rawIssue;
     this.componentKey = componentKey;
index 1d9885fcc4e17a6ef8d0505f3c126ead9dec7430..518f8620255280b5812e33fc3cc6e1ba44ce7024 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.scanner.issue;
 
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.InputModule;
 import org.sonar.api.scan.issue.filter.FilterableIssue;
 import org.sonar.api.scan.issue.filter.IssueFilter;
 import org.sonar.api.scan.issue.filter.IssueFilterChain;
@@ -32,16 +32,16 @@ import org.sonar.scanner.protocol.output.ScannerReport;
 @Deprecated
 public class ModuleIssueFilters {
   private final IssueFilterChain filterChain;
-  private final DefaultInputModule module;
+  private final InputModule module;
   private final ProjectAnalysisInfo projectAnalysisInfo;
 
-  public ModuleIssueFilters(DefaultInputModule module, ProjectAnalysisInfo projectAnalysisInfo, IssueFilter[] exclusionFilters) {
+  public ModuleIssueFilters(InputModule module, ProjectAnalysisInfo projectAnalysisInfo, IssueFilter[] exclusionFilters) {
     this.module = module;
     this.filterChain = new DefaultIssueFilterChain(exclusionFilters);
     this.projectAnalysisInfo = projectAnalysisInfo;
   }
 
-  public ModuleIssueFilters(DefaultInputModule module, ProjectAnalysisInfo projectAnalysisInfo) {
+  public ModuleIssueFilters(InputModule module, ProjectAnalysisInfo projectAnalysisInfo) {
     this(module, projectAnalysisInfo, new IssueFilter[0]);
   }
 
index ce07d5a59dba5f36e3b42993941ab4ca62ccd3ec..7cff04cee5865ca316d3840c3b08bad96a05f15d 100644 (file)
@@ -68,10 +68,10 @@ public class ModuleIssues {
       return false;
     }
 
-    ScannerReport.Issue rawIssue = createReportIssue(issue, inputComponent.batchId(), activeRule.severity());
+    ScannerReport.Issue rawIssue = createReportIssue(issue, inputComponent.scannerId(), activeRule.severity());
 
     if (filters.accept(inputComponent.key(), rawIssue)) {
-      write(inputComponent.batchId(), rawIssue);
+      write(inputComponent.scannerId(), rawIssue);
       return true;
     }
     return false;
@@ -87,8 +87,8 @@ public class ModuleIssues {
 
   public void initAndAddExternalIssue(ExternalIssue issue) {
     DefaultInputComponent inputComponent = (DefaultInputComponent) issue.primaryLocation().inputComponent();
-    ScannerReport.ExternalIssue rawExternalIssue = createReportExternalIssue(issue, inputComponent.batchId());
-    write(inputComponent.batchId(), rawExternalIssue);
+    ScannerReport.ExternalIssue rawExternalIssue = createReportExternalIssue(issue, inputComponent.scannerId());
+    write(inputComponent.scannerId(), rawExternalIssue);
   }
 
   private static ScannerReport.Issue createReportIssue(Issue issue, int componentRef, String activeRuleSeverity) {
@@ -158,7 +158,7 @@ public class ModuleIssues {
       }
       flowBuilder.clear();
       for (org.sonar.api.batch.sensor.issue.IssueLocation location : flow.locations()) {
-        int locationComponentRef = ((DefaultInputComponent) location.inputComponent()).batchId();
+        int locationComponentRef = ((DefaultInputComponent) location.inputComponent()).scannerId();
         locationBuilder.clear();
         locationBuilder.setComponentRef(locationComponentRef);
         String message = location.message();
index 6b658bd3191e09fca8a2b9287ed66246ac76c28d..dabba413c6c01446adb890e8b258794189507f2e 100644 (file)
@@ -90,7 +90,7 @@ public class IssueTransition {
   public void trackIssues(ScannerReportReader reader, DefaultInputComponent component) {
     // raw issues = all the issues created by rule engines during this module scan and not excluded by filters
     List<ScannerReport.Issue> rawIssues = new LinkedList<>();
-    try (CloseableIterator<ScannerReport.Issue> it = reader.readComponentIssues(component.batchId())) {
+    try (CloseableIterator<ScannerReport.Issue> it = reader.readComponentIssues(component.scannerId())) {
       while (it.hasNext()) {
         rawIssues.add(it.next());
       }
index 11d810688ecf68bdc68586387c4c3a25b51e566c..bf0264252058574d011a854e7bc2ef8e8ffd8d92 100644 (file)
@@ -37,7 +37,7 @@ import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.InputFile.Status;
 import org.sonar.api.batch.fs.InputModule;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.AbstractProjectOrModule;
 import org.sonar.api.batch.fs.internal.InputComponentTree;
 import org.sonar.api.batch.rule.ActiveRule;
 import org.sonar.api.batch.rule.ActiveRules;
@@ -165,7 +165,7 @@ public class LocalIssueTracking {
   private SourceHashHolder loadSourceHashes(InputComponent component) {
     SourceHashHolder sourceHashHolder = null;
     if (component.isFile()) {
-      DefaultInputModule module = (DefaultInputModule) componentTree.getParent(componentTree.getParent(component));
+      AbstractProjectOrModule module = (AbstractProjectOrModule) componentTree.getParent(componentTree.getParent(component));
       DefaultInputFile file = (DefaultInputFile) component;
       sourceHashHolder = new SourceHashHolder(module, file, lastLineHashes);
     }
index 5c11fb83d5969742b45381126aa35ac660461cc2..be8c7908ff2823fa778d7315ce2769255b3572fc 100644 (file)
@@ -22,9 +22,8 @@ package org.sonar.scanner.issue.tracking;
 import org.sonar.api.batch.InstantiationStrategy;
 import org.sonar.api.batch.ScannerSide;
 import org.sonar.api.batch.fs.InputComponent;
-import org.sonar.api.batch.fs.InputModule;
+import org.sonar.api.batch.fs.internal.AbstractProjectOrModule;
 import org.sonar.api.batch.fs.internal.DefaultInputComponent;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.api.utils.log.Profiler;
@@ -46,34 +45,35 @@ public class ServerIssueRepository {
   private Storage<ServerIssue> issuesCache;
   private final ServerIssuesLoader previousIssuesLoader;
   private final InputComponentStore componentStore;
+  private final AbstractProjectOrModule project;
 
-  public ServerIssueRepository(Storages caches, ServerIssuesLoader previousIssuesLoader, InputComponentStore componentStore) {
+  public ServerIssueRepository(Storages caches, ServerIssuesLoader previousIssuesLoader, InputComponentStore componentStore, AbstractProjectOrModule project) {
     this.caches = caches;
     this.previousIssuesLoader = previousIssuesLoader;
     this.componentStore = componentStore;
+    this.project = project;
   }
 
   public void load() {
     Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG);
     this.issuesCache = caches.createCache("previousIssues");
     caches.registerValueCoder(ServerIssue.class, new ServerIssueValueCoder());
-    DefaultInputModule root = (DefaultInputModule) componentStore.root();
-    previousIssuesLoader.load(root.getKeyWithBranch(), this::store);
+    previousIssuesLoader.load(project.getKeyWithBranch(), this::store);
     profiler.stopInfo();
   }
 
   public Iterable<ServerIssue> byComponent(InputComponent component) {
-    return issuesCache.values(((DefaultInputComponent) component).batchId());
+    return issuesCache.values(((DefaultInputComponent) component).scannerId());
   }
 
   private void store(ServerIssue issue) {
     String moduleKeyWithBranch = issue.getModuleKey();
-    InputModule module = componentStore.getModule(moduleKeyWithBranch);
-    if (module != null) {
-      String componentKeyWithoutBranch = ComponentKeys.createEffectiveKey(module.key(), issue.hasPath() ? issue.getPath() : null);
+    AbstractProjectOrModule moduleOrProject = componentStore.getModule(moduleKeyWithBranch);
+    if (moduleOrProject != null) {
+      String componentKeyWithoutBranch = ComponentKeys.createEffectiveKey(moduleOrProject.key(), issue.hasPath() ? issue.getPath() : null);
       DefaultInputComponent r = (DefaultInputComponent) componentStore.getByKey(componentKeyWithoutBranch);
       if (r != null) {
-        issuesCache.put(r.batchId(), issue.getKey(), issue);
+        issuesCache.put(r.scannerId(), issue.getKey(), issue);
         return;
       }
     }
index cb5fedcef43b0323512680ac129df6663b6a59de..b1b56be89a8660ea3382a4040d42f2662d78620e 100644 (file)
@@ -24,19 +24,19 @@ import java.util.Collections;
 import javax.annotation.CheckForNull;
 import org.sonar.api.batch.fs.InputFile.Status;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.AbstractProjectOrModule;
 import org.sonar.core.component.ComponentKeys;
 
 public class SourceHashHolder {
 
-  private final DefaultInputModule module;
+  private final AbstractProjectOrModule module;
   private final DefaultInputFile inputFile;
   private final ServerLineHashesLoader lastSnapshots;
 
   private FileHashes hashedReference;
   private FileHashes hashedSource;
 
-  public SourceHashHolder(DefaultInputModule module, DefaultInputFile inputFile, ServerLineHashesLoader lastSnapshots) {
+  public SourceHashHolder(AbstractProjectOrModule module, DefaultInputFile inputFile, ServerLineHashesLoader lastSnapshots) {
     this.module = module;
     this.inputFile = inputFile;
     this.lastSnapshots = lastSnapshots;
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/AnalysisObserver.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/AnalysisObserver.java
new file mode 100644 (file)
index 0000000..59ce0f1
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.scanner.mediumtest;
+
+import org.sonar.api.ExtensionPoint;
+import org.sonar.api.batch.ScannerSide;
+import org.sonar.scanner.scan.ProjectScanContainer;
+
+@ScannerSide
+@ExtensionPoint
+@FunctionalInterface
+public interface AnalysisObserver {
+
+  void analysisCompleted(ProjectScanContainer container);
+
+}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/AnalysisObservers.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/AnalysisObservers.java
new file mode 100644 (file)
index 0000000..d6d229a
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.scanner.mediumtest;
+
+import org.sonar.scanner.scan.ProjectScanContainer;
+
+public class AnalysisObservers {
+
+  private AnalysisObserver[] observers;
+  private ProjectScanContainer projectScanContainer;
+
+  public AnalysisObservers(ProjectScanContainer projectScanContainer, AnalysisObserver... observers) {
+    this.projectScanContainer = projectScanContainer;
+    this.observers = observers;
+  }
+
+  public AnalysisObservers(ProjectScanContainer projectScanContainer) {
+    this(projectScanContainer, new AnalysisObserver[0]);
+  }
+
+  public void notifyEndOfScanTask() {
+    for (AnalysisObserver analysisObserver : observers) {
+      analysisObserver.analysisCompleted(projectScanContainer);
+    }
+  }
+
+}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/AnalysisResult.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/AnalysisResult.java
new file mode 100644 (file)
index 0000000..4c2cff6
--- /dev/null
@@ -0,0 +1,327 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.scanner.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 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.api.scanner.fs.InputProject;
+import org.sonar.core.util.CloseableIterator;
+import org.sonar.scanner.issue.IssueCache;
+import org.sonar.scanner.issue.tracking.TrackedIssue;
+import org.sonar.scanner.protocol.output.ScannerReport;
+import org.sonar.scanner.protocol.output.ScannerReport.Component;
+import org.sonar.scanner.protocol.output.ScannerReport.Metadata;
+import org.sonar.scanner.protocol.output.ScannerReport.Symbol;
+import org.sonar.scanner.protocol.output.ScannerReportReader;
+import org.sonar.scanner.report.ReportPublisher;
+import org.sonar.scanner.report.ScannerReportUtils;
+import org.sonar.scanner.scan.ProjectScanContainer;
+import org.sonar.scanner.scan.filesystem.InputComponentStore;
+
+import static org.apache.commons.lang.StringUtils.isNotEmpty;
+
+public class AnalysisResult implements AnalysisObserver {
+
+  private static final Logger LOG = LoggerFactory.getLogger(AnalysisResult.class);
+
+  private List<TrackedIssue> issues = new ArrayList<>();
+  private Map<String, InputFile> inputFiles = new HashMap<>();
+  private Map<String, Component> reportComponents = new HashMap<>();
+  private Map<String, InputDir> inputDirs = new HashMap<>();
+  private InputProject project;
+  private ScannerReportReader reader;
+
+  @Override
+  public void analysisCompleted(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 ScannerReportReader(reportPublisher.getReportDir().toFile());
+    if (!container.getComponentByType(AnalysisMode.class).isIssues()) {
+      Metadata readMetadata = getReportReader().readMetadata();
+      int rootComponentRef = readMetadata.getRootComponentRef();
+      storeReportComponents(rootComponentRef, null);
+      project = container.getComponentByType(InputProject.class);
+    }
+
+    storeFs(container);
+
+  }
+
+  private void storeReportComponents(int componentRef, String parentModuleKey) {
+    Component component = getReportReader().readComponent(componentRef);
+    if (isNotEmpty(component.getKey())) {
+      reportComponents.put(component.getKey(), component);
+    } else {
+      reportComponents.put(parentModuleKey + ":" + component.getPath(), component);
+    }
+    for (int childId : component.getChildRefList()) {
+      storeReportComponents(childId, isNotEmpty(component.getKey()) ? component.getKey() : parentModuleKey);
+    }
+
+  }
+
+  public ScannerReportReader getReportReader() {
+    return reader;
+  }
+
+  private void storeFs(ProjectScanContainer container) {
+    InputComponentStore inputFileCache = container.getComponentByType(InputComponentStore.class);
+    for (InputFile inputPath : inputFileCache.allFiles()) {
+      inputFiles.put(((DefaultInputFile) inputPath).getProjectRelativePath(), inputPath);
+    }
+    for (InputDir inputPath : inputFileCache.allDirs()) {
+      inputDirs.put(inputPath.relativePath(), inputPath);
+    }
+  }
+
+  public List<TrackedIssue> trackedIssues() {
+    return issues;
+  }
+
+  public Component getReportComponent(String key) {
+    return reportComponents.get(key);
+  }
+
+  public List<ScannerReport.Issue> issuesFor(InputComponent inputComponent) {
+    int ref = reportComponents.get(inputComponent.key()).getRef();
+    return issuesFor(ref);
+  }
+  
+  public List<ScannerReport.ExternalIssue> externalIssuesFor(InputComponent inputComponent) {
+    int ref = reportComponents.get(inputComponent.key()).getRef();
+    return externalIssuesFor(ref);
+  }
+
+  public List<ScannerReport.Issue> issuesFor(Component reportComponent) {
+    int ref = reportComponent.getRef();
+    return issuesFor(ref);
+  }
+
+  private List<ScannerReport.Issue> issuesFor(int ref) {
+    List<ScannerReport.Issue> result = Lists.newArrayList();
+    try (CloseableIterator<ScannerReport.Issue> it = reader.readComponentIssues(ref)) {
+      while (it.hasNext()) {
+        result.add(it.next());
+      }
+    }
+    return result;
+  }
+  
+  private List<ScannerReport.ExternalIssue> externalIssuesFor(int ref) {
+    List<ScannerReport.ExternalIssue> result = Lists.newArrayList();
+    try (CloseableIterator<ScannerReport.ExternalIssue> it = reader.readComponentExternalIssues(ref)) {
+      while (it.hasNext()) {
+        result.add(it.next());
+      }
+    }
+    return result;
+  }
+
+  public InputProject project() {
+    return project;
+  }
+
+  public Collection<InputFile> inputFiles() {
+    return inputFiles.values();
+  }
+
+  @CheckForNull
+  public InputFile inputFile(String relativePath) {
+    return inputFiles.get(relativePath);
+  }
+
+  public Collection<InputDir> inputDirs() {
+    return inputDirs.values();
+  }
+
+  @CheckForNull
+  public InputDir inputDir(String relativePath) {
+    return inputDirs.get(relativePath);
+  }
+
+  public Map<String, List<ScannerReport.Measure>> allMeasures() {
+    Map<String, List<ScannerReport.Measure>> result = new HashMap<>();
+    for (Map.Entry<String, Component> component : reportComponents.entrySet()) {
+      List<ScannerReport.Measure> measures = new ArrayList<>();
+      try (CloseableIterator<ScannerReport.Measure> 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<TypeOfText> highlightingTypeFor(InputFile file, int line, int lineOffset) {
+    int ref = reportComponents.get(file.key()).getRef();
+    if (!reader.hasSyntaxHighlighting(ref)) {
+      return Collections.emptyList();
+    }
+    TextPointer pointer = file.newPointer(line, lineOffset);
+    List<TypeOfText> result = new ArrayList<>();
+    try (CloseableIterator<ScannerReport.SyntaxHighlightingRule> it = reader.readComponentSyntaxHighlighting(ref)) {
+      while (it.hasNext()) {
+        ScannerReport.SyntaxHighlightingRule rule = it.next();
+        TextRange ruleRange = toRange(file, rule.getRange());
+        if (ruleRange.start().compareTo(pointer) <= 0 && ruleRange.end().compareTo(pointer) > 0) {
+          result.add(ScannerReportUtils.toBatchType(rule.getType()));
+        }
+      }
+    } catch (Exception e) {
+      throw new IllegalStateException("Can't read syntax highlighting for " + file, e);
+    }
+    return result;
+  }
+
+  private static TextRange toRange(InputFile file, ScannerReport.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<ScannerReport.TextRange> symbolReferencesFor(InputFile file, int symbolStartLine, int symbolStartLineOffset) {
+    int ref = reportComponents.get(file.key()).getRef();
+    try (CloseableIterator<Symbol> 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<ScannerReport.Duplication> duplicationsFor(InputFile file) {
+    List<ScannerReport.Duplication> result = new ArrayList<>();
+    int ref = reportComponents.get(file.key()).getRef();
+    try (CloseableIterator<ScannerReport.Duplication> it = getReportReader().readComponentDuplications(ref)) {
+      while (it.hasNext()) {
+        result.add(it.next());
+      }
+    } catch (Exception e) {
+      throw new IllegalStateException(e);
+    }
+    return result;
+  }
+
+  public List<ScannerReport.CpdTextBlock> duplicationBlocksFor(InputFile file) {
+    List<ScannerReport.CpdTextBlock> result = new ArrayList<>();
+    int ref = reportComponents.get(file.key()).getRef();
+    try (CloseableIterator<ScannerReport.CpdTextBlock> it = getReportReader().readCpdTextBlocks(ref)) {
+      while (it.hasNext()) {
+        result.add(it.next());
+      }
+    } catch (Exception e) {
+      throw new IllegalStateException(e);
+    }
+    return result;
+  }
+
+  @CheckForNull
+  public ScannerReport.LineCoverage coverageFor(InputFile file, int line) {
+    int ref = reportComponents.get(file.key()).getRef();
+    try (CloseableIterator<ScannerReport.LineCoverage> it = getReportReader().readComponentCoverage(ref)) {
+      while (it.hasNext()) {
+        ScannerReport.LineCoverage coverage = it.next();
+        if (coverage.getLine() == line) {
+          return coverage;
+        }
+      }
+    } catch (Exception e) {
+      throw new IllegalStateException(e);
+    }
+    return null;
+  }
+
+  public ScannerReport.Test firstTestExecutionForName(InputFile testFile, String testName) {
+    int ref = reportComponents.get(testFile.key()).getRef();
+    try (InputStream inputStream = FileUtils.openInputStream(getReportReader().readTests(ref))) {
+      ScannerReport.Test test = ScannerReport.Test.parser().parseDelimitedFrom(inputStream);
+      while (test != null) {
+        if (test.getName().equals(testName)) {
+          return test;
+        }
+        test = ScannerReport.Test.parser().parseDelimitedFrom(inputStream);
+      }
+    } catch (Exception e) {
+      throw new IllegalStateException(e);
+    }
+    return null;
+  }
+
+  public ScannerReport.CoverageDetail coveragePerTestFor(InputFile testFile, String testName) {
+    int ref = reportComponents.get(testFile.key()).getRef();
+    try (InputStream inputStream = FileUtils.openInputStream(getReportReader().readCoverageDetails(ref))) {
+      ScannerReport.CoverageDetail details = ScannerReport.CoverageDetail.parser().parseDelimitedFrom(inputStream);
+      while (details != null) {
+        if (details.getTestName().equals(testName)) {
+          return details;
+        }
+        details = ScannerReport.CoverageDetail.parser().parseDelimitedFrom(inputStream);
+      }
+    } catch (Exception e) {
+      throw new IllegalStateException(e);
+    }
+    return null;
+  }
+
+  public List<ScannerReport.AdHocRule> adHocRules() {
+    List<ScannerReport.AdHocRule> result = new ArrayList<>();
+    try (CloseableIterator<ScannerReport.AdHocRule> it = getReportReader().readAdHocRules()) {
+      while (it.hasNext()) {
+        result.add(it.next());
+      }
+    } catch (Exception e) {
+      throw new IllegalStateException(e);
+    }
+    return result;
+  }
+}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/ScanTaskObserver.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/ScanTaskObserver.java
deleted file mode 100644 (file)
index f5f7ba4..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.scanner.mediumtest;
-
-import org.sonar.api.ExtensionPoint;
-import org.sonar.api.batch.ScannerSide;
-import org.sonar.scanner.scan.ProjectScanContainer;
-
-@ScannerSide
-@ExtensionPoint
-@FunctionalInterface
-public interface ScanTaskObserver {
-
-  void scanTaskCompleted(ProjectScanContainer container);
-
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/ScanTaskObservers.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/ScanTaskObservers.java
deleted file mode 100644 (file)
index a950300..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.scanner.mediumtest;
-
-import org.sonar.scanner.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-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/TaskResult.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/TaskResult.java
deleted file mode 100644 (file)
index d2ea968..0000000
+++ /dev/null
@@ -1,328 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.scanner.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 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.InputModule;
-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.core.util.CloseableIterator;
-import org.sonar.scanner.issue.IssueCache;
-import org.sonar.scanner.issue.tracking.TrackedIssue;
-import org.sonar.scanner.protocol.output.ScannerReport;
-import org.sonar.scanner.protocol.output.ScannerReport.Component;
-import org.sonar.scanner.protocol.output.ScannerReport.Metadata;
-import org.sonar.scanner.protocol.output.ScannerReport.Symbol;
-import org.sonar.scanner.protocol.output.ScannerReportReader;
-import org.sonar.scanner.report.ReportPublisher;
-import org.sonar.scanner.report.ScannerReportUtils;
-import org.sonar.scanner.scan.ProjectScanContainer;
-import org.sonar.scanner.scan.filesystem.InputComponentStore;
-
-import static org.apache.commons.lang.StringUtils.isNotEmpty;
-
-public class TaskResult implements org.sonar.scanner.mediumtest.ScanTaskObserver {
-
-  private static final Logger LOG = LoggerFactory.getLogger(TaskResult.class);
-
-  private List<TrackedIssue> issues = new ArrayList<>();
-  private Map<String, InputFile> inputFiles = new HashMap<>();
-  private Map<String, Component> reportComponents = new HashMap<>();
-  private Map<String, InputDir> inputDirs = new HashMap<>();
-  private InputModule root;
-  private ScannerReportReader 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 ScannerReportReader(reportPublisher.getReportDir().toFile());
-    if (!container.getComponentByType(AnalysisMode.class).isIssues()) {
-      Metadata readMetadata = getReportReader().readMetadata();
-      int rootComponentRef = readMetadata.getRootComponentRef();
-      storeReportComponents(rootComponentRef, null);
-      InputComponentStore inputFileCache = container.getComponentByType(InputComponentStore.class);
-      root = inputFileCache.root();
-    }
-
-    storeFs(container);
-
-  }
-
-  private void storeReportComponents(int componentRef, String parentModuleKey) {
-    Component component = getReportReader().readComponent(componentRef);
-    if (isNotEmpty(component.getKey())) {
-      reportComponents.put(component.getKey(), component);
-    } else {
-      reportComponents.put(parentModuleKey + ":" + component.getPath(), component);
-    }
-    for (int childId : component.getChildRefList()) {
-      storeReportComponents(childId, isNotEmpty(component.getKey()) ? component.getKey() : parentModuleKey);
-    }
-
-  }
-
-  public ScannerReportReader getReportReader() {
-    return reader;
-  }
-
-  private void storeFs(ProjectScanContainer container) {
-    InputComponentStore inputFileCache = container.getComponentByType(InputComponentStore.class);
-    for (InputFile inputPath : inputFileCache.allFiles()) {
-      inputFiles.put(((DefaultInputFile) inputPath).getProjectRelativePath(), inputPath);
-    }
-    for (InputDir inputPath : inputFileCache.allDirs()) {
-      inputDirs.put(inputPath.relativePath(), inputPath);
-    }
-  }
-
-  public List<TrackedIssue> trackedIssues() {
-    return issues;
-  }
-
-  public Component getReportComponent(String key) {
-    return reportComponents.get(key);
-  }
-
-  public List<ScannerReport.Issue> issuesFor(InputComponent inputComponent) {
-    int ref = reportComponents.get(inputComponent.key()).getRef();
-    return issuesFor(ref);
-  }
-  
-  public List<ScannerReport.ExternalIssue> externalIssuesFor(InputComponent inputComponent) {
-    int ref = reportComponents.get(inputComponent.key()).getRef();
-    return externalIssuesFor(ref);
-  }
-
-  public List<ScannerReport.Issue> issuesFor(Component reportComponent) {
-    int ref = reportComponent.getRef();
-    return issuesFor(ref);
-  }
-
-  private List<ScannerReport.Issue> issuesFor(int ref) {
-    List<ScannerReport.Issue> result = Lists.newArrayList();
-    try (CloseableIterator<ScannerReport.Issue> it = reader.readComponentIssues(ref)) {
-      while (it.hasNext()) {
-        result.add(it.next());
-      }
-    }
-    return result;
-  }
-  
-  private List<ScannerReport.ExternalIssue> externalIssuesFor(int ref) {
-    List<ScannerReport.ExternalIssue> result = Lists.newArrayList();
-    try (CloseableIterator<ScannerReport.ExternalIssue> it = reader.readComponentExternalIssues(ref)) {
-      while (it.hasNext()) {
-        result.add(it.next());
-      }
-    }
-    return result;
-  }
-
-  public InputModule root() {
-    return root;
-  }
-
-  public Collection<InputFile> inputFiles() {
-    return inputFiles.values();
-  }
-
-  @CheckForNull
-  public InputFile inputFile(String relativePath) {
-    return inputFiles.get(relativePath);
-  }
-
-  public Collection<InputDir> inputDirs() {
-    return inputDirs.values();
-  }
-
-  @CheckForNull
-  public InputDir inputDir(String relativePath) {
-    return inputDirs.get(relativePath);
-  }
-
-  public Map<String, List<ScannerReport.Measure>> allMeasures() {
-    Map<String, List<ScannerReport.Measure>> result = new HashMap<>();
-    for (Map.Entry<String, Component> component : reportComponents.entrySet()) {
-      List<ScannerReport.Measure> measures = new ArrayList<>();
-      try (CloseableIterator<ScannerReport.Measure> 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<TypeOfText> highlightingTypeFor(InputFile file, int line, int lineOffset) {
-    int ref = reportComponents.get(file.key()).getRef();
-    if (!reader.hasSyntaxHighlighting(ref)) {
-      return Collections.emptyList();
-    }
-    TextPointer pointer = file.newPointer(line, lineOffset);
-    List<TypeOfText> result = new ArrayList<>();
-    try (CloseableIterator<ScannerReport.SyntaxHighlightingRule> it = reader.readComponentSyntaxHighlighting(ref)) {
-      while (it.hasNext()) {
-        ScannerReport.SyntaxHighlightingRule rule = it.next();
-        TextRange ruleRange = toRange(file, rule.getRange());
-        if (ruleRange.start().compareTo(pointer) <= 0 && ruleRange.end().compareTo(pointer) > 0) {
-          result.add(ScannerReportUtils.toBatchType(rule.getType()));
-        }
-      }
-    } catch (Exception e) {
-      throw new IllegalStateException("Can't read syntax highlighting for " + file, e);
-    }
-    return result;
-  }
-
-  private static TextRange toRange(InputFile file, ScannerReport.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<ScannerReport.TextRange> symbolReferencesFor(InputFile file, int symbolStartLine, int symbolStartLineOffset) {
-    int ref = reportComponents.get(file.key()).getRef();
-    try (CloseableIterator<Symbol> 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<ScannerReport.Duplication> duplicationsFor(InputFile file) {
-    List<ScannerReport.Duplication> result = new ArrayList<>();
-    int ref = reportComponents.get(file.key()).getRef();
-    try (CloseableIterator<ScannerReport.Duplication> it = getReportReader().readComponentDuplications(ref)) {
-      while (it.hasNext()) {
-        result.add(it.next());
-      }
-    } catch (Exception e) {
-      throw new IllegalStateException(e);
-    }
-    return result;
-  }
-
-  public List<ScannerReport.CpdTextBlock> duplicationBlocksFor(InputFile file) {
-    List<ScannerReport.CpdTextBlock> result = new ArrayList<>();
-    int ref = reportComponents.get(file.key()).getRef();
-    try (CloseableIterator<ScannerReport.CpdTextBlock> it = getReportReader().readCpdTextBlocks(ref)) {
-      while (it.hasNext()) {
-        result.add(it.next());
-      }
-    } catch (Exception e) {
-      throw new IllegalStateException(e);
-    }
-    return result;
-  }
-
-  @CheckForNull
-  public ScannerReport.LineCoverage coverageFor(InputFile file, int line) {
-    int ref = reportComponents.get(file.key()).getRef();
-    try (CloseableIterator<ScannerReport.LineCoverage> it = getReportReader().readComponentCoverage(ref)) {
-      while (it.hasNext()) {
-        ScannerReport.LineCoverage coverage = it.next();
-        if (coverage.getLine() == line) {
-          return coverage;
-        }
-      }
-    } catch (Exception e) {
-      throw new IllegalStateException(e);
-    }
-    return null;
-  }
-
-  public ScannerReport.Test firstTestExecutionForName(InputFile testFile, String testName) {
-    int ref = reportComponents.get(testFile.key()).getRef();
-    try (InputStream inputStream = FileUtils.openInputStream(getReportReader().readTests(ref))) {
-      ScannerReport.Test test = ScannerReport.Test.parser().parseDelimitedFrom(inputStream);
-      while (test != null) {
-        if (test.getName().equals(testName)) {
-          return test;
-        }
-        test = ScannerReport.Test.parser().parseDelimitedFrom(inputStream);
-      }
-    } catch (Exception e) {
-      throw new IllegalStateException(e);
-    }
-    return null;
-  }
-
-  public ScannerReport.CoverageDetail coveragePerTestFor(InputFile testFile, String testName) {
-    int ref = reportComponents.get(testFile.key()).getRef();
-    try (InputStream inputStream = FileUtils.openInputStream(getReportReader().readCoverageDetails(ref))) {
-      ScannerReport.CoverageDetail details = ScannerReport.CoverageDetail.parser().parseDelimitedFrom(inputStream);
-      while (details != null) {
-        if (details.getTestName().equals(testName)) {
-          return details;
-        }
-        details = ScannerReport.CoverageDetail.parser().parseDelimitedFrom(inputStream);
-      }
-    } catch (Exception e) {
-      throw new IllegalStateException(e);
-    }
-    return null;
-  }
-
-  public List<ScannerReport.AdHocRule> adHocRules() {
-    List<ScannerReport.AdHocRule> result = new ArrayList<>();
-    try (CloseableIterator<ScannerReport.AdHocRule> it = getReportReader().readAdHocRules()) {
-      while (it.hasNext()) {
-        result.add(it.next());
-      }
-    } catch (Exception e) {
-      throw new IllegalStateException(e);
-    }
-    return result;
-  }
-}
index 9bcf8b3f4100fe65190978af588fe68d293459e1..7e3b1c3841440484c0f8bacaaf9b6284da419635 100644 (file)
@@ -23,6 +23,7 @@ import java.util.Arrays;
 import org.sonar.api.CoreProperties;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
+import org.sonar.api.batch.fs.internal.AbstractProjectOrModule;
 import org.sonar.api.batch.fs.internal.DefaultInputModule;
 import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
 import org.sonar.api.notifications.AnalysisWarnings;
@@ -91,7 +92,7 @@ public abstract class AbstractModulePhaseExecutor {
     }
   }
 
-  private void evaluateCoverageExclusions(DefaultInputModule module) {
+  private void evaluateCoverageExclusions(AbstractProjectOrModule module) {
     if (!Arrays.equals(moduleCoverageExclusions.getCoverageExclusionConfig(), projectCoverageExclusions.getCoverageExclusionConfig())) {
       moduleCoverageExclusions.log();
     }
index 124d93531cdded1ea4ddbc4485d9275f77484270..dd00766cfe79545f356f89f93a8eec49d8e0346a 100644 (file)
@@ -21,12 +21,12 @@ package org.sonar.scanner.phases;
 
 import javax.annotation.concurrent.Immutable;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.config.Configuration;
+import org.sonar.scanner.scan.ModuleConfiguration;
 
 @Immutable
 public class ModuleCoverageExclusions extends AbstractCoverageExclusions {
 
-  public ModuleCoverageExclusions(Configuration config) {
+  public ModuleCoverageExclusions(ModuleConfiguration config) {
     super(config, DefaultInputFile::getModuleRelativePath);
   }
 }
index e4139a214fbd096382c8507886ff45b5b7e3b347..c3167b2adcdc5e7375d7c52afb341b921b6a3d1f 100644 (file)
@@ -21,12 +21,12 @@ package org.sonar.scanner.phases;
 
 import javax.annotation.concurrent.Immutable;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.config.Configuration;
+import org.sonar.scanner.scan.ProjectConfiguration;
 
 @Immutable
 public class ProjectCoverageExclusions extends AbstractCoverageExclusions {
 
-  public ProjectCoverageExclusions(Configuration projectConfig) {
+  public ProjectCoverageExclusions(ProjectConfiguration projectConfig) {
     super(projectConfig, DefaultInputFile::getProjectRelativePath);
     log();
   }
index bccbd7a4bcfb51187e543f5d74a042ce0181e9de..94515124d0c46de6fe4922c377832458f50cc6a9 100644 (file)
@@ -44,7 +44,7 @@ public class SensorsExecutor {
   private final boolean isRoot;
 
   public SensorsExecutor(ScannerExtensionDictionnary selector, DefaultInputModule module, InputModuleHierarchy hierarchy,
-    SensorStrategy strategy, ScannerPluginRepository pluginRepo) {
+                         SensorStrategy strategy, ScannerPluginRepository pluginRepo) {
     this.selector = selector;
     this.strategy = strategy;
     this.pluginRepo = pluginRepo;
index dab13b89b71776f3fb09c5b5d2536d3a84ea2e64..8b53ab5e86d3fd072b0cf279e0695679ba692ab1 100644 (file)
@@ -25,7 +25,7 @@ import org.apache.commons.lang.StringUtils;
 import org.sonar.api.CoreProperties;
 import org.sonar.api.SonarRuntime;
 import org.sonar.api.batch.ScannerSide;
-import org.sonar.api.config.Settings;
+import org.sonar.api.config.Configuration;
 import org.sonar.api.platform.Server;
 import org.sonar.api.utils.DateUtils;
 import org.sonar.scanner.bootstrap.ScannerWsClient;
@@ -35,11 +35,11 @@ import static org.apache.commons.lang.StringUtils.trimToEmpty;
 @ScannerSide
 public class DefaultServer extends Server {
 
-  private final Settings settings;
+  private final Configuration settings;
   private final ScannerWsClient client;
   private final SonarRuntime runtime;
 
-  public DefaultServer(Settings settings, ScannerWsClient client, SonarRuntime runtime) {
+  public DefaultServer(Configuration settings, ScannerWsClient client, SonarRuntime runtime) {
     this.settings = settings;
     this.client = client;
     this.runtime = runtime;
@@ -47,7 +47,7 @@ public class DefaultServer extends Server {
 
   @Override
   public String getId() {
-    return settings.getString(CoreProperties.SERVER_ID);
+    return settings.get(CoreProperties.SERVER_ID).orElseThrow(() -> new IllegalStateException("Mandatory"));
   }
 
   @Override
@@ -57,7 +57,7 @@ public class DefaultServer extends Server {
 
   @Override
   public Date getStartedAt() {
-    String dateString = settings.getString(CoreProperties.SERVER_STARTTIME);
+    String dateString = settings.get(CoreProperties.SERVER_STARTTIME).orElseThrow(() -> new IllegalStateException("Mandatory"));
     return DateUtils.parseDateTime(dateString);
   }
 
@@ -73,7 +73,7 @@ public class DefaultServer extends Server {
 
   @Override
   public String getPublicRootUrl() {
-    String baseUrl = trimToEmpty(settings.getString(CoreProperties.SERVER_BASE_URL));
+    String baseUrl = trimToEmpty(settings.get(CoreProperties.SERVER_BASE_URL).orElse(""));
     if (baseUrl.isEmpty()) {
       // If server base URL was not configured in Sonar server then is is better to take URL configured on batch side
       baseUrl = client.baseUrl();
index 8badd6715df20b89a8c83a78d2a0ed9d2344dd43..22977f997a591e2584633599eb447edc13206010 100644 (file)
@@ -33,13 +33,14 @@ import org.apache.commons.lang.StringUtils;
 import org.sonar.api.CoreProperties;
 import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.batch.ScannerSide;
+import org.sonar.api.batch.fs.internal.AbstractProjectOrModule;
 import org.sonar.api.batch.fs.internal.DefaultInputModule;
 import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
 import org.sonar.api.utils.System2;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.core.platform.PluginInfo;
-import org.sonar.scanner.bootstrap.GlobalConfiguration;
+import org.sonar.scanner.bootstrap.GlobalServerSettings;
 import org.sonar.scanner.bootstrap.ScannerPluginRepository;
 import org.sonar.scanner.protocol.output.ScannerReportWriter;
 import org.sonar.scanner.repository.ProjectRepositories;
@@ -58,18 +59,18 @@ public class AnalysisContextReportPublisher {
   private final AnalysisMode mode;
   private final System2 system;
   private final ProjectRepositories projectRepos;
-  private final GlobalConfiguration globalSettings;
+  private final GlobalServerSettings globalServerSettings;
   private final InputModuleHierarchy hierarchy;
 
   private ScannerReportWriter writer;
 
   public AnalysisContextReportPublisher(AnalysisMode mode, ScannerPluginRepository pluginRepo, System2 system,
-    ProjectRepositories projectRepos, GlobalConfiguration globalSettings, InputModuleHierarchy hierarchy) {
+    ProjectRepositories projectRepos, GlobalServerSettings globalServerSettings, InputModuleHierarchy hierarchy) {
     this.mode = mode;
     this.pluginRepo = pluginRepo;
     this.system = system;
     this.projectRepos = projectRepos;
-    this.globalSettings = globalSettings;
+    this.globalServerSettings = globalServerSettings;
     this.hierarchy = hierarchy;
   }
 
@@ -125,7 +126,7 @@ public class AnalysisContextReportPublisher {
 
   private void writeGlobalSettings(BufferedWriter fileWriter) throws IOException {
     fileWriter.append("Global properties:\n");
-    Map<String, String> props = globalSettings.getServerSideSettings();
+    Map<String, String> props = globalServerSettings.properties();
     for (String prop : new TreeSet<>(props.keySet())) {
       dumpPropIfNotSensitive(fileWriter, prop, props.get(prop));
     }
@@ -163,7 +164,7 @@ public class AnalysisContextReportPublisher {
     if (projectRepos.moduleExists(module.getKeyWithBranch())) {
       moduleSpecificProps.putAll(projectRepos.settings(module.getKeyWithBranch()));
     }
-    DefaultInputModule parent = hierarchy.parent(module);
+    AbstractProjectOrModule parent = hierarchy.parent(module);
     if (parent == null) {
       moduleSpecificProps.putAll(module.properties());
     } else {
index 4b9d463a164b52ab4bbaa360071247ed0670892c..8bc978109b67b63d7260e599a31a4345df372b73 100644 (file)
@@ -26,7 +26,7 @@ import java.util.Set;
 import java.util.stream.Collectors;
 import java.util.stream.StreamSupport;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.batch.scm.ScmProvider;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
@@ -43,19 +43,20 @@ public class ChangedLinesPublisher implements ReportPublisherStep {
   private static final String LOG_MSG = "SCM writing changed lines";
 
   private final ScmConfiguration scmConfiguration;
-  private final InputModuleHierarchy inputModuleHierarchy;
+  private final DefaultInputProject project;
   private final InputComponentStore inputComponentStore;
   private final BranchConfiguration branchConfiguration;
 
-  public ChangedLinesPublisher(ScmConfiguration scmConfiguration, InputModuleHierarchy inputModuleHierarchy, InputComponentStore inputComponentStore,
+  public ChangedLinesPublisher(ScmConfiguration scmConfiguration, DefaultInputProject project, InputComponentStore inputComponentStore,
     BranchConfiguration branchConfiguration) {
     this.scmConfiguration = scmConfiguration;
-    this.inputModuleHierarchy = inputModuleHierarchy;
+    this.project = project;
     this.inputComponentStore = inputComponentStore;
     this.branchConfiguration = branchConfiguration;
   }
 
-  @Override public void publish(ScannerReportWriter writer) {
+  @Override
+  public void publish(ScannerReportWriter writer) {
     String targetScmBranch = branchConfiguration.targetScmBranch();
     if (scmConfiguration.isDisabled() || !branchConfiguration.isShortOrPullRequest() || targetScmBranch == null) {
       return;
@@ -73,7 +74,7 @@ public class ChangedLinesPublisher implements ReportPublisherStep {
   }
 
   private int writeChangedLines(ScmProvider provider, ScannerReportWriter writer, String targetScmBranch) {
-    Path rootBaseDir = inputModuleHierarchy.root().getBaseDir();
+    Path rootBaseDir = project.getBaseDir();
     Map<Path, DefaultInputFile> changedFiles = StreamSupport.stream(inputComponentStore.allChangedFilesToPublish().spliterator(), false)
       .collect(Collectors.toMap(DefaultInputFile::path, f -> f));
 
@@ -93,7 +94,7 @@ public class ChangedLinesPublisher implements ReportPublisherStep {
         LOG.warn("File '{}' was detected as changed but without having changed lines", e.getKey().toAbsolutePath());
       }
       count++;
-      writeChangedLines(writer, e.getValue().batchId(), changedLines);
+      writeChangedLines(writer, e.getValue().scannerId(), changedLines);
     }
     return count;
   }
index af4939885abe2ed24facf56add7236f5dac23c84..7902bcde70681621c0ef66146809ddd8bf725d87 100644 (file)
@@ -33,6 +33,7 @@ import org.sonar.api.batch.fs.InputFile.Status;
 import org.sonar.api.batch.fs.InputModule;
 import org.sonar.api.batch.fs.internal.DefaultInputComponent;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
+import org.sonar.api.batch.fs.internal.AbstractProjectOrModule;
 import org.sonar.api.batch.fs.internal.DefaultInputModule;
 import org.sonar.api.batch.fs.internal.InputComponentTree;
 import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
@@ -90,7 +91,7 @@ public class ComponentsPublisher implements ReportPublisherStep {
     ScannerReport.Component.Builder builder = ScannerReport.Component.newBuilder();
 
     // non-null fields
-    builder.setRef(component.batchId());
+    builder.setRef(component.scannerId());
     builder.setType(getType(component));
 
     // Don't set key on directories and files to save space since it can be deduced from path
@@ -133,7 +134,7 @@ public class ComponentsPublisher implements ReportPublisherStep {
     }
 
     for (InputComponent child : children) {
-      builder.addChildRef(((DefaultInputComponent) child).batchId());
+      builder.addChildRef(((DefaultInputComponent) child).scannerId());
     }
     writeLinks(component, builder);
     writer.writeComponent(builder.build());
@@ -156,9 +157,9 @@ public class ComponentsPublisher implements ReportPublisherStep {
   private boolean shouldSkipComponent(DefaultInputComponent component, Collection<InputComponent> children) {
     if (component instanceof InputModule && children.isEmpty() && (branchConfiguration.isShortOrPullRequest())) {
       // no children on a module in short branch analysis -> skip it (except root)
-      return !moduleHierarchy.isRoot((InputModule) component);
+      return !moduleHierarchy.isRoot((DefaultInputModule) component);
     } else if (component instanceof InputDir && children.isEmpty()) {
-      try (CloseableIterator<Issue> componentIssuesIt = reader.readComponentIssues(component.batchId())) {
+      try (CloseableIterator<Issue> componentIssuesIt = reader.readComponentIssues(component.scannerId())) {
         if (!componentIssuesIt.hasNext()) {
           // no files to publish on a directory without issues -> skip it
           return true;
@@ -192,7 +193,7 @@ public class ComponentsPublisher implements ReportPublisherStep {
         return inputPath.relativePath();
       }
     } else if (component instanceof InputModule) {
-      InputModule module = (InputModule) component;
+      DefaultInputModule module = (DefaultInputModule) component;
       return moduleHierarchy.relativePath(module);
     }
     throw new IllegalStateException("Unknown component: " + component.getClass());
@@ -211,7 +212,7 @@ public class ComponentsPublisher implements ReportPublisherStep {
       return PathUtils.sanitize(projectBaseDir.relativize(inputDir.path()).toString());
     }
     if (component instanceof InputModule) {
-      DefaultInputModule module = (DefaultInputModule) component;
+      AbstractProjectOrModule module = (AbstractProjectOrModule) component;
       return PathUtils.sanitize(projectBaseDir.relativize(module.getBaseDir()).toString());
     }
     throw new IllegalStateException("Unknown component: " + component.getClass());
@@ -230,7 +231,7 @@ public class ComponentsPublisher implements ReportPublisherStep {
 
   private static void writeLinks(InputComponent c, ScannerReport.Component.Builder builder) {
     if (c instanceof InputModule) {
-      DefaultInputModule inputModule = (DefaultInputModule) c;
+      AbstractProjectOrModule inputModule = (AbstractProjectOrModule) c;
       ProjectDefinition def = inputModule.definition();
       ComponentLink.Builder linkBuilder = ComponentLink.newBuilder();
 
@@ -258,7 +259,7 @@ public class ComponentsPublisher implements ReportPublisherStep {
   }
 
   @CheckForNull
-  private static String getName(DefaultInputModule module) {
+  private static String getName(AbstractProjectOrModule module) {
     if (StringUtils.isNotEmpty(module.definition().getBranch())) {
       return module.definition().getName() + " " + module.definition().getBranch();
     } else {
@@ -267,7 +268,7 @@ public class ComponentsPublisher implements ReportPublisherStep {
   }
 
   @CheckForNull
-  private static String getDescription(DefaultInputModule module) {
+  private static String getDescription(AbstractProjectOrModule module) {
     return module.definition().getDescription();
   }
 
@@ -276,7 +277,7 @@ public class ComponentsPublisher implements ReportPublisherStep {
       return ComponentType.FILE;
     } else if (r instanceof InputDir) {
       return ComponentType.DIRECTORY;
-    } else if ((r instanceof InputModule) && moduleHierarchy.isRoot((InputModule) r)) {
+    } else if ((r instanceof InputModule) && moduleHierarchy.isRoot((DefaultInputModule) r)) {
       return ComponentType.PROJECT;
     } else if (r instanceof InputModule) {
       return ComponentType.MODULE;
index 276a29c312072ff1012f706474ebd22b14b8b2cc..d2bb71b1cd36b1223b03f90ccb5dad2406b8e681 100644 (file)
@@ -58,7 +58,7 @@ public class CoveragePublisher implements ReportPublisherStep {
       applyLineMeasure(inputFile.key(), lineCount, CoreMetrics.COVERED_CONDITIONS_BY_LINE_KEY, coveragePerLine,
         (value, builder) -> builder.setCoveredConditions(Integer.parseInt(value)));
 
-      writer.writeComponentCoverage(inputFile.batchId(), coveragePerLine.values().stream().map(BuildCoverage.INSTANCE).collect(Collectors.toList()));
+      writer.writeComponentCoverage(inputFile.scannerId(), coveragePerLine.values().stream().map(BuildCoverage.INSTANCE).collect(Collectors.toList()));
     }
   }
 
index 089aafae320533e43c1a9c4a7af037aea338f090..75692161a69d4402f251de8d7b7d397ed0891457 100644 (file)
@@ -94,7 +94,7 @@ public class MeasuresPublisher implements ReportPublisherStep {
 
       Iterable<DefaultMeasure<?>> scannerMeasures = measureCache.byComponentKey(component.key());
       if (scannerMeasures.iterator().hasNext()) {
-        writer.writeComponentMeasures(component.batchId(), StreamSupport.stream(scannerMeasures.spliterator(), false)
+        writer.writeComponentMeasures(component.scannerId(), StreamSupport.stream(scannerMeasures.spliterator(), false)
           .map(input -> {
             if (input.value() == null) {
               throw new IllegalArgumentException(
index 73eced44cda6442929ce6c82564160aeff5106b1..26ca46ace2c2170f72eed6be67cd38151f0e6261 100644 (file)
@@ -25,7 +25,7 @@ import java.util.Map.Entry;
 import java.util.Optional;
 import java.util.regex.Pattern;
 import javax.annotation.Nullable;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.AbstractProjectOrModule;
 import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
 import org.sonar.api.batch.scm.ScmProvider;
 import org.sonar.api.utils.log.Logger;
@@ -37,8 +37,8 @@ import org.sonar.scanner.cpd.CpdSettings;
 import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.scanner.protocol.output.ScannerReport.Metadata.BranchType;
 import org.sonar.scanner.protocol.output.ScannerReportWriter;
-import org.sonar.scanner.rule.QualityProfiles;
 import org.sonar.scanner.rule.QProfile;
+import org.sonar.scanner.rule.QualityProfiles;
 import org.sonar.scanner.scan.ScanProperties;
 import org.sonar.scanner.scan.branch.BranchConfiguration;
 import org.sonar.scanner.scm.ScmConfiguration;
@@ -78,13 +78,13 @@ public class MetadataPublisher implements ReportPublisherStep {
 
   @Override
   public void publish(ScannerReportWriter writer) {
-    DefaultInputModule rootProject = moduleHierarchy.root();
+    AbstractProjectOrModule rootProject = moduleHierarchy.root();
     ScannerReport.Metadata.Builder builder = ScannerReport.Metadata.newBuilder()
       .setAnalysisDate(projectAnalysisInfo.analysisDate().getTime())
       // Here we want key without branch
       .setProjectKey(rootProject.key())
       .setCrossProjectDuplicationActivated(cpdSettings.isCrossProjectDuplicationEnabled())
-      .setRootComponentRef(rootProject.batchId());
+      .setRootComponentRef(rootProject.scannerId());
 
     properties.organizationKey().ifPresent(builder::setOrganizationKey);
 
index 604ef99600d64cd29d3bed7a8e7ddc7c2f811b4f..3ab19165dcc5502a993df4ac2f13b578b485554d 100644 (file)
@@ -45,7 +45,7 @@ public class SourcePublisher implements ReportPublisherStep {
   @Override
   public void publish(ScannerReportWriter writer) {
     for (final DefaultInputFile inputFile : componentCache.allChangedFilesToPublish()) {
-      File iofile = writer.getSourceFile(inputFile.batchId());
+      File iofile = writer.getSourceFile(inputFile.scannerId());
 
       try (OutputStream output = new BufferedOutputStream(new FileOutputStream(iofile));
         InputStream in = inputFile.inputStream();
index a08245415d27d7d8a8e0a5eb12408918f1123761..1b15ec25e5665e9e148ea1ee43aaa4de8957ffc5 100644 (file)
@@ -70,12 +70,12 @@ public class TestExecutionAndCoveragePublisher implements ReportPublisherStep {
 
       final Set<String> testNamesWithCoverage = new HashSet<>();
 
-      writer.writeTests(component.batchId(),
+      writer.writeTests(component.scannerId(),
         StreamSupport.stream(testPlan.testCases().spliterator(), false)
           .map(testCase -> toProtobufTest(testBuilder, testNamesWithCoverage, testCase))
           .collect(toList()));
 
-      writer.writeCoverageDetails(component.batchId(), testNamesWithCoverage.stream()
+      writer.writeCoverageDetails(component.scannerId(), testNamesWithCoverage.stream()
         .map(testName -> toProtobufCoverageDetails(builder, coveredBuilder, testPlan, testName))
         .collect(toList()));
     }
@@ -90,7 +90,7 @@ public class TestExecutionAndCoveragePublisher implements ReportPublisherStep {
     for (CoverageBlock block : testCase.coverageBlocks()) {
       coveredBuilder.clear();
       DefaultInputComponent c = (DefaultInputComponent) componentStore.getByKey(((DefaultTestable) block.testable()).inputFile().key());
-      coveredBuilder.setFileRef(c.batchId());
+      coveredBuilder.setFileRef(c.scannerId());
       for (int line : block.lines()) {
         coveredBuilder.addCoveredLine(line);
       }
index eb48e0195448010c76c2c9ed7a9b844563974d5c..30eabd15947cbb5f7f965aef20ac96781de19a68 100644 (file)
 package org.sonar.scanner.repository;
 
 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.scanner.bootstrap.GlobalAnalysisMode;
+import org.sonar.scanner.bootstrap.ScannerProperties;
 import org.sonar.scanner.scan.branch.BranchConfiguration;
 
 public class ProjectRepositoriesProvider extends ProviderAdapter {
@@ -32,11 +32,11 @@ public class ProjectRepositoriesProvider extends ProviderAdapter {
   private static final String LOG_MSG = "Load project repositories";
   private ProjectRepositories project = null;
 
-  public ProjectRepositories provide(ProjectRepositoriesLoader loader, ProjectKey projectKey, GlobalAnalysisMode mode, BranchConfiguration branchConfig) {
+  public ProjectRepositories provide(ProjectRepositoriesLoader loader, ScannerProperties scannerProperties, GlobalAnalysisMode mode, BranchConfiguration branchConfig) {
     if (project == null) {
       boolean isIssuesMode = mode.isIssues();
       Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG);
-      project = loader.load(projectKey.get(), isIssuesMode, branchConfig.longLivingSonarReferenceBranch());
+      project = loader.load(scannerProperties.getKeyWithBranch(), isIssuesMode, branchConfig.longLivingSonarReferenceBranch());
       checkProject(isIssuesMode);
       profiler.stopInfo();
     }
index 24286de6ec1f6e6c64919fca72e23c7df4ad4d08..60b52f440eea0ce976068e226a2d436776d4431d 100644 (file)
@@ -22,11 +22,10 @@ package org.sonar.scanner.repository;
 import java.util.List;
 import javax.annotation.CheckForNull;
 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.scanner.analysis.AnalysisProperties;
+import org.sonar.scanner.bootstrap.ScannerProperties;
 import org.sonar.scanner.rule.QualityProfiles;
 import org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile;
 
@@ -35,14 +34,14 @@ public class QualityProfilesProvider extends ProviderAdapter {
   private static final String LOG_MSG = "Load quality profiles";
   private QualityProfiles profiles = null;
 
-  public QualityProfiles provide(ProjectKey projectKey, QualityProfileLoader loader, ProjectRepositories projectRepositories, AnalysisProperties props) {
+  public QualityProfiles provide(QualityProfileLoader loader, ProjectRepositories projectRepositories, ScannerProperties props) {
     if (this.profiles == null) {
       List<QualityProfile> profileList;
       Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG);
       if (!projectRepositories.exists()) {
         profileList = loader.loadDefault(getSonarProfile(props));
       } else {
-        profileList = loader.load(projectKey.get(), getSonarProfile(props));
+        profileList = loader.load(props.getKeyWithBranch(), getSonarProfile(props));
       }
       profiler.stopInfo();
       profiles = new QualityProfiles(profileList);
@@ -52,7 +51,7 @@ public class QualityProfilesProvider extends ProviderAdapter {
   }
 
   @CheckForNull
-  private static String getSonarProfile(AnalysisProperties props) {
+  private static String getSonarProfile(ScannerProperties props) {
     String profile = props.property(QualityProfiles.SONAR_PROFILE_PROP);
     if (profile != null) {
       LOG.warn("Ability to set quality profile from command line using '" + QualityProfiles.SONAR_PROFILE_PROP
index 6ff02b3f71ec42f3ed58d630df065bb2a878addc..8c37407023a4abfd2c3c1d6f640597c5fc5c66ed 100644 (file)
@@ -27,7 +27,7 @@ import java.util.HashMap;
 import java.util.Map;
 import javax.annotation.CheckForNull;
 import javax.annotation.concurrent.Immutable;
-import org.sonar.api.batch.fs.InputModule;
+import org.sonar.api.batch.fs.internal.AbstractProjectOrModule;
 import org.sonar.api.batch.fs.internal.DefaultInputModule;
 import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
 import org.sonar.api.scan.filesystem.PathResolver;
@@ -38,10 +38,6 @@ public class DefaultInputModuleHierarchy implements InputModuleHierarchy {
   private final Map<DefaultInputModule, DefaultInputModule> parents;
   private final ImmutableMultimap<DefaultInputModule, DefaultInputModule> children;
 
-  public DefaultInputModuleHierarchy(DefaultInputModule parent, DefaultInputModule child) {
-    this(Collections.singletonMap(child, parent));
-  }
-
   public DefaultInputModuleHierarchy(DefaultInputModule root) {
     this.children = new ImmutableMultimap.Builder<DefaultInputModule, DefaultInputModule>().build();
     this.parents = Collections.emptyMap();
@@ -51,7 +47,7 @@ public class DefaultInputModuleHierarchy implements InputModuleHierarchy {
   /**
    * Map of child->parent. Neither the Keys or values can be null.
    */
-  public DefaultInputModuleHierarchy(Map<DefaultInputModule, DefaultInputModule> parents) {
+  public DefaultInputModuleHierarchy(DefaultInputModule root, Map<DefaultInputModule, DefaultInputModule> parents) {
     ImmutableMultimap.Builder<DefaultInputModule, DefaultInputModule> childrenBuilder = new ImmutableMultimap.Builder<>();
 
     for (Map.Entry<DefaultInputModule, DefaultInputModule> e : parents.entrySet()) {
@@ -60,23 +56,7 @@ public class DefaultInputModuleHierarchy implements InputModuleHierarchy {
 
     this.children = childrenBuilder.build();
     this.parents = Collections.unmodifiableMap(new HashMap<>(parents));
-    this.root = findRoot(parents);
-  }
-
-  private static DefaultInputModule findRoot(Map<DefaultInputModule, DefaultInputModule> parents) {
-    DefaultInputModule r = null;
-    for (DefaultInputModule parent : parents.values()) {
-      if (!parents.containsKey(parent)) {
-        if (r != null && r != parent) {
-          throw new IllegalStateException(String.format("Found two modules without parent: '%s' and '%s'", r.key(), parent.key()));
-        }
-        r = parent;
-      }
-    }
-    if (r == null) {
-      throw new IllegalStateException("Found no root module");
-    }
-    return r;
+    this.root = root;
   }
 
   @Override
@@ -85,24 +65,24 @@ public class DefaultInputModuleHierarchy implements InputModuleHierarchy {
   }
 
   @Override
-  public Collection<DefaultInputModule> children(InputModule component) {
-    return children.get((DefaultInputModule) component);
+  public Collection<DefaultInputModule> children(DefaultInputModule component) {
+    return children.get(component);
   }
 
   @Override
-  public DefaultInputModule parent(InputModule component) {
+  public DefaultInputModule parent(DefaultInputModule component) {
     return parents.get(component);
   }
 
   @Override
-  public boolean isRoot(InputModule module) {
+  public boolean isRoot(DefaultInputModule module) {
     return root.equals(module);
   }
 
   @Override
   @CheckForNull
-  public String relativePath(InputModule module) {
-    DefaultInputModule parent = parent(module);
+  public String relativePath(DefaultInputModule module) {
+    AbstractProjectOrModule parent = parent(module);
     if (parent == null) {
       return null;
     }
index c62c72f1122d99c31c61eae35f3f7726afa318fd..6392a5dd51584453d21815696bcc48c0e9f51c9c 100644 (file)
@@ -21,44 +21,35 @@ package org.sonar.scanner.scan;
 
 import java.util.HashMap;
 import java.util.Map;
-
 import org.picocontainer.injectors.ProviderAdapter;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.batch.bootstrap.ProjectReactor;
 import org.sonar.api.batch.fs.internal.DefaultInputModule;
-import org.sonar.scanner.scan.filesystem.BatchIdGenerator;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
+import org.sonar.scanner.scan.filesystem.ScannerComponentIdGenerator;
 
 public class InputModuleHierarchyProvider extends ProviderAdapter {
 
   private DefaultInputModuleHierarchy hierarchy = null;
 
-  public DefaultInputModuleHierarchy provide(ProjectBuildersExecutor projectBuildersExecutor, ProjectReactorValidator validator,
-    ProjectReactor projectReactor, BatchIdGenerator batchIdGenerator) {
+  public DefaultInputModuleHierarchy provide(ScannerComponentIdGenerator scannerComponentIdGenerator, DefaultInputProject project) {
     if (hierarchy == null) {
-      // 1 Apply project builders
-      projectBuildersExecutor.execute(projectReactor);
-
-      // 2 Validate final reactor
-      validator.validate(projectReactor);
-
-      // 3 Create modules and the hierarchy
-      DefaultInputModule root = new DefaultInputModule(projectReactor.getRoot(), batchIdGenerator.getAsInt());
-      Map<DefaultInputModule, DefaultInputModule> parents = createChildren(root, batchIdGenerator, new HashMap<>());
+      DefaultInputModule root = new DefaultInputModule(project.definition(), project.scannerId());
+      Map<DefaultInputModule, DefaultInputModule> parents = createChildren(root, scannerComponentIdGenerator, new HashMap<>());
       if (parents.isEmpty()) {
         hierarchy = new DefaultInputModuleHierarchy(root);
       } else {
-        hierarchy = new DefaultInputModuleHierarchy(parents);
+        hierarchy = new DefaultInputModuleHierarchy(root, parents);
       }
     }
     return hierarchy;
   }
 
-  private static Map<DefaultInputModule, DefaultInputModule> createChildren(DefaultInputModule parent, BatchIdGenerator batchIdGenerator,
-    Map<DefaultInputModule, DefaultInputModule> parents) {
+  private static Map<DefaultInputModule, DefaultInputModule> createChildren(DefaultInputModule parent, ScannerComponentIdGenerator scannerComponentIdGenerator,
+                                                                                      Map<DefaultInputModule, DefaultInputModule> parents) {
     for (ProjectDefinition def : parent.definition().getSubProjects()) {
-      DefaultInputModule child = new DefaultInputModule(def, batchIdGenerator.getAsInt());
+      DefaultInputModule child = new DefaultInputModule(def, scannerComponentIdGenerator.getAsInt());
       parents.put(child, parent);
-      createChildren(child, batchIdGenerator, parents);
+      createChildren(child, scannerComponentIdGenerator, parents);
     }
     return parents;
   }
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/InputProjectProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/InputProjectProvider.java
new file mode 100644 (file)
index 0000000..4363fb6
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.scanner.scan;
+
+import org.picocontainer.injectors.ProviderAdapter;
+import org.sonar.api.batch.bootstrap.ProjectReactor;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
+import org.sonar.scanner.scan.filesystem.ScannerComponentIdGenerator;
+
+public class InputProjectProvider extends ProviderAdapter {
+
+  private DefaultInputProject project = null;
+
+  public DefaultInputProject provide(ProjectBuildersExecutor projectBuildersExecutor, ProjectReactorValidator validator,
+                                         ProjectReactor projectReactor, ScannerComponentIdGenerator scannerComponentIdGenerator) {
+    if (project == null) {
+      // 1 Apply project builders
+      projectBuildersExecutor.execute(projectReactor);
+
+      // 2 Validate final reactor
+      validator.validate(projectReactor);
+
+      // 3 Create modules and the hierarchy
+      project = new DefaultInputProject(projectReactor.getRoot(), scannerComponentIdGenerator.getAsInt());
+    }
+    return project;
+  }
+}
index f078a0d11be17d441fda495b255223e8c6d0131e..7f03d2cca6558ef4f1aab1c07f700e690a03e718 100644 (file)
@@ -41,7 +41,6 @@ public class ModuleConfigurationProvider extends ProviderAdapter {
     if (moduleConfiguration == null) {
 
       Map<String, String> settings = new LinkedHashMap<>();
-      settings.putAll(globalConfig.getProperties());
       settings.putAll(addServerSidePropertiesIfModuleExists(projectRepos, module.definition()));
       addScannerSideProperties(settings, module.definition());
       contextReportPublisher.dumpModuleSettings(module);
index bf7d9fb6669d2c278676f8129e109600ad256ada..60baccdfa5ad7d1cb758e695d0e3b7dee9c1f1ed 100644 (file)
 package org.sonar.scanner.scan;
 
 import org.picocontainer.Startable;
+import org.sonar.api.batch.fs.internal.AbstractProjectOrModule;
 import org.sonar.api.batch.fs.internal.DefaultInputModule;
 import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
 import org.sonar.scanner.scan.filesystem.InputComponentStore;
 
 /**
- * Indexes all modules into {@link DefaultComponentTree}, {@link DefaultInputModuleHierarchy) and {@link InputComponentStore}, using the 
+ * Indexes all modules into {@link DefaultComponentTree}, {@link DefaultInputModuleHierarchy) and {@link InputComponentStore}, using the
  * project definitions provided by the {@link ImmutableProjectReactor}.
  */
 public class ModuleIndexer implements Startable {
@@ -42,6 +43,7 @@ public class ModuleIndexer implements Startable {
   @Override
   public void start() {
     DefaultInputModule root = moduleHierarchy.root();
+    componentStore.put(root);
     indexChildren(root);
   }
 
index d4a87b31e40c211a27de00da6806a3275871cc71..11853632ef20eded991558f2de916f3978b4469a 100644 (file)
@@ -27,7 +27,7 @@ import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
 import org.sonar.api.config.Settings;
 import org.sonar.api.utils.MessageException;
-import org.sonar.scanner.bootstrap.MutableGlobalSettings;
+import org.sonar.scanner.bootstrap.GlobalConfiguration;
 import org.sonar.scanner.repository.ProjectRepositories;
 
 import static java.util.Objects.requireNonNull;
@@ -42,23 +42,23 @@ public class MutableModuleSettings extends Settings {
   private final AnalysisMode analysisMode;
   private final Map<String, String> properties = new HashMap<>();
 
-  public MutableModuleSettings(MutableGlobalSettings batchSettings, ProjectDefinition moduleDefinition, ProjectRepositories projectSettingsRepo,
-    AnalysisMode analysisMode) {
-    super(batchSettings.getDefinitions(), batchSettings.getEncryption());
+  public MutableModuleSettings(GlobalConfiguration globalConfig, ProjectDefinition moduleDefinition, ProjectRepositories projectSettingsRepo,
+                               AnalysisMode analysisMode) {
+    super(globalConfig.getDefinitions(), globalConfig.getEncryption());
     this.projectRepos = projectSettingsRepo;
     this.analysisMode = analysisMode;
 
-    init(moduleDefinition, batchSettings);
+    init(moduleDefinition, globalConfig);
   }
 
-  private MutableModuleSettings init(ProjectDefinition moduleDefinition, MutableGlobalSettings batchSettings) {
-    addProjectProperties(moduleDefinition, batchSettings);
+  private MutableModuleSettings init(ProjectDefinition moduleDefinition, GlobalConfiguration globalConfig) {
+    addProjectProperties(moduleDefinition, globalConfig);
     addBuildProperties(moduleDefinition);
     return this;
   }
 
-  private void addProjectProperties(ProjectDefinition def, MutableGlobalSettings batchSettings) {
-    addProperties(batchSettings.getProperties());
+  private void addProjectProperties(ProjectDefinition def, GlobalConfiguration globalConfig) {
+    addProperties(globalConfig.getProperties());
     do {
       if (projectRepos.moduleExists(def.getKeyWithBranch())) {
         addProperties(projectRepos.settings(def.getKeyWithBranch()));
index c09c844a09544f5f17c14ab27cb9595895cec484..4d8d3f7a43d600518601d5e3ee386bcfd1aa76bb 100644 (file)
@@ -26,7 +26,7 @@ import org.sonar.api.batch.bootstrap.ProjectReactor;
 import org.sonar.api.config.Settings;
 import org.sonar.api.utils.MessageException;
 import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
-import org.sonar.scanner.bootstrap.MutableGlobalSettings;
+import org.sonar.scanner.bootstrap.GlobalConfiguration;
 import org.sonar.scanner.repository.ProjectRepositories;
 
 import static java.util.Objects.requireNonNull;
@@ -40,10 +40,10 @@ public class MutableProjectSettings extends Settings {
   private final GlobalAnalysisMode mode;
   private final Map<String, String> properties = new HashMap<>();
 
-  public MutableProjectSettings(ProjectReactor reactor, MutableGlobalSettings mutableGlobalSettings, ProjectRepositories projectRepositories, GlobalAnalysisMode mode) {
-    super(mutableGlobalSettings.getDefinitions(), mutableGlobalSettings.getEncryption());
+  public MutableProjectSettings(ProjectReactor reactor, GlobalConfiguration globalConfig, ProjectRepositories projectRepositories, GlobalAnalysisMode mode) {
+    super(globalConfig.getDefinitions(), globalConfig.getEncryption());
     this.mode = mode;
-    addProperties(mutableGlobalSettings.getProperties());
+    addProperties(globalConfig.getProperties());
     addProperties(projectRepositories.settings(reactor.getRoot().getKeyWithBranch()));
     addProperties(reactor.getRoot().properties());
   }
index 51041627d70411d62d889117da1c81b24b6bdd0d..9db726d7e75b9d88db2fb4205fcac097ff5efdf4 100644 (file)
@@ -22,24 +22,26 @@ package org.sonar.scanner.scan;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import org.picocontainer.injectors.ProviderAdapter;
-import org.sonar.api.batch.bootstrap.ProjectReactor;
+import org.sonar.api.batch.fs.internal.AbstractProjectOrModule;
 import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
 import org.sonar.scanner.bootstrap.GlobalConfiguration;
+import org.sonar.scanner.bootstrap.GlobalServerSettings;
 import org.sonar.scanner.repository.ProjectRepositories;
 
 public class ProjectConfigurationProvider extends ProviderAdapter {
 
   private ProjectConfiguration projectConfig;
 
-  public ProjectConfiguration provide(ProjectReactor reactor, GlobalConfiguration globalSettings, ProjectRepositories projectRepositories, GlobalAnalysisMode mode) {
+  public ProjectConfiguration provide(GlobalServerSettings globalServerSettings, AbstractProjectOrModule project,
+                                      GlobalConfiguration globalConfig, ProjectRepositories projectRepositories, GlobalAnalysisMode mode) {
     if (projectConfig == null) {
 
       Map<String, String> settings = new LinkedHashMap<>();
-      settings.putAll(globalSettings.getProperties());
-      settings.putAll(projectRepositories.settings(reactor.getRoot().getKeyWithBranch()));
-      settings.putAll(reactor.getRoot().properties());
+      settings.putAll(globalServerSettings.properties());
+      settings.putAll(projectRepositories.settings(project.getKeyWithBranch()));
+      settings.putAll(project.properties());
 
-      projectConfig = new ProjectConfiguration(globalSettings.getDefinitions(), globalSettings.getEncryption(), mode, settings);
+      projectConfig = new ProjectConfiguration(globalConfig.getDefinitions(), globalConfig.getEncryption(), mode, settings);
     }
     return projectConfig;
   }
index 04c0b3a1cbd5e7048e6adf2c0b47f8634e2259a7..89bfe76c1f278b68e777fb03b794baa3d19bdbe4 100644 (file)
@@ -24,13 +24,13 @@ import java.nio.channels.OverlappingFileLockException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import org.picocontainer.Startable;
-import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
+import org.sonar.api.batch.fs.internal.AbstractProjectOrModule;
 
 public class ProjectLock implements Startable {
   private final DirectoryLock lock;
 
-  public ProjectLock(InputModuleHierarchy moduleHierarchy) {
-    Path directory = moduleHierarchy.root().getWorkDir();
+  public ProjectLock(AbstractProjectOrModule project) {
+    Path directory = project.getWorkDir();
     try {
       if (!directory.toFile().exists()) {
         Files.createDirectories(directory);
index 724ef96517de0d70f64ab9623fdb26b065928bfc..f9667af57b1acd8176ab359d13ecb56b0463d0b9 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.scanner.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;
@@ -43,8 +42,7 @@ 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.scanner.analysis.AnalysisProperties;
-import org.sonar.scanner.bootstrap.DroppedPropertyChecker;
+import org.sonar.scanner.bootstrap.ScannerProperties;
 import org.sonar.scanner.util.ScannerUtils;
 
 import static org.sonar.core.config.MultivalueProperty.parseAsCsv;
@@ -56,13 +54,6 @@ 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<String, String> DROPPED_PROPERTIES = ImmutableMap.of(
-    "sonar.qualitygate", "It will be ignored.");
-
   private static final Logger LOG = Loggers.get(ProjectReactorBuilder.class);
 
   /**
@@ -109,30 +100,27 @@ public class ProjectReactorBuilder {
   private static final List<String> NON_HERITED_PROPERTIES_FOR_CHILD = Lists.newArrayList(PROPERTY_PROJECT_BASEDIR, CoreProperties.WORKING_DIRECTORY, PROPERTY_MODULES,
     CoreProperties.PROJECT_DESCRIPTION_PROPERTY);
 
-  private final AnalysisProperties analysisProps;
+  private final ScannerProperties scannerProps;
   private File rootProjectWorkDir;
 
-  public ProjectReactorBuilder(AnalysisProperties props) {
-    this.analysisProps = props;
+  public ProjectReactorBuilder(ScannerProperties props) {
+    this.scannerProps = props;
   }
 
   public ProjectReactor execute() {
     Profiler profiler = Profiler.create(LOG).startInfo("Process project properties");
-    new DroppedPropertyChecker(analysisProps.properties(), DROPPED_PROPERTIES).checkDroppedProperties();
     Map<String, Map<String, String>> propertiesByModuleIdPath = new HashMap<>();
-    extractPropertiesByModule(propertiesByModuleIdPath, "", "", analysisProps.properties());
-    ProjectDefinition rootProject = defineRootProject(propertiesByModuleIdPath.get(""), null);
+    extractPropertiesByModule(propertiesByModuleIdPath, "", "", new HashMap<>(scannerProps.properties()));
+    ProjectDefinition rootProject = createModuleDefinition(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<String, Map<String, String>> propertiesByModuleIdPath, String currentModuleId, String currentModuleIdPath,
-    Map<String, String> parentProperties) {
+                                                Map<String, String> 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));
     }
@@ -167,26 +155,26 @@ public class ProjectReactorBuilder {
     }
   }
 
-  protected ProjectDefinition defineRootProject(Map<String, String> rootProperties, @Nullable ProjectDefinition parent) {
-    if (rootProperties.containsKey(PROPERTY_MODULES)) {
-      checkMandatoryProperties(rootProperties, MANDATORY_PROPERTIES_FOR_MULTIMODULE_PROJECT);
+  protected ProjectDefinition createModuleDefinition(Map<String, String> moduleProperties, @Nullable ProjectDefinition parent) {
+    if (moduleProperties.containsKey(PROPERTY_MODULES)) {
+      checkMandatoryProperties(moduleProperties, MANDATORY_PROPERTIES_FOR_MULTIMODULE_PROJECT);
     } else {
-      checkMandatoryProperties(rootProperties, MANDATORY_PROPERTIES_FOR_SIMPLE_PROJECT);
+      checkMandatoryProperties(moduleProperties, MANDATORY_PROPERTIES_FOR_SIMPLE_PROJECT);
     }
-    File baseDir = new File(rootProperties.get(PROPERTY_PROJECT_BASEDIR));
-    final String projectKey = rootProperties.get(CoreProperties.PROJECT_KEY_PROPERTY);
+    File baseDir = new File(moduleProperties.get(PROPERTY_PROJECT_BASEDIR));
+    final String projectKey = moduleProperties.get(CoreProperties.PROJECT_KEY_PROPERTY);
     File workDir;
     if (parent == null) {
-      validateDirectories(rootProperties, baseDir, projectKey);
-      workDir = initRootProjectWorkDir(baseDir, rootProperties);
+      validateDirectories(moduleProperties, baseDir, projectKey);
+      workDir = initRootProjectWorkDir(baseDir, moduleProperties);
     } else {
-      workDir = initModuleWorkDir(baseDir, rootProperties);
+      workDir = initModuleWorkDir(baseDir, moduleProperties);
     }
 
-    return ProjectDefinition.create().setProperties(rootProperties)
+    return ProjectDefinition.create().setProperties(moduleProperties)
       .setBaseDir(baseDir)
       .setWorkDir(workDir)
-      .setBuildDir(initModuleBuildDir(baseDir, rootProperties));
+      .setBuildDir(initModuleBuildDir(baseDir, moduleProperties));
   }
 
   @VisibleForTesting
@@ -266,7 +254,7 @@ public class ProjectReactorBuilder {
 
     mergeParentProperties(moduleProps, parentProject.properties());
 
-    return defineRootProject(moduleProps, parentProject);
+    return createModuleDefinition(moduleProps, parentProject);
   }
 
   @VisibleForTesting
@@ -402,9 +390,8 @@ public class ProjectReactorBuilder {
 
   /**
    * Transforms a comma-separated list String property in to a array of trimmed strings.
-   *
+   * <p>
    * This works even if they are separated by whitespace characters (space char, EOL, ...)
-   *
    */
   static String[] getListFromProperty(Map<String, String> properties, String key) {
     String propValue = properties.get(key);
index a4dea8452bfbca34d912005a62bc0462718bb57c..332bb65299a4cb165b32d26bb42377ac9185b584 100644 (file)
@@ -36,7 +36,6 @@ import org.sonar.core.extension.CoreExtensionsInstaller;
 import org.sonar.core.metric.ScannerMetrics;
 import org.sonar.core.platform.ComponentContainer;
 import org.sonar.scanner.ProjectAnalysisInfo;
-import org.sonar.scanner.analysis.AnalysisProperties;
 import org.sonar.scanner.analysis.AnalysisTempFolderProvider;
 import org.sonar.scanner.analysis.DefaultAnalysisMode;
 import org.sonar.scanner.bootstrap.ExtensionInstaller;
@@ -56,7 +55,7 @@ import org.sonar.scanner.issue.tracking.IssueTransition;
 import org.sonar.scanner.issue.tracking.LocalIssueTracking;
 import org.sonar.scanner.issue.tracking.ServerIssueRepository;
 import org.sonar.scanner.issue.tracking.ServerLineHashesLoader;
-import org.sonar.scanner.mediumtest.ScanTaskObservers;
+import org.sonar.scanner.mediumtest.AnalysisObservers;
 import org.sonar.scanner.notifications.DefaultAnalysisWarnings;
 import org.sonar.scanner.phases.ProjectCoverageExclusions;
 import org.sonar.scanner.report.ActiveRulesPublisher;
@@ -93,8 +92,8 @@ import org.sonar.scanner.scan.branch.BranchConfigurationProvider;
 import org.sonar.scanner.scan.branch.BranchType;
 import org.sonar.scanner.scan.branch.ProjectBranchesProvider;
 import org.sonar.scanner.scan.branch.ProjectPullRequestsProvider;
-import org.sonar.scanner.scan.filesystem.BatchIdGenerator;
-import org.sonar.scanner.scan.filesystem.InputComponentStoreProvider;
+import org.sonar.scanner.scan.filesystem.InputComponentStore;
+import org.sonar.scanner.scan.filesystem.ScannerComponentIdGenerator;
 import org.sonar.scanner.scan.filesystem.StatusDetection;
 import org.sonar.scanner.scan.measure.DefaultMetricFinder;
 import org.sonar.scanner.scan.measure.MeasureCache;
@@ -111,11 +110,8 @@ public class ProjectScanContainer extends ComponentContainer {
 
   private static final Logger LOG = Loggers.get(ProjectScanContainer.class);
 
-  private final AnalysisProperties props;
-
-  public ProjectScanContainer(ComponentContainer globalContainer, AnalysisProperties props) {
+  public ProjectScanContainer(ComponentContainer globalContainer) {
     super(globalContainer);
-    this.props = props;
   }
 
   @Override
@@ -136,7 +132,6 @@ public class ProjectScanContainer extends ComponentContainer {
 
   private void addScannerComponents() {
     add(
-      props,
       ProjectReactorBuilder.class,
       ScanProperties.class,
       WorkDirectoriesInitializer.class,
@@ -160,11 +155,12 @@ public class ProjectScanContainer extends ComponentContainer {
 
       // file system
       ModuleIndexer.class,
-      new InputComponentStoreProvider(),
+      InputComponentStore.class,
       PathResolver.class,
+      new InputProjectProvider(),
       new InputModuleHierarchyProvider(),
       DefaultComponentTree.class,
-      BatchIdGenerator.class,
+      ScannerComponentIdGenerator.class,
       new ScmChangedFilesProvider(),
       StatusDetection.class,
 
@@ -221,7 +217,7 @@ public class ProjectScanContainer extends ComponentContainer {
       SonarCpdBlockIndex.class,
       JavaCpdBlockIndexerSensor.class,
 
-      ScanTaskObservers.class);
+      AnalysisObservers.class);
 
     addIfMissing(DefaultRulesLoader.class, RulesLoader.class);
     addIfMissing(DefaultActiveRulesLoader.class, ActiveRulesLoader.class);
@@ -296,7 +292,7 @@ public class ProjectScanContainer extends ComponentContainer {
     scanRecursively(tree, tree.root(), analysisMode);
 
     if (analysisMode.isMediumTest()) {
-      getComponentByType(ScanTaskObservers.class).notifyEndOfScanTask();
+      getComponentByType(AnalysisObservers.class).notifyEndOfScanTask();
     }
   }
 
index 4ea33493008cea7a5564bcf1c754736bcd4bc724..8dceea747fc3a744bddfe5e53579dca8dc2b7516 100644 (file)
@@ -23,7 +23,7 @@ import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.Optional;
 import org.sonar.api.batch.ScannerSide;
-import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.config.Configuration;
 import org.sonar.api.utils.MessageException;
 
@@ -44,11 +44,11 @@ public class ScanProperties {
   public static final String FORCE_RELOAD_KEY = "sonar.scm.forceReloadAll";
 
   private final Configuration configuration;
-  private final InputModuleHierarchy moduleHierarchy;
+  private final DefaultInputProject project;
 
-  public ScanProperties(Configuration configuration, InputModuleHierarchy moduleHierarchy) {
+  public ScanProperties(Configuration configuration, DefaultInputProject project) {
     this.configuration = configuration;
-    this.moduleHierarchy = moduleHierarchy;
+    this.project = project;
   }
 
   public boolean shouldKeepReport() {
@@ -74,9 +74,9 @@ public class ScanProperties {
       if (!metadataPath.isAbsolute()) {
         throw MessageException.of(String.format("Property '%s' must point to an absolute path: %s", METADATA_FILE_PATH_KEY, metadataFilePath.get()));
       }
-      return moduleHierarchy.root().getBaseDir().resolve(metadataPath);
+      return project.getBaseDir().resolve(metadataPath);
     } else {
-      return moduleHierarchy.root().getWorkDir().resolve(METADATA_DUMP_FILENAME);
+      return project.getWorkDir().resolve(METADATA_DUMP_FILENAME);
     }
   }
 
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/BatchIdGenerator.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/BatchIdGenerator.java
deleted file mode 100644 (file)
index 7ae7d40..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.scanner.scan.filesystem;
-
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.function.IntSupplier;
-
-import javax.annotation.concurrent.ThreadSafe;
-
-import org.sonar.api.batch.fs.InputComponent;
-
-/**
- * Generates unique IDs for any {@link InputComponent}. 
- * The IDs must be unique among all types of components and for all modules in the project.
- * The ID should never be 0, as it is sometimes used to indicate invalid components. 
- */
-@ThreadSafe
-public class BatchIdGenerator implements IntSupplier {
-  private AtomicInteger nextBatchId = new AtomicInteger(1);
-
-  @Override
-  public int getAsInt() {
-    return nextBatchId.getAndIncrement();
-  }
-}
index d6d9878c5ccbc9bd05acc79b4521c53bfe98d9f0..4e9dc9406de25164e20f788885b44964cebafc3a 100644 (file)
@@ -21,24 +21,24 @@ package org.sonar.scanner.scan.filesystem;
 
 import com.google.common.annotations.VisibleForTesting;
 import org.sonar.api.batch.fs.internal.DefaultFileSystem;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.AbstractProjectOrModule;
 import org.sonar.scanner.analysis.DefaultAnalysisMode;
 
 public class DefaultModuleFileSystem extends DefaultFileSystem {
 
-  public DefaultModuleFileSystem(ModuleInputComponentStore moduleInputFileCache, DefaultInputModule module, ModuleFileSystemInitializer initializer, DefaultAnalysisMode mode,
-    StatusDetection statusDetection) {
+  public DefaultModuleFileSystem(ModuleInputComponentStore moduleInputFileCache, AbstractProjectOrModule module, ModuleFileSystemInitializer initializer, DefaultAnalysisMode mode,
+                                 StatusDetection statusDetection) {
     super(module.getBaseDir(), moduleInputFileCache);
     setFields(module, initializer, mode, statusDetection);
   }
 
   @VisibleForTesting
-  public DefaultModuleFileSystem(DefaultInputModule module, ModuleFileSystemInitializer initializer, DefaultAnalysisMode mode, StatusDetection statusDetection) {
+  public DefaultModuleFileSystem(AbstractProjectOrModule module, ModuleFileSystemInitializer initializer, DefaultAnalysisMode mode, StatusDetection statusDetection) {
     super(module.getBaseDir());
     setFields(module, initializer, mode, statusDetection);
   }
 
-  private void setFields(DefaultInputModule module, ModuleFileSystemInitializer initializer, DefaultAnalysisMode mode, StatusDetection statusDetection) {
+  private void setFields(AbstractProjectOrModule module, ModuleFileSystemInitializer initializer, DefaultAnalysisMode mode, StatusDetection statusDetection) {
     setWorkDir(module.getWorkDir());
     setEncoding(initializer.defaultEncoding());
 
index 591c66bdc5d76f39c2777c1b397cf8b2e39c736f..7779852b181bf775ac425ad0e19af4639f7c4289 100644 (file)
@@ -44,9 +44,10 @@ import org.sonar.api.batch.ScannerSide;
 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.InputModule;
 import org.sonar.api.batch.fs.internal.DefaultInputDir;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.AbstractProjectOrModule;
 import org.sonar.api.scan.filesystem.PathResolver;
 import org.sonar.api.utils.MessageException;
 import org.sonar.scanner.scan.DefaultComponentTree;
@@ -63,8 +64,8 @@ public class FileIndexer {
   private final ExclusionFilters exclusionFilters;
   private final InputFileBuilder inputFileBuilder;
   private final DefaultComponentTree componentTree;
-  private final DefaultInputModule module;
-  private final BatchIdGenerator batchIdGenerator;
+  private final AbstractProjectOrModule module;
+  private final ScannerComponentIdGenerator scannerComponentIdGenerator;
   private final InputComponentStore componentStore;
   private final ModuleFileSystemInitializer moduleFileSystemInitializer;
   private ExecutorService executorService;
@@ -74,13 +75,13 @@ public class FileIndexer {
 
   private ProgressReport progressReport;
 
-  public FileIndexer(BatchIdGenerator batchIdGenerator, InputComponentStore componentStore, DefaultInputModule module, ExclusionFilters exclusionFilters,
-    DefaultComponentTree componentTree, InputFileBuilder inputFileBuilder, ModuleFileSystemInitializer initializer, DefaultModuleFileSystem defaultModuleFileSystem,
-    LanguageDetection languageDetection,
-    InputFileFilter[] filters) {
-    this.batchIdGenerator = batchIdGenerator;
+  public FileIndexer(ScannerComponentIdGenerator scannerComponentIdGenerator, InputComponentStore componentStore, InputModule module, ExclusionFilters exclusionFilters,
+                     DefaultComponentTree componentTree, InputFileBuilder inputFileBuilder, ModuleFileSystemInitializer initializer, DefaultModuleFileSystem defaultModuleFileSystem,
+                     LanguageDetection languageDetection,
+                     InputFileFilter[] filters) {
+    this.scannerComponentIdGenerator = scannerComponentIdGenerator;
     this.componentStore = componentStore;
-    this.module = module;
+    this.module = (AbstractProjectOrModule) module;
     this.componentTree = componentTree;
     this.inputFileBuilder = inputFileBuilder;
     this.moduleFileSystemInitializer = initializer;
@@ -91,10 +92,10 @@ public class FileIndexer {
     this.tasks = new ArrayList<>();
   }
 
-  public FileIndexer(BatchIdGenerator batchIdGenerator, InputComponentStore componentStore, DefaultInputModule module, ExclusionFilters exclusionFilters,
-    DefaultComponentTree componentTree, InputFileBuilder inputFileBuilder, ModuleFileSystemInitializer initializer, DefaultModuleFileSystem defaultModuleFileSystem,
-    LanguageDetection languageDetection) {
-    this(batchIdGenerator, componentStore, module, exclusionFilters, componentTree, inputFileBuilder, initializer, defaultModuleFileSystem, languageDetection,
+  public FileIndexer(ScannerComponentIdGenerator scannerComponentIdGenerator, InputComponentStore componentStore, InputModule module, ExclusionFilters exclusionFilters,
+                     DefaultComponentTree componentTree, InputFileBuilder inputFileBuilder, ModuleFileSystemInitializer initializer, DefaultModuleFileSystem defaultModuleFileSystem,
+                     LanguageDetection languageDetection) {
+    this(scannerComponentIdGenerator, componentStore, module, exclusionFilters, componentTree, inputFileBuilder, initializer, defaultModuleFileSystem, languageDetection,
       new InputFileFilter[0]);
   }
 
@@ -213,7 +214,7 @@ public class FileIndexer {
   private void indexFileAndParentDir(InputFile inputFile, String parentRelativePath) {
     DefaultInputDir inputDir = (DefaultInputDir) componentStore.getDir(module.key(), parentRelativePath);
     if (inputDir == null) {
-      inputDir = new DefaultInputDir(module.key(), parentRelativePath, batchIdGenerator.getAsInt());
+      inputDir = new DefaultInputDir(module.key(), parentRelativePath, scannerComponentIdGenerator.getAsInt());
       inputDir.setModuleBaseDir(module.getBaseDir());
       componentTree.index(inputDir, module);
       defaultModuleFileSystem.add(inputDir);
index 126cc8984194b8b55222916098ae1c5e2ea95fbd..15eb4f6b0a0cc7f87480b833c1e5149222dae798 100644 (file)
@@ -33,23 +33,21 @@ import java.util.SortedSet;
 import java.util.TreeSet;
 import java.util.stream.Stream;
 import javax.annotation.CheckForNull;
-import org.sonar.api.batch.ScannerSide;
 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.InputModule;
+import org.sonar.api.batch.fs.internal.AbstractProjectOrModule;
 import org.sonar.api.batch.fs.internal.DefaultInputDir;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
 import org.sonar.api.batch.fs.internal.FileExtensionPredicate;
 import org.sonar.api.scan.filesystem.PathResolver;
+import org.sonar.api.scanner.fs.InputProject;
 import org.sonar.scanner.scan.branch.BranchConfiguration;
 
 /**
- * Store of all files and dirs. This cache is shared amongst all project modules. Inclusion and
+ * Store of all files and dirs. Inclusion and
  * exclusion patterns are already applied.
  */
-@ScannerSide
 public class InputComponentStore {
 
   private final SortedSet<String> globalLanguagesCache = new TreeSet<>();
@@ -59,17 +57,16 @@ public class InputComponentStore {
   private final Map<String, InputDir> globalInputDirCache = new HashMap<>();
   private final Table<String, String, InputDir> inputDirCache = TreeBasedTable.create();
   // indexed by key with branch
-  private final Map<String, InputModule> inputModuleCache = new HashMap<>();
+  private final Map<String, AbstractProjectOrModule> inputModuleCache = new HashMap<>();
   private final Map<String, InputComponent> inputComponents = new HashMap<>();
   private final SetMultimap<String, InputFile> filesByNameCache = LinkedHashMultimap.create();
   private final SetMultimap<String, InputFile> filesByExtensionCache = LinkedHashMultimap.create();
-  private final InputModule root;
+  private final InputProject project;
   private final BranchConfiguration branchConfiguration;
 
-  public InputComponentStore(DefaultInputModule root, BranchConfiguration branchConfiguration) {
-    this.root = root;
+  public InputComponentStore(InputProject project, BranchConfiguration branchConfiguration) {
+    this.project = project;
     this.branchConfiguration = branchConfiguration;
-    this.put(root);
   }
 
   public Collection<InputComponent> all() {
@@ -104,10 +101,6 @@ public class InputComponentStore {
     return inputComponents.get(key);
   }
 
-  public InputModule root() {
-    return root;
-  }
-
   public Iterable<InputFile> filesByModule(String moduleKey) {
     return inputFileCache.row(moduleKey).values();
   }
@@ -167,7 +160,7 @@ public class InputComponentStore {
   }
 
   private Path getProjectBaseDir() {
-    return ((DefaultInputModule) root).getBaseDir();
+    return ((AbstractProjectOrModule) project).getBaseDir();
   }
 
   @CheckForNull
@@ -191,11 +184,11 @@ public class InputComponentStore {
   }
 
   @CheckForNull
-  public InputModule getModule(String moduleKeyWithBranch) {
+  public AbstractProjectOrModule getModule(String moduleKeyWithBranch) {
     return inputModuleCache.get(moduleKeyWithBranch);
   }
 
-  public void put(DefaultInputModule inputModule) {
+  public void put(AbstractProjectOrModule inputModule) {
     String key = inputModule.key();
     String keyWithBranch = inputModule.getKeyWithBranch();
     Preconditions.checkNotNull(inputModule);
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputComponentStoreProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputComponentStoreProvider.java
deleted file mode 100644 (file)
index 8dedebf..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.scanner.scan.filesystem;
-
-import org.picocontainer.injectors.ProviderAdapter;
-import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
-import org.sonar.scanner.scan.branch.BranchConfiguration;
-
-public class InputComponentStoreProvider extends ProviderAdapter {
-  private InputComponentStore store;
-
-  public InputComponentStore provide(InputModuleHierarchy hierarchy, BranchConfiguration branchConfiguration) {
-    if (store == null) {
-      store = new InputComponentStore(hierarchy.root(), branchConfiguration);
-    }
-    return store;
-  }
-}
index 1ed2c8438cf770f636c0b8058d8f81cca86078d6..8d14471b65c4946985802fb400339dda888e3e18 100644 (file)
@@ -21,11 +21,11 @@ package org.sonar.scanner.scan.filesystem;
 
 import java.nio.file.Path;
 import javax.annotation.Nullable;
-
 import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.fs.InputModule;
 import org.sonar.api.batch.fs.internal.DefaultIndexedFile;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.AbstractProjectOrModule;
 import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
 import org.sonar.api.batch.fs.internal.SensorStrategy;
 import org.sonar.scanner.scan.ScanProperties;
@@ -33,21 +33,21 @@ import org.sonar.scanner.scan.ScanProperties;
 public class InputFileBuilder {
   private final String moduleKey;
   private final Path moduleBaseDir;
-  private final BatchIdGenerator idGenerator;
+  private final ScannerComponentIdGenerator idGenerator;
   private final MetadataGenerator metadataGenerator;
   private final boolean preloadMetadata;
   private final ModuleFileSystemInitializer moduleFileSystemInitializer;
   private final Path projectBaseDir;
   private final SensorStrategy sensorStrategy;
 
-  public InputFileBuilder(DefaultInputModule module, MetadataGenerator metadataGenerator,
-    BatchIdGenerator idGenerator, ScanProperties properties, ModuleFileSystemInitializer moduleFileSystemInitializer, InputModuleHierarchy hierarchy,
-    SensorStrategy sensorStrategy) {
+  public InputFileBuilder(InputModule module, MetadataGenerator metadataGenerator,
+                          ScannerComponentIdGenerator idGenerator, ScanProperties properties, ModuleFileSystemInitializer moduleFileSystemInitializer, InputModuleHierarchy hierarchy,
+                          SensorStrategy sensorStrategy) {
     this.sensorStrategy = sensorStrategy;
     this.projectBaseDir = hierarchy.root().getBaseDir();
     this.moduleFileSystemInitializer = moduleFileSystemInitializer;
     this.moduleKey = module.key();
-    this.moduleBaseDir = module.getBaseDir();
+    this.moduleBaseDir = ((AbstractProjectOrModule) module).getBaseDir();
     this.metadataGenerator = metadataGenerator;
     this.idGenerator = idGenerator;
     this.preloadMetadata = properties.preloadFileMetadata();
index b157dbd986e19fe65cc7a33bc94b847a4aa3860d..8c32cd623220f47c60f62211766f7e38ed8678c7 100644 (file)
@@ -33,7 +33,8 @@ import org.apache.commons.lang.StringUtils;
 import org.sonar.api.CoreProperties;
 import org.sonar.api.batch.ScannerSide;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.InputModule;
+import org.sonar.api.batch.fs.internal.AbstractProjectOrModule;
 import org.sonar.api.scan.filesystem.PathResolver;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
@@ -50,15 +51,16 @@ public class ModuleFileSystemInitializer {
   private final List<Path> testDirsOrFiles;
   private final Charset encoding;
 
-  public ModuleFileSystemInitializer(DefaultInputModule inputModule) {
-    logDir("Base dir: ", inputModule.getBaseDir());
-    logDir("Working dir: ", inputModule.getWorkDir());
-    sourceDirsOrFiles = initSources(inputModule, ProjectDefinition.SOURCES_PROPERTY, "Source paths: ");
-    testDirsOrFiles = initSources(inputModule, ProjectDefinition.TESTS_PROPERTY, "Test paths: ");
-    encoding = initEncoding(inputModule);
+  public ModuleFileSystemInitializer(InputModule inputModule) {
+    AbstractProjectOrModule inputModuleCasted = (AbstractProjectOrModule) inputModule;
+    logDir("Base dir: ", inputModuleCasted.getBaseDir());
+    logDir("Working dir: ", inputModuleCasted.getWorkDir());
+    sourceDirsOrFiles = initSources(inputModuleCasted, ProjectDefinition.SOURCES_PROPERTY, "Source paths: ");
+    testDirsOrFiles = initSources(inputModuleCasted, ProjectDefinition.TESTS_PROPERTY, "Test paths: ");
+    encoding = initEncoding(inputModuleCasted);
   }
 
-  private static List<Path> initSources(DefaultInputModule module, String propertyKey, String logLabel) {
+  private static List<Path> initSources(AbstractProjectOrModule module, String propertyKey, String logLabel) {
     List<Path> result = new ArrayList<>();
     PathResolver pathResolver = new PathResolver();
     String srcPropValue = module.properties().get(propertyKey);
@@ -74,7 +76,7 @@ public class ModuleFileSystemInitializer {
     return result;
   }
 
-  private static Charset initEncoding(DefaultInputModule module) {
+  private static Charset initEncoding(AbstractProjectOrModule module) {
     String encodingStr = module.properties().get(CoreProperties.ENCODING_PROPERTY);
     Charset result;
     if (StringUtils.isNotEmpty(encodingStr)) {
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ScannerComponentIdGenerator.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ScannerComponentIdGenerator.java
new file mode 100644 (file)
index 0000000..2b16c3e
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.scanner.scan.filesystem;
+
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.IntSupplier;
+
+import javax.annotation.concurrent.ThreadSafe;
+
+import org.sonar.api.batch.fs.InputComponent;
+
+/**
+ * Generates unique IDs for any {@link InputComponent}. 
+ * The IDs must be unique among all types of components (project, files) in the project.
+ * The ID should never be 0, as it is sometimes used to indicate invalid components. 
+ */
+@ThreadSafe
+public class ScannerComponentIdGenerator implements IntSupplier {
+  private AtomicInteger nextId = new AtomicInteger(1);
+
+  @Override
+  public int getAsInt() {
+    return nextId.getAndIncrement();
+  }
+}
index dd59982f34a9870b560a394ac01147377bfdcf4d..b302742bf7b5ff12584d2f2b08745ee16cda93c7 100644 (file)
@@ -41,6 +41,7 @@ import org.sonar.api.batch.fs.InputComponent;
 import org.sonar.api.batch.fs.InputDir;
 import org.sonar.api.batch.fs.InputPath;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
+import org.sonar.api.batch.fs.internal.AbstractProjectOrModule;
 import org.sonar.api.batch.fs.internal.DefaultInputModule;
 import org.sonar.api.batch.fs.internal.InputComponentTree;
 import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
@@ -76,7 +77,7 @@ public class JSONReport implements Reporter {
   private final InputComponentTree inputComponentTree;
 
   public JSONReport(InputModuleHierarchy moduleHierarchy, Configuration settings, FileSystem fileSystem, Server server, Rules rules, IssueCache issueCache,
-    DefaultInputModule rootModule, InputComponentStore componentStore, InputComponentTree inputComponentTree) {
+                    DefaultInputModule rootModule, InputComponentStore componentStore, InputComponentTree inputComponentTree) {
     this.moduleHierarchy = moduleHierarchy;
     this.settings = settings;
     this.fileSystem = fileSystem;
@@ -157,14 +158,14 @@ public class JSONReport implements Reporter {
     json.endArray();
   }
 
-  private DefaultInputModule getModule(InputComponent component) {
+  private AbstractProjectOrModule getModule(InputComponent component) {
     if (component.isFile()) {
-      return (DefaultInputModule) inputComponentTree.getParent(inputComponentTree.getParent(component));
+      return (AbstractProjectOrModule) inputComponentTree.getParent(inputComponentTree.getParent(component));
     }
     if (component instanceof InputDir) {
-      return (DefaultInputModule) inputComponentTree.getParent(component);
+      return (AbstractProjectOrModule) inputComponentTree.getParent(component);
     }
-    return (DefaultInputModule) component;
+    return (AbstractProjectOrModule) component;
   }
 
   private void writeJsonComponents(JsonWriter json) {
@@ -196,13 +197,13 @@ public class JSONReport implements Reporter {
     json.endArray();
   }
 
-  private void writeJsonModuleComponents(JsonWriter json, DefaultInputModule module) {
+  private void writeJsonModuleComponents(JsonWriter json, DefaultInputModule moduleOrProject) {
     json
       .beginObject()
-      .prop("key", module.definition().getKeyWithBranch())
-      .prop("path", moduleHierarchy.relativePath(module))
+      .prop("key", moduleOrProject.definition().getKeyWithBranch())
+      .prop("path", moduleHierarchy.relativePath(moduleOrProject))
       .endObject();
-    for (DefaultInputModule subModule : moduleHierarchy.children(module)) {
+    for (DefaultInputModule subModule : moduleHierarchy.children(moduleOrProject)) {
       writeJsonModuleComponents(json, subModule);
     }
   }
index a328fd4c6d82f709ae7015f575732c794c8c79fb..3e6833cf34ba35f90febf036298ee7dd23fd07f5 100644 (file)
@@ -72,7 +72,7 @@ class DefaultBlameOutput implements BlameOutput {
 
     Builder scmBuilder = ScannerReport.Changesets.newBuilder();
     DefaultInputFile inputFile = (DefaultInputFile) file;
-    scmBuilder.setComponentRef(inputFile.batchId());
+    scmBuilder.setComponentRef(inputFile.scannerId());
     Map<String, Integer> changesetsIdByRevision = new HashMap<>();
 
     int lineId = 1;
index 3d2123a15d5259ab4f39eb54def84b6471700e69..454d2a6815a2f8b72e8605f8d2edc366f49a67f1 100644 (file)
@@ -24,7 +24,7 @@ import java.util.Collection;
 import javax.annotation.CheckForNull;
 import org.picocontainer.annotations.Nullable;
 import org.picocontainer.injectors.ProviderAdapter;
-import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.batch.scm.ScmProvider;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
@@ -41,12 +41,12 @@ public class ScmChangedFilesProvider extends ProviderAdapter {
   /*
    * ScmConfiguration is not available in issues mode
    */
-  public ScmChangedFiles provide(@Nullable ScmConfiguration scmConfiguration, BranchConfiguration branchConfiguration, InputModuleHierarchy inputModuleHierarchy) {
+  public ScmChangedFiles provide(@Nullable ScmConfiguration scmConfiguration, BranchConfiguration branchConfiguration, DefaultInputProject project) {
     if (scmBranchChangedFiles == null) {
       if (scmConfiguration == null) {
         scmBranchChangedFiles = new ScmChangedFiles(null);
       } else {
-        Path rootBaseDir = inputModuleHierarchy.root().getBaseDir();
+        Path rootBaseDir = project.getBaseDir();
         Collection<Path> changedFiles = loadChangedFilesIfNeeded(scmConfiguration, branchConfiguration, rootBaseDir);
         validatePaths(changedFiles);
         scmBranchChangedFiles = new ScmChangedFiles(changedFiles);
index f21a864feb81d2628de7a71dd6e5aa230b7230c7..78184f1dfb11b109c801251320e35e28eadfad7e 100644 (file)
@@ -28,7 +28,7 @@ import org.sonar.api.batch.ScannerSide;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.InputFile.Status;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.AbstractProjectOrModule;
 import org.sonar.api.batch.scm.ScmProvider;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
@@ -48,7 +48,7 @@ public final class ScmPublisher {
 
   private static final Logger LOG = Loggers.get(ScmPublisher.class);
 
-  private final DefaultInputModule inputModule;
+  private final AbstractProjectOrModule inputModule;
   private final ScmConfiguration configuration;
   private final ProjectRepositories projectRepositories;
   private final ModuleInputComponentStore componentStore;
@@ -56,8 +56,8 @@ public final class ScmPublisher {
   private final ScannerReportWriter writer;
   private final BranchConfiguration branchConfiguration;
 
-  public ScmPublisher(DefaultInputModule inputModule, ScmConfiguration configuration, ProjectRepositories projectRepositories,
-    ModuleInputComponentStore componentStore, DefaultModuleFileSystem fs, ReportPublisher reportPublisher, BranchConfiguration branchConfiguration) {
+  public ScmPublisher(AbstractProjectOrModule inputModule, ScmConfiguration configuration, ProjectRepositories projectRepositories,
+                      ModuleInputComponentStore componentStore, DefaultModuleFileSystem fs, ReportPublisher reportPublisher, BranchConfiguration branchConfiguration) {
     this.inputModule = inputModule;
     this.configuration = configuration;
     this.projectRepositories = projectRepositories;
@@ -121,7 +121,7 @@ public final class ScmPublisher {
 
   private static void askToCopyDataFromPreviousAnalysis(DefaultInputFile f, ScannerReportWriter writer) {
     Builder scmBuilder = ScannerReport.Changesets.newBuilder();
-    scmBuilder.setComponentRef(f.batchId());
+    scmBuilder.setComponentRef(f.scannerId());
     scmBuilder.setCopyFromPrevious(true);
     writer.writeComponentChangesets(scmBuilder.build());
   }
index ed8640d773223f245cead3f1f7ce4e84a7d4144d..a151e90c60cacb1012151e49ce2a6aad1b3b9fa7 100644 (file)
@@ -27,7 +27,7 @@ import org.sonar.api.batch.fs.FileSystem;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.InputModule;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.batch.rule.ActiveRules;
 import org.sonar.api.batch.sensor.SensorContext;
 import org.sonar.api.batch.sensor.code.NewSignificantCode;
@@ -52,6 +52,7 @@ import org.sonar.api.batch.sensor.symbol.NewSymbolTable;
 import org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable;
 import org.sonar.api.config.Configuration;
 import org.sonar.api.config.Settings;
+import org.sonar.api.scanner.fs.InputProject;
 import org.sonar.api.utils.Version;
 import org.sonar.scanner.sensor.noop.NoOpNewAdHocRule;
 import org.sonar.scanner.sensor.noop.NoOpNewAnalysisError;
@@ -77,13 +78,14 @@ public class DefaultSensorContext implements SensorContext {
   private final ActiveRules activeRules;
   private final SensorStorage sensorStorage;
   private final AnalysisMode analysisMode;
+  private final DefaultInputProject project;
   private final InputModule module;
   private final SonarRuntime sonarRuntime;
   private final Configuration config;
-  private final InputModuleHierarchy hierarchy;
 
-  public DefaultSensorContext(InputModule module, Configuration config, Settings mutableSettings, FileSystem fs, ActiveRules activeRules,
-    AnalysisMode analysisMode, SensorStorage sensorStorage, SonarRuntime sonarRuntime, InputModuleHierarchy hierarchy) {
+  public DefaultSensorContext(DefaultInputProject project, InputModule module, Configuration config, Settings mutableSettings, FileSystem fs, ActiveRules activeRules,
+                              AnalysisMode analysisMode, SensorStorage sensorStorage, SonarRuntime sonarRuntime) {
+    this.project = project;
     this.module = module;
     this.config = config;
     this.mutableSettings = mutableSettings;
@@ -92,7 +94,6 @@ public class DefaultSensorContext implements SensorContext {
     this.analysisMode = analysisMode;
     this.sensorStorage = sensorStorage;
     this.sonarRuntime = sonarRuntime;
-    this.hierarchy = hierarchy;
   }
 
   @Override
@@ -120,6 +121,11 @@ public class DefaultSensorContext implements SensorContext {
     return module;
   }
 
+  @Override
+  public InputProject project() {
+    return project;
+  }
+
   @Override
   public Version getSonarQubeVersion() {
     return sonarRuntime.getApiVersion();
@@ -137,7 +143,7 @@ public class DefaultSensorContext implements SensorContext {
 
   @Override
   public NewIssue newIssue() {
-    return new DefaultIssue(hierarchy.root(), sensorStorage);
+    return new DefaultIssue(project, sensorStorage);
   }
 
   @Override
@@ -145,7 +151,7 @@ public class DefaultSensorContext implements SensorContext {
     if (analysisMode.isIssues()) {
       return NO_OP_NEW_EXTERNAL_ISSUE;
     }
-    return new DefaultExternalIssue(hierarchy.root(), sensorStorage);
+    return new DefaultExternalIssue(project, sensorStorage);
   }
 
   @Override
index 15d65de1e79426e0ca85dc186e2fd698833ce51c..e4f447fffd8264f2d25c2fc3331ba3bb23f82715 100644 (file)
@@ -424,7 +424,7 @@ public class DefaultSensorStorage implements SensorStorage {
       return;
     }
     inputFile.setPublished(true);
-    int componentRef = inputFile.batchId();
+    int componentRef = inputFile.scannerId();
     if (writer.hasComponentData(FileStructure.Domain.SYNTAX_HIGHLIGHTINGS, componentRef)) {
       throw new UnsupportedOperationException("Trying to save highlighting twice for the same file is not supported: " + inputFile);
     }
@@ -452,7 +452,7 @@ public class DefaultSensorStorage implements SensorStorage {
       return;
     }
     inputFile.setPublished(true);
-    int componentRef = inputFile.batchId();
+    int componentRef = inputFile.scannerId();
     if (writer.hasComponentData(FileStructure.Domain.SYMBOLS, componentRef)) {
       throw new UnsupportedOperationException("Trying to save symbol table twice for the same file is not supported: " + symbolTable.inputFile());
     }
@@ -550,7 +550,7 @@ public class DefaultSensorStorage implements SensorStorage {
       return;
     }
     inputFile.setPublished(true);
-    int componentRef = inputFile.batchId();
+    int componentRef = inputFile.scannerId();
     if (writer.hasComponentData(FileStructure.Domain.SGNIFICANT_CODE, componentRef)) {
       throw new UnsupportedOperationException(
         "Trying to save significant code information twice for the same file is not supported: " + significantCode.inputFile());
index 3c645a9c731e8254fc3f2d491dab1485c8a10368..87e70a4bf8f7e7620e0d36a37690079e60e98e41 100644 (file)
@@ -21,14 +21,12 @@ package org.sonar.scanner.sensor;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.sonar.api.batch.ScannerSide;
 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.Configuration;
 
-@ScannerSide
 public class SensorOptimizer {
 
   private static final Logger LOG = LoggerFactory.getLogger(SensorOptimizer.class);
index a598a77e2624a9b8ff78d3e830f4e863e6966b2f..7779529c67fc72362907c8c1326e24cfb8a85361 100644 (file)
@@ -35,6 +35,9 @@ public class SensorWrapper {
     this.context = context;
     this.descriptor = new DefaultSensorDescriptor();
     newSensor.describe(this.descriptor);
+    if (descriptor.name() == null) {
+      descriptor.name(newSensor.getClass().getName());
+    }
   }
 
   public boolean shouldExecute() {
@@ -51,11 +54,7 @@ public class SensorWrapper {
 
   @Override
   public String toString() {
-    if (descriptor.name() != null) {
-      return descriptor.name();
-    } else {
-      return wrappedSensor.getClass().getName();
-    }
+    return descriptor.name();
   }
 
   public boolean isGlobal() {
index f40695073792b788ed331535d6ae9e5129a6f689..75fa6f856df30ce88f6ccc7230202740a90fbfea 100644 (file)
@@ -23,7 +23,6 @@ import org.sonar.api.CoreProperties;
 import org.sonar.api.task.Task;
 import org.sonar.api.task.TaskDefinition;
 import org.sonar.core.platform.ComponentContainer;
-import org.sonar.scanner.analysis.AnalysisProperties;
 import org.sonar.scanner.scan.ProjectScanContainer;
 
 public class ScanTask implements Task {
@@ -34,17 +33,13 @@ public class ScanTask implements Task {
     .build();
 
   private final ComponentContainer taskContainer;
-  private final TaskProperties taskProps;
 
-  public ScanTask(TaskContainer taskContainer, TaskProperties taskProps) {
+  public ScanTask(TaskContainer taskContainer) {
     this.taskContainer = taskContainer;
-    this.taskProps = taskProps;
   }
 
   @Override
   public void execute() {
-    AnalysisProperties props = new AnalysisProperties(taskProps.properties(), taskProps.property(CoreProperties.ENCRYPTION_SECRET_KEY_PATH));
-    ProjectScanContainer scanContainer = new ProjectScanContainer(taskContainer, props);
-    scanContainer.execute();
+    new ProjectScanContainer(taskContainer).execute();
   }
 }
index 22e8d58b95e48f8bc3ebc6df8ca99d35eeaea0ef..6bea86a731d751de1fd0b2e5958e682f57269d07 100644 (file)
@@ -30,7 +30,6 @@ import org.sonar.api.utils.log.Loggers;
 import org.sonar.core.extension.CoreExtensionsInstaller;
 import org.sonar.core.platform.ComponentContainer;
 import org.sonar.scanner.bootstrap.ExtensionInstaller;
-import org.sonar.scanner.bootstrap.GlobalProperties;
 
 import static org.sonar.api.batch.InstantiationStrategy.PER_TASK;
 import static org.sonar.core.extension.CoreExtensionsInstaller.noExtensionFilter;
@@ -53,16 +52,11 @@ public class TaskContainer extends ComponentContainer {
   @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)));
-  }
-
   private void addTaskExtensions() {
     getComponentByType(CoreExtensionsInstaller.class)
       .install(this, noExtensionFilter(), t -> isInstantiationStrategy(t, PER_TASK));
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/task/TaskProperties.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/task/TaskProperties.java
deleted file mode 100644 (file)
index cf363c6..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.scanner.task;
-
-import java.util.Map;
-import javax.annotation.Nullable;
-import org.sonar.scanner.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<String, String> properties, @Nullable String pathToSecretKey) {
-    super(properties, pathToSecretKey);
-  }
-
-}
index 59f8506ef14fcca3e50ee946979f3bd1b24608cc..27fa806da8b2e4b3789f23ef7269fdc501e3b748 100644 (file)
@@ -42,29 +42,13 @@ public class LoggingConfigurationTest {
 
   @Test
   public void testSetVerboseAnalysis() {
-    Map<String, String> globalProps = Maps.newHashMap();
-    LoggingConfiguration conf = new LoggingConfiguration(null).setProperties(globalProps);
+    Map<String, String> props = Maps.newHashMap();
+    LoggingConfiguration conf = new LoggingConfiguration(null).setProperties(props);
     assertThat(conf.getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_ROOT_DEFAULT);
 
-    Map<String, String> analysisProperties = Maps.newHashMap();
-    analysisProperties.put("sonar.verbose", "true");
-
-    conf.setProperties(analysisProperties, globalProps);
-    assertThat(conf.getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_ROOT_VERBOSE);
-  }
-
-  @Test
-  public void testOverrideVerbose() {
-    Map<String, String> globalProps = Maps.newHashMap();
-    globalProps.put("sonar.verbose", "true");
-    LoggingConfiguration conf = new LoggingConfiguration(null).setProperties(globalProps);
+    props.put("sonar.verbose", "true");
+    conf.setProperties(props);
     assertThat(conf.getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_ROOT_VERBOSE);
-
-    Map<String, String> analysisProperties = Maps.newHashMap();
-    analysisProperties.put("sonar.verbose", "false");
-
-    conf.setProperties(analysisProperties, globalProps);
-    assertThat(conf.getSubstitutionVariable(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_ROOT_DEFAULT);
   }
 
   @Test
index f15c15cefed71364441a986190bfe8cb2513d3b0..df848a5600689839c63ded9c508a5ad027092d26 100644 (file)
@@ -25,8 +25,7 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
-import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.utils.TempFolder;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -39,22 +38,19 @@ public class AnalysisTempFolderProviderTest {
   public TemporaryFolder temp = new TemporaryFolder();
 
   private AnalysisTempFolderProvider tempFolderProvider;
-  private InputModuleHierarchy moduleHierarchy;
+  DefaultInputProject project = mock(DefaultInputProject.class);
 
   @Before
   public void setUp() {
     tempFolderProvider = new AnalysisTempFolderProvider();
-    moduleHierarchy = mock(InputModuleHierarchy.class);
-    DefaultInputModule module = mock(DefaultInputModule.class);
-    when(moduleHierarchy.root()).thenReturn(module);
-    when(module.getWorkDir()).thenReturn(temp.getRoot().toPath());
+    when(project.getWorkDir()).thenReturn(temp.getRoot().toPath());
   }
 
   @Test
   public void createTempFolder() throws IOException {
     File defaultDir = new File(temp.getRoot(), AnalysisTempFolderProvider.TMP_NAME);
 
-    TempFolder tempFolder = tempFolderProvider.provide(moduleHierarchy);
+    TempFolder tempFolder = tempFolderProvider.provide(project);
     tempFolder.newDir();
     tempFolder.newFile();
     assertThat(defaultDir).exists();
index baae5badf2b0f4165a5fc4499ea778b40a28a059..19be5a48378037ea74ae8a7ec63eb8e54d6e4337 100644 (file)
@@ -25,6 +25,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
+import org.sonar.scanner.bootstrap.ScannerProperties;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
@@ -43,7 +44,7 @@ public class DefaultAnalysisModeTest {
 
   @Test
   public void scan_all_even_on_short_lived_branch() {
-    AnalysisProperties analysisProps = new AnalysisProperties(Collections.singletonMap("sonar.scanAllFiles", "true"));
+    ScannerProperties analysisProps = new ScannerProperties(Collections.singletonMap("sonar.scanAllFiles", "true"));
     DefaultAnalysisMode mode = createmode(analysisProps);
 
     assertThat(mode.scanAllFiles()).isTrue();
@@ -54,7 +55,7 @@ public class DefaultAnalysisModeTest {
     when(globalMode.isIssues()).thenReturn(true);
     when(globalMode.isPublish()).thenReturn(true);
     when(globalMode.isPreview()).thenReturn(true);
-    DefaultAnalysisMode mode = createmode(new AnalysisProperties(Collections.emptyMap()));
+    DefaultAnalysisMode mode = createmode(new ScannerProperties(Collections.emptyMap()));
 
     assertThat(mode.isIssues()).isTrue();
     assertThat(mode.isPublish()).isTrue();
@@ -64,14 +65,14 @@ public class DefaultAnalysisModeTest {
   @Test
   public void scan_all_if_publish() {
     when(globalMode.isIssues()).thenReturn(false);
-    DefaultAnalysisMode mode = createmode(new AnalysisProperties(Collections.emptyMap()));
+    DefaultAnalysisMode mode = createmode(new ScannerProperties(Collections.emptyMap()));
 
     assertThat(mode.scanAllFiles()).isTrue();
   }
 
   @Test
   public void scan_all_if_property_set() {
-    AnalysisProperties analysisProps = new AnalysisProperties(Collections.singletonMap("sonar.scanAllFiles", "true"));
+    ScannerProperties analysisProps = new ScannerProperties(Collections.singletonMap("sonar.scanAllFiles", "true"));
     DefaultAnalysisMode mode = createmode(analysisProps);
 
     assertThat(mode.scanAllFiles()).isTrue();
@@ -80,12 +81,12 @@ public class DefaultAnalysisModeTest {
   @Test
   public void dont_scan_all_if_issues_mode() {
     when(globalMode.isIssues()).thenReturn(true);
-    DefaultAnalysisMode mode = createmode(new AnalysisProperties(Collections.emptyMap()));
+    DefaultAnalysisMode mode = createmode(new ScannerProperties(Collections.emptyMap()));
 
     assertThat(mode.scanAllFiles()).isFalse();
   }
 
-  private DefaultAnalysisMode createmode(AnalysisProperties analysisProps) {
+  private DefaultAnalysisMode createmode(ScannerProperties analysisProps) {
     return new DefaultAnalysisMode(analysisProps, globalMode);
   }
 
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/DroppedPropertyCheckerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/DroppedPropertyCheckerTest.java
deleted file mode 100644 (file)
index 127d8b6..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.scanner.bootstrap;
-
-import com.google.common.collect.ImmutableMap;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.api.utils.log.LogTester;
-import org.sonar.api.utils.log.LoggerLevel;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class DroppedPropertyCheckerTest {
-  private static final String SOME_VALUE = "some value";
-  private static final String DROPPED_PROPERTY_1 = "I'm dropped";
-  private static final String DROPPED_PROPERTY_MSG_1 = "blablabla!";
-
-  @Rule
-  public LogTester logTester = new LogTester();
-
-  @Test
-  public void no_log_if_no_dropped_property() {
-    new DroppedPropertyChecker(ImmutableMap.of(DROPPED_PROPERTY_1, SOME_VALUE), ImmutableMap.<String, String>of()).checkDroppedProperties();
-
-    assertThat(logTester.logs()).isEmpty();
-  }
-
-  @Test
-  public void no_log_if_settings_does_not_contain_any_dropped_property() {
-    new DroppedPropertyChecker(ImmutableMap.<String, String>of(), ImmutableMap.of(DROPPED_PROPERTY_1, DROPPED_PROPERTY_MSG_1)).checkDroppedProperties();
-
-    assertThat(logTester.logs()).isEmpty();
-  }
-
-  @Test
-  public void warn_log_if_settings_contains_any_dropped_property() {
-    new DroppedPropertyChecker(ImmutableMap.of(DROPPED_PROPERTY_1, SOME_VALUE), ImmutableMap.of(DROPPED_PROPERTY_1, DROPPED_PROPERTY_MSG_1)).checkDroppedProperties();
-
-    assertThat(logTester.logs(LoggerLevel.ERROR)).isEmpty();
-    assertThat(logTester.logs(LoggerLevel.WARN)).containsOnly("Property '" + DROPPED_PROPERTY_1 + "' is not supported any more. " + DROPPED_PROPERTY_MSG_1);
-    assertThat(logTester.logs(LoggerLevel.INFO)).isEmpty();
-    assertThat(logTester.logs(LoggerLevel.DEBUG)).isEmpty();
-    assertThat(logTester.logs(LoggerLevel.TRACE)).isEmpty();
-  }
-}
index f9ec043062cbcf9c65c2b33d5ab180485d6003ad..306712ef9982e70363e03b9715fa5c32cc360575 100644 (file)
@@ -82,7 +82,7 @@ public class GlobalAnalysisModeTest {
     if (key != null) {
       map.put(key, value);
     }
-    GlobalProperties props = new GlobalProperties(map);
+    ScannerProperties props = new ScannerProperties(map);
     return new GlobalAnalysisMode(props);
   }
 }
index 1047bd3044d93224e74dac95f33a305f118ec7bd..0799d8b049ee413a1041a94f47ef7d44e42638cf 100644 (file)
@@ -27,8 +27,6 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.api.config.PropertyDefinitions;
 import org.sonar.api.utils.log.LogTester;
-import org.sonar.api.utils.log.LoggerLevel;
-import org.sonar.scanner.repository.settings.SettingsLoader;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
@@ -42,38 +40,24 @@ public class GlobalConfigurationProviderTest {
   @Rule
   public LogTester logTester = new LogTester();
 
-  SettingsLoader settingsLoader;
-  GlobalProperties bootstrapProps;
+  GlobalServerSettings globalServerSettings;
+  ScannerProperties scannerProps;
 
   private GlobalAnalysisMode mode;
 
   @Before
   public void prepare() {
-    settingsLoader = mock(SettingsLoader.class);
-    bootstrapProps = new GlobalProperties(Collections.<String, String>emptyMap());
+    globalServerSettings = mock(GlobalServerSettings.class);
+    scannerProps = new ScannerProperties(Collections.<String, String>emptyMap());
     mode = mock(GlobalAnalysisMode.class);
   }
 
   @Test
   public void should_load_global_settings() {
-    when(settingsLoader.load(null)).thenReturn(ImmutableMap.of("sonar.cpd.cross", "true"));
+    when(globalServerSettings.properties()).thenReturn(ImmutableMap.of("sonar.cpd.cross", "true"));
 
-    GlobalConfiguration globalConfig = new GlobalConfigurationProvider().provide(settingsLoader, bootstrapProps, new PropertyDefinitions(), mode);
+    GlobalConfiguration globalConfig = new GlobalConfigurationProvider().provide(globalServerSettings, scannerProps, new PropertyDefinitions(), mode);
 
     assertThat(globalConfig.get("sonar.cpd.cross")).hasValue("true");
   }
-
-  @Test
-  public void should_log_warn_msg_for_each_jdbc_property_if_present() {
-    when(settingsLoader.load(null)).thenReturn(ImmutableMap.of("sonar.jdbc.url", SOME_VALUE,
-      "sonar.jdbc.username", SOME_VALUE,
-      "sonar.jdbc.password", SOME_VALUE));
-
-    new GlobalConfigurationProvider().provide(settingsLoader, bootstrapProps, new PropertyDefinitions(), mode);
-
-    assertThat(logTester.logs(LoggerLevel.WARN)).containsOnly(
-      "Property 'sonar.jdbc.url' is not supported any more. It will be ignored. There is no longer any DB connection to the SQ database.",
-      "Property 'sonar.jdbc.username' is not supported any more. It will be ignored. There is no longer any DB connection to the SQ database.",
-      "Property 'sonar.jdbc.password' is not supported any more. It will be ignored. There is no longer any DB connection to the SQ database.");
-  }
 }
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalPropertiesTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalPropertiesTest.java
deleted file mode 100644 (file)
index 5cd8fe5..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.scanner.bootstrap;
-
-import com.google.common.collect.Maps;
-import java.util.Map;
-import org.junit.Test;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.entry;
-
-public class GlobalPropertiesTest {
-  @Test
-  public void test_copy_of_properties() {
-    Map<String, String> map = Maps.newHashMap();
-    map.put("foo", "bar");
-
-    GlobalProperties wrapper = new GlobalProperties(map);
-    assertThat(wrapper.properties()).containsOnly(entry("foo", "bar"));
-    assertThat(wrapper.properties()).isNotSameAs(map);
-
-    map.put("put", "after_copy");
-    assertThat(wrapper.properties()).hasSize(1);
-  }
-}
index b4b34bd76f912d20ef6422024653177a3837d8a5..3583ac85f34f43ae632870abce0fc1f6d44c2dbb 100644 (file)
@@ -51,7 +51,7 @@ public class GlobalTempFolderProviderTest {
     File workingDir = temp.newFolder();
     workingDir.delete();
 
-    TempFolder tempFolder = tempFolderProvider.provide(new GlobalProperties(ImmutableMap.of(CoreProperties.GLOBAL_WORKING_DIRECTORY, workingDir.getAbsolutePath())));
+    TempFolder tempFolder = tempFolderProvider.provide(new ScannerProperties(ImmutableMap.of(CoreProperties.GLOBAL_WORKING_DIRECTORY, workingDir.getAbsolutePath())));
     tempFolder.newDir();
     tempFolder.newFile();
     assertThat(getCreatedTempDir(workingDir)).exists();
@@ -71,7 +71,7 @@ public class GlobalTempFolderProviderTest {
       setFileCreationDate(tmp, creationTime);
     }
 
-    tempFolderProvider.provide(new GlobalProperties(ImmutableMap.of(CoreProperties.GLOBAL_WORKING_DIRECTORY, workingDir.getAbsolutePath())));
+    tempFolderProvider.provide(new ScannerProperties(ImmutableMap.of(CoreProperties.GLOBAL_WORKING_DIRECTORY, workingDir.getAbsolutePath())));
     // this also checks that all other temps were deleted
     assertThat(getCreatedTempDir(workingDir)).exists();
 
@@ -84,7 +84,7 @@ public class GlobalTempFolderProviderTest {
     File sonarHome = temp.newFolder();
     File workingDir = new File(sonarHome, CoreProperties.GLOBAL_WORKING_DIRECTORY_DEFAULT_VALUE).getAbsoluteFile();
 
-    TempFolder tempFolder = tempFolderProvider.provide(new GlobalProperties(ImmutableMap.of("sonar.userHome", sonarHome.getAbsolutePath())));
+    TempFolder tempFolder = tempFolderProvider.provide(new ScannerProperties(ImmutableMap.of("sonar.userHome", sonarHome.getAbsolutePath())));
     tempFolder.newDir();
     tempFolder.newFile();
     assertThat(getCreatedTempDir(workingDir)).exists();
@@ -106,7 +106,7 @@ public class GlobalTempFolderProviderTest {
     File defaultSonarHome = new File(userHome.getAbsolutePath(), ".sonar");
     File workingDir = new File(defaultSonarHome, CoreProperties.GLOBAL_WORKING_DIRECTORY_DEFAULT_VALUE).getAbsoluteFile();
     try {
-      TempFolder tempFolder = tempFolderProvider.provide(new GlobalProperties(Collections.<String, String>emptyMap()));
+      TempFolder tempFolder = tempFolderProvider.provide(new ScannerProperties(Collections.<String, String>emptyMap()));
       tempFolder.newDir();
       tempFolder.newFile();
       assertThat(getCreatedTempDir(workingDir)).exists();
@@ -120,7 +120,7 @@ public class GlobalTempFolderProviderTest {
   public void dotWorkingDir() throws IOException {
     File sonarHome = temp.getRoot();
     String globalWorkDir = ".";
-    GlobalProperties globalProperties = new GlobalProperties(ImmutableMap.of("sonar.userHome", sonarHome.getAbsolutePath(),
+    ScannerProperties globalProperties = new ScannerProperties(ImmutableMap.of("sonar.userHome", sonarHome.getAbsolutePath(),
       CoreProperties.GLOBAL_WORKING_DIRECTORY, globalWorkDir));
 
     TempFolder tempFolder = tempFolderProvider.provide(globalProperties);
@@ -136,7 +136,7 @@ public class GlobalTempFolderProviderTest {
     File symlink = temp.newFolder();
     symlink.delete();
     Files.createSymbolicLink(symlink.toPath(), realSonarHome.toPath());
-    GlobalProperties globalProperties = new GlobalProperties(ImmutableMap.of("sonar.userHome", symlink.getAbsolutePath()));
+    ScannerProperties globalProperties = new ScannerProperties(ImmutableMap.of("sonar.userHome", symlink.getAbsolutePath()));
 
     TempFolder tempFolder = tempFolderProvider.provide(globalProperties);
     File newFile = tempFolder.newFile();
index 2c449a535b37bbb3264dd35b120889ac7e36e7be..f63d60f14bb08c56789f07af382dea664e8aaa01 100644 (file)
@@ -73,7 +73,7 @@ public class PluginFilesTest {
   @Before
   public void setUp() throws Exception {
     HttpConnector connector = HttpConnector.newBuilder().url(server.url("/").toString()).build();
-    GlobalAnalysisMode analysisMode = new GlobalAnalysisMode(new GlobalProperties(Collections.emptyMap()));
+    GlobalAnalysisMode analysisMode = new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap()));
     ScannerWsClient wsClient = new ScannerWsClient(WsClientFactories.getDefault().newClient(connector), false, analysisMode);
 
     userHome = temp.newFolder();
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPropertiesTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPropertiesTest.java
new file mode 100644 (file)
index 0000000..670f0b0
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.scanner.bootstrap;
+
+import com.google.common.collect.Maps;
+import java.util.Map;
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.entry;
+
+public class ScannerPropertiesTest {
+  @Test
+  public void test_copy_of_properties() {
+    Map<String, String> map = Maps.newHashMap();
+    map.put("foo", "bar");
+
+    ScannerProperties underTest = new ScannerProperties(map);
+    assertThat(underTest.properties()).containsOnly(entry("foo", "bar"));
+    assertThat(underTest.properties()).isNotSameAs(map);
+
+    map.put("put", "after_copy");
+    assertThat(underTest.properties()).hasSize(1);
+  }
+}
index 804107b7886e4aa124cf6ce6e90ec817fedb3bef..9e4511cc48b7c11e7ade826fd64b3b372fbe5895 100644 (file)
@@ -37,9 +37,9 @@ public class ScannerWsClientProviderTest {
 
   @Test
   public void provide_client_with_default_settings() {
-    GlobalProperties settings = new GlobalProperties(new HashMap<>());
+    ScannerProperties settings = new ScannerProperties(new HashMap<>());
 
-    ScannerWsClient client = underTest.provide(settings, env, new GlobalAnalysisMode(new GlobalProperties(Collections.emptyMap())), mock(System2.class));
+    ScannerWsClient client = underTest.provide(settings, env, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap())), mock(System2.class));
 
     assertThat(client).isNotNull();
     assertThat(client.baseUrl()).isEqualTo("http://localhost:9000/");
@@ -57,9 +57,9 @@ public class ScannerWsClientProviderTest {
     props.put("sonar.login", "theLogin");
     props.put("sonar.password", "thePassword");
     props.put("sonar.ws.timeout", "42");
-    GlobalProperties settings = new GlobalProperties(props);
+    ScannerProperties settings = new ScannerProperties(props);
 
-    ScannerWsClient client = underTest.provide(settings, env, new GlobalAnalysisMode(new GlobalProperties(Collections.emptyMap())), mock(System2.class));
+    ScannerWsClient client = underTest.provide(settings, env, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap())), mock(System2.class));
 
     assertThat(client).isNotNull();
     HttpConnector httpConnector = (HttpConnector) client.wsConnector();
@@ -71,9 +71,9 @@ public class ScannerWsClientProviderTest {
   public void build_singleton() {
     System2 system = mock(System2.class);
 
-    GlobalProperties settings = new GlobalProperties(new HashMap<>());
-    ScannerWsClient first = underTest.provide(settings, env, new GlobalAnalysisMode(new GlobalProperties(Collections.emptyMap())), system);
-    ScannerWsClient second = underTest.provide(settings, env, new GlobalAnalysisMode(new GlobalProperties(Collections.emptyMap())), system);
+    ScannerProperties settings = new ScannerProperties(new HashMap<>());
+    ScannerWsClient first = underTest.provide(settings, env, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap())), system);
+    ScannerWsClient second = underTest.provide(settings, env, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap())), system);
     assertThat(first).isSameAs(second);
   }
 }
index 51339135a508eeab694553cb5cb1e2a007f5e220..8fcdeb5160ed873d2df53a4a9b3441566b1770c2 100644 (file)
@@ -57,7 +57,7 @@ public class ScannerWsClientTest {
     when(wsClient.wsConnector().call(request)).thenReturn(response);
 
     logTester.setLevel(LoggerLevel.DEBUG);
-    ScannerWsClient underTest = new ScannerWsClient(wsClient, false, new GlobalAnalysisMode(new GlobalProperties(Collections.emptyMap())));
+    ScannerWsClient underTest = new ScannerWsClient(wsClient, false, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap())));
 
     WsResponse result = underTest.call(request);
 
@@ -98,7 +98,7 @@ public class ScannerWsClientTest {
     WsResponse response = newResponse().setCode(401);
     when(wsClient.wsConnector().call(request)).thenReturn(response);
 
-    new ScannerWsClient(wsClient, false, new GlobalAnalysisMode(new GlobalProperties(Collections.emptyMap()))).call(request);
+    new ScannerWsClient(wsClient, false, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap()))).call(request);
   }
 
   @Test
@@ -110,7 +110,7 @@ public class ScannerWsClientTest {
     WsResponse response = newResponse().setCode(401);
     when(wsClient.wsConnector().call(request)).thenReturn(response);
 
-    new ScannerWsClient(wsClient, /* credentials are configured */true, new GlobalAnalysisMode(new GlobalProperties(Collections.emptyMap()))).call(request);
+    new ScannerWsClient(wsClient, /* credentials are configured */true, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap()))).call(request);
   }
 
   @Test
@@ -124,7 +124,7 @@ public class ScannerWsClientTest {
       .setContent("{\"errors\":[{\"msg\":\"missing scan permission\"}, {\"msg\":\"missing another permission\"}]}");
     when(wsClient.wsConnector().call(request)).thenReturn(response);
 
-    new ScannerWsClient(wsClient, true, new GlobalAnalysisMode(new GlobalProperties(Collections.emptyMap()))).call(request);
+    new ScannerWsClient(wsClient, true, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap()))).call(request);
   }
 
   @Test
@@ -138,7 +138,7 @@ public class ScannerWsClientTest {
       .setContent("{\"errors\":[{\"msg\":\"Boo! bad request! bad!\"}]}");
     when(wsClient.wsConnector().call(request)).thenReturn(response);
 
-    new ScannerWsClient(wsClient, true, new GlobalAnalysisMode(new GlobalProperties(Collections.emptyMap()))).call(request);
+    new ScannerWsClient(wsClient, true, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap()))).call(request);
   }
 
   private MockWsResponse newResponse() {
index 0945eac401436eab051e47fee251903f303a903a..611e42c779395f65ee175caf1f44993a477e4037 100644 (file)
@@ -37,7 +37,7 @@ import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
 import org.mockito.ArgumentMatchers;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
 import org.sonar.api.utils.log.LogTester;
 import org.sonar.api.utils.log.LoggerLevel;
@@ -89,8 +89,8 @@ public class CpdExecutorTest {
     baseDir = temp.newFolder();
     when(publisher.getWriter()).thenReturn(new ScannerReportWriter(outputDir));
 
-    DefaultInputModule inputModule = TestInputFileBuilder.newDefaultInputModule("foo", baseDir);
-    componentStore = new InputComponentStore(inputModule, mock(BranchConfiguration.class));
+    DefaultInputProject project = TestInputFileBuilder.newDefaultInputProject("foo", baseDir);
+    componentStore = new InputComponentStore(project, mock(BranchConfiguration.class));
     executor = new CpdExecutor(settings, index, publisher, componentStore, executorService);
     reader = new ScannerReportReader(outputDir);
 
@@ -102,7 +102,7 @@ public class CpdExecutorTest {
   @Test
   public void dont_fail_if_nothing_to_save() {
     executor.saveDuplications(batchComponent1, Collections.<CloneGroup>emptyList());
-    assertThat(reader.readComponentDuplications(batchComponent1.batchId())).hasSize(0);
+    assertThat(reader.readComponentDuplications(batchComponent1.scannerId())).hasSize(0);
   }
 
   @Test
@@ -114,7 +114,7 @@ public class CpdExecutorTest {
     executor.saveDuplications(batchComponent1, groups);
 
     Duplication[] dups = readDuplications(1);
-    assertDuplication(dups[0], 2, 4, batchComponent2.batchId(), 15, 17);
+    assertDuplication(dups[0], 2, 4, batchComponent2.scannerId(), 15, 17);
   }
 
   @Test
@@ -157,7 +157,7 @@ public class CpdExecutorTest {
     }
     executor.saveDuplications(batchComponent1, dups);
 
-    assertThat(reader.readComponentDuplications(batchComponent1.batchId())).hasSize(CpdExecutor.MAX_CLONE_GROUP_PER_FILE);
+    assertThat(reader.readComponentDuplications(batchComponent1.scannerId())).hasSize(CpdExecutor.MAX_CLONE_GROUP_PER_FILE);
 
     assertThat(logTester.logs(LoggerLevel.WARN))
       .contains("Too many duplication groups on file " + batchComponent1 + ". Keep only the first " + CpdExecutor.MAX_CLONE_GROUP_PER_FILE + " groups.");
@@ -173,8 +173,8 @@ public class CpdExecutorTest {
 
     Duplication[] dups = readDuplications(1);
     assertDuplication(dups[0], 5, 204, 2);
-    assertDuplicate(dups[0].getDuplicate(0), batchComponent2.batchId(), 15, 214);
-    assertDuplicate(dups[0].getDuplicate(1), batchComponent3.batchId(), 25, 224);
+    assertDuplicate(dups[0].getDuplicate(0), batchComponent2.scannerId(), 15, 214);
+    assertDuplicate(dups[0].getDuplicate(1), batchComponent3.scannerId(), 25, 224);
   }
 
   @Test
@@ -187,8 +187,8 @@ public class CpdExecutorTest {
     executor.saveDuplications(batchComponent1, groups);
 
     Duplication[] dups = readDuplications(2);
-    assertDuplication(dups[0], 5, 204, batchComponent2.batchId(), 15, 214);
-    assertDuplication(dups[1], 15, 214, batchComponent3.batchId(), 15, 214);
+    assertDuplication(dups[0], 5, 204, batchComponent2.scannerId(), 15, 214);
+    assertDuplication(dups[1], 15, 214, batchComponent3.scannerId(), 15, 214);
   }
 
   @Test
@@ -243,9 +243,9 @@ public class CpdExecutorTest {
   }
 
   private Duplication[] readDuplications(DefaultInputFile file, int expected) {
-    assertThat(reader.readComponentDuplications(file.batchId())).hasSize(expected);
+    assertThat(reader.readComponentDuplications(file.scannerId())).hasSize(expected);
     Duplication[] duplications = new Duplication[expected];
-    CloseableIterator<Duplication> dups = reader.readComponentDuplications(file.batchId());
+    CloseableIterator<Duplication> dups = reader.readComponentDuplications(file.scannerId());
 
     for (int i = 0; i < expected; i++) {
       duplications[i] = dups.next();
index 2a8b488ff7abc8eb51715f780dc6f75451f861e8..627114cce88c152847c14949ce833e2825c8d1ce 100644 (file)
@@ -22,8 +22,7 @@ package org.sonar.scanner.cpd;
 import java.util.Optional;
 import org.junit.Before;
 import org.junit.Test;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
-import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.config.Configuration;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -34,15 +33,13 @@ import static org.mockito.Mockito.when;
 public class CpdSettingsTest {
   private CpdSettings cpdSettings;
   private Configuration configuration;
-  private DefaultInputModule module;
+  private DefaultInputProject project;
 
   @Before
   public void setUp() {
-    module = mock(DefaultInputModule.class);
-    InputModuleHierarchy hierarchy = mock(InputModuleHierarchy.class);
-    when(hierarchy.root()).thenReturn(module);
+    project = mock(DefaultInputProject.class);
     configuration = mock(Configuration.class);
-    cpdSettings = new CpdSettings(configuration, hierarchy);
+    cpdSettings = new CpdSettings(configuration, project);
   }
 
   @Test
index d8c39b19e715dd171799f4cc12747a8982d18dcc..071f57834379214da5b097f2c860ae6829ff06e4 100644 (file)
@@ -28,8 +28,8 @@ import org.junit.BeforeClass;
 import org.junit.ClassRule;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.CoreProperties;
-import org.sonar.scanner.bootstrap.GlobalProperties;
 import org.sonar.scanner.bootstrap.GlobalTempFolderProvider;
+import org.sonar.scanner.bootstrap.ScannerProperties;
 import org.sonar.scanner.storage.Storages;
 import org.sonar.scanner.storage.StoragesManager;
 
@@ -44,7 +44,7 @@ public abstract class AbstractCachesTest {
     Map<String, String> props = ImmutableMap.of(CoreProperties.WORKING_DIRECTORY, temp.getRoot().getAbsolutePath(),
       CoreProperties.GLOBAL_WORKING_DIRECTORY, temp.getRoot().getAbsolutePath());
 
-    return new StoragesManager(new GlobalTempFolderProvider().provide(new GlobalProperties(props)));
+    return new StoragesManager(new GlobalTempFolderProvider().provide(new ScannerProperties(props)));
   }
 
   @BeforeClass
index f001bfc555d79ce51670eb39d5dc275c3850c059..c82cd46675674005fbd8a2ecd924e66a22df3ec5 100644 (file)
@@ -32,7 +32,7 @@ import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
 import org.sonar.api.batch.rule.internal.ActiveRulesBuilder;
 import org.sonar.api.batch.rule.internal.NewActiveRule;
@@ -63,7 +63,7 @@ public class ModuleIssuesTest {
   static final String SQUID_RULE_NAME = "Avoid Cycle";
   private static final RuleKey NOSONAR_RULE_KEY = RuleKey.of("squid", "NoSonarCheck");
 
-  private DefaultInputModule projectRoot;
+  private DefaultInputProject project;
 
   @Rule
   public TemporaryFolder temp = new TemporaryFolder();
@@ -81,7 +81,7 @@ public class ModuleIssuesTest {
 
   @Before
   public void prepare() throws IOException {
-    projectRoot = new DefaultInputModule(ProjectDefinition.create()
+    project = new DefaultInputProject(ProjectDefinition.create()
       .setKey("foo")
       .setBaseDir(temp.newFolder())
       .setWorkDir(temp.newFolder()));
@@ -91,7 +91,7 @@ public class ModuleIssuesTest {
   public void ignore_null_active_rule() {
     ruleBuilder.add(SQUID_RULE_KEY).setName(SQUID_RULE_NAME);
     initModuleIssues();
-    DefaultIssue issue = new DefaultIssue(projectRoot)
+    DefaultIssue issue = new DefaultIssue(project)
       .at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message("Foo"))
       .forRule(SQUID_RULE_KEY);
     boolean added = moduleIssues.initAndAddIssue(issue);
@@ -106,7 +106,7 @@ public class ModuleIssuesTest {
     activeRulesBuilder.addRule(new NewActiveRule.Builder().setRuleKey(SQUID_RULE_KEY).setQProfileKey("qp-1").build());
     initModuleIssues();
 
-    DefaultIssue issue = new DefaultIssue(projectRoot)
+    DefaultIssue issue = new DefaultIssue(project)
       .at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message("Foo"))
       .forRule(SQUID_RULE_KEY);
     boolean added = moduleIssues.initAndAddIssue(issue);
@@ -125,7 +125,7 @@ public class ModuleIssuesTest {
       .build());
     initModuleIssues();
 
-    DefaultIssue issue = new DefaultIssue(projectRoot)
+    DefaultIssue issue = new DefaultIssue(project)
       .at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message("Foo"))
       .forRule(SQUID_RULE_KEY)
       .overrideSeverity(org.sonar.api.batch.rule.Severity.CRITICAL);
@@ -136,7 +136,7 @@ public class ModuleIssuesTest {
 
     assertThat(added).isTrue();
     ArgumentCaptor<ScannerReport.Issue> argument = ArgumentCaptor.forClass(ScannerReport.Issue.class);
-    verify(reportPublisher.getWriter()).appendComponentIssue(eq(file.batchId()), argument.capture());
+    verify(reportPublisher.getWriter()).appendComponentIssue(eq(file.scannerId()), argument.capture());
     assertThat(argument.getValue().getSeverity()).isEqualTo(org.sonar.scanner.protocol.Constants.Severity.CRITICAL);
   }
 
@@ -145,7 +145,7 @@ public class ModuleIssuesTest {
     ruleBuilder.add(SQUID_RULE_KEY).setName(SQUID_RULE_NAME);
     initModuleIssues();
 
-    DefaultExternalIssue issue = new DefaultExternalIssue(projectRoot)
+    DefaultExternalIssue issue = new DefaultExternalIssue(project)
       .at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message("Foo"))
       .type(RuleType.BUG)
       .forRule(SQUID_RULE_KEY)
@@ -154,7 +154,7 @@ public class ModuleIssuesTest {
     moduleIssues.initAndAddExternalIssue(issue);
 
     ArgumentCaptor<ScannerReport.ExternalIssue> argument = ArgumentCaptor.forClass(ScannerReport.ExternalIssue.class);
-    verify(reportPublisher.getWriter()).appendComponentExternalIssue(eq(file.batchId()), argument.capture());
+    verify(reportPublisher.getWriter()).appendComponentExternalIssue(eq(file.scannerId()), argument.capture());
     assertThat(argument.getValue().getSeverity()).isEqualTo(org.sonar.scanner.protocol.Constants.Severity.CRITICAL);
   }
 
@@ -168,14 +168,14 @@ public class ModuleIssuesTest {
       .build());
     initModuleIssues();
 
-    DefaultIssue issue = new DefaultIssue(projectRoot)
+    DefaultIssue issue = new DefaultIssue(project)
       .at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message("Foo"))
       .forRule(SQUID_RULE_KEY);
     when(filters.accept(anyString(), any(ScannerReport.Issue.class))).thenReturn(true);
     moduleIssues.initAndAddIssue(issue);
 
     ArgumentCaptor<ScannerReport.Issue> argument = ArgumentCaptor.forClass(ScannerReport.Issue.class);
-    verify(reportPublisher.getWriter()).appendComponentIssue(eq(file.batchId()), argument.capture());
+    verify(reportPublisher.getWriter()).appendComponentIssue(eq(file.scannerId()), argument.capture());
     assertThat(argument.getValue().getSeverity()).isEqualTo(org.sonar.scanner.protocol.Constants.Severity.INFO);
   }
 
@@ -189,7 +189,7 @@ public class ModuleIssuesTest {
       .build());
     initModuleIssues();
 
-    DefaultIssue issue = new DefaultIssue(projectRoot)
+    DefaultIssue issue = new DefaultIssue(project)
       .at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message(""))
       .forRule(SQUID_RULE_KEY);
 
@@ -211,7 +211,7 @@ public class ModuleIssuesTest {
       .build());
     initModuleIssues();
 
-    DefaultIssue issue = new DefaultIssue(projectRoot)
+    DefaultIssue issue = new DefaultIssue(project)
       .at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message(""))
       .forRule(SQUID_RULE_KEY);
 
@@ -236,7 +236,7 @@ public class ModuleIssuesTest {
 
     file.noSonarAt(new HashSet<>(Collections.singletonList(3)));
 
-    DefaultIssue issue = new DefaultIssue(projectRoot)
+    DefaultIssue issue = new DefaultIssue(project)
       .at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message(""))
       .forRule(NOSONAR_RULE_KEY);
 
@@ -245,7 +245,7 @@ public class ModuleIssuesTest {
     boolean added = moduleIssues.initAndAddIssue(issue);
 
     assertThat(added).isTrue();
-    verify(reportPublisher.getWriter()).appendComponentIssue(eq(file.batchId()), any());
+    verify(reportPublisher.getWriter()).appendComponentIssue(eq(file.scannerId()), any());
   }
 
   /**
index ced3ec51d3dd5b93589955f2e572e49e1ae9e8ac..31c1c682b55a0a6ea4275240e6e0a272087e394f 100644 (file)
@@ -255,18 +255,18 @@ public class ScannerMediumTester extends ExternalResource {
     }
   }
 
-  public TaskBuilder newTask() {
-    return new TaskBuilder(this);
+  public AnalysisBuilder newAnalysis() {
+    return new AnalysisBuilder(this);
   }
 
-  public TaskBuilder newScanTask(File sonarProps) {
+  public AnalysisBuilder newAnalysis(File sonarProps) {
     Properties prop = new Properties();
     try (Reader reader = new InputStreamReader(new FileInputStream(sonarProps), StandardCharsets.UTF_8)) {
       prop.load(reader);
     } catch (Exception e) {
       throw new IllegalStateException("Unable to read configuration file", e);
     }
-    TaskBuilder builder = new TaskBuilder(this);
+    AnalysisBuilder builder = new AnalysisBuilder(this);
     builder.property("sonar.projectBaseDir", sonarProps.getParentFile().getAbsolutePath());
     for (Map.Entry<Object, Object> entry : prop.entrySet()) {
       builder.property(entry.getKey().toString(), entry.getValue().toString());
@@ -274,22 +274,22 @@ public class ScannerMediumTester extends ExternalResource {
     return builder;
   }
 
-  public static class TaskBuilder {
+  public static class AnalysisBuilder {
     private final Map<String, String> taskProperties = new HashMap<>();
     private ScannerMediumTester tester;
 
-    public TaskBuilder(ScannerMediumTester tester) {
+    public AnalysisBuilder(ScannerMediumTester tester) {
       this.tester = tester;
     }
 
-    public TaskResult execute() {
-      TaskResult result = new TaskResult();
+    public AnalysisResult execute() {
+      AnalysisResult result = new AnalysisResult();
       Map<String, String> props = new HashMap<>();
       props.putAll(tester.globalProperties);
       props.putAll(taskProperties);
 
       Batch.builder()
-        .setGlobalProperties(props)
+        .setScannerProperties(props)
         .setEnableLoggingConfiguration(true)
         .addComponents(new EnvironmentInformation("mediumTest", "1.0"),
           tester.pluginInstaller,
@@ -308,12 +308,12 @@ public class ScannerMediumTester extends ExternalResource {
       return result;
     }
 
-    public TaskBuilder properties(Map<String, String> props) {
+    public AnalysisBuilder properties(Map<String, String> props) {
       taskProperties.putAll(props);
       return this;
     }
 
-    public TaskBuilder property(String key, String value) {
+    public AnalysisBuilder property(String key, String value) {
       taskProperties.put(key, value);
       return this;
     }
index 6d669f90f8244a1a5e1657ff8d587455bd4774b1..21d88ed6f5de93bcab4b675e455fc2123240cdc6 100644 (file)
@@ -31,7 +31,7 @@ import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.fs.internal.FileMetadata;
 import org.sonar.scanner.mediumtest.ScannerMediumTester;
-import org.sonar.scanner.mediumtest.TaskResult;
+import org.sonar.scanner.mediumtest.AnalysisResult;
 import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.scanner.repository.FileData;
 import org.sonar.scanner.scan.branch.BranchType;
@@ -72,7 +72,7 @@ public class BranchMediumTest {
   @Test
   public void should_not_skip_report_for_unchanged_files_in_short_branch() {
     // sanity check, normally report gets generated
-    TaskResult result = getResult(tester);
+    AnalysisResult result = getResult(tester);
     assertThat(getResult(tester).getReportComponent(result.inputFile(FILE_PATH).key())).isNotNull();
     int fileId = 2;
     assertThat(result.getReportReader().readChangesets(fileId)).isNotNull();
@@ -80,7 +80,7 @@ public class BranchMediumTest {
     assertThat(result.getReportReader().readFileSource(fileId)).isNotNull();
 
     // file is not skipped for short branches (need coverage, duplications coming soon)
-    TaskResult result2 = getResult(tester.setBranchType(BranchType.SHORT));
+    AnalysisResult result2 = getResult(tester.setBranchType(BranchType.SHORT));
     assertThat(result2.getReportComponent(result2.inputFile(FILE_PATH).key())).isNotNull();
     assertThat(result2.getReportReader().readChangesets(fileId)).isNull();
     assertThat(result2.getReportReader().hasCoverage(fileId)).isTrue();
@@ -92,7 +92,7 @@ public class BranchMediumTest {
     String branchName = "feature";
     String branchTarget = "branch-1.x";
 
-    TaskResult result = getResult(tester
+    AnalysisResult result = getResult(tester
       .setBranchName(branchName)
       .setBranchTarget(branchTarget)
       .setLongLivingSonarReferenceBranch(branchTarget)
@@ -104,9 +104,9 @@ public class BranchMediumTest {
     assertThat(metadata.getMergeBranchName()).isEqualTo(branchTarget);
   }
 
-  private TaskResult getResult(ScannerMediumTester tester) {
+  private AnalysisResult getResult(ScannerMediumTester tester) {
     return tester
-      .newTask()
+      .newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
index 963958c28d6d6e0abd9709311b09cfd31f4b2c30..bcc46d488d4b85030eaace65fb71c22675f8532f 100644 (file)
@@ -33,7 +33,7 @@ import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.scanner.mediumtest.ScannerMediumTester;
-import org.sonar.scanner.mediumtest.TaskResult;
+import org.sonar.scanner.mediumtest.AnalysisResult;
 import org.sonar.xoo.XooPlugin;
 import org.sonar.xoo.rule.XooRulesDefinition;
 
@@ -82,7 +82,7 @@ public class DeprecatedBranchMediumTest {
     File xooFile = new File(srcDir, "sample.xoo");
     FileUtils.write(xooFile, "Sample xoo\ncontent");
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .putAll(commonProps)
         .put("sonar.branch", "branch")
@@ -93,11 +93,11 @@ public class DeprecatedBranchMediumTest {
     assertThat(result.inputFile("src/sample.xoo").key()).isEqualTo("com.foo.project:src/sample.xoo");
 
     DefaultInputFile inputfile = (DefaultInputFile) result.inputFile("src/sample.xoo");
-    assertThat(result.getReportReader().readComponent(inputfile.batchId()).getPath()).isEqualTo("src/sample.xoo");
+    assertThat(result.getReportReader().readComponent(inputfile.scannerId()).getPath()).isEqualTo("src/sample.xoo");
 
     assertThat(result.getReportReader().readMetadata().getDeprecatedBranch()).isEqualTo("branch");
 
-    result = tester.newTask()
+    result = tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .putAll(commonProps)
         .put("sonar.branch", "")
@@ -116,7 +116,7 @@ public class DeprecatedBranchMediumTest {
     File xooFile = new File(srcDir.toFile(), "sample.xoo");
     FileUtils.write(xooFile, "Sample xoo\ncontent");
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .putAll(commonProps)
         .put("sonar.branch", "branch")
@@ -129,14 +129,14 @@ public class DeprecatedBranchMediumTest {
 
     // no branch in the report
     DefaultInputFile inputfile = (DefaultInputFile) result.inputFile("moduleA/src/sample.xoo");
-    assertThat(result.getReportReader().readComponent(inputfile.batchId()).getPath()).isEqualTo("src/sample.xoo");
+    assertThat(result.getReportReader().readComponent(inputfile.scannerId()).getPath()).isEqualTo("src/sample.xoo");
 
     // no branch in InputModule's key or in report
     assertThat(result.getReportComponent("com.foo.project:moduleA").getKey()).isEqualTo("com.foo.project:moduleA");
 
     assertThat(result.getReportReader().readMetadata().getDeprecatedBranch()).isEqualTo("branch");
 
-    result = tester.newTask()
+    result = tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .putAll(commonProps)
         .put("sonar.branch", "")
index 5e1c10e6712e8973d7f1fb10d55c9d6cb40c3b85..f230f2b8bf8e03cb73dc174e29d96dbf9ad56c6a 100644 (file)
@@ -23,7 +23,6 @@ import com.google.common.collect.ImmutableMap;
 import java.io.File;
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import org.apache.commons.io.FileUtils;
@@ -32,8 +31,10 @@ import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.measures.CoreMetrics;
+import org.sonar.api.utils.log.LogTester;
+import org.sonar.api.utils.log.LoggerLevel;
 import org.sonar.scanner.mediumtest.ScannerMediumTester;
-import org.sonar.scanner.mediumtest.TaskResult;
+import org.sonar.scanner.mediumtest.AnalysisResult;
 import org.sonar.xoo.XooPlugin;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -41,14 +42,14 @@ import static org.assertj.core.api.Assertions.tuple;
 
 public class CoverageMediumTest {
 
-  private final List<String> logs = new ArrayList<>();
+  @Rule
+  public LogTester logTester = new LogTester();
 
   @Rule
   public TemporaryFolder temp = new TemporaryFolder();
 
   @Rule
   public ScannerMediumTester tester = new ScannerMediumTester()
-    .setLogOutput((msg, level) -> logs.add(msg))
     .registerPlugin("xoo", new XooPlugin())
     .addDefaultQProfile("xoo", "Sonar Way");
 
@@ -64,7 +65,7 @@ public class CoverageMediumTest {
     FileUtils.write(xooFile, "function foo() {\n  if (a && b) {\nalert('hello');\n}\n}", StandardCharsets.UTF_8);
     FileUtils.write(xooUtCoverageFile, "2:2:2:1\n3:1", StandardCharsets.UTF_8);
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
@@ -100,7 +101,7 @@ public class CoverageMediumTest {
     File xooItCoverageFile = new File(srcDir, "sample.xoo.itcoverage");
     FileUtils.write(xooItCoverageFile, "2:2:2:1\n3:1\n5:0", StandardCharsets.UTF_8);
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
@@ -138,7 +139,7 @@ public class CoverageMediumTest {
     FileUtils.write(xooFile, "function foo() {\n  if (a && b) {\nalert('hello');\n}\n}", StandardCharsets.UTF_8);
     FileUtils.write(xooUtCoverageFile, "2:2:2:1\n3:1", StandardCharsets.UTF_8);
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
@@ -178,7 +179,7 @@ public class CoverageMediumTest {
     FileUtils.write(xooFileB, "function foo() {\n  if (a && b) {\nalert('hello');\n}\n}", StandardCharsets.UTF_8);
     FileUtils.write(xooUtCoverageFileB, "2:2:2:1\n3:1", StandardCharsets.UTF_8);
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
@@ -195,7 +196,7 @@ public class CoverageMediumTest {
     InputFile fileB = result.inputFile("moduleB/src/sample.xoo");
     assertThat(result.coverageFor(fileB, 2)).isNull();
 
-    assertThat(logs).contains("File 'moduleA/src/sample.xoo' was excluded from coverage because patterns are still " +
+    assertThat(logTester.logs(LoggerLevel.WARN)).contains("File 'moduleA/src/sample.xoo' was excluded from coverage because patterns are still " +
       "evaluated using module relative paths but this is deprecated. Please update 'sonar.coverage.exclusions' " +
       "configuration so that patterns refer to project relative paths");
   }
@@ -221,7 +222,7 @@ public class CoverageMediumTest {
     FileUtils.write(xooFileB, "function foo() {\n  if (a && b) {\nalert('hello');\n}\n}", StandardCharsets.UTF_8);
     FileUtils.write(xooUtCoverageFileB, "2:2:2:1\n3:1", StandardCharsets.UTF_8);
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
@@ -238,9 +239,9 @@ public class CoverageMediumTest {
     InputFile fileB = result.inputFile("moduleB/src/sample.xoo");
     assertThat(result.coverageFor(fileB, 2)).isNull();
 
-    assertThat(logs).contains("Defining coverage exclusions at module level is deprecated. " +
+    assertThat(logTester.logs(LoggerLevel.WARN)).contains("Defining coverage exclusions at module level is deprecated. " +
       "Move 'sonar.coverage.exclusions' from module 'moduleB' " +
-        "to the root project and update patterns to refer to project relative paths");
+      "to the root project and update patterns to refer to project relative paths");
   }
 
   @Test
@@ -255,7 +256,7 @@ public class CoverageMediumTest {
     FileUtils.write(xooFile, "function foo() {\n  if (a && b) {\nalert('hello');\n}\n}", StandardCharsets.UTF_8);
     FileUtils.write(measuresFile, "executable_lines_data:2=1;3=1;4=0", StandardCharsets.UTF_8);
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
@@ -300,7 +301,7 @@ public class CoverageMediumTest {
     FileUtils.write(xooFile2, "function foo() {\n  if (a && b) {\nalert('hello');\n}\n}", StandardCharsets.UTF_8);
     FileUtils.write(measuresFile2, "executable_lines_data:2=1;3=1;4=0", StandardCharsets.UTF_8);
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
index 612bf057f1c441a8ccae6478f9a9cfec319d9fa3..e41b31e8d601c85363fd05d3fe6d123b7078c9e7 100644 (file)
@@ -28,7 +28,7 @@ import org.junit.Test;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.measures.CoreMetrics;
 import org.sonar.scanner.mediumtest.ScannerMediumTester;
-import org.sonar.scanner.mediumtest.TaskResult;
+import org.sonar.scanner.mediumtest.AnalysisResult;
 import org.sonar.xoo.XooPlugin;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -47,9 +47,9 @@ public class GenericCoverageMediumTest {
 
     File projectDir = new File("test-resources/mediumtest/xoo/sample-generic-coverage");
 
-    TaskResult result = tester
+    AnalysisResult result = tester
       .setLogOutput((msg, level) -> logs.add(msg))
-      .newScanTask(new File(projectDir, "sonar-project.properties"))
+      .newAnalysis(new File(projectDir, "sonar-project.properties"))
       .property("sonar.coverageReportPaths", "coverage.xml")
       .execute();
 
@@ -91,7 +91,7 @@ public class GenericCoverageMediumTest {
 
     tester
       .setLogOutput((msg, level) -> logs.add(msg))
-      .newScanTask(new File(projectDir, "sonar-project.properties"))
+      .newAnalysis(new File(projectDir, "sonar-project.properties"))
       .property("sonar.genericcoverage.reportPath", "coverage.xml")
       .execute();
       
@@ -104,9 +104,9 @@ public class GenericCoverageMediumTest {
 
     File projectDir = new File("test-resources/mediumtest/xoo/sample-generic-coverage");
 
-    TaskResult result = tester
+    AnalysisResult result = tester
       .setLogOutput((msg, level) -> logs.add(msg))
-      .newScanTask(new File(projectDir, "sonar-project.properties"))
+      .newAnalysis(new File(projectDir, "sonar-project.properties"))
       .property("sonar.coverageReportPaths", "coverage.xml,coverage2.xml")
       .execute();
 
index 52462d5d567128b8e2dd795750fc979247807b37..6ce98f526ac195acb2681597948fa35770909214 100644 (file)
@@ -31,9 +31,9 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.fs.InputFile;
-import org.sonar.scanner.mediumtest.LogOutputRecorder;
+import org.sonar.api.utils.log.LogTester;
 import org.sonar.scanner.mediumtest.ScannerMediumTester;
-import org.sonar.scanner.mediumtest.TaskResult;
+import org.sonar.scanner.mediumtest.AnalysisResult;
 import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.xoo.XooPlugin;
 import org.sonar.xoo.rule.XooRulesDefinition;
@@ -47,7 +47,9 @@ public class CpdMediumTest {
   @Rule
   public ExpectedException thrown = ExpectedException.none();
 
-  private LogOutputRecorder logRecorder = new LogOutputRecorder();
+  @Rule
+  public LogTester logTester = new LogTester();
+
   private File baseDir;
 
   @Rule
@@ -56,15 +58,13 @@ public class CpdMediumTest {
     .addDefaultQProfile("xoo", "Sonar Way")
     .addRules(new XooRulesDefinition())
     // active a rule just to be sure that xoo files are published
-    .addActiveRule("xoo", "xoo:OneIssuePerFile", null, "One Issue Per File", null, null, null)
-    .setLogOutput(logRecorder);
+    .addActiveRule("xoo", "xoo:OneIssuePerFile", null, "One Issue Per File", null, null, null);
 
   private ImmutableMap.Builder<String, String> builder;
 
   @Before
   public void prepare() {
     baseDir = temp.getRoot();
-    logRecorder.getAll().clear();
 
     builder = ImmutableMap.<String, String>builder()
       .put("sonar.task", "scan")
@@ -110,7 +110,7 @@ public class CpdMediumTest {
     File xooFile2 = new File(module2Dir, "sample2.xoo");
     FileUtils.write(xooFile2, duplicatedStuff);
 
-    TaskResult result = tester.newTask().properties(builder.build()).execute();
+    AnalysisResult result = tester.newAnalysis().properties(builder.build()).execute();
 
     assertThat(result.inputFiles()).hasSize(2);
 
@@ -156,7 +156,7 @@ public class CpdMediumTest {
     File xooFile2 = new File(srcDir, "sample2.xoo");
     FileUtils.write(xooFile2, duplicatedStuff, StandardCharsets.UTF_8);
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(builder
         .put("sonar.sources", "src")
         .put("sonar.cpd.xoo.minimumTokens", "10")
@@ -210,7 +210,7 @@ public class CpdMediumTest {
     File xooFile2 = new File(srcDir, "sample2.xoo");
     FileUtils.write(xooFile2, file2, StandardCharsets.UTF_8);
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(builder
         .put("sonar.sources", "src")
         .put("sonar.cpd.xoo.minimumTokens", "10")
@@ -220,8 +220,8 @@ public class CpdMediumTest {
 
     assertThat(result.inputFiles()).hasSize(2);
 
-    assertThat(logRecorder.getAllAsString()).contains("Not enough content in 'src/sample2.xoo' to have CPD blocks");
-    assertThat(logRecorder.getAllAsString()).contains("1 file had no CPD blocks");
+    assertThat(logTester.logs()).contains("Not enough content in 'src/sample2.xoo' to have CPD blocks, it will not be part of the duplication detection");
+    assertThat(logTester.logs()).contains("1 file had no CPD blocks");
 
   }
 
@@ -242,7 +242,7 @@ public class CpdMediumTest {
     File xooFile2 = new File(srcDir, "sample2.xoo");
     FileUtils.write(xooFile2, duplicatedStuff);
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(builder
         .put("sonar.sources", "src")
         .put("sonar.cpd.xoo.minimumTokens", "10")
@@ -272,7 +272,7 @@ public class CpdMediumTest {
     File xooFile1 = new File(srcDir, "sample1.xoo");
     FileUtils.write(xooFile1, duplicatedStuff);
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(builder
         .put("sonar.sources", "src")
         .put("sonar.cpd.xoo.minimumTokens", "1")
@@ -315,7 +315,7 @@ public class CpdMediumTest {
     File xooFile = new File(srcDir, "sample.xoo");
     FileUtils.write(xooFile, content);
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(builder
         .put("sonar.sources", "src")
         .put("sonar.cpd.xoo.minimumTokens", "2")
index d30beea2c532e838efd43092ce6dfa312bc417f9..a8e84a6faf20c94a5238ede96f4b3d450a587db4 100644 (file)
@@ -36,13 +36,13 @@ import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
 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.internal.DefaultInputFile;
+import org.sonar.api.scanner.fs.InputProject;
 import org.sonar.api.utils.MessageException;
 import org.sonar.api.utils.System2;
+import org.sonar.scanner.mediumtest.AnalysisResult;
 import org.sonar.scanner.mediumtest.LogOutputRecorder;
 import org.sonar.scanner.mediumtest.ScannerMediumTester;
-import org.sonar.scanner.mediumtest.TaskResult;
 import org.sonar.xoo.XooPlugin;
 import org.sonar.xoo.global.GlobalSensor;
 import org.sonar.xoo.rule.XooRulesDefinition;
@@ -103,7 +103,7 @@ public class FileSystemMediumTest {
     File xooFile = new File(srcDir, "sample.xoo");
     FileUtils.write(xooFile, "Sample xoo\ncontent");
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(builder
         .put("sonar.sources", "src")
         .build())
@@ -138,7 +138,7 @@ public class FileSystemMediumTest {
     File xooFile = new File(srcDir, "sample.xoo");
     FileUtils.write(xooFile, "Sample xoo\ncontent");
 
-    tester.newTask()
+    tester.newAnalysis()
       .properties(builder
         .put("sonar.sources", "src")
         .build())
@@ -159,7 +159,7 @@ public class FileSystemMediumTest {
     File xooFile = new File(srcDir, "sample.xoo");
     FileUtils.write(xooFile, "Sample xoo\ncontent");
 
-    tester.newTask()
+    tester.newAnalysis()
       .properties(builder
         .put("sonar.sources", "src")
         .build())
@@ -182,7 +182,7 @@ public class FileSystemMediumTest {
     // the fail-fast mechanism in the scanner should have prevented reaching this point.
     thrown.expect(IllegalStateException.class);
 
-    tester.newTask()
+    tester.newAnalysis()
       .properties(builder
         .put("sonar.sources", "src")
         .build())
@@ -198,7 +198,7 @@ public class FileSystemMediumTest {
     File xooFile = new File(srcDir, "sample.xoo");
     FileUtils.write(xooFile, "Sample xoo\ncontent");
 
-    tester.newTask()
+    tester.newAnalysis()
       .properties(builder
         .put("sonar.sources", "src")
         .build())
@@ -222,7 +222,7 @@ public class FileSystemMediumTest {
     File javaFile = new File(srcDir, "sample.java");
     FileUtils.write(javaFile, "Sample xoo\ncontent");
 
-    tester.newTask()
+    tester.newAnalysis()
       .properties(builder
         .put("sonar.sources", "src")
         .build())
@@ -248,7 +248,7 @@ public class FileSystemMediumTest {
     File javaFile = new File(srcDir, "sample.java");
     FileUtils.write(javaFile, "Sample xoo\ncontent");
 
-    tester.newTask()
+    tester.newAnalysis()
       .properties(builder
         .put("sonar.sources", "src")
         .build())
@@ -278,7 +278,7 @@ public class FileSystemMediumTest {
     Path javaFile = mainDir.resolve("sample.java");
     Files.write(javaFile, "Sample xoo\ncontent".getBytes(StandardCharsets.UTF_8));
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(builder
         .put("sonar.sources", "src/main")
         .put("sonar.tests", "src/test")
@@ -307,7 +307,7 @@ public class FileSystemMediumTest {
     File xooFile = new File(srcDir, "sample.unknown");
     FileUtils.write(xooFile, "Sample xoo\ncontent");
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(builder
         .put("sonar.sources", "src")
         .build())
@@ -340,7 +340,7 @@ public class FileSystemMediumTest {
     new Random().nextBytes(b);
     FileUtils.writeByteArrayToFile(unknownFile, b);
 
-    tester.newTask()
+    tester.newAnalysis()
       .properties(builder
         .put("sonar.sources", "src")
         .build())
@@ -366,7 +366,7 @@ public class FileSystemMediumTest {
     File unknownFile = new File(srcDir, "myfile.binary");
     FileUtils.write(unknownFile, "some text");
 
-    tester.newTask()
+    tester.newAnalysis()
       .properties(builder
         .put("sonar.sources", "src")
         .build())
@@ -390,7 +390,7 @@ public class FileSystemMediumTest {
     File xooFile = new File(srcDir, "sample.xoo");
     FileUtils.write(xooFile, "Sample xoo\ncontent");
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(builder
         .put("sonar.sources", "src")
         .build())
@@ -426,17 +426,17 @@ public class FileSystemMediumTest {
     Path emptyDirRelative = Paths.get("src", "emptydir");
     Files.createDirectories(emptyDirRelative);
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(builder
         .put("sonar.sources", "src")
         .build())
       .execute();
 
     DefaultInputFile unknownInputFile = (DefaultInputFile) result.inputFile("src/unknown/file.notanalyzed");
-    InputModule root = result.root();
+    InputProject project = result.project();
 
     assertThat(unknownInputFile.isPublished()).isFalse();
-    assertThat(result.getReportComponent(root.key())).isNotNull();
+    assertThat(result.getReportComponent(project.key())).isNotNull();
 
     // no issues on empty dir
     InputDir emptyInputDir = result.inputDir(emptyDirRelative.toString());
@@ -455,7 +455,7 @@ public class FileSystemMediumTest {
     File xooFile = new File(srcDir, "sample.xoo");
     FileUtils.write(xooFile, "Sample xoo\ncontent");
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(builder
         .put("sonar.sources", "src")
         .build())
@@ -480,7 +480,7 @@ public class FileSystemMediumTest {
       FileUtils.write(xooFile, StringUtils.repeat(StringUtils.repeat("a", 100) + "\n", ruleCount / 1000));
     }
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(builder
         .put("sonar.sources", "src")
         .build())
@@ -498,7 +498,7 @@ public class FileSystemMediumTest {
     File xooFile = new File(test, "sampleTest.xoo");
     FileUtils.write(xooFile, "Sample test xoo\ncontent");
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(builder
         .put("sonar.sources", "")
         .put("sonar.tests", "test")
@@ -532,7 +532,7 @@ public class FileSystemMediumTest {
     File xooTestFile2 = new File(testDir, "sampleTest.xoo");
     FileUtils.write(xooTestFile2, "Sample test xoo 2\ncontent");
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(builder
         .put("sonar.sources", "src,another.xoo")
         .put("sonar.tests", "test,sampleTest2.xoo")
@@ -563,7 +563,7 @@ public class FileSystemMediumTest {
     File xooTestFile2 = new File(testDir, "sampleTest.xoo");
     FileUtils.write(xooTestFile2, "Sample test xoo 2\ncontent");
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(builder
         .put("sonar.sources", "src,another.xoo")
         .put("sonar.tests", "test,sampleTest2.xoo")
@@ -587,7 +587,7 @@ public class FileSystemMediumTest {
 
     thrown.expect(MessageException.class);
     thrown.expectMessage("File src/sample.xoo can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files");
-    tester.newTask()
+    tester.newAnalysis()
       .properties(builder
         .put("sonar.sources", "src,src/sample.xoo")
         .build())
@@ -605,7 +605,7 @@ public class FileSystemMediumTest {
 
     thrown.expect(MessageException.class);
     thrown.expectMessage("File module1/src/sample.xoo can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files");
-    tester.newTask()
+    tester.newAnalysis()
       .properties(builder
         .put("sonar.sources", "module1/src")
         .put("sonar.modules", "module1")
@@ -620,8 +620,8 @@ public class FileSystemMediumTest {
   public void scanProjectWithSourceSymlink() {
     assumeTrue(!System2.INSTANCE.isOsWindows());
     File projectDir = new File("test-resources/mediumtest/xoo/sample-with-symlink");
-    TaskResult result = tester
-      .newScanTask(new File(projectDir, "sonar-project.properties"))
+    AnalysisResult result = tester
+      .newAnalysis(new File(projectDir, "sonar-project.properties"))
       .execute();
 
     assertThat(result.inputFiles()).hasSize(3);
@@ -635,8 +635,8 @@ public class FileSystemMediumTest {
     // To please the quality gate, don't use assumeTrue, or the test will be reported as skipped
     if (System2.INSTANCE.isOsWindows()) {
       File projectDir = new File("test-resources/mediumtest/xoo/sample");
-      TaskResult result = tester
-        .newScanTask(new File(projectDir, "sonar-project.properties"))
+      AnalysisResult result = tester
+        .newAnalysis(new File(projectDir, "sonar-project.properties"))
         .property("sonar.sources", "XOURCES")
         .property("sonar.tests", "TESTX")
         .execute();
@@ -660,7 +660,7 @@ public class FileSystemMediumTest {
     File otherFile = new File(srcDir, "sample.other");
     FileUtils.write(otherFile, "Sample other\ncontent");
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(builder
         .put("sonar.sources", "src")
         .build())
@@ -675,8 +675,8 @@ public class FileSystemMediumTest {
   @Test
   public void scanMultiModuleProject() {
     File projectDir = new File("test-resources/mediumtest/xoo/multi-modules-sample");
-    TaskResult result = tester
-      .newScanTask(new File(projectDir, "sonar-project.properties"))
+    AnalysisResult result = tester
+      .newAnalysis(new File(projectDir, "sonar-project.properties"))
       .execute();
 
     assertThat(result.inputFiles()).hasSize(4);
@@ -686,8 +686,8 @@ public class FileSystemMediumTest {
   @Test
   public void global_sensor_should_see_project_relative_paths() {
     File projectDir = new File("test-resources/mediumtest/xoo/multi-modules-sample");
-    TaskResult result = tester
-      .newScanTask(new File(projectDir, "sonar-project.properties"))
+    AnalysisResult result = tester
+      .newAnalysis(new File(projectDir, "sonar-project.properties"))
       .property(GlobalSensor.ENABLE_PROP, "true")
       .execute();
 
@@ -719,7 +719,7 @@ public class FileSystemMediumTest {
     File xooTestFile2 = new File(baseDir, "sampleTest,2.xoo");
     FileUtils.write(xooTestFile2, "Sample test xoo 2\ncontent");
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(builder
         .put("sonar.sources", "src,\"another,2.xoo\"")
         .put("sonar.tests", "\"test\",\"sampleTest,2.xoo\"")
@@ -741,7 +741,7 @@ public class FileSystemMediumTest {
     File xooFile2 = new File(srcDir, "sample.xoo2");
     FileUtils.write(xooFile2, "Sample xoo 2\ncontent");
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(builder
         .put("sonar.sources", "src")
         .build())
@@ -750,7 +750,7 @@ public class FileSystemMediumTest {
     assertThat(result.inputFiles()).hasSize(2);
 
     try {
-      result = tester.newTask()
+      result = tester.newAnalysis()
         .properties(builder
           .put("sonar.lang.patterns.xoo2", "**/*.xoo")
           .build())
@@ -764,7 +764,7 @@ public class FileSystemMediumTest {
     }
 
     // SONAR-9561
-    result = tester.newTask()
+    result = tester.newAnalysis()
       .properties(builder
         .put("sonar.exclusions", "**/sample.xoo")
         .build())
index 838d0fc8757f96492db29d33faf04cec3226dcd8..ab3baf428fc025cebdd758e1b568d976cc2a2dc2 100644 (file)
@@ -47,7 +47,7 @@ public class NoLanguagesPluginsMediumTest {
     exception.expectMessage("No language plugins are installed");
 
     tester
-      .newScanTask(new File(projectDir, "sonar-project.properties"))
+      .newAnalysis(new File(projectDir, "sonar-project.properties"))
       .execute();
   }
 
index dbbc27dfc7ce0712c6f5bda1c8d0481a85e9fb0b..4a2beacd4dc68ee8e451a54f5992d358fcbb56d3 100644 (file)
@@ -34,7 +34,7 @@ import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.bootstrap.ProjectBuilder;
 import org.sonar.api.utils.MessageException;
 import org.sonar.scanner.mediumtest.ScannerMediumTester;
-import org.sonar.scanner.mediumtest.TaskResult;
+import org.sonar.scanner.mediumtest.AnalysisResult;
 import org.sonar.scanner.protocol.output.ScannerReport.Issue;
 import org.sonar.xoo.XooPlugin;
 import org.sonar.xoo.rule.XooRulesDefinition;
@@ -100,7 +100,7 @@ public class ProjectBuilderMediumTest {
       }
     });
 
-    tester.newTask()
+    tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
@@ -119,7 +119,7 @@ public class ProjectBuilderMediumTest {
   public void testProjectBuilder() throws IOException {
     File baseDir = prepareProject();
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
@@ -148,7 +148,7 @@ public class ProjectBuilderMediumTest {
 
     exception.expect(MessageException.class);
     exception.expectMessage("is not a valid branch name");
-    tester.newTask()
+    tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
@@ -167,7 +167,7 @@ public class ProjectBuilderMediumTest {
   public void testProjectBuilderWithBranch() throws IOException {
     File baseDir = prepareProject();
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
index ed8cf9b71e2ae8c401d18ea88143e32225ca3e7e..eb1daae921d8df472e80822237ec72846e8cee50 100644 (file)
@@ -32,7 +32,7 @@ import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.sensor.highlighting.TypeOfText;
 import org.sonar.scanner.mediumtest.ScannerMediumTester;
-import org.sonar.scanner.mediumtest.TaskResult;
+import org.sonar.scanner.mediumtest.AnalysisResult;
 import org.sonar.xoo.XooPlugin;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -62,7 +62,7 @@ public class HighlightingMediumTest {
     FileUtils.write(xooFile, "Sample xoo\ncontent plop");
     FileUtils.write(xoohighlightingFile, "0:10:s\n11:18:k");
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
         .put("sonar.projectKey", "com.foo.project")
@@ -91,7 +91,7 @@ public class HighlightingMediumTest {
 
     exception.expect(UnsupportedOperationException.class);
     exception.expectMessage("Trying to save highlighting twice for the same file is not supported");
-    tester.newTask()
+    tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
         .put("sonar.projectKey", "com.foo.project")
@@ -131,7 +131,7 @@ public class HighlightingMediumTest {
       }
     });
 
-    tester.newTask()
+    tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
         .put("sonar.projectKey", "com.foo.project")
index 61c3e68d703fc36bea334d31c6bc9089c940d126..fdc8a2c2b68e66c67ba1df59ec2647d0d0b64a3e 100644 (file)
@@ -32,7 +32,7 @@ import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.scanner.mediumtest.ScannerMediumTester;
-import org.sonar.scanner.mediumtest.TaskResult;
+import org.sonar.scanner.mediumtest.AnalysisResult;
 import org.sonar.scanner.protocol.output.ScannerReport.Issue;
 import org.sonar.scanner.rule.LoadedActiveRule;
 import org.sonar.xoo.XooPlugin;
@@ -66,7 +66,7 @@ public class ChecksMediumTest {
     File xooFile = new File(srcDir, "sample.xoo");
     FileUtils.write(xooFile, "foo\nbar");
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
index 9377af4398fd04b7409920680e7cda8e654ff59f..185658f8d68e9eb843a08c4808651e8b2b4c3dfd 100644 (file)
@@ -29,7 +29,7 @@ import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.utils.log.LogTester;
 import org.sonar.scanner.mediumtest.ScannerMediumTester;
-import org.sonar.scanner.mediumtest.TaskResult;
+import org.sonar.scanner.mediumtest.AnalysisResult;
 import org.sonar.scanner.protocol.Constants.Severity;
 import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.scanner.protocol.output.ScannerReport.ExternalIssue;
@@ -57,8 +57,8 @@ public class ExternalIssuesMediumTest {
     File tmpDir = temp.newFolder();
     FileUtils.copyDirectory(projectDir, tmpDir);
 
-    TaskResult result = tester
-      .newScanTask(new File(tmpDir, "sonar-project.properties"))
+    AnalysisResult result = tester
+      .newAnalysis(new File(tmpDir, "sonar-project.properties"))
       .property(OneExternalIssuePerLineSensor.ACTIVATE, "true")
       .execute();
 
@@ -80,8 +80,8 @@ public class ExternalIssuesMediumTest {
     File tmpDir = temp.newFolder();
     FileUtils.copyDirectory(projectDir, tmpDir);
 
-    TaskResult result = tester
-      .newScanTask(new File(tmpDir, "sonar-project.properties"))
+    AnalysisResult result = tester
+      .newAnalysis(new File(tmpDir, "sonar-project.properties"))
       .property(OneExternalIssuePerLineSensor.ACTIVATE, "true")
       .property(OneExternalIssuePerLineSensor.REGISTER_AD_HOC_RULE, "true")
       .execute();
@@ -109,8 +109,8 @@ public class ExternalIssuesMediumTest {
     File tmpDir = temp.newFolder();
     FileUtils.copyDirectory(projectDir, tmpDir);
 
-    TaskResult result = tester
-      .newScanTask(new File(tmpDir, "sonar-project.properties"))
+    AnalysisResult result = tester
+      .newAnalysis(new File(tmpDir, "sonar-project.properties"))
       .property("sonar.externalIssuesReportPaths", "externalIssues.json")
       .execute();
 
index 8115c9e8ed99b595d41c9845a41006b6c707aef5..5a066cdc700fff9cddd31c928814a188a3ae333f 100644 (file)
@@ -28,7 +28,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.scanner.mediumtest.ScannerMediumTester;
-import org.sonar.scanner.mediumtest.TaskResult;
+import org.sonar.scanner.mediumtest.AnalysisResult;
 import org.sonar.scanner.protocol.output.ScannerReport.ExternalIssue;
 import org.sonar.scanner.protocol.output.ScannerReport.Issue;
 import org.sonar.xoo.XooPlugin;
@@ -56,8 +56,8 @@ public class IssuesMediumTest {
     File tmpDir = temp.newFolder();
     FileUtils.copyDirectory(projectDir, tmpDir);
 
-    TaskResult result = tester
-      .newScanTask(new File(tmpDir, "sonar-project.properties"))
+    AnalysisResult result = tester
+      .newAnalysis(new File(tmpDir, "sonar-project.properties"))
       .execute();
 
     List<Issue> issues = result.issuesFor(result.inputFile("xources/hello/HelloJava.xoo"));
@@ -73,8 +73,8 @@ public class IssuesMediumTest {
     File tmpDir = temp.newFolder();
     FileUtils.copyDirectory(projectDir, tmpDir);
 
-    TaskResult result = tester
-      .newScanTask(new File(tmpDir, "sonar-project.properties"))
+    AnalysisResult result = tester
+      .newAnalysis(new File(tmpDir, "sonar-project.properties"))
       .property(OneExternalIssuePerLineSensor.ACTIVATE, "true")
       .execute();
 
@@ -88,8 +88,8 @@ public class IssuesMediumTest {
     File tmpDir = temp.newFolder();
     FileUtils.copyDirectory(projectDir, tmpDir);
 
-    TaskResult result = tester
-      .newScanTask(new File(tmpDir, "sonar-project.properties"))
+    AnalysisResult result = tester
+      .newAnalysis(new File(tmpDir, "sonar-project.properties"))
       .property("sonar.xoo.internalKey", "OneIssuePerLine.internal")
       .execute();
 
@@ -103,8 +103,8 @@ public class IssuesMediumTest {
     File tmpDir = temp.newFolder();
     FileUtils.copyDirectory(projectDir, tmpDir);
 
-    TaskResult result = tester
-      .newScanTask(new File(tmpDir, "sonar-project.properties"))
+    AnalysisResult result = tester
+      .newAnalysis(new File(tmpDir, "sonar-project.properties"))
       .property("sonar.oneIssuePerLine.forceSeverity", "CRITICAL")
       .execute();
 
@@ -118,8 +118,8 @@ public class IssuesMediumTest {
     File tmpDir = temp.newFolder();
     FileUtils.copyDirectory(projectDir, tmpDir);
 
-    TaskResult result = tester
-      .newScanTask(new File(tmpDir, "sonar-project.properties"))
+    AnalysisResult result = tester
+      .newAnalysis(new File(tmpDir, "sonar-project.properties"))
       .property("sonar.issue.ignore.allfile", "1")
       .property("sonar.issue.ignore.allfile.1.fileRegexp", "object")
       .execute();
@@ -138,7 +138,7 @@ public class IssuesMediumTest {
     File xooFile = new File(srcDir, "sample.xoo");
     FileUtils.write(xooFile, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10");
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
@@ -159,12 +159,12 @@ public class IssuesMediumTest {
 
   @Test
   public void testIssueFilter() throws Exception {
-    File projectDir = new File(IssuesMediumTest.class.getResource("/mediumtest/xoo/sample").toURI());
+    File projectDir = new File("test-resources/mediumtest/xoo/sample");
     File tmpDir = temp.newFolder();
     FileUtils.copyDirectory(projectDir, tmpDir);
 
-    TaskResult result = tester
-      .newScanTask(new File(tmpDir, "sonar-project.properties"))
+    AnalysisResult result = tester
+      .newAnalysis(new File(tmpDir, "sonar-project.properties"))
       .property("sonar.xoo.excludeAllIssuesOnOddLines", "true")
       .execute();
 
index 95b92faf565560d857f5431c0ba37d4d73ca4e7b..ed76bba6c251800623e07f29feefbe882b324999 100644 (file)
@@ -27,7 +27,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.scanner.mediumtest.ScannerMediumTester;
-import org.sonar.scanner.mediumtest.TaskResult;
+import org.sonar.scanner.mediumtest.AnalysisResult;
 import org.sonar.xoo.XooPlugin;
 import org.sonar.xoo.rule.XooRulesDefinition;
 
@@ -58,7 +58,7 @@ public class IssuesOnDirMediumTest {
     File xooFile2 = new File(srcDir, "sample2.xoo");
     FileUtils.write(xooFile2, "Sample2 xoo\ncontent");
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
@@ -71,7 +71,7 @@ public class IssuesOnDirMediumTest {
       .execute();
 
     assertThat(result.issuesFor(result.inputDir("src"))).hasSize(0);
-    assertThat(result.issuesFor(result.root())).hasSize(2);
+    assertThat(result.issuesFor(result.project())).hasSize(2);
   }
 
   @Test
@@ -85,7 +85,7 @@ public class IssuesOnDirMediumTest {
     File xooFile2 = new File(baseDir, "sample2.xoo");
     FileUtils.write(xooFile2, "Sample2 xoo\ncontent");
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
@@ -98,7 +98,7 @@ public class IssuesOnDirMediumTest {
       .execute();
 
     assertThat(result.issuesFor(result.inputDir(""))).hasSize(0);
-    assertThat(result.issuesFor(result.root())).hasSize(2);
+    assertThat(result.issuesFor(result.project())).hasSize(2);
   }
 
 }
index a333fff9e3ace727688ff95b1fc5c43c3c17b870..48561c72e0a6c34fb7f054449441d874acc95368 100644 (file)
@@ -27,7 +27,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.scanner.mediumtest.ScannerMediumTester;
-import org.sonar.scanner.mediumtest.TaskResult;
+import org.sonar.scanner.mediumtest.AnalysisResult;
 import org.sonar.xoo.XooPlugin;
 import org.sonar.xoo.rule.XooRulesDefinition;
 
@@ -55,7 +55,7 @@ public class IssuesOnModuleMediumTest {
     File xooFile1 = new File(srcDir, "sample1.xoo");
     FileUtils.write(xooFile1, "Sample1 xoo\ncontent");
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
index 5141f344034c201f0316523f800fad7579c0448e..2430a41e128d6d49f49ccdb65bd772710d58f7fc 100644 (file)
@@ -27,7 +27,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.scanner.mediumtest.ScannerMediumTester;
-import org.sonar.scanner.mediumtest.TaskResult;
+import org.sonar.scanner.mediumtest.AnalysisResult;
 import org.sonar.scanner.protocol.output.ScannerReport.Flow;
 import org.sonar.scanner.protocol.output.ScannerReport.Issue;
 import org.sonar.scanner.protocol.output.ScannerReport.IssueLocation;
@@ -48,7 +48,7 @@ public class MultilineIssuesMediumTest {
     .addDefaultQProfile("xoo", "Sonar Way")
     .addActiveRule("xoo", "MultilineIssue", null, "Multinile Issue", "MAJOR", null, "xoo");
 
-  private TaskResult result;
+  private AnalysisResult result;
 
   @Before
   public void prepare() throws Exception {
@@ -57,7 +57,7 @@ public class MultilineIssuesMediumTest {
     FileUtils.copyDirectory(projectDir, tmpDir);
 
     result = tester
-      .newScanTask(new File(tmpDir, "sonar-project.properties"))
+      .newAnalysis(new File(tmpDir, "sonar-project.properties"))
       .execute();
   }
 
index ab92175c1a657659535e46af29857e8129fe587a..b87d034afedd86f292a4403e27c12cb95d9a3f36 100644 (file)
@@ -31,7 +31,7 @@ import org.sonar.api.CoreProperties;
 import org.sonar.api.utils.log.LogTester;
 import org.sonar.scanner.issue.tracking.TrackedIssue;
 import org.sonar.scanner.mediumtest.ScannerMediumTester;
-import org.sonar.scanner.mediumtest.TaskResult;
+import org.sonar.scanner.mediumtest.AnalysisResult;
 import org.sonar.xoo.XooPlugin;
 import org.sonar.xoo.rule.XooRulesDefinition;
 
@@ -58,8 +58,8 @@ public class EmptyFileTest {
   public void testIssueTrackingWithIssueOnEmptyFile() throws Exception {
     File projectDir = copyProject("test-resources/mediumtest/xoo/sample-with-empty-file");
 
-    TaskResult result = tester
-      .newScanTask(new File(projectDir, "sonar-project.properties"))
+    AnalysisResult result = tester
+      .newAnalysis(new File(projectDir, "sonar-project.properties"))
       .property("sonar.xoo.internalKey", "my/internal/key")
       .execute();
 
index 0656c7829561e78b82ff18cee5743012c4d5ba8f..cb29125779c564dae7f5c4e0734eee7a88a9ea63 100644 (file)
@@ -38,7 +38,7 @@ import org.sonar.api.utils.log.LogTester;
 import org.sonar.api.utils.log.LoggerLevel;
 import org.sonar.scanner.issue.tracking.TrackedIssue;
 import org.sonar.scanner.mediumtest.ScannerMediumTester;
-import org.sonar.scanner.mediumtest.TaskResult;
+import org.sonar.scanner.mediumtest.AnalysisResult;
 import org.sonar.scanner.protocol.Constants.Severity;
 import org.sonar.scanner.protocol.input.ScannerInput.ServerIssue;
 import org.sonar.xoo.XooPlugin;
@@ -119,8 +119,8 @@ public class IssueModeAndReportsMediumTest {
   public void testIssueTracking() throws Exception {
     File projectDir = copyProject("test-resources/mediumtest/xoo/sample");
 
-    TaskResult result = tester
-      .newScanTask(new File(projectDir, "sonar-project.properties"))
+    AnalysisResult result = tester
+      .newAnalysis(new File(projectDir, "sonar-project.properties"))
       .execute();
 
     int newIssues = 0;
@@ -166,7 +166,7 @@ public class IssueModeAndReportsMediumTest {
     File projectDir = copyProject("test-resources/mediumtest/xoo/sample");
 
     tester
-      .newScanTask(new File(projectDir, "sonar-project.properties"))
+      .newAnalysis(new File(projectDir, "sonar-project.properties"))
       .property("sonar.xoo.enablePostJob", "true")
       .execute();
 
@@ -185,7 +185,7 @@ public class IssueModeAndReportsMediumTest {
     FileUtils.write(xooFile, "Sample xoo\ncontent plop");
     FileUtils.write(xoohighlightingFile, "0:10:s\n11:18:k");
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
         .put("sonar.projectKey", "com.foo.project")
index 7316af210e3e04b0c5af3de7906ccc53592c820e..8a113d8382ee18a0b42a7cf9de38c8e9ae897ebc 100644 (file)
@@ -29,7 +29,7 @@ import org.junit.rules.TemporaryFolder;
 import org.sonar.api.CoreProperties;
 import org.sonar.api.utils.log.LogTester;
 import org.sonar.scanner.mediumtest.ScannerMediumTester;
-import org.sonar.scanner.mediumtest.TaskResult;
+import org.sonar.scanner.mediumtest.AnalysisResult;
 import org.sonar.xoo.XooPlugin;
 import org.sonar.xoo.rule.XooRulesDefinition;
 
@@ -55,8 +55,8 @@ public class NoPreviousAnalysisTest {
   public void testIssueTrackingWithIssueOnEmptyFile() throws Exception {
     File projectDir = copyProject("test-resources/mediumtest/xoo/sample");
 
-    TaskResult result = tester
-      .newScanTask(new File(projectDir, "sonar-project.properties"))
+    AnalysisResult result = tester
+      .newAnalysis(new File(projectDir, "sonar-project.properties"))
       .execute();
 
     assertThat(result.trackedIssues()).hasSize(14);
index 434f98af67ac9531f55ed4cee0f9c68a0607d2d6..4f68f3040fa45bc3b4b48f8fd00a4853b3cf24a9 100644 (file)
@@ -48,8 +48,8 @@ import org.sonar.api.batch.fs.internal.FileMetadata;
 import org.sonar.api.utils.log.LogTester;
 import org.sonar.scanner.issue.tracking.TrackedIssue;
 import org.sonar.scanner.mediumtest.ScannerMediumTester;
-import org.sonar.scanner.mediumtest.ScannerMediumTester.TaskBuilder;
-import org.sonar.scanner.mediumtest.TaskResult;
+import org.sonar.scanner.mediumtest.ScannerMediumTester.AnalysisBuilder;
+import org.sonar.scanner.mediumtest.AnalysisResult;
 import org.sonar.scanner.protocol.Constants.Severity;
 import org.sonar.scanner.protocol.input.ScannerInput.ServerIssue;
 import org.sonar.scanner.repository.FileData;
@@ -141,16 +141,16 @@ public class ScanOnlyChangedTest {
   public void testScanOnlyChangedFiles() throws Exception {
     File projectDir = copyProject("test-resources/mediumtest/xoo/sample");
 
-    TaskBuilder taskBuilder = tester
-      .newScanTask(new File(projectDir, "sonar-project.properties"))
+    AnalysisBuilder analysisBuilder = tester
+      .newAnalysis(new File(projectDir, "sonar-project.properties"))
       .property("sonar.report.export.path", "report.json");
     if (branch) {
-      taskBuilder.property("sonar.branch", "branch");
+      analysisBuilder.property("sonar.branch", "branch");
     } else {
-      taskBuilder.property("sonar.projectKey", projectKey);
+      analysisBuilder.property("sonar.projectKey", projectKey);
     }
 
-    TaskResult result = taskBuilder.execute();
+    AnalysisResult result = analysisBuilder.execute();
     /*
      * We have:
      * 6 new issues per line (open) in helloscala.xoo
@@ -169,16 +169,16 @@ public class ScanOnlyChangedTest {
   public void testScanAll() throws Exception {
     File projectDir = copyProject("test-resources/mediumtest/xoo/sample");
 
-    TaskBuilder taskBuilder = tester
-      .newScanTask(new File(projectDir, "sonar-project.properties"))
+    AnalysisBuilder analysisBuilder = tester
+      .newAnalysis(new File(projectDir, "sonar-project.properties"))
       .property("sonar.scanAllFiles", "true");
     if (branch) {
-      taskBuilder.property("sonar.branch", "branch");
+      analysisBuilder.property("sonar.branch", "branch");
     } else {
-      taskBuilder.property("sonar.projectKey", projectKey);
+      analysisBuilder.property("sonar.projectKey", projectKey);
     }
 
-    TaskResult result = taskBuilder.execute();
+    AnalysisResult result = analysisBuilder.execute();
 
     assertNumberIssues(result, 16, 2, 0);
 
@@ -188,7 +188,7 @@ public class ScanOnlyChangedTest {
     assertNumberIssuesOnFile(result, "HelloJava.xoo", 8);
   }
 
-  private static void assertNumberIssuesOnFile(TaskResult result, final String fileNameEndsWith, int issues) {
+  private static void assertNumberIssuesOnFile(AnalysisResult result, final String fileNameEndsWith, int issues) {
     assertThat(result.trackedIssues()).haveExactly(issues, new Condition<TrackedIssue>() {
       @Override
       public boolean matches(TrackedIssue value) {
@@ -197,7 +197,7 @@ public class ScanOnlyChangedTest {
     });
   }
 
-  private static void assertNumberIssues(TaskResult result, int expectedNew, int expectedOpen, int expectedResolved) {
+  private static void assertNumberIssues(AnalysisResult result, int expectedNew, int expectedOpen, int expectedResolved) {
     int newIssues = 0;
     int openIssues = 0;
     int resolvedIssue = 0;
index 40c99d9673b60f3bbffdce120d0f6021a0c8d439..feae49a1bbe5b3b7d55abd654fbd8e39238ae3b3 100644 (file)
@@ -66,7 +66,7 @@ public class ExceptionHandlingMediumTest {
     thrown.expectMessage("Error loading settings");
     thrown.expectCause(CoreMatchers.nullValue(Throwable.class));
 
-    batch.start();
+    batch.execute();
   }
 
   @Test
@@ -87,7 +87,7 @@ public class ExceptionHandlingMediumTest {
       }
     });
 
-    batch.start();
+    batch.execute();
   }
 
   @Test
@@ -95,7 +95,7 @@ public class ExceptionHandlingMediumTest {
     setUp(true);
     thrown.expect(IllegalStateException.class);
     thrown.expectMessage("Unable to load component class");
-    batch.start();
+    batch.execute();
   }
 
   private static class ErrorSettingsLoader implements SettingsLoader {
index dbb76f12421a776a2d04f67baee509c777e325b9..74cdb214654d38ddf8515d0f3a55572edae3c8ea 100644 (file)
@@ -137,7 +137,7 @@ public class LogListenerTest {
     File xooFile = new File(srcDir, "sample.xoo");
     FileUtils.write(xooFile, "Sample xoo\ncontent");
 
-    tester.newTask()
+    tester.newAnalysis()
       .properties(builder
         .put("sonar.sources", "src")
         .put("sonar.verbose", "true")
@@ -160,7 +160,7 @@ public class LogListenerTest {
     File xooFile = new File(srcDir, "sample.xoo");
     FileUtils.write(xooFile, "Sample xoo\ncontent");
 
-    tester.newTask()
+    tester.newAnalysis()
       .properties(builder
         .put("sonar.sources", "src")
         .build())
@@ -184,7 +184,7 @@ public class LogListenerTest {
     File xooFile = new File(srcDir, "sample.xoo");
     FileUtils.write(xooFile, "Sample xoo\ncontent");
 
-    tester.newTask()
+    tester.newAnalysis()
       .properties(builder
         .put("sonar.sources", "src")
         .build())
@@ -212,7 +212,7 @@ public class LogListenerTest {
     FileUtils.write(xooFileMeasure, "foo:bar");
 
     try {
-      tester.newTask()
+      tester.newAnalysis()
         .properties(builder
           .put("sonar.sources", "src")
           .build())
index 3c766eee7e1370e11b1827f1ad56861ee5100c77..657abfc75347b4b8f95b81f251acfb32a20877c8 100644 (file)
@@ -32,7 +32,7 @@ import org.junit.rules.TemporaryFolder;
 import org.sonar.api.utils.log.LogTester;
 import org.sonar.api.utils.log.LoggerLevel;
 import org.sonar.scanner.mediumtest.ScannerMediumTester;
-import org.sonar.scanner.mediumtest.TaskResult;
+import org.sonar.scanner.mediumtest.AnalysisResult;
 import org.sonar.scanner.protocol.output.ScannerReport.Measure;
 import org.sonar.xoo.XooPlugin;
 
@@ -71,7 +71,7 @@ public class MeasuresMediumTest {
     File measures = new File(srcDir, "sample.xoo.measures");
     FileUtils.write(measures, "lines_to_cover:2");
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
@@ -88,7 +88,7 @@ public class MeasuresMediumTest {
     assertThat(allMeasures.get("com.foo.project:src/sample.xoo")).extracting("metricKey", "intValue.value")
       .containsOnly(tuple("lines_to_cover", 2));
 
-    result = tester.newTask()
+    result = tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
@@ -114,7 +114,7 @@ public class MeasuresMediumTest {
     File measures = new File(srcDir, "sample.xoo.measures");
     FileUtils.write(measures, "it_lines_to_cover:2");
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
@@ -144,7 +144,7 @@ public class MeasuresMediumTest {
     FileUtils.write(measures, "new_lines:2");
 
     try {
-      tester.newTask()
+      tester.newAnalysis()
         .properties(ImmutableMap.<String, String>builder()
           .put("sonar.task", "scan")
           .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
@@ -171,7 +171,7 @@ public class MeasuresMediumTest {
     File lineMeasures = new File(srcDir, "sample.xoo.linemeasures");
     FileUtils.write(lineMeasures, "ncloc_data:1=1;2=0;4=1");
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
@@ -197,7 +197,7 @@ public class MeasuresMediumTest {
     File projectMeasures = new File(baseDir, "module.measures");
     FileUtils.write(projectMeasures, "tests:10");
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
index fb63e3ef1e2f73c6fc29e6221d7bfbe381a3c69f..5b42f3e016c1d14b1f35448f1485aa7bc5365c03 100644 (file)
@@ -33,7 +33,7 @@ import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.utils.log.LogTester;
 import org.sonar.scanner.mediumtest.ScannerMediumTester;
-import org.sonar.scanner.mediumtest.ScannerMediumTester.TaskBuilder;
+import org.sonar.scanner.mediumtest.ScannerMediumTester.AnalysisBuilder;
 import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.scanner.protocol.output.ScannerReport.Changesets.Changeset;
 import org.sonar.scanner.protocol.output.ScannerReport.Component;
@@ -78,7 +78,7 @@ public class ScmMediumTest {
   public void testScmMeasure() throws IOException, URISyntaxException {
     File baseDir = prepareProject();
 
-    tester.newTask()
+    tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
@@ -134,7 +134,7 @@ public class ScmMediumTest {
     // Clear file content
     FileUtils.write(new File(baseDir, "src/sample.xoo"), "");
 
-    tester.newTask()
+    tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
@@ -159,7 +159,7 @@ public class ScmMediumTest {
     File xooFileWithoutBlame = new File(baseDir, "src/sample_no_blame.xoo");
     FileUtils.write(xooFileWithoutBlame, "Sample xoo\ncontent\n3\n4\n5");
 
-    tester.newTask()
+    tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
@@ -212,7 +212,7 @@ public class ScmMediumTest {
       "1,foo,2013-01-04\n" +
         "1,bar,2013-01-04\n");
 
-    tester.newTask()
+    tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
@@ -253,7 +253,7 @@ public class ScmMediumTest {
       "1,foo,2013-01-04\n" +
         "1,bar,2013-01-04\n");
 
-    TaskBuilder taskBuilder = tester.newTask()
+    AnalysisBuilder analysisBuilder = tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
@@ -267,7 +267,7 @@ public class ScmMediumTest {
         .put("sonar.scm.forceReloadAll", "true")
         .build());
 
-    taskBuilder.execute();
+    analysisBuilder.execute();
 
     ScannerReport.Changesets file1Scm = getChangesets(baseDir, "src/sample.xoo");
     assertThat(file1Scm).isNotNull();
@@ -281,7 +281,7 @@ public class ScmMediumTest {
 
     File baseDir = prepareProject();
 
-    tester.newTask()
+    tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
@@ -304,7 +304,7 @@ public class ScmMediumTest {
     File baseDir = prepareProject();
     new File(baseDir, ".xoo").createNewFile();
 
-    tester.newTask()
+    tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
@@ -350,7 +350,7 @@ public class ScmMediumTest {
 
     File baseDir = prepareProject();
 
-    tester.newTask()
+    tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
index e1be31c15ef36de0dda7ee2732173592dfdd0cef..b860f68f2623499625477f4ff0387f18e904e3c1 100644 (file)
@@ -28,7 +28,7 @@ import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.scanner.mediumtest.ScannerMediumTester;
-import org.sonar.scanner.mediumtest.TaskResult;
+import org.sonar.scanner.mediumtest.AnalysisResult;
 import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.xoo.XooPlugin;
 
@@ -57,7 +57,7 @@ public class SymbolMediumTest {
     // Highlight xoo symbol
     FileUtils.write(xooSymbolFile, "7:10,27");
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
@@ -86,7 +86,7 @@ public class SymbolMediumTest {
     // Highlight xoo symbol
     FileUtils.write(xooSymbolFile, "7:10,27:32");
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
index 47ce068d0cc38fe0d836196c132484a3f51abd76..7ec30f93bf7d4a5638abb6db6ecbcb9a5a5ae023 100644 (file)
@@ -48,7 +48,7 @@ public class TasksMediumTest {
 
   @Test
   public void listTasksIncludingBroken() throws Exception {
-    tester.newTask()
+    tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "list").build())
       .execute();
@@ -70,7 +70,7 @@ public class TasksMediumTest {
     thrown.expectMessage(
       "Unable to load component class org.sonar.scanner.mediumtest.tasks.TasksMediumTest$BrokenTask");
 
-    tester.newTask()
+    tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "broken").build())
       .execute();
@@ -78,7 +78,7 @@ public class TasksMediumTest {
 
   @Test(expected = MessageException.class)
   public void unsupportedTask() throws Exception {
-    tester.newTask()
+    tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "foo").build())
       .execute();
index 4ec599310bcb6ced04ba420658c9490025f1a354..20f5fbc1b49d5aeca639c15aa826f1166ee84c07 100644 (file)
@@ -32,7 +32,7 @@ import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.scanner.mediumtest.ScannerMediumTester;
-import org.sonar.scanner.mediumtest.TaskResult;
+import org.sonar.scanner.mediumtest.AnalysisResult;
 import org.sonar.xoo.XooPlugin;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -91,7 +91,7 @@ public class CoveragePerTestMediumTest {
     FileUtils.write(xooCoveragePerTestFile, "some test;src/sample.xoo,10,11;src/sample2.xoo,1,2\n" +
       "another test;src/sample.xoo,10,20\n", StandardCharsets.UTF_8);
 
-    TaskResult result = runTask(baseDir);
+    AnalysisResult result = runTask(baseDir);
 
     InputFile file = result.inputFile("test/sampleTest.xoo");
     org.sonar.scanner.protocol.output.ScannerReport.CoverageDetail someTest = result.coveragePerTestFor(file, "some test");
@@ -107,8 +107,8 @@ public class CoveragePerTestMediumTest {
     assertThat(anotherTest.getCoveredFile(0).getCoveredLineList()).containsExactly(10, 20);
   }
 
-  private TaskResult runTask(File baseDir) {
-    return tester.newTask()
+  private AnalysisResult runTask(File baseDir) {
+    return tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
index 58d3efaa6cd70abb00888b8a9bc0bd42c1c7dd58..c2bbe13c732ad17b9de066dfcf574292f3557ede 100644 (file)
@@ -32,7 +32,7 @@ import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.measures.CoreMetrics;
 import org.sonar.scanner.mediumtest.ScannerMediumTester;
-import org.sonar.scanner.mediumtest.TaskResult;
+import org.sonar.scanner.mediumtest.AnalysisResult;
 import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.scanner.protocol.output.ScannerReport.Test.TestStatus;
 import org.sonar.xoo.XooPlugin;
@@ -72,8 +72,8 @@ public class GenericTestExecutionMediumTest {
       "error:2:Error:The stack:ERROR:UNIT\n" +
       "success:4:::OK:INTEGRATION", StandardCharsets.UTF_8);
 
-    TaskResult result = tester
-      .newTask()
+    AnalysisResult result = tester
+      .newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
@@ -103,9 +103,9 @@ public class GenericTestExecutionMediumTest {
 
     File projectDir = new File("test-resources/mediumtest/xoo/sample-generic-test-exec");
 
-    TaskResult result = tester
+    AnalysisResult result = tester
       .setLogOutput((msg, level) -> logs.add(msg))
-      .newScanTask(new File(projectDir, "sonar-project.properties"))
+      .newAnalysis(new File(projectDir, "sonar-project.properties"))
       .property("sonar.testExecutionReportPaths", "unittest.xml")
       .execute();
 
@@ -148,9 +148,9 @@ public class GenericTestExecutionMediumTest {
 
     File projectDir = new File("test-resources/mediumtest/xoo/sample-generic-test-exec");
 
-    TaskResult result = tester
+    AnalysisResult result = tester
       .setLogOutput((msg, level) -> logs.add(msg))
-      .newScanTask(new File(projectDir, "sonar-project.properties"))
+      .newAnalysis(new File(projectDir, "sonar-project.properties"))
       .property("sonar.testExecutionReportPaths", "unittest.xml,unittest2.xml")
       .execute();
 
index efcfcfcf8f37d88524cdb90ca0eba712cc3d6603..1a39263ce8ac51ad59787f7810ffa6a58d0add93 100644 (file)
@@ -28,7 +28,7 @@ import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.scanner.mediumtest.ScannerMediumTester;
-import org.sonar.scanner.mediumtest.TaskResult;
+import org.sonar.scanner.mediumtest.AnalysisResult;
 import org.sonar.scanner.protocol.output.ScannerReport.Test.TestStatus;
 import org.sonar.xoo.XooPlugin;
 
@@ -65,7 +65,7 @@ public class TestExecutionMediumTest {
       "error:2:Error:The stack:ERROR:UNIT\n" +
       "success:4:::OK:INTEGRATION");
 
-    TaskResult result = tester.newTask()
+    AnalysisResult result = tester.newAnalysis()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
index e06b46e342aa73a7c80031982bfd5c32af3cccdc..6d95e2ff8286db5bedcfc1af20bbfe4f5b18be6a 100644 (file)
@@ -26,24 +26,22 @@ import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
-import org.sonar.api.config.PropertyDefinitions;
-import org.sonar.api.config.internal.MapSettings;
-import org.sonar.core.config.ExclusionProperties;
+import org.sonar.scanner.scan.ModuleConfiguration;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 public class ModuleCoverageExclusionsTest {
 
   @Rule
   public TemporaryFolder temp = new TemporaryFolder();
 
-  private MapSettings settings;
   private ModuleCoverageExclusions coverageExclusions;
   private File baseDir;
 
   @Before
   public void prepare() throws Exception {
-    settings = new MapSettings(new PropertyDefinitions(ExclusionProperties.all()));
     baseDir = temp.newFolder();
   }
 
@@ -52,8 +50,7 @@ public class ModuleCoverageExclusionsTest {
     DefaultInputFile file = TestInputFileBuilder.create("foo", new File(baseDir, "moduleA"), new File(baseDir, "moduleA/src/org/polop/File.php"))
       .setProjectBaseDir(baseDir.toPath())
       .build();
-    settings.setProperty("sonar.coverage.exclusions", "src/org/polop/*");
-    coverageExclusions = new ModuleCoverageExclusions(settings.asConfig());
+    coverageExclusions = new ModuleCoverageExclusions(mockConfig("src/org/polop/*"));
     assertThat(coverageExclusions.isExcluded(file)).isTrue();
   }
 
@@ -62,8 +59,13 @@ public class ModuleCoverageExclusionsTest {
     DefaultInputFile file = TestInputFileBuilder.create("foo", new File(baseDir, "moduleA"), new File(baseDir, "moduleA/src/org/polop/File.php"))
       .setProjectBaseDir(baseDir.toPath())
       .build();
-    settings.setProperty("sonar.coverage.exclusions", "src/org/other/*");
-    coverageExclusions = new ModuleCoverageExclusions(settings.asConfig());
+    coverageExclusions = new ModuleCoverageExclusions(mockConfig("src/org/other/*"));
     assertThat(coverageExclusions.isExcluded(file)).isFalse();
   }
+
+  private ModuleConfiguration mockConfig(String... values) {
+    ModuleConfiguration config = mock(ModuleConfiguration.class);
+    when(config.getStringArray("sonar.coverage.exclusions")).thenReturn(values);
+    return config;
+  }
 }
index 9315cdeb943bf9f33194336a00b680c9d02df4f4..e55df705a6d8b9ab7ccd8ff675c4a22daf032c70 100644 (file)
@@ -26,24 +26,22 @@ import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
-import org.sonar.api.config.PropertyDefinitions;
-import org.sonar.api.config.internal.MapSettings;
-import org.sonar.core.config.ExclusionProperties;
+import org.sonar.scanner.scan.ProjectConfiguration;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 public class ProjectCoverageExclusionsTest {
 
   @Rule
   public TemporaryFolder temp = new TemporaryFolder();
 
-  private MapSettings settings;
   private ProjectCoverageExclusions coverageExclusions;
   private File baseDir;
 
   @Before
   public void prepare() throws Exception {
-    settings = new MapSettings(new PropertyDefinitions(ExclusionProperties.all()));
     baseDir = temp.newFolder();
   }
 
@@ -52,8 +50,7 @@ public class ProjectCoverageExclusionsTest {
     DefaultInputFile file = TestInputFileBuilder.create("foo", new File(baseDir, "moduleA"), new File(baseDir, "moduleA/src/org/polop/File.php"))
       .setProjectBaseDir(baseDir.toPath())
       .build();
-    settings.setProperty("sonar.coverage.exclusions", "moduleA/src/org/polop/*");
-    coverageExclusions = new ProjectCoverageExclusions(settings.asConfig());
+    coverageExclusions = new ProjectCoverageExclusions(mockConfig("moduleA/src/org/polop/*"));
     assertThat(coverageExclusions.isExcluded(file)).isTrue();
   }
 
@@ -62,8 +59,14 @@ public class ProjectCoverageExclusionsTest {
     DefaultInputFile file = TestInputFileBuilder.create("foo", new File(baseDir, "moduleA"), new File(baseDir, "moduleA/src/org/polop/File.php"))
       .setProjectBaseDir(baseDir.toPath())
       .build();
-    settings.setProperty("sonar.coverage.exclusions", "moduleA/src/org/other/*");
-    coverageExclusions = new ProjectCoverageExclusions(settings.asConfig());
+    coverageExclusions = new ProjectCoverageExclusions(mockConfig("moduleA/src/org/other/*"));
     assertThat(coverageExclusions.isExcluded(file)).isFalse();
   }
+
+  private ProjectConfiguration mockConfig(String... values) {
+    ProjectConfiguration config = mock(ProjectConfiguration.class);
+    when(config.getStringArray("sonar.coverage.exclusions")).thenReturn(values);
+    return config;
+  }
+
 }
index 2159a51ee1503a4d9a7bbcaf436e50fcda92c721..9b1db0a0229c87f16d1346e854c0bba69c4b37cd 100644 (file)
@@ -42,7 +42,7 @@ public class DefaultServerTest {
     ScannerWsClient client = mock(ScannerWsClient.class);
     when(client.baseUrl()).thenReturn("http://foo.com");
 
-    DefaultServer metadata = new DefaultServer(settings, client, SonarRuntimeImpl.forSonarQube(Version.parse("2.2"), SonarQubeSide.SCANNER));
+    DefaultServer metadata = new DefaultServer(((MapSettings) settings).asConfig(), client, SonarRuntimeImpl.forSonarQube(Version.parse("2.2"), SonarQubeSide.SCANNER));
 
     assertThat(metadata.getId()).isEqualTo("123");
     assertThat(metadata.getVersion()).isEqualTo("2.2");
@@ -61,7 +61,7 @@ public class DefaultServerTest {
     Settings settings = new MapSettings();
     ScannerWsClient client = mock(ScannerWsClient.class);
     when(client.baseUrl()).thenReturn("http://foo.com/");
-    DefaultServer metadata = new DefaultServer(settings, client, null);
+    DefaultServer metadata = new DefaultServer(((MapSettings) settings).asConfig(), client, null);
 
     settings.setProperty(CoreProperties.SERVER_BASE_URL, "http://server.com/");
     assertThat(metadata.getPublicRootUrl()).isEqualTo("http://server.com");
@@ -75,7 +75,7 @@ public class DefaultServerTest {
     Settings settings = new MapSettings();
     settings.setProperty(CoreProperties.SERVER_STARTTIME, "invalid");
     ScannerWsClient client = mock(ScannerWsClient.class);
-    DefaultServer metadata = new DefaultServer(settings, client, null);
+    DefaultServer metadata = new DefaultServer(((MapSettings) settings).asConfig(), client, null);
     metadata.getStartedAt();
   }
 }
index d757a265844b04f8b1811f527ca689a04a4c89d4..245fe2cefc1a4cb9e4bebf731376ca08105bbabb 100644 (file)
@@ -26,7 +26,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.AnalysisMode;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
 import org.sonar.api.batch.postjob.issue.PostJobIssue;
 import org.sonar.api.batch.rule.Severity;
@@ -54,8 +54,8 @@ public class DefaultPostJobContextTest {
   @Before
   public void setUp() throws IOException {
     issueCache = mock(IssueCache.class);
-    DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule("foo", temp.newFolder());
-    componentStore = new InputComponentStore(rootModule, mock(BranchConfiguration.class));
+    DefaultInputProject project = TestInputFileBuilder.newDefaultInputProject("foo", temp.newFolder());
+    componentStore = new InputComponentStore(project, mock(BranchConfiguration.class));
     settings = new MapSettings();
     analysisMode = mock(AnalysisMode.class);
     context = new DefaultPostJobContext(settings.asConfig(), settings, issueCache, componentStore, analysisMode);
index 457166e003748df73233ddee59f865ab036bd3cd..cbd14aa19c4a7396bf0625f616db27d183141bb4 100644 (file)
@@ -40,7 +40,7 @@ import org.sonar.api.utils.System2;
 import org.sonar.api.utils.log.LogTester;
 import org.sonar.api.utils.log.LoggerLevel;
 import org.sonar.core.platform.PluginInfo;
-import org.sonar.scanner.bootstrap.GlobalConfiguration;
+import org.sonar.scanner.bootstrap.GlobalServerSettings;
 import org.sonar.scanner.bootstrap.ScannerPluginRepository;
 import org.sonar.scanner.protocol.output.ScannerReportWriter;
 import org.sonar.scanner.repository.ProjectRepositories;
@@ -69,7 +69,7 @@ public class AnalysisContextReportPublisherTest {
   private AnalysisMode analysisMode = mock(AnalysisMode.class);
   private System2 system2;
   private ProjectRepositories projectRepos;
-  private GlobalConfiguration globalSettings;
+  private GlobalServerSettings globalServerSettings;
   private InputModuleHierarchy hierarchy;
 
   @Before
@@ -78,9 +78,9 @@ public class AnalysisContextReportPublisherTest {
     system2 = mock(System2.class);
     when(system2.properties()).thenReturn(new Properties());
     projectRepos = mock(ProjectRepositories.class);
-    globalSettings = mock(GlobalConfiguration.class);
+    globalServerSettings = mock(GlobalServerSettings.class);
     hierarchy = mock(InputModuleHierarchy.class);
-    publisher = new AnalysisContextReportPublisher(analysisMode, pluginRepo, system2, projectRepos, globalSettings, hierarchy);
+    publisher = new AnalysisContextReportPublisher(analysisMode, pluginRepo, system2, projectRepos, globalServerSettings, hierarchy);
   }
 
   @Test
@@ -111,7 +111,7 @@ public class AnalysisContextReportPublisherTest {
   public void dumpServerSideGlobalProps() throws Exception {
     logTester.setLevel(LoggerLevel.DEBUG);
     ScannerReportWriter writer = new ScannerReportWriter(temp.newFolder());
-    when(globalSettings.getServerSideSettings()).thenReturn(ImmutableMap.of(COM_FOO, "bar", SONAR_SKIP, "true"));
+    when(globalServerSettings.properties()).thenReturn(ImmutableMap.of(COM_FOO, "bar", SONAR_SKIP, "true"));
 
     publisher.init(writer);
 
@@ -238,7 +238,7 @@ public class AnalysisContextReportPublisherTest {
   @Test
   public void shouldNotDumpSensitiveGlobalProperties() throws Exception {
     ScannerReportWriter writer = new ScannerReportWriter(temp.newFolder());
-    when(globalSettings.getServerSideSettings()).thenReturn(ImmutableMap.of("sonar.login", "my_token", "sonar.password", "azerty", "sonar.cpp.license.secured", "AZERTY"));
+    when(globalServerSettings.properties()).thenReturn(ImmutableMap.of("sonar.login", "my_token", "sonar.password", "azerty", "sonar.cpp.license.secured", "AZERTY"));
 
     publisher.init(writer);
 
index c5de50d132e70a8bcfc884049da9707bc8dc0e1d..b45964ecad6bcbc0f63e13326d3b8ad7a98902ce 100644 (file)
@@ -31,7 +31,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
 import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
 import org.sonar.api.batch.scm.ScmProvider;
@@ -56,11 +56,12 @@ public class ChangedLinesPublisherTest {
   private BranchConfiguration branchConfiguration = mock(BranchConfiguration.class);
   private ScannerReportWriter writer;
   private ScmProvider provider = mock(ScmProvider.class);
+  private DefaultInputProject project = mock(DefaultInputProject.class);
 
   @Rule
   public TemporaryFolder temp = new TemporaryFolder();
 
-  private ChangedLinesPublisher publisher = new ChangedLinesPublisher(scmConfiguration, inputModuleHierarchy, inputComponentStore, branchConfiguration);
+  private ChangedLinesPublisher publisher = new ChangedLinesPublisher(scmConfiguration, project, inputComponentStore, branchConfiguration);
 
   @Before
   public void setUp() {
@@ -69,9 +70,7 @@ public class ChangedLinesPublisherTest {
     when(scmConfiguration.isDisabled()).thenReturn(false);
     when(scmConfiguration.provider()).thenReturn(provider);
     when(branchConfiguration.targetScmBranch()).thenReturn(TARGET_BRANCH);
-    DefaultInputModule root = mock(DefaultInputModule.class);
-    when(root.getBaseDir()).thenReturn(BASE_DIR);
-    when(inputModuleHierarchy.root()).thenReturn(root);
+    when(project.getBaseDir()).thenReturn(BASE_DIR);
   }
 
   @Test
@@ -135,13 +134,13 @@ public class ChangedLinesPublisherTest {
   }
 
   private void assertPublished(DefaultInputFile file, Set<Integer> lines) {
-    assertThat(new File(temp.getRoot(), "changed-lines-" + file.batchId() + ".pb")).exists();
+    assertThat(new File(temp.getRoot(), "changed-lines-" + file.scannerId() + ".pb")).exists();
     ScannerReportReader reader = new ScannerReportReader(temp.getRoot());
-    assertThat(reader.readComponentChangedLines(file.batchId()).getLineList()).containsExactlyElementsOf(lines);
+    assertThat(reader.readComponentChangedLines(file.scannerId()).getLineList()).containsExactlyElementsOf(lines);
   }
 
   private void assertNotPublished(DefaultInputFile file) {
-    assertThat(new File(temp.getRoot(), "changed-lines-" + file.batchId() + ".pb")).doesNotExist();
+    assertThat(new File(temp.getRoot(), "changed-lines-" + file.scannerId() + ".pb")).doesNotExist();
   }
 
   private void assertNotPublished() {
index 15c1d16ba1124f6eb3e35ff436789cf2fc34f338..4b27f676ae92a337fa0d5777bfeda3a2fe8e664f 100644 (file)
@@ -233,7 +233,7 @@ public class ComponentsPublisherTest {
     Map<DefaultInputModule, DefaultInputModule> modules = new HashMap<>();
     modules.put(module2, module1);
     modules.put(module1, root);
-    moduleHierarchy = new DefaultInputModuleHierarchy(modules);
+    moduleHierarchy = new DefaultInputModuleHierarchy(root, modules);
     tree.index(module2, module1);
     tree.index(module1, root);
     ComponentsPublisher publisher = new ComponentsPublisher(moduleHierarchy, tree, branchConfiguration);
@@ -674,7 +674,7 @@ public class ComponentsPublisherTest {
     DefaultInputFile mod1_mod2_dir_file = newDefaultInputFile(root.getBaseDir(), mod1_mod2, "dir/Foo.java");
     tree.index(mod1_mod2_dir_file, mod1_mod2_dir);
 
-    moduleHierarchy = new DefaultInputModuleHierarchy(parents);
+    moduleHierarchy = new DefaultInputModuleHierarchy(root, parents);
 
     ComponentsPublisher publisher = new ComponentsPublisher(moduleHierarchy, tree, branchConfiguration);
     publisher.publish(writer);
@@ -682,51 +682,51 @@ public class ComponentsPublisherTest {
     ScannerReportReader reader = new ScannerReportReader(outputDir);
 
     // project root
-    assertThat(reader.readComponent(root.batchId()).getPath()).isEmpty();
-    assertThat(reader.readComponent(root.batchId()).getProjectRelativePath()).isEmpty();
+    assertThat(reader.readComponent(root.scannerId()).getPath()).isEmpty();
+    assertThat(reader.readComponent(root.scannerId()).getProjectRelativePath()).isEmpty();
 
     // file in root
-    assertThat(reader.readComponent(file.batchId()).getPath()).isEqualTo("Foo.java");
-    assertThat(reader.readComponent(file.batchId()).getProjectRelativePath()).isEqualTo("Foo.java");
+    assertThat(reader.readComponent(file.scannerId()).getPath()).isEqualTo("Foo.java");
+    assertThat(reader.readComponent(file.scannerId()).getProjectRelativePath()).isEqualTo("Foo.java");
 
     // dir in root
-    assertThat(reader.readComponent(dir1.batchId()).getPath()).isEqualTo("dir1");
-    assertThat(reader.readComponent(dir1.batchId()).getProjectRelativePath()).isEqualTo("dir1");
+    assertThat(reader.readComponent(dir1.scannerId()).getPath()).isEqualTo("dir1");
+    assertThat(reader.readComponent(dir1.scannerId()).getProjectRelativePath()).isEqualTo("dir1");
 
     // file in dir in root
-    assertThat(reader.readComponent(dir1_file.batchId()).getPath()).isEqualTo("dir1/Foo.java");
-    assertThat(reader.readComponent(dir1_file.batchId()).getProjectRelativePath()).isEqualTo("dir1/Foo.java");
+    assertThat(reader.readComponent(dir1_file.scannerId()).getPath()).isEqualTo("dir1/Foo.java");
+    assertThat(reader.readComponent(dir1_file.scannerId()).getProjectRelativePath()).isEqualTo("dir1/Foo.java");
 
     // dir in dir in root
-    assertThat(reader.readComponent(dir1_dir1.batchId()).getPath()).isEqualTo("dir1/dir1");
-    assertThat(reader.readComponent(dir1_dir1.batchId()).getProjectRelativePath()).isEqualTo("dir1/dir1");
+    assertThat(reader.readComponent(dir1_dir1.scannerId()).getPath()).isEqualTo("dir1/dir1");
+    assertThat(reader.readComponent(dir1_dir1.scannerId()).getProjectRelativePath()).isEqualTo("dir1/dir1");
 
     // module in root
-    assertThat(reader.readComponent(mod1.batchId()).getPath()).isEqualTo("mod1");
-    assertThat(reader.readComponent(mod1.batchId()).getProjectRelativePath()).isEqualTo("mod1");
+    assertThat(reader.readComponent(mod1.scannerId()).getPath()).isEqualTo("mod1");
+    assertThat(reader.readComponent(mod1.scannerId()).getProjectRelativePath()).isEqualTo("mod1");
 
     // dir in module in root
-    assertThat(reader.readComponent(mod1_dir2.batchId()).getPath()).isEqualTo("dir2");
-    assertThat(reader.readComponent(mod1_dir2.batchId()).getProjectRelativePath()).isEqualTo("mod1/dir2");
+    assertThat(reader.readComponent(mod1_dir2.scannerId()).getPath()).isEqualTo("dir2");
+    assertThat(reader.readComponent(mod1_dir2.scannerId()).getProjectRelativePath()).isEqualTo("mod1/dir2");
 
     // file in dir in module in root
-    assertThat(reader.readComponent(mod1_dir2_file.batchId()).getPath()).isEqualTo("dir2/Foo.java");
-    assertThat(reader.readComponent(mod1_dir2_file.batchId()).getProjectRelativePath()).isEqualTo("mod1/dir2/Foo.java");
+    assertThat(reader.readComponent(mod1_dir2_file.scannerId()).getPath()).isEqualTo("dir2/Foo.java");
+    assertThat(reader.readComponent(mod1_dir2_file.scannerId()).getProjectRelativePath()).isEqualTo("mod1/dir2/Foo.java");
 
     // module in module
-    assertThat(reader.readComponent(mod1_mod2.batchId()).getPath()).isEqualTo("mod2");
-    assertThat(reader.readComponent(mod1_mod2.batchId()).getProjectRelativePath()).isEqualTo("mod1/mod2");
+    assertThat(reader.readComponent(mod1_mod2.scannerId()).getPath()).isEqualTo("mod2");
+    assertThat(reader.readComponent(mod1_mod2.scannerId()).getProjectRelativePath()).isEqualTo("mod1/mod2");
 
     // file in module in module
-    assertThat(reader.readComponent(mod1_mod2_file.batchId()).getPath()).isEqualTo("Foo.java");
-    assertThat(reader.readComponent(mod1_mod2_file.batchId()).getProjectRelativePath()).isEqualTo("mod1/mod2/Foo.java");
+    assertThat(reader.readComponent(mod1_mod2_file.scannerId()).getPath()).isEqualTo("Foo.java");
+    assertThat(reader.readComponent(mod1_mod2_file.scannerId()).getProjectRelativePath()).isEqualTo("mod1/mod2/Foo.java");
 
     // dir in module in module
-    assertThat(reader.readComponent(mod1_mod2_dir.batchId()).getPath()).isEqualTo("dir");
-    assertThat(reader.readComponent(mod1_mod2_dir.batchId()).getProjectRelativePath()).isEqualTo("mod1/mod2/dir");
+    assertThat(reader.readComponent(mod1_mod2_dir.scannerId()).getPath()).isEqualTo("dir");
+    assertThat(reader.readComponent(mod1_mod2_dir.scannerId()).getProjectRelativePath()).isEqualTo("mod1/mod2/dir");
 
     // file in dir in module in module
-    assertThat(reader.readComponent(mod1_mod2_dir_file.batchId()).getPath()).isEqualTo("dir/Foo.java");
-    assertThat(reader.readComponent(mod1_mod2_dir_file.batchId()).getProjectRelativePath()).isEqualTo("mod1/mod2/dir/Foo.java");
+    assertThat(reader.readComponent(mod1_mod2_dir_file.scannerId()).getPath()).isEqualTo("dir/Foo.java");
+    assertThat(reader.readComponent(mod1_mod2_dir_file.scannerId()).getProjectRelativePath()).isEqualTo("mod1/mod2/dir/Foo.java");
   }
 }
index 9ca8039bfef3d19532103c69a27039fd68d6c265..d2cc7ac178d66fcfd7c7a6e4200f0af5c225f2d7 100644 (file)
@@ -26,7 +26,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
 import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure;
 import org.sonar.api.measures.CoreMetrics;
@@ -57,7 +57,7 @@ public class CoveragePublisherTest {
   public void prepare() throws IOException {
     String moduleKey = "foo";
     inputFile = new TestInputFileBuilder(moduleKey, "src/Foo.php").setLines(5).build();
-    DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule(moduleKey, temp.newFolder());
+    DefaultInputProject rootModule = TestInputFileBuilder.newDefaultInputProject(moduleKey, temp.newFolder());
     InputComponentStore componentCache = new InputComponentStore(rootModule, mock(BranchConfiguration.class));
     componentCache.put(inputFile);
 
@@ -83,7 +83,7 @@ public class CoveragePublisherTest {
 
     publisher.publish(writer);
 
-    try (CloseableIterator<LineCoverage> it = new ScannerReportReader(outputDir).readComponentCoverage(inputFile.batchId())) {
+    try (CloseableIterator<LineCoverage> it = new ScannerReportReader(outputDir).readComponentCoverage(inputFile.scannerId())) {
       assertThat(it.next()).isEqualTo(LineCoverage.newBuilder()
         .setLine(2)
         .setHits(true)
index 33e9af10e173a8aa0f79e1e25468b22fe66c6f47..08cb3b61e3c0b877ba81bf063a03bd256fe35e8a 100644 (file)
@@ -29,7 +29,7 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
 import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure;
 import org.sonar.api.measures.CoreMetrics;
@@ -62,14 +62,14 @@ public class MeasuresPublisherTest {
   private File outputDir;
   private ScannerReportWriter writer;
   private DefaultInputFile inputFile;
-  private DefaultInputModule inputModule;
+  private DefaultInputProject project;
 
   @Before
   public void prepare() throws IOException {
-    String moduleKey = "foo";
-    inputModule = TestInputFileBuilder.newDefaultInputModule(moduleKey, temp.newFolder());
-    inputFile = new TestInputFileBuilder(moduleKey, "src/Foo.php").setPublish(true).build();
-    InputComponentStore componentCache = new InputComponentStore(inputModule, mock(BranchConfiguration.class));
+    String projectKey = "foo";
+    project = TestInputFileBuilder.newDefaultInputProject(projectKey, temp.newFolder());
+    inputFile = new TestInputFileBuilder(projectKey, "src/Foo.php").setPublish(true).build();
+    InputComponentStore componentCache = new InputComponentStore(project, mock(BranchConfiguration.class));
     componentCache.put(inputFile);
     measureCache = mock(MeasureCache.class);
     when(measureCache.byComponentKey(anyString())).thenReturn(Collections.<DefaultMeasure<?>>emptyList());
@@ -90,8 +90,8 @@ public class MeasuresPublisherTest {
     publisher.publish(writer);
     ScannerReportReader reader = new ScannerReportReader(outputDir);
 
-    assertThat(reader.readComponentMeasures(inputModule.batchId())).hasSize(0);
-    try (CloseableIterator<ScannerReport.Measure> componentMeasures = reader.readComponentMeasures(inputFile.batchId())) {
+    assertThat(reader.readComponentMeasures(project.scannerId())).hasSize(0);
+    try (CloseableIterator<ScannerReport.Measure> componentMeasures = reader.readComponentMeasures(inputFile.scannerId())) {
       assertThat(componentMeasures).hasSize(2);
     }
   }
index 5831a40d59d7c06e8878156442f3fd9afbd92326..5eda8a2114d1abbb247721754cb706f3cd066c2c 100644 (file)
@@ -43,8 +43,8 @@ import org.sonar.scanner.cpd.CpdSettings;
 import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.scanner.protocol.output.ScannerReportReader;
 import org.sonar.scanner.protocol.output.ScannerReportWriter;
-import org.sonar.scanner.rule.QualityProfiles;
 import org.sonar.scanner.rule.QProfile;
+import org.sonar.scanner.rule.QualityProfiles;
 import org.sonar.scanner.scan.ScanProperties;
 import org.sonar.scanner.scan.branch.BranchConfiguration;
 import org.sonar.scanner.scan.branch.BranchType;
index 8bbd9d4e11a4c211cd5cc6620419ef82064ec392..f6840f3b1754b25b3f224191439ee8e7a3ab1b55 100644 (file)
@@ -28,7 +28,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
 import org.sonar.scanner.protocol.output.ScannerReportWriter;
 import org.sonar.scanner.scan.branch.BranchConfiguration;
@@ -57,8 +57,8 @@ public class SourcePublisherTest {
       .setCharset(StandardCharsets.ISO_8859_1)
       .build();
 
-    DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule(moduleKey, baseDir);
-    InputComponentStore componentStore = new InputComponentStore(rootModule, mock(BranchConfiguration.class));
+    DefaultInputProject rootProject = TestInputFileBuilder.newDefaultInputProject(moduleKey, baseDir);
+    InputComponentStore componentStore = new InputComponentStore(rootProject, mock(BranchConfiguration.class));
     componentStore.put(inputFile);
 
     publisher = new SourcePublisher(componentStore);
@@ -72,7 +72,7 @@ public class SourcePublisherTest {
 
     publisher.publish(writer);
 
-    File out = writer.getSourceFile(inputFile.batchId());
+    File out = writer.getSourceFile(inputFile.scannerId());
     assertThat(FileUtils.readFileToString(out, StandardCharsets.UTF_8)).isEqualTo("");
   }
 
@@ -82,7 +82,7 @@ public class SourcePublisherTest {
 
     publisher.publish(writer);
 
-    File out = writer.getSourceFile(inputFile.batchId());
+    File out = writer.getSourceFile(inputFile.scannerId());
     assertThat(FileUtils.readFileToString(out, StandardCharsets.UTF_8)).isEqualTo("1\n2\n3\n4\n");
   }
 
@@ -93,7 +93,7 @@ public class SourcePublisherTest {
 
     publisher.publish(writer);
 
-    File out = writer.getSourceFile(inputFile.batchId());
+    File out = writer.getSourceFile(inputFile.scannerId());
     assertThat(FileUtils.readFileToString(out, StandardCharsets.UTF_8)).isEqualTo("1\n2\n3\n4\n");
   }
 
@@ -103,7 +103,7 @@ public class SourcePublisherTest {
 
     publisher.publish(writer);
 
-    File out = writer.getSourceFile(inputFile.batchId());
+    File out = writer.getSourceFile(inputFile.scannerId());
     assertThat(FileUtils.readFileToString(out, StandardCharsets.UTF_8)).isEqualTo("1\n2\n3\n4\n5");
   }
 
@@ -113,7 +113,7 @@ public class SourcePublisherTest {
 
     publisher.publish(writer);
 
-    File out = writer.getSourceFile(inputFile.batchId());
+    File out = writer.getSourceFile(inputFile.scannerId());
     assertThat(FileUtils.readFileToString(out, StandardCharsets.UTF_8)).isEqualTo("\n2\n3\n4\n5");
   }
 
index f57f5a3acc55e1c1b858af02556da286dd1802cd..6e39fe912da617dab15e81ce1e279ca9f6d3516c 100644 (file)
@@ -26,8 +26,8 @@ import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
-import org.sonar.api.batch.bootstrap.ProjectKey;
 import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
+import org.sonar.scanner.bootstrap.ScannerProperties;
 import org.sonar.scanner.scan.branch.BranchConfiguration;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -45,7 +45,7 @@ public class ProjectRepositoriesProviderTest {
   @Mock
   private ProjectRepositoriesLoader loader;
   @Mock
-  private ProjectKey projectKey;
+  private ScannerProperties props;
   @Mock
   private GlobalAnalysisMode mode;
   @Mock
@@ -61,7 +61,7 @@ public class ProjectRepositoriesProviderTest {
     project = new ProjectRepositories(t1, t2, new Date());
     provider = new ProjectRepositoriesProvider();
 
-    when(projectKey.get()).thenReturn("key");
+    when(props.getKeyWithBranch()).thenReturn("key");
   }
 
   @Test
@@ -69,7 +69,7 @@ public class ProjectRepositoriesProviderTest {
     when(mode.isIssues()).thenReturn(true);
     when(loader.load(eq("key"), eq(true), any())).thenReturn(project);
 
-    provider.provide(loader, projectKey, mode, branchConfiguration);
+    provider.provide(loader, props, mode, branchConfiguration);
   }
 
   @Test
@@ -77,14 +77,14 @@ public class ProjectRepositoriesProviderTest {
     when(mode.isIssues()).thenReturn(false);
     when(loader.load(eq("key"), eq(false), any())).thenReturn(project);
 
-    ProjectRepositories repo = provider.provide(loader, projectKey, mode, branchConfiguration);
+    ProjectRepositories repo = provider.provide(loader, props, mode, branchConfiguration);
 
     assertThat(repo.exists()).isEqualTo(true);
     assertThat(repo.lastAnalysisDate()).isNotNull();
 
     verify(mode, times(1)).isIssues();
-    verify(projectKey).get();
+    verify(props).getKeyWithBranch();
     verify(loader).load(eq("key"), eq(false), eq(null));
-    verifyNoMoreInteractions(loader, projectKey, mode);
+    verifyNoMoreInteractions(loader, props, mode);
   }
 }
index 5c715af7e3abaecc35c1e41054e38b1155c6f9b2..4ef1c77b08345217fbc9a3c6e0a8e39168f28e3b 100644 (file)
@@ -28,11 +28,10 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
-import org.sonar.api.batch.bootstrap.ProjectKey;
 import org.sonar.api.utils.DateUtils;
 import org.sonar.api.utils.log.LogTester;
 import org.sonar.api.utils.log.LoggerLevel;
-import org.sonar.scanner.analysis.AnalysisProperties;
+import org.sonar.scanner.bootstrap.ScannerProperties;
 import org.sonar.scanner.rule.QualityProfiles;
 import org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile;
 
@@ -53,9 +52,7 @@ public class QualityProfileProviderTest {
   @Mock
   private QualityProfileLoader loader;
   @Mock
-  private AnalysisProperties props;
-  @Mock
-  private ProjectKey key;
+  private ScannerProperties props;
   @Mock
   private ProjectRepositories projectRepo;
 
@@ -66,7 +63,7 @@ public class QualityProfileProviderTest {
     MockitoAnnotations.initMocks(this);
     qualityProfileProvider = new QualityProfilesProvider();
 
-    when(key.get()).thenReturn("project");
+    when(props.getKeyWithBranch()).thenReturn("project");
     when(projectRepo.exists()).thenReturn(true);
 
     response = new ArrayList<>(1);
@@ -76,7 +73,7 @@ public class QualityProfileProviderTest {
   @Test
   public void testProvide() {
     when(loader.load("project", null)).thenReturn(response);
-    QualityProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props);
+    QualityProfiles qps = qualityProfileProvider.provide(loader, projectRepo, props);
     assertResponse(qps);
 
     verify(loader).load("project", null);
@@ -88,7 +85,7 @@ public class QualityProfileProviderTest {
     when(projectRepo.exists()).thenReturn(false);
     when(loader.loadDefault(anyString())).thenReturn(response);
     when(props.property(QualityProfiles.SONAR_PROFILE_PROP)).thenReturn("profile");
-    QualityProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props);
+    QualityProfiles qps = qualityProfileProvider.provide(loader, projectRepo, props);
     assertResponse(qps);
 
     verify(loader).loadDefault(anyString());
@@ -101,7 +98,7 @@ public class QualityProfileProviderTest {
     when(props.property(QualityProfiles.SONAR_PROFILE_PROP)).thenReturn("custom");
     when(props.properties()).thenReturn(ImmutableMap.of(QualityProfiles.SONAR_PROFILE_PROP, "custom"));
 
-    QualityProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props);
+    QualityProfiles qps = qualityProfileProvider.provide(loader, projectRepo, props);
     assertResponse(qps);
 
     verify(loader).load(eq("project"), eq("custom"));
@@ -117,7 +114,7 @@ public class QualityProfileProviderTest {
     when(props.property(QualityProfiles.SONAR_PROFILE_PROP)).thenReturn("custom");
     when(props.properties()).thenReturn(ImmutableMap.of(QualityProfiles.SONAR_PROFILE_PROP, "custom"));
 
-    QualityProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props);
+    QualityProfiles qps = qualityProfileProvider.provide(loader, projectRepo, props);
     assertResponse(qps);
 
     verify(loader).loadDefault(eq("custom"));
index aa14cafc001278325fc1a7ab0fad4396178f0d81..930f5ee8086813187e7d55f8ff2bdb4ee5aecfda 100644 (file)
@@ -25,8 +25,8 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.batch.fs.internal.DefaultInputComponent;
 import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
@@ -44,11 +44,11 @@ public class DefaultComponentTreeTest {
 
   @Test
   public void test() throws IOException {
-    DefaultInputComponent root = new DefaultInputModule(ProjectDefinition.create().setKey("root").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder()));
-    DefaultInputComponent mod1 = new DefaultInputModule(ProjectDefinition.create().setKey("mod1").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder()));
-    DefaultInputComponent mod2 = new DefaultInputModule(ProjectDefinition.create().setKey("mod2").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder()));
-    DefaultInputComponent mod3 = new DefaultInputModule(ProjectDefinition.create().setKey("mod3").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder()));
-    DefaultInputComponent mod4 = new DefaultInputModule(ProjectDefinition.create().setKey("mod4").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder()));
+    DefaultInputProject root = new DefaultInputProject(ProjectDefinition.create().setKey("root").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder()));
+    DefaultInputModule mod1 = new DefaultInputModule(ProjectDefinition.create().setKey("mod1").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder()));
+    DefaultInputModule mod2 = new DefaultInputModule(ProjectDefinition.create().setKey("mod2").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder()));
+    DefaultInputModule mod3 = new DefaultInputModule(ProjectDefinition.create().setKey("mod3").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder()));
+    DefaultInputModule mod4 = new DefaultInputModule(ProjectDefinition.create().setKey("mod4").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder()));
 
     tree.index(mod1, root);
     tree.index(mod2, mod1);
index 0972e2af5d3497f107f8cc38826dd2e20b669ae6..206fbb8fd2c15966080f7a2acadcef7ae4cb6f15 100644 (file)
@@ -52,7 +52,7 @@ public class DefaultInputModuleHierarchyTest {
     parents.put(mod3, root);
     parents.put(mod4, root);
 
-    moduleHierarchy = new DefaultInputModuleHierarchy(parents);
+    moduleHierarchy = new DefaultInputModuleHierarchy(root, parents);
 
     assertThat(moduleHierarchy.children(root)).containsOnly(mod1, mod3, mod4);
     assertThat(moduleHierarchy.children(mod4)).isEmpty();
@@ -75,18 +75,4 @@ public class DefaultInputModuleHierarchyTest {
     assertThat(moduleHierarchy.parent(root)).isNull();
     assertThat(moduleHierarchy.root()).isEqualTo(root);
   }
-
-  @Test
-  public void testParentChild() throws IOException {
-    DefaultInputModule root = new DefaultInputModule(ProjectDefinition.create().setKey("root").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder()));
-    DefaultInputModule mod1 = new DefaultInputModule(ProjectDefinition.create().setKey("mod1").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder()));
-    moduleHierarchy = new DefaultInputModuleHierarchy(root, mod1);
-
-    assertThat(moduleHierarchy.children(root)).containsOnly(mod1);
-    assertThat(moduleHierarchy.children(mod1)).isEmpty();
-
-    assertThat(moduleHierarchy.parent(mod1)).isEqualTo(root);
-    assertThat(moduleHierarchy.parent(root)).isNull();
-    assertThat(moduleHierarchy.root()).isEqualTo(root);
-  }
 }
index 6085472ef99ada97d27d25c0e2a7ab62ebf2db02..2f54bfea404ec64aa6e4c14705637446f694bb41 100644 (file)
@@ -22,8 +22,8 @@ package org.sonar.scanner.scan;
 import java.util.Arrays;
 import org.junit.Test;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.batch.fs.InputModule;
 import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.scanner.scan.branch.BranchConfiguration;
 import org.sonar.scanner.scan.filesystem.InputComponentStore;
 
@@ -37,8 +37,8 @@ public class ModuleIndexerTest {
   private DefaultInputModuleHierarchy moduleHierarchy;
   private InputComponentStore componentStore;
 
-  public void createIndexer(DefaultInputModule rootModule) {
-    componentStore = new InputComponentStore(rootModule, mock(BranchConfiguration.class));
+  public void createIndexer(DefaultInputProject rootProject) {
+    componentStore = new InputComponentStore(rootProject, mock(BranchConfiguration.class));
     tree = new DefaultComponentTree();
     moduleHierarchy = mock(DefaultInputModuleHierarchy.class);
     indexer = new ModuleIndexer(tree, componentStore, moduleHierarchy);
@@ -71,13 +71,13 @@ public class ModuleIndexerTest {
     when(mod2.definition()).thenReturn(def);
     when(mod3.definition()).thenReturn(def);
 
-    createIndexer(root);
+    createIndexer(mock(DefaultInputProject.class));
     when(moduleHierarchy.root()).thenReturn(root);
     when(moduleHierarchy.children(root)).thenReturn(Arrays.asList(mod1, mod2, mod3));
 
     indexer.start();
 
-    InputModule rootModule = moduleHierarchy.root();
+    DefaultInputModule rootModule = moduleHierarchy.root();
     assertThat(rootModule).isNotNull();
     assertThat(moduleHierarchy.children(rootModule)).hasSize(3);
     assertThat(tree.getChildren(rootModule)).hasSize(3);
index 86be7dfda585f1a4e0daa6d1440678957bf8a5d4..12932c33d30f753e2a490c5b5dc6c6b05d0ee6b7 100644 (file)
@@ -33,14 +33,13 @@ import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
 import org.sonar.api.config.PropertyDefinitions;
 import org.sonar.api.utils.MessageException;
+import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
 import org.sonar.scanner.bootstrap.GlobalConfiguration;
 import org.sonar.scanner.bootstrap.GlobalConfigurationProvider;
-import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
-import org.sonar.scanner.bootstrap.GlobalProperties;
-import org.sonar.scanner.bootstrap.MutableGlobalSettings;
+import org.sonar.scanner.bootstrap.GlobalServerSettings;
+import org.sonar.scanner.bootstrap.ScannerProperties;
 import org.sonar.scanner.repository.FileData;
 import org.sonar.scanner.repository.ProjectRepositories;
-import org.sonar.scanner.repository.settings.SettingsLoader;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
@@ -84,7 +83,7 @@ public class MutableModuleSettingsTest {
 
   @Test
   public void test_loading_of_module_settings() {
-    GlobalConfiguration globalSettings = newGlobalSettings(ImmutableMap.of(
+    GlobalConfiguration globalConfig = newGlobalConfig(ImmutableMap.of(
       "overridding", "batch",
       "on-batch", "true"));
 
@@ -92,7 +91,7 @@ public class MutableModuleSettingsTest {
 
     ProjectDefinition module = ProjectDefinition.create().setKey("struts-core");
 
-    MutableModuleSettings moduleSettings = new MutableModuleSettings(new MutableGlobalSettings(globalSettings), module, projRepos, mode);
+    MutableModuleSettings moduleSettings = new MutableModuleSettings(globalConfig, module, projRepos, mode);
 
     assertThat(moduleSettings.getString("overridding")).isEqualTo("module");
     assertThat(moduleSettings.getString("on-batch")).isEqualTo("true");
@@ -102,7 +101,7 @@ public class MutableModuleSettingsTest {
   // SONAR-6386
   @Test
   public void test_loading_of_parent_module_settings_for_new_module() {
-    GlobalConfiguration globalSettings = newGlobalSettings(ImmutableMap.of(
+    GlobalConfiguration globalConfig = newGlobalConfig(ImmutableMap.of(
       "overridding", "batch",
       "on-batch", "true"));
 
@@ -111,7 +110,7 @@ public class MutableModuleSettingsTest {
     ProjectDefinition module = ProjectDefinition.create().setKey("struts-core");
     ProjectDefinition.create().setKey("struts").addSubProject(module);
 
-    MutableModuleSettings moduleSettings = new MutableModuleSettings(new MutableGlobalSettings(globalSettings), module, projRepos, mode);
+    MutableModuleSettings moduleSettings = new MutableModuleSettings(globalConfig, module, projRepos, mode);
 
     assertThat(moduleSettings.getString("overridding")).isEqualTo("module");
     assertThat(moduleSettings.getString("on-batch")).isEqualTo("true");
@@ -120,13 +119,13 @@ public class MutableModuleSettingsTest {
 
   @Test
   public void should_not_fail_when_accessing_secured_properties() {
-    GlobalConfiguration globalSettings = newGlobalSettings(ImmutableMap.of("sonar.foo.secured", "bar"));
+    GlobalConfiguration globalConfig = newGlobalConfig(ImmutableMap.of("sonar.foo.secured", "bar"));
 
     ProjectRepositories projSettingsRepo = createSettings("struts-core", ImmutableMap.of("sonar.foo.license.secured", "bar2"));
 
     ProjectDefinition module = ProjectDefinition.create().setKey("struts-core");
 
-    MutableModuleSettings moduleSettings = new MutableModuleSettings(new MutableGlobalSettings(globalSettings), module, projSettingsRepo, mode);
+    MutableModuleSettings moduleSettings = new MutableModuleSettings(globalConfig, module, projSettingsRepo, mode);
 
     assertThat(moduleSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2");
     assertThat(moduleSettings.getString("sonar.foo.secured")).isEqualTo("bar");
@@ -134,7 +133,7 @@ public class MutableModuleSettingsTest {
 
   @Test
   public void should_fail_when_accessing_secured_properties_in_issues() {
-    GlobalConfiguration globalSettings = newGlobalSettings(ImmutableMap.of(
+    GlobalConfiguration globalConfig = newGlobalConfig(ImmutableMap.of(
       "sonar.foo.secured", "bar"));
 
     ProjectRepositories projSettingsRepo = createSettings("struts-core", ImmutableMap.of("sonar.foo.license.secured", "bar2"));
@@ -143,7 +142,7 @@ public class MutableModuleSettingsTest {
 
     ProjectDefinition module = ProjectDefinition.create().setKey("struts-core");
 
-    MutableModuleSettings moduleSettings = new MutableModuleSettings(new MutableGlobalSettings(globalSettings), module, projSettingsRepo, mode);
+    MutableModuleSettings moduleSettings = new MutableModuleSettings(globalConfig, module, projSettingsRepo, mode);
 
     assertThat(moduleSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2");
 
@@ -154,9 +153,9 @@ public class MutableModuleSettingsTest {
     moduleSettings.getString("sonar.foo.secured");
   }
 
-  private GlobalConfiguration newGlobalSettings(Map<String, String> props) {
-    GlobalProperties globalProps = new GlobalProperties(props);
-    return new GlobalConfigurationProvider().provide(mock(SettingsLoader.class), globalProps, new PropertyDefinitions(),
-      new GlobalAnalysisMode(globalProps));
+  private GlobalConfiguration newGlobalConfig(Map<String, String> props) {
+    ScannerProperties scannerProps = new ScannerProperties(props);
+    return new GlobalConfigurationProvider().provide(mock(GlobalServerSettings.class), scannerProps, new PropertyDefinitions(),
+      new GlobalAnalysisMode(scannerProps));
   }
 }
index f9d3884d15692dd5a5ae7898be2391cd570fbfc1..4b0ed58b94896b608bc91d4a1f3ad4ec2298ff89 100644 (file)
@@ -33,14 +33,13 @@ import org.sonar.api.batch.bootstrap.ProjectReactor;
 import org.sonar.api.config.PropertyDefinitions;
 import org.sonar.api.utils.MessageException;
 import org.sonar.api.utils.log.LogTester;
+import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
 import org.sonar.scanner.bootstrap.GlobalConfiguration;
 import org.sonar.scanner.bootstrap.GlobalConfigurationProvider;
-import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
-import org.sonar.scanner.bootstrap.GlobalProperties;
-import org.sonar.scanner.bootstrap.MutableGlobalSettings;
+import org.sonar.scanner.bootstrap.GlobalServerSettings;
+import org.sonar.scanner.bootstrap.ScannerProperties;
 import org.sonar.scanner.repository.FileData;
 import org.sonar.scanner.repository.ProjectRepositories;
-import org.sonar.scanner.repository.settings.SettingsLoader;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
@@ -55,7 +54,7 @@ public class MutableProjectSettingsTest {
 
   private ProjectRepositories projectRef;
   private ProjectDefinition project;
-  private GlobalConfiguration bootstrapProps;
+  private GlobalConfiguration globalConfig;
   private Table<String, String, FileData> emptyFileData;
   private Table<String, String, String> emptySettings;
 
@@ -67,7 +66,7 @@ public class MutableProjectSettingsTest {
     emptySettings = ImmutableTable.of();
     project = ProjectDefinition.create().setKey("struts");
     globalMode = mock(GlobalAnalysisMode.class);
-    bootstrapProps = new GlobalConfigurationProvider().provide(mock(SettingsLoader.class), new GlobalProperties(Collections.<String, String>emptyMap()), new PropertyDefinitions(),
+    globalConfig = new GlobalConfigurationProvider().provide(mock(GlobalServerSettings.class), new ScannerProperties(Collections.<String, String>emptyMap()), new PropertyDefinitions(),
       globalMode);
   }
 
@@ -76,7 +75,7 @@ public class MutableProjectSettingsTest {
     project.setProperty("project.prop", "project");
 
     projectRef = new ProjectRepositories(emptySettings, emptyFileData, null);
-    MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), new MutableGlobalSettings(bootstrapProps), projectRef, globalMode);
+    MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), globalConfig, projectRef, globalMode);
 
     assertThat(batchSettings.getString("project.prop")).isEqualTo("project");
   }
@@ -88,7 +87,7 @@ public class MutableProjectSettingsTest {
     settings.put("struts", "sonar.java.coveragePlugin", "jacoco");
 
     projectRef = new ProjectRepositories(settings, emptyFileData, null);
-    MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), new MutableGlobalSettings(bootstrapProps), projectRef, globalMode);
+    MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), globalConfig, projectRef, globalMode);
     assertThat(batchSettings.getString("sonar.java.coveragePlugin")).isEqualTo("jacoco");
   }
 
@@ -102,7 +101,7 @@ public class MutableProjectSettingsTest {
 
     projectRef = new ProjectRepositories(settings, emptyFileData, null);
 
-    MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), new MutableGlobalSettings(bootstrapProps), projectRef, globalMode);
+    MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), globalConfig, projectRef, globalMode);
 
     assertThat(batchSettings.getString("sonar.java.coveragePlugin")).isEqualTo("jacoco");
   }
@@ -114,7 +113,7 @@ public class MutableProjectSettingsTest {
     settings.put("struts", "sonar.foo.license.secured", "bar2");
 
     projectRef = new ProjectRepositories(settings, emptyFileData, null);
-    MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), new MutableGlobalSettings(bootstrapProps), projectRef, globalMode);
+    MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), globalConfig, projectRef, globalMode);
 
     assertThat(batchSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2");
     assertThat(batchSettings.getString("sonar.foo.secured")).isEqualTo("bar");
@@ -129,7 +128,7 @@ public class MutableProjectSettingsTest {
     when(globalMode.isIssues()).thenReturn(true);
 
     projectRef = new ProjectRepositories(settings, emptyFileData, null);
-    MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), new MutableGlobalSettings(bootstrapProps), projectRef, globalMode);
+    MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), globalConfig, projectRef, globalMode);
 
     assertThat(batchSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2");
     thrown.expect(MessageException.class);
index 48b474092d8a92bb3c084739d28e0d4a71f46842..4a1b0b5a4a2deac4d9a7a5e99b2c261d17f3f045 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.scanner.scan;
 
 import java.io.File;
+import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import org.junit.Before;
@@ -27,12 +28,10 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
-import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
 public class ProjectLockTest {
   @Rule
@@ -41,24 +40,19 @@ public class ProjectLockTest {
   @Rule
   public ExpectedException exception = ExpectedException.none();
   private ProjectLock lock;
+  private File baseDir;
+  private File worDir;
 
   @Before
-  public void setUp() {
-    lock = setUpTest(tempFolder.getRoot());
-  }
-
-  private ProjectLock setUpTest(File file) {
-    InputModuleHierarchy hierarchy = mock(InputModuleHierarchy.class);
-    DefaultInputModule root = mock(DefaultInputModule.class);
-    when(hierarchy.root()).thenReturn(root);
-    when(root.getWorkDir()).thenReturn(file.toPath());
-
-    return new ProjectLock(hierarchy);
+  public void setUp() throws IOException {
+    baseDir = tempFolder.newFolder();
+    worDir = new File(baseDir, ".sonar");
+    lock = new ProjectLock(new DefaultInputProject(ProjectDefinition.create().setBaseDir(baseDir).setWorkDir(worDir)));
   }
 
   @Test
   public void tryLock() {
-    Path lockFilePath = tempFolder.getRoot().toPath().resolve(DirectoryLock.LOCK_FILE_NAME);
+    Path lockFilePath = worDir.toPath().resolve(DirectoryLock.LOCK_FILE_NAME);
     lock.tryLock();
     assertThat(Files.exists(lockFilePath)).isTrue();
     assertThat(Files.isRegularFile(lockFilePath)).isTrue();
index 9ebd6c9c0ef4ed2bf8f3d05b494a3228cae1fa4c..1db1cd92e0437e2692edae64abf61a88246a16a4 100644 (file)
@@ -37,8 +37,7 @@ 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.LogTester;
-import org.sonar.api.utils.log.LoggerLevel;
-import org.sonar.scanner.analysis.AnalysisProperties;
+import org.sonar.scanner.bootstrap.ScannerProperties;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
@@ -322,18 +321,6 @@ public class ProjectReactorBuilderTest {
     assertThat(module12.properties().get("sonar.profile")).isEqualTo("Foo");
   }
 
-  @Test
-  public void shouldRemoveModulePropertiesFromTaskProperties() {
-    Map<String, String> props = loadProps("big-multi-module-definitions-all-in-root");
-
-    AnalysisProperties taskProperties = new AnalysisProperties(props, null);
-    assertThat(taskProperties.property("module1.module11.property")).isEqualTo("My module11 property");
-
-    new ProjectReactorBuilder(taskProperties).execute();
-
-    assertThat(taskProperties.property("module1.module11.property")).isNull();
-  }
-
   @Test
   public void shouldFailIfMandatoryPropertiesAreNotPresent() {
     Map<String, String> props = new HashMap<>();
@@ -412,7 +399,7 @@ public class ProjectReactorBuilderTest {
 
   @Test
   public void shouldInitRootWorkDir() {
-    ProjectReactorBuilder builder = new ProjectReactorBuilder(new AnalysisProperties(Maps.<String, String>newHashMap(), null));
+    ProjectReactorBuilder builder = new ProjectReactorBuilder(new ScannerProperties(Maps.<String, String>newHashMap()));
     File baseDir = new File("target/tmp/baseDir");
 
     File workDir = builder.initRootProjectWorkDir(baseDir, Maps.<String, String>newHashMap());
@@ -424,7 +411,7 @@ public class ProjectReactorBuilderTest {
   public void shouldInitWorkDirWithCustomRelativeFolder() {
     Map<String, String> props = Maps.<String, String>newHashMap();
     props.put("sonar.working.directory", ".foo");
-    ProjectReactorBuilder builder = new ProjectReactorBuilder(new AnalysisProperties(props, null));
+    ProjectReactorBuilder builder = new ProjectReactorBuilder(new ScannerProperties(props));
     File baseDir = new File("target/tmp/baseDir");
 
     File workDir = builder.initRootProjectWorkDir(baseDir, props);
@@ -436,7 +423,7 @@ public class ProjectReactorBuilderTest {
   public void shouldInitRootWorkDirWithCustomAbsoluteFolder() {
     Map<String, String> props = Maps.<String, String>newHashMap();
     props.put("sonar.working.directory", new File("src").getAbsolutePath());
-    ProjectReactorBuilder builder = new ProjectReactorBuilder(new AnalysisProperties(props, null));
+    ProjectReactorBuilder builder = new ProjectReactorBuilder(new ScannerProperties(props));
     File baseDir = new File("target/tmp/baseDir");
 
     File workDir = builder.initRootProjectWorkDir(baseDir, props);
@@ -494,7 +481,7 @@ public class ProjectReactorBuilderTest {
 
   private ProjectDefinition loadProjectDefinition(String projectFolder) {
     Map<String, String> props = loadProps(projectFolder);
-    AnalysisProperties bootstrapProps = new AnalysisProperties(props, null);
+    ScannerProperties bootstrapProps = new ScannerProperties(props);
     ProjectReactor projectReactor = new ProjectReactorBuilder(bootstrapProps).execute();
     return projectReactor.getRoot();
   }
@@ -634,16 +621,6 @@ public class ProjectReactorBuilderTest {
       .isEqualTo(new File(getResource(this.getClass(), "multi-module-definitions-same-prefix"), ".sonar/com.foo.project_com.foo.project.module1.feature"));
   }
 
-  @Test
-  public void should_log_a_warning_when_a_dropped_property_is_present() {
-    Map<String, String> props = loadProps("simple-project");
-    props.put("sonar.qualitygate", "somevalue");
-    AnalysisProperties bootstrapProps = new AnalysisProperties(props, null);
-    new ProjectReactorBuilder(bootstrapProps).execute();
-
-    assertThat(logTester.logs(LoggerLevel.WARN)).containsOnly("Property 'sonar.qualitygate' is not supported any more. It will be ignored.");
-  }
-
   private Map<String, String> loadPropsFromFile(String filePath) throws IOException {
     Properties props = new Properties();
     try (FileInputStream fileInputStream = new FileInputStream(getResource(this.getClass(), filePath))) {
index b13ee62d5a218002859022e00eca5c6210a3c345..49f1804c550596b65a7fc4b2dd8b05b42f33afd2 100644 (file)
@@ -27,8 +27,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
-import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.utils.MessageException;
 
@@ -38,21 +37,19 @@ import static org.mockito.Mockito.when;
 
 public class ScanPropertiesTest {
   private MapSettings settings = new MapSettings();
-  private InputModuleHierarchy inputModuleHierarchy = mock(InputModuleHierarchy.class);
-  private ScanProperties underTest = new ScanProperties(settings.asConfig(), inputModuleHierarchy);
+  private DefaultInputProject project = mock(DefaultInputProject.class);
+  private ScanProperties underTest = new ScanProperties(settings.asConfig(), project);
 
   @Rule
   public TemporaryFolder temp = new TemporaryFolder();
-  
+
   @Rule
   public ExpectedException exception = ExpectedException.none();
 
   @Before
   public void setUp() throws IOException {
-    DefaultInputModule root = mock(DefaultInputModule.class);
-    when(root.getBaseDir()).thenReturn(temp.newFolder().toPath());
-    when(root.getWorkDir()).thenReturn(temp.newFolder().toPath());
-    when(inputModuleHierarchy.root()).thenReturn(root);
+    when(project.getBaseDir()).thenReturn(temp.newFolder().toPath());
+    when(project.getWorkDir()).thenReturn(temp.newFolder().toPath());
   }
 
   @Test
@@ -61,7 +58,7 @@ public class ScanPropertiesTest {
     assertThat(underTest.organizationKey()).isEmpty();
     assertThat(underTest.preloadFileMetadata()).isFalse();
     assertThat(underTest.shouldKeepReport()).isFalse();
-    assertThat(underTest.metadataFilePath()).isEqualTo(inputModuleHierarchy.root().getWorkDir().resolve("report-task.txt"));
+    assertThat(underTest.metadataFilePath()).isEqualTo(project.getWorkDir().resolve("report-task.txt"));
     underTest.validate();
   }
 
@@ -70,32 +67,32 @@ public class ScanPropertiesTest {
     settings.setProperty("sonar.organization", "org");
     assertThat(underTest.organizationKey()).isEqualTo(Optional.of("org"));
   }
-  
+
   @Test
   public void should_define_branch_name() {
     settings.setProperty("sonar.branch.name", "name");
     assertThat(underTest.branch()).isEqualTo(Optional.of("name"));
   }
-  
+
   @Test
   public void should_define_preload_file_metadata() {
     settings.setProperty("sonar.preloadFileMetadata", "true");
     assertThat(underTest.preloadFileMetadata()).isTrue();
   }
-  
+
   @Test
   public void should_define_keep_report() {
     settings.setProperty("sonar.scanner.keepReport", "true");
     assertThat(underTest.shouldKeepReport()).isTrue();
   }
-  
+
   @Test
   public void should_define_metadata_file_path() throws IOException {
     Path path = temp.newFolder().toPath().resolve("report");
     settings.setProperty("sonar.scanner.metadataFilePath", path.toString());
     assertThat(underTest.metadataFilePath()).isEqualTo(path);
   }
-  
+
   @Test
   public void validate_fails_if_metadata_file_location_is_not_absolute() {
     settings.setProperty("sonar.scanner.metadataFilePath", "relative");
index edf314b03d9d80bd6d83d5b365c1a7159e5d408e..5170bf0745ebfe6c7e72d63be386c649de41de4b 100644 (file)
@@ -34,6 +34,7 @@ import org.sonar.api.batch.fs.InputFile.Type;
 import org.sonar.api.batch.fs.InputPath;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
 import org.sonar.scanner.scan.branch.BranchConfiguration;
 
@@ -56,10 +57,10 @@ public class InputComponentStoreTest {
     ProjectDefinition rootDef = ProjectDefinition.create()
       .setKey(rootModuleKey).setBaseDir(rootBaseDir).setWorkDir(temp.newFolder()).addSubProject(moduleDef);
 
-    DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule(rootDef);
+    DefaultInputProject rootProject = TestInputFileBuilder.newDefaultInputProject(rootDef);
     DefaultInputModule subModule = TestInputFileBuilder.newDefaultInputModule(moduleDef);
 
-    InputComponentStore cache = new InputComponentStore(rootModule, mock(BranchConfiguration.class));
+    InputComponentStore cache = new InputComponentStore(rootProject, mock(BranchConfiguration.class));
     cache.put(subModule);
 
     DefaultInputFile fooFile = new TestInputFileBuilder(rootModuleKey, "src/main/java/Foo.java")
@@ -103,7 +104,7 @@ public class InputComponentStoreTest {
 
   static class InputComponentStoreTester extends InputComponentStore {
     InputComponentStoreTester() throws IOException {
-      super(TestInputFileBuilder.newDefaultInputModule("root", temp.newFolder()), mock(BranchConfiguration.class));
+      super(TestInputFileBuilder.newDefaultInputProject("root", temp.newFolder()), mock(BranchConfiguration.class));
     }
 
     InputFile addFile(String moduleKey, String relpath, String language) {
index b88d6b171394a0a277c1b5655afcf9d4fb968f8a..851eabb2c49431fba100e952246a858aa64a437a 100644 (file)
@@ -32,7 +32,6 @@ import org.sonar.api.batch.fs.InputFile.Type;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.fs.internal.DefaultInputModule;
 import org.sonar.api.batch.fs.internal.SensorStrategy;
-import org.sonar.api.config.internal.MapSettings;
 import org.sonar.scanner.scan.DefaultInputModuleHierarchy;
 import org.sonar.scanner.scan.ScanProperties;
 
@@ -66,7 +65,7 @@ public class InputFileBuilderTest {
       .setKey("module1"), 0);
 
     MetadataGenerator metadataGenerator = mock(MetadataGenerator.class);
-    BatchIdGenerator idGenerator = new BatchIdGenerator();
+    ScannerComponentIdGenerator idGenerator = new ScannerComponentIdGenerator();
     ScanProperties properties = mock(ScanProperties.class);
     ModuleFileSystemInitializer moduleFileSystemInitializer = mock(ModuleFileSystemInitializer.class);
     when(moduleFileSystemInitializer.defaultEncoding()).thenReturn(StandardCharsets.UTF_8);
index c8373e7957d6c717796d00bbb7b5fbc5aaf2da36..dcd265010d154717b3408ffddcf6ea3416f022d4 100644 (file)
@@ -26,7 +26,7 @@ import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.InputModule;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.batch.fs.internal.SensorStrategy;
 import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
 import org.sonar.scanner.scan.branch.BranchConfiguration;
@@ -44,11 +44,11 @@ public class ModuleInputComponentStoreTest {
 
   private InputComponentStore componentStore;
 
-  private final String moduleKey = "dummy key";
+  private final String projectKey = "dummy key";
 
   @Before
   public void setUp() throws IOException {
-    DefaultInputModule root = TestInputFileBuilder.newDefaultInputModule(moduleKey, temp.newFolder());
+    DefaultInputProject root = TestInputFileBuilder.newDefaultInputProject(projectKey, temp.newFolder());
     componentStore = new InputComponentStore(root, mock(BranchConfiguration.class));
   }
 
@@ -57,13 +57,13 @@ public class ModuleInputComponentStoreTest {
     ModuleInputComponentStore store = newModuleInputComponentStore();
 
     String filename = "some name";
-    InputFile inputFile1 = new TestInputFileBuilder(moduleKey, "some/path/" + filename).build();
+    InputFile inputFile1 = new TestInputFileBuilder(projectKey, "some/path/" + filename).build();
     store.doAdd(inputFile1);
 
-    InputFile inputFile2 = new TestInputFileBuilder(moduleKey, "other/path/" + filename).build();
+    InputFile inputFile2 = new TestInputFileBuilder(projectKey, "other/path/" + filename).build();
     store.doAdd(inputFile2);
 
-    InputFile dummyInputFile = new TestInputFileBuilder(moduleKey, "some/path/Dummy.java").build();
+    InputFile dummyInputFile = new TestInputFileBuilder(projectKey, "some/path/Dummy.java").build();
     store.doAdd(dummyInputFile);
 
     assertThat(store.getFilesByName(filename)).containsExactlyInAnyOrder(inputFile1, inputFile2);
@@ -73,13 +73,13 @@ public class ModuleInputComponentStoreTest {
   public void should_cache_files_by_extension() throws IOException {
     ModuleInputComponentStore store = newModuleInputComponentStore();
 
-    InputFile inputFile1 = new TestInputFileBuilder(moduleKey, "some/path/Program.java").build();
+    InputFile inputFile1 = new TestInputFileBuilder(projectKey, "some/path/Program.java").build();
     store.doAdd(inputFile1);
 
-    InputFile inputFile2 = new TestInputFileBuilder(moduleKey, "other/path/Utils.java").build();
+    InputFile inputFile2 = new TestInputFileBuilder(projectKey, "other/path/Utils.java").build();
     store.doAdd(inputFile2);
 
-    InputFile dummyInputFile = new TestInputFileBuilder(moduleKey, "some/path/NotJava.cpp").build();
+    InputFile dummyInputFile = new TestInputFileBuilder(projectKey, "some/path/NotJava.cpp").build();
     store.doAdd(dummyInputFile);
 
     assertThat(store.getFilesByExtension("java")).containsExactlyInAnyOrder(inputFile1, inputFile2);
@@ -91,7 +91,7 @@ public class ModuleInputComponentStoreTest {
 
     String ext = "java";
     String filename = "Program." + ext;
-    InputFile inputFile = new TestInputFileBuilder(moduleKey, "some/path/" + filename).build();
+    InputFile inputFile = new TestInputFileBuilder(projectKey, "some/path/" + filename).build();
     store.doAdd(inputFile);
     store.doAdd(inputFile);
     store.doAdd(inputFile);
@@ -106,7 +106,7 @@ public class ModuleInputComponentStoreTest {
 
     String ext = "java";
     String filename = "Program." + ext;
-    InputFile inputFile = new TestInputFileBuilder(moduleKey, "some/path/" + filename).build();
+    InputFile inputFile = new TestInputFileBuilder(projectKey, "some/path/" + filename).build();
     store.doAdd(inputFile);
 
     assertThat(store.getFilesByName("nonexistent")).isEmpty();
index 19d3acd7f9dfe55064333040f4274d7a28700855..d813051b3391af50a7163732ae4aca2cb98dbf9b 100644 (file)
@@ -37,6 +37,7 @@ import org.sonar.api.batch.fs.internal.DefaultFileSystem;
 import org.sonar.api.batch.fs.internal.DefaultInputDir;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
 import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
 import org.sonar.api.batch.rule.Rules;
@@ -82,8 +83,9 @@ public class JSONReportTest {
 
     DefaultComponentTree inputComponentTree = new DefaultComponentTree();
     ProjectDefinition def = ProjectDefinition.create().setBaseDir(projectBaseDir).setWorkDir(temp.newFolder()).setKey("struts");
+    DefaultInputProject project = new DefaultInputProject(def, 1);
     DefaultInputModule rootModule = new DefaultInputModule(def, 1);
-    InputComponentStore inputComponentStore = new InputComponentStore(rootModule, mock(BranchConfiguration.class));
+    InputComponentStore inputComponentStore = new InputComponentStore(project, mock(BranchConfiguration.class));
 
     DefaultInputModule moduleA = new DefaultInputModule(ProjectDefinition.create().setKey("struts-core").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder()));
     inputComponentTree.index(moduleA, rootModule);
index 6c6ed94a029fef6c9a1f2511e90f256c15e81f68..7d0795eb2dea6f3c41f393ffef3e080032ab000c 100644 (file)
@@ -28,7 +28,7 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
 import org.sonar.api.batch.scm.ScmProvider;
 import org.sonar.scanner.scan.branch.BranchConfiguration;
@@ -54,13 +54,12 @@ public class ScmChangedFilesProviderTest {
 
   private Path rootBaseDir = Paths.get("root");
   private ScmChangedFilesProvider provider;
+  private DefaultInputProject project = mock(DefaultInputProject.class);
 
   @Before
   public void setUp() {
     MockitoAnnotations.initMocks(this);
-    DefaultInputModule root = mock(DefaultInputModule.class);
-    when(root.getBaseDir()).thenReturn(rootBaseDir);
-    when(inputModuleHierarchy.root()).thenReturn(root);
+    when(project.getBaseDir()).thenReturn(rootBaseDir);
     provider = new ScmChangedFilesProvider();
   }
 
@@ -69,7 +68,7 @@ public class ScmChangedFilesProviderTest {
     when(branchConfiguration.isShortOrPullRequest()).thenReturn(true);
     when(branchConfiguration.targetScmBranch()).thenReturn("target");
 
-    ScmChangedFiles scmChangedFiles = provider.provide(scmConfiguration, branchConfiguration, inputModuleHierarchy);
+    ScmChangedFiles scmChangedFiles = provider.provide(scmConfiguration, branchConfiguration, project);
 
     assertThat(scmChangedFiles.get()).isNull();
     verify(scmConfiguration).provider();
@@ -84,7 +83,7 @@ public class ScmChangedFilesProviderTest {
 
     exception.expect(IllegalStateException.class);
     exception.expectMessage("changed file with a relative path");
-    provider.provide(scmConfiguration, branchConfiguration, inputModuleHierarchy);
+    provider.provide(scmConfiguration, branchConfiguration, project);
   }
 
   @Test
@@ -93,7 +92,7 @@ public class ScmChangedFilesProviderTest {
     when(branchConfiguration.isShortOrPullRequest()).thenReturn(true);
     when(scmConfiguration.provider()).thenReturn(scmProvider);
     when(scmProvider.branchChangedFiles("target", rootBaseDir)).thenReturn(null);
-    ScmChangedFiles scmChangedFiles = provider.provide(scmConfiguration, branchConfiguration, inputModuleHierarchy);
+    ScmChangedFiles scmChangedFiles = provider.provide(scmConfiguration, branchConfiguration, project);
 
     assertThat(scmChangedFiles.get()).isNull();
     verify(scmProvider).branchChangedFiles("target", rootBaseDir);
@@ -102,7 +101,7 @@ public class ScmChangedFilesProviderTest {
   @Test
   public void testNoOpInNonShortLivedBranch() {
     when(branchConfiguration.isShortOrPullRequest()).thenReturn(false);
-    ScmChangedFiles scmChangedFiles = provider.provide(scmConfiguration, branchConfiguration, inputModuleHierarchy);
+    ScmChangedFiles scmChangedFiles = provider.provide(scmConfiguration, branchConfiguration, project);
 
     assertThat(scmChangedFiles.get()).isNull();
     verifyZeroInteractions(scmConfiguration);
@@ -121,7 +120,7 @@ public class ScmChangedFilesProviderTest {
     when(branchConfiguration.isShortOrPullRequest()).thenReturn(true);
     when(branchConfiguration.targetScmBranch()).thenReturn("target");
 
-    ScmChangedFiles scmChangedFiles = provider.provide(scmConfiguration, branchConfiguration, inputModuleHierarchy);
+    ScmChangedFiles scmChangedFiles = provider.provide(scmConfiguration, branchConfiguration, project);
 
     assertThat(scmChangedFiles.get()).isNull();
     verify(scmConfiguration).provider();
@@ -133,7 +132,7 @@ public class ScmChangedFilesProviderTest {
     when(branchConfiguration.isShortOrPullRequest()).thenReturn(true);
     when(scmConfiguration.provider()).thenReturn(scmProvider);
     when(scmProvider.branchChangedFiles("target", rootBaseDir)).thenReturn(Collections.singleton(Paths.get("changedFile").toAbsolutePath()));
-    ScmChangedFiles scmChangedFiles = provider.provide(scmConfiguration, branchConfiguration, inputModuleHierarchy);
+    ScmChangedFiles scmChangedFiles = provider.provide(scmConfiguration, branchConfiguration, project);
 
     assertThat(scmChangedFiles.get()).containsOnly(Paths.get("changedFile").toAbsolutePath());
     verify(scmProvider).branchChangedFiles("target", rootBaseDir);
@@ -141,8 +140,8 @@ public class ScmChangedFilesProviderTest {
 
   @Test
   public void testCacheObject() {
-    provider.provide(scmConfiguration, branchConfiguration, inputModuleHierarchy);
-    provider.provide(scmConfiguration, branchConfiguration, inputModuleHierarchy);
+    provider.provide(scmConfiguration, branchConfiguration, project);
+    provider.provide(scmConfiguration, branchConfiguration, project);
     verify(branchConfiguration).isShortOrPullRequest();
   }
 
index 9747021d1d99509336b3ac605454f69b95c2f449..1c7d17b4e13db182e39cd9fdc2d20ab741cd0c49 100644 (file)
@@ -31,6 +31,7 @@ import org.sonar.api.batch.bootstrap.ProjectDefinition;
 import org.sonar.api.batch.fs.InputModule;
 import org.sonar.api.batch.fs.internal.DefaultFileSystem;
 import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
 import org.sonar.api.batch.measure.MetricFinder;
 import org.sonar.api.batch.rule.ActiveRules;
@@ -39,6 +40,7 @@ import org.sonar.api.batch.sensor.internal.SensorStorage;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.internal.SonarRuntimeImpl;
 import org.sonar.api.measures.CoreMetrics;
+import org.sonar.api.scanner.fs.InputProject;
 import org.sonar.api.utils.Version;
 import org.sonar.scanner.scan.DefaultInputModuleHierarchy;
 
@@ -77,7 +79,7 @@ public class DefaultSensorContextTest {
     hierarchy = new DefaultInputModuleHierarchy(new DefaultInputModule(ProjectDefinition.create()
       .setWorkDir(temp.newFolder())
       .setBaseDir(temp.newFolder()).setKey("foo")));
-    adaptor = new DefaultSensorContext(mock(InputModule.class), settings.asConfig(), settings, fs, activeRules, analysisMode, sensorStorage, runtime, hierarchy);
+    adaptor = new DefaultSensorContext(mock(DefaultInputProject.class), mock(InputModule.class), settings.asConfig(), settings, fs, activeRules, analysisMode, sensorStorage, runtime);
   }
 
   @Test
index a270f8076118510d004e2ee59550ce8d7e1ed6c9..16a2911245a819838f749e065eb8c9382b8cf3d3 100644 (file)
@@ -32,6 +32,7 @@ import org.sonar.api.batch.bootstrap.ProjectDefinition;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
 import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
 import org.sonar.api.batch.measure.MetricFinder;
 import org.sonar.api.batch.sensor.code.internal.DefaultSignificantCode;
@@ -80,7 +81,7 @@ public class DefaultSensorStorageTest {
   private ScannerReportWriter reportWriter;
   private ContextPropertiesCache contextPropertiesCache = new ContextPropertiesCache();
   private BranchConfiguration branchConfiguration;
-  private DefaultInputModule projectRoot;
+  private DefaultInputProject project;
 
   @Before
   public void prepare() throws Exception {
@@ -103,7 +104,7 @@ public class DefaultSensorStorageTest {
       moduleIssues, settings.asConfig(), reportPublisher, measureCache,
       mock(SonarCpdBlockIndex.class), contextPropertiesCache, new ScannerMetrics(), branchConfiguration);
 
-    projectRoot = new DefaultInputModule(ProjectDefinition.create()
+    project = new DefaultInputProject(ProjectDefinition.create()
       .setKey("foo")
       .setBaseDir(temp.newFolder())
       .setWorkDir(temp.newFolder()));
@@ -126,7 +127,7 @@ public class DefaultSensorStorageTest {
   public void should_save_issue() {
     InputFile file = new TestInputFileBuilder("foo", "src/Foo.php").build();
 
-    DefaultIssue issue = new DefaultIssue(projectRoot).at(new DefaultIssueLocation().on(file));
+    DefaultIssue issue = new DefaultIssue(project).at(new DefaultIssueLocation().on(file));
     underTest.store(issue);
 
     ArgumentCaptor<Issue> argumentCaptor = ArgumentCaptor.forClass(Issue.class);
@@ -138,7 +139,7 @@ public class DefaultSensorStorageTest {
   public void should_save_external_issue() {
     InputFile file = new TestInputFileBuilder("foo", "src/Foo.php").build();
 
-    DefaultExternalIssue externalIssue = new DefaultExternalIssue(projectRoot).at(new DefaultIssueLocation().on(file));
+    DefaultExternalIssue externalIssue = new DefaultExternalIssue(project).at(new DefaultIssueLocation().on(file));
     underTest.store(externalIssue);
 
     ArgumentCaptor<ExternalIssue> argumentCaptor = ArgumentCaptor.forClass(ExternalIssue.class);
@@ -151,7 +152,7 @@ public class DefaultSensorStorageTest {
     InputFile file = new TestInputFileBuilder("foo", "src/Foo.php").setStatus(InputFile.Status.SAME).build();
     when(branchConfiguration.isShortOrPullRequest()).thenReturn(true);
 
-    DefaultIssue issue = new DefaultIssue(projectRoot).at(new DefaultIssueLocation().on(file));
+    DefaultIssue issue = new DefaultIssue(project).at(new DefaultIssueLocation().on(file));
     underTest.store(issue);
 
     verifyZeroInteractions(moduleIssues);
@@ -165,7 +166,7 @@ public class DefaultSensorStorageTest {
     DefaultHighlighting highlighting = new DefaultHighlighting(underTest).onFile(file).highlight(0, 1, TypeOfText.KEYWORD);
     underTest.store(highlighting);
 
-    assertThat(reportWriter.hasComponentData(FileStructure.Domain.SYNTAX_HIGHLIGHTINGS, file.batchId())).isTrue();
+    assertThat(reportWriter.hasComponentData(FileStructure.Domain.SYNTAX_HIGHLIGHTINGS, file.scannerId())).isTrue();
   }
 
   @Test
@@ -178,7 +179,7 @@ public class DefaultSensorStorageTest {
     DefaultHighlighting highlighting = new DefaultHighlighting(underTest).onFile(file).highlight(0, 1, TypeOfText.KEYWORD);
     underTest.store(highlighting);
 
-    assertThat(reportWriter.hasComponentData(FileStructure.Domain.SYNTAX_HIGHLIGHTINGS, file.batchId())).isFalse();
+    assertThat(reportWriter.hasComponentData(FileStructure.Domain.SYNTAX_HIGHLIGHTINGS, file.scannerId())).isFalse();
   }
 
   @Test
@@ -226,7 +227,7 @@ public class DefaultSensorStorageTest {
       .onFile(file)
       .addRange(file.selectLine(1)));
 
-    assertThat(reportWriter.hasComponentData(FileStructure.Domain.SGNIFICANT_CODE, file.batchId())).isFalse();
+    assertThat(reportWriter.hasComponentData(FileStructure.Domain.SGNIFICANT_CODE, file.scannerId())).isFalse();
   }
 
   @Test
@@ -238,7 +239,7 @@ public class DefaultSensorStorageTest {
       .onFile(file)
       .addRange(file.selectLine(1)));
 
-    assertThat(reportWriter.hasComponentData(FileStructure.Domain.SGNIFICANT_CODE, file.batchId())).isTrue();
+    assertThat(reportWriter.hasComponentData(FileStructure.Domain.SGNIFICANT_CODE, file.scannerId())).isTrue();
   }
 
   @Test