diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2017-06-29 15:08:28 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2017-07-04 23:47:46 +0200 |
commit | 875e23e29f4ed2d41146d8bba8b22448b23df113 (patch) | |
tree | e100819edca0bc4c2d75adce8ba760f4fef87059 /sonar-scanner-engine | |
parent | d7f436725b0172217ff8156f1425b4a4a702529c (diff) | |
download | sonarqube-875e23e29f4ed2d41146d8bba8b22448b23df113.tar.gz sonarqube-875e23e29f4ed2d41146d8bba8b22448b23df113.zip |
SONAR-9478 Deprecate Settings and introduce new Configuration interface
Diffstat (limited to 'sonar-scanner-engine')
238 files changed, 1431 insertions, 1164 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/Batch.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/Batch.java index 7be87bcc876..07540030654 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/Batch.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/Batch.java @@ -20,7 +20,6 @@ package org.sonar.batch.bootstrapper; import com.google.common.base.Throwables; - import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/LoggingConfiguration.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/LoggingConfiguration.java index e6c54ec7b33..08b3d410625 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/LoggingConfiguration.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/LoggingConfiguration.java @@ -20,7 +20,6 @@ package org.sonar.batch.bootstrapper; import com.google.common.annotations.VisibleForTesting; - import java.util.HashMap; import java.util.Map; import javax.annotation.CheckForNull; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/ProjectAnalysisInfo.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/ProjectAnalysisInfo.java index 06cdd32e607..40d7cbcd3c7 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/ProjectAnalysisInfo.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/ProjectAnalysisInfo.java @@ -20,10 +20,12 @@ package org.sonar.scanner; import java.util.Date; +import java.util.Optional; import org.picocontainer.Startable; import org.sonar.api.CoreProperties; import org.sonar.api.batch.ScannerSide; -import org.sonar.api.config.Settings; +import org.sonar.api.config.Configuration; +import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.SonarException; import org.sonar.api.utils.System2; @@ -33,12 +35,12 @@ import org.sonar.api.utils.System2; @ScannerSide public class ProjectAnalysisInfo implements Startable { private final System2 system2; - private Settings settings; + private Configuration settings; private Date analysisDate; private String analysisVersion; - public ProjectAnalysisInfo(Settings settings, System2 system2) { + public ProjectAnalysisInfo(Configuration settings, System2 system2) { this.settings = settings; this.system2 = system2; } @@ -52,23 +54,22 @@ public class ProjectAnalysisInfo implements Startable { } private Date loadAnalysisDate() { + Optional<String> value = settings.get(CoreProperties.PROJECT_DATE_PROPERTY); + if (!value.isPresent()) { + return new Date(system2.now()); + } Date date; try { // sonar.projectDate may have been specified as a time - date = settings.getDateTime(CoreProperties.PROJECT_DATE_PROPERTY); + return DateUtils.parseDateTime(value.get()); } catch (SonarException e) { // this is probably just a date - date = settings.getDate(CoreProperties.PROJECT_DATE_PROPERTY); - } - if (date == null) { - date = new Date(system2.now()); - settings.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, date, true); + return DateUtils.parseDate(value.get()); } - return date; } private String loadAnalysisVersion() { - return settings.getString(CoreProperties.PROJECT_VERSION_PROPERTY); + return settings.get(CoreProperties.PROJECT_VERSION_PROPERTY).orElse(null); } @Override diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/AnalysisTempFolderProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/AnalysisTempFolderProvider.java index a43de6ee699..dc4a860533c 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/AnalysisTempFolderProvider.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/AnalysisTempFolderProvider.java @@ -19,17 +19,16 @@ */ package org.sonar.scanner.analysis; -import org.sonar.api.batch.bootstrap.ProjectReactor; -import org.picocontainer.PicoContainer; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import org.picocontainer.ComponentLifecycle; +import org.picocontainer.PicoContainer; import org.picocontainer.injectors.ProviderAdapter; +import org.sonar.api.batch.bootstrap.ProjectReactor; import org.sonar.api.utils.TempFolder; import org.sonar.api.utils.internal.DefaultTempFolder; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; - public class AnalysisTempFolderProvider extends ProviderAdapter implements ComponentLifecycle<TempFolder> { static final String TMP_NAME = ".sonartmp"; private DefaultTempFolder projectTempFolder; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/FileCacheProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/FileCacheProvider.java index 359d68547ed..103acf20863 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/FileCacheProvider.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/FileCacheProvider.java @@ -20,16 +20,16 @@ package org.sonar.scanner.bootstrap; import org.picocontainer.injectors.ProviderAdapter; -import org.sonar.api.config.Settings; +import org.sonar.api.config.Configuration; import org.sonar.home.cache.FileCache; import org.sonar.home.cache.FileCacheBuilder; public class FileCacheProvider extends ProviderAdapter { private FileCache cache; - public FileCache provide(Settings settings) { + public FileCache provide(Configuration settings) { if (cache == null) { - String home = settings.getString("sonar.userHome"); + String home = settings.get("sonar.userHome").orElse(null); cache = new FileCacheBuilder(new Slf4jLogger()).setUserHome(home).build(); } return cache; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalConfiguration.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalConfiguration.java new file mode 100644 index 00000000000..336d0ce73ff --- /dev/null +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalConfiguration.java @@ -0,0 +1,64 @@ +/* + * 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 com.google.common.collect.ImmutableMap; +import java.util.Collections; +import java.util.Map; +import javax.annotation.concurrent.Immutable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.sonar.api.CoreProperties; +import org.sonar.api.batch.AnalysisMode; +import org.sonar.api.config.Encryption; +import org.sonar.api.config.PropertyDefinitions; +import org.sonar.scanner.config.DefaultConfiguration; + +@Immutable +public class GlobalConfiguration extends DefaultConfiguration { + + private static final Logger LOG = LoggerFactory.getLogger(GlobalConfiguration.class); + + private static final String JDBC_SPECIFIC_MESSAGE = "It will be ignored. There is no longer any DB connection to the SQ database."; + /** + * A map of dropped properties as key and specific message to display for that property + * (what will happen, what should the user do, ...) as a value + */ + private static final Map<String, String> DROPPED_PROPERTIES = ImmutableMap.of( + "sonar.jdbc.url", JDBC_SPECIFIC_MESSAGE, + "sonar.jdbc.username", JDBC_SPECIFIC_MESSAGE, + "sonar.jdbc.password", JDBC_SPECIFIC_MESSAGE); + + private final Map<String, String> serverSideSettings; + + public GlobalConfiguration(PropertyDefinitions propertyDefinitions, Encryption encryption, AnalysisMode mode, + Map<String, String> settings, Map<String, String> serverSideSettings) { + super(propertyDefinitions, encryption, mode, settings); + this.serverSideSettings = serverSideSettings; + + get(CoreProperties.PERMANENT_SERVER_ID).ifPresent(v -> LOG.info("Server id: {}", v)); + new DroppedPropertyChecker(getProperties(), DROPPED_PROPERTIES).checkDroppedProperties(); + } + + public Map<String, String> getServerSideSettings() { + return Collections.unmodifiableMap(serverSideSettings); + } + +} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalConfigurationProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalConfigurationProvider.java new file mode 100644 index 00000000000..26467a6e5df --- /dev/null +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalConfigurationProvider.java @@ -0,0 +1,45 @@ +/* + * 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.LinkedHashMap; +import java.util.Map; +import org.picocontainer.injectors.ProviderAdapter; +import org.sonar.api.config.PropertyDefinitions; +import org.sonar.scanner.repository.settings.SettingsLoader; + +public class GlobalConfigurationProvider extends ProviderAdapter { + + private GlobalConfiguration globalSettings; + + public GlobalConfiguration provide(SettingsLoader loader, GlobalProperties globalProps, PropertyDefinitions propertyDefinitions, GlobalMode mode) { + if (globalSettings == null) { + + Map<String, String> serverSideSettings = loader.load(null); + + Map<String, String> settings = new LinkedHashMap<>(); + settings.putAll(serverSideSettings); + settings.putAll(globalProps.properties()); + + globalSettings = new GlobalConfiguration(propertyDefinitions, globalProps.getEncryption(), mode, settings, serverSideSettings); + } + return globalSettings; + } +} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalContainer.java index 55ab768d00f..259058a7163 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalContainer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalContainer.java @@ -85,7 +85,8 @@ public class GlobalContainer extends ComponentContainer { new SonarQubeVersion(apiVersion), SonarRuntimeImpl.forSonarQube(apiVersion, SonarQubeSide.SCANNER), StoragesManager.class, - GlobalSettings.class, + MutableGlobalSettings.class, + new GlobalConfigurationProvider(), new ScannerWsClientProvider(), DefaultServer.class, new GlobalTempFolderProvider(), diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalProperties.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalProperties.java index 4dac8f34ec7..d03a67b84ed 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalProperties.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalProperties.java @@ -19,9 +19,8 @@ */ package org.sonar.scanner.bootstrap; -import org.sonar.api.CoreProperties; - import java.util.Map; +import org.sonar.api.CoreProperties; /** * Immutable batch properties that are not specific to a task (for example diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalSettings.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalSettings.java deleted file mode 100644 index 8955281340a..00000000000 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalSettings.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.scanner.bootstrap; - -import com.google.common.collect.ImmutableMap; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.CoreProperties; -import org.sonar.api.config.Encryption; -import org.sonar.api.config.PropertyDefinitions; -import org.sonar.api.config.Settings; -import org.sonar.api.utils.MessageException; -import org.sonar.scanner.repository.settings.SettingsLoader; - -public class GlobalSettings extends Settings { - - private static final Logger LOG = LoggerFactory.getLogger(GlobalSettings.class); - - private static final String JDBC_SPECIFIC_MESSAGE = "It will be ignored. There is no longer any DB connection to the SQ database."; - /** - * A map of dropped properties as key and specific message to display for that property - * (what will happen, what should the user do, ...) as a value - */ - private static final Map<String, String> DROPPED_PROPERTIES = ImmutableMap.of( - "sonar.jdbc.url", JDBC_SPECIFIC_MESSAGE, - "sonar.jdbc.username", JDBC_SPECIFIC_MESSAGE, - "sonar.jdbc.password", JDBC_SPECIFIC_MESSAGE); - - private final Map<String, String> serverSideSettings; - - private final GlobalProperties bootstrapProps; - private final GlobalMode mode; - private final Map<String, String> properties = new HashMap<>(); - - public GlobalSettings(GlobalProperties bootstrapProps, PropertyDefinitions propertyDefinitions, - SettingsLoader settingsLoader, GlobalMode mode) { - - super(propertyDefinitions, new Encryption(bootstrapProps.property(CoreProperties.ENCRYPTION_SECRET_KEY_PATH))); - this.mode = mode; - this.bootstrapProps = bootstrapProps; - this.serverSideSettings = ImmutableMap.copyOf(settingsLoader.load(null)); - init(); - new DroppedPropertyChecker(this.getProperties(), DROPPED_PROPERTIES).checkDroppedProperties(); - } - - private void init() { - addProperties(serverSideSettings); - addProperties(bootstrapProps.properties()); - - if (hasKey(CoreProperties.PERMANENT_SERVER_ID)) { - LOG.info("Server id: " + getString(CoreProperties.PERMANENT_SERVER_ID)); - } - } - - public Map<String, String> getServerSideSettings() { - return serverSideSettings; - } - - @Override - protected Optional<String> get(String key) { - if (mode.isIssues() && key.endsWith(".secured") && !key.contains(".license")) { - throw MessageException.of("Access to the secured property '" + key - + "' is not possible in issues mode. The SonarQube plugin which requires this property must be deactivated in issues mode."); - } - return Optional.ofNullable(properties.get(key)); - } - - @Override - public Map<String, String> getProperties() { - return properties; - } - - @Override - protected void set(String key, String value) { - properties.put(key, value); - } - - @Override - protected void remove(String key) { - properties.remove(key); - } -} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/MetricProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/MetricProvider.java index 35426aebf5f..b6fbe2485e1 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/MetricProvider.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/MetricProvider.java @@ -20,15 +20,14 @@ package org.sonar.scanner.bootstrap; import com.google.common.collect.Lists; -import org.sonar.api.batch.ScannerSide; +import java.util.List; import org.sonar.api.ExtensionProvider; import org.sonar.api.batch.InstantiationStrategy; +import org.sonar.api.batch.ScannerSide; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Metric; import org.sonar.api.measures.Metrics; -import java.util.List; - @ScannerSide @InstantiationStrategy(InstantiationStrategy.PER_BATCH) public class MetricProvider extends ExtensionProvider { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/MutableGlobalSettings.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/MutableGlobalSettings.java new file mode 100644 index 00000000000..e31ce436394 --- /dev/null +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/MutableGlobalSettings.java @@ -0,0 +1,67 @@ +/* + * 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 java.util.Optional; +import org.sonar.api.batch.AnalysisMode; +import org.sonar.api.config.Settings; +import org.sonar.api.utils.MessageException; + +/** + * @deprecated since 6.5 {@link GlobalConfiguration} used to be mutable, so keep a mutable copy for backward compatibility. + */ +@Deprecated +public class MutableGlobalSettings extends Settings { + + private final AnalysisMode mode; + private final Map<String, String> mutableProperties = new HashMap<>(); + + public MutableGlobalSettings(GlobalConfiguration globalSettings) { + super(globalSettings.getDefinitions(), globalSettings.getEncryption()); + this.mutableProperties.putAll(globalSettings.getProperties()); + this.mode = globalSettings.getMode(); + } + + @Override + protected Optional<String> get(String key) { + if (mode.isIssues() && key.endsWith(".secured") && !key.contains(".license")) { + throw MessageException.of("Access to the secured property '" + key + + "' is not possible in issues mode. The SonarQube plugin which requires this property must be deactivated in issues mode."); + } + return Optional.ofNullable(mutableProperties.get(key)); + } + + @Override + public Map<String, String> getProperties() { + return mutableProperties; + } + + @Override + protected void set(String key, String value) { + mutableProperties.put(key, value); + } + + @Override + protected void remove(String key) { + mutableProperties.remove(key); + } +} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerExtensionDictionnary.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerExtensionDictionnary.java index 705b3cc4560..70749f70fc0 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerExtensionDictionnary.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerExtensionDictionnary.java @@ -29,7 +29,6 @@ import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.stream.Collectors; - import javax.annotation.Nullable; import org.apache.commons.lang.ClassUtils; import org.sonar.api.batch.CheckProject; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginJarExploder.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginJarExploder.java index 733048345ca..4fcf68ca918 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginJarExploder.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginJarExploder.java @@ -19,18 +19,17 @@ */ package org.sonar.scanner.bootstrap; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; import org.apache.commons.io.FileUtils; import org.sonar.api.batch.ScannerSide; import org.sonar.api.utils.ZipUtils; import org.sonar.core.platform.ExplodedPlugin; -import org.sonar.core.platform.PluginJarExploder; import org.sonar.core.platform.PluginInfo; +import org.sonar.core.platform.PluginJarExploder; import org.sonar.home.cache.FileCache; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; - import static org.sonar.core.util.FileUtils.deleteQuietly; @ScannerSide diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginPredicate.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginPredicate.java index 438bfda8b8c..befc42c1ea0 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginPredicate.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginPredicate.java @@ -22,20 +22,17 @@ package org.sonar.scanner.bootstrap; import com.google.common.base.Joiner; import com.google.common.base.Predicate; import com.google.common.base.Splitter; - import java.util.List; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.StreamSupport; - import javax.annotation.Nonnull; - -import org.apache.commons.lang.StringUtils; import org.sonar.api.CoreProperties; import org.sonar.api.batch.ScannerSide; -import org.sonar.api.config.Settings; +import org.sonar.api.config.Configuration; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; + import static com.google.common.collect.Sets.newHashSet; /** @@ -53,7 +50,7 @@ public class ScannerPluginPredicate implements Predicate<String> { private final Set<String> blacks = newHashSet(); private final GlobalMode mode; - public ScannerPluginPredicate(Settings settings, GlobalMode mode) { + public ScannerPluginPredicate(Configuration settings, GlobalMode mode) { this.mode = mode; if (mode.isPreview() || mode.isIssues()) { // These default values are not supported by Settings because the class CorePlugin @@ -92,8 +89,8 @@ public class ScannerPluginPredicate implements Predicate<String> { return blacks; } - private static List<String> propertyValues(Settings settings, String key, String defaultValue) { - String s = StringUtils.defaultIfEmpty(settings.getString(key), defaultValue); + private static List<String> propertyValues(Configuration settings, String key, String defaultValue) { + String s = settings.get(key).orElse(defaultValue); return StreamSupport.stream(Splitter.on(",").trimResults().omitEmptyStrings().split(s).spliterator(), false) .collect(Collectors.toList()); } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginRepository.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginRepository.java index 2065bb63755..06b6482500c 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginRepository.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginRepository.java @@ -23,9 +23,7 @@ import com.google.common.base.Preconditions; import java.util.Collection; import java.util.HashMap; import java.util.Map; - import javax.annotation.CheckForNull; - import org.picocontainer.Startable; import org.sonar.api.Plugin; import org.sonar.api.utils.log.Logger; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/UserProperties.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/UserProperties.java index 5de66cf665f..c6e4d8d77c3 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/UserProperties.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/UserProperties.java @@ -19,12 +19,10 @@ */ package org.sonar.scanner.bootstrap; -import org.sonar.api.config.Encryption; - -import javax.annotation.Nullable; - import java.util.HashMap; import java.util.Map; +import javax.annotation.Nullable; +import org.sonar.api.config.Encryption; /** * Properties that are coming from bootstrapper. @@ -51,6 +49,10 @@ public abstract class UserProperties { this.properties = decryptedProps; } + public Encryption getEncryption() { + return encryption; + } + public Map<String, String> properties() { return properties; } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/config/CsvParser.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/config/CsvParser.java new file mode 100644 index 00000000000..efdfc5bccdb --- /dev/null +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/config/CsvParser.java @@ -0,0 +1,105 @@ +/* + * 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.config; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; + +public class CsvParser { + + public static String[] parseLine(String line) { + List<String> result = new ArrayList<>(); + + AtomicInteger i = new AtomicInteger(0); + while (true) { + String cell = parseNextCell(line, i); + if (cell == null) + break; + result.add(cell); + } + + return result.toArray(new String[0]); + } + + // returns iterator after delimiter or after end of string + private static String parseNextCell(String line, AtomicInteger i) { + if (i.get() >= line.length()) + return null; + + if (line.charAt(i.get()) != '"') + return parseNotEscapedCell(line, i); + else + return parseEscapedCell(line, i); + } + + // returns iterator after delimiter or after end of string + private static String parseNotEscapedCell(String line, AtomicInteger i) { + StringBuilder sb = new StringBuilder(); + while (true) { + if (i.get() >= line.length()) { + // return iterator after end of string + break; + } + if (line.charAt(i.get()) == ',') { + // return iterator after delimiter + i.incrementAndGet(); + break; + } + sb.append(line.charAt(i.get())); + i.incrementAndGet(); + } + return sb.toString(); + } + + // returns iterator after delimiter or after end of string + private static String parseEscapedCell(String line, AtomicInteger i) { + i.incrementAndGet(); // omit first character (quotation mark) + StringBuilder sb = new StringBuilder(); + while (true) { + if (i.get() >= line.length()) { + break; + } + if (line.charAt(i.get()) == '"') { + i.incrementAndGet(); // we're more interested in the next character + if (i.get() >= line.length()) { + // quotation mark was closing cell + // return iterator after end of string + break; + } + if (line.charAt(i.get()) == ',') { + // quotation mark was closing cell + // return iterator after delimiter + i.incrementAndGet(); + break; + } + if (line.charAt(i.get()) == '"') { + // it was doubled (escaped) quotation mark + // do nothing -- we've already skipped first quotation mark + } + + } + sb.append(line.charAt(i.get())); + i.incrementAndGet(); + } + + return sb.toString(); + } +} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/config/DefaultConfiguration.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/config/DefaultConfiguration.java new file mode 100644 index 00000000000..35d9ac9b683 --- /dev/null +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/config/DefaultConfiguration.java @@ -0,0 +1,125 @@ +/* + * 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.config; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import javax.annotation.concurrent.Immutable; +import org.apache.commons.lang.ArrayUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +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.PropertyDefinitions; +import org.sonar.api.utils.MessageException; + +import static java.util.Objects.requireNonNull; +import static org.apache.commons.lang.StringUtils.trim; + +@Immutable +public abstract class DefaultConfiguration implements Configuration { + + private static final Logger LOG = LoggerFactory.getLogger(DefaultConfiguration.class); + + private final PropertyDefinitions definitions; + private final Encryption encryption; + private final AnalysisMode mode; + private final Map<String, String> properties = new HashMap<>(); + + public DefaultConfiguration(PropertyDefinitions propertyDefinitions, Encryption encryption, AnalysisMode mode, Map<String, String> props) { + this.definitions = requireNonNull(propertyDefinitions); + this.encryption = encryption; + this.mode = mode; + props.forEach((k, v) -> { + String validKey = definitions.validKey(k); + properties.put(validKey, trim(v)); + }); + } + + public AnalysisMode getMode() { + return mode; + } + + public Encryption getEncryption() { + return encryption; + } + + public PropertyDefinitions getDefinitions() { + return definitions; + } + + public Map<String, String> getProperties() { + return Collections.unmodifiableMap(properties); + } + + @Override + public boolean hasKey(String key) { + return properties.containsKey(key); + } + + @Override + public Optional<String> get(String key) { + String effectiveKey = definitions.validKey(key); + PropertyDefinition def = definitions.get(effectiveKey); + if (def != null && def.multiValues()) { + LOG.warn("Access to the multi-valued property '{}' should be made using 'getStringArray' method. The SonarQube plugin using this property should be updated."); + } + return getInternal(effectiveKey); + } + + @Override + public String[] getStringArray(String key) { + String effectiveKey = definitions.validKey(key); + PropertyDefinition def = definitions.get(effectiveKey); + if (def != null && !def.multiValues()) { + LOG.warn("Property '{}' is not declared as multi-valued but was read using 'getStringArray' method. The SonarQube plugin declaring this property should be updated."); + } + Optional<String> value = getInternal(key); + if (value.isPresent()) { + return CsvParser.parseLine(value.get()); + } + return ArrayUtils.EMPTY_STRING_ARRAY; + } + + private Optional<String> getInternal(String key) { + if (mode.isIssues() && key.endsWith(".secured") && !key.contains(".license")) { + throw MessageException.of("Access to the secured property '" + key + + "' is not possible in issues mode. The SonarQube plugin which requires this property must be deactivated in issues mode."); + } + Optional<String> value = Optional.ofNullable(properties.get(key)); + if (!value.isPresent()) { + // default values cannot be encrypted, so return value as-is. + return Optional.ofNullable(definitions.getDefaultValue(key)); + } + if (encryption.isEncrypted(value.get())) { + try { + return Optional.of(encryption.decrypt(value.get())); + } catch (Exception e) { + throw new IllegalStateException("Fail to decrypt the property " + key + ". Please check your secret key.", e); + } + } + return value; + } + +} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/config/package-info.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/config/package-info.java new file mode 100644 index 00000000000..f39bb549c0f --- /dev/null +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/config/package-info.java @@ -0,0 +1,23 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +@ParametersAreNonnullByDefault +package org.sonar.scanner.config; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/CpdExecutor.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/CpdExecutor.java index 0b964bb62de..87a0794c1e5 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/CpdExecutor.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/CpdExecutor.java @@ -30,11 +30,10 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; - import org.sonar.api.batch.fs.InputComponent; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.DefaultInputComponent; -import org.sonar.api.config.Settings; +import org.sonar.api.config.Configuration; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; import org.sonar.duplications.block.Block; @@ -67,12 +66,12 @@ public class CpdExecutor { private final SonarCpdBlockIndex index; private final ReportPublisher publisher; private final InputComponentStore componentStore; - private final Settings settings; + private final Configuration settings; private final ProgressReport progressReport; private int count; private int total; - public CpdExecutor(Settings settings, SonarCpdBlockIndex index, ReportPublisher publisher, InputComponentStore inputComponentCache) { + public CpdExecutor(Configuration settings, SonarCpdBlockIndex index, ReportPublisher publisher, InputComponentStore inputComponentCache) { this.settings = settings; this.index = index; this.publisher = publisher; @@ -157,12 +156,7 @@ public class CpdExecutor { * @return */ int getMinimumTokens(String languageKey) { - int minimumTokens = settings.getInt("sonar.cpd." + languageKey + ".minimumTokens"); - if (minimumTokens == 0) { - minimumTokens = 100; - } - - return minimumTokens; + return settings.getInt("sonar.cpd." + languageKey + ".minimumTokens").orElse(100); } @VisibleForTesting diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/DuplicationPredicates.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/DuplicationPredicates.java index 033b8f59855..f04f407d86e 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/DuplicationPredicates.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/DuplicationPredicates.java @@ -20,9 +20,8 @@ package org.sonar.scanner.cpd; import com.google.common.base.Predicate; -import org.sonar.duplications.index.CloneGroup; - import javax.annotation.Nullable; +import org.sonar.duplications.index.CloneGroup; public final class DuplicationPredicates { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/deprecated/CpdMappings.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/deprecated/CpdMappings.java index c88c32124d2..741f3046bc4 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/deprecated/CpdMappings.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/deprecated/CpdMappings.java @@ -19,10 +19,9 @@ */ package org.sonar.scanner.cpd.deprecated; -import org.sonar.api.batch.ScannerSide; -import org.sonar.api.batch.CpdMapping; - import javax.annotation.CheckForNull; +import org.sonar.api.batch.CpdMapping; +import org.sonar.api.batch.ScannerSide; @ScannerSide public class CpdMappings { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/deprecated/DefaultCpdBlockIndexer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/deprecated/DefaultCpdBlockIndexer.java index 587a88a7f16..88357968eb8 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/deprecated/DefaultCpdBlockIndexer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/deprecated/DefaultCpdBlockIndexer.java @@ -30,7 +30,7 @@ import org.sonar.api.batch.fs.FilePredicates; import org.sonar.api.batch.fs.FileSystem; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.config.Settings; +import org.sonar.api.config.Configuration; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; import org.sonar.duplications.block.Block; @@ -43,10 +43,10 @@ public class DefaultCpdBlockIndexer extends CpdBlockIndexer { private final CpdMappings mappings; private final FileSystem fs; - private final Settings settings; + private final Configuration settings; private final SonarCpdBlockIndex index; - public DefaultCpdBlockIndexer(CpdMappings mappings, FileSystem fs, Settings settings, SonarCpdBlockIndex index) { + public DefaultCpdBlockIndexer(CpdMappings mappings, FileSystem fs, Configuration settings, SonarCpdBlockIndex index) { this.mappings = mappings; this.fs = fs; this.settings = settings; @@ -100,11 +100,7 @@ public class DefaultCpdBlockIndexer extends CpdBlockIndexer { @VisibleForTesting int getBlockSize(String languageKey) { - int blockSize = settings.getInt("sonar.cpd." + languageKey + ".minimumLines"); - if (blockSize == 0) { - blockSize = getDefaultBlockSize(languageKey); - } - return blockSize; + return settings.getInt("sonar.cpd." + languageKey + ".minimumLines").orElse(getDefaultBlockSize(languageKey)); } @VisibleForTesting diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/deprecated/JavaCpdBlockIndexer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/deprecated/JavaCpdBlockIndexer.java index fc0e105d2c1..3b10cd613e8 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/deprecated/JavaCpdBlockIndexer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/deprecated/JavaCpdBlockIndexer.java @@ -31,7 +31,7 @@ import org.sonar.api.batch.fs.FilePredicates; import org.sonar.api.batch.fs.FileSystem; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.config.Settings; +import org.sonar.api.config.Configuration; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; import org.sonar.duplications.block.Block; @@ -50,10 +50,10 @@ public class JavaCpdBlockIndexer extends CpdBlockIndexer { private static final int BLOCK_SIZE = 10; private final FileSystem fs; - private final Settings settings; + private final Configuration settings; private final SonarCpdBlockIndex index; - public JavaCpdBlockIndexer(FileSystem fs, Settings settings, SonarCpdBlockIndex index) { + public JavaCpdBlockIndexer(FileSystem fs, Configuration settings, SonarCpdBlockIndex index) { this.fs = fs; this.settings = settings; this.index = index; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/index/SonarCpdBlockIndex.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/index/SonarCpdBlockIndex.java index 84c7d92371f..2a4cdf9eab0 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/index/SonarCpdBlockIndex.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/index/SonarCpdBlockIndex.java @@ -24,11 +24,10 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Set; import java.util.stream.Collectors; -import org.apache.commons.lang.StringUtils; import org.sonar.api.CoreProperties; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.config.Settings; +import org.sonar.api.config.Configuration; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; import org.sonar.duplications.block.Block; @@ -45,11 +44,11 @@ public class SonarCpdBlockIndex extends AbstractCloneIndex { private static final Logger LOG = Loggers.get(SonarCpdBlockIndex.class); private final CloneIndex mem = new PackedMemoryCloneIndex(); private final ReportPublisher publisher; - private final Settings settings; + private final Configuration settings; // Files already tokenized private final Set<InputFile> indexedFiles = new HashSet<>(); - public SonarCpdBlockIndex(ReportPublisher publisher, Settings settings) { + public SonarCpdBlockIndex(ReportPublisher publisher, Configuration settings) { this.publisher = publisher; this.settings = settings; } @@ -88,10 +87,10 @@ public class SonarCpdBlockIndex extends AbstractCloneIndex { return indexedFiles.contains(inputFile); } - public static boolean isCrossProjectDuplicationEnabled(Settings settings) { - return settings.getBoolean(CoreProperties.CPD_CROSS_PROJECT) + public static boolean isCrossProjectDuplicationEnabled(Configuration settings) { + return settings.getBoolean(CoreProperties.CPD_CROSS_PROJECT).orElse(false) // No cross project duplication for branches - && StringUtils.isBlank(settings.getString(CoreProperties.PROJECT_BRANCH_PROPERTY)); + && !settings.get(CoreProperties.PROJECT_BRANCH_PROPERTY).isPresent(); } public Collection<Block> getByInputFile(String resourceKey) { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/DeprecatedSensorContext.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/DeprecatedSensorContext.java index 40975c8538a..3679fa3fd1a 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/DeprecatedSensorContext.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/DeprecatedSensorContext.java @@ -31,7 +31,7 @@ import org.sonar.api.batch.fs.InputModule; import org.sonar.api.batch.fs.InputPath; import org.sonar.api.batch.rule.ActiveRules; import org.sonar.api.batch.sensor.internal.SensorStorage; -import org.sonar.api.config.Settings; +import org.sonar.api.config.Configuration; import org.sonar.api.design.Dependency; import org.sonar.api.measures.Measure; import org.sonar.api.measures.MeasuresFilter; @@ -46,9 +46,9 @@ public class DeprecatedSensorContext extends DefaultSensorContext implements Sen private final DefaultIndex index; private final InputModule module; - public DeprecatedSensorContext(InputModule module, DefaultIndex index, Settings settings, FileSystem fs, ActiveRules activeRules, + public DeprecatedSensorContext(InputModule module, DefaultIndex index, Configuration config, org.sonar.api.config.Settings mutableSettings, FileSystem fs, ActiveRules activeRules, AnalysisMode analysisMode, SensorStorage sensorStorage, SonarRuntime sonarRuntime) { - super(module, settings, fs, activeRules, analysisMode, sensorStorage, sonarRuntime); + super(module, config, mutableSettings, fs, activeRules, analysisMode, sensorStorage, sonarRuntime); this.index = index; this.module = module; } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/perspectives/ScannerPerspectives.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/perspectives/ScannerPerspectives.java index c4f17972835..3fe37dcf3c4 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/perspectives/ScannerPerspectives.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/perspectives/ScannerPerspectives.java @@ -22,7 +22,6 @@ package org.sonar.scanner.deprecated.perspectives; import com.google.common.collect.Maps; import java.util.Map; import javax.annotation.CheckForNull; - import org.sonar.api.batch.fs.InputComponent; import org.sonar.api.batch.fs.InputPath; import org.sonar.api.batch.fs.internal.DefaultInputModule; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/events/EventBus.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/events/EventBus.java index ac2a5b4d5e8..9237786f4a6 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/events/EventBus.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/events/EventBus.java @@ -19,10 +19,9 @@ */ package org.sonar.scanner.events; -import org.sonar.api.batch.events.EventHandler; - import java.util.ArrayList; import java.util.List; +import org.sonar.api.batch.events.EventHandler; /** * Dispatches {@link BatchEvent}s. Eases decoupling by allowing objects to interact without having direct dependencies upon one another, and diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericCoverageSensor.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericCoverageSensor.java index a0ae6f40108..cf0158cb718 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericCoverageSensor.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericCoverageSensor.java @@ -29,8 +29,8 @@ import org.sonar.api.batch.Initializer; import org.sonar.api.batch.sensor.Sensor; import org.sonar.api.batch.sensor.SensorContext; import org.sonar.api.batch.sensor.SensorDescriptor; +import org.sonar.api.config.Configuration; import org.sonar.api.config.PropertyDefinition; -import org.sonar.api.config.Settings; import org.sonar.api.resources.Qualifiers; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; @@ -63,9 +63,9 @@ public class GenericCoverageSensor extends Initializer implements Sensor { @Deprecated static final String OLD_OVERALL_COVERAGE_REPORT_PATHS_PROPERTY_KEY = "sonar.genericcoverage.overallReportPaths"; - private final Settings settings; + private final Configuration settings; - public GenericCoverageSensor(Settings settings) { + public GenericCoverageSensor(Configuration settings) { this.settings = settings; } @@ -95,7 +95,7 @@ public class GenericCoverageSensor extends Initializer implements Sensor { loadDeprecated(reportPaths, OLD_IT_COVERAGE_REPORT_PATHS_PROPERTY_KEY); loadDeprecated(reportPaths, OLD_OVERALL_COVERAGE_REPORT_PATHS_PROPERTY_KEY); if (!reportPaths.isEmpty()) { - settings.setProperty(REPORT_PATHS_PROPERTY_KEY, reportPaths.stream().collect(Collectors.joining(","))); + // settings.setProperty(REPORT_PATHS_PROPERTY_KEY, reportPaths.stream().collect(Collectors.joining(","))); } } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/index/DefaultIndex.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/index/DefaultIndex.java index 0848af1f9cb..1690a8a44be 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/index/DefaultIndex.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/index/DefaultIndex.java @@ -22,9 +22,7 @@ package org.sonar.scanner.index; import java.util.ArrayList; import java.util.Collection; import java.util.stream.Collectors; - import javax.annotation.CheckForNull; - import org.sonar.api.batch.fs.InputComponent; import org.sonar.api.batch.fs.InputDir; import org.sonar.api.batch.fs.InputFile; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultIssueCallback.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultIssueCallback.java index e1c8531e6b9..ca0c2cad15e 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultIssueCallback.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultIssueCallback.java @@ -19,11 +19,10 @@ */ package org.sonar.scanner.issue; -import org.sonar.api.rule.RuleKey; -import org.sonar.batch.bootstrapper.IssueListener; import org.sonar.api.batch.rule.Rule; import org.sonar.api.batch.rule.Rules; - +import org.sonar.api.rule.RuleKey; +import org.sonar.batch.bootstrapper.IssueListener; import org.sonar.scanner.issue.tracking.TrackedIssue; public class DefaultIssueCallback implements IssueCallback { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultIssueFilterChain.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultIssueFilterChain.java index 1895942e71a..d0f01cc432d 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultIssueFilterChain.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultIssueFilterChain.java @@ -19,13 +19,11 @@ */ package org.sonar.scanner.issue; -import org.sonar.api.scan.issue.filter.IssueFilter; - import java.util.Arrays; import java.util.Collections; import java.util.List; - import org.sonar.api.scan.issue.filter.FilterableIssue; +import org.sonar.api.scan.issue.filter.IssueFilter; import org.sonar.api.scan.issue.filter.IssueFilterChain; public class DefaultIssueFilterChain implements IssueFilterChain { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultProjectIssues.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultProjectIssues.java index 5714296a661..6a0c6bcee3b 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultProjectIssues.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultProjectIssues.java @@ -19,15 +19,13 @@ */ package org.sonar.scanner.issue; -import org.sonar.api.issue.Issue; -import org.sonar.api.issue.ProjectIssues; -import org.sonar.scanner.issue.tracking.TrackedIssue; - import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.StreamSupport; - import javax.annotation.Nullable; +import org.sonar.api.issue.Issue; +import org.sonar.api.issue.ProjectIssues; +import org.sonar.scanner.issue.tracking.TrackedIssue; /** * Expose list of issues for the current project diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DeprecatedIssueAdapterForFilter.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DeprecatedIssueAdapterForFilter.java index daae355a0e9..4b45945147e 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DeprecatedIssueAdapterForFilter.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DeprecatedIssueAdapterForFilter.java @@ -24,7 +24,6 @@ import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Map; - import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.issue.Issue; import org.sonar.api.issue.IssueComment; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DeprecatedIssueFilterChain.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DeprecatedIssueFilterChain.java index 9931d75d932..9b25e4b6a71 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DeprecatedIssueFilterChain.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DeprecatedIssueFilterChain.java @@ -19,13 +19,12 @@ */ package org.sonar.scanner.issue; -import org.sonar.api.issue.Issue; -import org.sonar.api.issue.batch.IssueFilter; -import org.sonar.api.issue.batch.IssueFilterChain; - import java.util.Arrays; import java.util.Collections; import java.util.List; +import org.sonar.api.issue.Issue; +import org.sonar.api.issue.batch.IssueFilter; +import org.sonar.api.issue.batch.IssueFilterChain; /** * @deprecated since 5.3 diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssueCache.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssueCache.java index dd5165a9432..2d67ab22c5b 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssueCache.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssueCache.java @@ -19,11 +19,11 @@ */ package org.sonar.scanner.issue; +import java.util.Collection; import org.sonar.api.batch.ScannerSide; import org.sonar.scanner.issue.tracking.TrackedIssue; import org.sonar.scanner.storage.Storage; import org.sonar.scanner.storage.Storages; -import java.util.Collection; /** * Shared issues among all project modules diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssueFilters.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssueFilters.java index bc630a725e1..db9105a3f90 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssueFilters.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssueFilters.java @@ -19,15 +19,14 @@ */ package org.sonar.scanner.issue; -import org.sonar.api.scan.issue.filter.FilterableIssue; - -import org.sonar.api.scan.issue.filter.IssueFilterChain; -import org.sonar.scanner.ProjectAnalysisInfo; -import org.sonar.scanner.protocol.output.ScannerReport; import org.sonar.api.batch.ScannerSide; import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.issue.Issue; +import org.sonar.api.scan.issue.filter.FilterableIssue; import org.sonar.api.scan.issue.filter.IssueFilter; +import org.sonar.api.scan.issue.filter.IssueFilterChain; +import org.sonar.scanner.ProjectAnalysisInfo; +import org.sonar.scanner.protocol.output.ScannerReport; @ScannerSide public class IssueFilters { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ModuleIssues.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ModuleIssues.java index 958b1e63843..874e4514cf9 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ModuleIssues.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ModuleIssues.java @@ -20,7 +20,6 @@ package org.sonar.scanner.issue; import com.google.common.base.Strings; - import org.sonar.api.batch.fs.TextRange; import org.sonar.api.batch.fs.internal.DefaultInputComponent; import org.sonar.api.batch.rule.ActiveRule; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/EnforceIssuesFilter.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/EnforceIssuesFilter.java index 5c6e4caf409..66efeb194f3 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/EnforceIssuesFilter.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/EnforceIssuesFilter.java @@ -19,14 +19,12 @@ */ package org.sonar.scanner.issue.ignore; -import org.sonar.api.batch.fs.InputComponent; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.scan.issue.filter.FilterableIssue; - import javax.annotation.CheckForNull; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.sonar.api.batch.fs.InputComponent; +import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.scan.issue.filter.FilterableIssue; import org.sonar.api.scan.issue.filter.IssueFilter; import org.sonar.api.scan.issue.filter.IssueFilterChain; import org.sonar.scanner.issue.ignore.pattern.IssueInclusionPatternInitializer; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/IgnoreIssuesFilter.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/IgnoreIssuesFilter.java index 0c543eab505..23c02f54f85 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/IgnoreIssuesFilter.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/IgnoreIssuesFilter.java @@ -19,9 +19,9 @@ */ package org.sonar.scanner.issue.ignore; -import org.sonar.api.scan.issue.filter.FilterableIssue; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.sonar.api.scan.issue.filter.FilterableIssue; import org.sonar.api.scan.issue.filter.IssueFilter; import org.sonar.api.scan.issue.filter.IssueFilterChain; import org.sonar.scanner.issue.ignore.pattern.IssuePattern; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/AbstractPatternInitializer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/AbstractPatternInitializer.java index b77a921e27f..9f6be8dd774 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/AbstractPatternInitializer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/AbstractPatternInitializer.java @@ -20,27 +20,26 @@ package org.sonar.scanner.issue.ignore.pattern; import com.google.common.annotations.VisibleForTesting; -import org.apache.commons.lang.StringUtils; -import org.sonar.api.batch.ScannerSide; -import org.sonar.api.config.Settings; - import java.util.ArrayList; import java.util.List; import java.util.Set; +import org.apache.commons.lang.StringUtils; +import org.sonar.api.batch.ScannerSide; +import org.sonar.api.config.Configuration; import static com.google.common.base.MoreObjects.firstNonNull; @ScannerSide public abstract class AbstractPatternInitializer { - private Settings settings; + private Configuration settings; private List<IssuePattern> multicriteriaPatterns; - protected AbstractPatternInitializer(Settings settings) { + protected AbstractPatternInitializer(Configuration settings) { this.settings = settings; initPatterns(); } - protected Settings getSettings() { + protected Configuration getSettings() { return settings; } @@ -60,11 +59,10 @@ public abstract class AbstractPatternInitializer { protected final void initPatterns() { // Patterns Multicriteria multicriteriaPatterns = new ArrayList<>(); - String patternConf = StringUtils.defaultIfBlank(settings.getString(getMulticriteriaConfigurationKey()), ""); - for (String id : StringUtils.split(patternConf, ',')) { + for (String id : settings.getStringArray(getMulticriteriaConfigurationKey())) { String propPrefix = getMulticriteriaConfigurationKey() + "." + id + "."; - String resourceKeyPattern = settings.getString(propPrefix + "resourceKey"); - String ruleKeyPattern = settings.getString(propPrefix + "ruleKey"); + String resourceKeyPattern = settings.get(propPrefix + "resourceKey").orElse(null); + String ruleKeyPattern = settings.get(propPrefix + "ruleKey").orElse(null); String lineRange = "*"; String[] fields = new String[] {resourceKeyPattern, ruleKeyPattern, lineRange}; PatternDecoder.checkRegularLineConstraints(StringUtils.join(fields, ","), fields); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/IssueExclusionPatternInitializer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/IssueExclusionPatternInitializer.java index 37d16ef51c5..bbb12afb905 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/IssueExclusionPatternInitializer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/IssueExclusionPatternInitializer.java @@ -19,13 +19,12 @@ */ package org.sonar.scanner.issue.ignore.pattern; -import org.apache.commons.lang.StringUtils; -import org.sonar.api.config.Settings; -import org.sonar.core.config.IssueExclusionProperties; - import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.apache.commons.lang.StringUtils; +import org.sonar.api.config.Configuration; +import org.sonar.core.config.IssueExclusionProperties; import static com.google.common.base.Strings.nullToEmpty; @@ -34,7 +33,7 @@ public class IssueExclusionPatternInitializer extends AbstractPatternInitializer private List<BlockIssuePattern> blockPatterns; private List<String> allFilePatterns; - public IssueExclusionPatternInitializer(Settings settings) { + public IssueExclusionPatternInitializer(Configuration settings) { super(settings); loadFileContentPatterns(); } @@ -52,11 +51,10 @@ public class IssueExclusionPatternInitializer extends AbstractPatternInitializer private final void loadFileContentPatterns() { // Patterns Block blockPatterns = new ArrayList<>(); - String patternConf = StringUtils.defaultIfBlank(getSettings().getString(IssueExclusionProperties.PATTERNS_BLOCK_KEY), ""); - for (String id : StringUtils.split(patternConf, ',')) { + for (String id : getSettings().getStringArray(IssueExclusionProperties.PATTERNS_BLOCK_KEY)) { String propPrefix = IssueExclusionProperties.PATTERNS_BLOCK_KEY + "." + id + "."; - String beginBlockRegexp = getSettings().getString(propPrefix + IssueExclusionProperties.BEGIN_BLOCK_REGEXP); - String endBlockRegexp = getSettings().getString(propPrefix + IssueExclusionProperties.END_BLOCK_REGEXP); + String beginBlockRegexp = getSettings().get(propPrefix + IssueExclusionProperties.BEGIN_BLOCK_REGEXP).orElse(null); + String endBlockRegexp = getSettings().get(propPrefix + IssueExclusionProperties.END_BLOCK_REGEXP).orElse(null); String[] fields = new String[] {beginBlockRegexp, endBlockRegexp}; PatternDecoder.checkDoubleRegexpLineConstraints(StringUtils.join(fields, ","), fields); BlockIssuePattern pattern = new BlockIssuePattern(nullToEmpty(beginBlockRegexp), nullToEmpty(endBlockRegexp)); @@ -66,10 +64,9 @@ public class IssueExclusionPatternInitializer extends AbstractPatternInitializer // Patterns All File allFilePatterns = new ArrayList<>(); - patternConf = StringUtils.defaultIfBlank(getSettings().getString(IssueExclusionProperties.PATTERNS_ALLFILE_KEY), ""); - for (String id : StringUtils.split(patternConf, ',')) { + for (String id : getSettings().getStringArray(IssueExclusionProperties.PATTERNS_ALLFILE_KEY)) { String propPrefix = IssueExclusionProperties.PATTERNS_ALLFILE_KEY + "." + id + "."; - String allFileRegexp = getSettings().getString(propPrefix + IssueExclusionProperties.FILE_REGEXP); + String allFileRegexp = getSettings().get(propPrefix + IssueExclusionProperties.FILE_REGEXP).orElse(null); PatternDecoder.checkWholeFileRegexp(allFileRegexp); allFilePatterns.add(nullToEmpty(allFileRegexp)); } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/IssueInclusionPatternInitializer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/IssueInclusionPatternInitializer.java index 7e3992e493c..2d76c749f57 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/IssueInclusionPatternInitializer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/IssueInclusionPatternInitializer.java @@ -19,11 +19,11 @@ */ package org.sonar.scanner.issue.ignore.pattern; -import org.sonar.api.config.Settings; +import org.sonar.api.config.Configuration; public class IssueInclusionPatternInitializer extends AbstractPatternInitializer { - public IssueInclusionPatternInitializer(Settings settings) { + public IssueInclusionPatternInitializer(Configuration settings) { super(settings); } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/IssuePattern.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/IssuePattern.java index 9ef0d64c9d4..4d326f7c198 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/IssuePattern.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/IssuePattern.java @@ -20,7 +20,6 @@ package org.sonar.scanner.issue.ignore.pattern; import com.google.common.collect.Sets; - import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/LineRange.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/LineRange.java index b252484fb7a..0f49d446504 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/LineRange.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/LineRange.java @@ -20,7 +20,6 @@ package org.sonar.scanner.issue.ignore.pattern; import com.google.common.base.Preconditions; - import java.util.LinkedHashSet; import java.util.Set; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/PatternDecoder.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/PatternDecoder.java index f0ce08b2a19..2aa80064276 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/PatternDecoder.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/PatternDecoder.java @@ -19,14 +19,12 @@ */ package org.sonar.scanner.issue.ignore.pattern; +import com.google.common.annotations.VisibleForTesting; import java.util.Collections; import java.util.HashSet; import java.util.Set; - import org.apache.commons.lang.StringUtils; -import com.google.common.annotations.VisibleForTesting; - public class PatternDecoder { private static final String LINE_RANGE_REGEXP = "\\[((\\d+|\\d+-\\d+),?)*\\]"; private static final String CONFIG_FORMAT_ERROR_PREFIX = "Exclusions > Issues : Invalid format. "; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/PatternMatcher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/PatternMatcher.java index 2d008410cbe..9afe7ae375b 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/PatternMatcher.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/PatternMatcher.java @@ -19,17 +19,14 @@ */ package org.sonar.scanner.issue.ignore.pattern; -import org.sonar.api.rule.RuleKey; - import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.Multimap; - import java.util.Collection; import java.util.Set; - import javax.annotation.CheckForNull; import javax.annotation.Nullable; +import org.sonar.api.rule.RuleKey; public class PatternMatcher { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsLoader.java index 30cdeb0c582..4bdf149ec05 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsLoader.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsLoader.java @@ -21,9 +21,7 @@ package org.sonar.scanner.issue.ignore.scanner; import java.util.ArrayList; import java.util.List; - import javax.annotation.CheckForNull; - import org.apache.commons.lang.StringUtils; import org.sonar.api.batch.fs.internal.FileMetadata.CharHandler; import org.sonar.scanner.issue.ignore.pattern.BlockIssuePattern; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsRegexpScanner.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsRegexpScanner.java index 0ad4373665a..e0230681382 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsRegexpScanner.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsRegexpScanner.java @@ -24,7 +24,6 @@ import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.regex.Pattern; - import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/DefaultServerLineHashesLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/DefaultServerLineHashesLoader.java index 0f7c9de0ace..01c9140227f 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/DefaultServerLineHashesLoader.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/DefaultServerLineHashesLoader.java @@ -19,18 +19,16 @@ */ package org.sonar.scanner.issue.tracking; -import org.sonarqube.ws.client.GetRequest; - -import java.io.IOException; -import java.io.Reader; - import com.google.common.base.Splitter; import com.google.common.collect.Iterators; +import java.io.IOException; +import java.io.Reader; import org.apache.commons.io.IOUtils; import org.sonar.api.utils.log.Loggers; import org.sonar.api.utils.log.Profiler; import org.sonar.scanner.bootstrap.ScannerWsClient; import org.sonar.scanner.util.ScannerUtils; +import org.sonarqube.ws.client.GetRequest; public class DefaultServerLineHashesLoader implements ServerLineHashesLoader { private ScannerWsClient wsClient; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/IssueTrackingInput.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/IssueTrackingInput.java index 3ee4ac48da3..9f2876275b9 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/IssueTrackingInput.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/IssueTrackingInput.java @@ -19,14 +19,12 @@ */ package org.sonar.scanner.issue.tracking; -import org.sonar.core.issue.tracking.Trackable; -import org.sonar.core.issue.tracking.BlockHashSequence; -import org.sonar.core.issue.tracking.LineHashSequence; - import java.util.Collection; import java.util.List; - +import org.sonar.core.issue.tracking.BlockHashSequence; import org.sonar.core.issue.tracking.Input; +import org.sonar.core.issue.tracking.LineHashSequence; +import org.sonar.core.issue.tracking.Trackable; public class IssueTrackingInput<T extends Trackable> implements Input<T> { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/IssueTransition.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/IssueTransition.java index 3f32e511f78..8dffa1f7015 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/IssueTransition.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/IssueTransition.java @@ -19,6 +19,12 @@ */ package org.sonar.scanner.issue.tracking; +import java.util.ArrayList; +import java.util.Date; +import java.util.LinkedList; +import java.util.List; +import java.util.concurrent.TimeUnit; +import javax.annotation.Nullable; import org.sonar.api.batch.ScannerSide; import org.sonar.api.batch.fs.InputComponent; import org.sonar.api.batch.fs.internal.DefaultInputComponent; @@ -31,13 +37,6 @@ import org.sonar.scanner.protocol.output.ScannerReportReader; import org.sonar.scanner.report.ReportPublisher; import org.sonar.scanner.scan.filesystem.InputComponentStore; import org.sonar.scanner.util.ProgressReport; -import javax.annotation.Nullable; - -import java.util.ArrayList; -import java.util.Date; -import java.util.LinkedList; -import java.util.List; -import java.util.concurrent.TimeUnit; @ScannerSide public class IssueTransition { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/TrackedIssue.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/TrackedIssue.java index 31bf62f0143..b9446d52807 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/TrackedIssue.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/TrackedIssue.java @@ -24,7 +24,6 @@ import java.io.Serializable; import java.util.Date; import javax.annotation.CheckForNull; import javax.annotation.Nullable; - import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; import org.sonar.api.rule.RuleKey; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/TaskResult.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/TaskResult.java index 0d391526e1f..e5f17cbb443 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/TaskResult.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/TaskResult.java @@ -47,11 +47,11 @@ import org.sonar.scanner.protocol.output.ScannerReport; import org.sonar.scanner.protocol.output.ScannerReport.Component; import org.sonar.scanner.protocol.output.ScannerReport.Metadata; import org.sonar.scanner.protocol.output.ScannerReport.Symbol; +import org.sonar.scanner.protocol.output.ScannerReportReader; import org.sonar.scanner.report.ReportPublisher; import org.sonar.scanner.report.ScannerReportUtils; import org.sonar.scanner.scan.ProjectScanContainer; import org.sonar.scanner.scan.filesystem.InputComponentStore; -import org.sonar.scanner.protocol.output.ScannerReportReader; import static org.apache.commons.lang.StringUtils.isNotEmpty; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/InitializersExecutor.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/InitializersExecutor.java index ca1722afad0..b4d5818fc47 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/InitializersExecutor.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/InitializersExecutor.java @@ -20,6 +20,7 @@ package org.sonar.scanner.phases; import com.google.common.collect.Lists; +import java.util.Collection; import org.apache.commons.lang.StringUtils; import org.sonar.api.batch.Initializer; import org.sonar.api.batch.fs.internal.DefaultInputModule; @@ -29,7 +30,6 @@ import org.sonar.api.utils.log.Loggers; import org.sonar.api.utils.log.Profiler; import org.sonar.scanner.bootstrap.ScannerExtensionDictionnary; import org.sonar.scanner.events.EventBus; -import java.util.Collection; public class InitializersExecutor { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/SensorsPhaseEvent.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/SensorsPhaseEvent.java index b231e09f89f..63d3526f659 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/SensorsPhaseEvent.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/SensorsPhaseEvent.java @@ -19,11 +19,10 @@ */ package org.sonar.scanner.phases; +import java.util.List; import org.sonar.api.batch.Sensor; import org.sonar.api.batch.events.SensorsPhaseHandler; -import java.util.List; - class SensorsPhaseEvent extends AbstractPhaseEvent<SensorsPhaseHandler> implements org.sonar.api.batch.events.SensorsPhaseHandler.SensorsPhaseEvent { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/postjob/DefaultPostJobContext.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/postjob/DefaultPostJobContext.java index d51903e4646..1848b811c43 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/postjob/DefaultPostJobContext.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/postjob/DefaultPostJobContext.java @@ -22,13 +22,13 @@ package org.sonar.scanner.postjob; import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.StreamSupport; - import javax.annotation.Nullable; import org.sonar.api.batch.AnalysisMode; import org.sonar.api.batch.fs.InputComponent; import org.sonar.api.batch.postjob.PostJobContext; import org.sonar.api.batch.postjob.issue.PostJobIssue; import org.sonar.api.batch.rule.Severity; +import org.sonar.api.config.Configuration; import org.sonar.api.config.Settings; import org.sonar.api.rule.RuleKey; import org.sonar.scanner.issue.IssueCache; @@ -37,13 +37,16 @@ import org.sonar.scanner.scan.filesystem.InputComponentStore; public class DefaultPostJobContext implements PostJobContext { - private final Settings settings; + private final Configuration config; private final IssueCache cache; private final AnalysisMode analysisMode; private InputComponentStore inputComponentStore; + private final Settings mutableSettings; - public DefaultPostJobContext(Settings settings, IssueCache cache, InputComponentStore inputComponentStore, AnalysisMode analysisMode) { - this.settings = settings; + public DefaultPostJobContext(Configuration config, Settings mutableSettings, IssueCache cache, InputComponentStore inputComponentStore, + AnalysisMode analysisMode) { + this.config = config; + this.mutableSettings = mutableSettings; this.cache = cache; this.inputComponentStore = inputComponentStore; this.analysisMode = analysisMode; @@ -51,7 +54,12 @@ public class DefaultPostJobContext implements PostJobContext { @Override public Settings settings() { - return settings; + return mutableSettings; + } + + @Override + public Configuration config() { + return config; } @Override diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/AnalysisContextReportPublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/AnalysisContextReportPublisher.java index b4d2b94bb1f..4da1aeda04e 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/AnalysisContextReportPublisher.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/AnalysisContextReportPublisher.java @@ -37,7 +37,7 @@ import org.sonar.api.utils.System2; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; import org.sonar.core.platform.PluginInfo; -import org.sonar.scanner.bootstrap.GlobalSettings; +import org.sonar.scanner.bootstrap.GlobalConfiguration; import org.sonar.scanner.bootstrap.ScannerPluginRepository; import org.sonar.scanner.protocol.output.ScannerReportWriter; import org.sonar.scanner.repository.ProjectRepositories; @@ -55,12 +55,12 @@ public class AnalysisContextReportPublisher { private final AnalysisMode mode; private final System2 system; private final ProjectRepositories projectRepos; - private final GlobalSettings globalSettings; + private final GlobalConfiguration globalSettings; private ScannerReportWriter writer; public AnalysisContextReportPublisher(AnalysisMode mode, ScannerPluginRepository pluginRepo, System2 system, - ProjectRepositories projectRepos, GlobalSettings globalSettings) { + ProjectRepositories projectRepos, GlobalConfiguration globalSettings) { this.mode = mode; this.pluginRepo = pluginRepo; this.system = system; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java index 99623384ab3..78fa6bea16c 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java @@ -21,7 +21,6 @@ package org.sonar.scanner.report; import java.util.Collection; import java.util.stream.Collectors; - import javax.annotation.CheckForNull; import org.apache.commons.lang.StringUtils; import org.sonar.api.CoreProperties; @@ -38,11 +37,11 @@ import org.sonar.api.batch.fs.internal.InputComponentTree; import org.sonar.api.batch.fs.internal.InputModuleHierarchy; import org.sonar.core.util.CloseableIterator; import org.sonar.scanner.protocol.output.ScannerReport; -import org.sonar.scanner.protocol.output.ScannerReportReader; import org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType; import org.sonar.scanner.protocol.output.ScannerReport.ComponentLink; import org.sonar.scanner.protocol.output.ScannerReport.ComponentLink.ComponentLinkType; import org.sonar.scanner.protocol.output.ScannerReport.Issue; +import org.sonar.scanner.protocol.output.ScannerReportReader; import org.sonar.scanner.protocol.output.ScannerReportWriter; /** diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ContextPropertiesPublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ContextPropertiesPublisher.java index 66ba41ded41..fea8c739fc0 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ContextPropertiesPublisher.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ContextPropertiesPublisher.java @@ -23,9 +23,8 @@ import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; - import javax.annotation.Nonnull; -import org.sonar.api.config.Settings; +import org.sonar.scanner.config.DefaultConfiguration; import org.sonar.scanner.protocol.output.ScannerReport; import org.sonar.scanner.protocol.output.ScannerReportWriter; import org.sonar.scanner.repository.ContextPropertiesCache; @@ -35,11 +34,11 @@ import static org.sonar.core.config.WebhookProperties.ANALYSIS_PROPERTY_PREFIX; public class ContextPropertiesPublisher implements ReportPublisherStep { private final ContextPropertiesCache cache; - private final Settings settings; + private final DefaultConfiguration config; - public ContextPropertiesPublisher(ContextPropertiesCache cache, Settings settings) { + public ContextPropertiesPublisher(ContextPropertiesCache cache, DefaultConfiguration config) { this.cache = cache; - this.settings = settings; + this.config = config; } @Override @@ -51,7 +50,7 @@ public class ContextPropertiesPublisher implements ReportPublisherStep { // properties that are automatically included to report so that // they can be included to webhook payloads - Stream<ScannerReport.ContextProperty> fromSettings = settings.getProperties().entrySet().stream() + Stream<ScannerReport.ContextProperty> fromSettings = config.getProperties().entrySet().stream() .filter(e -> e.getKey().startsWith(ANALYSIS_PROPERTY_PREFIX)) .map(transformer); @@ -62,7 +61,7 @@ public class ContextPropertiesPublisher implements ReportPublisherStep { private final ScannerReport.ContextProperty.Builder builder = ScannerReport.ContextProperty.newBuilder(); @Override - public ScannerReport.ContextProperty apply(@Nonnull Map.Entry<String, String> input) { + public ScannerReport.ContextProperty apply(@Nonnull Map.Entry<String, String> input) { return builder.clear().setKey(input.getKey()).setValue(input.getValue()).build(); } } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java index 63f01984259..9afa52f2ca8 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java @@ -23,7 +23,7 @@ import org.sonar.api.CoreProperties; 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.Settings; +import org.sonar.api.config.Configuration; import org.sonar.scanner.ProjectAnalysisInfo; import org.sonar.scanner.cpd.index.SonarCpdBlockIndex; import org.sonar.scanner.protocol.output.ScannerReport; @@ -33,12 +33,12 @@ import org.sonar.scanner.rule.QProfile; public class MetadataPublisher implements ReportPublisherStep { - private final Settings settings; + private final Configuration settings; private final ModuleQProfiles qProfiles; private final ProjectAnalysisInfo projectAnalysisInfo; private final InputModuleHierarchy moduleHierarchy; - public MetadataPublisher(ProjectAnalysisInfo projectAnalysisInfo, InputModuleHierarchy moduleHierarchy, Settings settings, ModuleQProfiles qProfiles) { + public MetadataPublisher(ProjectAnalysisInfo projectAnalysisInfo, InputModuleHierarchy moduleHierarchy, Configuration settings, ModuleQProfiles qProfiles) { this.projectAnalysisInfo = projectAnalysisInfo; this.moduleHierarchy = moduleHierarchy; this.settings = settings; @@ -56,10 +56,7 @@ public class MetadataPublisher implements ReportPublisherStep { .setCrossProjectDuplicationActivated(SonarCpdBlockIndex.isCrossProjectDuplicationEnabled(settings)) .setRootComponentRef(rootProject.batchId()); - String organization = settings.getString(CoreProperties.PROJECT_ORGANIZATION_PROPERTY); - if (organization != null) { - builder.setOrganizationKey(organization); - } + settings.get(CoreProperties.PROJECT_ORGANIZATION_PROPERTY).ifPresent(builder::setOrganizationKey); String branch = rootDef.getBranch(); if (branch != null) { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ReportPublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ReportPublisher.java index bb38c3ea6e0..487c48cd4e5 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ReportPublisher.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ReportPublisher.java @@ -38,7 +38,7 @@ import org.picocontainer.Startable; import org.sonar.api.CoreProperties; import org.sonar.api.batch.ScannerSide; import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.api.config.Settings; +import org.sonar.api.config.Configuration; import org.sonar.api.platform.Server; import org.sonar.api.utils.MessageException; import org.sonar.api.utils.TempFolder; @@ -66,7 +66,7 @@ public class ReportPublisher implements Startable { public static final String VERBOSE_KEY = "sonar.verbose"; public static final String METADATA_DUMP_FILENAME = "report-task.txt"; - private final Settings settings; + private final Configuration settings; private final ScannerWsClient wsClient; private final AnalysisContextReportPublisher contextPublisher; private final ImmutableProjectReactor projectReactor; @@ -78,7 +78,7 @@ public class ReportPublisher implements Startable { private File reportDir; private ScannerReportWriter writer; - public ReportPublisher(Settings settings, ScannerWsClient wsClient, Server server, AnalysisContextReportPublisher contextPublisher, + public ReportPublisher(Configuration settings, ScannerWsClient wsClient, Server server, AnalysisContextReportPublisher contextPublisher, ImmutableProjectReactor projectReactor, DefaultAnalysisMode analysisMode, TempFolder temp, ReportPublisherStep[] publishers) { this.settings = settings; this.wsClient = wsClient; @@ -135,7 +135,7 @@ public class ReportPublisher implements Startable { } private boolean shouldKeepReport() { - return settings.getBoolean(KEEP_REPORT_PROP_KEY) || settings.getBoolean(VERBOSE_KEY); + return settings.getBoolean(KEEP_REPORT_PROP_KEY).orElse(false) || settings.getBoolean(VERBOSE_KEY).orElse(false); } private File generateReportFile() { @@ -169,7 +169,7 @@ public class ReportPublisher implements Startable { PostRequest.Part filePart = new PostRequest.Part(MediaTypes.ZIP, report); PostRequest post = new PostRequest("api/ce/submit") .setMediaType(MediaTypes.PROTOBUF) - .setParam("organization", settings.getString(CoreProperties.PROJECT_ORGANIZATION_PROPERTY)) + .setParam("organization", settings.get(CoreProperties.PROJECT_ORGANIZATION_PROPERTY).orElse(null)) .setParam("projectKey", projectDefinition.getKey()) .setParam("projectName", projectDefinition.getOriginalName()) .setParam("projectBranch", projectDefinition.getBranch()) @@ -202,9 +202,7 @@ public class ReportPublisher implements Startable { Map<String, String> metadata = new LinkedHashMap<>(); String effectiveKey = projectReactor.getRoot().getKeyWithBranch(); - if (settings.hasKey(CoreProperties.PROJECT_ORGANIZATION_PROPERTY)) { - metadata.put("organization", settings.getString(CoreProperties.PROJECT_ORGANIZATION_PROPERTY)); - } + settings.get(CoreProperties.PROJECT_ORGANIZATION_PROPERTY).ifPresent(org -> metadata.put("organization", org)); metadata.put("projectKey", effectiveKey); metadata.put("serverUrl", publicUrl); metadata.put("serverVersion", server.getVersion()); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/TestExecutionAndCoveragePublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/TestExecutionAndCoveragePublisher.java index b549f34ea67..43411c011c0 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/TestExecutionAndCoveragePublisher.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/TestExecutionAndCoveragePublisher.java @@ -23,7 +23,6 @@ import com.google.common.collect.Iterables; import java.util.HashSet; import java.util.Set; import java.util.stream.StreamSupport; - import org.sonar.api.batch.fs.InputComponent; import org.sonar.api.batch.fs.internal.DefaultInputComponent; import org.sonar.api.test.CoverageBlock; @@ -36,8 +35,8 @@ import org.sonar.scanner.protocol.output.ScannerReport; import org.sonar.scanner.protocol.output.ScannerReport.CoverageDetail; import org.sonar.scanner.protocol.output.ScannerReport.Test; import org.sonar.scanner.protocol.output.ScannerReport.Test.TestStatus; -import org.sonar.scanner.scan.filesystem.InputComponentStore; import org.sonar.scanner.protocol.output.ScannerReportWriter; +import org.sonar.scanner.scan.filesystem.InputComponentStore; import static java.util.stream.Collectors.toList; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultQualityProfileLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultQualityProfileLoader.java index 92fced49ea2..eb86e53237a 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultQualityProfileLoader.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultQualityProfileLoader.java @@ -29,7 +29,8 @@ import java.util.Optional; import java.util.function.BinaryOperator; import javax.annotation.Nullable; import org.apache.commons.io.IOUtils; -import org.sonar.api.config.Settings; +import org.sonar.api.CoreProperties; +import org.sonar.api.config.Configuration; import org.sonar.api.utils.MessageException; import org.sonar.scanner.bootstrap.ScannerWsClient; import org.sonarqube.ws.QualityProfiles.SearchWsResponse; @@ -43,10 +44,10 @@ import static org.sonar.scanner.util.ScannerUtils.encodeForUrl; public class DefaultQualityProfileLoader implements QualityProfileLoader { private static final String WS_URL = "/api/qualityprofiles/search.protobuf"; - private final Settings settings; + private final Configuration settings; private final ScannerWsClient wsClient; - public DefaultQualityProfileLoader(Settings settings, ScannerWsClient wsClient) { + public DefaultQualityProfileLoader(Configuration settings, ScannerWsClient wsClient) { this.settings = settings; this.wsClient = wsClient; } @@ -81,7 +82,7 @@ public class DefaultQualityProfileLoader implements QualityProfileLoader { } private Optional<String> getOrganizationKey() { - return Optional.ofNullable(settings.getString("sonar.organization")); + return settings.get(CoreProperties.PROJECT_ORGANIZATION_PROPERTY); } private Map<String, QualityProfile> call(String url) { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ProjectRepositoriesProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ProjectRepositoriesProvider.java index adb696b079f..fa52178accd 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ProjectRepositoriesProvider.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ProjectRepositoriesProvider.java @@ -19,12 +19,12 @@ */ package org.sonar.scanner.repository; -import org.sonar.api.utils.log.Profiler; -import org.sonar.scanner.analysis.DefaultAnalysisMode; +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.picocontainer.injectors.ProviderAdapter; +import org.sonar.api.utils.log.Profiler; +import org.sonar.scanner.analysis.DefaultAnalysisMode; public class ProjectRepositoriesProvider extends ProviderAdapter { private static final Logger LOG = Loggers.get(ProjectRepositoriesProvider.class); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/QualityProfileLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/QualityProfileLoader.java index 8e0eba0eb7f..96394c57c41 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/QualityProfileLoader.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/QualityProfileLoader.java @@ -19,11 +19,9 @@ */ package org.sonar.scanner.repository; -import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile; - -import javax.annotation.Nullable; - import java.util.List; +import javax.annotation.Nullable; +import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile; public interface QualityProfileLoader { List<QualityProfile> load(String projectKey, @Nullable String profileName); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/language/DefaultLanguagesRepository.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/language/DefaultLanguagesRepository.java index 1850a3b95fc..4af9e6a6e74 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/language/DefaultLanguagesRepository.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/language/DefaultLanguagesRepository.java @@ -19,14 +19,11 @@ */ package org.sonar.scanner.repository.language; -import org.picocontainer.Startable; - -import org.sonar.api.resources.Languages; - -import javax.annotation.CheckForNull; - import java.util.ArrayList; import java.util.Collection; +import javax.annotation.CheckForNull; +import org.picocontainer.Startable; +import org.sonar.api.resources.Languages; /** * Languages repository using {@link Languages} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/language/LanguagesRepository.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/language/LanguagesRepository.java index e7bbfa79fc9..626a3361f8f 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/language/LanguagesRepository.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/language/LanguagesRepository.java @@ -19,11 +19,9 @@ */ package org.sonar.scanner.repository.language; -import org.sonar.api.batch.ScannerSide; - -import javax.annotation.CheckForNull; - import java.util.Collection; +import javax.annotation.CheckForNull; +import org.sonar.api.batch.ScannerSide; /** * Languages repository diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/DefaultRulesLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/DefaultRulesLoader.java index cec04cc2242..4a3d7a3673e 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/DefaultRulesLoader.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/DefaultRulesLoader.java @@ -19,15 +19,14 @@ */ package org.sonar.scanner.rule; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; import org.apache.commons.io.IOUtils; import org.sonar.scanner.bootstrap.ScannerWsClient; +import org.sonarqube.ws.Rules.ListResponse; import org.sonarqube.ws.Rules.ListResponse.Rule; import org.sonarqube.ws.client.GetRequest; -import org.sonarqube.ws.Rules.ListResponse; - -import java.io.IOException; -import java.io.InputStream; -import java.util.List; public class DefaultRulesLoader implements RulesLoader { private static final String RULES_SEARCH_URL = "/api/rules/list.protobuf"; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/ModuleQProfiles.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/ModuleQProfiles.java index ec541c56c97..013e22e352e 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/ModuleQProfiles.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/ModuleQProfiles.java @@ -19,17 +19,14 @@ */ package org.sonar.scanner.rule; -import org.sonar.api.utils.DateUtils; - -import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile; -import org.sonar.api.batch.ScannerSide; - -import javax.annotation.CheckForNull; - import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Map; +import javax.annotation.CheckForNull; +import org.sonar.api.batch.ScannerSide; +import org.sonar.api.utils.DateUtils; +import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile; /** * Lists the Quality profiles enabled on the current module. diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/QProfile.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/QProfile.java index 3f1dcf705e2..a38f942b929 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/QProfile.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/QProfile.java @@ -20,7 +20,6 @@ package org.sonar.scanner.rule; import com.google.common.base.MoreObjects; - import java.util.Date; public class QProfile { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/QProfileVerifier.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/QProfileVerifier.java index 91fbae0a577..b3a309228e1 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/QProfileVerifier.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/QProfileVerifier.java @@ -25,7 +25,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.api.batch.ScannerSide; import org.sonar.api.batch.fs.FileSystem; -import org.sonar.api.config.Settings; +import org.sonar.api.config.Configuration; import org.sonar.api.utils.MessageException; import static org.apache.commons.lang.StringUtils.isNotEmpty; @@ -35,11 +35,11 @@ public class QProfileVerifier { private static final Logger LOG = LoggerFactory.getLogger(QProfileVerifier.class); - private final Settings settings; + private final Configuration settings; private final FileSystem fs; private final ModuleQProfiles profiles; - public QProfileVerifier(Settings settings, FileSystem fs, ModuleQProfiles profiles) { + public QProfileVerifier(Configuration settings, FileSystem fs, ModuleQProfiles profiles) { this.settings = settings; this.fs = fs; this.profiles = profiles; @@ -51,7 +51,7 @@ public class QProfileVerifier { @VisibleForTesting void execute(Logger logger) { - String defaultName = settings.getString(ModuleQProfiles.SONAR_PROFILE_PROP); + String defaultName = settings.get(ModuleQProfiles.SONAR_PROFILE_PROP).orElse(null); boolean defaultNameUsed = StringUtils.isBlank(defaultName); for (String lang : fs.languages()) { QProfile profile = profiles.findByLanguage(lang); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RuleFinderCompatibility.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RuleFinderCompatibility.java index 185b98d76e5..bd3d822bdec 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RuleFinderCompatibility.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RuleFinderCompatibility.java @@ -23,7 +23,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.stream.Collectors; - import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.apache.commons.lang.builder.ReflectionToStringBuilder; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RulesProfileProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RulesProfileProvider.java index b5fc765c0cc..fdf35103ce8 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RulesProfileProvider.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RulesProfileProvider.java @@ -26,7 +26,7 @@ import org.apache.commons.lang.StringUtils; import org.picocontainer.injectors.ProviderAdapter; import org.sonar.api.CoreProperties; import org.sonar.api.batch.rule.ActiveRules; -import org.sonar.api.config.Settings; +import org.sonar.api.config.Configuration; import org.sonar.api.profiles.RulesProfile; import org.sonar.api.rules.ActiveRule; import org.sonar.api.rules.Rule; @@ -39,9 +39,9 @@ public class RulesProfileProvider extends ProviderAdapter { private RulesProfile singleton = null; - public RulesProfile provide(ModuleQProfiles qProfiles, ActiveRules activeRules, Settings settings) { + public RulesProfile provide(ModuleQProfiles qProfiles, ActiveRules activeRules, Configuration settings) { if (singleton == null) { - String lang = settings.getString(CoreProperties.PROJECT_LANGUAGE_PROPERTY); + String lang = settings.get(CoreProperties.PROJECT_LANGUAGE_PROPERTY).orElse(null); if (StringUtils.isNotBlank(lang)) { // Backward-compatibility with single-language modules singleton = loadSingleLanguageProfile(qProfiles, activeRules, lang); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RulesProfileWrapper.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RulesProfileWrapper.java index 0893c2447cc..6ef87f18442 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RulesProfileWrapper.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RulesProfileWrapper.java @@ -19,6 +19,10 @@ */ package org.sonar.scanner.rule; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.api.profiles.RulesProfile; @@ -26,11 +30,6 @@ import org.sonar.api.rules.ActiveRule; import org.sonar.api.rules.Rule; import org.sonar.api.utils.SonarException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - /** * This wrapper is used to try to preserve backward compatibility for plugins that used to * depends on {@link org.sonar.api.profiles.RulesProfile} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RulesProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RulesProvider.java index 9fe5a93f633..69fbaa4c19a 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RulesProvider.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RulesProvider.java @@ -19,18 +19,16 @@ */ package org.sonar.scanner.rule; +import java.util.List; +import org.picocontainer.injectors.ProviderAdapter; +import org.sonar.api.batch.rule.Rules; +import org.sonar.api.batch.rule.internal.NewRule; +import org.sonar.api.batch.rule.internal.RulesBuilder; +import org.sonar.api.rule.RuleKey; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; import org.sonar.api.utils.log.Profiler; - -import java.util.List; - import org.sonarqube.ws.Rules.ListResponse.Rule; -import org.picocontainer.injectors.ProviderAdapter; -import org.sonar.api.rule.RuleKey; -import org.sonar.api.batch.rule.internal.RulesBuilder; -import org.sonar.api.batch.rule.internal.NewRule; -import org.sonar.api.batch.rule.Rules; public class RulesProvider extends ProviderAdapter { private static final Logger LOG = Loggers.get(RulesProvider.class); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DefaultInputModuleHierarchy.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DefaultInputModuleHierarchy.java index 5275352b9c5..ae7f1de06ec 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DefaultInputModuleHierarchy.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DefaultInputModuleHierarchy.java @@ -19,23 +19,20 @@ */ package org.sonar.scanner.scan; +import com.google.common.base.Preconditions; +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Multimap; import java.nio.file.Path; import java.util.Collection; import java.util.HashMap; import java.util.Map; - import javax.annotation.CheckForNull; - import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.fs.InputModule; import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.batch.fs.internal.InputModuleHierarchy; import org.sonar.api.scan.filesystem.PathResolver; -import com.google.common.base.Preconditions; -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Multimap; - public class DefaultInputModuleHierarchy implements InputModuleHierarchy { private final PathResolver pathResolver = new PathResolver(); private DefaultInputModule root; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleScanContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleScanContainer.java index b7ba4b5cf0b..8305472e8aa 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleScanContainer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleScanContainer.java @@ -30,9 +30,9 @@ import org.sonar.api.resources.Project; import org.sonar.api.scan.filesystem.FileExclusions; import org.sonar.core.platform.ComponentContainer; import org.sonar.scanner.DefaultFileLinesContextFactory; -import org.sonar.scanner.bootstrap.ScannerExtensionDictionnary; import org.sonar.scanner.bootstrap.ExtensionInstaller; import org.sonar.scanner.bootstrap.ExtensionUtils; +import org.sonar.scanner.bootstrap.ScannerExtensionDictionnary; import org.sonar.scanner.deprecated.DeprecatedSensorContext; import org.sonar.scanner.deprecated.perspectives.ScannerPerspectives; import org.sonar.scanner.events.EventBus; @@ -97,7 +97,8 @@ public class ModuleScanContainer extends ComponentContainer { // still injected by some plugins new Project(module.definition()), module, - ModuleSettings.class); + MutableModuleSettings.class, + new ModuleSettingsProvider()); if (getComponentByType(AnalysisMode.class).isIssues()) { add(IssuesPhaseExecutor.class, diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleSettings.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleSettings.java index 28c25f40657..a2a4c0b90b0 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleSettings.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleSettings.java @@ -19,96 +19,16 @@ */ package org.sonar.scanner.scan; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; import java.util.Map; -import java.util.Optional; -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.GlobalSettings; -import org.sonar.scanner.report.AnalysisContextReportPublisher; -import org.sonar.scanner.repository.ProjectRepositories; +import org.sonar.api.batch.AnalysisMode; +import org.sonar.api.config.Encryption; +import org.sonar.api.config.PropertyDefinitions; +import org.sonar.scanner.config.DefaultConfiguration; -/** - * @since 2.12 - */ -public class ModuleSettings extends Settings { - - private final ProjectRepositories projectRepos; - private final DefaultAnalysisMode analysisMode; - private final Map<String, String> properties = new HashMap<>(); - - public ModuleSettings(GlobalSettings batchSettings, ProjectDefinition moduleDefinition, ProjectRepositories projectSettingsRepo, - DefaultAnalysisMode analysisMode, AnalysisContextReportPublisher contextReportPublisher) { - super(batchSettings.getDefinitions(), batchSettings.getEncryption()); - this.projectRepos = projectSettingsRepo; - this.analysisMode = analysisMode; - - init(moduleDefinition, batchSettings); - contextReportPublisher.dumpModuleSettings(moduleDefinition); - } - - private ModuleSettings init(ProjectDefinition moduleDefinition, GlobalSettings batchSettings) { - addProjectProperties(moduleDefinition, batchSettings); - addBuildProperties(moduleDefinition); - return this; - } - - private void addProjectProperties(ProjectDefinition def, GlobalSettings batchSettings) { - addProperties(batchSettings.getProperties()); - do { - if (projectRepos.moduleExists(def.getKeyWithBranch())) { - addProperties(projectRepos.settings(def.getKeyWithBranch())); - break; - } - def = def.getParent(); - } while (def != null); - } +public class ModuleSettings extends DefaultConfiguration { - private void addBuildProperties(ProjectDefinition project) { - List<ProjectDefinition> orderedProjects = getTopDownParentProjects(project); - for (ProjectDefinition p : orderedProjects) { - addProperties(p.properties()); - } + public ModuleSettings(PropertyDefinitions propertyDefinitions, Encryption encryption, AnalysisMode mode, Map<String, String> props) { + super(propertyDefinitions, encryption, mode, props); } - /** - * From root to given project - */ - static List<ProjectDefinition> getTopDownParentProjects(ProjectDefinition project) { - List<ProjectDefinition> result = new ArrayList<>(); - ProjectDefinition p = project; - while (p != null) { - result.add(0, p); - p = p.getParent(); - } - return result; - } - - @Override - protected Optional<String> get(String key) { - if (analysisMode.isIssues() && key.endsWith(".secured") && !key.contains(".license")) { - throw MessageException.of("Access to the secured property '" + key - + "' is not possible in issues mode. The SonarQube plugin which requires this property must be deactivated in issues mode."); - } - return Optional.ofNullable(properties.get(key)); - } - - @Override - protected void set(String key, String value) { - properties.put(key, value); - } - - @Override - protected void remove(String key) { - properties.remove(key); - } - - @Override - public Map<String, String> getProperties() { - return properties; - } } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleSettingsProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleSettingsProvider.java new file mode 100644 index 00000000000..7fd4d6a24d6 --- /dev/null +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleSettingsProvider.java @@ -0,0 +1,85 @@ +/* + * 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.ArrayList; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import org.picocontainer.injectors.ProviderAdapter; +import org.sonar.api.batch.AnalysisMode; +import org.sonar.api.batch.bootstrap.ProjectDefinition; +import org.sonar.scanner.bootstrap.GlobalConfiguration; +import org.sonar.scanner.report.AnalysisContextReportPublisher; +import org.sonar.scanner.repository.ProjectRepositories; + +public class ModuleSettingsProvider extends ProviderAdapter { + + private ModuleSettings projectSettings; + + public ModuleSettings provide(GlobalConfiguration globalSettings, ProjectDefinition moduleDefinition, ProjectRepositories projectRepos, + AnalysisMode analysisMode, AnalysisContextReportPublisher contextReportPublisher) { + if (projectSettings == null) { + + Map<String, String> settings = new LinkedHashMap<>(); + settings.putAll(globalSettings.getProperties()); + settings.putAll(addServerSidePropertiesIfModuleExists(projectRepos, moduleDefinition)); + addScannerSideProperties(settings, moduleDefinition); + contextReportPublisher.dumpModuleSettings(moduleDefinition); + + projectSettings = new ModuleSettings(globalSettings.getDefinitions(), globalSettings.getEncryption(), analysisMode, settings); + } + return projectSettings; + } + + private Map<String, String> addServerSidePropertiesIfModuleExists(ProjectRepositories projectRepos, ProjectDefinition def) { + if (projectRepos.moduleExists(def.getKeyWithBranch())) { + return projectRepos.settings(def.getKeyWithBranch()); + } else { + // Module doesn't exist on server. Try to add parent server settings as inheritance. + ProjectDefinition parentDef = def.getParent(); + if (parentDef != null) { + return addServerSidePropertiesIfModuleExists(projectRepos, parentDef); + } + return Collections.emptyMap(); + } + } + + private void addScannerSideProperties(Map<String, String> settings, ProjectDefinition project) { + List<ProjectDefinition> orderedProjects = getTopDownParentProjects(project); + for (ProjectDefinition p : orderedProjects) { + settings.putAll(p.properties()); + } + } + + /** + * From root to given project + */ + static List<ProjectDefinition> getTopDownParentProjects(ProjectDefinition project) { + List<ProjectDefinition> result = new ArrayList<>(); + ProjectDefinition p = project; + while (p != null) { + result.add(0, p); + p = p.getParent(); + } + return result; + } +} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/MutableModuleSettings.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/MutableModuleSettings.java new file mode 100644 index 00000000000..8ae1bfb6ca4 --- /dev/null +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/MutableModuleSettings.java @@ -0,0 +1,113 @@ +/* + * 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.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +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; + +/** + * @deprecated since 6.5 {@link ModuleSettings} used to be mutable, so keep a mutable copy for backward compatibility. + */ +@Deprecated +public class MutableModuleSettings extends Settings { + + private final ProjectRepositories projectRepos; + private final DefaultAnalysisMode analysisMode; + private final Map<String, String> properties = new HashMap<>(); + + public MutableModuleSettings(MutableGlobalSettings batchSettings, ProjectDefinition moduleDefinition, ProjectRepositories projectSettingsRepo, + DefaultAnalysisMode analysisMode) { + super(batchSettings.getDefinitions(), batchSettings.getEncryption()); + this.projectRepos = projectSettingsRepo; + this.analysisMode = analysisMode; + + init(moduleDefinition, batchSettings); + } + + private MutableModuleSettings init(ProjectDefinition moduleDefinition, MutableGlobalSettings batchSettings) { + addProjectProperties(moduleDefinition, batchSettings); + addBuildProperties(moduleDefinition); + return this; + } + + private void addProjectProperties(ProjectDefinition def, MutableGlobalSettings batchSettings) { + addProperties(batchSettings.getProperties()); + do { + if (projectRepos.moduleExists(def.getKeyWithBranch())) { + addProperties(projectRepos.settings(def.getKeyWithBranch())); + break; + } + def = def.getParent(); + } while (def != null); + } + + private void addBuildProperties(ProjectDefinition project) { + List<ProjectDefinition> orderedProjects = getTopDownParentProjects(project); + for (ProjectDefinition p : orderedProjects) { + addProperties(p.properties()); + } + } + + /** + * From root to given project + */ + static List<ProjectDefinition> getTopDownParentProjects(ProjectDefinition project) { + List<ProjectDefinition> result = new ArrayList<>(); + ProjectDefinition p = project; + while (p != null) { + result.add(0, p); + p = p.getParent(); + } + return result; + } + + @Override + protected Optional<String> get(String key) { + if (analysisMode.isIssues() && key.endsWith(".secured") && !key.contains(".license")) { + throw MessageException.of("Access to the secured property '" + key + + "' is not possible in issues mode. The SonarQube plugin which requires this property must be deactivated in issues mode."); + } + return Optional.ofNullable(properties.get(key)); + } + + @Override + protected void set(String key, String value) { + properties.put(key, value); + } + + @Override + protected void remove(String key) { + properties.remove(key); + } + + @Override + public Map<String, String> getProperties() { + return properties; + } +} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/MutableProjectSettings.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/MutableProjectSettings.java new file mode 100644 index 00000000000..8f0fb5ea142 --- /dev/null +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/MutableProjectSettings.java @@ -0,0 +1,72 @@ +/* + * 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.HashMap; +import java.util.Map; +import java.util.Optional; +import org.sonar.api.batch.bootstrap.ProjectReactor; +import org.sonar.api.config.Settings; +import org.sonar.api.utils.MessageException; +import org.sonar.scanner.analysis.DefaultAnalysisMode; +import org.sonar.scanner.bootstrap.MutableGlobalSettings; +import org.sonar.scanner.repository.ProjectRepositories; + +/** + * @deprecated since 6.5 {@link ProjectSettings} used to be mutable, so keep a mutable copy for backward compatibility. + */ +@Deprecated +public class MutableProjectSettings extends Settings { + + private final DefaultAnalysisMode mode; + private final Map<String, String> properties = new HashMap<>(); + + public MutableProjectSettings(ProjectReactor reactor, MutableGlobalSettings mutableGlobalSettings, ProjectRepositories projectRepositories, DefaultAnalysisMode mode) { + super(mutableGlobalSettings.getDefinitions(), mutableGlobalSettings.getEncryption()); + this.mode = mode; + addProperties(mutableGlobalSettings.getProperties()); + addProperties(projectRepositories.settings(reactor.getRoot().getKeyWithBranch())); + addProperties(reactor.getRoot().properties()); + } + + @Override + protected Optional<String> get(String key) { + if (mode.isIssues() && key.endsWith(".secured") && !key.contains(".license")) { + throw MessageException.of("Access to the secured property '" + key + + "' is not possible in issues mode. The SonarQube plugin which requires this property must be deactivated in issues mode."); + } + return Optional.ofNullable(properties.get(key)); + } + + @Override + protected void set(String key, String value) { + properties.put(key, value); + } + + @Override + protected void remove(String key) { + properties.remove(key); + } + + @Override + public Map<String, String> getProperties() { + return properties; + } +} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectBuildersExecutor.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectBuildersExecutor.java index a2a321a5c36..53ed950330e 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectBuildersExecutor.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectBuildersExecutor.java @@ -20,7 +20,6 @@ package org.sonar.scanner.scan; import java.lang.reflect.Method; - import org.sonar.api.batch.bootstrap.ProjectBuilder; import org.sonar.api.batch.bootstrap.ProjectReactor; import org.sonar.api.batch.bootstrap.internal.ProjectBuilderContext; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectLock.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectLock.java index e1f6e77e384..bddf206cc59 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectLock.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectLock.java @@ -19,15 +19,14 @@ */ package org.sonar.scanner.scan; -import org.sonar.home.cache.DirectoryLock; -import org.sonar.scanner.bootstrap.Slf4jLogger; -import org.picocontainer.Startable; -import org.sonar.api.batch.bootstrap.ProjectReactor; - import java.io.IOException; import java.nio.channels.OverlappingFileLockException; import java.nio.file.Files; import java.nio.file.Path; +import org.picocontainer.Startable; +import org.sonar.api.batch.bootstrap.ProjectReactor; +import org.sonar.home.cache.DirectoryLock; +import org.sonar.scanner.bootstrap.Slf4jLogger; public class ProjectLock implements Startable { private final DirectoryLock lock; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorValidator.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorValidator.java index 48aae076fa8..f5f9d0886e7 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorValidator.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorValidator.java @@ -19,18 +19,15 @@ */ package org.sonar.scanner.scan; -import org.sonar.api.utils.MessageException; import com.google.common.base.Joiner; - import java.util.ArrayList; import java.util.List; - import javax.annotation.Nullable; - import org.apache.commons.lang.StringUtils; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.bootstrap.ProjectReactor; import org.sonar.api.config.Settings; +import org.sonar.api.utils.MessageException; import org.sonar.core.component.ComponentKeys; import org.sonar.scanner.analysis.DefaultAnalysisMode; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java index b3a9fb68c21..9720666b113 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java @@ -20,7 +20,6 @@ package org.sonar.scanner.scan; import com.google.common.annotations.VisibleForTesting; - import org.apache.commons.lang.StringUtils; import org.sonar.api.CoreProperties; import org.sonar.api.batch.InstantiationStrategy; @@ -181,7 +180,8 @@ public class ProjectScanContainer extends ComponentContainer { ContextPropertiesCache.class, ContextPropertiesPublisher.class, - ProjectSettings.class, + MutableProjectSettings.class, + new ProjectSettingsProvider(), // Report ScannerMetrics.class, diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectSettings.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectSettings.java index 65eda80b5b0..a25dc51ad43 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectSettings.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectSettings.java @@ -19,60 +19,16 @@ */ package org.sonar.scanner.scan; -import java.util.HashMap; import java.util.Map; -import java.util.Optional; -import org.sonar.api.batch.bootstrap.ProjectReactor; -import org.sonar.api.config.Settings; -import org.sonar.api.utils.MessageException; -import org.sonar.scanner.analysis.DefaultAnalysisMode; -import org.sonar.scanner.bootstrap.GlobalSettings; -import org.sonar.scanner.repository.ProjectRepositories; +import org.sonar.api.batch.AnalysisMode; +import org.sonar.api.config.Encryption; +import org.sonar.api.config.PropertyDefinitions; +import org.sonar.scanner.config.DefaultConfiguration; -public class ProjectSettings extends Settings { +public class ProjectSettings extends DefaultConfiguration { - private final GlobalSettings globalSettings; - private final ProjectRepositories projectRepositories; - private final DefaultAnalysisMode mode; - private final Map<String, String> properties = new HashMap<>(); - - public ProjectSettings(ProjectReactor reactor, GlobalSettings globalSettings, ProjectRepositories projectRepositories, DefaultAnalysisMode mode) { - super(globalSettings.getDefinitions(), globalSettings.getEncryption()); - this.mode = mode; - this.globalSettings = globalSettings; - this.projectRepositories = projectRepositories; - init(reactor); - } - - private void init(ProjectReactor reactor) { - addProperties(globalSettings.getProperties()); - - addProperties(projectRepositories.settings(reactor.getRoot().getKeyWithBranch())); - - addProperties(reactor.getRoot().properties()); - } - - @Override - protected Optional<String> get(String key) { - if (mode.isIssues() && key.endsWith(".secured") && !key.contains(".license")) { - throw MessageException.of("Access to the secured property '" + key - + "' is not possible in issues mode. The SonarQube plugin which requires this property must be deactivated in issues mode."); - } - return Optional.ofNullable(properties.get(key)); - } - - @Override - protected void set(String key, String value) { - properties.put(key, value); + public ProjectSettings(PropertyDefinitions propertyDefinitions, Encryption encryption, AnalysisMode mode, Map<String, String> props) { + super(propertyDefinitions, encryption, mode, props); } - @Override - protected void remove(String key) { - properties.remove(key); - } - - @Override - public Map<String, String> getProperties() { - return properties; - } } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectSettingsProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectSettingsProvider.java new file mode 100644 index 00000000000..ec167a39290 --- /dev/null +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectSettingsProvider.java @@ -0,0 +1,46 @@ +/* + * 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.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; + +public class ProjectSettingsProvider extends ProviderAdapter { + + private ProjectSettings projectSettings; + + public ProjectSettings provide(ProjectReactor reactor, GlobalConfiguration globalSettings, ProjectRepositories projectRepositories, AnalysisMode mode) { + if (projectSettings == null) { + + Map<String, String> settings = new LinkedHashMap<>(); + settings.putAll(globalSettings.getProperties()); + settings.putAll(projectRepositories.settings(reactor.getRoot().getKeyWithBranch())); + settings.putAll(reactor.getRoot().properties()); + + projectSettings = new ProjectSettings(globalSettings.getDefinitions(), globalSettings.getEncryption(), mode, settings); + } + return projectSettings; + } +} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/WorkDirectoryCleaner.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/WorkDirectoryCleaner.java index 98dd1d4d77c..607b7bb0397 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/WorkDirectoryCleaner.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/WorkDirectoryCleaner.java @@ -19,15 +19,14 @@ */ package org.sonar.scanner.scan; -import org.sonar.api.batch.bootstrap.ProjectReactor; -import org.sonar.core.util.FileUtils; -import org.sonar.home.cache.DirectoryLock; - import java.io.IOException; import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; import java.util.Iterator; +import org.sonar.api.batch.bootstrap.ProjectReactor; +import org.sonar.core.util.FileUtils; +import org.sonar.home.cache.DirectoryLock; public class WorkDirectoryCleaner { private Path workDir; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/BatchIdGenerator.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/BatchIdGenerator.java index a4142618dbe..087f8445ad3 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/BatchIdGenerator.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/BatchIdGenerator.java @@ -21,7 +21,6 @@ package org.sonar.scanner.scan.filesystem; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Supplier; - import org.sonar.api.batch.fs.InputComponent; /** diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ByteCharsetDetector.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ByteCharsetDetector.java index 6295e44ec62..5dd2657521b 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ByteCharsetDetector.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ByteCharsetDetector.java @@ -19,20 +19,18 @@ */ package org.sonar.scanner.scan.filesystem; -import static java.nio.charset.StandardCharsets.UTF_16; -import static java.nio.charset.StandardCharsets.UTF_16LE; -import static java.nio.charset.StandardCharsets.UTF_16BE; -import static java.nio.charset.StandardCharsets.UTF_8; - import java.nio.charset.Charset; import java.util.Arrays; - import javax.annotation.CheckForNull; - import org.apache.commons.io.ByteOrderMark; import org.sonar.scanner.scan.filesystem.CharsetValidation.Result; import org.sonar.scanner.scan.filesystem.CharsetValidation.Validation; +import static java.nio.charset.StandardCharsets.UTF_16; +import static java.nio.charset.StandardCharsets.UTF_16BE; +import static java.nio.charset.StandardCharsets.UTF_16LE; +import static java.nio.charset.StandardCharsets.UTF_8; + public class ByteCharsetDetector { // these needs to be sorted by longer first! private static final ByteOrderMark[] boms = {ByteOrderMark.UTF_8, ByteOrderMark.UTF_32LE, ByteOrderMark.UTF_32BE, diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/CharsetDetector.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/CharsetDetector.java index a2eb629c1a7..e579f5c47f2 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/CharsetDetector.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/CharsetDetector.java @@ -26,9 +26,7 @@ import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.util.Arrays; - import javax.annotation.CheckForNull; - import org.apache.commons.io.ByteOrderMark; import org.apache.commons.io.IOUtils; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/DefaultModuleFileSystem.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/DefaultModuleFileSystem.java index 43a52aa4de2..e01e5202401 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/DefaultModuleFileSystem.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/DefaultModuleFileSystem.java @@ -28,7 +28,7 @@ import org.apache.commons.lang.StringUtils; import org.sonar.api.CoreProperties; import org.sonar.api.batch.fs.internal.DefaultFileSystem; import org.sonar.api.batch.fs.internal.DefaultInputModule; -import org.sonar.api.config.Settings; +import org.sonar.api.config.Configuration; import org.sonar.api.utils.MessageException; import org.sonar.scanner.analysis.DefaultAnalysisMode; import org.sonar.scanner.repository.ProjectRepositories; @@ -40,7 +40,7 @@ public class DefaultModuleFileSystem extends DefaultFileSystem { private String moduleKey; private FileIndexer indexer; - private Settings settings; + private Configuration settings; private List<File> sourceDirsOrFiles = new ArrayList<>(); private List<File> testDirsOrFiles = new ArrayList<>(); @@ -48,7 +48,7 @@ public class DefaultModuleFileSystem extends DefaultFileSystem { private Charset charset = null; public DefaultModuleFileSystem(ModuleInputComponentStore moduleInputFileCache, DefaultInputModule module, - Settings settings, FileIndexer indexer, ModuleFileSystemInitializer initializer, DefaultAnalysisMode mode, + Configuration settings, FileIndexer indexer, ModuleFileSystemInitializer initializer, DefaultAnalysisMode mode, ProjectRepositories projectRepositories) { super(initializer.baseDir(), moduleInputFileCache); setFields(module, settings, indexer, initializer, mode, projectRepositories); @@ -56,14 +56,14 @@ public class DefaultModuleFileSystem extends DefaultFileSystem { @VisibleForTesting public DefaultModuleFileSystem(DefaultInputModule module, - Settings settings, FileIndexer indexer, ModuleFileSystemInitializer initializer, DefaultAnalysisMode mode, + Configuration settings, FileIndexer indexer, ModuleFileSystemInitializer initializer, DefaultAnalysisMode mode, ProjectRepositories projectRepositories) { super(initializer.baseDir().toPath()); setFields(module, settings, indexer, initializer, mode, projectRepositories); } private void setFields(DefaultInputModule module, - Settings settings, FileIndexer indexer, ModuleFileSystemInitializer initializer, DefaultAnalysisMode mode, + Configuration settings, FileIndexer indexer, ModuleFileSystemInitializer initializer, DefaultAnalysisMode mode, ProjectRepositories projectRepositories) { this.moduleKey = module.key(); this.settings = settings; @@ -97,7 +97,7 @@ public class DefaultModuleFileSystem extends DefaultFileSystem { @Override public Charset encoding() { if (charset == null) { - String encoding = settings.getString(CoreProperties.ENCODING_PROPERTY); + String encoding = settings.get(CoreProperties.ENCODING_PROPERTY).orElse(null); if (StringUtils.isNotEmpty(encoding)) { charset = Charset.forName(StringUtils.trim(encoding)); } else { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java index dad23ab9a19..dd8a32e91e5 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java @@ -19,6 +19,7 @@ */ package org.sonar.scanner.scan.filesystem; +import com.google.common.util.concurrent.ThreadFactoryBuilder; import java.io.File; import java.io.IOException; import java.nio.file.FileSystemLoopException; @@ -40,24 +41,21 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.api.batch.ScannerSide; import org.sonar.api.batch.fs.IndexedFile; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.InputFile.Type; +import org.sonar.api.batch.fs.InputFileFilter; import org.sonar.api.batch.fs.internal.DefaultInputDir; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.scan.filesystem.PathResolver; -import org.sonar.api.batch.fs.InputFileFilter; import org.sonar.api.utils.MessageException; import org.sonar.scanner.scan.DefaultComponentTree; import org.sonar.scanner.util.ProgressReport; -import com.google.common.util.concurrent.ThreadFactoryBuilder; - /** * Index input files into {@link InputComponentStore}. */ diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputFileBuilder.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputFileBuilder.java index 8441b252ba6..c44e24f4942 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputFileBuilder.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputFileBuilder.java @@ -21,16 +21,14 @@ package org.sonar.scanner.scan.filesystem; import java.nio.charset.Charset; import java.nio.file.Path; - import javax.annotation.CheckForNull; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.DefaultIndexedFile; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.fs.internal.DefaultInputModule; -import org.sonar.api.config.Settings; +import org.sonar.api.config.Configuration; import org.sonar.api.scan.filesystem.PathResolver; public class InputFileBuilder { @@ -45,14 +43,14 @@ public class InputFileBuilder { private final boolean preloadMetadata; public InputFileBuilder(DefaultInputModule module, PathResolver pathResolver, LanguageDetection langDetection, MetadataGenerator metadataGenerator, - BatchIdGenerator idGenerator, Settings settings) { + BatchIdGenerator idGenerator, Configuration settings) { this.moduleKey = module.key(); this.moduleBaseDir = module.definition().getBaseDir().toPath(); this.pathResolver = pathResolver; this.langDetection = langDetection; this.metadataGenerator = metadataGenerator; this.idGenerator = idGenerator; - this.preloadMetadata = settings.getBoolean(PRELOAD_FILE_METADATA_KEY); + this.preloadMetadata = settings.getBoolean(PRELOAD_FILE_METADATA_KEY).orElse(false); } @CheckForNull diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/LanguageDetection.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/LanguageDetection.java index 404d50e98aa..828a8403655 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/LanguageDetection.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/LanguageDetection.java @@ -33,7 +33,7 @@ import org.sonar.api.CoreProperties; import org.sonar.api.batch.ScannerSide; import org.sonar.api.batch.fs.internal.DefaultIndexedFile; import org.sonar.api.batch.fs.internal.PathPattern; -import org.sonar.api.config.Settings; +import org.sonar.api.config.Configuration; import org.sonar.api.utils.MessageException; import org.sonar.scanner.repository.language.Language; import org.sonar.scanner.repository.language.LanguagesRepository; @@ -53,7 +53,7 @@ public class LanguageDetection { private final List<String> languagesToConsider = new ArrayList<>(); private final String forcedLanguage; - public LanguageDetection(Settings settings, LanguagesRepository languages) { + public LanguageDetection(Configuration settings, LanguagesRepository languages) { for (Language language : languages.all()) { String[] filePatterns = settings.getStringArray(getFileLangPatternPropKey(language.key())); PathPattern[] pathPatterns = PathPattern.create(filePatterns); @@ -73,7 +73,7 @@ public class LanguageDetection { } } - forcedLanguage = StringUtils.defaultIfBlank(settings.getString(CoreProperties.PROJECT_LANGUAGE_PROPERTY), null); + forcedLanguage = StringUtils.defaultIfBlank(settings.get(CoreProperties.PROJECT_LANGUAGE_PROPERTY).orElse(null), null); // First try with lang patterns if (forcedLanguage != null) { if (!patternsByLanguage.containsKey(forcedLanguage)) { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/MetadataGenerator.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/MetadataGenerator.java index 6c408522a09..f0bfe220d08 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/MetadataGenerator.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/MetadataGenerator.java @@ -19,9 +19,9 @@ */ package org.sonar.scanner.scan.filesystem; +import com.google.common.annotations.VisibleForTesting; import java.io.InputStream; import java.nio.charset.Charset; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.api.batch.fs.InputFile.Type; @@ -31,8 +31,6 @@ import org.sonar.api.batch.fs.internal.FileMetadata; import org.sonar.api.batch.fs.internal.Metadata; import org.sonar.scanner.issue.ignore.scanner.IssueExclusionsLoader; -import com.google.common.annotations.VisibleForTesting; - class MetadataGenerator { private static final Logger LOG = LoggerFactory.getLogger(MetadataGenerator.class); @VisibleForTesting diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/SameInputFilePredicate.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/SameInputFilePredicate.java index bf5206be7ad..629a25161aa 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/SameInputFilePredicate.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/SameInputFilePredicate.java @@ -20,7 +20,6 @@ package org.sonar.scanner.scan.filesystem; import java.util.function.Predicate; - import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/measure/MeasureCache.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/measure/MeasureCache.java index 5c7c1c3d055..f8c8b143853 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/measure/MeasureCache.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/measure/MeasureCache.java @@ -25,8 +25,8 @@ import org.sonar.api.batch.ScannerSide; import org.sonar.api.batch.measure.MetricFinder; import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure; import org.sonar.scanner.storage.Storage; -import org.sonar.scanner.storage.Storages; import org.sonar.scanner.storage.Storage.Entry; +import org.sonar.scanner.storage.Storages; /** * Cache of all measures. This cache is shared amongst all project modules. diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/ConsoleReport.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/ConsoleReport.java index 37898424cd0..fcb9dcac21b 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/ConsoleReport.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/ConsoleReport.java @@ -24,7 +24,7 @@ import org.apache.commons.lang.StringUtils; import org.sonar.api.Properties; import org.sonar.api.Property; import org.sonar.api.PropertyType; -import org.sonar.api.config.Settings; +import org.sonar.api.config.Configuration; import org.sonar.api.rule.Severity; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; @@ -45,12 +45,12 @@ public class ConsoleReport implements Reporter { public static final String CONSOLE_REPORT_ENABLED_KEY = "sonar.issuesReport.console.enable"; private static final int LEFT_PAD = 10; - private Settings settings; + private Configuration settings; private IssueCache issueCache; private InputComponentStore componentStore; @VisibleForTesting - public ConsoleReport(Settings settings, IssueCache issueCache, InputComponentStore componentStore) { + public ConsoleReport(Configuration settings, IssueCache issueCache, InputComponentStore componentStore) { this.settings = settings; this.issueCache = issueCache; this.componentStore = componentStore; @@ -97,7 +97,7 @@ public class ConsoleReport implements Reporter { @Override public void execute() { - if (settings.getBoolean(CONSOLE_REPORT_ENABLED_KEY)) { + if (settings.getBoolean(CONSOLE_REPORT_ENABLED_KEY).orElse(false)) { LOG.warn("Console report is deprecated. Use SonarLint CLI to have local reports of issues"); Report r = new Report(); r.setNoFile(!componentStore.allFilesToPublish().iterator().hasNext()); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/HtmlReport.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/HtmlReport.java index 4be0a717108..c3cd07a90fb 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/HtmlReport.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/HtmlReport.java @@ -38,7 +38,8 @@ import org.sonar.api.Properties; import org.sonar.api.Property; import org.sonar.api.PropertyType; import org.sonar.api.batch.fs.FileSystem; -import org.sonar.api.config.Settings; +import org.sonar.api.config.Configuration; +import org.sonar.api.utils.MessageException; @Properties({ @Property(key = HtmlReport.HTML_REPORT_ENABLED_KEY, defaultValue = "false", name = "Enable HTML report", description = "Set this to true to generate an HTML report", @@ -59,13 +60,13 @@ public class HtmlReport implements Reporter { public static final String HTML_REPORT_NAME_DEFAULT = "issues-report"; public static final String HTML_REPORT_LIGHTMODE_ONLY = "sonar.issuesReport.lightModeOnly"; - private final Settings settings; + private final Configuration settings; private final FileSystem fs; private final IssuesReportBuilder builder; private final SourceProvider sourceProvider; private final RuleNameProvider ruleNameProvider; - public HtmlReport(Settings settings, FileSystem fs, IssuesReportBuilder builder, SourceProvider sourceProvider, RuleNameProvider ruleNameProvider) { + public HtmlReport(Configuration settings, FileSystem fs, IssuesReportBuilder builder, SourceProvider sourceProvider, RuleNameProvider ruleNameProvider) { this.settings = settings; this.fs = fs; this.builder = builder; @@ -75,7 +76,7 @@ public class HtmlReport implements Reporter { @Override public void execute() { - if (settings.getBoolean(HTML_REPORT_ENABLED_KEY)) { + if (settings.getBoolean(HTML_REPORT_ENABLED_KEY).orElse(false)) { LOG.warn("HTML report is deprecated. Use SonarLint CLI to have local reports of issues"); IssuesReport report = builder.buildReport(); print(report); @@ -84,7 +85,7 @@ public class HtmlReport implements Reporter { public void print(IssuesReport report) { File reportFileDir = getReportFileDir(); - String reportName = settings.getString(HTML_REPORT_NAME_KEY); + String reportName = settings.get(HTML_REPORT_NAME_KEY).orElseThrow(() -> MessageException.of("Missing report name. Please set property '" + HTML_REPORT_NAME_KEY + "'")); if (!isLightModeOnly()) { File reportFile = new File(reportFileDir, reportName + ".html"); LOG.debug("Generating HTML Report to: " + reportFile.getAbsolutePath()); @@ -103,7 +104,8 @@ public class HtmlReport implements Reporter { } private File getReportFileDir() { - String reportFileDirStr = settings.getString(HTML_REPORT_LOCATION_KEY); + String reportFileDirStr = settings.get(HTML_REPORT_LOCATION_KEY) + .orElseThrow(() -> MessageException.of("Missing report location. Please set property '" + HTML_REPORT_LOCATION_KEY + "'")); File reportFileDir = new File(reportFileDirStr); if (!reportFileDir.isAbsolute()) { reportFileDir = new File(fs.workDir(), reportFileDirStr); @@ -174,6 +176,6 @@ public class HtmlReport implements Reporter { } public boolean isLightModeOnly() { - return settings.getBoolean(HTML_REPORT_LIGHTMODE_ONLY); + return settings.getBoolean(HTML_REPORT_LIGHTMODE_ONLY).orElse(false); } } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/IssuesReport.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/IssuesReport.java index 45224ef7dab..11143b41e71 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/IssuesReport.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/IssuesReport.java @@ -24,7 +24,6 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; - import org.sonar.api.batch.fs.InputComponent; import org.sonar.api.batch.rule.Rule; import org.sonar.api.rules.RulePriority; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/JSONReport.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/JSONReport.java index c7079a019ce..1b821a22e7b 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/JSONReport.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/JSONReport.java @@ -46,7 +46,7 @@ import org.sonar.api.batch.fs.internal.InputComponentTree; import org.sonar.api.batch.fs.internal.InputModuleHierarchy; import org.sonar.api.batch.rule.Rule; import org.sonar.api.batch.rule.Rules; -import org.sonar.api.config.Settings; +import org.sonar.api.config.Configuration; import org.sonar.api.platform.Server; import org.sonar.api.rule.RuleKey; import org.sonar.api.utils.text.JsonWriter; @@ -65,7 +65,7 @@ public class JSONReport implements Reporter { static final String SONAR_REPORT_EXPORT_PATH = "sonar.report.export.path"; private static final Logger LOG = LoggerFactory.getLogger(JSONReport.class); - private final Settings settings; + private final Configuration settings; private final FileSystem fileSystem; private final Server server; private final Rules rules; @@ -75,7 +75,7 @@ public class JSONReport implements Reporter { private final InputModuleHierarchy moduleHierarchy; private final InputComponentTree inputComponentTree; - public JSONReport(InputModuleHierarchy moduleHierarchy, Settings settings, FileSystem fileSystem, Server server, Rules rules, IssueCache issueCache, + public JSONReport(InputModuleHierarchy moduleHierarchy, Configuration settings, FileSystem fileSystem, Server server, Rules rules, IssueCache issueCache, DefaultInputModule rootModule, InputComponentStore componentStore, InputComponentTree inputComponentTree) { this.moduleHierarchy = moduleHierarchy; this.settings = settings; @@ -90,10 +90,7 @@ public class JSONReport implements Reporter { @Override public void execute() { - String exportPath = settings.getString(SONAR_REPORT_EXPORT_PATH); - if (exportPath != null) { - exportResults(exportPath); - } + settings.get(SONAR_REPORT_EXPORT_PATH).ifPresent(this::exportResults); } private void exportResults(String exportPath) { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/ReportRuleKey.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/ReportRuleKey.java index 3783e4d1f81..2af99f07bb9 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/ReportRuleKey.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/ReportRuleKey.java @@ -19,10 +19,9 @@ */ package org.sonar.scanner.scan.report; -import org.sonar.api.batch.rule.Rule; - import org.apache.commons.lang.ObjectUtils; import org.apache.commons.lang.builder.ToStringBuilder; +import org.sonar.api.batch.rule.Rule; import org.sonar.api.rules.RulePriority; /** diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/ResourceReport.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/ResourceReport.java index d7402233f71..c3c93bfb461 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/ResourceReport.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/ResourceReport.java @@ -27,7 +27,6 @@ import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import javax.annotation.Nullable; - import org.sonar.api.batch.fs.InputComponent; import org.sonar.api.batch.fs.InputDir; import org.sonar.api.batch.fs.InputFile; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/RuleNameProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/RuleNameProvider.java index 2ffcabdbaf2..eaaf9b00b0e 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/RuleNameProvider.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/RuleNameProvider.java @@ -19,15 +19,13 @@ */ package org.sonar.scanner.scan.report; -import org.sonar.api.batch.rule.Rule; - -import org.sonar.api.batch.rule.Rules; +import javax.annotation.CheckForNull; import org.apache.commons.lang.StringEscapeUtils; import org.sonar.api.batch.ScannerSide; +import org.sonar.api.batch.rule.Rule; +import org.sonar.api.batch.rule.Rules; import org.sonar.api.rule.RuleKey; -import javax.annotation.CheckForNull; - @ScannerSide public class RuleNameProvider { private Rules rules; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/RuleReport.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/RuleReport.java index 8b3231fbf41..528a372eb52 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/RuleReport.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/RuleReport.java @@ -19,9 +19,8 @@ */ package org.sonar.scanner.scan.report; -import org.sonar.api.batch.rule.Rule; - import org.apache.commons.lang.builder.ToStringBuilder; +import org.sonar.api.batch.rule.Rule; public final class RuleReport { private final ReportRuleKey reportRuleKey; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/DefaultBlameOutput.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/DefaultBlameOutput.java index 3d81b49d250..5311b807330 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/DefaultBlameOutput.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/DefaultBlameOutput.java @@ -36,8 +36,8 @@ import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; import org.sonar.scanner.protocol.output.ScannerReport; import org.sonar.scanner.protocol.output.ScannerReport.Changesets.Builder; -import org.sonar.scanner.util.ProgressReport; import org.sonar.scanner.protocol.output.ScannerReportWriter; +import org.sonar.scanner.util.ProgressReport; class DefaultBlameOutput implements BlameOutput { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/ScmConfiguration.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/ScmConfiguration.java index 883d8207225..68c75b647a6 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/ScmConfiguration.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/ScmConfiguration.java @@ -29,10 +29,10 @@ import org.sonar.api.Properties; import org.sonar.api.Property; import org.sonar.api.PropertyType; import org.sonar.api.batch.AnalysisMode; -import org.sonar.api.batch.ScannerSide; import org.sonar.api.batch.InstantiationStrategy; +import org.sonar.api.batch.ScannerSide; import org.sonar.api.batch.scm.ScmProvider; -import org.sonar.api.config.Settings; +import org.sonar.api.config.Configuration; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; import org.sonar.scanner.scan.ImmutableProjectReactor; @@ -57,13 +57,13 @@ public final class ScmConfiguration implements Startable { public static final String FORCE_RELOAD_KEY = "sonar.scm.forceReloadAll"; private final ImmutableProjectReactor projectReactor; - private final Settings settings; + private final Configuration settings; private final Map<String, ScmProvider> providerPerKey = new LinkedHashMap<>(); private final AnalysisMode analysisMode; private ScmProvider provider; - public ScmConfiguration(ImmutableProjectReactor projectReactor, AnalysisMode analysisMode, Settings settings, ScmProvider... providers) { + public ScmConfiguration(ImmutableProjectReactor projectReactor, AnalysisMode analysisMode, Configuration settings, ScmProvider... providers) { this.projectReactor = projectReactor; this.analysisMode = analysisMode; this.settings = settings; @@ -72,7 +72,7 @@ public final class ScmConfiguration implements Startable { } } - public ScmConfiguration(ImmutableProjectReactor projectReactor, AnalysisMode analysisMode, Settings settings) { + public ScmConfiguration(ImmutableProjectReactor projectReactor, AnalysisMode analysisMode, Configuration settings) { this(projectReactor, analysisMode, settings, new ScmProvider[0]); } @@ -86,8 +86,7 @@ public final class ScmConfiguration implements Startable { return; } if (settings.hasKey(CoreProperties.SCM_PROVIDER_KEY)) { - String forcedProviderKey = settings.getString(CoreProperties.SCM_PROVIDER_KEY); - setProviderIfSupported(forcedProviderKey); + settings.get(CoreProperties.SCM_PROVIDER_KEY).ifPresent(this::setProviderIfSupported); } else { autodetection(); if (this.provider == null) { @@ -110,16 +109,14 @@ public final class ScmConfiguration implements Startable { } private void considerOldScmUrl() { - if (settings.hasKey(CoreProperties.LINKS_SOURCES_DEV)) { - String url = settings.getString(CoreProperties.LINKS_SOURCES_DEV); + settings.get(CoreProperties.LINKS_SOURCES_DEV).ifPresent(url -> { if (StringUtils.startsWith(url, "scm:")) { String[] split = url.split(":"); if (split.length > 1) { setProviderIfSupported(split[1]); } } - } - + }); } private void autodetection() { @@ -140,11 +137,11 @@ public final class ScmConfiguration implements Startable { } public boolean isDisabled() { - return settings.getBoolean(CoreProperties.SCM_DISABLED_KEY); + return settings.getBoolean(CoreProperties.SCM_DISABLED_KEY).orElse(false); } public boolean forceReloadAll() { - return settings.getBoolean(FORCE_RELOAD_KEY); + return settings.getBoolean(FORCE_RELOAD_KEY).orElse(false); } @Override diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/ScmPublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/ScmPublisher.java index a0d6e89338c..28d8a400b61 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/ScmPublisher.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/ScmPublisher.java @@ -32,9 +32,9 @@ import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; import org.sonar.scanner.protocol.output.ScannerReport; +import org.sonar.scanner.protocol.output.ScannerReport.Changesets.Builder; import org.sonar.scanner.protocol.output.ScannerReportWriter; import org.sonar.scanner.report.ReportPublisher; -import org.sonar.scanner.protocol.output.ScannerReport.Changesets.Builder; import org.sonar.scanner.repository.FileData; import org.sonar.scanner.repository.ProjectRepositories; import org.sonar.scanner.scan.filesystem.DefaultModuleFileSystem; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorContext.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorContext.java index 3a300a7196e..9467d96829a 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorContext.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorContext.java @@ -42,6 +42,7 @@ import org.sonar.api.batch.sensor.measure.NewMeasure; import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure; import org.sonar.api.batch.sensor.symbol.NewSymbolTable; import org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable; +import org.sonar.api.config.Configuration; import org.sonar.api.config.Settings; import org.sonar.api.utils.Version; import org.sonar.scanner.sensor.noop.NoOpNewAnalysisError; @@ -56,18 +57,21 @@ public class DefaultSensorContext implements SensorContext { private static final NoOpNewCpdTokens NO_OP_NEW_CPD_TOKENS = new NoOpNewCpdTokens(); private static final NoOpNewAnalysisError NO_OP_NEW_ANALYSIS_ERROR = new NoOpNewAnalysisError(); - private final Settings settings; + private final Settings mutableSettings; private final FileSystem fs; private final ActiveRules activeRules; private final SensorStorage sensorStorage; private final AnalysisMode analysisMode; private final InputModule module; private final SonarRuntime sonarRuntime; + private final Configuration config; - public DefaultSensorContext(InputModule module, Settings settings, FileSystem fs, ActiveRules activeRules, AnalysisMode analysisMode, SensorStorage sensorStorage, + public DefaultSensorContext(InputModule module, Configuration config, Settings mutableSettings, FileSystem fs, ActiveRules activeRules, + AnalysisMode analysisMode, SensorStorage sensorStorage, SonarRuntime sonarRuntime) { this.module = module; - this.settings = settings; + this.config = config; + this.mutableSettings = mutableSettings; this.fs = fs; this.activeRules = activeRules; this.analysisMode = analysisMode; @@ -77,7 +81,12 @@ public class DefaultSensorContext implements SensorContext { @Override public Settings settings() { - return settings; + return mutableSettings; + } + + @Override + public Configuration config() { + return config; } @Override @@ -141,7 +150,7 @@ public class DefaultSensorContext implements SensorContext { if (analysisMode.isIssues()) { return NO_OP_NEW_CPD_TOKENS; } - return new DefaultCpdTokens(settings, sensorStorage); + return new DefaultCpdTokens(config, sensorStorage); } @Override diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorStorage.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorStorage.java index 096732cc304..ac966c2a855 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorStorage.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorStorage.java @@ -45,7 +45,7 @@ import org.sonar.api.batch.sensor.issue.Issue; import org.sonar.api.batch.sensor.measure.Measure; import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure; import org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable; -import org.sonar.api.config.Settings; +import org.sonar.api.config.Configuration; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.utils.KeyValueFormat; import org.sonar.api.utils.log.Logger; @@ -146,7 +146,7 @@ public class DefaultSensorStorage implements SensorStorage { private final MeasureCache measureCache; private final SonarCpdBlockIndex index; private final ContextPropertiesCache contextPropertiesCache; - private final Settings settings; + private final Configuration settings; private final ScannerMetrics scannerMetrics; private final Map<Metric<?>, Metric<?>> deprecatedCoverageMetricMapping = new HashMap<>(); private final Set<Metric<?>> coverageMetrics = new HashSet<>(); @@ -154,7 +154,7 @@ public class DefaultSensorStorage implements SensorStorage { private Set<String> alreadyLogged = new HashSet<>(); public DefaultSensorStorage(MetricFinder metricFinder, ModuleIssues moduleIssues, - Settings settings, + Configuration settings, CoverageExclusions coverageExclusions, ReportPublisher reportPublisher, MeasureCache measureCache, SonarCpdBlockIndex index, ContextPropertiesCache contextPropertiesCache, ScannerMetrics scannerMetrics) { @@ -221,7 +221,7 @@ public class DefaultSensorStorage implements SensorStorage { if (component.isFile()) { ((DefaultInputFile) component).setPublish(true); } - + if (isDeprecatedMetric(measure.metric().key())) { logOnce(measure.metric().key(), "Metric '{}' is deprecated. Provided value is ignored.", measure.metric().key()); return; @@ -452,11 +452,7 @@ public class DefaultSensorStorage implements SensorStorage { @VisibleForTesting int getBlockSize(String languageKey) { - int blockSize = settings.getInt("sonar.cpd." + languageKey + ".minimumLines"); - if (blockSize == 0) { - blockSize = DefaultCpdBlockIndexer.getDefaultBlockSize(languageKey); - } - return blockSize; + return settings.getInt("sonar.cpd." + languageKey + ".minimumLines").orElse(DefaultCpdBlockIndexer.getDefaultBlockSize(languageKey)); } @Override diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/SensorOptimizer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/SensorOptimizer.java index 68f38565d23..8f8907dbb9a 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/SensorOptimizer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/SensorOptimizer.java @@ -26,7 +26,7 @@ import org.sonar.api.batch.fs.FilePredicate; import org.sonar.api.batch.fs.FileSystem; import org.sonar.api.batch.rule.ActiveRules; import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor; -import org.sonar.api.config.Settings; +import org.sonar.api.config.Configuration; @ScannerSide public class SensorOptimizer { @@ -35,12 +35,12 @@ public class SensorOptimizer { private final FileSystem fs; private final ActiveRules activeRules; - private final Settings settings; + private final Configuration config; - public SensorOptimizer(FileSystem fs, ActiveRules activeRules, Settings settings) { + public SensorOptimizer(FileSystem fs, ActiveRules activeRules, Configuration config) { this.fs = fs; this.activeRules = activeRules; - this.settings = settings; + this.config = config; } /** @@ -65,7 +65,7 @@ public class SensorOptimizer { private boolean settingsCondition(DefaultSensorDescriptor descriptor) { if (!descriptor.properties().isEmpty()) { for (String propertyKey : descriptor.properties()) { - if (!settings.hasKey(propertyKey)) { + if (!config.hasKey(propertyKey)) { return false; } } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/coverage/CoverageExclusions.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/coverage/CoverageExclusions.java index d909dfe81bf..490f067d764 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/coverage/CoverageExclusions.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/coverage/CoverageExclusions.java @@ -29,17 +29,17 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.api.CoreProperties; import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.config.Settings; +import org.sonar.api.config.Configuration; import org.sonar.api.utils.WildcardPattern; public class CoverageExclusions implements Startable { private static final Logger LOG = LoggerFactory.getLogger(CoverageExclusions.class); - private final Settings settings; + private final Configuration settings; private Collection<WildcardPattern> exclusionPatterns; - public CoverageExclusions(Settings settings) { + public CoverageExclusions(Configuration settings) { this.settings = settings; } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/source/ZeroCoverageSensor.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/source/ZeroCoverageSensor.java index 446fbd4089b..47f10cabe8f 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/source/ZeroCoverageSensor.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/source/ZeroCoverageSensor.java @@ -19,11 +19,11 @@ */ package org.sonar.scanner.source; +import com.google.common.collect.Sets; import java.util.Map; import java.util.Set; import java.util.function.Function; import java.util.stream.StreamSupport; - import org.sonar.api.batch.Phase; import org.sonar.api.batch.fs.FileSystem; import org.sonar.api.batch.fs.InputFile; @@ -41,8 +41,6 @@ import org.sonar.core.util.stream.MoreCollectors; import org.sonar.scanner.scan.measure.MeasureCache; import org.sonar.scanner.sensor.coverage.CoverageExclusions; -import com.google.common.collect.Sets; - @Phase(name = Phase.Name.POST) public final class ZeroCoverageSensor implements Sensor { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/storage/Storages.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/storage/Storages.java index 776e76f3e85..ca307cfa8ac 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/storage/Storages.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/storage/Storages.java @@ -27,7 +27,6 @@ import com.persistit.Volume; import com.persistit.encoding.CoderManager; import com.persistit.encoding.ValueCoder; import com.persistit.exception.PersistitException; - import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/task/TaskContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/task/TaskContainer.java index 3591d7788da..477bd4d2d83 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/task/TaskContainer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/task/TaskContainer.java @@ -23,7 +23,6 @@ import java.util.Map; import org.apache.commons.lang.StringUtils; import org.sonar.api.CoreProperties; import org.sonar.api.batch.InstantiationStrategy; -import org.sonar.api.config.EmailSettings; import org.sonar.api.task.Task; import org.sonar.api.task.TaskDefinition; import org.sonar.api.utils.MessageException; @@ -55,7 +54,6 @@ public class TaskContainer extends ComponentContainer { private void addCoreComponents() { add(new TaskProperties(taskProperties, getParent().getComponentByType(GlobalProperties.class).property(CoreProperties.ENCRYPTION_SECRET_KEY_PATH))); - add(EmailSettings.class); } private void addTaskExtensions() { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/task/Tasks.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/task/Tasks.java index 0b19a508fc9..a674649b6ba 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/task/Tasks.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/task/Tasks.java @@ -24,8 +24,8 @@ import com.google.common.collect.Maps; import java.util.Collection; import java.util.Map; import java.util.SortedMap; -import org.sonar.api.batch.ScannerSide; import org.sonar.api.batch.InstantiationStrategy; +import org.sonar.api.batch.ScannerSide; import org.sonar.api.task.Task; import org.sonar.api.task.TaskDefinition; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrapper/BatchTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrapper/BatchTest.java index 5709fd8d33f..fd0f6842150 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrapper/BatchTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrapper/BatchTest.java @@ -20,9 +20,6 @@ package org.sonar.batch.bootstrapper; import org.junit.Test; -import org.sonar.batch.bootstrapper.Batch; -import org.sonar.batch.bootstrapper.EnvironmentInformation; -import org.sonar.batch.bootstrapper.LogOutput; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertNotNull; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrapper/EnvironmentInformationTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrapper/EnvironmentInformationTest.java index 45e5aef44aa..a5a53519833 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrapper/EnvironmentInformationTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrapper/EnvironmentInformationTest.java @@ -20,7 +20,6 @@ package org.sonar.batch.bootstrapper; import org.junit.Test; -import org.sonar.batch.bootstrapper.EnvironmentInformation; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrapper/LogCallbackAppenderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrapper/LogCallbackAppenderTest.java index bdd9ec58f96..3baa1d2c240 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrapper/LogCallbackAppenderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrapper/LogCallbackAppenderTest.java @@ -23,8 +23,6 @@ import ch.qos.logback.classic.Level; import ch.qos.logback.classic.spi.ILoggingEvent; import org.junit.Before; import org.junit.Test; -import org.sonar.batch.bootstrapper.LogCallbackAppender; -import org.sonar.batch.bootstrapper.LogOutput; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/ProjectAnalysisInfoTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/ProjectAnalysisInfoTest.java index 71ce99fca72..0e0cdb0f3f5 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/ProjectAnalysisInfoTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/ProjectAnalysisInfoTest.java @@ -19,27 +19,25 @@ */ package org.sonar.scanner; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; - import java.time.LocalDate; import java.time.ZoneId; import java.util.Date; - import org.junit.Test; import org.sonar.api.CoreProperties; -import org.sonar.api.config.MapSettings; -import org.sonar.api.config.Settings; +import org.sonar.api.config.internal.MapSettings; import org.sonar.api.utils.System2; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; + public class ProjectAnalysisInfoTest { @Test public void testSimpleDate() { - Settings settings = new MapSettings(); + MapSettings settings = new MapSettings(); settings.appendProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2017-01-01"); settings.appendProperty(CoreProperties.PROJECT_VERSION_PROPERTY, "version"); System2 system = mock(System2.class); - ProjectAnalysisInfo info = new ProjectAnalysisInfo(settings, system); + ProjectAnalysisInfo info = new ProjectAnalysisInfo(settings.asConfig(), system); info.start(); LocalDate date = LocalDate.of(2017, 1, 1); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/WsTestUtil.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/WsTestUtil.java index 88b2c7d05eb..694830ad918 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/WsTestUtil.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/WsTestUtil.java @@ -19,6 +19,8 @@ */ package org.sonar.scanner; +import java.io.InputStream; +import java.io.Reader; import org.apache.commons.lang.StringUtils; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; @@ -26,9 +28,6 @@ import org.sonar.scanner.bootstrap.ScannerWsClient; import org.sonarqube.ws.client.WsRequest; import org.sonarqube.ws.client.WsResponse; -import java.io.InputStream; -import java.io.Reader; - import static org.mockito.Matchers.any; import static org.mockito.Matchers.argThat; import static org.mockito.Mockito.mock; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/analysis/AnalysisTempFolderProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/analysis/AnalysisTempFolderProviderTest.java index c7ff8309577..60a8f7140bb 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/analysis/AnalysisTempFolderProviderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/analysis/AnalysisTempFolderProviderTest.java @@ -19,22 +19,19 @@ */ package org.sonar.scanner.analysis; -import org.sonar.api.batch.bootstrap.ProjectDefinition; - -import org.sonar.api.batch.bootstrap.ProjectReactor; +import java.io.File; +import java.io.IOException; import org.junit.Before; -import org.sonar.api.utils.TempFolder; -import org.sonar.scanner.analysis.AnalysisTempFolderProvider; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; +import org.sonar.api.batch.bootstrap.ProjectDefinition; +import org.sonar.api.batch.bootstrap.ProjectReactor; +import org.sonar.api.utils.TempFolder; -import java.io.File; -import java.io.IOException; - -import static org.mockito.Mockito.when; -import static org.mockito.Mockito.mock; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class AnalysisTempFolderProviderTest { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/analysis/DefaultAnalysisModeTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/analysis/DefaultAnalysisModeTest.java index 095da114e93..b7544e1f0ce 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/analysis/DefaultAnalysisModeTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/analysis/DefaultAnalysisModeTest.java @@ -19,16 +19,14 @@ */ package org.sonar.scanner.analysis; -import org.junit.Rule; -import org.junit.rules.ExpectedException; +import java.util.HashMap; +import java.util.Map; import javax.annotation.Nullable; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.sonar.api.CoreProperties; -import org.sonar.scanner.analysis.AnalysisProperties; -import org.sonar.scanner.analysis.DefaultAnalysisMode; import org.sonar.scanner.bootstrap.GlobalProperties; -import java.util.HashMap; -import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/DroppedPropertyCheckerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/DroppedPropertyCheckerTest.java index 8126f43c29a..e4d9168a288 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/DroppedPropertyCheckerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/DroppedPropertyCheckerTest.java @@ -24,7 +24,6 @@ import org.junit.Rule; import org.junit.Test; import org.sonar.api.utils.log.LogTester; import org.sonar.api.utils.log.LoggerLevel; -import org.sonar.scanner.bootstrap.DroppedPropertyChecker; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ExtensionUtilsTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ExtensionUtilsTest.java index 2c867b61bce..8b2baaf57e1 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ExtensionUtilsTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ExtensionUtilsTest.java @@ -26,7 +26,6 @@ import org.sonar.api.batch.InstantiationStrategy; import org.sonar.api.batch.ScannerSide; import org.sonar.api.ce.ComputeEngineSide; import org.sonar.api.server.ServerSide; -import org.sonar.scanner.bootstrap.ExtensionUtils; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/FileCacheProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/FileCacheProviderTest.java index 06bde834a69..f86ef04f4a2 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/FileCacheProviderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/FileCacheProviderTest.java @@ -24,8 +24,7 @@ import java.io.IOException; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import org.sonar.api.config.Settings; -import org.sonar.api.config.MapSettings; +import org.sonar.api.config.internal.MapSettings; import org.sonar.home.cache.FileCache; import static org.assertj.core.api.Assertions.assertThat; @@ -37,7 +36,7 @@ public class FileCacheProviderTest { @Test public void provide() { FileCacheProvider provider = new FileCacheProvider(); - FileCache cache = provider.provide(new MapSettings()); + FileCache cache = provider.provide(new MapSettings().asConfig()); assertThat(cache).isNotNull(); assertThat(cache.getDir()).isNotNull().exists(); @@ -46,9 +45,9 @@ public class FileCacheProviderTest { @Test public void keep_singleton_instance() { FileCacheProvider provider = new FileCacheProvider(); - Settings settings = new MapSettings(); - FileCache cache1 = provider.provide(settings); - FileCache cache2 = provider.provide(settings); + MapSettings settings = new MapSettings(); + FileCache cache1 = provider.provide(settings.asConfig()); + FileCache cache2 = provider.provide(settings.asConfig()); assertThat(cache1).isSameAs(cache2); } @@ -56,10 +55,10 @@ public class FileCacheProviderTest { @Test public void honor_sonarUserHome() throws IOException { FileCacheProvider provider = new FileCacheProvider(); - Settings settings = new MapSettings(); + MapSettings settings = new MapSettings(); File f = temp.newFolder(); settings.appendProperty("sonar.userHome", f.getAbsolutePath()); - FileCache cache = provider.provide(settings); + FileCache cache = provider.provide(settings.asConfig()); assertThat(cache.getDir()).isEqualTo(new File(f, "cache")); } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalSettingsTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalConfigurationProviderTest.java index 7d9bf07ab0a..0ee71d91ecf 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalSettingsTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalConfigurationProviderTest.java @@ -34,7 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class GlobalSettingsTest { +public class GlobalConfigurationProviderTest { public static final String SOME_VALUE = "some_value"; @Rule @@ -58,9 +58,9 @@ public class GlobalSettingsTest { public void should_load_global_settings() { when(settingsLoader.load(null)).thenReturn(ImmutableMap.of("sonar.cpd.cross", "true")); - GlobalSettings batchSettings = new GlobalSettings(bootstrapProps, new PropertyDefinitions(), settingsLoader, mode); + GlobalConfiguration globalConfig = new GlobalConfigurationProvider().provide(settingsLoader, bootstrapProps, new PropertyDefinitions(), mode); - assertThat(batchSettings.getBoolean("sonar.cpd.cross")).isTrue(); + assertThat(globalConfig.get("sonar.cpd.cross")).hasValue("true"); } @Test @@ -69,7 +69,7 @@ public class GlobalSettingsTest { "sonar.jdbc.username", SOME_VALUE, "sonar.jdbc.password", SOME_VALUE)); - new GlobalSettings(bootstrapProps, new PropertyDefinitions(), settingsLoader, mode); + new GlobalConfigurationProvider().provide(settingsLoader, bootstrapProps, new PropertyDefinitions(), mode); assertThat(logTester.logs(LoggerLevel.WARN)).containsOnly( "Property 'sonar.jdbc.url' is not supported any more. It will be ignored. There is no longer any DB connection to the SQ database.", diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalContainerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalContainerTest.java index 7333a707144..26e8d1e912f 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalContainerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalContainerTest.java @@ -31,7 +31,6 @@ import org.sonar.api.CoreProperties; import org.sonar.api.batch.BatchSide; import org.sonar.api.utils.TempFolder; import org.sonar.core.util.UuidFactory; -import org.sonar.scanner.bootstrap.GlobalContainer; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalModeTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalModeTest.java index 4bbab8408f7..fed2ba5aa92 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalModeTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalModeTest.java @@ -19,15 +19,12 @@ */ 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 org.sonar.scanner.bootstrap.GlobalMode; -import org.sonar.scanner.bootstrap.GlobalProperties; -import org.junit.Test; - -import java.util.HashMap; -import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalPropertiesTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalPropertiesTest.java index d6f544b1a6c..d459e7303b6 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalPropertiesTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalPropertiesTest.java @@ -20,9 +20,8 @@ package org.sonar.scanner.bootstrap; import com.google.common.collect.Maps; -import org.junit.Test; -import org.sonar.scanner.bootstrap.GlobalProperties; import java.util.Map; +import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalTempFolderProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalTempFolderProviderTest.java index 23218bf7092..5585545241b 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalTempFolderProviderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalTempFolderProviderTest.java @@ -19,14 +19,7 @@ */ package org.sonar.scanner.bootstrap; -import org.sonar.api.utils.System2; -import org.apache.commons.io.FileUtils; -import org.sonar.api.utils.TempFolder; -import org.sonar.scanner.bootstrap.GlobalProperties; -import org.sonar.scanner.bootstrap.GlobalTempFolderProvider; import com.google.common.collect.ImmutableMap; -import org.sonar.api.CoreProperties; - import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -34,13 +27,17 @@ import java.nio.file.attribute.BasicFileAttributeView; import java.nio.file.attribute.FileTime; import java.util.Collections; import java.util.concurrent.TimeUnit; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import static org.assertj.core.api.Assertions.assertThat; +import org.apache.commons.io.FileUtils; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; +import org.sonar.api.CoreProperties; +import org.sonar.api.utils.System2; +import org.sonar.api.utils.TempFolder; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class GlobalTempFolderProviderTest { @Rule diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/MetricProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/MetricProviderTest.java index 2babecd6585..88555e6775b 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/MetricProviderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/MetricProviderTest.java @@ -19,13 +19,12 @@ */ package org.sonar.scanner.bootstrap; +import java.util.Arrays; +import java.util.List; import org.junit.Test; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Metric; import org.sonar.api.measures.Metrics; -import org.sonar.scanner.bootstrap.MetricProvider; -import java.util.Arrays; -import java.util.List; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginJarExploderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginJarExploderTest.java index f5f7f20f684..3f799a74815 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginJarExploderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginJarExploderTest.java @@ -30,8 +30,6 @@ import org.sonar.core.platform.ExplodedPlugin; import org.sonar.core.platform.PluginInfo; import org.sonar.home.cache.FileCache; import org.sonar.home.cache.FileCacheBuilder; -import org.sonar.scanner.bootstrap.ScannerPluginJarExploder; -import org.sonar.scanner.bootstrap.Slf4jLogger; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginPredicateTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginPredicateTest.java index fbc7ee0f4ea..6ae96de59e8 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginPredicateTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginPredicateTest.java @@ -21,8 +21,7 @@ package org.sonar.scanner.bootstrap; import org.junit.Test; import org.sonar.api.CoreProperties; -import org.sonar.api.config.Settings; -import org.sonar.api.config.MapSettings; +import org.sonar.api.config.internal.MapSettings; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -30,12 +29,12 @@ import static org.mockito.Mockito.when; public class ScannerPluginPredicateTest { - Settings settings = new MapSettings(); - GlobalMode mode = mock(GlobalMode.class); + private MapSettings settings = new MapSettings(); + private GlobalMode mode = mock(GlobalMode.class); @Test public void accept_if_no_inclusions_nor_exclusions() { - ScannerPluginPredicate predicate = new ScannerPluginPredicate(settings, mode); + ScannerPluginPredicate predicate = new ScannerPluginPredicate(settings.asConfig(), mode); assertThat(predicate.getWhites()).isEmpty(); assertThat(predicate.getBlacks()).isEmpty(); assertThat(predicate.apply("pmd")).isTrue(); @@ -45,7 +44,7 @@ public class ScannerPluginPredicateTest { @Test public void exclude_buildbreaker_in_preview_mode() { when(mode.isPreview()).thenReturn(true); - ScannerPluginPredicate predicate = new ScannerPluginPredicate(settings, mode); + ScannerPluginPredicate predicate = new ScannerPluginPredicate(settings.asConfig(), mode); assertThat(predicate.apply("buildbreaker")).isFalse(); } @@ -55,7 +54,7 @@ public class ScannerPluginPredicateTest { settings .setProperty(CoreProperties.PREVIEW_INCLUDE_PLUGINS, "checkstyle,pmd,findbugs") .setProperty(CoreProperties.PREVIEW_EXCLUDE_PLUGINS, "cobertura,pmd"); - ScannerPluginPredicate predicate = new ScannerPluginPredicate(settings, mode); + ScannerPluginPredicate predicate = new ScannerPluginPredicate(settings.asConfig(), mode); assertThat(predicate.apply("pmd")).isTrue(); } @@ -65,7 +64,7 @@ public class ScannerPluginPredicateTest { settings .setProperty(CoreProperties.PREVIEW_INCLUDE_PLUGINS, "checkstyle,pmd,findbugs") .setProperty(CoreProperties.PREVIEW_EXCLUDE_PLUGINS, "cobertura"); - ScannerPluginPredicate predicate = new ScannerPluginPredicate(settings, mode); + ScannerPluginPredicate predicate = new ScannerPluginPredicate(settings.asConfig(), mode); assertThat(predicate.apply("checkstyle")).isTrue(); assertThat(predicate.apply("pmd")).isTrue(); assertThat(predicate.apply("cobertura")).isFalse(); @@ -77,7 +76,7 @@ public class ScannerPluginPredicateTest { settings .setProperty(CoreProperties.PREVIEW_INCLUDE_PLUGINS, "checkstyle,pmd,findbugs") .setProperty(CoreProperties.PREVIEW_EXCLUDE_PLUGINS, "cobertura"); - ScannerPluginPredicate predicate = new ScannerPluginPredicate(settings, mode); + ScannerPluginPredicate predicate = new ScannerPluginPredicate(settings.asConfig(), mode); assertThat(predicate.apply("checkstyle")).isTrue(); assertThat(predicate.apply("pmd")).isTrue(); assertThat(predicate.apply("cobertura")).isFalse(); @@ -87,7 +86,7 @@ public class ScannerPluginPredicateTest { public void test_exclusions_without_any_inclusions() { when(mode.isPreview()).thenReturn(true); settings.setProperty(CoreProperties.PREVIEW_EXCLUDE_PLUGINS, "checkstyle,pmd,findbugs"); - ScannerPluginPredicate predicate = new ScannerPluginPredicate(settings, mode); + ScannerPluginPredicate predicate = new ScannerPluginPredicate(settings.asConfig(), mode); assertThat(predicate.apply("checkstyle")).isFalse(); assertThat(predicate.apply("pmd")).isFalse(); assertThat(predicate.apply("cobertura")).isTrue(); @@ -98,7 +97,7 @@ public class ScannerPluginPredicateTest { settings .setProperty(CoreProperties.PREVIEW_INCLUDE_PLUGINS, "checkstyle, pmd, findbugs") .setProperty(CoreProperties.PREVIEW_EXCLUDE_PLUGINS, "cobertura, pmd"); - ScannerPluginPredicate predicate = new ScannerPluginPredicate(settings, mode); + ScannerPluginPredicate predicate = new ScannerPluginPredicate(settings.asConfig(), mode); assertThat(predicate.apply("pmd")).isTrue(); } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginRepositoryTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginRepositoryTest.java index 9750e7cec60..967c5c8f351 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginRepositoryTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginRepositoryTest.java @@ -24,8 +24,6 @@ import org.junit.Test; import org.sonar.api.Plugin; import org.sonar.core.platform.PluginInfo; import org.sonar.core.platform.PluginLoader; -import org.sonar.scanner.bootstrap.ScannerPluginRepository; -import org.sonar.scanner.bootstrap.PluginInstaller; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdComponentsTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdComponentsTest.java index 465200012bf..e885192a59f 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdComponentsTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdComponentsTest.java @@ -20,7 +20,6 @@ package org.sonar.scanner.cpd; import org.junit.Test; -import org.sonar.scanner.cpd.CpdComponents; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdExecutorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdExecutorTest.java index 708f5ac97bc..e46702cb90e 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdExecutorTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdExecutorTest.java @@ -33,8 +33,7 @@ import org.junit.rules.TemporaryFolder; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; -import org.sonar.api.config.MapSettings; -import org.sonar.api.config.Settings; +import org.sonar.api.config.internal.MapSettings; import org.sonar.api.scan.filesystem.PathResolver; import org.sonar.api.utils.log.LogTester; import org.sonar.api.utils.log.LoggerLevel; @@ -56,11 +55,6 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; public class CpdExecutorTest { - private CpdExecutor executor; - private Settings settings; - private SonarCpdBlockIndex index; - private ReportPublisher publisher; - @Rule public LogTester logTester = new LogTester(); @@ -70,6 +64,10 @@ public class CpdExecutorTest { @Rule public ExpectedException thrown = ExpectedException.none(); + private CpdExecutor executor; + private MapSettings settings; + private SonarCpdBlockIndex index; + private ReportPublisher publisher; private ScannerReportReader reader; private DefaultInputFile batchComponent1; private DefaultInputFile batchComponent2; @@ -85,9 +83,9 @@ public class CpdExecutorTest { settings = new MapSettings(); publisher = mock(ReportPublisher.class); when(publisher.getWriter()).thenReturn(new ScannerReportWriter(outputDir)); - index = new SonarCpdBlockIndex(publisher, settings); + index = new SonarCpdBlockIndex(publisher, settings.asConfig()); componentStore = new InputComponentStore(new PathResolver()); - executor = new CpdExecutor(settings, index, publisher, componentStore); + executor = new CpdExecutor(settings.asConfig(), index, publisher, componentStore); reader = new ScannerReportReader(outputDir); componentStore.put(TestInputFileBuilder.newDefaultInputModule("foo", baseDir)); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/DuplicationPredicatesTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/DuplicationPredicatesTest.java index d02dff61853..6b961772daa 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/DuplicationPredicatesTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/DuplicationPredicatesTest.java @@ -22,7 +22,6 @@ package org.sonar.scanner.cpd; import com.google.common.base.Predicate; import org.junit.Test; import org.sonar.duplications.index.CloneGroup; -import org.sonar.scanner.cpd.DuplicationPredicates; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/deprecated/DefaultCpdBlockIndexerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/deprecated/DefaultCpdBlockIndexerTest.java index 616a7c66e7a..6446aa1822f 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/deprecated/DefaultCpdBlockIndexerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/deprecated/DefaultCpdBlockIndexerTest.java @@ -22,8 +22,7 @@ package org.sonar.scanner.cpd.deprecated; import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.sonar.api.config.MapSettings; -import org.sonar.api.config.Settings; +import org.sonar.api.config.internal.MapSettings; import org.sonar.api.utils.log.LogTester; import static org.assertj.core.api.Assertions.assertThat; @@ -31,7 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class DefaultCpdBlockIndexerTest { private DefaultCpdBlockIndexer engine; - private Settings settings; + private MapSettings settings; @Rule public LogTester logTester = new LogTester(); @@ -39,7 +38,7 @@ public class DefaultCpdBlockIndexerTest { @Before public void init() { settings = new MapSettings(); - engine = new DefaultCpdBlockIndexer(null, null, settings, null); + engine = new DefaultCpdBlockIndexer(null, null, settings.asConfig(), null); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/deprecated/JavaCpdBlockIndexerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/deprecated/JavaCpdBlockIndexerTest.java index 325bb08789b..4952e1cab2d 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/deprecated/JavaCpdBlockIndexerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/deprecated/JavaCpdBlockIndexerTest.java @@ -37,8 +37,7 @@ import org.sonar.api.batch.fs.FileSystem; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.DefaultFileSystem; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; -import org.sonar.api.config.MapSettings; -import org.sonar.api.config.Settings; +import org.sonar.api.config.internal.MapSettings; import org.sonar.duplications.block.Block; import org.sonar.scanner.cpd.index.SonarCpdBlockIndex; @@ -57,7 +56,7 @@ public class JavaCpdBlockIndexerTest { @Captor private ArgumentCaptor<List<Block>> blockCaptor; - private Settings settings; + private MapSettings settings; private JavaCpdBlockIndexer engine; private InputFile file; @@ -79,12 +78,12 @@ public class JavaCpdBlockIndexerTest { FileUtils.copyURLToFile(this.getClass().getResource("ManyStatements.java"), ioFile); settings = new MapSettings(); - engine = new JavaCpdBlockIndexer(fs, settings, index); + engine = new JavaCpdBlockIndexer(fs, settings.asConfig(), index); } @Test public void languageSupported() { - JavaCpdBlockIndexer engine = new JavaCpdBlockIndexer(mock(FileSystem.class), new MapSettings(), index); + JavaCpdBlockIndexer engine = new JavaCpdBlockIndexer(mock(FileSystem.class), new MapSettings().asConfig(), index); assertThat(engine.isLanguageSupported(JAVA)).isTrue(); assertThat(engine.isLanguageSupported("php")).isFalse(); } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/events/BatchStepEventTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/events/BatchStepEventTest.java index 7c714e0231e..7385e3af1e6 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/events/BatchStepEventTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/events/BatchStepEventTest.java @@ -20,8 +20,6 @@ package org.sonar.scanner.events; import org.junit.Test; -import org.sonar.scanner.events.BatchStepEvent; -import org.sonar.scanner.events.BatchStepHandler; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/events/EventBusTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/events/EventBusTest.java index 1ccae4fe949..4608be2638f 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/events/EventBusTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/events/EventBusTest.java @@ -21,8 +21,6 @@ package org.sonar.scanner.events; import org.junit.Test; import org.sonar.api.batch.events.EventHandler; -import org.sonar.scanner.events.BatchEvent; -import org.sonar.scanner.events.EventBus; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericCoverageSensorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericCoverageSensorTest.java index 4bae1ec3135..a23a5d6499f 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericCoverageSensorTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericCoverageSensorTest.java @@ -21,9 +21,9 @@ package org.sonar.scanner.genericcoverage; import org.junit.Rule; import org.junit.Test; -import org.sonar.api.config.MapSettings; import org.sonar.api.config.PropertyDefinitions; import org.sonar.api.config.Settings; +import org.sonar.api.config.internal.MapSettings; import org.sonar.api.utils.log.LogTester; import org.sonar.api.utils.log.LoggerLevel; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericTestExecutionSensorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericTestExecutionSensorTest.java index 99af4485fe1..356db75b3e6 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericTestExecutionSensorTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericTestExecutionSensorTest.java @@ -26,9 +26,9 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.api.batch.sensor.internal.SensorContextTester; -import org.sonar.api.config.MapSettings; import org.sonar.api.config.PropertyDefinitions; import org.sonar.api.config.Settings; +import org.sonar.api.config.internal.MapSettings; import org.sonar.api.utils.log.LogTester; import org.sonar.api.utils.log.LoggerLevel; import org.sonar.scanner.deprecated.test.TestPlanBuilder; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/index/AbstractCachesTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/index/AbstractCachesTest.java index b9a3d19fd11..72b5b501d4f 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/index/AbstractCachesTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/index/AbstractCachesTest.java @@ -19,21 +19,19 @@ */ package org.sonar.scanner.index; +import com.google.common.collect.ImmutableMap; +import java.util.Map; import org.junit.After; - -import org.junit.Before; import org.junit.AfterClass; +import org.junit.Before; import org.junit.BeforeClass; -import com.google.common.collect.ImmutableMap; +import org.junit.ClassRule; +import org.junit.rules.TemporaryFolder; import org.sonar.api.CoreProperties; import org.sonar.scanner.bootstrap.GlobalProperties; import org.sonar.scanner.bootstrap.GlobalTempFolderProvider; import org.sonar.scanner.storage.Storages; import org.sonar.scanner.storage.StoragesManager; -import java.util.Map; - -import org.junit.ClassRule; -import org.junit.rules.TemporaryFolder; public abstract class AbstractCachesTest { @ClassRule diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/index/DefaultIndexTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/index/DefaultIndexTest.java index 1ddf03b28ed..d82bb5d20b1 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/index/DefaultIndexTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/index/DefaultIndexTest.java @@ -21,7 +21,6 @@ package org.sonar.scanner.index; import java.io.IOException; import java.util.Collections; - import org.junit.Before; import org.junit.Test; import org.junit.rules.TemporaryFolder; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DefaultFilterableIssueTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DefaultFilterableIssueTest.java index 9553dfaa659..24c36cda115 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DefaultFilterableIssueTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DefaultFilterableIssueTest.java @@ -24,7 +24,6 @@ import org.junit.Before; import org.junit.Test; import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.scanner.ProjectAnalysisInfo; -import org.sonar.scanner.issue.DefaultFilterableIssue; import org.sonar.scanner.protocol.Constants.Severity; import org.sonar.scanner.protocol.output.ScannerReport.Issue; import org.sonar.scanner.protocol.output.ScannerReport.TextRange; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DefaultIssueCallbackTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DefaultIssueCallbackTest.java index c6c7f1b7aec..c5f606f7739 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DefaultIssueCallbackTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DefaultIssueCallbackTest.java @@ -19,28 +19,24 @@ */ package org.sonar.scanner.issue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - +import com.google.common.collect.ImmutableList; +import java.util.LinkedList; +import java.util.List; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; import org.sonar.api.batch.rule.Rule; +import org.sonar.api.batch.rule.Rules; import org.sonar.api.rule.RuleKey; import org.sonar.batch.bootstrapper.IssueListener; import org.sonar.batch.bootstrapper.IssueListener.Issue; -import org.mockito.MockitoAnnotations; -import org.mockito.Mock; -import org.sonar.api.batch.rule.Rules; -import org.sonar.scanner.issue.DefaultIssueCallback; -import org.sonar.scanner.issue.IssueCache; import org.sonar.scanner.issue.tracking.TrackedIssue; -import org.junit.Before; -import com.google.common.collect.ImmutableList; - -import java.util.LinkedList; -import java.util.List; -import static org.mockito.Matchers.any; import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class DefaultIssueCallbackTest { @Mock diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DefaultIssueFilterChainTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DefaultIssueFilterChainTest.java index d91fa2ed0e4..b7120772896 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DefaultIssueFilterChainTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DefaultIssueFilterChainTest.java @@ -19,12 +19,10 @@ */ package org.sonar.scanner.issue; -import org.sonar.api.scan.issue.filter.FilterableIssue; - import org.junit.Test; +import org.sonar.api.scan.issue.filter.FilterableIssue; import org.sonar.api.scan.issue.filter.IssueFilter; import org.sonar.api.scan.issue.filter.IssueFilterChain; -import org.sonar.scanner.issue.DefaultIssueFilterChain; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DefaultProjectIssuesTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DefaultProjectIssuesTest.java index 0a2b6be76ff..9ecef3b1f21 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DefaultProjectIssuesTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DefaultProjectIssuesTest.java @@ -20,17 +20,14 @@ package org.sonar.scanner.issue; import com.google.common.collect.Lists; +import java.util.Arrays; +import java.util.List; import org.junit.Test; import org.sonar.api.issue.Issue; -import org.sonar.core.issue.DefaultIssue; -import org.sonar.scanner.issue.DefaultProjectIssues; -import org.sonar.scanner.issue.IssueCache; -import org.sonar.scanner.issue.tracking.TrackedIssue; import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.Severity; - -import java.util.Arrays; -import java.util.List; +import org.sonar.core.issue.DefaultIssue; +import org.sonar.scanner.issue.tracking.TrackedIssue; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DeprecatedIssueAdapterForFilterTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DeprecatedIssueAdapterForFilterTest.java index abe6fcf2dee..19585cbab08 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DeprecatedIssueAdapterForFilterTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DeprecatedIssueAdapterForFilterTest.java @@ -25,7 +25,6 @@ import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.issue.Issue; import org.sonar.api.rule.RuleKey; import org.sonar.scanner.ProjectAnalysisInfo; -import org.sonar.scanner.issue.DeprecatedIssueAdapterForFilter; import org.sonar.scanner.protocol.Constants.Severity; import org.sonar.scanner.protocol.output.ScannerReport.TextRange; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DeprecatedIssueFilterChainTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DeprecatedIssueFilterChainTest.java index 4297d6e3a4d..41908eed508 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DeprecatedIssueFilterChainTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DeprecatedIssueFilterChainTest.java @@ -23,7 +23,6 @@ import org.junit.Test; import org.sonar.api.issue.Issue; import org.sonar.api.issue.batch.IssueFilter; import org.sonar.api.issue.batch.IssueFilterChain; -import org.sonar.scanner.issue.DeprecatedIssueFilterChain; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ModuleIssuesTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ModuleIssuesTest.java index c180e8e1da6..8bbdee15b59 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ModuleIssuesTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ModuleIssuesTest.java @@ -33,8 +33,6 @@ import org.sonar.api.batch.sensor.issue.internal.DefaultIssueLocation; import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.Severity; import org.sonar.api.utils.MessageException; -import org.sonar.scanner.issue.IssueFilters; -import org.sonar.scanner.issue.ModuleIssues; import org.sonar.scanner.protocol.output.ScannerReport; import org.sonar.scanner.report.ReportPublisher; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/TrackedIssueAdapterTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/TrackedIssueAdapterTest.java index 8d7fdead717..5b7396c959c 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/TrackedIssueAdapterTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/TrackedIssueAdapterTest.java @@ -23,7 +23,6 @@ import java.util.Date; import org.junit.Test; import org.sonar.api.issue.Issue; import org.sonar.api.rule.RuleKey; -import org.sonar.scanner.issue.TrackedIssueAdapter; import org.sonar.scanner.issue.tracking.TrackedIssue; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/EnforceIssuesFilterTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/EnforceIssuesFilterTest.java index d3089b298fa..a0aae458ed9 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/EnforceIssuesFilterTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/EnforceIssuesFilterTest.java @@ -19,17 +19,15 @@ */ package org.sonar.scanner.issue.ignore; -import org.sonar.api.scan.issue.filter.FilterableIssue; - import com.google.common.collect.ImmutableList; import org.junit.Before; import org.junit.Test; -import org.sonar.api.scan.issue.filter.IssueFilterChain; import org.sonar.api.batch.fs.InputComponent; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.api.rule.RuleKey; +import org.sonar.api.scan.issue.filter.FilterableIssue; +import org.sonar.api.scan.issue.filter.IssueFilterChain; import org.sonar.api.utils.WildcardPattern; -import org.sonar.scanner.issue.ignore.EnforceIssuesFilter; import org.sonar.scanner.issue.ignore.pattern.IssueInclusionPatternInitializer; import org.sonar.scanner.issue.ignore.pattern.IssuePattern; import org.sonar.scanner.scan.filesystem.InputComponentStore; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/IgnoreIssuesFilterTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/IgnoreIssuesFilterTest.java index ccf1ed016c6..5dc8a09e511 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/IgnoreIssuesFilterTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/IgnoreIssuesFilterTest.java @@ -19,20 +19,18 @@ */ package org.sonar.scanner.issue.ignore; -import org.sonar.api.rule.RuleKey; -import org.sonar.api.scan.issue.filter.FilterableIssue; - import org.junit.Before; import org.junit.Test; +import org.sonar.api.rule.RuleKey; +import org.sonar.api.scan.issue.filter.FilterableIssue; import org.sonar.api.scan.issue.filter.IssueFilterChain; -import org.sonar.scanner.issue.ignore.IgnoreIssuesFilter; import org.sonar.scanner.issue.ignore.pattern.IssuePattern; import org.sonar.scanner.issue.ignore.pattern.PatternMatcher; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; public class IgnoreIssuesFilterTest { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/IssueExclusionPatternInitializerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/IssueExclusionPatternInitializerTest.java index 7fadd593235..3a8e6ca8b3c 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/IssueExclusionPatternInitializerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/IssueExclusionPatternInitializerTest.java @@ -22,15 +22,14 @@ package org.sonar.scanner.issue.ignore.pattern; import org.junit.Before; import org.junit.Test; import org.sonar.api.config.PropertyDefinitions; -import org.sonar.api.config.Settings; -import org.sonar.api.config.MapSettings; +import org.sonar.api.config.internal.MapSettings; import org.sonar.core.config.IssueExclusionProperties; import static org.assertj.core.api.Assertions.assertThat; public class IssueExclusionPatternInitializerTest { private IssueExclusionPatternInitializer patternsInitializer; - private Settings settings; + private MapSettings settings; @Before public void init() { @@ -39,7 +38,7 @@ public class IssueExclusionPatternInitializerTest { @Test public void testNoConfiguration() { - patternsInitializer = new IssueExclusionPatternInitializer(settings); + patternsInitializer = new IssueExclusionPatternInitializer(settings.asConfig()); assertThat(patternsInitializer.hasConfiguredPatterns()).isFalse(); assertThat(patternsInitializer.getMulticriteriaPatterns().size()).isEqualTo(0); } @@ -49,7 +48,7 @@ public class IssueExclusionPatternInitializerTest { settings.setProperty("sonar.issue.ignore" + ".multicriteria", "1"); settings.setProperty("sonar.issue.ignore" + ".multicriteria" + ".1." + "resourceKey", ""); settings.setProperty("sonar.issue.ignore" + ".multicriteria" + ".1." + "ruleKey", "*"); - patternsInitializer = new IssueExclusionPatternInitializer(settings); + patternsInitializer = new IssueExclusionPatternInitializer(settings.asConfig()); } @Test(expected = IllegalStateException.class) @@ -57,7 +56,7 @@ public class IssueExclusionPatternInitializerTest { settings.setProperty("sonar.issue.ignore" + ".multicriteria", "1"); settings.setProperty("sonar.issue.ignore" + ".multicriteria" + ".1." + "resourceKey", "*"); settings.setProperty("sonar.issue.ignore" + ".multicriteria" + ".1." + "ruleKey", ""); - patternsInitializer = new IssueExclusionPatternInitializer(settings); + patternsInitializer = new IssueExclusionPatternInitializer(settings.asConfig()); } @Test @@ -69,7 +68,7 @@ public class IssueExclusionPatternInitializerTest { settings.setProperty(IssueExclusionProperties.PATTERNS_BLOCK_KEY + ".2." + IssueExclusionProperties.END_BLOCK_REGEXP, "// FOO-ON"); settings.setProperty(IssueExclusionProperties.PATTERNS_BLOCK_KEY + ".3." + IssueExclusionProperties.BEGIN_BLOCK_REGEXP, "// IGNORE-TO-EOF"); settings.setProperty(IssueExclusionProperties.PATTERNS_BLOCK_KEY + ".3." + IssueExclusionProperties.END_BLOCK_REGEXP, ""); - patternsInitializer = new IssueExclusionPatternInitializer(settings); + patternsInitializer = new IssueExclusionPatternInitializer(settings.asConfig()); assertThat(patternsInitializer.hasConfiguredPatterns()).isTrue(); assertThat(patternsInitializer.hasFileContentPattern()).isTrue(); @@ -84,7 +83,7 @@ public class IssueExclusionPatternInitializerTest { settings.setProperty(IssueExclusionProperties.PATTERNS_BLOCK_KEY, "1"); settings.setProperty(IssueExclusionProperties.PATTERNS_BLOCK_KEY + ".1." + IssueExclusionProperties.BEGIN_BLOCK_REGEXP, ""); settings.setProperty(IssueExclusionProperties.PATTERNS_BLOCK_KEY + ".1." + IssueExclusionProperties.END_BLOCK_REGEXP, "// SONAR-ON"); - patternsInitializer = new IssueExclusionPatternInitializer(settings); + patternsInitializer = new IssueExclusionPatternInitializer(settings.asConfig()); } @Test @@ -92,7 +91,7 @@ public class IssueExclusionPatternInitializerTest { settings.setProperty(IssueExclusionProperties.PATTERNS_ALLFILE_KEY, "1,2"); settings.setProperty(IssueExclusionProperties.PATTERNS_ALLFILE_KEY + ".1." + IssueExclusionProperties.FILE_REGEXP, "@SONAR-IGNORE-ALL"); settings.setProperty(IssueExclusionProperties.PATTERNS_ALLFILE_KEY + ".2." + IssueExclusionProperties.FILE_REGEXP, "//FOO-IGNORE-ALL"); - patternsInitializer = new IssueExclusionPatternInitializer(settings); + patternsInitializer = new IssueExclusionPatternInitializer(settings.asConfig()); assertThat(patternsInitializer.hasConfiguredPatterns()).isTrue(); assertThat(patternsInitializer.hasFileContentPattern()).isTrue(); @@ -106,6 +105,6 @@ public class IssueExclusionPatternInitializerTest { public void shouldLogInvalidAllFilePattern() { settings.setProperty(IssueExclusionProperties.PATTERNS_ALLFILE_KEY, "1"); settings.setProperty(IssueExclusionProperties.PATTERNS_ALLFILE_KEY + ".1." + IssueExclusionProperties.FILE_REGEXP, ""); - patternsInitializer = new IssueExclusionPatternInitializer(settings); + patternsInitializer = new IssueExclusionPatternInitializer(settings.asConfig()); } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/IssueInclusionPatternInitializerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/IssueInclusionPatternInitializerTest.java index 6feecb28637..a8522146039 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/IssueInclusionPatternInitializerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/IssueInclusionPatternInitializerTest.java @@ -22,8 +22,7 @@ package org.sonar.scanner.issue.ignore.pattern; import org.junit.Before; import org.junit.Test; import org.sonar.api.config.PropertyDefinitions; -import org.sonar.api.config.Settings; -import org.sonar.api.config.MapSettings; +import org.sonar.api.config.internal.MapSettings; import org.sonar.core.config.IssueExclusionProperties; import static org.assertj.core.api.Assertions.assertThat; @@ -31,12 +30,12 @@ import static org.assertj.core.api.Assertions.assertThat; public class IssueInclusionPatternInitializerTest { private IssueInclusionPatternInitializer patternsInitializer; - private Settings settings; + private MapSettings settings; @Before public void init() { settings = new MapSettings(new PropertyDefinitions(IssueExclusionProperties.all())); - patternsInitializer = new IssueInclusionPatternInitializer(settings); + patternsInitializer = new IssueInclusionPatternInitializer(settings.asConfig()); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/IssuePatternTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/IssuePatternTest.java index d6c6f778b53..a20dcd7c81a 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/IssuePatternTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/IssuePatternTest.java @@ -19,16 +19,15 @@ */ package org.sonar.scanner.issue.ignore.pattern; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; import org.junit.Test; import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.Rule; import static org.assertj.core.api.Assertions.assertThat; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - public class IssuePatternTest { @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/LineRangeTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/LineRangeTest.java index 0d610f1ffeb..45a2a5f74af 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/LineRangeTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/LineRangeTest.java @@ -20,7 +20,6 @@ package org.sonar.scanner.issue.ignore.pattern; import org.junit.Test; -import org.sonar.scanner.issue.ignore.pattern.LineRange; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/PatternDecoderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/PatternDecoderTest.java index f4ca8b9c745..3d4bfa3ab84 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/PatternDecoderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/PatternDecoderTest.java @@ -20,7 +20,6 @@ package org.sonar.scanner.issue.ignore.pattern; import org.junit.Test; -import org.sonar.scanner.issue.ignore.pattern.PatternDecoder; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/PatternMatcherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/PatternMatcherTest.java index ea9cdb5606c..a474e349f2a 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/PatternMatcherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/PatternMatcherTest.java @@ -19,18 +19,13 @@ */ package org.sonar.scanner.issue.ignore.pattern; -import org.sonar.scanner.issue.ignore.pattern.IssuePattern; -import org.sonar.scanner.issue.ignore.pattern.LineRange; -import org.sonar.scanner.issue.ignore.pattern.PatternMatcher; import com.google.common.collect.Sets; -import org.junit.Before; -import org.junit.Test; -import org.sonar.api.rules.Rule; - import java.util.Collections; import java.util.Set; - import javax.annotation.Nullable; +import org.junit.Before; +import org.junit.Test; +import org.sonar.api.rules.Rule; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsLoaderTest.java index 638e504b6ce..2e15da1999c 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsLoaderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsLoaderTest.java @@ -22,7 +22,6 @@ package org.sonar.scanner.issue.ignore.scanner; import java.io.IOException; import java.util.Arrays; import java.util.Collections; - import org.junit.Before; import org.junit.Rule; import org.junit.Test; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsRegexpScannerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsRegexpScannerTest.java index e3a322e6938..f90c384bcb6 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsRegexpScannerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsRegexpScannerTest.java @@ -20,17 +20,6 @@ package org.sonar.scanner.issue.ignore.scanner; import com.google.common.io.Resources; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.sonar.api.batch.fs.internal.FileMetadata; -import org.sonar.scanner.issue.ignore.pattern.IssueExclusionPatternInitializer; -import org.sonar.scanner.issue.ignore.pattern.LineRange; -import org.sonar.scanner.issue.ignore.pattern.PatternMatcher; -import org.sonar.scanner.issue.ignore.scanner.IssueExclusionsRegexpScanner; -import org.sonar.scanner.issue.ignore.scanner.IssueExclusionsLoader.DoubleRegexpMatcher; - import java.io.IOException; import java.net.URISyntaxException; import java.nio.file.Files; @@ -42,6 +31,15 @@ import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.regex.Pattern; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.sonar.api.batch.fs.internal.FileMetadata; +import org.sonar.scanner.issue.ignore.pattern.IssueExclusionPatternInitializer; +import org.sonar.scanner.issue.ignore.pattern.LineRange; +import org.sonar.scanner.issue.ignore.pattern.PatternMatcher; +import org.sonar.scanner.issue.ignore.scanner.IssueExclusionsLoader.DoubleRegexpMatcher; import static java.nio.charset.StandardCharsets.UTF_8; import static org.mockito.Mockito.times; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/tracking/RollingFileHashesTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/tracking/RollingFileHashesTest.java index 67f5076556b..2efd24dc7db 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/tracking/RollingFileHashesTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/tracking/RollingFileHashesTest.java @@ -20,8 +20,6 @@ package org.sonar.scanner.issue.tracking; import org.junit.Test; -import org.sonar.scanner.issue.tracking.FileHashes; -import org.sonar.scanner.issue.tracking.RollingFileHashes; import static org.apache.commons.codec.digest.DigestUtils.md5Hex; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/tracking/SourceHashHolderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/tracking/SourceHashHolderTest.java index b0465a5ce40..0cf540f0b7a 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/tracking/SourceHashHolderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/tracking/SourceHashHolderTest.java @@ -22,7 +22,6 @@ package org.sonar.scanner.issue.tracking; import java.io.File; import java.nio.charset.StandardCharsets; import java.nio.file.Files; - import org.apache.commons.io.FileUtils; import org.junit.Before; import org.junit.Rule; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/tracking/TrackedIssueTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/tracking/TrackedIssueTest.java index 7fc7146c622..cd24905d493 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/tracking/TrackedIssueTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/tracking/TrackedIssueTest.java @@ -19,11 +19,9 @@ */ package org.sonar.scanner.issue.tracking; -import static org.assertj.core.api.Assertions.assertThat; - import org.junit.Test; -import org.sonar.scanner.issue.tracking.FileHashes; -import org.sonar.scanner.issue.tracking.TrackedIssue; + +import static org.assertj.core.api.Assertions.assertThat; public class TrackedIssueTest { @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/LogOutputRecorder.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/LogOutputRecorder.java index 5f980c04ade..443f4cb09fb 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/LogOutputRecorder.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/LogOutputRecorder.java @@ -19,15 +19,14 @@ */ package org.sonar.scanner.mediumtest; +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Multimap; import java.util.ArrayList; import java.util.Collection; import java.util.LinkedList; import java.util.List; import java.util.stream.Collectors; - import org.sonar.batch.bootstrapper.LogOutput; -import com.google.common.collect.Multimap; -import com.google.common.collect.HashMultimap; public class LogOutputRecorder implements LogOutput { private final Multimap<String, String> recordedByLevel = HashMultimap.create(); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java index f7860cd3db0..e369aefeb05 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java @@ -20,13 +20,13 @@ package org.sonar.scanner.mediumtest.fs; import com.google.common.collect.ImmutableMap; - +import java.io.File; +import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Random; - import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.junit.After; @@ -46,9 +46,6 @@ import org.sonar.scanner.mediumtest.TaskResult; import org.sonar.xoo.XooPlugin; import org.sonar.xoo.rule.XooRulesDefinition; -import java.io.File; -import java.io.IOException; - import static org.assertj.core.api.Assertions.assertThat; public class FileSystemMediumTest { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/NoLanguagesPluginsMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/NoLanguagesPluginsMediumTest.java index 52a99d7408a..721e4a7af6b 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/NoLanguagesPluginsMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/NoLanguagesPluginsMediumTest.java @@ -19,16 +19,14 @@ */ package org.sonar.scanner.mediumtest.fs; -import org.junit.rules.ExpectedException; - +import java.io.File; import org.apache.commons.io.FileUtils; import org.apache.commons.io.filefilter.FileFilterUtils; -import java.io.File; - import org.junit.After; import org.junit.Before; -import org.junit.Test; import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import org.sonar.scanner.mediumtest.ScannerMediumTester; import org.sonar.scanner.mediumtest.issuesmode.IssueModeAndReportsMediumTest; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/ProjectBuilderMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/ProjectBuilderMediumTest.java index 3b9c0bc4dfe..ea16deec3cc 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/ProjectBuilderMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/ProjectBuilderMediumTest.java @@ -31,11 +31,6 @@ import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; - -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; - import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import org.sonar.api.batch.bootstrap.ProjectBuilder; @@ -48,6 +43,9 @@ import org.sonar.xoo.rule.XooRulesDefinition; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.tuple; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; public class ProjectBuilderMediumTest { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesIssuesModeMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesIssuesModeMediumTest.java index 96bf0996b82..7eb43a3b100 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesIssuesModeMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesIssuesModeMediumTest.java @@ -19,22 +19,22 @@ */ package org.sonar.scanner.mediumtest.issues; -import org.junit.rules.TemporaryFolder; +import com.google.common.collect.ImmutableMap; +import java.io.File; +import java.util.Date; +import java.util.LinkedList; +import java.util.List; +import org.apache.commons.io.FileUtils; import org.junit.After; import org.junit.Before; -import com.google.common.collect.ImmutableMap; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; import org.sonar.api.CoreProperties; import org.sonar.batch.bootstrapper.IssueListener; import org.sonar.scanner.mediumtest.ScannerMediumTester; import org.sonar.scanner.mediumtest.TaskResult; import org.sonar.xoo.XooPlugin; import org.sonar.xoo.rule.XooRulesDefinition; -import org.apache.commons.io.FileUtils; -import org.junit.Test; -import java.io.File; -import java.util.Date; -import java.util.LinkedList; -import java.util.List; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issuesmode/EmptyFileTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issuesmode/EmptyFileTest.java index 2379b4e081a..84434b7f8cb 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issuesmode/EmptyFileTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issuesmode/EmptyFileTest.java @@ -19,10 +19,11 @@ */ package org.sonar.scanner.mediumtest.issuesmode; -import org.apache.commons.io.filefilter.FileFilterUtils; -import org.apache.commons.io.FileUtils; -import org.sonar.xoo.rule.XooRulesDefinition; import com.google.common.collect.ImmutableMap; +import java.io.File; +import java.util.Date; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.filefilter.FileFilterUtils; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -30,13 +31,11 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.api.CoreProperties; import org.sonar.api.utils.log.LogTester; -import org.sonar.scanner.mediumtest.ScannerMediumTester; import org.sonar.scanner.issue.tracking.TrackedIssue; +import org.sonar.scanner.mediumtest.ScannerMediumTester; import org.sonar.scanner.mediumtest.TaskResult; import org.sonar.xoo.XooPlugin; - -import java.io.File; -import java.util.Date; +import org.sonar.xoo.rule.XooRulesDefinition; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issuesmode/IssueModeAndReportsMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issuesmode/IssueModeAndReportsMediumTest.java index d53074e0463..6eb4283c0cf 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issuesmode/IssueModeAndReportsMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issuesmode/IssueModeAndReportsMediumTest.java @@ -40,8 +40,8 @@ import org.sonar.api.CoreProperties; import org.sonar.api.utils.log.LogTester; import org.sonar.api.utils.log.LoggerLevel; import org.sonar.batch.bootstrapper.IssueListener; -import org.sonar.scanner.mediumtest.ScannerMediumTester; import org.sonar.scanner.issue.tracking.TrackedIssue; +import org.sonar.scanner.mediumtest.ScannerMediumTester; import org.sonar.scanner.mediumtest.TaskResult; import org.sonar.scanner.protocol.Constants.Severity; import org.sonar.scanner.protocol.input.ScannerInput.ServerIssue; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issuesmode/NoPreviousAnalysisTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issuesmode/NoPreviousAnalysisTest.java index 8fcf882a5e0..4a81c797e21 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issuesmode/NoPreviousAnalysisTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issuesmode/NoPreviousAnalysisTest.java @@ -19,14 +19,10 @@ */ package org.sonar.scanner.mediumtest.issuesmode; +import com.google.common.collect.ImmutableMap; +import java.io.File; import org.apache.commons.io.FileUtils; import org.apache.commons.io.filefilter.FileFilterUtils; - -import java.io.File; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.common.collect.ImmutableMap; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -39,6 +35,8 @@ import org.sonar.scanner.mediumtest.TaskResult; import org.sonar.xoo.XooPlugin; import org.sonar.xoo.rule.XooRulesDefinition; +import static org.assertj.core.api.Assertions.assertThat; + public class NoPreviousAnalysisTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issuesmode/ScanOnlyChangedTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issuesmode/ScanOnlyChangedTest.java index dafd2fedfb2..c0043f1ef24 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issuesmode/ScanOnlyChangedTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issuesmode/ScanOnlyChangedTest.java @@ -49,10 +49,10 @@ import org.junit.runners.Parameterized.Parameters; import org.sonar.api.CoreProperties; import org.sonar.api.batch.fs.internal.FileMetadata; import org.sonar.api.utils.log.LogTester; -import org.sonar.scanner.mediumtest.ScannerMediumTester; import org.sonar.scanner.issue.tracking.TrackedIssue; -import org.sonar.scanner.mediumtest.TaskResult; +import org.sonar.scanner.mediumtest.ScannerMediumTester; import org.sonar.scanner.mediumtest.ScannerMediumTester.TaskBuilder; +import org.sonar.scanner.mediumtest.TaskResult; import org.sonar.scanner.protocol.Constants.Severity; import org.sonar.scanner.protocol.input.ScannerInput.ServerIssue; import org.sonar.scanner.repository.FileData; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/scm/ScmMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/scm/ScmMediumTest.java index bea4f440735..dc411eb2e08 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/scm/ScmMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/scm/ScmMediumTest.java @@ -24,7 +24,6 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; - import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.io.FileUtils; import org.assertj.core.util.Files; @@ -40,9 +39,9 @@ import org.sonar.scanner.mediumtest.ScannerMediumTester; import org.sonar.scanner.mediumtest.ScannerMediumTester.TaskBuilder; import org.sonar.scanner.protocol.output.ScannerReport; import org.sonar.scanner.protocol.output.ScannerReport.Changesets.Changeset; -import org.sonar.scanner.repository.FileData; import org.sonar.scanner.protocol.output.ScannerReport.Component; import org.sonar.scanner.protocol.output.ScannerReportReader; +import org.sonar.scanner.repository.FileData; import org.sonar.xoo.XooPlugin; import org.sonar.xoo.rule.XooRulesDefinition; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tests/CoveragePerTestMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tests/CoveragePerTestMediumTest.java index 8ed5309684a..a949587caa1 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tests/CoveragePerTestMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tests/CoveragePerTestMediumTest.java @@ -19,25 +19,23 @@ */ package org.sonar.scanner.mediumtest.tests; -import org.hamcrest.Description; - -import org.hamcrest.TypeSafeMatcher; -import org.junit.Rule; -import org.junit.rules.ExpectedException; import com.google.common.collect.ImmutableMap; +import java.io.File; +import java.io.IOException; import org.apache.commons.io.FileUtils; +import org.hamcrest.Description; +import org.hamcrest.TypeSafeMatcher; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import org.sonar.api.batch.fs.InputFile; import org.sonar.scanner.mediumtest.ScannerMediumTester; import org.sonar.scanner.mediumtest.TaskResult; import org.sonar.xoo.XooPlugin; -import java.io.File; -import java.io.IOException; - import static org.assertj.core.api.Assertions.assertThat; public class CoveragePerTestMediumTest { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/PostJobsExecutorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/PostJobsExecutorTest.java index 06f9bff6afe..488d9694763 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/PostJobsExecutorTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/PostJobsExecutorTest.java @@ -19,6 +19,7 @@ */ package org.sonar.scanner.phases; +import java.util.Arrays; import org.junit.Before; import org.junit.Test; import org.sonar.api.batch.PostJob; @@ -27,14 +28,12 @@ import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.resources.Project; import org.sonar.scanner.bootstrap.ScannerExtensionDictionnary; import org.sonar.scanner.events.EventBus; -import org.sonar.scanner.phases.PostJobsExecutor; -import java.util.Arrays; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.Mockito.eq; -import static org.mockito.Mockito.any; public class PostJobsExecutorTest { PostJobsExecutor executor; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/SensorsExecutorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/SensorsExecutorTest.java index b7431b1ac7d..5afcb9ee1f5 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/SensorsExecutorTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/SensorsExecutorTest.java @@ -21,7 +21,9 @@ package org.sonar.scanner.phases; import java.io.IOException; import java.util.Collections; -import org.junit.*; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.api.batch.Sensor; import org.sonar.api.batch.SensorContext; @@ -33,7 +35,10 @@ import org.sonar.scanner.events.EventBus; import org.sonar.scanner.sensor.SensorStrategy; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.*; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class SensorsExecutorTest { @Rule diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java index 47a09228471..2af9a10feab 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java @@ -22,8 +22,8 @@ package org.sonar.scanner.platform; import org.junit.Test; import org.sonar.api.CoreProperties; import org.sonar.api.SonarQubeSide; -import org.sonar.api.config.MapSettings; import org.sonar.api.config.Settings; +import org.sonar.api.config.internal.MapSettings; import org.sonar.api.internal.SonarRuntimeImpl; import org.sonar.api.utils.Version; import org.sonar.scanner.bootstrap.ScannerWsClient; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.java index 64a87b2295d..47ceca94888 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.java @@ -29,8 +29,7 @@ import org.sonar.api.batch.AnalysisMode; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.api.batch.postjob.issue.PostJobIssue; import org.sonar.api.batch.rule.Severity; -import org.sonar.api.config.MapSettings; -import org.sonar.api.config.Settings; +import org.sonar.api.config.internal.MapSettings; import org.sonar.api.scan.filesystem.PathResolver; import org.sonar.scanner.issue.IssueCache; import org.sonar.scanner.issue.tracking.TrackedIssue; @@ -48,7 +47,7 @@ public class DefaultPostJobContextTest { private IssueCache issueCache; private InputComponentStore componentStore; private DefaultPostJobContext context; - private Settings settings; + private MapSettings settings; private AnalysisMode analysisMode; @Before @@ -57,7 +56,7 @@ public class DefaultPostJobContextTest { componentStore = new InputComponentStore(new PathResolver()); settings = new MapSettings(); analysisMode = mock(AnalysisMode.class); - context = new DefaultPostJobContext(settings, issueCache, componentStore, analysisMode); + context = new DefaultPostJobContext(settings.asConfig(), settings, issueCache, componentStore, analysisMode); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/PostJobOptimizerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/PostJobOptimizerTest.java index b23fdc402c5..85f62407d34 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/PostJobOptimizerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/PostJobOptimizerTest.java @@ -25,7 +25,7 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.api.batch.postjob.internal.DefaultPostJobDescriptor; import org.sonar.api.config.Settings; -import org.sonar.api.config.MapSettings; +import org.sonar.api.config.internal.MapSettings; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/profiling/PhasesSumUpTimeProfilerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/profiling/PhasesSumUpTimeProfilerTest.java index 68804f5891e..a3d55dfa855 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/profiling/PhasesSumUpTimeProfilerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/profiling/PhasesSumUpTimeProfilerTest.java @@ -19,11 +19,9 @@ */ package org.sonar.scanner.profiling; -import static org.assertj.core.api.Assertions.assertThat; - +import com.google.common.collect.Maps; import java.util.List; import java.util.Map; - import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -49,7 +47,7 @@ import org.sonar.api.utils.System2; import org.sonar.scanner.bootstrap.GlobalProperties; import org.sonar.scanner.events.BatchStepEvent; -import com.google.common.collect.Maps; +import static org.assertj.core.api.Assertions.assertThat; public class PhasesSumUpTimeProfilerTest { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ActiveRulesPublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ActiveRulesPublisherTest.java index 6af4cda0881..b7d8a0d6328 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ActiveRulesPublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ActiveRulesPublisherTest.java @@ -34,7 +34,6 @@ import org.sonar.scanner.protocol.Constants; 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.report.ActiveRulesPublisher; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/AnalysisContextReportPublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/AnalysisContextReportPublisherTest.java index cce73c7dc8d..3c65a91b598 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/AnalysisContextReportPublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/AnalysisContextReportPublisherTest.java @@ -35,7 +35,7 @@ import org.sonar.api.utils.System2; import org.sonar.api.utils.log.LogTester; import org.sonar.api.utils.log.LoggerLevel; import org.sonar.core.platform.PluginInfo; -import org.sonar.scanner.bootstrap.GlobalSettings; +import org.sonar.scanner.bootstrap.GlobalConfiguration; import org.sonar.scanner.bootstrap.ScannerPluginRepository; import org.sonar.scanner.protocol.output.ScannerReportWriter; import org.sonar.scanner.repository.ProjectRepositories; @@ -64,7 +64,7 @@ public class AnalysisContextReportPublisherTest { private AnalysisMode analysisMode = mock(AnalysisMode.class); private System2 system2; private ProjectRepositories projectRepos; - private GlobalSettings globalSettings; + private GlobalConfiguration globalSettings; @Before public void prepare() throws Exception { @@ -72,7 +72,7 @@ public class AnalysisContextReportPublisherTest { system2 = mock(System2.class); when(system2.properties()).thenReturn(new Properties()); projectRepos = mock(ProjectRepositories.class); - globalSettings = mock(GlobalSettings.class); + globalSettings = mock(GlobalConfiguration.class); publisher = new AnalysisContextReportPublisher(analysisMode, pluginRepo, system2, projectRepos, globalSettings); } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java index 60a85ab6d22..2f1a13d1d94 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java @@ -22,7 +22,6 @@ package org.sonar.scanner.report; import java.io.File; import java.io.IOException; import java.util.Collections; - import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -41,10 +40,9 @@ import org.sonar.scanner.protocol.output.FileStructure; import org.sonar.scanner.protocol.output.ScannerReport; import org.sonar.scanner.protocol.output.ScannerReport.Component; import org.sonar.scanner.protocol.output.ScannerReport.ComponentLink.ComponentLinkType; -import org.sonar.scanner.report.ComponentsPublisher; -import org.sonar.scanner.scan.DefaultComponentTree; import org.sonar.scanner.protocol.output.ScannerReportReader; import org.sonar.scanner.protocol.output.ScannerReportWriter; +import org.sonar.scanner.scan.DefaultComponentTree; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ContextPropertiesPublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ContextPropertiesPublisherTest.java index 4760295a4c9..a767182c6a7 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ContextPropertiesPublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ContextPropertiesPublisherTest.java @@ -21,14 +21,16 @@ package org.sonar.scanner.report; import com.google.common.collect.Lists; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.hamcrest.Description; import org.hamcrest.TypeSafeMatcher; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.sonar.api.config.MapSettings; -import org.sonar.api.config.Settings; +import org.sonar.scanner.config.DefaultConfiguration; import org.sonar.scanner.protocol.output.ScannerReport; import org.sonar.scanner.protocol.output.ScannerReportWriter; import org.sonar.scanner.repository.ContextPropertiesCache; @@ -37,6 +39,7 @@ import static java.util.Collections.emptyList; import static org.mockito.Matchers.argThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; public class ContextPropertiesPublisherTest { @Rule @@ -44,8 +47,14 @@ public class ContextPropertiesPublisherTest { private ScannerReportWriter writer = mock(ScannerReportWriter.class); private ContextPropertiesCache cache = new ContextPropertiesCache(); - private Settings settings = new MapSettings(); - private ContextPropertiesPublisher underTest = new ContextPropertiesPublisher(cache, settings); + private DefaultConfiguration config = mock(DefaultConfiguration.class); + private Map<String, String> props = new HashMap<>(); + private ContextPropertiesPublisher underTest = new ContextPropertiesPublisher(cache, config); + + @Before + public void prepareMock() { + when(config.getProperties()).thenReturn(props); + } @Test public void publish_writes_properties_to_report() { @@ -69,9 +78,9 @@ public class ContextPropertiesPublisherTest { @Test public void publish_settings_prefixed_with_sonar_analysis_for_webhooks() { - settings.setProperty("foo", "should not be exported"); - settings.setProperty("sonar.analysis.revision", "ab45b3"); - settings.setProperty("sonar.analysis.build.number", "B123"); + props.put("foo", "should not be exported"); + props.put("sonar.analysis.revision", "ab45b3"); + props.put("sonar.analysis.build.number", "B123"); underTest.publish(writer); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MetadataPublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MetadataPublisherTest.java index a8e0795f18c..e59cbd47ee4 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MetadataPublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MetadataPublisherTest.java @@ -27,11 +27,10 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.api.CoreProperties; import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.api.config.MapSettings; -import org.sonar.api.config.Settings; import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.batch.fs.internal.InputModuleHierarchy; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; +import org.sonar.api.config.internal.MapSettings; import org.sonar.scanner.ProjectAnalysisInfo; import org.sonar.scanner.protocol.output.ScannerReport; import org.sonar.scanner.protocol.output.ScannerReportReader; @@ -53,7 +52,7 @@ public class MetadataPublisherTest { private ProjectDefinition projectDef; private DefaultInputModule rootModule; private MetadataPublisher underTest; - private Settings settings; + private MapSettings settings; private ModuleQProfiles qProfiles; private ProjectAnalysisInfo projectAnalysisInfo; private InputModuleHierarchy inputModuleHierarchy; @@ -68,7 +67,7 @@ public class MetadataPublisherTest { when(inputModuleHierarchy.root()).thenReturn(rootModule); settings = new MapSettings(); qProfiles = mock(ModuleQProfiles.class); - underTest = new MetadataPublisher(projectAnalysisInfo, inputModuleHierarchy, settings, qProfiles); + underTest = new MetadataPublisher(projectAnalysisInfo, inputModuleHierarchy, settings.asConfig(), qProfiles); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java index a47550ba721..7b93925349e 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java @@ -34,9 +34,8 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mockito; import org.sonar.api.CoreProperties; import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.api.config.MapSettings; import org.sonar.api.config.PropertyDefinitions; -import org.sonar.api.config.Settings; +import org.sonar.api.config.internal.MapSettings; import org.sonar.api.platform.Server; import org.sonar.api.utils.MessageException; import org.sonar.api.utils.TempFolder; @@ -71,7 +70,7 @@ public class ReportPublisherTest { public ExpectedException exception = ExpectedException.none(); DefaultAnalysisMode mode = mock(DefaultAnalysisMode.class); - Settings settings = new MapSettings(new PropertyDefinitions(CorePropertyDefinitions.all())); + MapSettings settings = new MapSettings(new PropertyDefinitions(CorePropertyDefinitions.all())); ScannerWsClient wsClient; Server server = mock(Server.class); ImmutableProjectReactor reactor = mock(ImmutableProjectReactor.class); @@ -89,7 +88,7 @@ public class ReportPublisherTest { @Test public void log_and_dump_information_about_report_uploading() throws IOException { - ReportPublisher underTest = new ReportPublisher(settings, wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]); + ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]); settings.setProperty(CoreProperties.PROJECT_ORGANIZATION_PROPERTY, "MyOrg"); underTest.logSuccess("TASK-123"); @@ -112,7 +111,7 @@ public class ReportPublisherTest { @Test public void parse_upload_error_message() throws IOException { - ReportPublisher underTest = new ReportPublisher(settings, wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]); + ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]); 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); @@ -126,7 +125,7 @@ public class ReportPublisherTest { @Test public void log_public_url_if_defined() throws IOException { when(server.getPublicRootUrl()).thenReturn("https://publicserver/sonarqube"); - ReportPublisher underTest = new ReportPublisher(settings, wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]); + ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]); underTest.logSuccess("TASK-123"); @@ -147,7 +146,7 @@ public class ReportPublisherTest { @Test public void fail_if_public_url_malformed() throws IOException { when(server.getPublicRootUrl()).thenReturn("invalid"); - ReportPublisher underTest = new ReportPublisher(settings, wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]); + ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]); exception.expect(MessageException.class); exception.expectMessage("Failed to parse public URL set in SonarQube server: invalid"); @@ -156,7 +155,7 @@ public class ReportPublisherTest { @Test public void log_but_not_dump_information_when_report_is_not_uploaded() { - ReportPublisher underTest = new ReportPublisher(settings, wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]); + ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]); underTest.logSuccess(/* report not uploaded, no server task */null); @@ -173,7 +172,7 @@ public class ReportPublisherTest { settings.setProperty("sonar.batch.keepReport", true); Path reportDir = temp.getRoot().toPath().resolve("batch-report"); Files.createDirectory(reportDir); - ReportPublisher underTest = new ReportPublisher(settings, wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]); + ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]); underTest.start(); underTest.stop(); @@ -184,7 +183,7 @@ public class ReportPublisherTest { public void should_delete_report_by_default() throws IOException { Path reportDir = temp.getRoot().toPath().resolve("batch-report"); Files.createDirectory(reportDir); - ReportPublisher job = new ReportPublisher(settings, wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]); + ReportPublisher job = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]); job.start(); job.stop(); @@ -193,7 +192,7 @@ public class ReportPublisherTest { @Test public void test_ws_parameters() throws Exception { - ReportPublisher underTest = new ReportPublisher(settings, wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]); + ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]); settings.setProperty(CoreProperties.PROJECT_ORGANIZATION_PROPERTY, "MyOrg"); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultQualityProfileLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultQualityProfileLoaderTest.java index 7a2982e77f1..c02c6d05a40 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultQualityProfileLoaderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultQualityProfileLoaderTest.java @@ -26,8 +26,7 @@ import java.io.InputStream; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.sonar.api.config.MapSettings; -import org.sonar.api.config.Settings; +import org.sonar.api.config.internal.MapSettings; import org.sonar.api.utils.MessageException; import org.sonar.scanner.WsTestUtil; import org.sonar.scanner.bootstrap.ScannerWsClient; @@ -42,8 +41,8 @@ public class DefaultQualityProfileLoaderTest { public ExpectedException exception = ExpectedException.none(); private ScannerWsClient wsClient = mock(ScannerWsClient.class); - private Settings settings = new MapSettings(); - private DefaultQualityProfileLoader underTest = new DefaultQualityProfileLoader(settings, wsClient); + private MapSettings settings = new MapSettings(); + private DefaultQualityProfileLoader underTest = new DefaultQualityProfileLoader(settings.asConfig(), wsClient); @Test public void load_gets_profiles_for_specified_project_and_profile_name() throws IOException { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/ProjectRepositoriesProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/ProjectRepositoriesProviderTest.java index c49c76423fa..2db06e5ad68 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/ProjectRepositoriesProviderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/ProjectRepositoriesProviderTest.java @@ -19,19 +19,15 @@ */ package org.sonar.scanner.repository; -import java.util.Date; -import com.google.common.collect.Table; import com.google.common.collect.HashBasedTable; +import com.google.common.collect.Table; +import java.util.Date; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.sonar.api.batch.bootstrap.ProjectKey; import org.sonar.scanner.analysis.DefaultAnalysisMode; -import org.sonar.scanner.repository.FileData; -import org.sonar.scanner.repository.ProjectRepositories; -import org.sonar.scanner.repository.ProjectRepositoriesLoader; -import org.sonar.scanner.repository.ProjectRepositoriesProvider; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.eq; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/QualityProfileProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/QualityProfileProviderTest.java index a36abe70f4a..aaea7dde877 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/QualityProfileProviderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/QualityProfileProviderTest.java @@ -31,9 +31,6 @@ import org.sonar.api.batch.bootstrap.ProjectKey; import org.sonar.api.utils.log.LogTester; import org.sonar.api.utils.log.LoggerLevel; import org.sonar.scanner.analysis.AnalysisProperties; -import org.sonar.scanner.repository.ProjectRepositories; -import org.sonar.scanner.repository.QualityProfileLoader; -import org.sonar.scanner.repository.QualityProfileProvider; import org.sonar.scanner.rule.ModuleQProfiles; import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/ActiveRulesProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/ActiveRulesProviderTest.java index 18a6fa9ec78..d6ff0c61f3e 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/ActiveRulesProviderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/ActiveRulesProviderTest.java @@ -28,10 +28,6 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.sonar.api.batch.rule.ActiveRules; import org.sonar.api.rule.RuleKey; -import org.sonar.scanner.rule.ActiveRulesProvider; -import org.sonar.scanner.rule.DefaultActiveRulesLoader; -import org.sonar.scanner.rule.LoadedActiveRule; -import org.sonar.scanner.rule.ModuleQProfiles; import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/QProfileTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/QProfileTest.java index c605cf7a54d..a21efc17c55 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/QProfileTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/QProfileTest.java @@ -20,7 +20,8 @@ package org.sonar.scanner.rule; import org.junit.Test; -import static org.assertj.core.api.Assertions.*; + +import static org.assertj.core.api.Assertions.assertThat; public class QProfileTest { @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/QProfileVerifierTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/QProfileVerifierTest.java index bfb438c3fb6..f68303521a5 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/QProfileVerifierTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/QProfileVerifierTest.java @@ -27,8 +27,7 @@ import org.junit.rules.TemporaryFolder; import org.slf4j.Logger; import org.sonar.api.batch.fs.internal.DefaultFileSystem; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; -import org.sonar.api.config.Settings; -import org.sonar.api.config.MapSettings; +import org.sonar.api.config.internal.MapSettings; import org.sonar.api.utils.MessageException; import static org.mockito.Mockito.mock; @@ -45,7 +44,7 @@ public class QProfileVerifierTest { private DefaultFileSystem fs; private ModuleQProfiles profiles; - private Settings settings = new MapSettings(); + private MapSettings settings = new MapSettings(); @Before public void before() throws Exception { @@ -62,7 +61,7 @@ public class QProfileVerifierTest { fs.add(new TestInputFileBuilder("foo", "src/Bar.java").setLanguage("java").build()); fs.add(new TestInputFileBuilder("foo", "src/Baz.cbl").setLanguage("cobol").build()); - QProfileVerifier profileLogger = new QProfileVerifier(settings, fs, profiles); + QProfileVerifier profileLogger = new QProfileVerifier(settings.asConfig(), fs, profiles); Logger logger = mock(Logger.class); profileLogger.execute(logger); @@ -76,7 +75,7 @@ public class QProfileVerifierTest { settings.setProperty("sonar.profile", "Unknown"); - QProfileVerifier profileLogger = new QProfileVerifier(settings, fs, profiles); + QProfileVerifier profileLogger = new QProfileVerifier(settings.asConfig(), fs, profiles); thrown.expect(MessageException.class); thrown.expectMessage("sonar.profile was set to 'Unknown' but didn't match any profile for any language. Please check your configuration."); @@ -88,7 +87,7 @@ public class QProfileVerifierTest { public void should_not_fail_if_no_language_on_project() { settings.setProperty("sonar.profile", "Unknown"); - QProfileVerifier profileLogger = new QProfileVerifier(settings, fs, profiles); + QProfileVerifier profileLogger = new QProfileVerifier(settings.asConfig(), fs, profiles); profileLogger.execute(); @@ -100,7 +99,7 @@ public class QProfileVerifierTest { settings.setProperty("sonar.profile", "My Java profile"); - QProfileVerifier profileLogger = new QProfileVerifier(settings, fs, profiles); + QProfileVerifier profileLogger = new QProfileVerifier(settings.asConfig(), fs, profiles); profileLogger.execute(); } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/RuleFinderCompatibilityTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/RuleFinderCompatibilityTest.java index 37133509508..097a1caf4b8 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/RuleFinderCompatibilityTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/RuleFinderCompatibilityTest.java @@ -19,16 +19,14 @@ */ package org.sonar.scanner.rule; -import org.sonar.api.batch.rule.internal.RulesBuilder; - -import org.sonar.api.batch.rule.Rules; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.sonar.api.batch.rule.Rules; +import org.sonar.api.batch.rule.internal.RulesBuilder; import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.RuleQuery; -import org.sonar.scanner.rule.RuleFinderCompatibility; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/RulesProfileProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/RulesProfileProviderTest.java index 029f7847177..8dff3fadef3 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/RulesProfileProviderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/RulesProfileProviderTest.java @@ -22,8 +22,7 @@ package org.sonar.scanner.rule; import java.util.Arrays; import org.junit.Test; import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; -import org.sonar.api.config.Settings; -import org.sonar.api.config.MapSettings; +import org.sonar.api.config.internal.MapSettings; import org.sonar.api.profiles.RulesProfile; import org.sonar.api.rule.RuleKey; @@ -34,16 +33,16 @@ import static org.mockito.Mockito.when; public class RulesProfileProviderTest { - ModuleQProfiles qProfiles = mock(ModuleQProfiles.class); - Settings settings = new MapSettings(); - RulesProfileProvider provider = new RulesProfileProvider(); + private ModuleQProfiles qProfiles = mock(ModuleQProfiles.class); + private MapSettings settings = new MapSettings(); + private RulesProfileProvider provider = new RulesProfileProvider(); @Test public void merge_profiles() { QProfile qProfile = new QProfile().setKey("java-sw").setName("Sonar way").setLanguage("java"); when(qProfiles.findAll()).thenReturn(Arrays.asList(qProfile)); - RulesProfile profile = provider.provide(qProfiles, new ActiveRulesBuilder().build(), settings); + RulesProfile profile = provider.provide(qProfiles, new ActiveRulesBuilder().build(), settings.asConfig()); // merge of all profiles assertThat(profile).isNotNull().isInstanceOf(RulesProfileWrapper.class); @@ -65,7 +64,7 @@ public class RulesProfileProviderTest { QProfile qProfile = new QProfile().setKey("java-sw").setName("Sonar way").setLanguage("java"); when(qProfiles.findByLanguage("java")).thenReturn(qProfile); - RulesProfile profile = provider.provide(qProfiles, new ActiveRulesBuilder().build(), settings); + RulesProfile profile = provider.provide(qProfiles, new ActiveRulesBuilder().build(), settings.asConfig()); // no merge, directly the old hibernate profile assertThat(profile).isNotNull(); @@ -80,7 +79,7 @@ public class RulesProfileProviderTest { ActiveRulesBuilder activeRulesBuilder = new ActiveRulesBuilder(); activeRulesBuilder.create(RuleKey.of("java", "S001")).setTemplateRuleKey("T001").setLanguage("java").activate(); - RulesProfile profile = provider.provide(qProfiles, activeRulesBuilder.build(), settings); + RulesProfile profile = provider.provide(qProfiles, activeRulesBuilder.build(), settings.asConfig()); assertThat(profile.getActiveRule("java", "S001").getRule().getTemplate().getKey()).isEqualTo("T001"); } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/RulesProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/RulesProviderTest.java index 38272dc68e7..918471d8e97 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/RulesProviderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/RulesProviderTest.java @@ -20,15 +20,13 @@ package org.sonar.scanner.rule; import com.google.common.collect.Lists; +import org.junit.Test; import org.sonar.api.batch.rule.Rules; -import org.sonar.scanner.rule.RulesLoader; -import org.sonar.scanner.rule.RulesProvider; +import org.sonarqube.ws.Rules.ListResponse.Rule; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.when; import static org.mockito.Mockito.mock; -import org.sonarqube.ws.Rules.ListResponse.Rule; -import org.junit.Test; +import static org.mockito.Mockito.when; public class RulesProviderTest { @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/DefaultComponentTreeTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/DefaultComponentTreeTest.java index 538a4b50879..e60b3303d40 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/DefaultComponentTreeTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/DefaultComponentTreeTest.java @@ -19,13 +19,13 @@ */ package org.sonar.scanner.scan; -import static org.assertj.core.api.Assertions.assertThat; - import org.junit.Before; import org.junit.Test; import org.sonar.api.batch.fs.internal.DefaultInputComponent; import org.sonar.api.batch.fs.internal.DefaultInputModule; +import static org.assertj.core.api.Assertions.assertThat; + public class DefaultComponentTreeTest { private DefaultComponentTree tree; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/DefaultInputModuleHierarchyTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/DefaultInputModuleHierarchyTest.java index 4febcb225fe..be0f7773038 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/DefaultInputModuleHierarchyTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/DefaultInputModuleHierarchyTest.java @@ -19,12 +19,12 @@ */ package org.sonar.scanner.scan; -import static org.assertj.core.api.Assertions.assertThat; - import org.junit.Before; import org.junit.Test; import org.sonar.api.batch.fs.internal.DefaultInputModule; +import static org.assertj.core.api.Assertions.assertThat; + public class DefaultInputModuleHierarchyTest { private DefaultInputModuleHierarchy moduleHierarchy; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ModuleSettingsTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/MutableModuleSettingsTest.java index 4b2b371c507..f1a150d800f 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ModuleSettingsTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/MutableModuleSettingsTest.java @@ -33,10 +33,11 @@ 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.GlobalProperties; -import org.sonar.scanner.bootstrap.GlobalSettings; -import org.sonar.scanner.report.AnalysisContextReportPublisher; +import org.sonar.scanner.bootstrap.MutableGlobalSettings; import org.sonar.scanner.repository.FileData; import org.sonar.scanner.repository.ProjectRepositories; import org.sonar.scanner.repository.settings.SettingsLoader; @@ -45,7 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class ModuleSettingsTest { +public class MutableModuleSettingsTest { @Rule public ExpectedException thrown = ExpectedException.none(); @@ -75,7 +76,7 @@ public class ModuleSettingsTest { grandParent.addSubProject(parent); parent.addSubProject(child); - List<ProjectDefinition> hierarchy = ModuleSettings.getTopDownParentProjects(child); + List<ProjectDefinition> hierarchy = MutableModuleSettings.getTopDownParentProjects(child); assertThat(hierarchy.get(0)).isEqualTo(grandParent); assertThat(hierarchy.get(1)).isEqualTo(parent); assertThat(hierarchy.get(2)).isEqualTo(child); @@ -83,7 +84,7 @@ public class ModuleSettingsTest { @Test public void test_loading_of_module_settings() { - GlobalSettings globalSettings = newGlobalSettings(ImmutableMap.of( + GlobalConfiguration globalSettings = newGlobalSettings(ImmutableMap.of( "overridding", "batch", "on-batch", "true")); @@ -91,7 +92,7 @@ public class ModuleSettingsTest { ProjectDefinition module = ProjectDefinition.create().setKey("struts-core"); - ModuleSettings moduleSettings = new ModuleSettings(globalSettings, module, projRepos, mode, mock(AnalysisContextReportPublisher.class)); + MutableModuleSettings moduleSettings = new MutableModuleSettings(new MutableGlobalSettings(globalSettings), module, projRepos, mode); assertThat(moduleSettings.getString("overridding")).isEqualTo("module"); assertThat(moduleSettings.getString("on-batch")).isEqualTo("true"); @@ -101,7 +102,7 @@ public class ModuleSettingsTest { // SONAR-6386 @Test public void test_loading_of_parent_module_settings_for_new_module() { - GlobalSettings globalSettings = newGlobalSettings(ImmutableMap.of( + GlobalConfiguration globalSettings = newGlobalSettings(ImmutableMap.of( "overridding", "batch", "on-batch", "true")); @@ -110,7 +111,7 @@ public class ModuleSettingsTest { ProjectDefinition module = ProjectDefinition.create().setKey("struts-core"); ProjectDefinition.create().setKey("struts").addSubProject(module); - ModuleSettings moduleSettings = new ModuleSettings(globalSettings, module, projRepos, mode, mock(AnalysisContextReportPublisher.class)); + MutableModuleSettings moduleSettings = new MutableModuleSettings(new MutableGlobalSettings(globalSettings), module, projRepos, mode); assertThat(moduleSettings.getString("overridding")).isEqualTo("module"); assertThat(moduleSettings.getString("on-batch")).isEqualTo("true"); @@ -119,14 +120,13 @@ public class ModuleSettingsTest { @Test public void should_not_fail_when_accessing_secured_properties() { - GlobalSettings globalSettings = newGlobalSettings(ImmutableMap.of( - "sonar.foo.secured", "bar")); + GlobalConfiguration globalSettings = newGlobalSettings(ImmutableMap.of("sonar.foo.secured", "bar")); ProjectRepositories projSettingsRepo = createSettings("struts-core", ImmutableMap.of("sonar.foo.license.secured", "bar2")); ProjectDefinition module = ProjectDefinition.create().setKey("struts-core"); - ModuleSettings moduleSettings = new ModuleSettings(globalSettings, module, projSettingsRepo, mode, mock(AnalysisContextReportPublisher.class)); + MutableModuleSettings moduleSettings = new MutableModuleSettings(new MutableGlobalSettings(globalSettings), module, projSettingsRepo, mode); assertThat(moduleSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2"); assertThat(moduleSettings.getString("sonar.foo.secured")).isEqualTo("bar"); @@ -134,7 +134,7 @@ public class ModuleSettingsTest { @Test public void should_fail_when_accessing_secured_properties_in_issues() { - GlobalSettings globalSettings = newGlobalSettings(ImmutableMap.of( + GlobalConfiguration globalSettings = newGlobalSettings(ImmutableMap.of( "sonar.foo.secured", "bar")); ProjectRepositories projSettingsRepo = createSettings("struts-core", ImmutableMap.of("sonar.foo.license.secured", "bar2")); @@ -143,7 +143,7 @@ public class ModuleSettingsTest { ProjectDefinition module = ProjectDefinition.create().setKey("struts-core"); - ModuleSettings moduleSettings = new ModuleSettings(globalSettings, module, projSettingsRepo, mode, mock(AnalysisContextReportPublisher.class)); + MutableModuleSettings moduleSettings = new MutableModuleSettings(new MutableGlobalSettings(globalSettings), module, projSettingsRepo, mode); assertThat(moduleSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2"); @@ -154,9 +154,9 @@ public class ModuleSettingsTest { moduleSettings.getString("sonar.foo.secured"); } - private GlobalSettings newGlobalSettings(Map<String, String> props) { + private GlobalConfiguration newGlobalSettings(Map<String, String> props) { GlobalProperties globalProps = new GlobalProperties(props); - return new GlobalSettings(globalProps, new PropertyDefinitions(), - mock(SettingsLoader.class), new GlobalMode(globalProps)); + return new GlobalConfigurationProvider().provide(mock(SettingsLoader.class), globalProps, new PropertyDefinitions(), + new GlobalMode(globalProps)); } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectSettingsTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/MutableProjectSettingsTest.java index e0d687a8981..0087e27fede 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectSettingsTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/MutableProjectSettingsTest.java @@ -34,9 +34,11 @@ 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.GlobalProperties; -import org.sonar.scanner.bootstrap.GlobalSettings; +import org.sonar.scanner.bootstrap.MutableGlobalSettings; import org.sonar.scanner.repository.FileData; import org.sonar.scanner.repository.ProjectRepositories; import org.sonar.scanner.repository.settings.SettingsLoader; @@ -45,7 +47,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class ProjectSettingsTest { +public class MutableProjectSettingsTest { @Rule public ExpectedException thrown = ExpectedException.none(); @@ -54,7 +56,7 @@ public class ProjectSettingsTest { private ProjectRepositories projectRef; private ProjectDefinition project; - private GlobalSettings bootstrapProps; + private GlobalConfiguration bootstrapProps; private Table<String, String, FileData> emptyFileData; private Table<String, String, String> emptySettings; @@ -68,7 +70,8 @@ public class ProjectSettingsTest { project = ProjectDefinition.create().setKey("struts"); globalMode = mock(GlobalMode.class); mode = mock(DefaultAnalysisMode.class); - bootstrapProps = new GlobalSettings(new GlobalProperties(Collections.<String, String>emptyMap()), new PropertyDefinitions(), mock(SettingsLoader.class), globalMode); + bootstrapProps = new GlobalConfigurationProvider().provide(mock(SettingsLoader.class), new GlobalProperties(Collections.<String, String>emptyMap()), new PropertyDefinitions(), + globalMode); } @Test @@ -76,7 +79,7 @@ public class ProjectSettingsTest { project.setProperty("project.prop", "project"); projectRef = new ProjectRepositories(emptySettings, emptyFileData, null); - ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, projectRef, mode); + MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), new MutableGlobalSettings(bootstrapProps), projectRef, mode); assertThat(batchSettings.getString("project.prop")).isEqualTo("project"); } @@ -88,7 +91,7 @@ public class ProjectSettingsTest { settings.put("struts", "sonar.java.coveragePlugin", "jacoco"); projectRef = new ProjectRepositories(settings, emptyFileData, null); - ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, projectRef, mode); + MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), new MutableGlobalSettings(bootstrapProps), projectRef, mode); assertThat(batchSettings.getString("sonar.java.coveragePlugin")).isEqualTo("jacoco"); } @@ -102,7 +105,7 @@ public class ProjectSettingsTest { projectRef = new ProjectRepositories(settings, emptyFileData, null); - ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, projectRef, mode); + MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), new MutableGlobalSettings(bootstrapProps), projectRef, mode); assertThat(batchSettings.getString("sonar.java.coveragePlugin")).isEqualTo("jacoco"); } @@ -114,7 +117,7 @@ public class ProjectSettingsTest { settings.put("struts", "sonar.foo.license.secured", "bar2"); projectRef = new ProjectRepositories(settings, emptyFileData, null); - ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, projectRef, mode); + MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), new MutableGlobalSettings(bootstrapProps), projectRef, mode); assertThat(batchSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2"); assertThat(batchSettings.getString("sonar.foo.secured")).isEqualTo("bar"); @@ -129,7 +132,7 @@ public class ProjectSettingsTest { when(mode.isIssues()).thenReturn(true); projectRef = new ProjectRepositories(settings, emptyFileData, null); - ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, projectRef, mode); + MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), new MutableGlobalSettings(bootstrapProps), projectRef, mode); assertThat(batchSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2"); thrown.expect(MessageException.class); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectBuildersExecutorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectBuildersExecutorTest.java index aaea18a974f..a76ced58419 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectBuildersExecutorTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectBuildersExecutorTest.java @@ -19,10 +19,6 @@ */ package org.sonar.scanner.scan; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; - import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -32,6 +28,10 @@ import org.sonar.api.batch.bootstrap.ProjectBuilder.Context; import org.sonar.api.batch.bootstrap.ProjectReactor; import org.sonar.api.utils.MessageException; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; + public class ProjectBuildersExecutorTest { private ProjectReactor reactor; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectLockTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectLockTest.java index b206d1b0508..cd628bbe8f4 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectLockTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectLockTest.java @@ -19,22 +19,21 @@ */ package org.sonar.scanner.scan; +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; import org.junit.rules.ExpectedException; +import org.junit.rules.TemporaryFolder; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.bootstrap.ProjectReactor; import org.sonar.home.cache.DirectoryLock; -import org.sonar.scanner.scan.ProjectLock; -import java.io.File; -import java.nio.file.Files; -import java.nio.file.Path; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; -import org.junit.Before; -import org.junit.Rule; -import org.junit.rules.TemporaryFolder; public class ProjectLockTest { @Rule diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorValidatorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorValidatorTest.java index 737db71b599..9f7833fbc75 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorValidatorTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorValidatorTest.java @@ -27,7 +27,7 @@ import org.sonar.api.CoreProperties; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.bootstrap.ProjectReactor; import org.sonar.api.config.Settings; -import org.sonar.api.config.MapSettings; +import org.sonar.api.config.internal.MapSettings; import org.sonar.api.utils.MessageException; import org.sonar.scanner.analysis.DefaultAnalysisMode; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectScanContainerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectScanContainerTest.java index 05a0d06f4cd..0d2c247e3e8 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectScanContainerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectScanContainerTest.java @@ -24,7 +24,6 @@ import org.sonar.api.BatchExtension; import org.sonar.api.ServerExtension; import org.sonar.api.batch.InstantiationStrategy; import org.sonar.api.task.TaskExtension; -import org.sonar.scanner.scan.ProjectScanContainer; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/WorkDirectoryCleanerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/WorkDirectoryCleanerTest.java index c53512cbd19..58b4acc2823 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/WorkDirectoryCleanerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/WorkDirectoryCleanerTest.java @@ -19,6 +19,8 @@ */ package org.sonar.scanner.scan; +import java.io.File; +import java.io.IOException; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -26,9 +28,6 @@ import org.junit.rules.TemporaryFolder; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.bootstrap.ProjectReactor; import org.sonar.home.cache.DirectoryLock; -import org.sonar.scanner.scan.WorkDirectoryCleaner; -import java.io.File; -import java.io.IOException; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/AdditionalFilePredicatesTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/AdditionalFilePredicatesTest.java index 230ddbee1ec..d0522adac02 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/AdditionalFilePredicatesTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/AdditionalFilePredicatesTest.java @@ -23,7 +23,6 @@ import org.junit.Test; import org.sonar.api.batch.fs.FilePredicate; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; -import org.sonar.scanner.scan.filesystem.AdditionalFilePredicates; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ByteCharsetDetectorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ByteCharsetDetectorTest.java index ff3f3feb711..911fcc7c7fa 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ByteCharsetDetectorTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ByteCharsetDetectorTest.java @@ -19,13 +19,6 @@ */ package org.sonar.scanner.scan.filesystem; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - import java.io.IOException; import java.net.URISyntaxException; import java.nio.charset.Charset; @@ -33,13 +26,19 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; - import org.apache.commons.io.ByteOrderMark; import org.junit.Before; import org.junit.Test; import org.sonar.scanner.scan.filesystem.CharsetValidation.Result; import org.sonar.scanner.scan.filesystem.CharsetValidation.Validation; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyBoolean; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + public class ByteCharsetDetectorTest { private CharsetValidation validation; private ByteCharsetDetector charsets; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/CharsetDetectorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/CharsetDetectorTest.java index aeb38ee7993..0da6349119b 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/CharsetDetectorTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/CharsetDetectorTest.java @@ -19,13 +19,6 @@ */ package org.sonar.scanner.scan.filesystem; -import static java.nio.charset.StandardCharsets.US_ASCII; -import static java.nio.charset.StandardCharsets.UTF_16; -import static java.nio.charset.StandardCharsets.UTF_16BE; -import static java.nio.charset.StandardCharsets.UTF_16LE; -import static java.nio.charset.StandardCharsets.UTF_8; -import static org.assertj.core.api.Assertions.assertThat; - import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStreamReader; @@ -35,7 +28,6 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; import java.util.Random; - import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.junit.Rule; @@ -43,6 +35,13 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; +import static java.nio.charset.StandardCharsets.US_ASCII; +import static java.nio.charset.StandardCharsets.UTF_16; +import static java.nio.charset.StandardCharsets.UTF_16BE; +import static java.nio.charset.StandardCharsets.UTF_16LE; +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.assertj.core.api.Assertions.assertThat; + public class CharsetDetectorTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/CharsetValidationTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/CharsetValidationTest.java index 269bb6eef3a..9956a6aa25d 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/CharsetValidationTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/CharsetValidationTest.java @@ -19,8 +19,6 @@ */ package org.sonar.scanner.scan.filesystem; -import static org.assertj.core.api.Assertions.assertThat; - import java.io.IOException; import java.net.URISyntaxException; import java.nio.ByteBuffer; @@ -35,12 +33,13 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; import java.util.List; - import org.apache.commons.lang.StringUtils; import org.junit.Before; import org.junit.Test; import org.sonar.scanner.scan.filesystem.CharsetValidation.Validation; +import static org.assertj.core.api.Assertions.assertThat; + public class CharsetValidationTest { private CharsetValidation charsets; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ExclusionFiltersTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ExclusionFiltersTest.java index 20a528ac7a8..9815f2de7f2 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ExclusionFiltersTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ExclusionFiltersTest.java @@ -30,8 +30,7 @@ import org.sonar.api.CoreProperties; import org.sonar.api.batch.fs.IndexedFile; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.DefaultIndexedFile; -import org.sonar.api.config.MapSettings; -import org.sonar.api.config.Settings; +import org.sonar.api.config.internal.MapSettings; import org.sonar.api.scan.filesystem.FileExclusions; import static org.assertj.core.api.Assertions.assertThat; @@ -41,17 +40,19 @@ public class ExclusionFiltersTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); private Path moduleBaseDir; + private MapSettings settings; + private ExclusionFilters filter; @Before public void setUp() throws IOException { + settings = new MapSettings(); moduleBaseDir = temp.newFolder().toPath(); + filter = new ExclusionFilters(new FileExclusions(settings.asConfig())); } @Test public void no_inclusions_nor_exclusions() throws IOException { - ExclusionFilters filter = new ExclusionFilters(new FileExclusions(new MapSettings())); filter.prepare(); - IndexedFile indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/com/mycompany/FooDao.java"); assertThat(filter.accept(indexedFile, InputFile.Type.MAIN)).isTrue(); assertThat(filter.accept(indexedFile, InputFile.Type.TEST)).isTrue(); @@ -59,9 +60,7 @@ public class ExclusionFiltersTest { @Test public void match_inclusion() throws IOException { - Settings settings = new MapSettings(); settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "**/*Dao.java"); - ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings)); filter.prepare(); IndexedFile indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/com/mycompany/FooDao.java"); @@ -73,10 +72,7 @@ public class ExclusionFiltersTest { @Test public void match_at_least_one_inclusion() throws IOException { - Settings settings = new MapSettings(); settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "**/*Dao.java,**/*Dto.java"); - ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings)); - filter.prepare(); IndexedFile indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/com/mycompany/Foo.java"); @@ -88,12 +84,9 @@ public class ExclusionFiltersTest { @Test public void match_exclusions() throws IOException { - Settings settings = new MapSettings(); settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "src/main/java/**/*"); settings.setProperty(CoreProperties.PROJECT_TEST_INCLUSIONS_PROPERTY, "src/test/java/**/*"); settings.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "**/*Dao.java"); - ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings)); - filter.prepare(); IndexedFile indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/com/mycompany/FooDao.java"); @@ -111,11 +104,8 @@ public class ExclusionFiltersTest { public void match_exclusion_by_absolute_path() throws IOException { File excludedFile = new File(moduleBaseDir.toString(), "src/main/java/org/bar/Bar.java"); - Settings settings = new MapSettings(); settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "src/main/java/**/*"); settings.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "file:" + excludedFile.getAbsolutePath()); - ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings)); - filter.prepare(); IndexedFile indexedFile = new DefaultIndexedFile("foo", moduleBaseDir, "src/main/java/org/bar/Foo.java"); @@ -127,9 +117,7 @@ public class ExclusionFiltersTest { @Test public void trim_pattern() { - Settings settings = new MapSettings(); settings.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, " **/*Dao.java "); - ExclusionFilters filter = new ExclusionFilters(new FileExclusions(settings)); assertThat(filter.prepareMainExclusions()[0].toString()).isEqualTo("**/*Dao.java"); } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/InputFileBuilderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/InputFileBuilderTest.java index f3b147e00c4..4a7800668e3 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/InputFileBuilderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/InputFileBuilderTest.java @@ -19,13 +19,9 @@ */ package org.sonar.scanner.scan.filesystem; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; - import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Path; - import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -34,10 +30,12 @@ import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.fs.InputFile.Type; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.fs.internal.DefaultInputModule; -import org.sonar.api.config.MapSettings; -import org.sonar.api.config.Settings; +import org.sonar.api.config.internal.MapSettings; import org.sonar.api.scan.filesystem.PathResolver; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; + public class InputFileBuilderTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); @@ -56,8 +54,8 @@ public class InputFileBuilderTest { LanguageDetection langDetection = mock(LanguageDetection.class); MetadataGenerator metadataGenerator = mock(MetadataGenerator.class); BatchIdGenerator idGenerator = new BatchIdGenerator(); - Settings settings = new MapSettings(); - builder = new InputFileBuilder(module, pathResolver, langDetection, metadataGenerator, idGenerator, settings); + MapSettings settings = new MapSettings(); + builder = new InputFileBuilder(module, pathResolver, langDetection, metadataGenerator, idGenerator, settings.asConfig()); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/LanguageDetectionTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/LanguageDetectionTest.java index f59b3bf0632..86d33bb6660 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/LanguageDetectionTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/LanguageDetectionTest.java @@ -21,14 +21,14 @@ package org.sonar.scanner.scan.filesystem; import java.io.File; import java.io.IOException; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import org.sonar.api.CoreProperties; import org.sonar.api.batch.fs.internal.DefaultIndexedFile; -import org.sonar.api.config.Settings; -import org.sonar.api.config.MapSettings; +import org.sonar.api.config.internal.MapSettings; import org.sonar.api.resources.Language; import org.sonar.api.resources.Languages; import org.sonar.api.utils.MessageException; @@ -47,6 +47,13 @@ public class LanguageDetectionTest { @Rule public ExpectedException thrown = ExpectedException.none(); + private MapSettings settings; + + @Before + public void setUp() throws IOException { + settings = new MapSettings(); + } + @Test public void test_sanitizeExtension() throws Exception { assertThat(LanguageDetection.sanitizeExtension(".cbl")).isEqualTo("cbl"); @@ -58,7 +65,7 @@ public class LanguageDetectionTest { @Test public void search_by_file_extension() throws Exception { LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("java", "java", "jav"), new MockLanguage("cobol", "cbl", "cob"))); - LanguageDetection detection = new LanguageDetection(new MapSettings(), languages); + LanguageDetection detection = new LanguageDetection(settings.asConfig(), languages); assertThat(detection.language(newIndexedFile("Foo.java"))).isEqualTo("java"); assertThat(detection.language(newIndexedFile("src/Foo.java"))).isEqualTo("java"); @@ -75,7 +82,7 @@ public class LanguageDetectionTest { @Test public void should_not_fail_if_no_language() throws Exception { - LanguageDetection detection = spy(new LanguageDetection(new MapSettings(), new DefaultLanguagesRepository(new Languages()))); + LanguageDetection detection = spy(new LanguageDetection(settings.asConfig(), new DefaultLanguagesRepository(new Languages()))); assertThat(detection.language(newIndexedFile("Foo.java"))).isNull(); } @@ -83,7 +90,7 @@ public class LanguageDetectionTest { public void plugin_can_declare_a_file_extension_twice_for_case_sensitivity() throws Exception { LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("abap", "abap", "ABAP"))); - LanguageDetection detection = new LanguageDetection(new MapSettings(), languages); + LanguageDetection detection = new LanguageDetection(settings.asConfig(), languages); assertThat(detection.language(newIndexedFile("abc.abap"))).isEqualTo("abap"); } @@ -94,14 +101,13 @@ public class LanguageDetectionTest { LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("java", "java"), new MockLanguage("abap"))); // No side-effect on non-ABAP projects - LanguageDetection detection = new LanguageDetection(new MapSettings(), languages); + LanguageDetection detection = new LanguageDetection(settings.asConfig(), languages); assertThat(detection.language(newIndexedFile("abc"))).isNull(); assertThat(detection.language(newIndexedFile("abc.abap"))).isNull(); assertThat(detection.language(newIndexedFile("abc.java"))).isEqualTo("java"); - Settings settings = new MapSettings(); settings.setProperty(CoreProperties.PROJECT_LANGUAGE_PROPERTY, "abap"); - detection = new LanguageDetection(settings, languages); + detection = new LanguageDetection(settings.asConfig(), languages); assertThat(detection.language(newIndexedFile("abc"))).isEqualTo("abap"); assertThat(detection.language(newIndexedFile("abc.txt"))).isEqualTo("abap"); assertThat(detection.language(newIndexedFile("abc.java"))).isEqualTo("abap"); @@ -111,9 +117,8 @@ public class LanguageDetectionTest { public void force_language_using_deprecated_property() throws Exception { LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("java", "java"), new MockLanguage("php", "php"))); - Settings settings = new MapSettings(); settings.setProperty(CoreProperties.PROJECT_LANGUAGE_PROPERTY, "java"); - LanguageDetection detection = new LanguageDetection(settings, languages); + LanguageDetection detection = new LanguageDetection(settings.asConfig(), languages); assertThat(detection.language(newIndexedFile("abc"))).isNull(); assertThat(detection.language(newIndexedFile("abc.php"))).isNull(); assertThat(detection.language(newIndexedFile("abc.java"))).isEqualTo("java"); @@ -126,15 +131,14 @@ public class LanguageDetectionTest { thrown.expectMessage("You must install a plugin that supports the language 'unknown'"); LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("java", "java"), new MockLanguage("php", "php"))); - Settings settings = new MapSettings(); settings.setProperty(CoreProperties.PROJECT_LANGUAGE_PROPERTY, "unknown"); - new LanguageDetection(settings, languages); + new LanguageDetection(settings.asConfig(), languages); } @Test public void fail_if_conflicting_language_suffix() throws Exception { LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("xml", "xhtml"), new MockLanguage("web", "xhtml"))); - LanguageDetection detection = new LanguageDetection(new MapSettings(), languages); + LanguageDetection detection = new LanguageDetection(settings.asConfig(), languages); try { detection.language(newIndexedFile("abc.xhtml")); fail(); @@ -150,10 +154,9 @@ public class LanguageDetectionTest { public void solve_conflict_using_filepattern() throws Exception { LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("xml", "xhtml"), new MockLanguage("web", "xhtml"))); - Settings settings = new MapSettings(); settings.setProperty("sonar.lang.patterns.xml", "xml/**"); settings.setProperty("sonar.lang.patterns.web", "web/**"); - LanguageDetection detection = new LanguageDetection(settings, languages); + LanguageDetection detection = new LanguageDetection(settings.asConfig(), languages); assertThat(detection.language(newIndexedFile("xml/abc.xhtml"))).isEqualTo("xml"); assertThat(detection.language(newIndexedFile("web/abc.xhtml"))).isEqualTo("web"); } @@ -161,11 +164,10 @@ public class LanguageDetectionTest { @Test public void fail_if_conflicting_filepattern() throws Exception { LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("abap", "abap"), new MockLanguage("cobol", "cobol"))); - Settings settings = new MapSettings(); settings.setProperty("sonar.lang.patterns.abap", "*.abap,*.txt"); settings.setProperty("sonar.lang.patterns.cobol", "*.cobol,*.txt"); - LanguageDetection detection = new LanguageDetection(settings, languages); + LanguageDetection detection = new LanguageDetection(settings.asConfig(), languages); assertThat(detection.language(newIndexedFile("abc.abap"))).isEqualTo("abap"); assertThat(detection.language(newIndexedFile("abc.cobol"))).isEqualTo("cobol"); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/MetadataGeneratorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/MetadataGeneratorTest.java index ae73b76db13..b9a9723e0eb 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/MetadataGeneratorTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/MetadataGeneratorTest.java @@ -19,16 +19,10 @@ */ package org.sonar.scanner.scan.filesystem; -import static org.apache.commons.codec.digest.DigestUtils.md5Hex; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.nio.file.Paths; - import org.apache.commons.io.FileUtils; import org.junit.Assert; import org.junit.Before; @@ -47,6 +41,11 @@ import org.sonar.scanner.issue.ignore.pattern.IssueExclusionPatternInitializer; import org.sonar.scanner.issue.ignore.pattern.PatternMatcher; import org.sonar.scanner.issue.ignore.scanner.IssueExclusionsLoader; +import static org.apache.commons.codec.digest.DigestUtils.md5Hex; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + public class MetadataGeneratorTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/StatusDetectionFactoryTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/StatusDetectionFactoryTest.java index 2d6ffaa8449..160580763f0 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/StatusDetectionFactoryTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/StatusDetectionFactoryTest.java @@ -21,8 +21,6 @@ package org.sonar.scanner.scan.filesystem; import org.junit.Test; import org.sonar.scanner.repository.ProjectRepositories; -import org.sonar.scanner.scan.filesystem.StatusDetection; -import org.sonar.scanner.scan.filesystem.StatusDetectionFactory; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/StatusDetectionTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/StatusDetectionTest.java index 0c7eadb86bd..a295fdc08be 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/StatusDetectionTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/StatusDetectionTest.java @@ -26,7 +26,6 @@ import org.junit.Test; import org.sonar.api.batch.fs.InputFile; import org.sonar.scanner.repository.FileData; import org.sonar.scanner.repository.ProjectRepositories; -import org.sonar.scanner.scan.filesystem.StatusDetection; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/report/ConsoleReportTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/report/ConsoleReportTest.java index 572753822cd..0f302bf2161 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/report/ConsoleReportTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/report/ConsoleReportTest.java @@ -26,8 +26,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; -import org.sonar.api.config.Settings; -import org.sonar.api.config.MapSettings; +import org.sonar.api.config.internal.MapSettings; import org.sonar.api.rule.Severity; import org.sonar.api.utils.log.LogTester; import org.sonar.scanner.issue.IssueCache; @@ -43,7 +42,7 @@ public class ConsoleReportTest { @Rule public LogTester logTester = new LogTester(); - private Settings settings; + private MapSettings settings; private IssueCache issueCache; private InputComponentStore inputPathCache; private ConsoleReport report; @@ -53,7 +52,7 @@ public class ConsoleReportTest { settings = new MapSettings(); issueCache = mock(IssueCache.class); inputPathCache = mock(InputComponentStore.class); - report = new ConsoleReport(settings, issueCache, inputPathCache); + report = new ConsoleReport(settings.asConfig(), issueCache, inputPathCache); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/report/JSONReportTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/report/JSONReportTest.java index e999104d907..926b149ef3e 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/report/JSONReportTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/report/JSONReportTest.java @@ -41,8 +41,7 @@ import org.sonar.api.batch.fs.internal.InputModuleHierarchy; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.api.batch.rule.Rules; import org.sonar.api.batch.rule.internal.RulesBuilder; -import org.sonar.api.config.MapSettings; -import org.sonar.api.config.Settings; +import org.sonar.api.config.internal.MapSettings; import org.sonar.api.issue.Issue; import org.sonar.api.platform.Server; import org.sonar.api.rule.RuleKey; @@ -65,12 +64,12 @@ public class JSONReportTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); - JSONReport jsonReport; - DefaultFileSystem fs; - Server server = mock(Server.class); - Rules rules = mock(Rules.class); - Settings settings = new MapSettings(); - IssueCache issueCache = mock(IssueCache.class); + private JSONReport jsonReport; + private DefaultFileSystem fs; + private Server server = mock(Server.class); + private Rules rules = mock(Rules.class); + private MapSettings settings = new MapSettings(); + private IssueCache issueCache = mock(IssueCache.class); private InputModuleHierarchy moduleHierarchy; @Before @@ -111,7 +110,7 @@ public class JSONReportTest { RulesBuilder builder = new RulesBuilder(); builder.add(RuleKey.of("squid", "AvoidCycles")).setName("Avoid Cycles"); rules = builder.build(); - jsonReport = new JSONReport(moduleHierarchy, settings, fs, server, rules, issueCache, rootModule, inputComponentStore, inputComponentTree); + jsonReport = new JSONReport(moduleHierarchy, settings.asConfig(), fs, server, rules, issueCache, rootModule, inputComponentStore, inputComponentTree); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/report/RuleNameProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/report/RuleNameProviderTest.java index d9abc47deea..1284ab03bd2 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/report/RuleNameProviderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/report/RuleNameProviderTest.java @@ -19,24 +19,22 @@ */ package org.sonar.scanner.scan.report; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import static org.assertj.core.api.Assertions.assertThat; - -import static org.mockito.Matchers.any; - -import org.sonar.api.rule.RuleKey; -import org.sonar.scanner.scan.report.RuleNameProvider; -import org.sonar.api.batch.rule.Rule; -import org.junit.Test; import org.junit.Before; +import org.junit.Test; +import org.sonar.api.batch.rule.Rule; import org.sonar.api.batch.rule.Rules; +import org.sonar.api.rule.RuleKey; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class RuleNameProviderTest { - RuleNameProvider provider; - Rules rules; - Rule rule; - RuleKey ruleKey; + private RuleNameProvider provider; + private Rules rules; + private Rule rule; + private RuleKey ruleKey; @Before public void setUp() { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/DefaultBlameOutputTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/DefaultBlameOutputTest.java index f416dd642aa..8713d8c88a7 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/DefaultBlameOutputTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/DefaultBlameOutputTest.java @@ -27,7 +27,6 @@ import org.junit.rules.ExpectedException; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.api.batch.scm.BlameLine; -import org.sonar.scanner.scm.DefaultBlameOutput; public class DefaultBlameOutputTest { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorContextTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorContextTest.java index 2d5f98780f5..c73b0636e67 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorContextTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorContextTest.java @@ -33,8 +33,7 @@ import org.sonar.api.batch.measure.MetricFinder; import org.sonar.api.batch.rule.ActiveRules; import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; import org.sonar.api.batch.sensor.internal.SensorStorage; -import org.sonar.api.config.Settings; -import org.sonar.api.config.MapSettings; +import org.sonar.api.config.internal.MapSettings; import org.sonar.api.internal.SonarRuntimeImpl; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.utils.Version; @@ -54,7 +53,7 @@ public class DefaultSensorContextTest { private ActiveRules activeRules; private DefaultFileSystem fs; private DefaultSensorContext adaptor; - private Settings settings; + private MapSettings settings; private SensorStorage sensorStorage; private AnalysisMode analysisMode; private SonarRuntime runtime; @@ -70,7 +69,7 @@ public class DefaultSensorContextTest { sensorStorage = mock(SensorStorage.class); analysisMode = mock(AnalysisMode.class); runtime = SonarRuntimeImpl.forSonarQube(Version.parse("5.5"), SonarQubeSide.SCANNER); - adaptor = new DefaultSensorContext(mock(InputModule.class), settings, fs, activeRules, analysisMode, sensorStorage, runtime); + adaptor = new DefaultSensorContext(mock(InputModule.class), settings.asConfig(), settings, fs, activeRules, analysisMode, sensorStorage, runtime); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorStorageTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorStorageTest.java index 75d25e7080b..2c375606ae9 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorStorageTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorStorageTest.java @@ -34,8 +34,7 @@ import org.sonar.api.batch.measure.MetricFinder; import org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting; import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure; import org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable; -import org.sonar.api.config.MapSettings; -import org.sonar.api.config.Settings; +import org.sonar.api.config.internal.MapSettings; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.utils.KeyValueFormat; import org.sonar.core.metric.ScannerMetrics; @@ -63,7 +62,7 @@ public class DefaultSensorStorageTest { public ExpectedException thrown = ExpectedException.none(); private DefaultSensorStorage underTest; - private Settings settings; + private MapSettings settings; private ModuleIssues moduleIssues; private MeasureCache measureCache; private ContextPropertiesCache contextPropertiesCache = new ContextPropertiesCache(); @@ -81,7 +80,7 @@ public class DefaultSensorStorageTest { ReportPublisher reportPublisher = mock(ReportPublisher.class); when(reportPublisher.getWriter()).thenReturn(new ScannerReportWriter(temp.newFolder())); underTest = new DefaultSensorStorage(metricFinder, - moduleIssues, settings, coverageExclusions, reportPublisher, measureCache, + moduleIssues, settings.asConfig(), coverageExclusions, reportPublisher, measureCache, mock(SonarCpdBlockIndex.class), contextPropertiesCache, new ScannerMetrics()); } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/SensorOptimizerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/SensorOptimizerTest.java index 748470679cc..76b83f4318e 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/SensorOptimizerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/SensorOptimizerTest.java @@ -30,8 +30,7 @@ import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.api.batch.rule.ActiveRules; import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor; -import org.sonar.api.config.Settings; -import org.sonar.api.config.MapSettings; +import org.sonar.api.config.internal.MapSettings; import org.sonar.api.rule.RuleKey; import static org.assertj.core.api.Assertions.assertThat; @@ -46,13 +45,13 @@ public class SensorOptimizerTest { private DefaultFileSystem fs; private SensorOptimizer optimizer; - private Settings settings; + private MapSettings settings; @Before public void prepare() throws Exception { fs = new DefaultFileSystem(temp.newFolder().toPath()); settings = new MapSettings(); - optimizer = new SensorOptimizer(fs, new ActiveRulesBuilder().build(), settings); + optimizer = new SensorOptimizer(fs, new ActiveRulesBuilder().build(), settings.asConfig()); } @Test @@ -110,7 +109,7 @@ public class SensorOptimizerTest { .create(RuleKey.of("repo1", "foo")) .activate() .build(); - optimizer = new SensorOptimizer(fs, activeRules, settings); + optimizer = new SensorOptimizer(fs, activeRules, settings.asConfig()); assertThat(optimizer.shouldExecute(descriptor)).isFalse(); @@ -120,7 +119,7 @@ public class SensorOptimizerTest { .create(RuleKey.of("squid", "rule")) .activate() .build(); - optimizer = new SensorOptimizer(fs, activeRules, settings); + optimizer = new SensorOptimizer(fs, activeRules, settings.asConfig()); assertThat(optimizer.shouldExecute(descriptor)).isTrue(); } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/coverage/CoverageExclusionsTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/coverage/CoverageExclusionsTest.java index 99e82e68976..7eafee529ef 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/coverage/CoverageExclusionsTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/coverage/CoverageExclusionsTest.java @@ -23,22 +23,21 @@ import org.junit.Before; import org.junit.Test; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; -import org.sonar.api.config.MapSettings; import org.sonar.api.config.PropertyDefinitions; -import org.sonar.api.config.Settings; +import org.sonar.api.config.internal.MapSettings; import org.sonar.core.config.ExclusionProperties; import static org.assertj.core.api.Assertions.assertThat; public class CoverageExclusionsTest { - private Settings settings; + private MapSettings settings; private CoverageExclusions coverageExclusions; @Before public void prepare() { settings = new MapSettings(new PropertyDefinitions(ExclusionProperties.all())); - coverageExclusions = new CoverageExclusions(settings); + coverageExclusions = new CoverageExclusions(settings.asConfig()); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/source/DefaultHighlightableTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/source/DefaultHighlightableTest.java index 602d139bd84..45bd4fc8a06 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/source/DefaultHighlightableTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/source/DefaultHighlightableTest.java @@ -28,7 +28,6 @@ import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting; import org.sonar.api.batch.sensor.internal.SensorStorage; -import org.sonar.scanner.source.DefaultHighlightable; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/source/DefaultSymbolizableTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/source/DefaultSymbolizableTest.java index 80a35c1df7e..0c67f1369b5 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/source/DefaultSymbolizableTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/source/DefaultSymbolizableTest.java @@ -29,7 +29,6 @@ import org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable; import org.sonar.api.source.Symbol; import org.sonar.api.source.Symbolizable; import org.sonar.scanner.sensor.DefaultSensorStorage; -import org.sonar.scanner.source.DefaultSymbolizable; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/source/DeprecatedDefaultSymbolTableTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/source/DeprecatedDefaultSymbolTableTest.java index 7e7114edafa..370c6bdb5fd 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/source/DeprecatedDefaultSymbolTableTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/source/DeprecatedDefaultSymbolTableTest.java @@ -31,7 +31,6 @@ import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable; import org.sonar.api.source.Symbol; import org.sonar.api.source.Symbolizable; -import org.sonar.scanner.source.DeprecatedDefaultSymbolTable; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/storage/StorageTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/storage/StorageTest.java index 239f761710b..7b1b1791332 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/storage/StorageTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/storage/StorageTest.java @@ -22,7 +22,6 @@ package org.sonar.scanner.storage; import com.google.common.collect.Iterables; import org.junit.Test; import org.sonar.scanner.index.AbstractCachesTest; -import org.sonar.scanner.storage.Storage; import org.sonar.scanner.storage.Storage.Entry; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/storage/StoragesManagerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/storage/StoragesManagerTest.java index 612431b5110..03730f412b8 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/storage/StoragesManagerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/storage/StoragesManagerTest.java @@ -19,9 +19,9 @@ */ package org.sonar.scanner.storage; +import java.io.File; import org.junit.Test; import org.sonar.scanner.index.AbstractCachesTest; -import java.io.File; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/storage/StoragesTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/storage/StoragesTest.java index 4fd5337872a..4de2db91ee0 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/storage/StoragesTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/storage/StoragesTest.java @@ -19,13 +19,10 @@ */ package org.sonar.scanner.storage; -import java.io.Serializable; - import com.persistit.exception.PersistitException; +import java.io.Serializable; import org.junit.Test; import org.sonar.scanner.index.AbstractCachesTest; -import org.sonar.scanner.storage.Storage; -import org.sonar.scanner.storage.Storages; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/task/ListTaskTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/task/ListTaskTest.java index 9f7788a37ab..f07e6c8054e 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/task/ListTaskTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/task/ListTaskTest.java @@ -26,8 +26,6 @@ import org.sonar.api.task.Task; import org.sonar.api.task.TaskDefinition; import org.sonar.api.utils.log.LogTester; import org.sonar.api.utils.log.LoggerLevel; -import org.sonar.scanner.task.ListTask; -import org.sonar.scanner.task.Tasks; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/task/TasksTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/task/TasksTest.java index 93340aeeadf..828f86dfadb 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/task/TasksTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/task/TasksTest.java @@ -24,9 +24,6 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.api.task.Task; import org.sonar.api.task.TaskDefinition; -import org.sonar.scanner.task.ListTask; -import org.sonar.scanner.task.ScanTask; -import org.sonar.scanner.task.Tasks; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/util/ScannerUtilsTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/util/ScannerUtilsTest.java index 79e4fc3bcea..517cca80743 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/util/ScannerUtilsTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/util/ScannerUtilsTest.java @@ -20,7 +20,6 @@ package org.sonar.scanner.util; import org.junit.Test; -import org.sonar.scanner.util.ScannerUtils; import static org.assertj.core.api.Assertions.assertThat; |