From e20ec8f128b9680f000663481dcaf52c797fe14a Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Thu, 15 Nov 2018 10:58:11 +0100 Subject: [PATCH] SONAR-11476 Remove scanner task support --- .../org/sonar/batch/bootstrapper/Batch.java | 67 +++++--------- .../scanner/bootstrap/BatchComponents.java | 15 +--- .../scanner/bootstrap/GlobalContainer.java | 24 +++-- .../java/org/sonar/scanner/task/ListTask.java | 56 ------------ .../java/org/sonar/scanner/task/ScanTask.java | 45 ---------- .../org/sonar/scanner/task/TaskContainer.java | 88 ------------------ .../java/org/sonar/scanner/task/Tasks.java | 75 ---------------- .../org/sonar/scanner/task/ViewsTask.java | 47 ---------- .../org/sonar/scanner/task/package-info.java | 23 ----- .../mediumtest/ScannerMediumTester.java | 2 +- .../mediumtest/tasks/TasksMediumTest.java | 71 +++++---------- .../org/sonar/scanner/task/ListTaskTest.java | 63 ------------- .../org/sonar/scanner/task/TasksTest.java | 90 ------------------- .../org/sonar/scanner/task/ViewsTaskTest.java | 52 ----------- 14 files changed, 65 insertions(+), 653 deletions(-) delete mode 100644 sonar-scanner-engine/src/main/java/org/sonar/scanner/task/ListTask.java delete mode 100644 sonar-scanner-engine/src/main/java/org/sonar/scanner/task/ScanTask.java delete mode 100644 sonar-scanner-engine/src/main/java/org/sonar/scanner/task/TaskContainer.java delete mode 100644 sonar-scanner-engine/src/main/java/org/sonar/scanner/task/Tasks.java delete mode 100644 sonar-scanner-engine/src/main/java/org/sonar/scanner/task/ViewsTask.java delete mode 100644 sonar-scanner-engine/src/main/java/org/sonar/scanner/task/package-info.java delete mode 100644 sonar-scanner-engine/src/test/java/org/sonar/scanner/task/ListTaskTest.java delete mode 100644 sonar-scanner-engine/src/test/java/org/sonar/scanner/task/TasksTest.java delete mode 100644 sonar-scanner-engine/src/test/java/org/sonar/scanner/task/ViewsTaskTest.java 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 75c8725b8a8..ae16e5c247d 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 @@ -21,6 +21,7 @@ package org.sonar.batch.bootstrapper; import com.google.common.base.Throwables; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -38,8 +39,7 @@ public final class Batch { private LoggingConfiguration loggingConfig; private List components; - private Map scannerProperties = new HashMap<>(); - private GlobalContainer bootstrapContainer; + private Map globalProperties = new HashMap<>(); private Batch(Builder builder) { components = new ArrayList<>(); @@ -47,11 +47,11 @@ public final class Batch { if (builder.environment != null) { components.add(builder.environment); } - if (builder.scannerProperties != null) { - scannerProperties.putAll(builder.scannerProperties); + if (builder.globalProperties != null) { + globalProperties.putAll(builder.globalProperties); } if (builder.isEnableLoggingConfiguration()) { - loggingConfig = new LoggingConfiguration(builder.environment).setProperties(scannerProperties); + loggingConfig = new LoggingConfiguration(builder.environment).setProperties(globalProperties); if (builder.logOutput != null) { loggingConfig.setLogOutput(builder.logOutput); @@ -64,12 +64,15 @@ public final class Batch { } public synchronized Batch execute() { + return doExecute(this.globalProperties, this.components); + } + + public synchronized Batch doExecute(Map scannerProperties, List components) { configureLogging(); - doStart(); try { - doExecute(); - } finally { - doStop(); + GlobalContainer.create(scannerProperties, components).execute(); + } catch (RuntimeException e) { + throw handleException(e); } return this; } @@ -83,33 +86,17 @@ public final class Batch { return this; } - private Batch doStart() { - try { - bootstrapContainer = GlobalContainer.create(scannerProperties, components); - bootstrapContainer.startComponents(); - } catch (RuntimeException e) { - throw handleException(e); - } - - return this; - } - /** * @since 4.4 * @deprecated since 6.6 use {@link #execute()} */ @Deprecated public Batch executeTask(Map analysisProperties, Object... components) { - return execute(); - } - - private Batch doExecute(Object... components) { - try { - bootstrapContainer.executeTask(scannerProperties, components); - } catch (RuntimeException e) { - throw handleException(e); - } - return this; + Map mergedProps = new HashMap<>(this.globalProperties); + mergedProps.putAll(analysisProperties); + List mergedComponents = new ArrayList<>(this.components); + mergedComponents.addAll(Arrays.asList(components)); + return doExecute(mergedProps, mergedComponents); } private RuntimeException handleException(RuntimeException t) { @@ -134,17 +121,9 @@ public final class Batch { public synchronized void stop() { } - private void doStop() { - try { - bootstrapContainer.stopComponents(); - } catch (RuntimeException e) { - throw handleException(e); - } - } - private void configureLogging() { if (loggingConfig != null) { - loggingConfig.setProperties(scannerProperties); + loggingConfig.setProperties(globalProperties); LoggingConfigurator.apply(loggingConfig); } } @@ -154,7 +133,7 @@ public final class Batch { } public static final class Builder { - private Map scannerProperties; + private Map globalProperties; private EnvironmentInformation environment; private List components = new ArrayList<>(); private boolean enableLoggingConfiguration = true; @@ -178,17 +157,17 @@ public final class Batch { return this; } - public Builder setScannerProperties(Map scannerProperties) { - this.scannerProperties = scannerProperties; + public Builder setGlobalProperties(Map globalProperties) { + this.globalProperties = globalProperties; return this; } /** - * @deprecated since 6.6 use {@link #setScannerProperties(Map)} + * @deprecated since 6.6 use {@link #setGlobalProperties(Map)} */ @Deprecated public Builder setBootstrapProperties(Map bootstrapProperties) { - this.scannerProperties = bootstrapProperties; + this.globalProperties = bootstrapProperties; return this; } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/BatchComponents.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/BatchComponents.java index 52f00dce1a4..c6b844a78c3 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/BatchComponents.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/BatchComponents.java @@ -34,10 +34,6 @@ import org.sonar.scanner.scan.report.JSONReport; import org.sonar.scanner.scm.ScmConfiguration; import org.sonar.scanner.scm.ScmPublisher; import org.sonar.scanner.source.ZeroCoverageSensor; -import org.sonar.scanner.task.ListTask; -import org.sonar.scanner.task.ScanTask; -import org.sonar.scanner.task.Tasks; -import org.sonar.scanner.task.ViewsTask; public class BatchComponents { private BatchComponents() { @@ -46,16 +42,7 @@ public class BatchComponents { public static Collection all(GlobalAnalysisMode analysisMode) { List components = Lists.newArrayList( - DefaultResourceTypes.get(), - - // Tasks - Tasks.class, - ListTask.DEFINITION, - ListTask.class, - ScanTask.DEFINITION, - ScanTask.class, - ViewsTask.DEFINITION, - ViewsTask.class); + DefaultResourceTypes.get()); components.addAll(CorePropertyDefinitions.all()); if (!analysisMode.isIssues()) { // SCM 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 61e6534972c..a8202e1fc48 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 @@ -22,11 +22,14 @@ package org.sonar.scanner.bootstrap; import java.time.Clock; import java.util.List; import java.util.Map; +import org.apache.commons.lang.StringUtils; +import org.sonar.api.CoreProperties; import org.sonar.api.Plugin; import org.sonar.api.SonarQubeSide; import org.sonar.api.SonarQubeVersion; import org.sonar.api.internal.ApiVersion; import org.sonar.api.internal.SonarRuntimeImpl; +import org.sonar.api.utils.MessageException; import org.sonar.api.utils.System2; import org.sonar.api.utils.UriReader; import org.sonar.api.utils.Version; @@ -48,8 +51,8 @@ import org.sonar.scanner.repository.MetricsRepositoryLoader; import org.sonar.scanner.repository.MetricsRepositoryProvider; import org.sonar.scanner.repository.settings.DefaultSettingsLoader; import org.sonar.scanner.repository.settings.SettingsLoader; +import org.sonar.scanner.scan.ProjectScanContainer; import org.sonar.scanner.storage.StoragesManager; -import org.sonar.scanner.task.TaskContainer; public class GlobalContainer extends ComponentContainer { private static final Logger LOG = Loggers.get(GlobalContainer.class); @@ -111,6 +114,18 @@ public class GlobalContainer extends ComponentContainer { protected void doAfterStart() { installPlugins(); loadCoreExtensions(); + + long startTime = System.currentTimeMillis(); + String taskKey = StringUtils.defaultIfEmpty(scannerProperties.get(CoreProperties.TASK), CoreProperties.SCAN_TASK); + if (taskKey.equals("views")) { + throw MessageException.of("The task 'views' was removed with SonarQube 7.1. " + + "You can safely remove this call since portfolios and applications are automatically re-calculated."); + } else if (!taskKey.equals(CoreProperties.SCAN_TASK)) { + throw MessageException.of("Tasks support was removed in SonarQube 7.6."); + } + new ProjectScanContainer(this).execute(); + + LOG.info("Analysis total time: {}", formatTime(System.currentTimeMillis() - startTime)); } private void installPlugins() { @@ -126,13 +141,6 @@ public class GlobalContainer extends ComponentContainer { loader.load(); } - public void executeTask(Map taskProperties, Object... components) { - long startTime = System.currentTimeMillis(); - new TaskContainer(this, taskProperties, components).execute(); - - LOG.info("Task total time: {}", formatTime(System.currentTimeMillis() - startTime)); - } - static String formatTime(long time) { long h = time / (60 * 60 * 1000); long m = (time - h * 60 * 60 * 1000) / (60 * 1000); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/task/ListTask.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/task/ListTask.java deleted file mode 100644 index 7d12981786f..00000000000 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/task/ListTask.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.scanner.task; - -import org.sonar.api.task.Task; -import org.sonar.api.task.TaskDefinition; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; - -public class ListTask implements Task { - - private static final Logger LOG = Loggers.get(ListTask.class); - - public static final String KEY = "list"; - - public static final TaskDefinition DEFINITION = TaskDefinition.builder() - .key(KEY) - .description("List available tasks") - .taskClass(ListTask.class) - .build(); - - private final Tasks tasks; - - public ListTask(Tasks tasks) { - this.tasks = tasks; - } - - @Override - public void execute() { - StringBuilder sb = new StringBuilder(); - sb.append("\nAvailable tasks:\n"); - for (TaskDefinition def : tasks.definitions()) { - sb.append(" - " + def.key() + ": " + def.description() + "\n"); - } - sb.append("\n"); - LOG.info(sb.toString()); - } - -} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/task/ScanTask.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/task/ScanTask.java deleted file mode 100644 index 75fa6f856df..00000000000 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/task/ScanTask.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.scanner.task; - -import org.sonar.api.CoreProperties; -import org.sonar.api.task.Task; -import org.sonar.api.task.TaskDefinition; -import org.sonar.core.platform.ComponentContainer; -import org.sonar.scanner.scan.ProjectScanContainer; - -public class ScanTask implements Task { - public static final TaskDefinition DEFINITION = TaskDefinition.builder() - .description("Scan project") - .key(CoreProperties.SCAN_TASK) - .taskClass(ScanTask.class) - .build(); - - private final ComponentContainer taskContainer; - - public ScanTask(TaskContainer taskContainer) { - this.taskContainer = taskContainer; - } - - @Override - public void execute() { - new ProjectScanContainer(taskContainer).execute(); - } -} 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 deleted file mode 100644 index 6bea86a731d..00000000000 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/task/TaskContainer.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.scanner.task; - -import java.util.Map; -import org.apache.commons.lang.StringUtils; -import org.sonar.api.CoreProperties; -import org.sonar.api.task.Task; -import org.sonar.api.task.TaskDefinition; -import org.sonar.api.utils.MessageException; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; -import org.sonar.core.extension.CoreExtensionsInstaller; -import org.sonar.core.platform.ComponentContainer; -import org.sonar.scanner.bootstrap.ExtensionInstaller; - -import static org.sonar.api.batch.InstantiationStrategy.PER_TASK; -import static org.sonar.core.extension.CoreExtensionsInstaller.noExtensionFilter; -import static org.sonar.scanner.bootstrap.ExtensionUtils.isDeprecatedScannerSide; -import static org.sonar.scanner.bootstrap.ExtensionUtils.isInstantiationStrategy; - -public class TaskContainer extends ComponentContainer { - - private static final Logger LOG = Loggers.get(TaskContainer.class); - - private final Map taskProperties; - private final Object[] components; - - public TaskContainer(ComponentContainer parent, Map taskProperties, Object... components) { - super(parent); - this.taskProperties = taskProperties; - this.components = components; - } - - @Override - protected void doBeforeStart() { - addTaskExtensions(); - for (Object component : components) { - add(component); - } - } - - private void addTaskExtensions() { - getComponentByType(CoreExtensionsInstaller.class) - .install(this, noExtensionFilter(), t -> isInstantiationStrategy(t, PER_TASK)); - getComponentByType(ExtensionInstaller.class) - .install(this, extension -> isDeprecatedScannerSide(extension) && isInstantiationStrategy(extension, PER_TASK)); - } - - @Override - public void doAfterStart() { - // default value is declared in CorePlugin - String taskKey = StringUtils.defaultIfEmpty(taskProperties.get(CoreProperties.TASK), CoreProperties.SCAN_TASK); - if (!taskKey.equals(CoreProperties.SCAN_TASK)) { - LOG.warn("Scanner tasks are deprecated"); - } - // Release memory - taskProperties.clear(); - - TaskDefinition def = getComponentByType(Tasks.class).definition(taskKey); - if (def == null) { - throw MessageException.of("Task '" + taskKey + "' does not exist. Please use '" + ListTask.KEY + "' task to see all available tasks."); - } - Task task = getComponentByType(def.taskClass()); - if (task != null) { - task.execute(); - } else { - throw new IllegalStateException("Task " + taskKey + " is badly defined"); - } - } -} 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 deleted file mode 100644 index d3b7b3db73f..00000000000 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/task/Tasks.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.scanner.task; - -import com.google.common.collect.ImmutableSortedMap; -import com.google.common.collect.Maps; -import java.util.Collection; -import java.util.Map; -import java.util.SortedMap; -import org.sonar.api.batch.InstantiationStrategy; -import org.sonar.api.batch.ScannerSide; -import org.sonar.api.task.Task; -import org.sonar.api.task.TaskDefinition; - -@ScannerSide -@InstantiationStrategy(InstantiationStrategy.PER_TASK) -public class Tasks { - - private final SortedMap byKey; - - public Tasks(TaskDefinition[] definitions) { - SortedMap map = Maps.newTreeMap(); - for (TaskDefinition definition : definitions) { - if (map.containsKey(definition.key())) { - throw new IllegalStateException("Task '" + definition.key() + "' is declared twice"); - } - map.put(definition.key(), definition); - } - this.byKey = ImmutableSortedMap.copyOf(map); - } - - public TaskDefinition definition(String taskKey) { - return byKey.get(taskKey); - } - - public Collection definitions() { - return byKey.values(); - } - - /** - * Perform validation of task definitions - */ - public void start() { - checkDuplicatedClasses(); - } - - private void checkDuplicatedClasses() { - Map, TaskDefinition> byClass = Maps.newHashMap(); - for (TaskDefinition def : definitions()) { - TaskDefinition other = byClass.get(def.taskClass()); - if (other == null) { - byClass.put(def.taskClass(), def); - } else { - throw new IllegalStateException("Task '" + def.taskClass().getName() + "' is defined twice: first by '" + other.key() + "' and then by '" + def.key() + "'"); - } - } - } -} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/task/ViewsTask.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/task/ViewsTask.java deleted file mode 100644 index dcf725c3ef6..00000000000 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/task/ViewsTask.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.scanner.task; - -import org.sonar.api.task.Task; -import org.sonar.api.task.TaskDefinition; -import org.sonar.api.utils.MessageException; - -/** - * This task is deprecated since the refresh of portfolios and application is now automatic - * This task does nothing - * - * @deprecated since 7.1 - */ -@Deprecated -public class ViewsTask implements Task { - - private static final String KEY = "views"; - - public static final TaskDefinition DEFINITION = TaskDefinition.builder() - .key(KEY) - .description("Removed - was used to trigger portfolios refresh") - .taskClass(ViewsTask.class) - .build(); - - @Override - public void execute() { - throw MessageException.of("The task 'views' was removed with SonarQube 7.1. You can safely remove this call since portfolios and applications are automatically re-calculated."); - } -} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/task/package-info.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/task/package-info.java deleted file mode 100644 index 3ebb698f122..00000000000 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/task/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.scanner.task; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java index 31c1c682b55..08691f99683 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java @@ -289,7 +289,7 @@ public class ScannerMediumTester extends ExternalResource { props.putAll(taskProperties); Batch.builder() - .setScannerProperties(props) + .setGlobalProperties(props) .setEnableLoggingConfiguration(true) .addComponents(new EnvironmentInformation("mediumTest", "1.0"), tester.pluginInstaller, diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tasks/TasksMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tasks/TasksMediumTest.java index 7ec30f93bf7..9d3d84124b2 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tasks/TasksMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tasks/TasksMediumTest.java @@ -20,7 +20,6 @@ package org.sonar.scanner.mediumtest.tasks; import com.google.common.collect.ImmutableMap; -import org.assertj.core.api.Condition; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -29,10 +28,10 @@ import org.sonar.api.task.Task; import org.sonar.api.task.TaskDefinition; import org.sonar.api.utils.MessageException; import org.sonar.api.utils.log.LogTester; -import org.sonar.api.utils.log.LoggerLevel; import org.sonar.scanner.mediumtest.ScannerMediumTester; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; public class TasksMediumTest { @@ -47,47 +46,36 @@ public class TasksMediumTest { .registerPlugin("faketask", new FakeTaskPlugin()); @Test - public void listTasksIncludingBroken() throws Exception { - tester.newAnalysis() - .properties(ImmutableMap.builder() - .put("sonar.task", "list").build()) - .execute(); - - assertThat(logTester.logs()).haveExactly(1, new Condition() { - - @Override - public boolean matches(String value) { - return value.contains("Available tasks:") && value.contains("fake: Fake description") && value.contains("broken: Broken description"); - } - }); - - assertThat(logTester.logs(LoggerLevel.WARN)).contains("Scanner tasks are deprecated"); + public void failWhenCallingTask() throws Exception { + try { + tester.newAnalysis() + .properties(ImmutableMap.builder() + .put("sonar.task", "fake").build()) + .execute(); + fail("Expected exception"); + } catch (Exception e) { + assertThat(e).isInstanceOf(MessageException.class).hasMessage("Tasks support was removed in SonarQube 7.6."); + } } @Test - public void runBroken() throws Exception { - thrown.expect(IllegalStateException.class); - thrown.expectMessage( - "Unable to load component class org.sonar.scanner.mediumtest.tasks.TasksMediumTest$BrokenTask"); - - tester.newAnalysis() - .properties(ImmutableMap.builder() - .put("sonar.task", "broken").build()) - .execute(); - } - - @Test(expected = MessageException.class) - public void unsupportedTask() throws Exception { - tester.newAnalysis() - .properties(ImmutableMap.builder() - .put("sonar.task", "foo").build()) - .execute(); + public void failWhenCallingViews() throws Exception { + try { + tester.newAnalysis() + .properties(ImmutableMap.builder() + .put("sonar.task", "views").build()) + .execute(); + fail("Expected exception"); + } catch (Exception e) { + assertThat(e).isInstanceOf(MessageException.class).hasMessage("The task 'views' was removed with SonarQube 7.1. You can safely remove this call since portfolios and applications are automatically re-calculated."); + } } private static class FakeTaskPlugin implements Plugin { - @Override public void define(Context context) { - context.addExtensions(FakeTask.DEF, FakeTask.class, BrokenTask.DEF, BrokenTask.class); + @Override + public void define(Context context) { + context.addExtensions(FakeTask.DEF, FakeTask.class); } } @@ -103,15 +91,4 @@ public class TasksMediumTest { } - private static class BrokenTask implements Task { - - public static final TaskDefinition DEF = TaskDefinition.builder().key("broken").description("Broken description").taskClass(BrokenTask.class).build(); - - @Override - public void execute() { - // do nothing - } - - } - } 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 deleted file mode 100644 index 861c45b3d7e..00000000000 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/task/ListTaskTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.scanner.task; - -import java.util.Arrays; -import org.junit.Rule; -import org.junit.Test; -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 static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class ListTaskTest { - - @Rule - public LogTester logTester = new LogTester(); - - @Test - public void should_list_available_tasks() { - Tasks tasks = mock(Tasks.class); - when(tasks.definitions()).thenReturn(Arrays.asList( - TaskDefinition.builder().key("foo").description("Foo").taskClass(FooTask.class).build(), - TaskDefinition.builder().key("purge").description("Purge database").taskClass(FakePurgeTask.class).build())); - - ListTask task = new ListTask(tasks); - - task.execute(); - - assertThat(logTester.logs(LoggerLevel.INFO)).hasSize(1); - assertThat(logTester.logs(LoggerLevel.INFO).get(0)).contains("Available tasks:", " - foo: Foo", " - purge: Purge database"); - } - - private static class FakePurgeTask implements Task { - public void execute() { - } - } - - private static class FooTask implements Task { - public void execute() { - } - } -} 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 deleted file mode 100644 index d20875f31b0..00000000000 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/task/TasksTest.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.scanner.task; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.sonar.api.task.Task; -import org.sonar.api.task.TaskDefinition; - -import static org.assertj.core.api.Assertions.assertThat; - -public class TasksTest { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void should_get_definitions() { - Tasks tasks = new Tasks(new TaskDefinition[] {ScanTask.DEFINITION, ListTask.DEFINITION}); - assertThat(tasks.definitions()).hasSize(2); - } - - @Test - public void should_get_definition_by_key() { - Tasks tasks = new Tasks(new TaskDefinition[] {ScanTask.DEFINITION, ListTask.DEFINITION}); - tasks.start(); - assertThat(tasks.definition(ListTask.DEFINITION.key())).isEqualTo(ListTask.DEFINITION); - } - - @Test - public void should_return_null_if_task_not_found() { - Tasks tasks = new Tasks(new TaskDefinition[] {ScanTask.DEFINITION, ListTask.DEFINITION}); - - assertThat(tasks.definition("not-exists")).isNull(); - } - - @Test - public void should_fail_on_duplicated_keys() { - thrown.expect(IllegalStateException.class); - thrown.expectMessage("Task 'foo' is declared twice"); - - new Tasks(new TaskDefinition[] { - TaskDefinition.builder().key("foo").taskClass(FakeTask1.class).description("foo1").build(), - TaskDefinition.builder().key("foo").taskClass(FakeTask2.class).description("foo2").build() - }); - } - - @Test - public void should_fail_on_duplicated_class() { - Tasks tasks = new Tasks(new TaskDefinition[] { - TaskDefinition.builder().key("foo1").taskClass(FakeTask1.class).description("foo1").build(), - TaskDefinition.builder().key("foo2").taskClass(FakeTask1.class).description("foo1").build() - }); - - thrown.expect(IllegalStateException.class); - thrown.expectMessage("Task 'org.sonar.scanner.task.TasksTest$FakeTask1' is defined twice: first by 'foo1' and then by 'foo2'"); - - tasks.start(); - } - - private static class FakeTask1 implements Task { - public void execute() { - } - } - - private static class FakeTask2 implements Task { - public void execute() { - } - - } - -} diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/task/ViewsTaskTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/task/ViewsTaskTest.java deleted file mode 100644 index f4026e4b877..00000000000 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/task/ViewsTaskTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.scanner.task; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.sonar.api.utils.MessageException; -import org.sonar.api.utils.log.LogTester; - -public class ViewsTaskTest { - - @Rule - public LogTester logTester = new LogTester(); - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - private ViewsTask underTest = new ViewsTask(); - - @Test - public void triggerShowError() { - expectedException.expect(MessageException.class); - expectedException.expectMessage( - "The task 'views' was removed with SonarQube 7.1. You can safely remove this call since portfolios and applications are automatically re-calculated."); - - underTest.execute(); - } -} -- 2.39.5