public static final String BRANCHES_DOC_LINK = "https://redirect.sonarsource.com/doc/branches.html";
- public static final String ORGANIZATION = "sonar.organization";
-
public static final String BRANCH_NAME = "sonar.branch.name";
@Deprecated
public static final String BRANCH_TARGET = "sonar.branch.target";
.category(CoreProperties.CATEGORY_SCM)
.onlyOnQualifiers(Qualifiers.PROJECT)
.build(),
- PropertyDefinition.builder(ORGANIZATION)
- .name("Organization key")
- .description("Key of the organization that contains the project being analyzed. If unset, then the organization marked as default is used.")
- .hidden()
- .build(),
PropertyDefinition.builder(BRANCH_NAME)
.name("Optional name of SonarQube/SCM branch")
.description("Provide a name for the branch being analyzed. It might match an existing branch of the project, otherwise a new branch will be created.")
@Test
public void all() {
List<PropertyDefinition> defs = CorePropertyDefinitions.all();
- assertThat(defs).hasSize(55);
+ assertThat(defs).hasSize(54);
}
@Test
protected boolean mediumTestMode;
- public GlobalAnalysisMode(RawScannerProperties props) {
+ public GlobalAnalysisMode(ScannerProperties props) {
mediumTestMode = "true".equals(props.property(MEDIUM_TEST_ENABLED));
if (mediumTestMode) {
LOG.info("Medium test mode");
private GlobalConfiguration globalConfig;
- public GlobalConfiguration provide(GlobalServerSettings globalServerSettings, RawScannerProperties scannerProps,
+ public GlobalConfiguration provide(GlobalServerSettings globalServerSettings, ScannerProperties scannerProps,
PropertyDefinitions propertyDefinitions) {
if (globalConfig == null) {
Map<String, String> mergedSettings = new LinkedHashMap<>();
@Override
protected void doBeforeStart() {
- RawScannerProperties rawScannerProperties = new RawScannerProperties(scannerProperties);
+ ScannerProperties rawScannerProperties = new ScannerProperties(scannerProperties);
GlobalAnalysisMode globalMode = new GlobalAnalysisMode(rawScannerProperties);
add(rawScannerProperties);
add(globalMode);
this.system = system;
}
- public TempFolder provide(RawScannerProperties scannerProps) {
+ public TempFolder provide(ScannerProperties scannerProps) {
if (tempFolder == null) {
String workingPathName = StringUtils.defaultIfBlank(scannerProps.property(CoreProperties.GLOBAL_WORKING_DIRECTORY), CoreProperties.GLOBAL_WORKING_DIRECTORY_DEFAULT_VALUE);
}
}
- private Path findSonarHome(RawScannerProperties props) {
+ private Path findSonarHome(ScannerProperties props) {
String home = props.property("sonar.userHome");
if (home != null) {
return Paths.get(home).toAbsolutePath();
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2020 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.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import javax.annotation.concurrent.Immutable;
-import org.sonar.scanner.scan.ExternalProjectKeyAndOrganization;
-
-import static org.sonar.api.CoreProperties.PROJECT_KEY_PROPERTY;
-
-/**
- * Properties that are coming from scanner.
- */
-@Immutable
-public class ProcessedScannerProperties {
-
- private final Map<String, String> properties;
-
- public ProcessedScannerProperties(RawScannerProperties rawScannerProperties,
- ExternalProjectKeyAndOrganization externalProjectKeyAndOrganization) {
- this.properties = new HashMap<>();
- this.properties.putAll(rawScannerProperties.properties());
-
- externalProjectKeyAndOrganization.getProjectKey()
- .ifPresent(projectKey -> properties.put(PROJECT_KEY_PROPERTY, projectKey));
- externalProjectKeyAndOrganization.getOrganization()
- .ifPresent(organization -> properties.put(org.sonar.core.config.ScannerProperties.ORGANIZATION, organization));
- }
-
- public Map<String, String> properties() {
- return Collections.unmodifiableMap(new HashMap<>(properties));
- }
-
- public String property(String key) {
- return properties.get(key);
- }
-
- public String getProjectKey() {
- return this.properties.get(PROJECT_KEY_PROPERTY);
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2020 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.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import javax.annotation.concurrent.Immutable;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.config.internal.Encryption;
-
-/**
- * Properties that are coming from scanner.
- */
-@Immutable
-public class RawScannerProperties {
-
- private final Map<String, String> properties;
- private final Encryption encryption;
-
- public RawScannerProperties(Map<String, String> properties) {
- encryption = new Encryption(properties.get(CoreProperties.ENCRYPTION_SECRET_KEY_PATH));
- Map<String, String> decryptedProps = new HashMap<>(properties.size());
- for (Map.Entry<String, String> entry : properties.entrySet()) {
- String value = entry.getValue();
- if (value != null && encryption.isEncrypted(value)) {
- try {
- value = encryption.decrypt(value);
- } catch (Exception e) {
- throw new IllegalStateException("Fail to decrypt the property " + entry.getKey() + ". Please check your secret key.", e);
- }
- }
- decryptedProps.put(entry.getKey(), value);
- }
- this.properties = Collections.unmodifiableMap(new HashMap<>(decryptedProps));
- }
-
- public Encryption getEncryption() {
- return encryption;
- }
-
- public Map<String, String> properties() {
- return properties;
- }
-
- public String property(String key) {
- return properties.get(key);
- }
-}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.concurrent.Immutable;
+import org.sonar.api.config.internal.Encryption;
+
+import static org.sonar.api.CoreProperties.ENCRYPTION_SECRET_KEY_PATH;
+import static org.sonar.api.CoreProperties.PROJECT_KEY_PROPERTY;
+
+/**
+ * Properties that are coming from scanner.
+ */
+@Immutable
+public class ScannerProperties {
+
+ private final Map<String, String> properties;
+ private final Encryption encryption;
+
+ public ScannerProperties(Map<String, String> properties) {
+ encryption = new Encryption(properties.get(ENCRYPTION_SECRET_KEY_PATH));
+ Map<String, String> decryptedProps = new HashMap<>(properties.size());
+ for (Map.Entry<String, String> entry : properties.entrySet()) {
+ String value = entry.getValue();
+ if (value != null && encryption.isEncrypted(value)) {
+ try {
+ value = encryption.decrypt(value);
+ } catch (Exception e) {
+ throw new IllegalStateException("Fail to decrypt the property " + entry.getKey() + ". Please check your secret key.", e);
+ }
+ }
+ decryptedProps.put(entry.getKey(), value);
+ }
+ this.properties = Collections.unmodifiableMap(new HashMap<>(decryptedProps));
+ }
+
+ public Encryption getEncryption() {
+ return encryption;
+ }
+
+ public Map<String, String> properties() {
+ return properties;
+ }
+
+ public String property(String key) {
+ return properties.get(key);
+ }
+
+ public String getProjectKey() {
+ return properties.get(PROJECT_KEY_PROPERTY);
+ }
+}
private DefaultScannerWsClient wsClient;
- public synchronized DefaultScannerWsClient provide(final RawScannerProperties scannerProps,
+ public synchronized DefaultScannerWsClient provide(final ScannerProperties scannerProps,
final EnvironmentInformation env, GlobalAnalysisMode globalMode, System2 system) {
if (wsClient == null) {
String url = defaultIfBlank(scannerProps.property("sonar.host.url"), "http://localhost:9000");
import org.sonar.scanner.repository.ForkDateSupplier;
import org.sonar.scanner.rule.QProfile;
import org.sonar.scanner.rule.QualityProfiles;
-import org.sonar.scanner.scan.ScanProperties;
import org.sonar.scanner.scan.branch.BranchConfiguration;
import org.sonar.scanner.scan.filesystem.InputComponentStore;
import org.sonar.scanner.scm.ScmConfiguration;
private static final Logger LOG = Loggers.get(MetadataPublisher.class);
- private final ScanProperties properties;
private final QualityProfiles qProfiles;
private final ProjectInfo projectInfo;
private final InputModuleHierarchy moduleHierarchy;
private final InputComponentStore componentStore;
private final ScmConfiguration scmConfiguration;
- public MetadataPublisher(ProjectInfo projectInfo, InputModuleHierarchy moduleHierarchy, ScanProperties properties,
- QualityProfiles qProfiles, CpdSettings cpdSettings, ScannerPluginRepository pluginRepository, BranchConfiguration branchConfiguration,
+ public MetadataPublisher(ProjectInfo projectInfo, InputModuleHierarchy moduleHierarchy, QualityProfiles qProfiles,
+ CpdSettings cpdSettings, ScannerPluginRepository pluginRepository, BranchConfiguration branchConfiguration,
ScmRevision scmRevision, ForkDateSupplier forkDateSupplier, InputComponentStore componentStore, ScmConfiguration scmConfiguration) {
this.projectInfo = projectInfo;
this.moduleHierarchy = moduleHierarchy;
- this.properties = properties;
this.qProfiles = qProfiles;
this.cpdSettings = cpdSettings;
this.pluginRepository = pluginRepository;
PostRequest.Part filePart = new PostRequest.Part(MediaTypes.ZIP, report);
PostRequest post = new PostRequest("api/ce/submit")
.setMediaType(MediaTypes.PROTOBUF)
- .setParam("organization", properties.organizationKey().orElse(null))
.setParam("projectKey", moduleHierarchy.root().key())
.setParam("projectName", moduleHierarchy.root().getOriginalName())
.setPart("report", filePart);
void prepareAndDumpMetadata(String taskId) {
Map<String, String> metadata = new LinkedHashMap<>();
- properties.organizationKey().ifPresent(org -> metadata.put("organization", org));
metadata.put("projectKey", moduleHierarchy.root().key());
metadata.put("serverUrl", server.getPublicRootUrl());
metadata.put("serverVersion", server.getVersion());
import java.util.function.Supplier;
import org.sonar.api.utils.MessageException;
import org.sonar.scanner.bootstrap.DefaultScannerWsClient;
-import org.sonar.scanner.scan.ScanProperties;
import org.sonarqube.ws.Qualityprofiles.SearchWsResponse;
import org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile;
import org.sonarqube.ws.client.GetRequest;
private static final String WS_URL = "/api/qualityprofiles/search.protobuf";
private final DefaultScannerWsClient wsClient;
- private final ScanProperties properties;
- public DefaultQualityProfileLoader(ScanProperties properties, DefaultScannerWsClient wsClient) {
- this.properties = properties;
+ public DefaultQualityProfileLoader(DefaultScannerWsClient wsClient) {
this.wsClient = wsClient;
}
}
private List<QualityProfile> doLoad(StringBuilder url) throws IOException {
- properties.organizationKey().ifPresent(k -> url.append("&organization=").append(encodeForUrl(k)));
Map<String, QualityProfile> result = call(url.toString());
if (result.isEmpty()) {
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.ProcessedScannerProperties;
+import org.sonar.scanner.bootstrap.ScannerProperties;
import org.sonar.scanner.scan.branch.BranchConfiguration;
public class ProjectRepositoriesSupplier implements Supplier<ProjectRepositories> {
private static final Logger LOG = Loggers.get(ProjectRepositoriesSupplier.class);
private static final String LOG_MSG = "Load project repositories";
private final ProjectRepositoriesLoader loader;
- private final ProcessedScannerProperties scannerProperties;
+ private final ScannerProperties scannerProperties;
private final BranchConfiguration branchConfig;
private ProjectRepositories project = null;
- public ProjectRepositoriesSupplier(ProjectRepositoriesLoader loader, ProcessedScannerProperties scannerProperties, BranchConfiguration branchConfig) {
+ public ProjectRepositoriesSupplier(ProjectRepositoriesLoader loader, ScannerProperties scannerProperties, BranchConfiguration branchConfig) {
this.loader = loader;
this.scannerProperties = scannerProperties;
this.branchConfig = branchConfig;
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.ProcessedScannerProperties;
+import org.sonar.scanner.bootstrap.ScannerProperties;
import org.sonar.scanner.rule.QualityProfiles;
public class QualityProfilesProvider extends ProviderAdapter {
private static final String LOG_MSG = "Load quality profiles";
private QualityProfiles profiles = null;
- public QualityProfiles provide(QualityProfileLoader loader, ProcessedScannerProperties props) {
+ public QualityProfiles provide(QualityProfileLoader loader, ScannerProperties props) {
if (this.profiles == null) {
Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG);
profiles = new QualityProfiles(loader.load(props.getProjectKey()));
package org.sonar.scanner.repository.settings;
import java.util.Map;
-import org.sonar.scanner.bootstrap.ProcessedScannerProperties;
import org.sonar.scanner.bootstrap.DefaultScannerWsClient;
+import org.sonar.scanner.bootstrap.ScannerProperties;
public class DefaultProjectSettingsLoader extends AbstractSettingsLoader implements ProjectSettingsLoader {
- private final ProcessedScannerProperties scannerProperties;
+ private final ScannerProperties scannerProperties;
- public DefaultProjectSettingsLoader(final DefaultScannerWsClient wsClient, final ProcessedScannerProperties scannerProperties) {
+ public DefaultProjectSettingsLoader(final DefaultScannerWsClient wsClient, final ScannerProperties scannerProperties) {
super(wsClient);
this.scannerProperties = scannerProperties;
}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2020 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.Optional;
-import javax.annotation.concurrent.Immutable;
-
-import static java.util.Optional.empty;
-
-@Immutable
-public class EmptyExternalProjectKeyAndOrganization implements ExternalProjectKeyAndOrganization {
- @Override
- public Optional<String> getProjectKey() {
- return empty();
- }
-
- @Override
- public Optional<String> getOrganization() {
- return empty();
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2020 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.Optional;
-import javax.annotation.concurrent.Immutable;
-
-@Immutable
-public interface ExternalProjectKeyAndOrganization {
- Optional<String> getProjectKey();
-
- Optional<String> getOrganization();
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2020 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.Optional;
-import org.sonar.api.scanner.ScannerSide;
-
-@ScannerSide
-public interface ExternalProjectKeyAndOrganizationLoader {
- Optional<ExternalProjectKeyAndOrganization> load();
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2020 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.utils.log.Logger;
-import org.sonar.api.utils.log.Loggers;
-import org.sonar.scanner.bootstrap.RawScannerProperties;
-
-import static org.apache.commons.lang.StringUtils.equalsIgnoreCase;
-import static org.sonar.core.config.ScannerProperties.DISABLE_PROJECT_AND_ORG_AUTODETECTION;
-
-public class ExternalProjectKeyAndOrganizationProvider extends ProviderAdapter {
- private static final Logger LOG = Loggers.get(ExternalProjectKeyAndOrganizationProvider.class);
- private ExternalProjectKeyAndOrganization properties = null;
-
- public ExternalProjectKeyAndOrganization provide(RawScannerProperties rawScannerProperties,
- @Nullable @javax.annotation.Nullable ExternalProjectKeyAndOrganizationLoader loader) {
- if (properties == null) {
- boolean disableProjectKeyAndOrgAutodetection = equalsIgnoreCase(
- rawScannerProperties.property(DISABLE_PROJECT_AND_ORG_AUTODETECTION), "true");
- if (disableProjectKeyAndOrgAutodetection) {
- LOG.info("Skipping project and organization key auto-detection.");
- }
-
- if (loader != null && !disableProjectKeyAndOrgAutodetection) {
- properties = loader.load().orElse(new EmptyExternalProjectKeyAndOrganization());
- } else {
- properties = new EmptyExternalProjectKeyAndOrganization();
- }
- }
-
- return properties;
- }
-}
import org.sonar.api.utils.log.Loggers;
import org.sonar.api.utils.log.Profiler;
import org.sonar.core.config.IssueExclusionProperties;
-import org.sonar.scanner.bootstrap.ProcessedScannerProperties;
+import org.sonar.scanner.bootstrap.ScannerProperties;
import org.sonar.scanner.issue.ignore.pattern.IssueExclusionPatternInitializer;
import org.sonar.scanner.issue.ignore.pattern.IssueInclusionPatternInitializer;
private static final List<String> NON_HERITED_PROPERTIES_FOR_CHILD = Stream.concat(Stream.of(PROPERTY_PROJECT_BASEDIR, CoreProperties.WORKING_DIRECTORY, PROPERTY_MODULES,
CoreProperties.PROJECT_DESCRIPTION_PROPERTY), UNSUPPORTED_PROPS_FOR_MODULES.stream()).collect(toList());
- private final ProcessedScannerProperties scannerProps;
+ private final ScannerProperties scannerProps;
private final AnalysisWarnings analysisWarnings;
private File rootProjectWorkDir;
private boolean warnExclusionsAlreadyLogged;
- public ProjectReactorBuilder(ProcessedScannerProperties props, AnalysisWarnings analysisWarnings) {
+ public ProjectReactorBuilder(ScannerProperties props, AnalysisWarnings analysisWarnings) {
this.scannerProps = props;
this.analysisWarnings = analysisWarnings;
}
import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
import org.sonar.scanner.bootstrap.MetricProvider;
import org.sonar.scanner.bootstrap.PostJobExtensionDictionnary;
-import org.sonar.scanner.bootstrap.ProcessedScannerProperties;
import org.sonar.scanner.ci.CiConfigurationProvider;
import org.sonar.scanner.ci.vendors.AppVeyor;
import org.sonar.scanner.ci.vendors.AzureDevops;
private void addScannerComponents() {
add(
- new ExternalProjectKeyAndOrganizationProvider(),
- ProcessedScannerProperties.class,
ScanProperties.class,
ProjectReactorBuilder.class,
WorkDirectoriesInitializer.class,
ScanProperties properties = getComponentByType(ScanProperties.class);
properties.validate();
- properties.organizationKey().ifPresent(k -> LOG.info("Organization key: {}", k));
properties.get("sonar.branch").ifPresent(deprecatedBranch -> {
throw MessageException.of("The 'sonar.branch' parameter is no longer supported. You should stop using it. " +
"Branch analysis is available in Developer Edition and above. See https://redirect.sonarsource.com/editions/developer.html for more information.");
import org.sonar.api.utils.MessageException;
import static org.sonar.core.config.ScannerProperties.BRANCH_NAME;
-import static org.sonar.core.config.ScannerProperties.ORGANIZATION;
/**
* Properties that can be passed to the scanners and are not exposed in SonarQube.
return configuration.getBoolean(PRELOAD_FILE_METADATA_KEY).orElse(false);
}
- public Optional<String> organizationKey() {
- return configuration.get(ORGANIZATION);
- }
-
public Optional<String> branch() {
return configuration.get(BRANCH_NAME);
}
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.ProcessedScannerProperties;
+import org.sonar.scanner.bootstrap.ScannerProperties;
public class ProjectBranchesProvider extends ProviderAdapter {
private ProjectBranches branches = null;
- public ProjectBranches provide(@Nullable ProjectBranchesLoader loader, ProcessedScannerProperties scannerProperties) {
+ public ProjectBranches provide(@Nullable ProjectBranchesLoader loader, ScannerProperties scannerProperties) {
if (this.branches != null) {
return this.branches;
}
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.ProcessedScannerProperties;
+import org.sonar.scanner.bootstrap.ScannerProperties;
public class ProjectPullRequestsProvider extends ProviderAdapter {
private ProjectPullRequests pullRequests = null;
- public ProjectPullRequests provide(@org.picocontainer.annotations.Nullable ProjectPullRequestsLoader loader, ProcessedScannerProperties scannerProperties) {
+ public ProjectPullRequests provide(@org.picocontainer.annotations.Nullable ProjectPullRequestsLoader loader, ScannerProperties scannerProperties) {
if (pullRequests != null) {
return pullRequests;
}
import org.sonar.api.batch.scm.ScmProvider;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
-import org.sonar.scanner.bootstrap.RawScannerProperties;
+import org.sonar.scanner.bootstrap.ScannerProperties;
import org.sonar.scanner.ci.CiConfiguration;
import org.sonar.scanner.fs.InputModuleHierarchy;
private static final Logger LOG = Loggers.get(ScmRevisionImpl.class);
private final CiConfiguration ciConfiguration;
- private final RawScannerProperties scannerConfiguration;
+ private final ScannerProperties scannerConfiguration;
private final ScmConfiguration scmConfiguration;
private final InputModuleHierarchy moduleHierarchy;
- public ScmRevisionImpl(CiConfiguration ciConfiguration, RawScannerProperties scannerConfiguration, ScmConfiguration scmConfiguration, InputModuleHierarchy moduleHierarchy) {
+ public ScmRevisionImpl(CiConfiguration ciConfiguration, ScannerProperties scannerConfiguration, ScmConfiguration scmConfiguration, InputModuleHierarchy moduleHierarchy) {
this.ciConfiguration = ciConfiguration;
this.scannerConfiguration = scannerConfiguration;
this.scmConfiguration = scmConfiguration;
logTester.setLevel(LoggerLevel.DEBUG);
DefaultScannerWsClient underTest = new DefaultScannerWsClient(wsClient, false, new GlobalAnalysisMode(
- new RawScannerProperties(Collections.emptyMap())));
+ new ScannerProperties(Collections.emptyMap())));
WsResponse result = underTest.call(request);
WsResponse response = newResponse().setCode(401);
when(wsClient.wsConnector().call(request)).thenReturn(response);
- new DefaultScannerWsClient(wsClient, false, new GlobalAnalysisMode(new RawScannerProperties(Collections.emptyMap()))).call(request);
+ new DefaultScannerWsClient(wsClient, false, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap()))).call(request);
}
@Test
WsResponse response = newResponse().setCode(401);
when(wsClient.wsConnector().call(request)).thenReturn(response);
- new DefaultScannerWsClient(wsClient, /* credentials are configured */true, new GlobalAnalysisMode(new RawScannerProperties(Collections.emptyMap()))).call(request);
+ new DefaultScannerWsClient(wsClient, /* credentials are configured */true, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap()))).call(request);
}
@Test
.setCode(403);
when(wsClient.wsConnector().call(request)).thenReturn(response);
- new DefaultScannerWsClient(wsClient, true, new GlobalAnalysisMode(new RawScannerProperties(Collections.emptyMap()))).call(request);
+ new DefaultScannerWsClient(wsClient, true, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap()))).call(request);
}
@Test
.setContent("{\"errors\":[{\"msg\":\"Boo! bad request! bad!\"}]}");
when(wsClient.wsConnector().call(request)).thenReturn(response);
- new DefaultScannerWsClient(wsClient, true, new GlobalAnalysisMode(new RawScannerProperties(Collections.emptyMap()))).call(request);
+ new DefaultScannerWsClient(wsClient, true, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap()))).call(request);
}
private MockWsResponse newResponse() {
public LogTester logTester = new LogTester();
GlobalServerSettings globalServerSettings;
- RawScannerProperties scannerProps;
+ ScannerProperties scannerProps;
@Before
public void prepare() {
globalServerSettings = mock(GlobalServerSettings.class);
- scannerProps = new RawScannerProperties(Collections.emptyMap());
+ scannerProps = new ScannerProperties(Collections.emptyMap());
}
@Test
workingDir.delete();
TempFolder tempFolder = tempFolderProvider.provide(
- new RawScannerProperties(ImmutableMap.of(CoreProperties.GLOBAL_WORKING_DIRECTORY, workingDir.getAbsolutePath())));
+ new ScannerProperties(ImmutableMap.of(CoreProperties.GLOBAL_WORKING_DIRECTORY, workingDir.getAbsolutePath())));
tempFolder.newDir();
tempFolder.newFile();
assertThat(getCreatedTempDir(workingDir)).exists();
}
tempFolderProvider.provide(
- new RawScannerProperties(ImmutableMap.of(CoreProperties.GLOBAL_WORKING_DIRECTORY, workingDir.getAbsolutePath())));
+ new ScannerProperties(ImmutableMap.of(CoreProperties.GLOBAL_WORKING_DIRECTORY, workingDir.getAbsolutePath())));
// this also checks that all other temps were deleted
assertThat(getCreatedTempDir(workingDir)).exists();
File workingDir = new File(sonarHome, CoreProperties.GLOBAL_WORKING_DIRECTORY_DEFAULT_VALUE).getAbsoluteFile();
TempFolder tempFolder = tempFolderProvider.provide(
- new RawScannerProperties(ImmutableMap.of("sonar.userHome", sonarHome.getAbsolutePath())));
+ new ScannerProperties(ImmutableMap.of("sonar.userHome", sonarHome.getAbsolutePath())));
tempFolder.newDir();
tempFolder.newFile();
assertThat(getCreatedTempDir(workingDir)).exists();
File workingDir = new File(defaultSonarHome, CoreProperties.GLOBAL_WORKING_DIRECTORY_DEFAULT_VALUE).getAbsoluteFile();
try {
TempFolder tempFolder = tempFolderProvider.provide(
- new RawScannerProperties(Collections.emptyMap()));
+ new ScannerProperties(Collections.emptyMap()));
tempFolder.newDir();
tempFolder.newFile();
assertThat(getCreatedTempDir(workingDir)).exists();
public void dotWorkingDir() {
File sonarHome = temp.getRoot();
String globalWorkDir = ".";
- RawScannerProperties globalProperties = new RawScannerProperties(
+ ScannerProperties globalProperties = new ScannerProperties(
ImmutableMap.of("sonar.userHome", sonarHome.getAbsolutePath(), CoreProperties.GLOBAL_WORKING_DIRECTORY, globalWorkDir));
TempFolder tempFolder = tempFolderProvider.provide(globalProperties);
File symlink = temp.newFolder();
symlink.delete();
Files.createSymbolicLink(symlink.toPath(), realSonarHome.toPath());
- RawScannerProperties globalProperties = new RawScannerProperties(ImmutableMap.of("sonar.userHome", symlink.getAbsolutePath()));
+ ScannerProperties globalProperties = new ScannerProperties(ImmutableMap.of("sonar.userHome", symlink.getAbsolutePath()));
TempFolder tempFolder = tempFolderProvider.provide(globalProperties);
File newFile = tempFolder.newFile();
@Before
public void setUp() throws Exception {
HttpConnector connector = HttpConnector.newBuilder().url(server.url("/").toString()).build();
- GlobalAnalysisMode analysisMode = new GlobalAnalysisMode(new RawScannerProperties(Collections.emptyMap()));
+ GlobalAnalysisMode analysisMode = new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap()));
DefaultScannerWsClient wsClient = new DefaultScannerWsClient(WsClientFactories.getDefault().newClient(connector), false, analysisMode);
userHome = temp.newFolder();
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2020 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.Test;
-import org.sonar.scanner.scan.EmptyExternalProjectKeyAndOrganization;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.entry;
-
-public class ProcessedScannerPropertiesTest {
- @Test
- public void test_copy_of_properties() {
- Map<String, String> map = new HashMap<>();
- map.put("foo", "bar");
-
- ProcessedScannerProperties underTest = new ProcessedScannerProperties(
- new RawScannerProperties(map),
- new EmptyExternalProjectKeyAndOrganization());
- assertThat(underTest.properties()).containsOnly(entry("foo", "bar"));
- assertThat(underTest.properties()).isNotSameAs(map);
-
- map.put("put", "after_copy");
- assertThat(underTest.properties()).hasSize(1);
- }
-}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.scanner.bootstrap;
+
+import com.google.common.collect.ImmutableMap;
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class ScannerPropertiesTest {
+
+ @Test
+ public void initialization() {
+ ImmutableMap<String, String> map = ImmutableMap.<String, String>builder()
+ .put("prop-1", "{b64}Zm9v")
+ .put("sonar.projectKey", "my-project")
+ .build();
+ ScannerProperties underTest = new ScannerProperties(map);
+
+ assertThat(underTest.getEncryption()).isNotNull();
+ assertThat(underTest.properties())
+ .containsEntry("prop-1", "foo")
+ .containsEntry("sonar.projectKey", "my-project");
+ assertThat(underTest.getProjectKey()).isEqualTo("my-project");
+ }
+
+ @Test
+ public void encryption_fail() {
+ ImmutableMap<String, String> map = ImmutableMap.<String, String>builder()
+ .put("prop-1", "{aes}Zm9vzxc")
+ .build();
+ assertThatThrownBy(() -> new ScannerProperties(map))
+ .isInstanceOf(IllegalStateException.class)
+ .hasMessageContaining("Fail to decrypt the property");
+ }
+
+ @Test
+ public void encryption_ok() {
+ ImmutableMap<String, String> map = ImmutableMap.<String, String>builder()
+ .put("prop-1", "{b64}Zm9v")
+ .build();
+ ScannerProperties underTest = new ScannerProperties(map);
+
+ assertThat(underTest.property("prop-1")).isEqualTo("foo");
+ }
+
+}
@Test
public void provide_client_with_default_settings() {
- RawScannerProperties settings = new RawScannerProperties(new HashMap<>());
+ ScannerProperties settings = new ScannerProperties(new HashMap<>());
- DefaultScannerWsClient client = underTest.provide(settings, env, new GlobalAnalysisMode(new RawScannerProperties(Collections.emptyMap())), mock(System2.class));
+ DefaultScannerWsClient client = underTest.provide(settings, env, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap())), mock(System2.class));
assertThat(client).isNotNull();
assertThat(client.baseUrl()).isEqualTo("http://localhost:9000/");
props.put("sonar.login", "theLogin");
props.put("sonar.password", "thePassword");
props.put("sonar.ws.timeout", "42");
- RawScannerProperties settings = new RawScannerProperties(props);
+ ScannerProperties settings = new ScannerProperties(props);
- DefaultScannerWsClient client = underTest.provide(settings, env, new GlobalAnalysisMode(new RawScannerProperties(Collections.emptyMap())), mock(System2.class));
+ DefaultScannerWsClient client = underTest.provide(settings, env, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap())), mock(System2.class));
assertThat(client).isNotNull();
HttpConnector httpConnector = (HttpConnector) client.wsConnector();
public void build_singleton() {
System2 system = mock(System2.class);
- RawScannerProperties settings = new RawScannerProperties(new HashMap<>());
- DefaultScannerWsClient first = underTest.provide(settings, env, new GlobalAnalysisMode(new RawScannerProperties(Collections.emptyMap())), system);
- DefaultScannerWsClient second = underTest.provide(settings, env, new GlobalAnalysisMode(new RawScannerProperties(Collections.emptyMap())), system);
+ ScannerProperties settings = new ScannerProperties(new HashMap<>());
+ DefaultScannerWsClient first = underTest.provide(settings, env, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap())), system);
+ DefaultScannerWsClient second = underTest.provide(settings, env, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap())), system);
assertThat(first).isSameAs(second);
}
}
import org.sonar.scanner.repository.ForkDateSupplier;
import org.sonar.scanner.rule.QProfile;
import org.sonar.scanner.rule.QualityProfiles;
-import org.sonar.scanner.scan.ScanProperties;
import org.sonar.scanner.scan.branch.BranchConfiguration;
import org.sonar.scanner.scan.branch.BranchType;
import org.sonar.scanner.scan.filesystem.InputComponentStore;
public TemporaryFolder temp = new TemporaryFolder();
private MetadataPublisher underTest;
- private final ScanProperties properties = mock(ScanProperties.class);
private final QualityProfiles qProfiles = mock(QualityProfiles.class);
private final ProjectInfo projectInfo = mock(ProjectInfo.class);
private final CpdSettings cpdSettings = mock(CpdSettings.class);
branches = mock(BranchConfiguration.class);
scmConfiguration = mock(ScmConfiguration.class);
when(scmConfiguration.provider()).thenReturn(scmProvider);
- underTest = new MetadataPublisher(projectInfo, inputModuleHierarchy, properties, qProfiles, cpdSettings,
+ underTest = new MetadataPublisher(projectInfo, inputModuleHierarchy, qProfiles, cpdSettings,
pluginRepository, branches, scmRevision, forkDateSupplier, componentStore, scmConfiguration);
}
@UseDataProvider("projectVersions")
public void write_project_version(@Nullable String projectVersion, String expected) throws Exception {
when(projectInfo.getProjectVersion()).thenReturn(Optional.ofNullable(projectVersion));
- when(properties.organizationKey()).thenReturn(Optional.of("SonarSource"));
File outputDir = temp.newFolder();
ScannerReportWriter writer = new ScannerReportWriter(outputDir);
@UseDataProvider("buildStrings")
public void write_buildString(@Nullable String buildString, String expected) throws Exception {
when(projectInfo.getBuildString()).thenReturn(Optional.ofNullable(buildString));
- when(properties.organizationKey()).thenReturn(Optional.of("SonarSource"));
File outputDir = temp.newFolder();
ScannerReportWriter writer = new ScannerReportWriter(outputDir);
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
-import java.util.Optional;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@Test
public void dump_information_about_report_uploading() throws IOException {
- when(properties.organizationKey()).thenReturn(Optional.of("MyOrg"));
underTest.prepareAndDumpMetadata("TASK-123");
assertThat(readFileToString(properties.metadataFilePath().toFile(), StandardCharsets.UTF_8)).isEqualTo(
- "organization=MyOrg\n" +
"projectKey=org.sonarsource.sonarqube:sonarqube\n" +
"serverUrl=https://localhost\n" +
"serverVersion=6.4\n" +
@Test
public void test_ws_parameters() throws Exception {
- when(properties.organizationKey()).thenReturn(Optional.of("MyOrg"));
-
WsResponse response = mock(WsResponse.class);
PipedOutputStream out = new PipedOutputStream();
verify(wsClient).call(capture.capture());
WsRequest wsRequest = capture.getValue();
- assertThat(wsRequest.getParameters().getKeys()).containsOnly("organization", "projectKey");
- assertThat(wsRequest.getParameters().getValue("organization")).isEqualTo("MyOrg");
+ assertThat(wsRequest.getParameters().getKeys()).containsOnly("projectKey");
assertThat(wsRequest.getParameters().getValue("projectKey")).isEqualTo("org.sonarsource.sonarqube:sonarqube");
}
@Test
public void test_send_branches_characteristics() throws Exception {
- String orgName = "MyOrg";
- when(properties.organizationKey()).thenReturn(Optional.of(orgName));
-
String branchName = "feature";
when(branchConfiguration.branchName()).thenReturn(branchName);
when(branchConfiguration.branchType()).thenReturn(BRANCH);
verify(wsClient).call(capture.capture());
WsRequest wsRequest = capture.getValue();
- assertThat(wsRequest.getParameters().getKeys()).hasSize(3);
- assertThat(wsRequest.getParameters().getValues("organization")).containsExactly(orgName);
+ assertThat(wsRequest.getParameters().getKeys()).hasSize(2);
assertThat(wsRequest.getParameters().getValues("projectKey")).containsExactly("org.sonarsource.sonarqube:sonarqube");
assertThat(wsRequest.getParameters().getValues("characteristic"))
.containsExactlyInAnyOrder("branch=" + branchName, "branchType=" + BRANCH.name());
@Test
public void send_pull_request_characteristic() throws Exception {
- String orgName = "MyOrg";
- when(properties.organizationKey()).thenReturn(Optional.of(orgName));
-
String branchName = "feature";
String pullRequestId = "pr-123";
when(branchConfiguration.branchName()).thenReturn(branchName);
verify(wsClient).call(capture.capture());
WsRequest wsRequest = capture.getValue();
- assertThat(wsRequest.getParameters().getKeys()).hasSize(3);
- assertThat(wsRequest.getParameters().getValues("organization")).containsExactly(orgName);
+ assertThat(wsRequest.getParameters().getKeys()).hasSize(2);
assertThat(wsRequest.getParameters().getValues("projectKey")).containsExactly("org.sonarsource.sonarqube:sonarqube");
assertThat(wsRequest.getParameters().getValues("characteristic"))
.containsExactlyInAnyOrder("pullRequest=" + pullRequestId);
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.util.Optional;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.when;
public class DefaultQualityProfileLoaderTest {
@Rule
public ExpectedException exception = ExpectedException.none();
- private DefaultScannerWsClient wsClient = mock(DefaultScannerWsClient.class);
- private ScanProperties properties = mock(ScanProperties.class);
- private DefaultQualityProfileLoader underTest = new DefaultQualityProfileLoader(properties, wsClient);
+ private final DefaultScannerWsClient wsClient = mock(DefaultScannerWsClient.class);
+ private final ScanProperties properties = mock(ScanProperties.class);
+ private final DefaultQualityProfileLoader underTest = new DefaultQualityProfileLoader(wsClient);
@Test
public void load_gets_all_profiles_for_specified_project() throws IOException {
verifyCalledPath("/api/qualityprofiles/search.protobuf?project=foo%232");
}
- @Test
- public void load_sets_organization_parameter_if_defined_in_settings() throws IOException {
- when(properties.organizationKey()).thenReturn(Optional.of("my-org"));
- prepareCallWithResults();
- underTest.load("foo");
- verifyCalledPath("/api/qualityprofiles/search.protobuf?project=foo&organization=my-org");
- }
-
@Test
public void load_tries_default_if_no_profiles_found_for_project() throws IOException {
HttpException e = new HttpException("", 404, "{\"errors\":[{\"msg\":\"No project found with key 'foo'\"}]}");
verifyCalledPath("/api/qualityprofiles/search.protobuf?defaults=true");
}
- @Test
- public void loadDefault_sets_organization_parameter_if_defined_in_settings() throws IOException {
- when(properties.organizationKey()).thenReturn(Optional.of("my-org"));
-
- HttpException e = new HttpException("", 404, "{\"errors\":[{\"msg\":\"No organization with key 'myorg'\"}]}");
- WsTestUtil.mockException(wsClient, "/api/qualityprofiles/search.protobuf?project=foo&organization=my-org", e);
- WsTestUtil.mockStream(wsClient, "/api/qualityprofiles/search.protobuf?defaults=true&organization=my-org", createStreamOfProfiles("qp"));
-
- underTest.load("foo");
-
- verifyCalledPath("/api/qualityprofiles/search.protobuf?defaults=true&organization=my-org");
- }
-
@Test
public void load_throws_MessageException_if_no_profiles_are_available_for_specified_project() throws IOException {
prepareCallWithEmptyResults();
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
-import org.sonar.scanner.bootstrap.ProcessedScannerProperties;
+import org.sonar.scanner.bootstrap.ScannerProperties;
import org.sonar.scanner.scan.branch.BranchConfiguration;
import static java.util.Collections.emptyMap;
private ProjectRepositories project;
private ProjectRepositoriesLoader loader = mock(ProjectRepositoriesLoader.class);
- private ProcessedScannerProperties props = mock(ProcessedScannerProperties.class);
+ private ScannerProperties props = mock(ScannerProperties.class);
private BranchConfiguration branchConfiguration = mock(BranchConfiguration.class);
@Before
import org.junit.Test;
import org.sonar.api.utils.DateUtils;
import org.sonar.api.utils.log.LogTester;
-import org.sonar.scanner.bootstrap.ProcessedScannerProperties;
+import org.sonar.scanner.bootstrap.ScannerProperties;
import org.sonar.scanner.rule.QualityProfiles;
import org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile;
private QualityProfilesProvider qualityProfileProvider;
private QualityProfileLoader loader = mock(QualityProfileLoader.class);
- private ProcessedScannerProperties props = mock(ProcessedScannerProperties.class);
+ private ScannerProperties props = mock(ScannerProperties.class);
private List<QualityProfile> response;
import java.util.Map;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
-import org.sonar.scanner.bootstrap.ProcessedScannerProperties;
+import org.sonar.scanner.bootstrap.ScannerProperties;
import org.sonar.scanner.bootstrap.DefaultScannerWsClient;
import org.sonarqube.ws.Settings;
import org.sonarqube.ws.client.GetRequest;
public class DefaultProjectSettingsLoaderTest {
private DefaultScannerWsClient wsClient = mock(DefaultScannerWsClient.class);
- private ProcessedScannerProperties properties = mock(ProcessedScannerProperties.class);
+ private ScannerProperties properties = mock(ScannerProperties.class);
private DefaultProjectSettingsLoader underTest = new DefaultProjectSettingsLoader(wsClient, properties);
@Test
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2020 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.Optional;
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.scanner.bootstrap.RawScannerProperties;
-
-import static java.util.Optional.of;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class ExternalProjectKeyAndOrganizationProviderTest {
-
- private ExternalProjectKeyAndOrganizationLoader loader = mock(ExternalProjectKeyAndOrganizationLoader.class);
- private RawScannerProperties rawProperties = mock(RawScannerProperties.class);
-
- private ExternalProjectKeyAndOrganizationProvider underTest = new ExternalProjectKeyAndOrganizationProvider();
-
- @Before
- public void setUp() {
- when(loader.load()).thenReturn(of(new ExternalProjectKeyAndOrganization() {
- @Override
- public Optional<String> getProjectKey() {
- return of("some_key");
- }
-
- @Override
- public Optional<String> getOrganization() {
- return of("organization_key");
- }
- }));
- }
-
- @Test
- public void does_nothing_when_key_autodetection_is_disabled() {
- when(rawProperties.property("sonar.keys_autodetection.disabled")).thenReturn("true");
-
- ExternalProjectKeyAndOrganization result = underTest.provide(rawProperties, loader);
-
- assertThat(result).isInstanceOf(EmptyExternalProjectKeyAndOrganization.class);
- }
-
- @Test
- public void by_default_attempts_to_autodetect_keys_if_external_key_loader_detected() {
- when(rawProperties.property("sonar.keys_autodetection.disabled")).thenReturn(null);
-
- ExternalProjectKeyAndOrganization result = underTest.provide(rawProperties, loader);
-
- assertThat(result).isNotInstanceOf(EmptyExternalProjectKeyAndOrganization.class);
- assertThat(result.getProjectKey()).isEqualTo(of("some_key"));
- assertThat(result.getOrganization()).isEqualTo(of("organization_key"));
- }
-
- @Test
- public void by_default_does_nothing_when_no_external_key_loader_detected() {
- when(rawProperties.property("sonar.keys_autodetection.disabled")).thenReturn(null);
-
- ExternalProjectKeyAndOrganization result = underTest.provide(rawProperties, null);
-
- assertThat(result).isInstanceOf(EmptyExternalProjectKeyAndOrganization.class);
- }
-
- @Test
- public void attempts_to_autodetect_keys_if_autodection_is_explicitly_enabled() {
- when(rawProperties.property("sonar.keys_autodetection.disabled")).thenReturn("false");
-
- ExternalProjectKeyAndOrganization result = underTest.provide(rawProperties, loader);
-
- assertThat(result).isNotInstanceOf(EmptyExternalProjectKeyAndOrganization.class);
- assertThat(result.getProjectKey()).isEqualTo(of("some_key"));
- assertThat(result.getOrganization()).isEqualTo(of("organization_key"));
- }
-}
import org.sonar.api.notifications.AnalysisWarnings;
import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.log.LogTester;
-import org.sonar.scanner.bootstrap.ProcessedScannerProperties;
-import org.sonar.scanner.bootstrap.RawScannerProperties;
+import org.sonar.scanner.bootstrap.ScannerProperties;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonMap;
@Test
public void shouldInitRootWorkDir() {
- ProjectReactorBuilder builder = new ProjectReactorBuilder(new ProcessedScannerProperties(
- new RawScannerProperties(emptyMap()), new EmptyExternalProjectKeyAndOrganization()),
+ ProjectReactorBuilder builder = new ProjectReactorBuilder(new ScannerProperties(emptyMap()),
mock(AnalysisWarnings.class));
File baseDir = new File("target/tmp/baseDir");
@Test
public void shouldInitWorkDirWithCustomRelativeFolder() {
Map<String, String> props = singletonMap("sonar.working.directory", ".foo");
- ProjectReactorBuilder builder = new ProjectReactorBuilder(new ProcessedScannerProperties(
- new RawScannerProperties(props),
- new EmptyExternalProjectKeyAndOrganization()),
+ ProjectReactorBuilder builder = new ProjectReactorBuilder(new ScannerProperties(props),
mock(AnalysisWarnings.class));
File baseDir = new File("target/tmp/baseDir");
@Test
public void shouldInitRootWorkDirWithCustomAbsoluteFolder() {
Map<String, String> props = singletonMap("sonar.working.directory", new File("src").getAbsolutePath());
- ProjectReactorBuilder builder = new ProjectReactorBuilder(new ProcessedScannerProperties(
- new RawScannerProperties(props), new EmptyExternalProjectKeyAndOrganization()),
+ ProjectReactorBuilder builder = new ProjectReactorBuilder(new ScannerProperties(props),
mock(AnalysisWarnings.class));
File baseDir = new File("target/tmp/baseDir");
private ProjectDefinition loadProjectDefinition(String projectFolder) {
Map<String, String> props = loadProps(projectFolder);
- ProcessedScannerProperties bootstrapProps = new ProcessedScannerProperties(
- new RawScannerProperties(props),
- new EmptyExternalProjectKeyAndOrganization());
+ ScannerProperties bootstrapProps = new ScannerProperties(props);
ProjectReactor projectReactor = new ProjectReactorBuilder(bootstrapProps, mock(AnalysisWarnings.class)).execute();
return projectReactor.getRoot();
}
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.MessageException;
-import org.sonar.api.batch.fs.internal.DefaultInputProject;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class ScanPropertiesTest {
- private MapSettings settings = new MapSettings();
- private DefaultInputProject project = mock(DefaultInputProject.class);
- private ScanProperties underTest = new ScanProperties(settings.asConfig(), project);
+ private final MapSettings settings = new MapSettings();
+ private final DefaultInputProject project = mock(DefaultInputProject.class);
+ private final ScanProperties underTest = new ScanProperties(settings.asConfig(), project);
@Rule
public TemporaryFolder temp = new TemporaryFolder();
@Test
public void defaults_if_no_setting_defined() {
assertThat(underTest.branch()).isEmpty();
- assertThat(underTest.organizationKey()).isEmpty();
assertThat(underTest.preloadFileMetadata()).isFalse();
assertThat(underTest.shouldKeepReport()).isFalse();
assertThat(underTest.metadataFilePath()).isEqualTo(project.getWorkDir().resolve("report-task.txt"));
underTest.validate();
}
- @Test
- public void should_define_organization_key() {
- settings.setProperty("sonar.organization", "org");
- assertThat(underTest.organizationKey()).isEqualTo(Optional.of("org"));
- }
-
@Test
public void should_define_branch_name() {
settings.setProperty("sonar.branch.name", "name");
import org.junit.Before;
import org.junit.Test;
-import org.sonar.scanner.bootstrap.ProcessedScannerProperties;
+import org.sonar.scanner.bootstrap.ScannerProperties;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
private ProjectBranchesProvider provider = new ProjectBranchesProvider();
private ProjectBranchesLoader mockLoader;
private ProjectBranches mockBranches;
- private ProcessedScannerProperties scannerProperties;
+ private ScannerProperties scannerProperties;
@Before
public void setUp() {
mockLoader = mock(ProjectBranchesLoader.class);
mockBranches = mock(ProjectBranches.class);
- scannerProperties = mock(ProcessedScannerProperties.class);
+ scannerProperties = mock(ScannerProperties.class);
}
import org.junit.Before;
import org.junit.Test;
-import org.sonar.scanner.bootstrap.ProcessedScannerProperties;
+import org.sonar.scanner.bootstrap.ScannerProperties;
import static java.util.Collections.emptyList;
import static org.assertj.core.api.Assertions.assertThat;
private ProjectPullRequestsProvider provider = new ProjectPullRequestsProvider();
private ProjectPullRequestsLoader mockLoader;
private ProjectPullRequests pullRequests;
- private ProcessedScannerProperties scannerProperties;
+ private ScannerProperties scannerProperties;
@Before
public void setUp() {
mockLoader = mock(ProjectPullRequestsLoader.class);
pullRequests = new ProjectPullRequests(emptyList());
- scannerProperties = mock(ProcessedScannerProperties.class);
+ scannerProperties = mock(ScannerProperties.class);
}
@Test
import java.util.Optional;
import javax.annotation.Nullable;
import org.junit.Test;
-import org.sonar.scanner.bootstrap.RawScannerProperties;
+import org.sonar.scanner.bootstrap.ScannerProperties;
import org.sonar.scanner.ci.CiConfiguration;
import org.sonar.scanner.fs.InputModuleHierarchy;
when(scmConfiguration.provider().revisionId(any())).thenThrow(new UnsupportedOperationException("BOOM"));
InputModuleHierarchy moduleHierarchy = mock(InputModuleHierarchy.class, RETURNS_DEEP_STUBS);
- ScmRevisionImpl underTest = new ScmRevisionImpl(ciConfiguration, new RawScannerProperties(scannerConfiguration), scmConfiguration, moduleHierarchy);
+ ScmRevisionImpl underTest = new ScmRevisionImpl(ciConfiguration, new ScannerProperties(scannerConfiguration), scmConfiguration, moduleHierarchy);
assertThat(underTest.get()).isEmpty();
}
when(scmConfiguration.provider().revisionId(any())).thenReturn(scmValue);
InputModuleHierarchy moduleHierarchy = mock(InputModuleHierarchy.class, RETURNS_DEEP_STUBS);
- ScmRevisionImpl underTest = new ScmRevisionImpl(ciConfiguration, new RawScannerProperties(scannerConfiguration), scmConfiguration, moduleHierarchy);
+ ScmRevisionImpl underTest = new ScmRevisionImpl(ciConfiguration, new ScannerProperties(scannerConfiguration), scmConfiguration, moduleHierarchy);
return underTest.get();
}
}