]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9670 Introduce sonar.branch.longLivedBranches.regex
authorJanos Gyerik <janos.gyerik@sonarsource.com>
Mon, 11 Sep 2017 08:50:28 +0000 (10:50 +0200)
committerJanos Gyerik <janos.gyerik@sonarsource.com>
Tue, 12 Sep 2017 09:34:59 +0000 (11:34 +0200)
90 files changed:
sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/internal/MockAnalysisModeTest.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/DefaultAnalysisMode.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/ValidateIncremental.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/AbstractAnalysisMode.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/BatchComponents.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ExtensionInstaller.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalAnalysisMode.java [new file with mode: 0644]
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/GlobalMode.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/MutableGlobalSettings.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginPredicate.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerWsClient.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerWsClientProvider.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/config/DefaultConfiguration.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/CpdExecutor.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/DeprecatedSensorContext.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ReportPublisher.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ProjectRepositoriesProvider.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/settings/DefaultSettingsLoader.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/BranchConfiguration.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/BranchConfigurationLoader.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/BranchConfigurationProvider.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/BranchParamsValidator.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DefaultBranchConfiguration.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DefaultBranchParamsValidator.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleSettings.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleSettingsProvider.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/ProjectReactorValidator.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectSettings.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectSettingsProvider.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/BranchConfiguration.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/BranchConfigurationLoader.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/BranchConfigurationProvider.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/BranchInfo.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/BranchParamsValidator.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/BranchType.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/DefaultBranchConfiguration.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/DefaultBranchParamsValidator.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectBranches.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectBranchesLoader.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectBranchesProvider.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/package-info.java [new file with mode: 0644]
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
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/source/ZeroCoverageSensor.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/test/java/org/sonar/scanner/analysis/DefaultAnalysisModeTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ExtensionInstallerTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalAnalysisModeTest.java [new file with mode: 0644]
sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalConfigurationProviderTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalModeTest.java [deleted file]
sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginPredicateTest.java
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/config/DefaultConfigurationTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdExecutorTest.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/tasks/TasksMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.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/ReportPublisherTest.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/settings/DefaultSettingsLoaderTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/BranchConfigurationProviderTest.java [deleted file]
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/ProjectReactorValidatorTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/branch/BranchConfigurationProviderTest.java [new file with mode: 0644]
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/branch/ProjectBranchesProviderTest.java [new file with mode: 0644]
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/InputComponentStoreTest.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/sensor/DefaultSensorContextTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/source/ZeroCoverageSensorTest.java

index 5fbe93e7cbfbf9c0301c0a6d760420db190fa6e3..8a8179f9062c41fe8f32baa407e4c1c77976b20a 100644 (file)
@@ -31,13 +31,10 @@ public class MockAnalysisModeTest {
     assertThat(mode.isIssues()).isFalse();
     assertThat(mode.isPreview()).isFalse();
     assertThat(mode.isPublish()).isTrue();
-    assertThat(mode.isIncremental()).isFalse();
     mode.setPreviewOrIssue(true);
-    mode.setIncremental(true);
     assertThat(mode.isIssues()).isTrue();
     assertThat(mode.isPreview()).isTrue();
     assertThat(mode.isPublish()).isFalse();
-    assertThat(mode.isIncremental()).isTrue();
   }
 
 }
index 6e7bf1a508c4fb120b1b52678e9c8b5d85f0e834..534dad293adef2c6d8fdd7049763743d479da52d 100644 (file)
 package org.sonar.scanner.analysis;
 
 import java.util.Map;
-import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
 import javax.annotation.concurrent.Immutable;
-import org.sonar.api.CoreProperties;
+import org.sonar.api.batch.AnalysisMode;
+import org.sonar.api.utils.DateUtils;
+import org.sonar.api.utils.MessageException;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
-import org.sonar.scanner.bootstrap.AbstractAnalysisMode;
-import org.sonar.scanner.bootstrap.GlobalProperties;
-import org.sonar.scanner.scan.BranchConfiguration;
+import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
+import org.sonar.scanner.repository.ProjectRepositories;
+import org.sonar.scanner.scan.branch.BranchConfiguration;
 
 @Immutable
