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();
}
}
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();
}
}
--- /dev/null
+/*
+ * 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();
+}
+++ /dev/null
-/*
- * 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));
- }
-
- }
-
-}
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;
// only static stuff
}
- public static Collection<Object> all(AnalysisMode analysisMode) {
+ public static Collection<Object> all(GlobalAnalysisMode analysisMode) {
List<Object> components = Lists.newArrayList(
DefaultResourceTypes.get(),
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;
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;
--- /dev/null
+/*
+ * 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");
+ }
+ }
+}
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;
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;
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);
@Override
protected void doBeforeStart() {
GlobalProperties bootstrapProps = new GlobalProperties(bootstrapProperties);
- GlobalMode globalMode = new GlobalMode(bootstrapProps);
+ GlobalAnalysisMode globalMode = new GlobalAnalysisMode(bootstrapProps);
add(bootstrapProps);
add(globalMode);
addBootstrapComponents();
+++ /dev/null
-/*
- * 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();
- }
-
-}
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;
@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) {
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
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;
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();
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;
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;
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;
});
}
- public AnalysisMode getMode() {
+ public GlobalAnalysisMode getMode() {
return mode;
}
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;
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 {
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
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;
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;
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;
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;
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;
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;
.setParam("projectBranch", moduleHierarchy.root().getBranch())
.setPart("report", filePart);
- if (analysisMode.isIncremental()) {
+ if (analysisFlags.isIncremental()) {
post.setParam("characteristic", "incremental=true");
}
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();
}
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;
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);
@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<>();
+++ /dev/null
-/*
- * 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();
-}
+++ /dev/null
-/*
- * 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);
-}
+++ /dev/null
-/*
- * 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;
- }
-}
+++ /dev/null
-/*
- * 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);
-}
+++ /dev/null
-/*
- * 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;
- }
-}
+++ /dev/null
-/*
- * 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
- }
-}
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);
}
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;
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<>();
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;
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;
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;
@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());
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) {
String deprecatedBranchName = reactor.getRoot().getBranch();
- branchParamsValidator.validate(validationMessages, deprecatedBranchName, mode.isIncremental());
+ branchParamsValidator.validate(validationMessages, deprecatedBranchName, analysisFlags.isIncremental());
validateBranch(validationMessages, deprecatedBranchName);
if (!validationMessages.isEmpty()) {
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;
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;
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;
Storages.class,
new RulesProvider(),
new BranchConfigurationProvider(),
+ new ProjectBranchesProvider(),
+ DefaultAnalysisMode.class,
+ new ProjectRepositoriesProvider(),
// temp
new AnalysisTempFolderProvider(),
@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)) {
}
}
- private static String toDisplayName(BranchConfiguration.BranchType branchType) {
+ private static String toDisplayName(BranchType branchType) {
switch (branchType) {
case LONG:
return "long living";
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);
}
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);
+ }
}
--- /dev/null
+/*
+ * 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();
+}
--- /dev/null
+/*
+ * 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);
+}
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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);
+}
--- /dev/null
+/*
+ * 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
+}
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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
+ }
+}
--- /dev/null
+/*
+ * 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();
+ }
+}
--- /dev/null
+/*
+ * 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);
+
+}
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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;
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;
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
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);
}
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() {
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;
}
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;
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;
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;
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;
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
@Override
public void execute(final SensorContext context) {
- if (mode.isIncremental()) {
+ if (analysisFlags.isIncremental()) {
LOG.debug("Incremental mode: not forcing coverage to zero");
return;
}
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 {
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();
}
}
@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) {
*/
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);
}
}
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;
public class ExtensionInstallerTest {
- GlobalMode mode;
+ GlobalAnalysisMode mode;
ScannerPluginRepository pluginRepository = mock(ScannerPluginRepository.class);
private static SonarPlugin newPluginInstance(final Object... extensions) {
@Before
public void setUp() {
- mode = mock(GlobalMode.class);
+ mode = mock(GlobalAnalysisMode.class);
}
@Test
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();
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());
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());
--- /dev/null
+/*
+ * 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);
+ }
+}
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
+++ /dev/null
-/*
- * 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);
- }
-}
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() {
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/");
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();
@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);
}
}
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);
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
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
.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
.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() {
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;
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;
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")) {
};
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")) {
};
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()) {
};
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");
}
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;
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;
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);
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;
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;
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());
}
}
}
- public ScannerMediumTester setBranchType(BranchConfiguration.BranchType branchType) {
+ public ScannerMediumTester setBranchType(BranchType branchType) {
branchConfiguration.branchType = branchType;
return this;
}
private class FakeBranchConfigurationLoader implements BranchConfigurationLoader {
@Override
- public BranchConfiguration load(String projectKey, GlobalConfiguration settings) {
+ public BranchConfiguration load(ProjectSettings settings, ProjectBranches branches) {
return branchConfiguration;
}
}
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;
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();
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);
import static org.assertj.core.api.Assertions.assertThat;
+import java.io.File;
import java.util.Arrays;
import java.util.List;
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;
@Rule
public LogTester logTester = new LogTester();
+ @Rule
+ public TemporaryFolder temp = new TemporaryFolder();
+
@Rule
public ScannerMediumTester tester = new ScannerMediumTester()
.registerPlugin("faketask", new FakeTaskPlugin());
@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();
}
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;
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);
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;
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;
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);
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;
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());
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;
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;
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;
private ProjectAnalysisInfo projectAnalysisInfo;
private CpdSettings cpdSettings;
private InputModuleHierarchy inputModuleHierarchy;
- private AnalysisMode analysisMode;
+ private DefaultAnalysisMode analysisMode;
private ScannerPluginRepository pluginRepository;
private BranchConfiguration branches;
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);
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));
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;
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 {
@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);
@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");
@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);
@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");
@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);
@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);
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();
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();
@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");
@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);
@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";
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;
private File sourceFile;
private ScannerReportWriter writer;
private DefaultInputFile inputFile;
- private AnalysisMode analysisMode;
+ private DefaultAnalysisMode analysisFlags;
@Before
public void prepare() throws IOException {
.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);
@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);
@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);
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;
@Mock
private ProjectKey projectKey;
@Mock
- private DefaultAnalysisMode mode;
+ private GlobalAnalysisMode mode;
@Mock
private BranchConfiguration branchConfiguration;
*/
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;
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() {
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();
+ }
+
}
+++ /dev/null
-/*
- * 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);
- }
-}
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;
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);
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;
@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) {
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));
}
}
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;
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);
}
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");
}
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");
}
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");
}
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");
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);
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;
@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
--- /dev/null
+/*
+ * 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);
+ }
+}
--- /dev/null
+/*
+ * 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();
+ }
+}
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;
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;
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")
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) {
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;
@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
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;
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;
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);
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;
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;
@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");
}