-public class DefaultAnalysisMode extends AbstractAnalysisMode {
-
+public class DefaultAnalysisMode implements AnalysisMode {
   private static final Logger LOG = Loggers.get(DefaultAnalysisMode.class);
   private static final String KEY_SCAN_ALL = "sonar.scanAllFiles";
+  private static final String KEY_INCREMENTAL = "sonar.incremental";
+
+  private final Map<String, String> analysisProps;
+  private final GlobalAnalysisMode analysisMode;
+  private final BranchConfiguration branchConfig;
+  private final ProjectRepositories projectRepos;
+  private final ValidateIncremental validateIncremental;
 
   private boolean scanAllFiles;
+  private boolean incremental;
 
-  public DefaultAnalysisMode(GlobalProperties globalProps, AnalysisProperties props, BranchConfiguration branchConfig) {
-    init(globalProps.properties(), props.properties(), branchConfig);
+  public DefaultAnalysisMode(AnalysisProperties props, BranchConfiguration branchConfig, GlobalAnalysisMode analysisMode, ProjectRepositories projectRepos) {
+    this(props, branchConfig, analysisMode, projectRepos, null);
   }
 
-  public boolean scanAllFiles() {
-    return scanAllFiles;
+  public DefaultAnalysisMode(AnalysisProperties props, BranchConfiguration branchConfig,
+    GlobalAnalysisMode analysisMode, ProjectRepositories projectRepos, @Nullable ValidateIncremental validateIncremental) {
+    this.branchConfig = branchConfig;
+    this.analysisMode = analysisMode;
+    this.projectRepos = projectRepos;
+    this.validateIncremental = validateIncremental;
+    this.analysisProps = props.properties();
+    load();
   }
 
-  private void init(Map<String, String> globalProps, Map<String, String> analysisProps, BranchConfiguration branchConfig) {
-    // make sure analysis is consistent with global properties
-    boolean globalPreview = isIssues(globalProps);
-    boolean analysisPreview = isIssues(analysisProps);
-
-    if (!globalPreview && analysisPreview) {
-      throw new IllegalStateException("Inconsistent properties: global properties doesn't enable issues mode while analysis properties enables it");
-    }
-
-    load(globalProps, analysisProps, branchConfig.isShortLivingBranch());
+  @Override
+  public boolean isIncremental() {
+    return incremental;
   }
 
-  private void load(Map<String, String> globalProps, Map<String, String> analysisProps, boolean isShortLivingBranch) {
-    String mode = getPropertyWithFallback(analysisProps, globalProps, CoreProperties.ANALYSIS_MODE);
-    validate(mode);
-    issues = CoreProperties.ANALYSIS_MODE_ISSUES.equals(mode) || CoreProperties.ANALYSIS_MODE_PREVIEW.equals(mode);
-    mediumTestMode = "true".equals(getPropertyWithFallback(analysisProps, globalProps, MEDIUM_TEST_ENABLED));
-    String scanAllStr = getPropertyWithFallback(analysisProps, globalProps, KEY_SCAN_ALL);
-    scanAllFiles = !isShortLivingBranch && (!issues || "true".equals(scanAllStr));
+  public boolean scanAllFiles() {
+    return scanAllFiles;
   }
 
-  public void printMode() {
-    if (preview) {
-      LOG.info("Preview mode");
-    } else if (issues) {
-      LOG.info("Issues mode");
-    } else {
-      LOG.info("Publish mode");
-    }
-    if (mediumTestMode) {
-      LOG.info("Medium test mode");
-    }
+  public void printFlags() {
     if (!scanAllFiles) {
       LOG.info("Scanning only changed files");
     }
   }
 
-  @Override
-  public boolean isIncremental() {
-    return false;
+  private void load() {
+    String scanAllStr = analysisProps.get(KEY_SCAN_ALL);
+    scanAllFiles = !branchConfig.isShortLivingBranch() && (!analysisMode.isIssues() || "true".equals(scanAllStr));
+    incremental = incremental();
   }
 
-  @CheckForNull
-  private static String getPropertyWithFallback(Map<String, String> props1, Map<String, String> props2, String key) {
-    if (props1.containsKey(key)) {
-      return props1.get(key);
+  private boolean incremental() {
+    String inc = analysisProps.get(KEY_INCREMENTAL);
+    if ("true".equals(inc)) {
+      if (validateIncremental == null || !validateIncremental.validate()) {
+        throw MessageException.of("Incremental mode is not available. Please contact your administrator.");
+      }
+
+      if (!analysisMode.isPublish()) {
+        throw new IllegalStateException("Incremental analysis is only available in publish mode");
+      }
+
+      if (branchConfig.branchName() != null) {
+        LOG.warn("Incremental analysis mode has been activated but it's not compatible with branches so a full analysis will be done.");
+        return false;
+      }
+
+      if (!projectRepos.exists() || projectRepos.lastAnalysisDate() == null) {
+        LOG.warn("Incremental analysis mode has been activated but the project was never analyzed before so a full analysis is about to be done.");
+        return false;
+      }
+
+      LOG.debug("Reference analysis is {}", DateUtils.formatDateTime(projectRepos.lastAnalysisDate()));
+      return true;
     }
 
-    return props2.get(key);
+    return false;
   }
 
-  private static boolean isIssues(Map<String, String> props) {
-    String mode = props.get(CoreProperties.ANALYSIS_MODE);
+  @Override
+  public boolean isPreview() {
+    return analysisMode.isPreview();
+  }
 
-    return CoreProperties.ANALYSIS_MODE_ISSUES.equals(mode);
+  @Override
+  public boolean isIssues() {
+    return analysisMode.isIssues();
+  }
+
+  @Override
+  public boolean isPublish() {
+    return analysisMode.isPublish();
   }
 }
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/ValidateIncremental.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/ValidateIncremental.java
new file mode 100644 (file)
index 0000000..0db769b
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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;
+
+public interface ValidateIncremental {
+  boolean validate();
+}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/AbstractAnalysisMode.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/AbstractAnalysisMode.java
deleted file mode 100644 (file)
index d9ba120..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 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.Arrays;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.batch.AnalysisMode;
-
-public abstract class AbstractAnalysisMode implements AnalysisMode {
-
-  private static final String[] VALID_MODES = {CoreProperties.ANALYSIS_MODE_PREVIEW, CoreProperties.ANALYSIS_MODE_PUBLISH, CoreProperties.ANALYSIS_MODE_ISSUES};
-  public static final String MEDIUM_TEST_ENABLED = "sonar.mediumTest.enabled";
-
-  protected boolean preview;
-  protected boolean issues;
-  protected boolean mediumTestMode;
-
-  protected AbstractAnalysisMode() {
-  }
-
-  @Override
-  public boolean isPreview() {
-    return preview;
-  }
-
-  @Override
-  public boolean isIssues() {
-    return issues;
-  }
-
-  @Override
-  public boolean isPublish() {
-    return !preview && !issues;
-  }
-
-  public boolean isMediumTest() {
-    return mediumTestMode;
-  }
-
-  protected static void validate(String mode) {
-    if (StringUtils.isEmpty(mode)) {
-      return;
-    }
-
-    if (CoreProperties.ANALYSIS_MODE_INCREMENTAL.equals(mode)) {
-      throw new IllegalStateException("Invalid analysis mode: " + mode + ". This mode was removed in SonarQube 5.2. Valid modes are: " + Arrays.toString(VALID_MODES));
-    }
-
-    if (!Arrays.asList(VALID_MODES).contains(mode)) {
-      throw new IllegalStateException("Invalid analysis mode: " + mode + ". Valid modes are: " + Arrays.toString(VALID_MODES));
-    }
-
-  }
-
-}
index 94536420f0c76fc361ef3681cde98a1f409a1b6c..48f4d5a14d5aef1ef8eb4cd46112dc25168f850b 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.scanner.bootstrap;
 import com.google.common.collect.Lists;
 import java.util.Collection;
 import java.util.List;
-import org.sonar.api.batch.AnalysisMode;
 import org.sonar.core.component.DefaultResourceTypes;
 import org.sonar.core.config.CorePropertyDefinitions;
 import org.sonar.core.issue.tracking.Tracker;
@@ -49,7 +48,7 @@ public class BatchComponents {
     // only static stuff
   }
 
-  public static Collection<Object> all(AnalysisMode analysisMode) {
+  public static Collection<Object> all(GlobalAnalysisMode analysisMode) {
     List<Object> components = Lists.newArrayList(
       DefaultResourceTypes.get(),
 
index 97366e2179d3bce0f94c4faee23956484441c7e6..a25a44f85974bbe8ed046bc167597afb5a601d01 100644 (file)
@@ -24,7 +24,6 @@ import javax.annotation.Nullable;
 import org.sonar.api.ExtensionProvider;
 import org.sonar.api.Plugin;
 import org.sonar.api.SonarRuntime;
-import org.sonar.api.batch.AnalysisMode;
 import org.sonar.core.platform.ComponentContainer;
 import org.sonar.core.platform.PluginInfo;
 import org.sonar.core.platform.PluginRepository;
@@ -33,9 +32,9 @@ public class ExtensionInstaller {
 
   private final SonarRuntime sonarRuntime;
   private final PluginRepository pluginRepository;
-  private final AnalysisMode analysisMode;
+  private final GlobalAnalysisMode analysisMode;
 
-  public ExtensionInstaller(SonarRuntime sonarRuntime, PluginRepository pluginRepository, AnalysisMode analysisMode) {
+  public ExtensionInstaller(SonarRuntime sonarRuntime, PluginRepository pluginRepository, GlobalAnalysisMode analysisMode) {
     this.sonarRuntime = sonarRuntime;
     this.pluginRepository = pluginRepository;
     this.analysisMode = analysisMode;
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalAnalysisMode.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalAnalysisMode.java
new file mode 100644 (file)
index 0000000..a6dddc7
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.Arrays;
+import javax.annotation.concurrent.Immutable;
+import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.sonar.api.CoreProperties;
+
+@Immutable
+public class GlobalAnalysisMode {
+  public static final String MEDIUM_TEST_ENABLED = "sonar.mediumTest.enabled";
+  private static final Logger LOG = LoggerFactory.getLogger(GlobalAnalysisMode.class);
+  private static final String[] VALID_MODES = {CoreProperties.ANALYSIS_MODE_PREVIEW, CoreProperties.ANALYSIS_MODE_PUBLISH, CoreProperties.ANALYSIS_MODE_ISSUES};
+
+  protected boolean preview;
+  protected boolean issues;
+  protected boolean mediumTestMode;
+
+  public boolean isPreview() {
+    return preview;
+  }
+
+  public boolean isIssues() {
+    return issues;
+  }
+
+  public boolean isPublish() {
+    return !preview && !issues;
+  }
+
+  public boolean isMediumTest() {
+    return mediumTestMode;
+  }
+
+  protected static void validate(String mode) {
+    if (StringUtils.isEmpty(mode)) {
+      return;
+    }
+
+    if (CoreProperties.ANALYSIS_MODE_INCREMENTAL.equals(mode)) {
+      throw new IllegalStateException("Invalid analysis mode: " + mode + ". This mode was removed in SonarQube 5.2. Valid modes are: " + Arrays.toString(VALID_MODES));
+    }
+
+    if (!Arrays.asList(VALID_MODES).contains(mode)) {
+      throw new IllegalStateException("Invalid analysis mode: " + mode + ". Valid modes are: " + Arrays.toString(VALID_MODES));
+    }
+
+  }
+
+  public GlobalAnalysisMode(GlobalProperties props) {
+    String mode = props.property(CoreProperties.ANALYSIS_MODE);
+    validate(mode);
+    issues = CoreProperties.ANALYSIS_MODE_ISSUES.equals(mode) || CoreProperties.ANALYSIS_MODE_PREVIEW.equals(mode);
+    mediumTestMode = "true".equals(props.property(MEDIUM_TEST_ENABLED));
+    if (preview) {
+      LOG.debug("Preview mode");
+    } else if (issues) {
+      LOG.debug("Issues mode");
+    } else {
+      LOG.debug("Publish mode");
+    }
+    if (mediumTestMode) {
+      LOG.info("Medium test mode");
+    }
+  }
+}
index 336d0ce73ff7f48e3c79be2a65496c06deac6f8b..b41cf7d4f0b7bc99477497d6f917c86135bdb37f 100644 (file)
@@ -26,7 +26,6 @@ import javax.annotation.concurrent.Immutable;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.sonar.api.CoreProperties;
-import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.config.Encryption;
 import org.sonar.api.config.PropertyDefinitions;
 import org.sonar.scanner.config.DefaultConfiguration;
@@ -48,7 +47,7 @@ public class GlobalConfiguration extends DefaultConfiguration {
 
   private final Map<String, String> serverSideSettings;
 
-  public GlobalConfiguration(PropertyDefinitions propertyDefinitions, Encryption encryption, AnalysisMode mode,
+  public GlobalConfiguration(PropertyDefinitions propertyDefinitions, Encryption encryption, GlobalAnalysisMode mode,
     Map<String, String> settings, Map<String, String> serverSideSettings) {
     super(propertyDefinitions, encryption, mode, settings);
     this.serverSideSettings = serverSideSettings;
index 26467a6e5dfef1fc5c5a85db5ae6ce6d23b366af..46a591b75b1fa285e00b2fd74bbbe037d857e796 100644 (file)
@@ -29,7 +29,7 @@ public class GlobalConfigurationProvider extends ProviderAdapter {
 
   private GlobalConfiguration globalSettings;
 
-  public GlobalConfiguration provide(SettingsLoader loader, GlobalProperties globalProps, PropertyDefinitions propertyDefinitions, GlobalMode mode) {
+  public GlobalConfiguration provide(SettingsLoader loader, GlobalProperties globalProps, PropertyDefinitions propertyDefinitions, GlobalAnalysisMode mode) {
     if (globalSettings == null) {
 
       Map<String, String> serverSideSettings = loader.load(null);
index 259058a71632f4b9297c5eecf864b1059754fb31..94dbe459a7c7500ba60b83b67a454484de0f8b41 100644 (file)
@@ -65,7 +65,7 @@ public class GlobalContainer extends ComponentContainer {
   @Override
   protected void doBeforeStart() {
     GlobalProperties bootstrapProps = new GlobalProperties(bootstrapProperties);
-    GlobalMode globalMode = new GlobalMode(bootstrapProps);
+    GlobalAnalysisMode globalMode = new GlobalAnalysisMode(bootstrapProps);
     add(bootstrapProps);
     add(globalMode);
     addBootstrapComponents();
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalMode.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalMode.java
deleted file mode 100644 (file)
index df21776..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 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 javax.annotation.concurrent.Immutable;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.CoreProperties;
-
-@Immutable
-public class GlobalMode extends AbstractAnalysisMode {
-  private static final Logger LOG = LoggerFactory.getLogger(GlobalMode.class);
-
-  public GlobalMode(GlobalProperties props) {
-    String mode = props.property(CoreProperties.ANALYSIS_MODE);
-    validate(mode);
-    issues = CoreProperties.ANALYSIS_MODE_ISSUES.equals(mode) || CoreProperties.ANALYSIS_MODE_PREVIEW.equals(mode);
-    mediumTestMode = "true".equals(props.property(MEDIUM_TEST_ENABLED));
-    if (preview) {
-      LOG.debug("Preview global mode");
-    } else if (issues) {
-      LOG.debug("Issues global mode");
-    } else {
-      LOG.debug("Publish global mode");
-    }
-    if (mediumTestMode) {
-      LOG.info("Medium test mode");
-    }
-  }
-
-  @Override
-  public boolean isIncremental() {
-    throw new UnsupportedOperationException();
-  }
-
-}
index e31ce4363940edacd1ff998304b10e2fe88aaa96..b3355a89228cadb5273de6602900d9549c3328f0 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.scanner.bootstrap;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Optional;
-import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.config.Settings;
 import org.sonar.api.utils.MessageException;
 
@@ -32,7 +31,7 @@ import org.sonar.api.utils.MessageException;
 @Deprecated
 public class MutableGlobalSettings extends Settings {
 
-  private final AnalysisMode mode;
+  private final GlobalAnalysisMode mode;
   private final Map<String, String> mutableProperties = new HashMap<>();
 
   public MutableGlobalSettings(GlobalConfiguration globalSettings) {
index dc39f5c0ced4623b320fcce02a3b243647cbdc01..a219abe87aafdef8558f3f8de3b0042a69a69813 100644 (file)
@@ -47,9 +47,9 @@ public class ScannerPluginPredicate implements Predicate<String> {
 
   private final Set<String> whites = new HashSet<>();
   private final Set<String> blacks = new HashSet<>();
-  private final GlobalMode mode;
+  private final GlobalAnalysisMode mode;
 
-  public ScannerPluginPredicate(Configuration settings, GlobalMode mode) {
+  public ScannerPluginPredicate(Configuration settings, GlobalAnalysisMode mode) {
     this.mode = mode;
     if (mode.isPreview() || mode.isIssues()) {
       // These default values are not supported by Settings because the class CorePlugin
index 19e0169e182efe581794ffb70dd4eef709f68d89..6ec0eaac6dc765670a6a68e8bc60ee38766e98b8 100644 (file)
@@ -50,9 +50,9 @@ public class ScannerWsClient {
 
   private final WsClient target;
   private final boolean hasCredentials;
-  private final GlobalMode globalMode;
+  private final GlobalAnalysisMode globalMode;
 
-  public ScannerWsClient(WsClient target, boolean hasCredentials, GlobalMode globalMode) {
+  public ScannerWsClient(WsClient target, boolean hasCredentials, GlobalAnalysisMode globalMode) {
     this.target = target;
     this.hasCredentials = hasCredentials;
     this.globalMode = globalMode;
index 3ffd9275d3990750701dbfd8f56ca02add430342..51d0b4c50e5bd945ef08420d6371f6ba53ab02f0 100644 (file)
@@ -39,7 +39,7 @@ public class ScannerWsClientProvider extends ProviderAdapter {
 
   private ScannerWsClient wsClient;
 
-  public synchronized ScannerWsClient provide(final GlobalProperties settings, final EnvironmentInformation env, GlobalMode globalMode) {
+  public synchronized ScannerWsClient provide(final GlobalProperties settings, final EnvironmentInformation env, GlobalAnalysisMode globalMode) {
     if (wsClient == null) {
       String url = defaultIfBlank(settings.property("sonar.host.url"), CoreProperties.SERVER_BASE_URL_DEFAULT_VALUE);
       HttpConnector.Builder connectorBuilder = HttpConnector.newBuilder();
index 62e5d10fc0da5e73e868ab9acf3ebd2a6875ecbc..6433faa01f01404ad6634f0fc1667f3664e2fc2e 100644 (file)
@@ -32,7 +32,6 @@ import org.apache.commons.csv.CSVFormat;
 import org.apache.commons.csv.CSVParser;
 import org.apache.commons.csv.CSVRecord;
 import org.apache.commons.lang.ArrayUtils;
-import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.config.Configuration;
 import org.sonar.api.config.Encryption;
 import org.sonar.api.config.PropertyDefinition;
@@ -40,6 +39,7 @@ import org.sonar.api.config.PropertyDefinitions;
 import org.sonar.api.utils.MessageException;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
+import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
 
 import static java.util.Objects.requireNonNull;
 import static org.apache.commons.lang.StringUtils.trim;
@@ -51,10 +51,10 @@ public abstract class DefaultConfiguration implements Configuration {
 
   private final PropertyDefinitions definitions;
   private final Encryption encryption;
-  private final AnalysisMode mode;
+  private final GlobalAnalysisMode mode;
   private final Map<String, String> properties = new HashMap<>();
 
-  public DefaultConfiguration(PropertyDefinitions propertyDefinitions, Encryption encryption, AnalysisMode mode, Map<String, String> props) {
+  public DefaultConfiguration(PropertyDefinitions propertyDefinitions, Encryption encryption, GlobalAnalysisMode mode, Map<String, String> props) {
     this.definitions = requireNonNull(propertyDefinitions);
     this.encryption = encryption;
     this.mode = mode;
@@ -64,7 +64,7 @@ public abstract class DefaultConfiguration implements Configuration {
     });
   }
 
-  public AnalysisMode getMode() {
+  public GlobalAnalysisMode getMode() {
     return mode;
   }
 
index af5bddfc8f5171225b5361273ab40dc861f73f95..df2d09e1f1a0df0ab22be8ec203f3340f043e856 100644 (file)
@@ -45,7 +45,7 @@ import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.scanner.protocol.output.ScannerReport.Duplicate;
 import org.sonar.scanner.protocol.output.ScannerReport.Duplication;
 import org.sonar.scanner.report.ReportPublisher;
-import org.sonar.scanner.scan.BranchConfiguration;
+import org.sonar.scanner.scan.branch.BranchConfiguration;
 import org.sonar.scanner.scan.filesystem.InputComponentStore;
 import org.sonar.scanner.util.ProgressReport;
 
index 8f4a0c420d667fc160c4a4796f43479c2097ed1b..bd1d9f8914a86ec13d837bd6b564680de391f1ca 100644 (file)
@@ -40,7 +40,7 @@ import org.sonar.api.resources.Resource;
 import org.sonar.api.resources.ResourceUtils;
 import org.sonar.core.component.ComponentKeys;
 import org.sonar.scanner.index.DefaultIndex;
-import org.sonar.scanner.scan.BranchConfiguration;
+import org.sonar.scanner.scan.branch.BranchConfiguration;
 import org.sonar.scanner.sensor.DefaultSensorContext;
 
 public class DeprecatedSensorContext extends DefaultSensorContext implements SensorContext {
index c8dd7a3097bd01fe6cf53ed14107b6b198fedf9a..a36dbcef2c0d97e9c9e9fdb51900732fab9125e6 100644 (file)
@@ -44,7 +44,7 @@ import org.sonar.scanner.protocol.output.ScannerReport.ComponentLink.ComponentLi
 import org.sonar.scanner.protocol.output.ScannerReport.Issue;
 import org.sonar.scanner.protocol.output.ScannerReportReader;
 import org.sonar.scanner.protocol.output.ScannerReportWriter;
-import org.sonar.scanner.scan.BranchConfiguration;
+import org.sonar.scanner.scan.branch.BranchConfiguration;
 
 /**
  * Adds components and analysis metadata to output report
index 9d9d62328f9db2af6c505193088df00403efb51e..18390ef6a89131fc1ed098963b9a4cb5cbdc6a4a 100644 (file)
@@ -21,12 +21,12 @@ package org.sonar.scanner.report;
 
 import java.util.Map.Entry;
 import java.util.Optional;
-import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
 import org.sonar.api.batch.fs.internal.DefaultInputModule;
 import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
 import org.sonar.api.config.Configuration;
 import org.sonar.scanner.ProjectAnalysisInfo;
+import org.sonar.scanner.analysis.DefaultAnalysisMode;
 import org.sonar.scanner.bootstrap.ScannerPlugin;
 import org.sonar.scanner.bootstrap.ScannerPluginRepository;
 import org.sonar.scanner.cpd.CpdSettings;
@@ -35,7 +35,7 @@ import org.sonar.scanner.protocol.output.ScannerReport.Metadata.BranchType;
 import org.sonar.scanner.protocol.output.ScannerReportWriter;
 import org.sonar.scanner.rule.ModuleQProfiles;
 import org.sonar.scanner.rule.QProfile;
-import org.sonar.scanner.scan.BranchConfiguration;
+import org.sonar.scanner.scan.branch.BranchConfiguration;
 
 import static org.sonar.core.config.ScannerProperties.ORGANIZATION;
 
@@ -46,12 +46,12 @@ public class MetadataPublisher implements ReportPublisherStep {
   private final ProjectAnalysisInfo projectAnalysisInfo;
   private final InputModuleHierarchy moduleHierarchy;
   private final CpdSettings cpdSettings;
-  private final AnalysisMode mode;
+  private final DefaultAnalysisMode mode;
   private final ScannerPluginRepository pluginRepository;
   private final BranchConfiguration branchConfiguration;
 
   public MetadataPublisher(ProjectAnalysisInfo projectAnalysisInfo, InputModuleHierarchy moduleHierarchy, Configuration settings,
-    ModuleQProfiles qProfiles, CpdSettings cpdSettings, AnalysisMode mode, ScannerPluginRepository pluginRepository, BranchConfiguration branchConfiguration) {
+    ModuleQProfiles qProfiles, CpdSettings cpdSettings, DefaultAnalysisMode mode, ScannerPluginRepository pluginRepository, BranchConfiguration branchConfiguration) {
     this.projectAnalysisInfo = projectAnalysisInfo;
     this.moduleHierarchy = moduleHierarchy;
     this.settings = settings;
@@ -101,8 +101,8 @@ public class MetadataPublisher implements ReportPublisherStep {
     writer.writeMetadata(builder.build());
   }
 
-  private static BranchType toProtobufBranchType(BranchConfiguration.BranchType branchType) {
-    if (branchType == BranchConfiguration.BranchType.LONG) {
+  private static BranchType toProtobufBranchType(org.sonar.scanner.scan.branch.BranchType branchType) {
+    if (branchType == org.sonar.scanner.scan.branch.BranchType.LONG) {
       return BranchType.LONG;
     }
     return BranchType.SHORT;
index 790e6192772c56ae1e2b1f1cbdad5bf1e4140ccc..4f24f13b3dd8861f9833cb008b14dca210884edd 100644 (file)
@@ -45,9 +45,10 @@ import org.sonar.api.utils.ZipUtils;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.scanner.analysis.DefaultAnalysisMode;
+import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
 import org.sonar.scanner.bootstrap.ScannerWsClient;
 import org.sonar.scanner.protocol.output.ScannerReportWriter;
-import org.sonar.scanner.scan.BranchConfiguration;
+import org.sonar.scanner.scan.branch.BranchConfiguration;
 import org.sonarqube.ws.MediaTypes;
 import org.sonarqube.ws.WsCe;
 import org.sonarqube.ws.client.HttpException;
@@ -71,21 +72,23 @@ public class ReportPublisher implements Startable {
   private final ScannerWsClient wsClient;
   private final AnalysisContextReportPublisher contextPublisher;
   private final InputModuleHierarchy moduleHierarchy;
-  private final DefaultAnalysisMode analysisMode;
+  private final GlobalAnalysisMode analysisMode;
   private final TempFolder temp;
   private final ReportPublisherStep[] publishers;
   private final Server server;
   private final BranchConfiguration branchConfiguration;
+  private final DefaultAnalysisMode analysisFlags;
 
   private Path reportDir;
   private ScannerReportWriter writer;
 
-  public ReportPublisher(Configuration settings, ScannerWsClient wsClient, Server server, AnalysisContextReportPublisher contextPublisher,
-                         InputModuleHierarchy moduleHierarchy, DefaultAnalysisMode analysisMode, TempFolder temp, ReportPublisherStep[] publishers, BranchConfiguration branchConfiguration) {
+  public ReportPublisher(Configuration settings, ScannerWsClient wsClient, Server server, AnalysisContextReportPublisher contextPublisher, DefaultAnalysisMode analysisFlags,
+    InputModuleHierarchy moduleHierarchy, GlobalAnalysisMode analysisMode, TempFolder temp, ReportPublisherStep[] publishers, BranchConfiguration branchConfiguration) {
     this.settings = settings;
     this.wsClient = wsClient;
     this.server = server;
     this.contextPublisher = contextPublisher;
+    this.analysisFlags = analysisFlags;
     this.moduleHierarchy = moduleHierarchy;
     this.analysisMode = analysisMode;
     this.temp = temp;
@@ -177,7 +180,7 @@ public class ReportPublisher implements Startable {
       .setParam("projectBranch", moduleHierarchy.root().getBranch())
       .setPart("report", filePart);
 
-    if (analysisMode.isIncremental()) {
+    if (analysisFlags.isIncremental()) {
       post.setParam("characteristic", "incremental=true");
     }
 
index d4675ff1c073f734815df348fe19ce826ddf3a87..a35ddde0fbd3cb78c38ec512ef06bc0a38075049 100644 (file)
@@ -24,23 +24,20 @@ 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.DefaultAnalysisMode;
-import org.sonar.scanner.scan.BranchConfiguration;
+import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
+import org.sonar.scanner.scan.branch.BranchConfiguration;
 
 public class ProjectRepositoriesProvider extends ProviderAdapter {
   private static final Logger LOG = Loggers.get(ProjectRepositoriesProvider.class);
   private static final String LOG_MSG = "Load project repositories";
   private ProjectRepositories project = null;
 
-  public ProjectRepositories provide(ProjectRepositoriesLoader loader, ProjectKey projectKey, DefaultAnalysisMode mode, BranchConfiguration branchConfig) {
-    return provideInternal(loader, projectKey, mode.isIssues(), branchConfig);
-  }
-
-  protected ProjectRepositories provideInternal(ProjectRepositoriesLoader loader, ProjectKey projectKey, boolean isIssueMode, BranchConfiguration branchConfig) {
+  public ProjectRepositories provide(ProjectRepositoriesLoader loader, ProjectKey projectKey, GlobalAnalysisMode mode, BranchConfiguration branchConfig) {
     if (project == null) {
+      boolean isIssuesMode = mode.isIssues();
       Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG);
-      project = loader.load(projectKey.get(), isIssueMode, branchConfig.branchBase());
-      checkProject(isIssueMode);
+      project = loader.load(projectKey.get(), isIssuesMode, branchConfig.branchBase());
+      checkProject(isIssuesMode);
       profiler.stopInfo();
     }
 
index 928d9c8ba1fff3fb7362690a2bd1ae971df7fe58..a999fa980cf9b99bd5f188061ed797271c170482 100644 (file)
 package org.sonar.scanner.repository.settings;
 
 import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Throwables;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.HttpURLConnection;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
 import javax.annotation.Nullable;
 import org.apache.commons.lang.StringEscapeUtils;
+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;
@@ -38,9 +42,10 @@ import org.sonarqube.ws.Settings.FieldValues.Value;
 import org.sonarqube.ws.Settings.Setting;
 import org.sonarqube.ws.Settings.ValuesWsResponse;
 import org.sonarqube.ws.client.GetRequest;
+import org.sonarqube.ws.client.HttpException;
 
 public class DefaultSettingsLoader implements SettingsLoader {
-
+  static final String URL = "api/settings/values.protobuf";
   private ScannerWsClient wsClient;
   private static final Logger LOG = Loggers.get(DefaultSettingsLoader.class);
 
@@ -50,23 +55,58 @@ public class DefaultSettingsLoader implements SettingsLoader {
 
   @Override
   public Map<String, String> load(@Nullable String componentKey) {
-    String url = "api/settings/values.protobuf";
     Profiler profiler = Profiler.create(LOG);
-    if (componentKey != null) {
-      url += "?component=" + ScannerUtils.encodeForUrl(componentKey);
-      profiler.startInfo("Load settings for component '" + componentKey + "'");
-    } else {
-      profiler.startInfo("Load global settings");
+
+    try {
+      if (componentKey != null) {
+        profiler.startInfo("Load settings for component '" + componentKey + "'");
+        return loadProjectSettings(componentKey);
+      } else {
+        profiler.startInfo("Load global settings");
+        return loadSettings(URL);
+      }
+    } catch (IOException e) {
+      throw new IllegalStateException("Failed to load server settings", e);
+    } finally {
+      profiler.stopInfo();
     }
+  }
+
+  private Map<String, String> loadSettings(String url) throws IOException {
     try (InputStream is = wsClient.call(new GetRequest(url)).contentStream()) {
       ValuesWsResponse values = ValuesWsResponse.parseFrom(is);
-      profiler.stopInfo();
       return toMap(values.getSettingsList());
-    } catch (IOException e) {
-      throw new IllegalStateException("Failed to load server settings", e);
     }
   }
 
+  private Map<String, String> loadProjectSettings(String componentKey) throws IOException {
+    String url = URL + "?component=" + ScannerUtils.encodeForUrl(componentKey);
+    try {
+      return loadSettings(url);
+    } catch (RuntimeException e) {
+      if (shouldThrow(e)) {
+        throw e;
+      }
+
+      LOG.debug("Project settings not available - continuing without it");
+    }
+    return Collections.emptyMap();
+  }
+
+  private static boolean shouldThrow(Exception e) {
+    for (Throwable t : Throwables.getCausalChain(e)) {
+      if (t instanceof HttpException) {
+        HttpException http = (HttpException) t;
+        return http.code() != HttpURLConnection.HTTP_NOT_FOUND;
+      }
+      if (t instanceof MessageException) {
+        return true;
+      }
+    }
+
+    return false;
+  }
+
   @VisibleForTesting
   static Map<String, String> toMap(List<Setting> settingsList) {
     Map<String, String> result = new LinkedHashMap<>();
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/BranchConfiguration.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/BranchConfiguration.java
deleted file mode 100644 (file)
index 2a4152c..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 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 javax.annotation.CheckForNull;
-import javax.annotation.concurrent.Immutable;
-
-@Immutable
-public interface BranchConfiguration {
-
-  enum BranchType {
-    SHORT, LONG
-  }
-
-  /**
-   * The type of the branch we're on, determined by:
-   *
-   * - If the specified branch exists on the server, then its type
-   * - If the branch name matches the pattern of long-lived branches, then it's long-lived
-   * - Otherwise it's short-lived
-   *
-   * @return type of the current branch
-   */
-  BranchType branchType();
-
-  default boolean isShortLivingBranch() {
-    return branchType() == BranchType.SHORT;
-  }
-
-  /**
-   * The name of the branch.
-   */
-  @CheckForNull
-  String branchName();
-
-  /**
-   * The name of the target branch to merge into.
-   */
-  @CheckForNull
-  String branchTarget();
-
-  /**
-   * The name of the base branch to determine project repository and changed files.
-   */
-  @CheckForNull
-  String branchBase();
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/BranchConfigurationLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/BranchConfigurationLoader.java
deleted file mode 100644 (file)
index 5d50c99..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 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.sonar.api.batch.InstantiationStrategy;
-import org.sonar.api.batch.ScannerSide;
-import org.sonar.scanner.bootstrap.GlobalConfiguration;
-
-@ScannerSide
-@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
-public interface BranchConfigurationLoader {
-  BranchConfiguration load(String projectKey, GlobalConfiguration settings);
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/BranchConfigurationProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/BranchConfigurationProvider.java
deleted file mode 100644 (file)
index db35c12..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 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.annotations.Nullable;
-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.GlobalConfiguration;
-
-public class BranchConfigurationProvider extends ProviderAdapter {
-
-  private static final Logger LOG = Loggers.get(BranchConfigurationProvider.class);
-  private static final String LOG_MSG = "Load project branches";
-
-  private BranchConfiguration branchConfiguration = null;
-
-  public BranchConfiguration provide(@Nullable BranchConfigurationLoader loader, ProjectKey projectKey, GlobalConfiguration globalConfiguration) {
-    if (branchConfiguration == null) {
-      if (loader == null) {
-        branchConfiguration = new DefaultBranchConfiguration();
-      } else {
-        Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG);
-        branchConfiguration = loader.load(projectKey.get(), globalConfiguration);
-        profiler.stopInfo();
-      }
-    }
-    return branchConfiguration;
-  }
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/BranchParamsValidator.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/BranchParamsValidator.java
deleted file mode 100644 (file)
index 441ca02..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 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 java.util.List;
-import javax.annotation.Nullable;
-import org.sonar.api.batch.InstantiationStrategy;
-import org.sonar.api.batch.ScannerSide;
-
-@ScannerSide
-@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
-public interface BranchParamsValidator {
-  void validate(List<String> validationMessages, @Nullable String deprecatedBranchName, boolean incrementalMode);
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DefaultBranchConfiguration.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DefaultBranchConfiguration.java
deleted file mode 100644 (file)
index 97a9ddf..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 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 javax.annotation.CheckForNull;
-import javax.annotation.concurrent.Immutable;
-
-@Immutable
-public class DefaultBranchConfiguration implements BranchConfiguration {
-  @Override
-  public BranchType branchType() {
-    return BranchType.LONG;
-  }
-
-  @CheckForNull
-  @Override
-  public String branchName() {
-    return null;
-  }
-
-  @CheckForNull
-  @Override
-  public String branchTarget() {
-    return null;
-  }
-
-  @CheckForNull
-  @Override
-  public String branchBase() {
-    return null;
-  }
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DefaultBranchParamsValidator.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DefaultBranchParamsValidator.java
deleted file mode 100644 (file)
index 4d39cda..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 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 java.util.List;
-import javax.annotation.Nullable;
-
-public class DefaultBranchParamsValidator implements BranchParamsValidator {
-  @Override
-  public void validate(List<String> validationMessages, @Nullable String deprecatedBranchName, boolean incrementalMode) {
-    // no-op
-  }
-}
index a2a4c0b90b09d15d5fa51f72804503059e83cc62..c6a73416a9d440d72acedac1eeecc659452f89d3 100644 (file)
 package org.sonar.scanner.scan;
 
 import java.util.Map;
-import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.config.Encryption;
 import org.sonar.api.config.PropertyDefinitions;
+import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
 import org.sonar.scanner.config.DefaultConfiguration;
 
 public class ModuleSettings extends DefaultConfiguration {
 
-  public ModuleSettings(PropertyDefinitions propertyDefinitions, Encryption encryption, AnalysisMode mode, Map<String, String> props) {
+  public ModuleSettings(PropertyDefinitions propertyDefinitions, Encryption encryption, GlobalAnalysisMode mode, Map<String, String> props) {
     super(propertyDefinitions, encryption, mode, props);
   }
 
index 25db68aad37aa1ad5a63102e0b97c28d1e6ff4ca..46742e63153e7da2b408b756aabc7a370972850e 100644 (file)
@@ -25,9 +25,9 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import org.picocontainer.injectors.ProviderAdapter;
-import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
 import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
 import org.sonar.scanner.bootstrap.GlobalConfiguration;
 import org.sonar.scanner.report.AnalysisContextReportPublisher;
 import org.sonar.scanner.repository.ProjectRepositories;
@@ -37,7 +37,7 @@ public class ModuleSettingsProvider extends ProviderAdapter {
   private ModuleSettings projectSettings;
 
   public ModuleSettings provide(GlobalConfiguration globalSettings, DefaultInputModule module, ProjectRepositories projectRepos,
-    AnalysisMode analysisMode, AnalysisContextReportPublisher contextReportPublisher) {
+    GlobalAnalysisMode analysisMode, AnalysisContextReportPublisher contextReportPublisher) {
     if (projectSettings == null) {
 
       Map<String, String> settings = new LinkedHashMap<>();
index da9caf1a825ed85ab76436f9f62fe5e230f34d80..f906f59f53250768be358000fa11fcba7a77d173 100644 (file)
@@ -23,10 +23,10 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
+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.analysis.DefaultAnalysisMode;
 import org.sonar.scanner.bootstrap.MutableGlobalSettings;
 import org.sonar.scanner.repository.ProjectRepositories;
 
@@ -37,11 +37,11 @@ import org.sonar.scanner.repository.ProjectRepositories;
 public class MutableModuleSettings extends Settings {
 
   private final ProjectRepositories projectRepos;
-  private final DefaultAnalysisMode analysisMode;
+  private final AnalysisMode analysisMode;
   private final Map<String, String> properties = new HashMap<>();
 
   public MutableModuleSettings(MutableGlobalSettings batchSettings, ProjectDefinition moduleDefinition, ProjectRepositories projectSettingsRepo,
-    DefaultAnalysisMode analysisMode) {
+    AnalysisMode analysisMode) {
     super(batchSettings.getDefinitions(), batchSettings.getEncryption());
     this.projectRepos = projectSettingsRepo;
     this.analysisMode = analysisMode;
index 8f0fb5ea142124cad02aef39c5d5d5c083656fc1..8c234a9ed33001f694e1344c0fc24de2b8053358 100644 (file)
@@ -25,7 +25,7 @@ import java.util.Optional;
 import org.sonar.api.batch.bootstrap.ProjectReactor;
 import org.sonar.api.config.Settings;
 import org.sonar.api.utils.MessageException;
-import org.sonar.scanner.analysis.DefaultAnalysisMode;
+import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
 import org.sonar.scanner.bootstrap.MutableGlobalSettings;
 import org.sonar.scanner.repository.ProjectRepositories;
 
@@ -35,10 +35,10 @@ import org.sonar.scanner.repository.ProjectRepositories;
 @Deprecated
 public class MutableProjectSettings extends Settings {
 
-  private final DefaultAnalysisMode mode;
+  private final GlobalAnalysisMode mode;
   private final Map<String, String> properties = new HashMap<>();
 
-  public MutableProjectSettings(ProjectReactor reactor, MutableGlobalSettings mutableGlobalSettings, ProjectRepositories projectRepositories, DefaultAnalysisMode mode) {
+  public MutableProjectSettings(ProjectReactor reactor, MutableGlobalSettings mutableGlobalSettings, ProjectRepositories projectRepositories, GlobalAnalysisMode mode) {
     super(mutableGlobalSettings.getDefinitions(), mutableGlobalSettings.getEncryption());
     this.mode = mode;
     addProperties(mutableGlobalSettings.getProperties());
index 81f2ba4ffd9b167a69a216f21d8594c77e44d1a8..24d1b6a4bcaa13b18de0cca6616f2e56cd9e1d86 100644 (file)
@@ -24,28 +24,32 @@ import java.util.ArrayList;
 import java.util.List;
 import javax.annotation.Nullable;
 import org.apache.commons.lang.StringUtils;
+import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
 import org.sonar.api.batch.bootstrap.ProjectReactor;
 import org.sonar.api.utils.MessageException;
 import org.sonar.core.component.ComponentKeys;
 import org.sonar.scanner.analysis.DefaultAnalysisMode;
+import org.sonar.scanner.scan.branch.BranchParamsValidator;
+import org.sonar.scanner.scan.branch.DefaultBranchParamsValidator;
 
 /**
  * This class aims at validating project reactor
  * @since 3.6
  */
 public class ProjectReactorValidator {
-  private final DefaultAnalysisMode mode;
-
+  private final AnalysisMode mode;
   private final BranchParamsValidator branchParamsValidator;
+  private final DefaultAnalysisMode analysisFlags;
 
-  public ProjectReactorValidator(DefaultAnalysisMode mode, BranchParamsValidator branchParamsValidator) {
+  public ProjectReactorValidator(AnalysisMode mode, DefaultAnalysisMode analysisFlags, BranchParamsValidator branchParamsValidator) {
     this.mode = mode;
+    this.analysisFlags = analysisFlags;
     this.branchParamsValidator = branchParamsValidator;
   }
 
-  public ProjectReactorValidator(DefaultAnalysisMode mode) {
-    this(mode, new DefaultBranchParamsValidator());
+  public ProjectReactorValidator(AnalysisMode mode, DefaultAnalysisMode analysisFlags) {
+    this(mode, analysisFlags, new DefaultBranchParamsValidator());
   }
 
   public void validate(ProjectReactor reactor) {
@@ -61,7 +65,7 @@ public class ProjectReactorValidator {
 
     String deprecatedBranchName = reactor.getRoot().getBranch();
 
-    branchParamsValidator.validate(validationMessages, deprecatedBranchName, mode.isIncremental());
+    branchParamsValidator.validate(validationMessages, deprecatedBranchName, analysisFlags.isIncremental());
     validateBranch(validationMessages, deprecatedBranchName);
 
     if (!validationMessages.isEmpty()) {
index 42311f87b7551e10d59745719fd9526fcbbcc703..7deb3166880efa1bf99343d8029b33eef3530090 100644 (file)
@@ -41,6 +41,7 @@ import org.sonar.scanner.analysis.DefaultAnalysisMode;
 import org.sonar.scanner.bootstrap.ExtensionInstaller;
 import org.sonar.scanner.bootstrap.ExtensionMatcher;
 import org.sonar.scanner.bootstrap.ExtensionUtils;
+import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
 import org.sonar.scanner.bootstrap.MetricProvider;
 import org.sonar.scanner.cpd.CpdExecutor;
 import org.sonar.scanner.cpd.CpdSettings;
@@ -75,6 +76,7 @@ import org.sonar.scanner.repository.DefaultQualityProfileLoader;
 import org.sonar.scanner.repository.DefaultServerIssuesLoader;
 import org.sonar.scanner.repository.ProjectRepositories;
 import org.sonar.scanner.repository.ProjectRepositoriesLoader;
+import org.sonar.scanner.repository.ProjectRepositoriesProvider;
 import org.sonar.scanner.repository.QualityProfileLoader;
 import org.sonar.scanner.repository.QualityProfileProvider;
 import org.sonar.scanner.repository.ServerIssuesLoader;
@@ -85,6 +87,10 @@ import org.sonar.scanner.rule.DefaultActiveRulesLoader;
 import org.sonar.scanner.rule.DefaultRulesLoader;
 import org.sonar.scanner.rule.RulesLoader;
 import org.sonar.scanner.rule.RulesProvider;
+import org.sonar.scanner.scan.branch.BranchConfiguration;
+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.filesystem.BatchIdGenerator;
 import org.sonar.scanner.scan.filesystem.InputComponentStoreProvider;
 import org.sonar.scanner.scan.measure.DefaultMetricFinder;
@@ -137,6 +143,9 @@ public class ProjectScanContainer extends ComponentContainer {
       Storages.class,
       new RulesProvider(),
       new BranchConfigurationProvider(),
+      new ProjectBranchesProvider(),
+      DefaultAnalysisMode.class,
+      new ProjectRepositoriesProvider(),
 
       // temp
       new AnalysisTempFolderProvider(),
@@ -223,10 +232,9 @@ public class ProjectScanContainer extends ComponentContainer {
 
   @Override
   protected void doAfterStart() {
-    DefaultAnalysisMode analysisMode = getComponentByType(DefaultAnalysisMode.class);
+    GlobalAnalysisMode analysisMode = getComponentByType(GlobalAnalysisMode.class);
     InputModuleHierarchy tree = getComponentByType(InputModuleHierarchy.class);
 
-    analysisMode.printMode();
     LOG.info("Project key: {}", tree.root().key());
     String organization = props.property("sonar.organization");
     if (StringUtils.isNotEmpty(organization)) {
@@ -251,7 +259,7 @@ public class ProjectScanContainer extends ComponentContainer {
     }
   }
 
-  private static String toDisplayName(BranchConfiguration.BranchType branchType) {
+  private static String toDisplayName(BranchType branchType) {
     switch (branchType) {
       case LONG:
         return "long living";
index a25dc51ad43d96e40a46a6a374842b5242365ce8..930a728d2095b1fefd69ba37c750fae63ca19059 100644 (file)
 package org.sonar.scanner.scan;
 
 import java.util.Map;
-import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.config.Encryption;
 import org.sonar.api.config.PropertyDefinitions;
+import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
 import org.sonar.scanner.config.DefaultConfiguration;
 
 public class ProjectSettings extends DefaultConfiguration {
 
-  public ProjectSettings(PropertyDefinitions propertyDefinitions, Encryption encryption, AnalysisMode mode, Map<String, String> props) {
+  public ProjectSettings(PropertyDefinitions propertyDefinitions, Encryption encryption, GlobalAnalysisMode mode, Map<String, String> props) {
     super(propertyDefinitions, encryption, mode, props);
   }
 
index ec167a392901d7d3882bcca54698d4e93e98e3e7..4823c8ec0063a41e9bf4ba244ed9c80da2132efd 100644 (file)
@@ -22,25 +22,29 @@ package org.sonar.scanner.scan;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import org.picocontainer.injectors.ProviderAdapter;
-import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.batch.bootstrap.ProjectReactor;
 import org.sonar.scanner.bootstrap.GlobalConfiguration;
-import org.sonar.scanner.repository.ProjectRepositories;
+import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
+import org.sonar.scanner.repository.settings.SettingsLoader;
 
 public class ProjectSettingsProvider extends ProviderAdapter {
 
   private ProjectSettings projectSettings;
 
-  public ProjectSettings provide(ProjectReactor reactor, GlobalConfiguration globalSettings, ProjectRepositories projectRepositories, AnalysisMode mode) {
+  public ProjectSettings provide(ProjectReactor reactor, GlobalConfiguration globalSettings, SettingsLoader settingsLoader, GlobalAnalysisMode mode) {
     if (projectSettings == null) {
 
       Map<String, String> settings = new LinkedHashMap<>();
       settings.putAll(globalSettings.getProperties());
-      settings.putAll(projectRepositories.settings(reactor.getRoot().getKeyWithBranch()));
+      settings.putAll(loadProjectSettings(settingsLoader, reactor.getRoot().getKeyWithBranch()));
       settings.putAll(reactor.getRoot().properties());
 
       projectSettings = new ProjectSettings(globalSettings.getDefinitions(), globalSettings.getEncryption(), mode, settings);
     }
     return projectSettings;
   }
+
+  private Map<String, String> loadProjectSettings(SettingsLoader settingsLoader, String projectKey) {
+    return settingsLoader.load(projectKey);
+  }
 }
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/BranchConfiguration.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/BranchConfiguration.java
new file mode 100644 (file)
index 0000000..7c29f02
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.branch;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.concurrent.Immutable;
+
+@Immutable
+public interface BranchConfiguration {
+
+  /**
+   * The type of the branch we're on, determined by:
+   *
+   * - If the specified branch exists on the server, then its type
+   * - If the branch name matches the pattern of long-lived branches, then it's long-lived
+   * - Otherwise it's short-lived
+   *
+   * @return type of the current branch
+   */
+  BranchType branchType();
+
+  default boolean isShortLivingBranch() {
+    return branchType() == BranchType.SHORT;
+  }
+
+  /**
+   * The name of the branch.
+   */
+  @CheckForNull
+  String branchName();
+
+  /**
+   * The name of the target branch to merge into.
+   */
+  @CheckForNull
+  String branchTarget();
+
+  /**
+   * The name of the base branch to determine project repository and changed files.
+   */
+  @CheckForNull
+  String branchBase();
+}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/BranchConfigurationLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/BranchConfigurationLoader.java
new file mode 100644 (file)
index 0000000..ba0e0cd
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.branch;
+
+import org.sonar.api.batch.InstantiationStrategy;
+import org.sonar.api.batch.ScannerSide;
+import org.sonar.scanner.scan.ProjectSettings;
+
+@ScannerSide
+@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
+public interface BranchConfigurationLoader {
+  BranchConfiguration load(ProjectSettings projectSettings, ProjectBranches branches);
+}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/BranchConfigurationProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/BranchConfigurationProvider.java
new file mode 100644 (file)
index 0000000..aac1661
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.branch;
+
+import org.picocontainer.annotations.Nullable;
+import org.picocontainer.injectors.ProviderAdapter;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
+import org.sonar.api.utils.log.Profiler;
+import org.sonar.scanner.scan.ProjectSettings;
+
+public class BranchConfigurationProvider extends ProviderAdapter {
+
+  private static final Logger LOG = Loggers.get(BranchConfigurationProvider.class);
+  private static final String LOG_MSG = "Load branch configuration";
+
+  private BranchConfiguration branchConfiguration = null;
+
+  public BranchConfiguration provide(@Nullable BranchConfigurationLoader loader, ProjectSettings projectSettings, ProjectBranches branches) {
+    if (branchConfiguration == null) {
+      if (loader == null) {
+        branchConfiguration = new DefaultBranchConfiguration();
+      } else {
+        Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG);
+        branchConfiguration = loader.load(projectSettings, branches);
+        profiler.stopInfo();
+      }
+    }
+    return branchConfiguration;
+  }
+}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/BranchInfo.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/BranchInfo.java
new file mode 100644 (file)
index 0000000..508d8d1
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.branch;
+
+import javax.annotation.concurrent.Immutable;
+
+/**
+ * Container class for information about a branch.
+ */
+@Immutable
+public class BranchInfo {
+  private final String name;
+  private final BranchType type;
+  private final boolean isMain;
+
+  public BranchInfo(String name, BranchType type, boolean isMain) {
+    this.name = name;
+    this.type = type;
+    this.isMain = isMain;
+  }
+
+  public String name() {
+    return name;
+  }
+
+  public BranchType type() {
+    return type;
+  }
+
+  public boolean isMain() {
+    return isMain;
+  }
+}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/BranchParamsValidator.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/BranchParamsValidator.java
new file mode 100644 (file)
index 0000000..99bc2b6
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.branch;
+
+import java.util.List;
+import javax.annotation.Nullable;
+import org.sonar.api.batch.InstantiationStrategy;
+import org.sonar.api.batch.ScannerSide;
+
+@ScannerSide
+@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
+public interface BranchParamsValidator {
+  void validate(List<String> validationMessages, @Nullable String deprecatedBranchName, boolean incrementalMode);
+}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/BranchType.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/BranchType.java
new file mode 100644 (file)
index 0000000..e5a93e4
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.branch;
+
+public enum BranchType {
+  SHORT, LONG
+}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/DefaultBranchConfiguration.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/DefaultBranchConfiguration.java
new file mode 100644 (file)
index 0000000..1d17224
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.branch;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.concurrent.Immutable;
+
+@Immutable
+public class DefaultBranchConfiguration implements BranchConfiguration {
+  @Override
+  public BranchType branchType() {
+    return BranchType.LONG;
+  }
+
+  @CheckForNull
+  @Override
+  public String branchName() {
+    return null;
+  }
+
+  @CheckForNull
+  @Override
+  public String branchTarget() {
+    return null;
+  }
+
+  @CheckForNull
+  @Override
+  public String branchBase() {
+    return null;
+  }
+}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/DefaultBranchParamsValidator.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/DefaultBranchParamsValidator.java
new file mode 100644 (file)
index 0000000..09db0ed
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.branch;
+
+import java.util.List;
+import javax.annotation.Nullable;
+
+public class DefaultBranchParamsValidator implements BranchParamsValidator {
+  @Override
+  public void validate(List<String> validationMessages, @Nullable String deprecatedBranchName, boolean incrementalMode) {
+    // no-op
+  }
+}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectBranches.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectBranches.java
new file mode 100644 (file)
index 0000000..697ab5d
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.branch;
+
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import javax.annotation.concurrent.Immutable;
+
+/**
+ * Container class for information about the branches of a project.
+ */
+@Immutable
+public class ProjectBranches {
+
+  private final Map<String, BranchInfo> branches;
+
+  public ProjectBranches(List<BranchInfo> branchInfos) {
+    branches = branchInfos.stream().collect(Collectors.toMap(BranchInfo::name, Function.identity()));
+  }
+
+  public BranchInfo get(String name) {
+    return branches.get(name);
+  }
+
+  public boolean isEmpty() {
+    return branches.isEmpty();
+  }
+}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectBranchesLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectBranchesLoader.java
new file mode 100644 (file)
index 0000000..8b615ff
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.branch;
+
+import org.sonar.api.batch.InstantiationStrategy;
+import org.sonar.api.batch.ScannerSide;
+
+@ScannerSide
+@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
+public interface ProjectBranchesLoader {
+
+  /**
+   * Load the branches of a project.
+   */
+  ProjectBranches load(String projectKey);
+
+}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectBranchesProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectBranchesProvider.java
new file mode 100644 (file)
index 0000000..197030c
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.branch;
+
+import java.util.Collections;
+import org.picocontainer.annotations.Nullable;
+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.core.config.ScannerProperties;
+import org.sonar.scanner.bootstrap.GlobalConfiguration;
+
+public class ProjectBranchesProvider extends ProviderAdapter {
+
+  private static final Logger LOG = Loggers.get(ProjectBranchesProvider.class);
+  private static final String LOG_MSG = "Load project branches";
+
+  private ProjectBranches branches = null;
+
+  public ProjectBranches provide(@Nullable ProjectBranchesLoader loader, ProjectKey projectKey, GlobalConfiguration settings) {
+    if (branches == null) {
+      if (loader == null || !settings.get(ScannerProperties.BRANCH_NAME).isPresent()) {
+        branches = new ProjectBranches(Collections.emptyList());
+      } else {
+        Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG);
+        branches = loader.load(projectKey.get());
+        profiler.stopInfo();
+      }
+    }
+    return branches;
+  }
+}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/package-info.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/package-info.java
new file mode 100644 (file)
index 0000000..e3779c0
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.scanner.scan.branch;
+
+import javax.annotation.ParametersAreNonnullByDefault;
index 3c50e847b2827557eaed98a798aaf064847d56f1..9e5d573351d62d64e3b6ffb5bd70c133c4ff7dce 100644 (file)
@@ -32,7 +32,6 @@ import java.util.Map;
 import java.util.SortedSet;
 import java.util.TreeSet;
 import javax.annotation.CheckForNull;
-import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.batch.ScannerSide;
 import org.sonar.api.batch.fs.InputComponent;
 import org.sonar.api.batch.fs.InputDir;
@@ -44,7 +43,8 @@ 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.scanner.scan.BranchConfiguration;
+import org.sonar.scanner.analysis.DefaultAnalysisMode;
+import org.sonar.scanner.scan.branch.BranchConfiguration;
 
 /**
  * Store of all files and dirs. This cache is shared amongst all project modules. Inclusion and
@@ -65,12 +65,12 @@ public class InputComponentStore {
   private final SetMultimap<String, InputFile> filesByNameCache = LinkedHashMultimap.create();
   private final SetMultimap<String, InputFile> filesByExtensionCache = LinkedHashMultimap.create();
   private final InputModule root;
-  private final AnalysisMode mode;
+  private final DefaultAnalysisMode analysisFlags;
   private final BranchConfiguration branchConfiguration;
 
-  public InputComponentStore(DefaultInputModule root, AnalysisMode mode, BranchConfiguration branchConfiguration) {
+  public InputComponentStore(DefaultInputModule root, DefaultAnalysisMode analysisFlags, BranchConfiguration branchConfiguration) {
     this.root = root;
-    this.mode = mode;
+    this.analysisFlags = analysisFlags;
     this.branchConfiguration = branchConfiguration;
     this.put(root);
   }
@@ -83,7 +83,7 @@ public class InputComponentStore {
     return inputFileCache.values().stream()
       .map(f -> (DefaultInputFile) f)
       .filter(DefaultInputFile::isPublished)
-      .filter(f -> (!mode.isIncremental() && !branchConfiguration.isShortLivingBranch()) || f.status() != Status.SAME)::iterator;
+      .filter(f -> (!analysisFlags.isIncremental() && !branchConfiguration.isShortLivingBranch()) || f.status() != Status.SAME)::iterator;
   }
 
   public Iterable<InputFile> allFiles() {
index f8e55b011de4658f7865d4a6e893a9b1f3c20aef..79ad929d9a91b7426faddf7e7ae99d974c7d5159 100644 (file)
 package org.sonar.scanner.scan.filesystem;
 
 import org.picocontainer.injectors.ProviderAdapter;
-import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
-import org.sonar.scanner.scan.BranchConfiguration;
+import org.sonar.scanner.analysis.DefaultAnalysisMode;
+import org.sonar.scanner.scan.branch.BranchConfiguration;
 
 public class InputComponentStoreProvider extends ProviderAdapter {
   private InputComponentStore store;
 
-  public InputComponentStore provide(InputModuleHierarchy hierarchy, AnalysisMode mode, BranchConfiguration branchConfiguration) {
+  public InputComponentStore provide(InputModuleHierarchy hierarchy, DefaultAnalysisMode analysisFlags, BranchConfiguration branchConfiguration) {
     if (store == null) {
-      store = new InputComponentStore(hierarchy.root(), mode, branchConfiguration);
+      store = new InputComponentStore(hierarchy.root(), analysisFlags, branchConfiguration);
     }
     return store;
   }
index 50cf4958c5f815604ca46ee72a2e1638c7b744c3..39a304cf46c63387d2881ddae824c5aa9e30a707 100644 (file)
@@ -37,7 +37,7 @@ import org.sonar.scanner.protocol.output.ScannerReportWriter;
 import org.sonar.scanner.report.ReportPublisher;
 import org.sonar.scanner.repository.FileData;
 import org.sonar.scanner.repository.ProjectRepositories;
-import org.sonar.scanner.scan.BranchConfiguration;
+import org.sonar.scanner.scan.branch.BranchConfiguration;
 import org.sonar.scanner.scan.filesystem.DefaultModuleFileSystem;
 import org.sonar.scanner.scan.filesystem.ModuleInputComponentStore;
 
index db2e7f8e014da3be20eda7235f1070f4d4ca4962..0aa49b0ecc1b8cfa02e8ead8d7f9c357ab913502 100644 (file)
@@ -46,7 +46,7 @@ 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.utils.Version;
-import org.sonar.scanner.scan.BranchConfiguration;
+import org.sonar.scanner.scan.branch.BranchConfiguration;
 import org.sonar.scanner.sensor.noop.NoOpNewAnalysisError;
 import org.sonar.scanner.sensor.noop.NoOpNewCoverage;
 import org.sonar.scanner.sensor.noop.NoOpNewCpdTokens;
index e788a597f51ee73ba4ce90fb6bbae54a33114736..c989f6ef533552a76afe882404f096ce12c62419 100644 (file)
@@ -23,7 +23,6 @@ import com.google.common.collect.Sets;
 import java.util.Map;
 import java.util.Set;
 import java.util.stream.StreamSupport;
-import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.batch.Phase;
 import org.sonar.api.batch.fs.FileSystem;
 import org.sonar.api.batch.fs.InputFile;
@@ -40,6 +39,7 @@ import org.sonar.api.measures.CoreMetrics;
 import org.sonar.api.utils.KeyValueFormat;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
+import org.sonar.scanner.analysis.DefaultAnalysisMode;
 import org.sonar.scanner.scan.measure.MeasureCache;
 
 import static org.sonar.core.util.stream.MoreCollectors.toSet;
@@ -50,11 +50,11 @@ public final class ZeroCoverageSensor implements Sensor {
   private static final Logger LOG = Loggers.get(ZeroCoverageSensor.class);
 
   private final MeasureCache measureCache;
-  private final AnalysisMode mode;
+  private final DefaultAnalysisMode analysisFlags;
 
-  public ZeroCoverageSensor(MeasureCache measureCache, AnalysisMode mode) {
+  public ZeroCoverageSensor(MeasureCache measureCache, DefaultAnalysisMode analysisFlags) {
     this.measureCache = measureCache;
-    this.mode = mode;
+    this.analysisFlags = analysisFlags;
   }
 
   @Override
@@ -65,7 +65,7 @@ public final class ZeroCoverageSensor implements Sensor {
 
   @Override
   public void execute(final SensorContext context) {
-    if (mode.isIncremental()) {
+    if (analysisFlags.isIncremental()) {
       LOG.debug("Incremental mode: not forcing coverage to zero");
       return;
     }
index 56423077a5198bfce6dbe0e1d14c5b55265eec1b..eb8b22e125ab253d944c7d952f0216f52c6c8bdd 100644 (file)
@@ -24,8 +24,6 @@ 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.analysis.DefaultAnalysisMode;
-import org.sonar.scanner.repository.ProjectRepositoriesProvider;
 import org.sonar.scanner.scan.ProjectScanContainer;
 
 public class ScanTask implements Task {
@@ -47,8 +45,6 @@ public class ScanTask implements Task {
   public void execute() {
     AnalysisProperties props = new AnalysisProperties(taskProps.properties(), taskProps.property(CoreProperties.ENCRYPTION_SECRET_KEY_PATH));
     ProjectScanContainer scanContainer = new ProjectScanContainer(taskContainer, props);
-    scanContainer.add(DefaultAnalysisMode.class);
-    scanContainer.add(new ProjectRepositoriesProvider());
     scanContainer.execute();
   }
 }
index 32d3b81b141b04b7f1a49144259e60124f50b77a..477bd4d2d836ad6bf8cde72aae107fdcb9a456f1 100644 (file)
@@ -70,21 +70,14 @@ public class TaskContainer extends ComponentContainer {
 
   @Override
   public void doAfterStart() {
+    // default value is declared in CorePlugin
     String taskKey = StringUtils.defaultIfEmpty(taskProperties.get(CoreProperties.TASK), CoreProperties.SCAN_TASK);
-    boolean incremental = "true".equals(taskProperties.get("sonar.incremental"));
-    if (CoreProperties.SCAN_TASK.equals(taskKey) && incremental) {
-      taskKey = "incremental";
-    }
     // Release memory
     taskProperties.clear();
 
     TaskDefinition def = getComponentByType(Tasks.class).definition(taskKey);
     if (def == null) {
-      if (incremental) {
-        throw MessageException.of("Incremental mode is not available. Please contact your administrator.");
-      } else {
-        throw MessageException.of("Task '" + taskKey + "' does not exist. Please use '" + ListTask.KEY + "' task to see all available tasks.");
-      }
+      throw MessageException.of("Task '" + taskKey + "' does not exist. Please use '" + ListTask.KEY + "' task to see all available tasks.");
     }
     Task task = getComponentByType(def.taskClass());
     if (task != null) {
index 8841dd881c6dd9df81bf66dbdc7f280a56f02d27..5b68fd567a4ab53db27ba3d0bf87c889ca5ac01d 100644 (file)
  */
 package org.sonar.scanner.analysis;
 
-import java.util.HashMap;
-import java.util.Map;
-import javax.annotation.Nullable;
+import java.util.Collections;
+import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
-import org.sonar.api.CoreProperties;
-import org.sonar.scanner.bootstrap.GlobalProperties;
-import org.sonar.scanner.scan.BranchConfiguration;
-import org.sonar.scanner.scan.DefaultBranchConfiguration;
+import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
+import org.sonar.scanner.repository.ProjectRepositories;
+import org.sonar.scanner.scan.branch.BranchConfiguration;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 public class DefaultAnalysisModeTest {
-  @Rule
-  public ExpectedException thrown = ExpectedException.none();
-
-  @Test
-  public void regular_analysis_by_default() {
-    DefaultAnalysisMode mode = createMode(null, null);
-    assertThat(mode.isPreview()).isFalse();
-    assertThat(mode.isPublish()).isTrue();
-  }
-
-  @Test(expected = IllegalStateException.class)
-  public void fail_if_inconsistent() {
-    createMode(null, CoreProperties.ANALYSIS_MODE_ISSUES);
+  private BranchConfiguration branchConfig;
+  private ProjectRepositories projectRepos;
+  private GlobalAnalysisMode globalMode;
+  private ValidateIncremental validateIncremental;
+
+  @Before
+  public void setUp() {
+    branchConfig = mock(BranchConfiguration.class);
+    projectRepos = mock(ProjectRepositories.class);
+    globalMode = mock(GlobalAnalysisMode.class);
+    validateIncremental = mock(ValidateIncremental.class);
   }
 
-  @Test
-  public void support_publish_mode() {
-    DefaultAnalysisMode mode = createMode(CoreProperties.ANALYSIS_MODE_PUBLISH);
-
-    assertThat(mode.isPreview()).isFalse();
-    assertThat(mode.isPublish()).isTrue();
-  }
-
-  @Test
-  public void incremental_mode_no_longer_valid() {
-    thrown.expect(IllegalStateException.class);
-    thrown.expectMessage("This mode was removed in SonarQube 5.2");
-
-    createMode(CoreProperties.ANALYSIS_MODE_INCREMENTAL);
-  }
+  @Rule
+  public ExpectedException thrown = ExpectedException.none();
 
   @Test
-  public void invalidate_mode() {
-    thrown.expect(IllegalStateException.class);
-    thrown.expectMessage("[preview, publish, issues]");
+  public void dont_scan_all_if_short_lived_branch() {
+    AnalysisProperties analysisProps = new AnalysisProperties(Collections.singletonMap("sonar.scanAllFiles", "true"));
+    when(branchConfig.isShortLivingBranch()).thenReturn(true);
+    DefaultAnalysisMode mode = createmode(analysisProps);
 
-    createMode("invalid");
+    assertThat(mode.scanAllFiles()).isFalse();
   }
 
   @Test
-  public void preview_mode_fallback_issues() {
-    DefaultAnalysisMode mode = createMode(CoreProperties.ANALYSIS_MODE_PREVIEW);
+  public void reuse_global_mode() {
+    when(globalMode.isIssues()).thenReturn(true);
+    when(globalMode.isPublish()).thenReturn(true);
+    when(globalMode.isPreview()).thenReturn(true);
+    DefaultAnalysisMode mode = createmode(new AnalysisProperties(Collections.emptyMap()));
 
     assertThat(mode.isIssues()).isTrue();
-    assertThat(mode.isPreview()).isFalse();
+    assertThat(mode.isPublish()).isTrue();
+    assertThat(mode.isPreview()).isTrue();
   }
 
   @Test
-  public void scan_all() {
-    Map<String, String> props = new HashMap<>();
-    props.put(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES);
-    GlobalProperties globalProps = new GlobalProperties(props);
-    BranchConfiguration branchConfig = new DefaultBranchConfiguration();
-
-    AnalysisProperties analysisProps = new AnalysisProperties(new HashMap<String, String>());
-    DefaultAnalysisMode mode = new DefaultAnalysisMode(globalProps, analysisProps, branchConfig);
-    assertThat(mode.scanAllFiles()).isFalse();
-
-    props.put("sonar.scanAllFiles", "true");
-    analysisProps = new AnalysisProperties(props);
-
-    mode = new DefaultAnalysisMode(globalProps, analysisProps, branchConfig);
-    assertThat(mode.scanAllFiles()).isTrue();
-
-    props.put(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_PUBLISH);
-    analysisProps = new AnalysisProperties(props);
+  public void scan_all_if_publish() {
+    when(globalMode.isIssues()).thenReturn(false);
+    DefaultAnalysisMode mode = createmode(new AnalysisProperties(Collections.emptyMap()));
 
-    mode = new DefaultAnalysisMode(globalProps, analysisProps, branchConfig);
     assertThat(mode.scanAllFiles()).isTrue();
   }
 
   @Test
-  public void default_publish_mode() {
-    DefaultAnalysisMode mode = createMode(null);
-    assertThat(mode.isPublish()).isTrue();
+  public void scan_all_if_property_set() {
+    AnalysisProperties analysisProps = new AnalysisProperties(Collections.singletonMap("sonar.scanAllFiles", "true"));
+    DefaultAnalysisMode mode = createmode(analysisProps);
+
     assertThat(mode.scanAllFiles()).isTrue();
   }
 
   @Test
-  public void support_issues_mode() {
-    DefaultAnalysisMode mode = createMode(CoreProperties.ANALYSIS_MODE_ISSUES);
+  public void dont_scan_all_if_issues_mode() {
+    when(globalMode.isIssues()).thenReturn(true);
+    DefaultAnalysisMode mode = createmode(new AnalysisProperties(Collections.emptyMap()));
 
-    assertThat(mode.isIssues()).isTrue();
     assertThat(mode.scanAllFiles()).isFalse();
   }
 
-  private static DefaultAnalysisMode createMode(@Nullable String mode) {
-    return createMode(mode, mode);
-  }
-
-  private static DefaultAnalysisMode createMode(@Nullable String bootstrapMode, @Nullable String analysisMode) {
-    Map<String, String> bootstrapMap = new HashMap<>();
-    Map<String, String> analysisMap = new HashMap<>();
-    BranchConfiguration branchConfig = new DefaultBranchConfiguration();
-
-    if (bootstrapMode != null) {
-      bootstrapMap.put(CoreProperties.ANALYSIS_MODE, bootstrapMode);
-    }
-    if (analysisMode != null) {
-      analysisMap.put(CoreProperties.ANALYSIS_MODE, analysisMode);
-    }
-    return new DefaultAnalysisMode(new GlobalProperties(bootstrapMap), new AnalysisProperties(analysisMap), branchConfig);
+  private DefaultAnalysisMode createmode(AnalysisProperties analysisProps) {
+    return new DefaultAnalysisMode(analysisProps, branchConfig, globalMode, projectRepos, validateIncremental);
   }
 
 }
index 927e9629959429e96d630922544cb423fe6ff09b..618edbd42950f1167e5b15e52bbb2357ba4b42b6 100644 (file)
@@ -28,7 +28,6 @@ import org.sonar.api.BatchExtension;
 import org.sonar.api.ExtensionProvider;
 import org.sonar.api.SonarPlugin;
 import org.sonar.api.SonarRuntime;
-import org.sonar.api.batch.AnalysisMode;
 import org.sonar.core.platform.ComponentContainer;
 import org.sonar.core.platform.PluginInfo;
 
@@ -38,7 +37,7 @@ import static org.mockito.Mockito.when;
 
 public class ExtensionInstallerTest {
 
-  GlobalMode mode;
+  GlobalAnalysisMode mode;
   ScannerPluginRepository pluginRepository = mock(ScannerPluginRepository.class);
 
   private static SonarPlugin newPluginInstance(final Object... extensions) {
@@ -51,7 +50,7 @@ public class ExtensionInstallerTest {
 
   @Before
   public void setUp() {
-    mode = mock(GlobalMode.class);
+    mode = mock(GlobalAnalysisMode.class);
   }
 
   @Test
@@ -60,7 +59,7 @@ public class ExtensionInstallerTest {
     when(pluginRepository.getPluginInstance("foo")).thenReturn(newPluginInstance(Foo.class, Bar.class));
 
     ComponentContainer container = new ComponentContainer();
-    ExtensionInstaller installer = new ExtensionInstaller(mock(SonarRuntime.class), pluginRepository, mock(AnalysisMode.class));
+    ExtensionInstaller installer = new ExtensionInstaller(mock(SonarRuntime.class), pluginRepository, mock(GlobalAnalysisMode.class));
     installer.install(container, new FooMatcher());
 
     assertThat(container.getComponentByType(Foo.class)).isNotNull();
@@ -72,7 +71,7 @@ public class ExtensionInstallerTest {
     when(pluginRepository.getPluginInfos()).thenReturn(Arrays.asList(new PluginInfo("foo")));
     when(pluginRepository.getPluginInstance("foo")).thenReturn(newPluginInstance(new FooProvider(), new BarProvider()));
     ComponentContainer container = new ComponentContainer();
-    ExtensionInstaller installer = new ExtensionInstaller(mock(SonarRuntime.class), pluginRepository, mock(AnalysisMode.class));
+    ExtensionInstaller installer = new ExtensionInstaller(mock(SonarRuntime.class), pluginRepository, mock(GlobalAnalysisMode.class));
 
     installer.install(container, new FooMatcher());
 
@@ -85,7 +84,7 @@ public class ExtensionInstallerTest {
     when(pluginRepository.getPluginInfos()).thenReturn(Arrays.asList(new PluginInfo("foo")));
     when(pluginRepository.getPluginInstance("foo")).thenReturn(newPluginInstance(new FooBarProvider()));
     ComponentContainer container = new ComponentContainer();
-    ExtensionInstaller installer = new ExtensionInstaller(mock(SonarRuntime.class), pluginRepository, mock(AnalysisMode.class));
+    ExtensionInstaller installer = new ExtensionInstaller(mock(SonarRuntime.class), pluginRepository, mock(GlobalAnalysisMode.class));
 
     installer.install(container, new TrueMatcher());
 
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalAnalysisModeTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalAnalysisModeTest.java
new file mode 100644 (file)
index 0000000..0581e43
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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 org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.CoreProperties;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class GlobalAnalysisModeTest {
+  @Rule
+  public ExpectedException thrown = ExpectedException.none();
+
+  @Test
+  public void testModeNotSupported() {
+    thrown.expect(IllegalStateException.class);
+    thrown.expectMessage("[preview, publish, issues]");
+
+    createMode(CoreProperties.ANALYSIS_MODE, "invalid");
+  }
+
+  @Test
+  public void incremental_mode_no_longer_valid() {
+    thrown.expect(IllegalStateException.class);
+    thrown.expectMessage("This mode was removed in SonarQube 5.2");
+
+    createMode(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_INCREMENTAL);
+  }
+
+  @Test
+  public void invalidate_mode() {
+    thrown.expect(IllegalStateException.class);
+    thrown.expectMessage("[preview, publish, issues]");
+
+    createMode(CoreProperties.ANALYSIS_MODE, "invalid");
+  }
+
+  @Test
+  public void testOtherProperty() {
+    GlobalAnalysisMode mode = createMode(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_PUBLISH);
+    assertThat(mode.isPreview()).isFalse();
+    assertThat(mode.isIssues()).isFalse();
+    assertThat(mode.isPublish()).isTrue();
+  }
+
+  @Test
+  public void testIssuesMode() {
+    GlobalAnalysisMode mode = createMode(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES);
+    assertThat(mode.isPreview()).isFalse();
+    assertThat(mode.isIssues()).isTrue();
+    assertThat(mode.isPublish()).isFalse();
+  }
+
+  @Test
+  public void preview_mode_fallback_issues() {
+    GlobalAnalysisMode mode = createMode(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_PREVIEW);
+
+    assertThat(mode.isIssues()).isTrue();
+    assertThat(mode.isPreview()).isFalse();
+  }
+
+  @Test
+  public void testDefault() {
+    GlobalAnalysisMode mode = createMode(null, null);
+    assertThat(mode.isPreview()).isFalse();
+    assertThat(mode.isIssues()).isFalse();
+    assertThat(mode.isPublish()).isTrue();
+  }
+
+  @Test(expected = IllegalStateException.class)
+  public void testInvalidMode() {
+    createMode(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ANALYSIS);
+  }
+
+  private GlobalAnalysisMode createMode(String key, String value) {
+    Map<String, String> map = new HashMap<>();
+    if (key != null) {
+      map.put(key, value);
+    }
+    GlobalProperties props = new GlobalProperties(map);
+    return new GlobalAnalysisMode(props);
+  }
+}
index 0ee71d91ecff7a01156b013860ccc42a1751e13e..6dba27c160a1ed8c3bbb0ca7b6f08e5749d4035c 100644 (file)
@@ -45,13 +45,13 @@ public class GlobalConfigurationProviderTest {
   SettingsLoader settingsLoader;
   GlobalProperties bootstrapProps;
 
-  private GlobalMode mode;
+  private GlobalAnalysisMode mode;
 
   @Before
   public void prepare() {
     settingsLoader = mock(SettingsLoader.class);
     bootstrapProps = new GlobalProperties(Collections.<String, String>emptyMap());
-    mode = mock(GlobalMode.class);
+    mode = mock(GlobalAnalysisMode.class);
   }
 
   @Test
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalModeTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalModeTest.java
deleted file mode 100644 (file)
index fed2ba5..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 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 org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.api.CoreProperties;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class GlobalModeTest {
-  @Rule
-  public ExpectedException thrown = ExpectedException.none();
-
-  @Test
-  public void testModeNotSupported() {
-    thrown.expect(IllegalStateException.class);
-    thrown.expectMessage("[preview, publish, issues]");
-
-    createMode(CoreProperties.ANALYSIS_MODE, "invalid");
-  }
-
-  @Test
-  public void testOtherProperty() {
-    GlobalMode mode = createMode(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_PUBLISH);
-    assertThat(mode.isPreview()).isFalse();
-    assertThat(mode.isIssues()).isFalse();
-    assertThat(mode.isPublish()).isTrue();
-  }
-
-  @Test
-  public void testIssuesMode() {
-    GlobalMode mode = createMode(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES);
-    assertThat(mode.isPreview()).isFalse();
-    assertThat(mode.isIssues()).isTrue();
-    assertThat(mode.isPublish()).isFalse();
-  }
-
-  @Test
-  public void preview_mode_fallback_issues() {
-    GlobalMode mode = createMode(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_PREVIEW);
-
-    assertThat(mode.isIssues()).isTrue();
-    assertThat(mode.isPreview()).isFalse();
-  }
-
-  @Test
-  public void testDefault() {
-    GlobalMode mode = createMode(null, null);
-    assertThat(mode.isPreview()).isFalse();
-    assertThat(mode.isIssues()).isFalse();
-    assertThat(mode.isPublish()).isTrue();
-  }
-
-  @Test(expected = IllegalStateException.class)
-  public void testInvalidMode() {
-    createMode(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ANALYSIS);
-  }
-
-  private GlobalMode createMode(String key, String value) {
-    Map<String, String> map = new HashMap<>();
-    if (key != null) {
-      map.put(key, value);
-    }
-    GlobalProperties props = new GlobalProperties(map);
-    return new GlobalMode(props);
-  }
-}
index 6ae96de59e849f0c97de393b84032ae351bf2095..cdc5938ef3514c9cb0c2f76092d9f53cf30631da 100644 (file)
@@ -30,7 +30,7 @@ import static org.mockito.Mockito.when;
 public class ScannerPluginPredicateTest {
 
   private MapSettings settings = new MapSettings();
-  private GlobalMode mode = mock(GlobalMode.class);
+  private GlobalAnalysisMode mode = mock(GlobalAnalysisMode.class);
 
   @Test
   public void accept_if_no_inclusions_nor_exclusions() {
index 07c68101a6590696a670a45e17550506c264ed3c..7a9a490476bcebab40f4bb9be885d094b500308a 100644 (file)
@@ -37,7 +37,7 @@ public class ScannerWsClientProviderTest {
   public void provide_client_with_default_settings() {
     GlobalProperties settings = new GlobalProperties(new HashMap<>());
 
-    ScannerWsClient client = underTest.provide(settings, env, new GlobalMode(new GlobalProperties(Collections.emptyMap())));
+    ScannerWsClient client = underTest.provide(settings, env, new GlobalAnalysisMode(new GlobalProperties(Collections.emptyMap())));
 
     assertThat(client).isNotNull();
     assertThat(client.baseUrl()).isEqualTo("http://localhost:9000/");
@@ -57,7 +57,7 @@ public class ScannerWsClientProviderTest {
     props.put("sonar.ws.timeout", "42");
     GlobalProperties settings = new GlobalProperties(props);
 
-    ScannerWsClient client = underTest.provide(settings, env, new GlobalMode(new GlobalProperties(Collections.emptyMap())));
+    ScannerWsClient client = underTest.provide(settings, env, new GlobalAnalysisMode(new GlobalProperties(Collections.emptyMap())));
 
     assertThat(client).isNotNull();
     HttpConnector httpConnector = (HttpConnector) client.wsConnector();
@@ -68,8 +68,8 @@ public class ScannerWsClientProviderTest {
   @Test
   public void build_singleton() {
     GlobalProperties settings = new GlobalProperties(new HashMap<>());
-    ScannerWsClient first = underTest.provide(settings, env, new GlobalMode(new GlobalProperties(Collections.emptyMap())));
-    ScannerWsClient second = underTest.provide(settings, env, new GlobalMode(new GlobalProperties(Collections.emptyMap())));
+    ScannerWsClient first = underTest.provide(settings, env, new GlobalAnalysisMode(new GlobalProperties(Collections.emptyMap())));
+    ScannerWsClient second = underTest.provide(settings, env, new GlobalAnalysisMode(new GlobalProperties(Collections.emptyMap())));
     assertThat(first).isSameAs(second);
   }
 }
index 3b58773dd6633a7e6e78b2f2247b5683b229f336..fa7c8b0891670b91924f8ea5d4faaab92e305c9f 100644 (file)
@@ -55,7 +55,7 @@ public class ScannerWsClientTest {
     when(wsClient.wsConnector().call(request)).thenReturn(response);
 
     logTester.setLevel(LoggerLevel.DEBUG);
-    ScannerWsClient underTest = new ScannerWsClient(wsClient, false, new GlobalMode(new GlobalProperties(Collections.emptyMap())));
+    ScannerWsClient underTest = new ScannerWsClient(wsClient, false, new GlobalAnalysisMode(new GlobalProperties(Collections.emptyMap())));
 
     WsResponse result = underTest.call(request);
 
@@ -78,7 +78,7 @@ public class ScannerWsClientTest {
     WsResponse response = newResponse().setCode(401);
     when(wsClient.wsConnector().call(request)).thenReturn(response);
 
-    new ScannerWsClient(wsClient, false, new GlobalMode(new GlobalProperties(Collections.emptyMap()))).call(request);
+    new ScannerWsClient(wsClient, false, new GlobalAnalysisMode(new GlobalProperties(Collections.emptyMap()))).call(request);
   }
 
   @Test
@@ -90,7 +90,7 @@ public class ScannerWsClientTest {
     WsResponse response = newResponse().setCode(401);
     when(wsClient.wsConnector().call(request)).thenReturn(response);
 
-    new ScannerWsClient(wsClient, /* credentials are configured */true, new GlobalMode(new GlobalProperties(Collections.emptyMap()))).call(request);
+    new ScannerWsClient(wsClient, /* credentials are configured */true, new GlobalAnalysisMode(new GlobalProperties(Collections.emptyMap()))).call(request);
   }
 
   @Test
@@ -104,7 +104,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 GlobalMode(new GlobalProperties(Collections.emptyMap()))).call(request);
+    new ScannerWsClient(wsClient, true, new GlobalAnalysisMode(new GlobalProperties(Collections.emptyMap()))).call(request);
   }
 
   @Test
@@ -118,7 +118,7 @@ public class ScannerWsClientTest {
       .setContent("{\"errors\":[{\"msg\":\"Boo! bad request! bad!\"}]}");
     when(wsClient.wsConnector().call(request)).thenReturn(response);
 
-    new ScannerWsClient(wsClient, true, new GlobalMode(new GlobalProperties(Collections.emptyMap()))).call(request);
+    new ScannerWsClient(wsClient, true, new GlobalAnalysisMode(new GlobalProperties(Collections.emptyMap()))).call(request);
   }
 
   private MockWsResponse newResponse() {
index 0432e2511a0e172f36ea66cf7be16ad0adc47361..adf55780f1d31000a792ff6088ecea0de5f433cd 100644 (file)
@@ -23,7 +23,6 @@ import com.google.common.collect.ImmutableMap;
 import java.util.Arrays;
 import org.junit.Rule;
 import org.junit.Test;
-import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.config.Configuration;
 import org.sonar.api.config.Encryption;
 import org.sonar.api.config.PropertyDefinition;
@@ -31,6 +30,7 @@ import org.sonar.api.config.PropertyDefinitions;
 import org.sonar.api.config.PropertyFieldDefinition;
 import org.sonar.api.utils.log.LogTester;
 import org.sonar.api.utils.log.LoggerLevel;
+import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.fail;
@@ -46,7 +46,7 @@ public class DefaultConfigurationTest {
     Configuration config = new DefaultConfiguration(new PropertyDefinitions(Arrays.asList(
       PropertyDefinition.builder("single").multiValues(false).build(),
       PropertyDefinition.builder("multiA").multiValues(true).build())), new Encryption(null),
-      mock(AnalysisMode.class),
+      mock(GlobalAnalysisMode.class),
       ImmutableMap.of("single", "foo", "multiA", "a,b", "notDeclared", "c,d")) {
     };
 
@@ -74,7 +74,7 @@ public class DefaultConfigurationTest {
     Configuration config = new DefaultConfiguration(new PropertyDefinitions(Arrays.asList(
       PropertyDefinition.builder("props").fields(PropertyFieldDefinition.build("foo1").name("Foo1").build(), PropertyFieldDefinition.build("foo2").name("Foo2").build()).build())),
       new Encryption(null),
-      mock(AnalysisMode.class),
+      mock(GlobalAnalysisMode.class),
       ImmutableMap.of("props", "1,2", "props.1.foo1", "a", "props.1.foo2", "b")) {
     };
 
@@ -94,7 +94,7 @@ public class DefaultConfigurationTest {
     Configuration config = new DefaultConfiguration(new PropertyDefinitions(Arrays.asList(
       PropertyDefinition.builder("single").multiValues(false).defaultValue("default").build(),
       PropertyDefinition.builder("multiA").multiValues(true).defaultValue("foo,bar").build())), new Encryption(null),
-      mock(AnalysisMode.class),
+      mock(GlobalAnalysisMode.class),
       ImmutableMap.of()) {
     };
 
@@ -125,7 +125,7 @@ public class DefaultConfigurationTest {
   private String[] getStringArray(String value) {
     return new DefaultConfiguration(new PropertyDefinitions(Arrays.asList(
       PropertyDefinition.builder("multi").multiValues(true).build())), new Encryption(null),
-      mock(AnalysisMode.class),
+      mock(GlobalAnalysisMode.class),
       ImmutableMap.of("multi", value)) {
     }.getStringArray("multi");
   }
index 0d0ead878ab648b21e46337a12234d8d274560b6..2ef29f1d751df2d681d796d1f98580c8fa4d7b9c 100644 (file)
@@ -30,7 +30,6 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
-import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.fs.internal.DefaultInputModule;
@@ -42,13 +41,14 @@ import org.sonar.duplications.block.Block;
 import org.sonar.duplications.block.ByteArray;
 import org.sonar.duplications.index.CloneGroup;
 import org.sonar.duplications.index.ClonePart;
+import org.sonar.scanner.analysis.DefaultAnalysisMode;
 import org.sonar.scanner.cpd.index.SonarCpdBlockIndex;
 import org.sonar.scanner.protocol.output.ScannerReport.Duplicate;
 import org.sonar.scanner.protocol.output.ScannerReport.Duplication;
 import org.sonar.scanner.protocol.output.ScannerReportReader;
 import org.sonar.scanner.protocol.output.ScannerReportWriter;
 import org.sonar.scanner.report.ReportPublisher;
-import org.sonar.scanner.scan.BranchConfiguration;
+import org.sonar.scanner.scan.branch.BranchConfiguration;
 import org.sonar.scanner.scan.filesystem.InputComponentStore;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -90,7 +90,7 @@ public class CpdExecutorTest {
 
     index = new SonarCpdBlockIndex(publisher, settings);
     DefaultInputModule inputModule = TestInputFileBuilder.newDefaultInputModule("foo", baseDir);
-    componentStore = new InputComponentStore(inputModule, mock(AnalysisMode.class), mock(BranchConfiguration.class));
+    componentStore = new InputComponentStore(inputModule, mock(DefaultAnalysisMode.class), mock(BranchConfiguration.class));
     executor = new CpdExecutor(settings, index, publisher, componentStore, branchConfig);
     reader = new ScannerReportReader(outputDir);
 
index df04b69b62e6f95523d9ebe34fbf64baef068d2b..ffd845e347900318a6b390aedf81b6c1c2fbcd53 100644 (file)
@@ -52,8 +52,7 @@ import org.sonar.api.utils.DateUtils;
 import org.sonar.batch.bootstrapper.Batch;
 import org.sonar.batch.bootstrapper.EnvironmentInformation;
 import org.sonar.batch.bootstrapper.LogOutput;
-import org.sonar.scanner.bootstrap.GlobalConfiguration;
-import org.sonar.scanner.bootstrap.GlobalMode;
+import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
 import org.sonar.scanner.issue.tracking.ServerLineHashesLoader;
 import org.sonar.scanner.protocol.input.ScannerInput.ServerIssue;
 import org.sonar.scanner.report.ReportPublisher;
@@ -68,8 +67,11 @@ import org.sonar.scanner.repository.settings.SettingsLoader;
 import org.sonar.scanner.rule.ActiveRulesLoader;
 import org.sonar.scanner.rule.LoadedActiveRule;
 import org.sonar.scanner.rule.RulesLoader;
-import org.sonar.scanner.scan.BranchConfiguration;
-import org.sonar.scanner.scan.BranchConfigurationLoader;
+import org.sonar.scanner.scan.ProjectSettings;
+import org.sonar.scanner.scan.branch.BranchConfiguration;
+import org.sonar.scanner.scan.branch.BranchConfigurationLoader;
+import org.sonar.scanner.scan.branch.BranchType;
+import org.sonar.scanner.scan.branch.ProjectBranches;
 import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
 import org.sonarqube.ws.Rules.ListResponse.Rule;
 
@@ -239,7 +241,7 @@ public class ScannerMediumTester extends ExternalResource {
       throw new IllegalStateException(e);
     }
     registerCoreMetrics();
-    globalProperties.put(GlobalMode.MEDIUM_TEST_ENABLED, "true");
+    globalProperties.put(GlobalAnalysisMode.MEDIUM_TEST_ENABLED, "true");
     globalProperties.put(ReportPublisher.KEEP_REPORT_PROP_KEY, "true");
     globalProperties.put("sonar.userHome", userHome.toString());
   }
@@ -420,7 +422,7 @@ public class ScannerMediumTester extends ExternalResource {
     }
   }
 
-  public ScannerMediumTester setBranchType(BranchConfiguration.BranchType branchType) {
+  public ScannerMediumTester setBranchType(BranchType branchType) {
     branchConfiguration.branchType = branchType;
     return this;
   }
@@ -437,7 +439,7 @@ public class ScannerMediumTester extends ExternalResource {
 
   private class FakeBranchConfigurationLoader implements BranchConfigurationLoader {
     @Override
-    public BranchConfiguration load(String projectKey, GlobalConfiguration settings) {
+    public BranchConfiguration load(ProjectSettings settings, ProjectBranches branches) {
       return branchConfiguration;
     }
   }
index 58d9133dddc150541386aa8516f87fdd334e8216..2461e5ea786a170178fda72640aaf725e68744ee 100644 (file)
@@ -34,7 +34,7 @@ import org.sonar.scanner.mediumtest.ScannerMediumTester;
 import org.sonar.scanner.mediumtest.TaskResult;
 import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.scanner.repository.FileData;
-import org.sonar.scanner.scan.BranchConfiguration;
+import org.sonar.scanner.scan.branch.BranchType;
 import org.sonar.xoo.XooPlugin;
 import org.sonar.xoo.rule.XooRulesDefinition;
 
@@ -80,7 +80,7 @@ public class BranchMediumTest {
     assertThat(result.getReportReader().readFileSource(fileId)).isNotNull();
 
     // file is skipped for short branches (no report, no coverage, no duplications)
-    TaskResult result2 = getResult(tester.setBranchType(BranchConfiguration.BranchType.SHORT));
+    TaskResult result2 = getResult(tester.setBranchType(BranchType.SHORT));
     assertThat(result2.getReportComponent(result2.inputFile(FILE_PATH).key())).isNull();
     assertThat(result2.getReportReader().readChangesets(fileId)).isNull();
     assertThat(result2.getReportReader().hasCoverage(fileId)).isFalse();
@@ -95,7 +95,7 @@ public class BranchMediumTest {
     TaskResult result = getResult(tester
       .setBranchName(branchName)
       .setBranchTarget(branchTarget)
-      .setBranchType(BranchConfiguration.BranchType.SHORT));
+      .setBranchType(BranchType.SHORT));
 
     ScannerReport.Metadata metadata = result.getReportReader().readMetadata();
     assertThat(metadata.getBranchName()).isEqualTo(branchName);
index 8d679016b61b648903f79ac04ba6cf2c1028267e..d7cb80f787e9c5eb88f4e80e868e2d17dc7991f7 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.scanner.mediumtest.tasks;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
+import java.io.File;
 import java.util.Arrays;
 import java.util.List;
 
@@ -28,6 +29,7 @@ import org.assertj.core.api.Condition;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
+import org.junit.rules.TemporaryFolder;
 import org.sonar.api.SonarPlugin;
 import org.sonar.api.task.Task;
 import org.sonar.api.task.TaskDefinition;
@@ -45,6 +47,9 @@ public class TasksMediumTest {
   @Rule
   public LogTester logTester = new LogTester();
 
+  @Rule
+  public TemporaryFolder temp = new TemporaryFolder();
+
   @Rule
   public ScannerMediumTester tester = new ScannerMediumTester()
     .registerPlugin("faketask", new FakeTaskPlugin());
@@ -87,12 +92,16 @@ public class TasksMediumTest {
 
   @Test
   public void incrementalNotFound() throws Exception {
+    File baseDir = temp.newFolder();
     thrown.expect(MessageException.class);
     thrown.expectMessage(
       "Incremental mode is not available. Please contact your administrator.");
 
     tester.newTask()
       .properties(ImmutableMap.<String, String>builder()
+        .put("sonar.projectKey", "key")
+        .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
+        .put("sonar.sources", ".")
         .put("sonar.incremental", "true").build())
       .execute();
   }
index f39cafcadb7a92953b7fd78dc11f1ec2d644018c..1bbd510f6e7e7be472e3a12d5a5dfe9975cc33d0 100644 (file)
@@ -31,9 +31,10 @@ import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
 import org.sonar.api.batch.postjob.issue.PostJobIssue;
 import org.sonar.api.batch.rule.Severity;
 import org.sonar.api.config.internal.MapSettings;
+import org.sonar.scanner.analysis.DefaultAnalysisMode;
 import org.sonar.scanner.issue.IssueCache;
 import org.sonar.scanner.issue.tracking.TrackedIssue;
-import org.sonar.scanner.scan.BranchConfiguration;
+import org.sonar.scanner.scan.branch.BranchConfiguration;
 import org.sonar.scanner.scan.filesystem.InputComponentStore;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -55,7 +56,7 @@ public class DefaultPostJobContextTest {
   public void setUp() throws IOException {
     issueCache = mock(IssueCache.class);
     DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule("foo", temp.newFolder());
-    componentStore = new InputComponentStore(rootModule, mock(AnalysisMode.class), mock(BranchConfiguration.class));
+    componentStore = new InputComponentStore(rootModule, mock(DefaultAnalysisMode.class), mock(BranchConfiguration.class));
     settings = new MapSettings();
     analysisMode = mock(AnalysisMode.class);
     context = new DefaultPostJobContext(settings.asConfig(), settings, issueCache, componentStore, analysisMode);
index a03afd14359d91fd36118d24cb718acb9cd8b9f6..5ebfeb7e8526c89f3ef6d7081e19daa9af5efccb 100644 (file)
@@ -45,8 +45,8 @@ import org.sonar.scanner.protocol.output.ScannerReport.Component.FileStatus;
 import org.sonar.scanner.protocol.output.ScannerReport.ComponentLink.ComponentLinkType;
 import org.sonar.scanner.protocol.output.ScannerReportReader;
 import org.sonar.scanner.protocol.output.ScannerReportWriter;
-import org.sonar.scanner.scan.BranchConfiguration;
-import org.sonar.scanner.scan.BranchConfiguration.BranchType;
+import org.sonar.scanner.scan.branch.BranchConfiguration;
+import org.sonar.scanner.scan.branch.BranchType;
 import org.sonar.scanner.scan.DefaultComponentTree;
 
 import static org.assertj.core.api.Assertions.assertThat;
index f2a0e614bae29ae8a2aa2d9cb70e9bdf7b3c0f71..b517367c309b4daac061e9cfc5ed5e446c3cc233 100644 (file)
@@ -25,17 +25,17 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
-import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.fs.internal.DefaultInputModule;
 import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
 import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure;
 import org.sonar.api.measures.CoreMetrics;
 import org.sonar.core.util.CloseableIterator;
+import org.sonar.scanner.analysis.DefaultAnalysisMode;
 import org.sonar.scanner.protocol.output.ScannerReport.LineCoverage;
 import org.sonar.scanner.protocol.output.ScannerReportReader;
 import org.sonar.scanner.protocol.output.ScannerReportWriter;
-import org.sonar.scanner.scan.BranchConfiguration;
+import org.sonar.scanner.scan.branch.BranchConfiguration;
 import org.sonar.scanner.scan.filesystem.InputComponentStore;
 import org.sonar.scanner.scan.measure.MeasureCache;
 
@@ -59,7 +59,7 @@ public class CoveragePublisherTest {
     String moduleKey = "foo";
     inputFile = new TestInputFileBuilder(moduleKey, "src/Foo.php").setLines(5).build();
     DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule(moduleKey, temp.newFolder());
-    InputComponentStore componentCache = new InputComponentStore(rootModule, mock(AnalysisMode.class), mock(BranchConfiguration.class));
+    InputComponentStore componentCache = new InputComponentStore(rootModule, mock(DefaultAnalysisMode.class), mock(BranchConfiguration.class));
     componentCache.put(inputFile);
 
     measureCache = mock(MeasureCache.class);
index 31a60b633c8f95c2e3099f442d889248e6257bb4..b42567c73cc55c67cb4820efc87c0eb39438085f 100644 (file)
@@ -28,18 +28,18 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
-import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.fs.internal.DefaultInputModule;
 import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
 import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure;
 import org.sonar.api.measures.CoreMetrics;
 import org.sonar.core.util.CloseableIterator;
+import org.sonar.scanner.analysis.DefaultAnalysisMode;
 import org.sonar.scanner.deprecated.test.TestPlanBuilder;
 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.scan.BranchConfiguration;
+import org.sonar.scanner.scan.branch.BranchConfiguration;
 import org.sonar.scanner.scan.filesystem.InputComponentStore;
 import org.sonar.scanner.scan.measure.MeasureCache;
 
@@ -70,7 +70,7 @@ public class MeasuresPublisherTest {
     String moduleKey = "foo";
     inputModule = TestInputFileBuilder.newDefaultInputModule(moduleKey, temp.newFolder());
     inputFile = new TestInputFileBuilder(moduleKey, "src/Foo.php").setPublish(true).build();
-    InputComponentStore componentCache = new InputComponentStore(inputModule, mock(AnalysisMode.class), mock(BranchConfiguration.class));
+    InputComponentStore componentCache = new InputComponentStore(inputModule, mock(DefaultAnalysisMode.class), mock(BranchConfiguration.class));
     componentCache.put(inputFile);
     measureCache = mock(MeasureCache.class);
     when(measureCache.byComponentKey(anyString())).thenReturn(Collections.<DefaultMeasure<?>>emptyList());
index 3bc70f9c875c09b020fa29a6b3b44cc5b33abe68..f00269ac4b145a4bdbd2017bafc0f584f7303935 100644 (file)
@@ -28,7 +28,6 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.CoreProperties;
-import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
 import org.sonar.api.batch.fs.internal.DefaultInputModule;
 import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
@@ -36,6 +35,7 @@ import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.core.config.ScannerProperties;
 import org.sonar.scanner.ProjectAnalysisInfo;
+import org.sonar.scanner.analysis.DefaultAnalysisMode;
 import org.sonar.scanner.bootstrap.ScannerPlugin;
 import org.sonar.scanner.bootstrap.ScannerPluginRepository;
 import org.sonar.scanner.cpd.CpdSettings;
@@ -44,7 +44,8 @@ import org.sonar.scanner.protocol.output.ScannerReportReader;
 import org.sonar.scanner.protocol.output.ScannerReportWriter;
 import org.sonar.scanner.rule.ModuleQProfiles;
 import org.sonar.scanner.rule.QProfile;
-import org.sonar.scanner.scan.BranchConfiguration;
+import org.sonar.scanner.scan.branch.BranchConfiguration;
+import org.sonar.scanner.scan.branch.BranchType;
 
 import static java.util.Arrays.asList;
 import static java.util.Collections.emptyMap;
@@ -65,7 +66,7 @@ public class MetadataPublisherTest {
   private ProjectAnalysisInfo projectAnalysisInfo;
   private CpdSettings cpdSettings;
   private InputModuleHierarchy inputModuleHierarchy;
-  private AnalysisMode analysisMode;
+  private DefaultAnalysisMode analysisMode;
   private ScannerPluginRepository pluginRepository;
   private BranchConfiguration branches;
 
@@ -85,7 +86,7 @@ public class MetadataPublisherTest {
     rootModule = new DefaultInputModule(def.setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder()), TestInputFileBuilder.nextBatchId());
     inputModuleHierarchy = mock(InputModuleHierarchy.class);
     when(inputModuleHierarchy.root()).thenReturn(rootModule);
-    analysisMode = mock(AnalysisMode.class);
+    analysisMode = mock(DefaultAnalysisMode.class);
     branches = mock(BranchConfiguration.class);
     underTest = new MetadataPublisher(projectAnalysisInfo, inputModuleHierarchy, settings.asConfig(), qProfiles, cpdSettings, analysisMode,
       pluginRepository, branches);
@@ -168,7 +169,7 @@ public class MetadataPublisherTest {
   public void write_long_lived_branch_info() throws Exception {
     String branchName = "long-lived";
     when(branches.branchName()).thenReturn(branchName);
-    when(branches.branchType()).thenReturn(BranchConfiguration.BranchType.LONG);
+    when(branches.branchType()).thenReturn(BranchType.LONG);
 
     File outputDir = temp.newFolder();
     underTest.publish(new ScannerReportWriter(outputDir));
index e7da36601b05dca90644c04bb9c0682e7bf17e76..e3bccbd64ff31a7d079ae822e0769e855702019d 100644 (file)
@@ -45,8 +45,9 @@ import org.sonar.api.utils.log.LoggerLevel;
 import org.sonar.core.config.CorePropertyDefinitions;
 import org.sonar.core.config.ScannerProperties;
 import org.sonar.scanner.analysis.DefaultAnalysisMode;
+import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
 import org.sonar.scanner.bootstrap.ScannerWsClient;
-import org.sonar.scanner.scan.BranchConfiguration;
+import org.sonar.scanner.scan.branch.BranchConfiguration;
 import org.sonarqube.ws.WsCe;
 import org.sonarqube.ws.client.HttpException;
 import org.sonarqube.ws.client.WsRequest;
@@ -59,7 +60,7 @@ import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
-import static org.sonar.scanner.scan.BranchConfiguration.BranchType.SHORT;
+import static org.sonar.scanner.scan.branch.BranchType.SHORT;
 
 public class ReportPublisherTest {
 
@@ -72,7 +73,8 @@ public class ReportPublisherTest {
   @Rule
   public ExpectedException exception = ExpectedException.none();
 
-  DefaultAnalysisMode mode = mock(DefaultAnalysisMode.class);
+  DefaultAnalysisMode analysisFlags = mock(DefaultAnalysisMode.class);
+  GlobalAnalysisMode mode = mock(GlobalAnalysisMode.class);
   MapSettings settings = new MapSettings(new PropertyDefinitions(CorePropertyDefinitions.all()));
   ScannerWsClient wsClient;
   Server server = mock(Server.class);
@@ -92,8 +94,8 @@ public class ReportPublisherTest {
 
   @Test
   public void log_and_dump_information_about_report_uploading() throws IOException {
-    ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class),
-      new ReportPublisherStep[0], branchConfiguration);
+    ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, analysisFlags, moduleHierarchy, mode,
+      mock(TempFolder.class), new ReportPublisherStep[0], branchConfiguration);
     settings.setProperty(ScannerProperties.ORGANIZATION, "MyOrg");
 
     underTest.logSuccess("TASK-123");
@@ -116,8 +118,8 @@ public class ReportPublisherTest {
 
   @Test
   public void parse_upload_error_message() throws IOException {
-    ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class),
-      new ReportPublisherStep[0], branchConfiguration);
+    ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, analysisFlags, moduleHierarchy, mode,
+      mock(TempFolder.class), new ReportPublisherStep[0], branchConfiguration);
     HttpException ex = new HttpException("url", 404, "{\"errors\":[{\"msg\":\"Organization with key 'MyOrg' does not exist\"}]}");
     WsResponse response = mock(WsResponse.class);
     when(response.failIfNotSuccessful()).thenThrow(ex);
@@ -131,7 +133,7 @@ public class ReportPublisherTest {
   @Test
   public void log_public_url_if_defined() throws IOException {
     when(server.getPublicRootUrl()).thenReturn("https://publicserver/sonarqube");
-    ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class),
+    ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, analysisFlags, moduleHierarchy, mode, mock(TempFolder.class),
       new ReportPublisherStep[0], branchConfiguration);
 
     underTest.logSuccess("TASK-123");
@@ -153,7 +155,7 @@ public class ReportPublisherTest {
   @Test
   public void fail_if_public_url_malformed() throws IOException {
     when(server.getPublicRootUrl()).thenReturn("invalid");
-    ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class),
+    ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, analysisFlags, moduleHierarchy, mode, mock(TempFolder.class),
       new ReportPublisherStep[0], branchConfiguration);
 
     exception.expect(MessageException.class);
@@ -163,7 +165,7 @@ public class ReportPublisherTest {
 
   @Test
   public void log_but_not_dump_information_when_report_is_not_uploaded() {
-    ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class),
+    ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, analysisFlags, moduleHierarchy, mode, mock(TempFolder.class),
       new ReportPublisherStep[0], branchConfiguration);
 
     underTest.logSuccess(/* report not uploaded, no server task */null);
@@ -181,7 +183,7 @@ public class ReportPublisherTest {
     settings.setProperty("sonar.scanner.keepReport", true);
     Path reportDir = temp.getRoot().toPath().resolve("scanner-report");
     Files.createDirectory(reportDir);
-    ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class),
+    ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, analysisFlags, moduleHierarchy, mode, mock(TempFolder.class),
       new ReportPublisherStep[0], branchConfiguration);
 
     underTest.start();
@@ -193,7 +195,8 @@ public class ReportPublisherTest {
   public void should_delete_report_by_default() throws IOException {
     Path reportDir = temp.getRoot().toPath().resolve("scanner-report");
     Files.createDirectory(reportDir);
-    ReportPublisher job = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class), new ReportPublisherStep[0],
+    ReportPublisher job = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, analysisFlags, moduleHierarchy, mode, mock(TempFolder.class),
+      new ReportPublisherStep[0],
       branchConfiguration);
 
     job.start();
@@ -203,7 +206,7 @@ public class ReportPublisherTest {
 
   @Test
   public void test_ws_parameters() throws Exception {
-    ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class),
+    ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, analysisFlags, moduleHierarchy, mode, mock(TempFolder.class),
       new ReportPublisherStep[0], branchConfiguration);
 
     settings.setProperty(ScannerProperties.ORGANIZATION, "MyOrg");
@@ -232,10 +235,10 @@ public class ReportPublisherTest {
 
   @Test
   public void test_send_incremental_characteristic() throws Exception {
-    ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class),
+    ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, analysisFlags, moduleHierarchy, mode, mock(TempFolder.class),
       new ReportPublisherStep[0], branchConfiguration);
 
-    when(mode.isIncremental()).thenReturn(true);
+    when(analysisFlags.isIncremental()).thenReturn(true);
     String orgName = "MyOrg";
     settings.setProperty(ScannerProperties.ORGANIZATION, orgName);
 
@@ -265,7 +268,7 @@ public class ReportPublisherTest {
 
   @Test
   public void test_send_branches_characteristics() throws Exception {
-    ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class),
+    ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, analysisFlags, moduleHierarchy, mode, mock(TempFolder.class),
       new ReportPublisherStep[0], branchConfiguration);
 
     String orgName = "MyOrg";
index b859b3962e836bb7dc1d1ab415070806ade6aee7..a343584a9114b848c9a2d0ba693dc0ba79c9a135 100644 (file)
@@ -27,13 +27,13 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
-import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.batch.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.TestInputFileBuilder;
+import org.sonar.scanner.analysis.DefaultAnalysisMode;
 import org.sonar.scanner.protocol.output.ScannerReportWriter;
-import org.sonar.scanner.scan.BranchConfiguration;
+import org.sonar.scanner.scan.branch.BranchConfiguration;
 import org.sonar.scanner.scan.filesystem.InputComponentStore;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -48,7 +48,7 @@ public class SourcePublisherTest {
   private File sourceFile;
   private ScannerReportWriter writer;
   private DefaultInputFile inputFile;
-  private AnalysisMode analysisMode;
+  private DefaultAnalysisMode analysisFlags;
 
   @Before
   public void prepare() throws IOException {
@@ -62,8 +62,8 @@ public class SourcePublisherTest {
       .build();
 
     DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule(moduleKey, baseDir);
-    analysisMode = mock(AnalysisMode.class);
-    InputComponentStore componentStore = new InputComponentStore(rootModule, analysisMode, mock(BranchConfiguration.class));
+    analysisFlags = mock(DefaultAnalysisMode.class);
+    InputComponentStore componentStore = new InputComponentStore(rootModule, analysisFlags, mock(BranchConfiguration.class));
     componentStore.put(inputFile);
 
     publisher = new SourcePublisher(componentStore);
@@ -124,7 +124,7 @@ public class SourcePublisherTest {
 
   @Test
   public void publishChangedSourceInIncrementalMode() throws Exception {
-    when(analysisMode.isIncremental()).thenReturn(true);
+    when(analysisFlags.isIncremental()).thenReturn(true);
     FileUtils.write(sourceFile, "1\n2\n3\n4\n5", StandardCharsets.ISO_8859_1);
     inputFile.setStatus(Status.CHANGED);
 
@@ -136,7 +136,7 @@ public class SourcePublisherTest {
 
   @Test
   public void dontPublishUnchangedSourceInIncrementalMode() throws Exception {
-    when(analysisMode.isIncremental()).thenReturn(true);
+    when(analysisFlags.isIncremental()).thenReturn(true);
     FileUtils.write(sourceFile, "foo", StandardCharsets.ISO_8859_1);
     inputFile.setStatus(Status.SAME);
 
index e7c5b810a107592d090e103a4a5936c5b809c916..1935ab503d76d9b3c34c967fe3847e1fbe0a91a0 100644 (file)
@@ -27,8 +27,8 @@ import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.sonar.api.batch.bootstrap.ProjectKey;
-import org.sonar.scanner.analysis.DefaultAnalysisMode;
-import org.sonar.scanner.scan.BranchConfiguration;
+import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
+import org.sonar.scanner.scan.branch.BranchConfiguration;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Matchers.any;
@@ -47,7 +47,7 @@ public class ProjectRepositoriesProviderTest {
   @Mock
   private ProjectKey projectKey;
   @Mock
-  private DefaultAnalysisMode mode;
+  private GlobalAnalysisMode mode;
   @Mock
   private BranchConfiguration branchConfiguration;
 
index f2ecbe4d5fba5622e3581f8775f8daca27c55fa9..2171a2b88094aeea5fed98734151e8988531ec80 100644 (file)
  */
 package org.sonar.scanner.repository.settings;
 
+import java.io.IOException;
+import org.junit.Before;
 import org.junit.Test;
+import org.sonar.scanner.WsTestUtil;
+import org.sonar.scanner.bootstrap.ScannerWsClient;
 import org.sonarqube.ws.Settings.FieldValues;
 import org.sonarqube.ws.Settings.FieldValues.Value;
 import org.sonarqube.ws.Settings.FieldValues.Value.Builder;
@@ -29,8 +33,17 @@ import org.sonarqube.ws.Settings.Values;
 import static java.util.Arrays.asList;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.entry;
+import static org.mockito.Mockito.mock;
 
 public class DefaultSettingsLoaderTest {
+  private ScannerWsClient wsClient;
+  private DefaultSettingsLoader loader;
+
+  @Before
+  public void prepare() throws IOException {
+    wsClient = mock(ScannerWsClient.class);
+    loader = new DefaultSettingsLoader(wsClient);
+  }
 
   @Test
   public void should_load_global_multivalue_settings() {
@@ -69,4 +82,10 @@ public class DefaultSettingsLoaderTest {
           entry("sonar.issue.exclusions.multicriteria.2.rulepattern", "*:S456"));
   }
 
+  @Test
+  public void continue_on_error() {
+    WsTestUtil.mockException(wsClient, DefaultSettingsLoader.URL + "?component=project", new IllegalStateException());
+    assertThat(loader.load("project")).isEmpty();
+  }
+
 }
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/BranchConfigurationProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/BranchConfigurationProviderTest.java
deleted file mode 100644 (file)
index 41c3f9a..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 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 static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.scanner.bootstrap.GlobalConfiguration;
-import org.sonar.scanner.scan.BranchConfiguration.BranchType;
-
-public class BranchConfigurationProviderTest {
-  private BranchConfigurationProvider provider = new BranchConfigurationProvider();
-  private GlobalConfiguration globalConfiguration;
-  private BranchConfigurationLoader loader;
-  private BranchConfiguration config;
-
-  @Before
-  public void setUp() {
-    globalConfiguration = mock(GlobalConfiguration.class);
-    loader = mock(BranchConfigurationLoader.class);
-    config = mock(BranchConfiguration.class);
-  }
-
-  @Test
-  public void should_cache_config() {
-    BranchConfiguration configuration = provider.provide(null, () -> "project", globalConfiguration);
-    assertThat(provider.provide(null, () -> "project", globalConfiguration)).isSameAs(configuration);
-  }
-
-  @Test
-  public void should_use_loader() {
-    when(loader.load("key", globalConfiguration)).thenReturn(config);
-    BranchConfiguration branchConfig = provider.provide(loader, () -> "key", globalConfiguration);
-
-    assertThat(branchConfig).isSameAs(config);
-  }
-
-  @Test
-  public void should_return_default_if_no_loader() {
-    BranchConfiguration configuration = provider.provide(null, () -> "project", globalConfiguration);
-    assertThat(configuration.branchTarget()).isNull();
-    assertThat(configuration.branchType()).isEqualTo(BranchType.LONG);
-  }
-}
index e9d075d327e228fc6a9d969e82d9b7b5ac4d3c0b..fbaca69eecadb7fcd2bb67d6d8b5d3c88de991cb 100644 (file)
@@ -21,10 +21,11 @@ package org.sonar.scanner.scan;
 
 import java.util.Arrays;
 import org.junit.Test;
-import org.sonar.api.batch.AnalysisMode;
 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.scanner.analysis.DefaultAnalysisMode;
+import org.sonar.scanner.scan.branch.BranchConfiguration;
 import org.sonar.scanner.scan.filesystem.InputComponentStore;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -38,7 +39,7 @@ public class ModuleIndexerTest {
   private InputComponentStore componentStore;
 
   public void createIndexer(DefaultInputModule rootModule) {
-    componentStore = new InputComponentStore(rootModule, mock(AnalysisMode.class), mock(BranchConfiguration.class));
+    componentStore = new InputComponentStore(rootModule, mock(DefaultAnalysisMode.class), mock(BranchConfiguration.class));
     tree = new DefaultComponentTree();
     moduleHierarchy = mock(DefaultInputModuleHierarchy.class);
     indexer = new ModuleIndexer(tree, componentStore, moduleHierarchy);
index c0e4d487632de848eb39ef0e5cfd1c397df562e6..317849838b3f5739434dec6d6030fe7784c829f7 100644 (file)
@@ -29,13 +29,13 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
+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.analysis.DefaultAnalysisMode;
 import org.sonar.scanner.bootstrap.GlobalConfiguration;
 import org.sonar.scanner.bootstrap.GlobalConfigurationProvider;
-import org.sonar.scanner.bootstrap.GlobalMode;
+import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
 import org.sonar.scanner.bootstrap.GlobalProperties;
 import org.sonar.scanner.bootstrap.MutableGlobalSettings;
 import org.sonar.scanner.repository.FileData;
@@ -51,11 +51,11 @@ public class MutableModuleSettingsTest {
   @Rule
   public ExpectedException thrown = ExpectedException.none();
 
-  private DefaultAnalysisMode mode;
+  private AnalysisMode mode;
 
   @Before
   public void before() {
-    mode = mock(DefaultAnalysisMode.class);
+    mode = mock(AnalysisMode.class);
   }
 
   private ProjectRepositories createSettings(String module, Map<String, String> settingsMap) {
@@ -157,6 +157,6 @@ public class MutableModuleSettingsTest {
   private GlobalConfiguration newGlobalSettings(Map<String, String> props) {
     GlobalProperties globalProps = new GlobalProperties(props);
     return new GlobalConfigurationProvider().provide(mock(SettingsLoader.class), globalProps, new PropertyDefinitions(),
-      new GlobalMode(globalProps));
+      new GlobalAnalysisMode(globalProps));
   }
 }
index 0087e27fedec6360d534b0156d631247a53a19af..707e4b33a237bb49e66e46c585ee2d556c274741 100644 (file)
@@ -33,10 +33,9 @@ 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.analysis.DefaultAnalysisMode;
 import org.sonar.scanner.bootstrap.GlobalConfiguration;
 import org.sonar.scanner.bootstrap.GlobalConfigurationProvider;
-import org.sonar.scanner.bootstrap.GlobalMode;
+import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
 import org.sonar.scanner.bootstrap.GlobalProperties;
 import org.sonar.scanner.bootstrap.MutableGlobalSettings;
 import org.sonar.scanner.repository.FileData;
@@ -60,16 +59,14 @@ public class MutableProjectSettingsTest {
   private Table<String, String, FileData> emptyFileData;
   private Table<String, String, String> emptySettings;
 
-  private GlobalMode globalMode;
-  private DefaultAnalysisMode mode;
+  private GlobalAnalysisMode globalMode;
 
   @Before
   public void prepare() {
     emptyFileData = ImmutableTable.of();
     emptySettings = ImmutableTable.of();
     project = ProjectDefinition.create().setKey("struts");
-    globalMode = mock(GlobalMode.class);
-    mode = mock(DefaultAnalysisMode.class);
+    globalMode = mock(GlobalAnalysisMode.class);
     bootstrapProps = new GlobalConfigurationProvider().provide(mock(SettingsLoader.class), new GlobalProperties(Collections.<String, String>emptyMap()), new PropertyDefinitions(),
       globalMode);
   }
@@ -79,7 +76,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, mode);
+    MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), new MutableGlobalSettings(bootstrapProps), projectRef, globalMode);
 
     assertThat(batchSettings.getString("project.prop")).isEqualTo("project");
   }
@@ -91,7 +88,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, mode);
+    MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), new MutableGlobalSettings(bootstrapProps), projectRef, globalMode);
     assertThat(batchSettings.getString("sonar.java.coveragePlugin")).isEqualTo("jacoco");
   }
 
@@ -105,7 +102,7 @@ public class MutableProjectSettingsTest {
 
     projectRef = new ProjectRepositories(settings, emptyFileData, null);
 
-    MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), new MutableGlobalSettings(bootstrapProps), projectRef, mode);
+    MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), new MutableGlobalSettings(bootstrapProps), projectRef, globalMode);
 
     assertThat(batchSettings.getString("sonar.java.coveragePlugin")).isEqualTo("jacoco");
   }
@@ -117,7 +114,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, mode);
+    MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), new MutableGlobalSettings(bootstrapProps), projectRef, globalMode);
 
     assertThat(batchSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2");
     assertThat(batchSettings.getString("sonar.foo.secured")).isEqualTo("bar");
@@ -129,10 +126,10 @@ public class MutableProjectSettingsTest {
     settings.put("struts", "sonar.foo.secured", "bar");
     settings.put("struts", "sonar.foo.license.secured", "bar2");
 
-    when(mode.isIssues()).thenReturn(true);
+    when(globalMode.isIssues()).thenReturn(true);
 
     projectRef = new ProjectRepositories(settings, emptyFileData, null);
-    MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), new MutableGlobalSettings(bootstrapProps), projectRef, mode);
+    MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), new MutableGlobalSettings(bootstrapProps), projectRef, globalMode);
 
     assertThat(batchSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2");
     thrown.expect(MessageException.class);
index 896b3a9fd0688fe8b086b0a249805d7368f03be8..5c88bd4406a8be9ed065fb9a6d25da5fa2601798 100644 (file)
@@ -24,6 +24,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.api.CoreProperties;
+import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
 import org.sonar.api.batch.bootstrap.ProjectReactor;
 import org.sonar.api.utils.MessageException;
@@ -37,13 +38,15 @@ public class ProjectReactorValidatorTest {
   @Rule
   public ExpectedException thrown = ExpectedException.none();
 
-  private DefaultAnalysisMode mode;
+  private AnalysisMode mode;
+  private DefaultAnalysisMode analysisFlags;
   private ProjectReactorValidator validator;
 
   @Before
   public void prepare() {
-    mode = mock(DefaultAnalysisMode.class);
-    validator = new ProjectReactorValidator(mode);
+    mode = mock(AnalysisMode.class);
+    analysisFlags = mock(DefaultAnalysisMode.class);
+    validator = new ProjectReactorValidator(mode, analysisFlags);
   }
 
   @Test
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/branch/BranchConfigurationProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/branch/BranchConfigurationProviderTest.java
new file mode 100644 (file)
index 0000000..7201374
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.branch;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.scanner.scan.ProjectSettings;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class BranchConfigurationProviderTest {
+  private BranchConfigurationProvider provider = new BranchConfigurationProvider();
+  private ProjectSettings projectSettings;
+  private BranchConfigurationLoader loader;
+  private BranchConfiguration config;
+  private ProjectBranches branches;
+
+  @Before
+  public void setUp() {
+    projectSettings = mock(ProjectSettings.class);
+    loader = mock(BranchConfigurationLoader.class);
+    config = mock(BranchConfiguration.class);
+    branches = mock(ProjectBranches.class);
+  }
+
+  @Test
+  public void should_cache_config() {
+    BranchConfiguration configuration = provider.provide(null, projectSettings, branches);
+    assertThat(provider.provide(null, projectSettings, branches)).isSameAs(configuration);
+  }
+
+  @Test
+  public void should_use_loader() {
+    when(loader.load(projectSettings, branches)).thenReturn(config);
+    BranchConfiguration branchConfig = provider.provide(loader, projectSettings, branches);
+
+    assertThat(branchConfig).isSameAs(config);
+  }
+
+  @Test
+  public void should_return_default_if_no_loader() {
+    BranchConfiguration configuration = provider.provide(null, projectSettings, branches);
+    assertThat(configuration.branchTarget()).isNull();
+    assertThat(configuration.branchType()).isEqualTo(BranchType.LONG);
+  }
+}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/branch/ProjectBranchesProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/branch/ProjectBranchesProviderTest.java
new file mode 100644 (file)
index 0000000..3a22798
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.branch;
+
+import java.util.Optional;
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.config.Configuration;
+import org.sonar.scanner.bootstrap.GlobalConfiguration;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class ProjectBranchesProviderTest {
+  private ProjectBranchesProvider provider = new ProjectBranchesProvider();
+  private ProjectBranchesLoader mockLoader;
+  private ProjectBranches mockBranches;
+  private GlobalConfiguration mockSettings;
+
+  @Before
+  public void setUp() {
+    mockLoader = mock(ProjectBranchesLoader.class);
+    mockBranches = mock(ProjectBranches.class);
+    mockSettings = mock(GlobalConfiguration.class);
+  }
+
+  @Test
+  public void should_cache_branches() {
+    ProjectBranches branches = provider.provide(null, () -> "project", mockSettings);
+    assertThat(provider.provide(null, () -> "project", mockSettings)).isSameAs(branches);
+  }
+
+  @Test
+  public void should_use_loader() {
+    when(mockLoader.load("key")).thenReturn(mockBranches);
+    when(mockSettings.get(anyString())).thenReturn(Optional.of("somebranch"));
+    ProjectBranches branches = provider.provide(mockLoader, () -> "key", mockSettings);
+
+    assertThat(branches).isSameAs(mockBranches);
+  }
+
+  @Test
+  public void should_return_default_if_no_loader() {
+    ProjectBranches branches = provider.provide(null, () -> "project", mockSettings);
+    assertThat(branches.isEmpty()).isTrue();
+  }
+}
index aacfb609f52947b73dbc977aa65b5ea93444d0ae..9d96bd65dfb53ddc69c41b1fddf46880e8acb673 100644 (file)
@@ -27,7 +27,6 @@ import java.util.List;
 import org.junit.ClassRule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
-import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.InputFile.Status;
@@ -36,7 +35,8 @@ import org.sonar.api.batch.fs.InputPath;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.fs.internal.DefaultInputModule;
 import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
-import org.sonar.scanner.scan.BranchConfiguration;
+import org.sonar.scanner.analysis.DefaultAnalysisMode;
+import org.sonar.scanner.scan.branch.BranchConfiguration;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
@@ -60,7 +60,7 @@ public class InputComponentStoreTest {
     DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule(rootDef);
     DefaultInputModule subModule = TestInputFileBuilder.newDefaultInputModule(moduleDef);
 
-    InputComponentStore cache = new InputComponentStore(rootModule, mock(AnalysisMode.class), mock(BranchConfiguration.class));
+    InputComponentStore cache = new InputComponentStore(rootModule, mock(DefaultAnalysisMode.class), mock(BranchConfiguration.class));
     cache.put(subModule);
 
     DefaultInputFile fooFile = new TestInputFileBuilder(rootModuleKey, "src/main/java/Foo.java")
@@ -104,7 +104,7 @@ public class InputComponentStoreTest {
 
   static class InputComponentStoreTester extends InputComponentStore {
     InputComponentStoreTester() throws IOException {
-      super(TestInputFileBuilder.newDefaultInputModule("root", temp.newFolder()), mock(AnalysisMode.class), mock(BranchConfiguration.class));
+      super(TestInputFileBuilder.newDefaultInputModule("root", temp.newFolder()), mock(DefaultAnalysisMode.class), mock(BranchConfiguration.class));
     }
 
     InputFile addFile(String moduleKey, String relpath, String language) {
index 9856377a92ce820cefa44ab0ece9dd738e4b5d59..a50f8de957233b392a95883948a5bd1d1c22a0a4 100644 (file)
@@ -24,13 +24,13 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
-import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.InputModule;
 import org.sonar.api.batch.fs.internal.DefaultInputModule;
 import org.sonar.api.batch.fs.internal.SensorStrategy;
 import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
-import org.sonar.scanner.scan.BranchConfiguration;
+import org.sonar.scanner.analysis.DefaultAnalysisMode;
+import org.sonar.scanner.scan.branch.BranchConfiguration;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Matchers.any;
@@ -49,7 +49,7 @@ public class ModuleInputComponentStoreTest {
   @Before
   public void setUp() throws IOException {
     DefaultInputModule root = TestInputFileBuilder.newDefaultInputModule(moduleKey, temp.newFolder());
-    componentStore = new InputComponentStore(root, mock(AnalysisMode.class), mock(BranchConfiguration.class));
+    componentStore = new InputComponentStore(root, mock(DefaultAnalysisMode.class), mock(BranchConfiguration.class));
   }
 
   @Test
index 4b005062ddb53eed870820a12dcd39e77be8fd8a..1819252ae3c4c7f9ce10b89fe98b7e5828d44d2b 100644 (file)
@@ -31,7 +31,6 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
-import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.internal.DefaultFileSystem;
@@ -46,10 +45,11 @@ import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.issue.Issue;
 import org.sonar.api.platform.Server;
 import org.sonar.api.rule.RuleKey;
+import org.sonar.scanner.analysis.DefaultAnalysisMode;
 import org.sonar.scanner.issue.IssueCache;
 import org.sonar.scanner.issue.tracking.TrackedIssue;
-import org.sonar.scanner.scan.BranchConfiguration;
 import org.sonar.scanner.scan.DefaultComponentTree;
+import org.sonar.scanner.scan.branch.BranchConfiguration;
 import org.sonar.scanner.scan.filesystem.InputComponentStore;
 
 import static net.javacrumbs.jsonunit.assertj.JsonAssert.assertThatJson;
@@ -84,7 +84,7 @@ public class JSONReportTest {
     DefaultComponentTree inputComponentTree = new DefaultComponentTree();
     ProjectDefinition def = ProjectDefinition.create().setBaseDir(projectBaseDir).setWorkDir(temp.newFolder()).setKey("struts");
     DefaultInputModule rootModule = new DefaultInputModule(def, 1);
-    InputComponentStore inputComponentStore = new InputComponentStore(rootModule, mock(AnalysisMode.class), mock(BranchConfiguration.class));
+    InputComponentStore inputComponentStore = new InputComponentStore(rootModule, mock(DefaultAnalysisMode.class), mock(BranchConfiguration.class));
 
     DefaultInputModule moduleA = new DefaultInputModule(ProjectDefinition.create().setKey("struts-core").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder()));
     inputComponentTree.index(moduleA, rootModule);
index aa62800ee918ab560d0096c072f56b380823c86a..afe8a413d988a7eaf8f03c791babca751ce9c625 100644 (file)
@@ -37,7 +37,7 @@ import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.internal.SonarRuntimeImpl;
 import org.sonar.api.measures.CoreMetrics;
 import org.sonar.api.utils.Version;
-import org.sonar.scanner.scan.BranchConfiguration;
+import org.sonar.scanner.scan.branch.BranchConfiguration;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
index 09a347f71dc0242fde312c9b1c727dd3ab3d2b63..ab3295ac4099e71d4d7c25f6de3eb96c15380802 100644 (file)
@@ -21,9 +21,9 @@ package org.sonar.scanner.source;
 
 import org.junit.Rule;
 import org.junit.Test;
-import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.utils.log.LogTester;
 import org.sonar.api.utils.log.LoggerLevel;
+import org.sonar.scanner.analysis.DefaultAnalysisMode;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
@@ -36,9 +36,9 @@ public class ZeroCoverageSensorTest {
 
   @Test
   public void dontForceCoverageInIncrementalMode() {
-    AnalysisMode analysisMode = mock(AnalysisMode.class);
-    when(analysisMode.isIncremental()).thenReturn(true);
-    ZeroCoverageSensor zeroCoverageSensor = new ZeroCoverageSensor(null, analysisMode);
+    DefaultAnalysisMode analysisFlags = mock(DefaultAnalysisMode.class);
+    when(analysisFlags.isIncremental()).thenReturn(true);
+    ZeroCoverageSensor zeroCoverageSensor = new ZeroCoverageSensor(null, analysisFlags);
     zeroCoverageSensor.execute(null);
     assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("Incremental mode: not forcing coverage to zero");
   }