From db739ab58a7979877fabeffdd371118e3dbf89f7 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Thu, 27 Jul 2017 15:44:32 +0200 Subject: [PATCH] SONAR-9606 Clean scanner-engine entry point --- .../org/sonar/batch/bootstrapper/Batch.java | 84 ++--- .../batch/bootstrapper/IssueListener.java | 172 --------- .../scanner/issue/DefaultIssueCallback.java | 78 ----- .../sonar/scanner/issue/IssueCallback.java | 25 -- .../scanner/phases/IssuesPhaseExecutor.java | 13 +- .../sonar/scanner/report/ReportPublisher.java | 16 +- .../scanner/scan/ProjectScanContainer.java | 5 +- .../issue/DefaultIssueCallbackTest.java | 124 ------- .../mediumtest/ScannerMediumTester.java | 330 ++++++++---------- .../mediumtest/branch/BranchMediumTest.java | 22 +- .../coverage/CoverageMediumTest.java | 27 +- .../coverage/GenericCoverageMediumTest.java | 23 +- .../scanner/mediumtest/cpd/CpdMediumTest.java | 25 +- .../deprecated/DeprecatedApiMediumTest.java | 25 +- .../mediumtest/fs/FileSystemMediumTest.java | 110 ++---- .../fs/NoLanguagesPluginsMediumTest.java | 20 +- .../fs/ProjectBuilderMediumTest.java | 26 +- .../highlighting/HighlightingMediumTest.java | 24 +- .../mediumtest/issues/ChecksMediumTest.java | 21 +- .../issues/IssuesIssuesModeMediumTest.java | 99 ------ .../mediumtest/issues/IssuesMediumTest.java | 55 +-- .../issues/IssuesOnDirMediumTest.java | 25 +- .../issues/IssuesOnModuleMediumTest.java | 23 +- .../issues/MultilineIssuesMediumTest.java | 19 +- .../mediumtest/issuesmode/EmptyFileTest.java | 24 +- .../IssueModeAndReportsMediumTest.java | 62 +--- .../issuesmode/NoPreviousAnalysisTest.java | 26 +- .../issuesmode/ScanOnlyChangedTest.java | 33 +- .../mediumtest/log/LogListenerTest.java | 19 +- .../measures/MeasuresMediumTest.java | 29 +- .../scanner/mediumtest/scm/ScmMediumTest.java | 38 +- .../mediumtest/symbol/SymbolMediumTest.java | 25 +- .../mediumtest/tasks/TasksMediumTest.java | 23 +- .../tests/CoveragePerTestMediumTest.java | 20 +- .../tests/GenericTestExecutionMediumTest.java | 27 +- .../tests/TestExecutionMediumTest.java | 21 +- .../scanner/report/ReportPublisherTest.java | 23 +- .../sonarqube/tests/analysis/ScannerTest.java | 8 +- 38 files changed, 417 insertions(+), 1352 deletions(-) delete mode 100644 sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/IssueListener.java delete mode 100644 sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultIssueCallback.java delete mode 100644 sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssueCallback.java delete mode 100644 sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DefaultIssueCallbackTest.java delete mode 100644 sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesIssuesModeMediumTest.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 07540030654..9d745c53008 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 @@ -39,7 +39,7 @@ public final class Batch { private boolean started = false; private LoggingConfiguration loggingConfig; private List components; - private Map bootstrapProperties = new HashMap<>(); + private Map globalProperties = new HashMap<>(); private GlobalContainer bootstrapContainer; private Batch(Builder builder) { @@ -48,11 +48,11 @@ public final class Batch { if (builder.environment != null) { components.add(builder.environment); } - if (builder.bootstrapProperties != null) { - bootstrapProperties.putAll(builder.bootstrapProperties); + if (builder.globalProperties != null) { + globalProperties.putAll(builder.globalProperties); } if (builder.isEnableLoggingConfiguration()) { - loggingConfig = new LoggingConfiguration(builder.environment).setProperties(bootstrapProperties); + loggingConfig = new LoggingConfiguration(builder.environment).setProperties(globalProperties); if (builder.logOutput != null) { loggingConfig.setLogOutput(builder.logOutput); @@ -64,39 +64,35 @@ public final class Batch { return loggingConfig; } - /** - * @deprecated since 4.4 use {@link #start()}, {@link #executeTask(Map)} and then {@link #stop()} - */ - @Deprecated public synchronized Batch execute() { configureLogging(); - start(); + doStart(); boolean threw = true; try { - executeTask(bootstrapProperties); + doExecuteTask(globalProperties); threw = false; } finally { doStop(threw); } - return this; } /** * @since 4.4 + * @deprecated since 6.6 use {@link #execute()} */ + @Deprecated public synchronized Batch start() { - return start(false); - } - - public synchronized Batch start(boolean preferCache) { if (started) { - throw new IllegalStateException("Batch is already started"); + throw new IllegalStateException("Scanner Engine is already started"); } - configureLogging(); + return doStart(); + } + + private Batch doStart() { try { - bootstrapContainer = GlobalContainer.create(bootstrapProperties, components); + bootstrapContainer = GlobalContainer.create(globalProperties, components); bootstrapContainer.startComponents(); } catch (RuntimeException e) { throw handleException(e); @@ -108,26 +104,18 @@ public final class Batch { /** * @since 4.4 + * @deprecated since 6.6 use {@link #execute()} */ + @Deprecated public Batch executeTask(Map analysisProperties, Object... components) { checkStarted(); configureTaskLogging(analysisProperties); - try { - bootstrapContainer.executeTask(analysisProperties, components); - } catch (RuntimeException e) { - throw handleException(e); - } - return this; + return doExecuteTask(analysisProperties, components); } - /** - * @since 5.2 - */ - public Batch executeTask(Map analysisProperties, IssueListener issueListener) { - checkStarted(); - configureTaskLogging(analysisProperties); + private Batch doExecuteTask(Map analysisProperties, Object... components) { try { - bootstrapContainer.executeTask(analysisProperties, components, issueListener); + bootstrapContainer.executeTask(analysisProperties, components); } catch (RuntimeException e) { throw handleException(e); } @@ -154,26 +142,18 @@ public final class Batch { return t; } - /** - * @since 5.2 - * @deprecated since 5.6 - */ - @Deprecated - public Batch syncProject(String projectKey) { - checkStarted(); - return this; - } - /** * @since 4.4 + * @deprecated since 6.6 use {@link #execute()} */ + @Deprecated public synchronized void stop() { + checkStarted(); + configureLogging(); doStop(false); } private void doStop(boolean swallowException) { - checkStarted(); - configureLogging(); try { bootstrapContainer.stopComponents(swallowException); } catch (RuntimeException e) { @@ -184,14 +164,14 @@ public final class Batch { private void configureLogging() { if (loggingConfig != null) { - loggingConfig.setProperties(bootstrapProperties); + loggingConfig.setProperties(globalProperties); LoggingConfigurator.apply(loggingConfig); } } private void configureTaskLogging(Map taskProperties) { if (loggingConfig != null) { - loggingConfig.setProperties(taskProperties, bootstrapProperties); + loggingConfig.setProperties(taskProperties, globalProperties); LoggingConfigurator.apply(loggingConfig); } } @@ -201,7 +181,7 @@ public final class Batch { } public static final class Builder { - private Map bootstrapProperties; + private Map globalProperties; private EnvironmentInformation environment; private List components = new ArrayList<>(); private boolean enableLoggingConfiguration = true; @@ -225,17 +205,17 @@ public final class Batch { return this; } - /** - * @deprecated since 3.7 use {@link #setBootstrapProperties(Map)} - */ - @Deprecated public Builder setGlobalProperties(Map globalProperties) { - this.bootstrapProperties = globalProperties; + this.globalProperties = globalProperties; return this; } + /** + * @deprecated since 6.6 use {@link #setGlobalProperties(Map)} + */ + @Deprecated public Builder setBootstrapProperties(Map bootstrapProperties) { - this.bootstrapProperties = bootstrapProperties; + this.globalProperties = bootstrapProperties; return this; } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/IssueListener.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/IssueListener.java deleted file mode 100644 index 5255126aee5..00000000000 --- a/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/IssueListener.java +++ /dev/null @@ -1,172 +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.batch.bootstrapper; - -/** - * @deprecated since 6.2 was used by initial version of SonarLint. No more used. - */ -@Deprecated -@FunctionalInterface -public interface IssueListener { - void handle(Issue issue); - - class Issue { - /** @since 5.3 */ - private Integer startLine; - /** @since 5.3 */ - private Integer startLineOffset; - /** @since 5.3 */ - private Integer endLine; - /** @since 5.3 */ - private Integer endLineOffset; - - private String key; - private String componentKey; - private String message; - private String ruleKey; - private String ruleName; - private String status; - private String resolution; - private boolean isNew; - private String assigneeLogin; - private String assigneeName; - private String severity; - - public String getSeverity() { - return severity; - } - - public void setSeverity(String severity) { - this.severity = severity; - } - - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - - public String getComponentKey() { - return componentKey; - } - - public void setComponentKey(String componentKey) { - this.componentKey = componentKey; - } - - public Integer getStartLine() { - return startLine; - } - - public void setStartLine(Integer startLine) { - this.startLine = startLine; - } - - public Integer getStartLineOffset() { - return startLineOffset; - } - - public void setStartLineOffset(Integer startLineOffset) { - this.startLineOffset = startLineOffset; - } - - public Integer getEndLine() { - return endLine; - } - - public void setEndLine(Integer endLine) { - this.endLine = endLine; - } - - public Integer getEndLineOffset() { - return endLineOffset; - } - - public void setEndLineOffset(Integer endLineOffset) { - this.endLineOffset = endLineOffset; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public String getRuleKey() { - return ruleKey; - } - - public void setRuleKey(String ruleKey) { - this.ruleKey = ruleKey; - } - - public String getRuleName() { - return ruleName; - } - - public void setRuleName(String ruleName) { - this.ruleName = ruleName; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - public String getResolution() { - return resolution; - } - - public void setResolution(String resolution) { - this.resolution = resolution; - } - - public boolean isNew() { - return isNew; - } - - public void setNew(boolean isNew) { - this.isNew = isNew; - } - - public String getAssigneeLogin() { - return assigneeLogin; - } - - public void setAssigneeLogin(String assigneeLogin) { - this.assigneeLogin = assigneeLogin; - } - - public String getAssigneeName() { - return assigneeName; - } - - public void setAssigneeName(String assigneeName) { - this.assigneeName = assigneeName; - } - } -} 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 deleted file mode 100644 index ca0c2cad15e..00000000000 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultIssueCallback.java +++ /dev/null @@ -1,78 +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.issue; - -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 { - private final IssueCache issues; - private final IssueListener listener; - private final Rules rules; - - public DefaultIssueCallback(IssueCache issues, IssueListener listener, Rules rules) { - this.issues = issues; - this.listener = listener; - this.rules = rules; - } - - /** - * If no listener exists, this constructor will be used by pico. - */ - public DefaultIssueCallback(IssueCache issues, Rules rules) { - this(issues, null, rules); - } - - @Override - public void execute() { - if (listener == null) { - return; - } - - for (TrackedIssue issue : issues.all()) { - IssueListener.Issue newIssue = new IssueListener.Issue(); - newIssue.setAssigneeLogin(issue.assignee()); - newIssue.setAssigneeName(issue.assignee()); - newIssue.setComponentKey(issue.componentKey()); - newIssue.setKey(issue.key()); - newIssue.setMessage(issue.getMessage()); - newIssue.setNew(issue.isNew()); - newIssue.setResolution(issue.resolution()); - newIssue.setRuleKey(issue.getRuleKey().toString()); - newIssue.setRuleName(getRuleName(issue.getRuleKey())); - newIssue.setSeverity(issue.severity()); - newIssue.setStatus(issue.status()); - newIssue.setStartLine(issue.startLine()); - newIssue.setStartLineOffset(issue.startLineOffset()); - newIssue.setEndLine(issue.endLine()); - newIssue.setEndLineOffset(issue.endLineOffset()); - - listener.handle(newIssue); - } - } - - private String getRuleName(RuleKey ruleKey) { - Rule rule = rules.find(ruleKey); - return rule != null ? rule.name() : null; - } -} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssueCallback.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssueCallback.java deleted file mode 100644 index 297604bbc71..00000000000 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssueCallback.java +++ /dev/null @@ -1,25 +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.issue; - -@FunctionalInterface -public interface IssueCallback { - void execute(); -} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/IssuesPhaseExecutor.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/IssuesPhaseExecutor.java index e2fd0aea9ff..b82ca8961a7 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/IssuesPhaseExecutor.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/IssuesPhaseExecutor.java @@ -25,7 +25,6 @@ import org.sonar.api.batch.SensorContext; import org.sonar.api.batch.fs.internal.InputModuleHierarchy; import org.sonar.scanner.events.BatchStepEvent; import org.sonar.scanner.events.EventBus; -import org.sonar.scanner.issue.IssueCallback; import org.sonar.scanner.issue.ignore.scanner.IssueExclusionsLoader; import org.sonar.scanner.issue.tracking.IssueTransition; import org.sonar.scanner.rule.QProfileVerifier; @@ -40,22 +39,19 @@ public final class IssuesPhaseExecutor extends AbstractPhaseExecutor { private final EventBus eventBus; private final IssuesReports issuesReport; private final IssueTransition localIssueTracking; - private final IssueCallback issueCallback; public IssuesPhaseExecutor(InitializersExecutor initializersExecutor, PostJobsExecutor postJobsExecutor, SensorsExecutor sensorsExecutor, SensorContext sensorContext, EventBus eventBus, FileSystemLogger fsLogger, IssuesReports jsonReport, DefaultModuleFileSystem fs, QProfileVerifier profileVerifier, - IssueExclusionsLoader issueExclusionsLoader, IssueTransition localIssueTracking, IssueCallback issueCallback, InputModuleHierarchy moduleHierarchy) { + IssueExclusionsLoader issueExclusionsLoader, IssueTransition localIssueTracking, InputModuleHierarchy moduleHierarchy) { super(initializersExecutor, postJobsExecutor, sensorsExecutor, sensorContext, moduleHierarchy, eventBus, fsLogger, fs, profileVerifier, issueExclusionsLoader); this.eventBus = eventBus; this.issuesReport = jsonReport; this.localIssueTracking = localIssueTracking; - this.issueCallback = issueCallback; } @Override protected void executeOnRoot() { localIssueTracking(); - issuesCallback(); issuesReport(); LOG.info("ANALYSIS SUCCESSFUL"); } @@ -67,13 +63,6 @@ public final class IssuesPhaseExecutor extends AbstractPhaseExecutor { eventBus.fireEvent(new BatchStepEvent(stepName, false)); } - private void issuesCallback() { - String stepName = "Issues Callback"; - eventBus.fireEvent(new BatchStepEvent(stepName, true)); - issueCallback.execute(); - eventBus.fireEvent(new BatchStepEvent(stepName, false)); - } - private void issuesReport() { String stepName = "Issues Reports"; eventBus.fireEvent(new BatchStepEvent(stepName, true)); 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 54fd94ca923..a909a9a4aca 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 @@ -19,8 +19,8 @@ */ package org.sonar.scanner.report; -import static org.sonar.core.util.FileUtils.deleteQuietly; - +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Throwables; import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -31,9 +31,8 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.LinkedHashMap; import java.util.Map; - import javax.annotation.Nullable; - +import okhttp3.HttpUrl; import org.apache.commons.io.FileUtils; import org.picocontainer.Startable; import org.sonar.api.CoreProperties; @@ -55,17 +54,14 @@ import org.sonarqube.ws.client.HttpException; import org.sonarqube.ws.client.PostRequest; import org.sonarqube.ws.client.WsResponse; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Throwables; - -import okhttp3.HttpUrl; +import static org.sonar.core.util.FileUtils.deleteQuietly; @ScannerSide public class ReportPublisher implements Startable { private static final Logger LOG = Loggers.get(ReportPublisher.class); - public static final String KEEP_REPORT_PROP_KEY = "sonar.batch.keepReport"; + public static final String KEEP_REPORT_PROP_KEY = "sonar.scanner.keepReport"; public static final String VERBOSE_KEY = "sonar.verbose"; public static final String METADATA_DUMP_FILENAME = "report-task.txt"; @@ -95,7 +91,7 @@ public class ReportPublisher implements Startable { @Override public void start() { - reportDir = new File(moduleHierarchy.root().getWorkDir(), "batch-report"); + reportDir = new File(moduleHierarchy.root().getWorkDir(), "scanner-report"); writer = new ScannerReportWriter(reportDir); contextPublisher.init(writer); 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 458239cc526..291630228c7 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 @@ -19,6 +19,7 @@ */ 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; @@ -47,7 +48,6 @@ import org.sonar.scanner.deprecated.test.TestPlanBuilder; import org.sonar.scanner.deprecated.test.TestableBuilder; import org.sonar.scanner.events.EventBus; import org.sonar.scanner.index.DefaultIndex; -import org.sonar.scanner.issue.DefaultIssueCallback; import org.sonar.scanner.issue.DefaultProjectIssues; import org.sonar.scanner.issue.IssueCache; import org.sonar.scanner.issue.tracking.DefaultServerLineHashesLoader; @@ -92,8 +92,6 @@ import org.sonar.scanner.scan.measure.DeprecatedMetricFinder; import org.sonar.scanner.scan.measure.MeasureCache; import org.sonar.scanner.storage.Storages; -import com.google.common.annotations.VisibleForTesting; - public class ProjectScanContainer extends ComponentContainer { private static final Logger LOG = Loggers.get(ProjectScanContainer.class); @@ -157,7 +155,6 @@ public class ProjectScanContainer extends ComponentContainer { new QualityProfileProvider(), // issues - DefaultIssueCallback.class, IssueCache.class, DefaultProjectIssues.class, IssueTransition.class, 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 deleted file mode 100644 index c5f606f7739..00000000000 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DefaultIssueCallbackTest.java +++ /dev/null @@ -1,124 +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.issue; - -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.sonar.scanner.issue.tracking.TrackedIssue; - -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 DefaultIssueCallbackTest { - @Mock - private IssueCache issueCache; - @Mock - private Rules rules; - - private TrackedIssue issue; - - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - - RuleKey ruleKey = RuleKey.of("repo", "key"); - issue = new TrackedIssue(); - issue.setKey("key"); - issue.setAssignee("user"); - issue.setRuleKey(ruleKey); - - when(issueCache.all()).thenReturn(ImmutableList.of(issue)); - - Rule r = mock(Rule.class); - when(r.name()).thenReturn("rule name"); - when(rules.find(ruleKey)).thenReturn(r); - } - - @Test - public void testWithoutListener() { - DefaultIssueCallback issueCallback = new DefaultIssueCallback(issueCache, rules); - issueCallback.execute(); - } - - @Test - public void testWithListener() { - final List issueList = new LinkedList<>(); - IssueListener listener = new IssueListener() { - @Override - public void handle(Issue issue) { - issueList.add(issue); - } - }; - - DefaultIssueCallback issueCallback = new DefaultIssueCallback(issueCache, listener, rules); - issueCallback.execute(); - - assertThat(issueList).hasSize(1); - Issue callbackIssue = issueList.get(0); - - assertThat(callbackIssue.getAssigneeName()).isEqualTo("user"); - assertThat(callbackIssue.getRuleName()).isEqualTo("rule name"); - } - - @Test - public void testWithNulls() { - final List issueList = new LinkedList<>(); - IssueListener listener = new IssueListener() { - @Override - public void handle(Issue issue) { - issueList.add(issue); - } - }; - - issue.setKey(null); - issue.setAssignee(null); - - DefaultIssueCallback issueCallback = new DefaultIssueCallback(issueCache, listener, rules); - issueCallback.execute(); - } - - @Test - public void testDecorationNotFound() { - final List issueList = new LinkedList<>(); - IssueListener listener = new IssueListener() { - @Override - public void handle(Issue issue) { - issueList.add(issue); - } - }; - - when(rules.find(any(RuleKey.class))).thenReturn(null); - - DefaultIssueCallback issueCallback = new DefaultIssueCallback(issueCache, listener, rules); - issueCallback.execute(); - } -} 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 065dc0bcc4b..92d0cd0598f 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 @@ -39,7 +39,7 @@ import java.util.Properties; import java.util.function.Consumer; import javax.annotation.Nullable; import org.apache.commons.io.FileUtils; -import org.sonar.api.CoreProperties; +import org.junit.rules.ExternalResource; import org.sonar.api.Plugin; import org.sonar.api.batch.debt.internal.DefaultDebtModel; import org.sonar.api.measures.CoreMetrics; @@ -50,7 +50,6 @@ import org.sonar.api.server.rule.RulesDefinition.Repository; import org.sonar.api.utils.DateUtils; import org.sonar.batch.bootstrapper.Batch; import org.sonar.batch.bootstrapper.EnvironmentInformation; -import org.sonar.batch.bootstrapper.IssueListener; import org.sonar.batch.bootstrapper.LogOutput; import org.sonar.scanner.bootstrap.GlobalMode; import org.sonar.scanner.issue.tracking.ServerLineHashesLoader; @@ -74,226 +73,170 @@ import org.sonarqube.ws.Rules.ListResponse.Rule; * Main utility class for writing scanner medium tests. * */ -public class ScannerMediumTester { - - private Batch batch; - private static Path workingDir = null; - private static Path globalWorkingDir = null; +public class ScannerMediumTester extends ExternalResource { + + private static Path userHome = null; + private Map globalProperties = new HashMap<>(); + private final FakeMetricsRepositoryLoader globalRefProvider = new FakeMetricsRepositoryLoader(); + private final FakeProjectRepositoriesLoader projectRefProvider = new FakeProjectRepositoriesLoader(); + private final FakePluginInstaller pluginInstaller = new FakePluginInstaller(); + private final FakeServerIssuesLoader serverIssues = new FakeServerIssuesLoader(); + private final FakeServerLineHashesLoader serverLineHashes = new FakeServerLineHashesLoader(); + private final FakeRulesLoader rulesLoader = new FakeRulesLoader(); + private final FakeQualityProfileLoader qualityProfiles = new FakeQualityProfileLoader(); + private final FakeActiveRulesLoader activeRules = new FakeActiveRulesLoader(); + private LogOutput logOutput = null; private static void createWorkingDirs() throws IOException { destroyWorkingDirs(); - workingDir = java.nio.file.Files.createTempDirectory("mediumtest-working-dir"); - globalWorkingDir = java.nio.file.Files.createTempDirectory("mediumtest-global-working-dir"); + userHome = java.nio.file.Files.createTempDirectory("mediumtest-userHome"); } private static void destroyWorkingDirs() throws IOException { - if (workingDir != null) { - FileUtils.deleteDirectory(workingDir.toFile()); - workingDir = null; - } - - if (globalWorkingDir != null) { - FileUtils.deleteDirectory(globalWorkingDir.toFile()); - globalWorkingDir = null; + if (userHome != null) { + FileUtils.deleteDirectory(userHome.toFile()); + userHome = null; } - } - public static BatchMediumTesterBuilder builder() { - try { - createWorkingDirs(); - } catch (IOException e) { - e.printStackTrace(); - } - - BatchMediumTesterBuilder builder = new BatchMediumTesterBuilder().registerCoreMetrics(); - builder.bootstrapProperties.put(GlobalMode.MEDIUM_TEST_ENABLED, "true"); - builder.bootstrapProperties.put(ReportPublisher.KEEP_REPORT_PROP_KEY, "true"); - builder.bootstrapProperties.put(CoreProperties.WORKING_DIRECTORY, workingDir.toString()); - builder.bootstrapProperties.put("sonar.userHome", globalWorkingDir.toString()); - return builder; + public ScannerMediumTester setLogOutput(LogOutput logOutput) { + this.logOutput = logOutput; + return this; } - public static class BatchMediumTesterBuilder { - private final FakeMetricsRepositoryLoader globalRefProvider = new FakeMetricsRepositoryLoader(); - private final FakeProjectRepositoriesLoader projectRefProvider = new FakeProjectRepositoriesLoader(); - private final FakePluginInstaller pluginInstaller = new FakePluginInstaller(); - private final FakeServerIssuesLoader serverIssues = new FakeServerIssuesLoader(); - private final FakeServerLineHashesLoader serverLineHashes = new FakeServerLineHashesLoader(); - private final Map bootstrapProperties = new HashMap<>(); - private final FakeRulesLoader rulesLoader = new FakeRulesLoader(); - private final FakeQualityProfileLoader qualityProfiles = new FakeQualityProfileLoader(); - private final FakeActiveRulesLoader activeRules = new FakeActiveRulesLoader(); - private boolean associated = true; - private LogOutput logOutput = null; - - public ScannerMediumTester build() { - return new ScannerMediumTester(this); - } - - public BatchMediumTesterBuilder setAssociated(boolean associated) { - this.associated = associated; - return this; - } - - public BatchMediumTesterBuilder setLogOutput(LogOutput logOutput) { - this.logOutput = logOutput; - return this; - } + public ScannerMediumTester registerPlugin(String pluginKey, File location) { + pluginInstaller.add(pluginKey, location); + return this; + } - public BatchMediumTesterBuilder registerPlugin(String pluginKey, File location) { - pluginInstaller.add(pluginKey, location); - return this; - } + public ScannerMediumTester registerPlugin(String pluginKey, Plugin instance) { + pluginInstaller.add(pluginKey, instance); + return this; + } - public BatchMediumTesterBuilder registerPlugin(String pluginKey, Plugin instance) { - pluginInstaller.add(pluginKey, instance); - return this; + public ScannerMediumTester registerCoreMetrics() { + for (Metric m : CoreMetrics.getMetrics()) { + registerMetric(m); } + return this; + } - public BatchMediumTesterBuilder registerCoreMetrics() { - for (Metric m : CoreMetrics.getMetrics()) { - registerMetric(m); - } - return this; - } + public ScannerMediumTester registerMetric(Metric metric) { + globalRefProvider.add(metric); + return this; + } - public BatchMediumTesterBuilder registerMetric(Metric metric) { - globalRefProvider.add(metric); - return this; - } + public ScannerMediumTester addQProfile(String language, String name) { + qualityProfiles.add(language, name); + return this; + } - public BatchMediumTesterBuilder addQProfile(String language, String name) { - qualityProfiles.add(language, name); - return this; - } + public ScannerMediumTester addRule(Rule rule) { + rulesLoader.addRule(rule); + return this; + } - public BatchMediumTesterBuilder addRule(Rule rule) { - rulesLoader.addRule(rule); - return this; + public ScannerMediumTester addRule(String key, String repoKey, String internalKey, String name) { + Rule.Builder builder = Rule.newBuilder(); + builder.setKey(key); + builder.setRepository(repoKey); + if (internalKey != null) { + builder.setInternalKey(internalKey); } + builder.setName(name); - public BatchMediumTesterBuilder addRule(String key, String repoKey, String internalKey, String name) { - Rule.Builder builder = Rule.newBuilder(); - builder.setKey(key); - builder.setRepository(repoKey); - if (internalKey != null) { - builder.setInternalKey(internalKey); - } - builder.setName(name); - - rulesLoader.addRule(builder.build()); - return this; - } + rulesLoader.addRule(builder.build()); + return this; + } - public BatchMediumTesterBuilder addRules(RulesDefinition rulesDefinition) { - RulesDefinition.Context context = new RulesDefinition.Context(); - rulesDefinition.define(context); - List repositories = context.repositories(); - for (Repository repo : repositories) { - for (RulesDefinition.Rule rule : repo.rules()) { - this.addRule(rule.key(), rule.repository().key(), rule.internalKey(), rule.name()); - } + public ScannerMediumTester addRules(RulesDefinition rulesDefinition) { + RulesDefinition.Context context = new RulesDefinition.Context(); + rulesDefinition.define(context); + List repositories = context.repositories(); + for (Repository repo : repositories) { + for (RulesDefinition.Rule rule : repo.rules()) { + this.addRule(rule.key(), rule.repository().key(), rule.internalKey(), rule.name()); } - return this; - } - - public BatchMediumTesterBuilder addDefaultQProfile(String language, String name) { - addQProfile(language, name); - return this; - } - - public BatchMediumTesterBuilder setPreviousAnalysisDate(Date previousAnalysis) { - projectRefProvider.setLastAnalysisDate(previousAnalysis); - return this; } + return this; + } - public BatchMediumTesterBuilder bootstrapProperties(Map props) { - bootstrapProperties.putAll(props); - return this; - } + public ScannerMediumTester addDefaultQProfile(String language, String name) { + addQProfile(language, name); + return this; + } - public BatchMediumTesterBuilder activateRule(LoadedActiveRule activeRule) { - activeRules.addActiveRule(activeRule); - return this; - } + public ScannerMediumTester setPreviousAnalysisDate(Date previousAnalysis) { + projectRefProvider.setLastAnalysisDate(previousAnalysis); + return this; + } - public BatchMediumTesterBuilder addActiveRule(String repositoryKey, String ruleKey, @Nullable String templateRuleKey, String name, @Nullable String severity, - @Nullable String internalKey, @Nullable String languag) { - LoadedActiveRule r = new LoadedActiveRule(); + public ScannerMediumTester bootstrapProperties(Map props) { + globalProperties.putAll(props); + return this; + } - r.setInternalKey(internalKey); - r.setRuleKey(RuleKey.of(repositoryKey, ruleKey)); - r.setName(name); - r.setTemplateRuleKey(templateRuleKey); - r.setLanguage(languag); - r.setSeverity(severity); + public ScannerMediumTester activateRule(LoadedActiveRule activeRule) { + activeRules.addActiveRule(activeRule); + return this; + } - activeRules.addActiveRule(r); - return this; - } + public ScannerMediumTester addActiveRule(String repositoryKey, String ruleKey, @Nullable String templateRuleKey, String name, @Nullable String severity, + @Nullable String internalKey, @Nullable String languag) { + LoadedActiveRule r = new LoadedActiveRule(); - public BatchMediumTesterBuilder addFileData(String moduleKey, String path, FileData fileData) { - projectRefProvider.addFileData(moduleKey, path, fileData); - return this; - } + r.setInternalKey(internalKey); + r.setRuleKey(RuleKey.of(repositoryKey, ruleKey)); + r.setName(name); + r.setTemplateRuleKey(templateRuleKey); + r.setLanguage(languag); + r.setSeverity(severity); - public BatchMediumTesterBuilder setLastBuildDate(Date d) { - projectRefProvider.setLastAnalysisDate(d); - return this; - } + activeRules.addActiveRule(r); + return this; + } - public BatchMediumTesterBuilder mockServerIssue(ServerIssue issue) { - serverIssues.getServerIssues().add(issue); - return this; - } + public ScannerMediumTester addFileData(String moduleKey, String path, FileData fileData) { + projectRefProvider.addFileData(moduleKey, path, fileData); + return this; + } - public BatchMediumTesterBuilder mockLineHashes(String fileKey, String[] lineHashes) { - serverLineHashes.byKey.put(fileKey, lineHashes); - return this; - } + public ScannerMediumTester setLastBuildDate(Date d) { + projectRefProvider.setLastAnalysisDate(d); + return this; + } + public ScannerMediumTester mockServerIssue(ServerIssue issue) { + serverIssues.getServerIssues().add(issue); + return this; } - public void start() { - batch.start(); + public ScannerMediumTester mockLineHashes(String fileKey, String[] lineHashes) { + serverLineHashes.byKey.put(fileKey, lineHashes); + return this; } - public void stop() { - batch.stop(); + @Override + protected void before() throws Throwable { try { - destroyWorkingDirs(); + createWorkingDirs(); } catch (IOException e) { - e.printStackTrace(); + throw new IllegalStateException(e); } + registerCoreMetrics(); + globalProperties.put(GlobalMode.MEDIUM_TEST_ENABLED, "true"); + globalProperties.put(ReportPublisher.KEEP_REPORT_PROP_KEY, "true"); + globalProperties.put("sonar.userHome", userHome.toString()); } - public void syncProject(String projectKey) { - batch.syncProject(projectKey); - } - - private ScannerMediumTester(BatchMediumTesterBuilder builder) { - Batch.Builder batchBuilder = Batch.builder() - .setEnableLoggingConfiguration(true) - .addComponents( - new EnvironmentInformation("mediumTest", "1.0"), - builder.pluginInstaller, - builder.globalRefProvider, - builder.qualityProfiles, - builder.rulesLoader, - builder.projectRefProvider, - builder.activeRules, - new DefaultDebtModel(), - new FakeSettingsLoader()) - .setBootstrapProperties(builder.bootstrapProperties) - .setLogOutput(builder.logOutput); - - if (builder.associated) { - batchBuilder.addComponents( - builder.serverIssues); + @Override + protected void after() { + try { + destroyWorkingDirs(); + } catch (IOException e) { + throw new IllegalStateException(e); } - batch = batchBuilder.build(); } public TaskBuilder newTask() { @@ -318,21 +261,34 @@ public class ScannerMediumTester { public static class TaskBuilder { private final Map taskProperties = new HashMap<>(); private ScannerMediumTester tester; - private IssueListener issueListener = null; public TaskBuilder(ScannerMediumTester tester) { this.tester = tester; } - public TaskResult start() { + public TaskResult execute() { TaskResult result = new TaskResult(); Map props = new HashMap<>(); + props.putAll(tester.globalProperties); props.putAll(taskProperties); - if (issueListener != null) { - tester.batch.executeTask(props, result, issueListener); - } else { - tester.batch.executeTask(props, result); - } + + Batch.builder() + .setGlobalProperties(props) + .setEnableLoggingConfiguration(true) + .addComponents(new EnvironmentInformation("mediumTest", "1.0"), + tester.pluginInstaller, + tester.globalRefProvider, + tester.qualityProfiles, + tester.rulesLoader, + tester.projectRefProvider, + tester.activeRules, + tester.serverIssues, + new DefaultDebtModel(), + new FakeSettingsLoader(), + result) + .setLogOutput(tester.logOutput) + .build().execute(); + return result; } @@ -346,10 +302,6 @@ public class ScannerMediumTester { return this; } - public TaskBuilder setIssueListener(IssueListener issueListener) { - this.issueListener = issueListener; - return this; - } } private static class FakeRulesLoader implements RulesLoader { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/branch/BranchMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/branch/BranchMediumTest.java index 8cddb21d14f..5c0c0351fc2 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/branch/BranchMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/branch/BranchMediumTest.java @@ -26,7 +26,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Map; import org.apache.commons.io.FileUtils; -import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -48,13 +47,13 @@ public class BranchMediumTest { @Rule public ExpectedException thrown = ExpectedException.none(); - public ScannerMediumTester tester = ScannerMediumTester.builder() + @Rule + public ScannerMediumTester tester = new ScannerMediumTester() .registerPlugin("xoo", new XooPlugin()) .addRules(new XooRulesDefinition()) // active a rule just to be sure that xoo files are published .addActiveRule("xoo", "xoo:OneIssuePerFile", null, "One Issue Per File", null, null, null) - .addDefaultQProfile("xoo", "Sonar Way") - .build(); + .addDefaultQProfile("xoo", "Sonar Way"); private File baseDir; @@ -62,8 +61,6 @@ public class BranchMediumTest { @Before public void prepare() throws IOException { - tester.start(); - baseDir = temp.getRoot(); commonProps = ImmutableMap.builder() @@ -77,11 +74,6 @@ public class BranchMediumTest { .build(); } - @After - public void stop() { - tester.stop(); - } - @Test public void scanProjectWithBranch() throws IOException { File srcDir = new File(baseDir, "src"); @@ -95,7 +87,7 @@ public class BranchMediumTest { .putAll(commonProps) .put("sonar.branch", "branch") .build()) - .start(); + .execute(); assertThat(result.inputFiles()).hasSize(1); assertThat(result.inputFile("src/sample.xoo").key()).isEqualTo("com.foo.project:src/sample.xoo"); @@ -110,7 +102,7 @@ public class BranchMediumTest { .putAll(commonProps) .put("sonar.branch", "") .build()) - .start(); + .execute(); assertThat(result.inputFiles()).hasSize(1); assertThat(result.inputFile("src/sample.xoo").key()).isEqualTo("com.foo.project:src/sample.xoo"); @@ -130,7 +122,7 @@ public class BranchMediumTest { .put("sonar.branch", "branch") .put("sonar.modules", "moduleA") .build()) - .start(); + .execute(); assertThat(result.inputFiles()).hasSize(1); assertThat(result.inputFile("src/sample.xoo").key()).isEqualTo("com.foo.project:moduleA:src/sample.xoo"); @@ -150,7 +142,7 @@ public class BranchMediumTest { .put("sonar.branch", "") .put("sonar.modules", "moduleA") .build()) - .start(); + .execute(); assertThat(result.inputFiles()).hasSize(1); assertThat(result.inputFile("src/sample.xoo").key()).isEqualTo("com.foo.project:moduleA:src/sample.xoo"); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/coverage/CoverageMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/coverage/CoverageMediumTest.java index f31b3205390..e840ef3cda4 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/coverage/CoverageMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/coverage/CoverageMediumTest.java @@ -25,8 +25,7 @@ import java.io.IOException; import java.util.List; import java.util.Map; import org.apache.commons.io.FileUtils; -import org.junit.After; -import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.api.batch.fs.InputFile; @@ -43,20 +42,10 @@ public class CoverageMediumTest { @org.junit.Rule public TemporaryFolder temp = new TemporaryFolder(); - public ScannerMediumTester tester = ScannerMediumTester.builder() + @Rule + public ScannerMediumTester tester = new ScannerMediumTester() .registerPlugin("xoo", new XooPlugin()) - .addDefaultQProfile("xoo", "Sonar Way") - .build(); - - @Before - public void prepare() { - tester.start(); - } - - @After - public void stop() { - tester.stop(); - } + .addDefaultQProfile("xoo", "Sonar Way"); @Test public void singleReport() throws IOException { @@ -80,7 +69,7 @@ public class CoverageMediumTest { .put("sonar.projectDescription", "Description of Foo Project") .put("sonar.sources", "src") .build()) - .start(); + .execute(); InputFile file = result.inputFile("src/sample.xoo"); assertThat(result.coverageFor(file, 2).getHits()).isTrue(); @@ -119,7 +108,7 @@ public class CoverageMediumTest { .put("sonar.projectDescription", "Description of Foo Project") .put("sonar.sources", "src") .build()) - .start(); + .execute(); InputFile file = result.inputFile("src/sample.xoo"); assertThat(result.coverageFor(file, 2).getHits()).isTrue(); @@ -161,7 +150,7 @@ public class CoverageMediumTest { .put("sonar.sources", "src") .put("sonar.coverage.exclusions", "**/sample.xoo") .build()) - .start(); + .execute(); InputFile file = result.inputFile("src/sample.xoo"); assertThat(result.coverageFor(file, 2)).isNull(); @@ -194,7 +183,7 @@ public class CoverageMediumTest { .put("sonar.projectDescription", "Description of Foo Project") .put("sonar.sources", "src") .build()) - .start(); + .execute(); InputFile file = result.inputFile("src/sample.xoo"); assertThat(result.coverageFor(file, 1)).isNull(); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/coverage/GenericCoverageMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/coverage/GenericCoverageMediumTest.java index 1b82927bcd0..1ea18e7f70f 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/coverage/GenericCoverageMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/coverage/GenericCoverageMediumTest.java @@ -21,8 +21,7 @@ package org.sonar.scanner.mediumtest.coverage; import java.io.File; import java.io.IOException; -import org.junit.After; -import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.measures.CoreMetrics; @@ -35,20 +34,10 @@ import static org.assertj.core.api.Assertions.tuple; public class GenericCoverageMediumTest { - public ScannerMediumTester tester = ScannerMediumTester.builder() + @Rule + public ScannerMediumTester tester = new ScannerMediumTester() .registerPlugin("xoo", new XooPlugin()) - .addDefaultQProfile("xoo", "Sonar Way") - .build(); - - @Before - public void prepare() { - tester.start(); - } - - @After - public void stop() { - tester.stop(); - } + .addDefaultQProfile("xoo", "Sonar Way"); @Test public void singleReport() throws IOException { @@ -58,7 +47,7 @@ public class GenericCoverageMediumTest { TaskResult result = tester .newScanTask(new File(projectDir, "sonar-project.properties")) .property("sonar.coverageReportPaths", "coverage.xml") - .start(); + .execute(); InputFile noConditions = result.inputFile("xources/hello/NoConditions.xoo"); assertThat(result.coverageFor(noConditions, 6).getHits()).isTrue(); @@ -99,7 +88,7 @@ public class GenericCoverageMediumTest { TaskResult result = tester .newScanTask(new File(projectDir, "sonar-project.properties")) .property("sonar.coverageReportPaths", "coverage.xml,coverage2.xml") - .start(); + .execute(); InputFile noConditions = result.inputFile("xources/hello/NoConditions.xoo"); assertThat(result.coverageFor(noConditions, 6).getHits()).isTrue(); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/cpd/CpdMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/cpd/CpdMediumTest.java index 31d259acd11..00c1ca1042a 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/cpd/CpdMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/cpd/CpdMediumTest.java @@ -26,7 +26,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; import org.apache.commons.io.FileUtils; -import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -65,14 +64,14 @@ public class CpdMediumTest { private LogOutputRecorder logRecorder = new LogOutputRecorder(); - public ScannerMediumTester tester = ScannerMediumTester.builder() + @Rule + public ScannerMediumTester tester = new ScannerMediumTester() .registerPlugin("xoo", new XooPlugin()) .addDefaultQProfile("xoo", "Sonar Way") .addRules(new XooRulesDefinition()) // active a rule just to be sure that xoo files are published .addActiveRule("xoo", "xoo:OneIssuePerFile", null, "One Issue Per File", null, null, null) - .setLogOutput(logRecorder) - .build(); + .setLogOutput(logRecorder); private File baseDir; @@ -89,7 +88,6 @@ public class CpdMediumTest { @Before public void prepare() throws IOException { logRecorder.getAll().clear(); - tester.start(); baseDir = temp.getRoot(); @@ -105,11 +103,6 @@ public class CpdMediumTest { } } - @After - public void stop() { - tester.stop(); - } - @Test public void testCrossModuleDuplications() throws IOException { builder.put("sonar.modules", "module1,module2") @@ -145,7 +138,7 @@ public class CpdMediumTest { File xooFile2 = new File(module2Dir, "sample2.xoo"); FileUtils.write(xooFile2, duplicatedStuff); - TaskResult result = tester.newTask().properties(builder.build()).start(); + TaskResult result = tester.newTask().properties(builder.build()).execute(); assertThat(result.inputFiles()).hasSize(2); @@ -197,7 +190,7 @@ public class CpdMediumTest { .put("sonar.cpd.xoo.minimumTokens", "10") .put("sonar.verbose", "true") .build()) - .start(); + .execute(); assertThat(result.inputFiles()).hasSize(2); @@ -251,7 +244,7 @@ public class CpdMediumTest { .put("sonar.cpd.xoo.minimumTokens", "10") .put("sonar.verbose", "true") .build()) - .start(); + .execute(); assertThat(result.inputFiles()).hasSize(2); @@ -283,7 +276,7 @@ public class CpdMediumTest { .put("sonar.cpd.xoo.minimumTokens", "10") .put("sonar.cpd.exclusions", "src/sample1.xoo") .build()) - .start(); + .execute(); assertThat(result.inputFiles()).hasSize(2); @@ -315,7 +308,7 @@ public class CpdMediumTest { .put("sonar.verbose", "true") .put("sonar.cpd.cross_project", "true") .build()) - .start(); + .execute(); InputFile inputFile1 = result.inputFile("src/sample1.xoo"); @@ -357,7 +350,7 @@ public class CpdMediumTest { .put("sonar.cpd.xoo.minimumLines", "2") .put("sonar.verbose", "true") .build()) - .start(); + .execute(); InputFile inputFile = result.inputFile("src/sample.xoo"); // One clone group diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/deprecated/DeprecatedApiMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/deprecated/DeprecatedApiMediumTest.java index 87642aac97f..3c0eed0694c 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/deprecated/DeprecatedApiMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/deprecated/DeprecatedApiMediumTest.java @@ -23,8 +23,7 @@ import com.google.common.collect.ImmutableMap; import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; -import org.junit.After; -import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.scanner.mediumtest.ScannerMediumTester; @@ -37,25 +36,15 @@ import static org.assertj.core.groups.Tuple.tuple; public class DeprecatedApiMediumTest { - @org.junit.Rule + @Rule public TemporaryFolder temp = new TemporaryFolder(); - public ScannerMediumTester tester = ScannerMediumTester.builder() + @Rule + public ScannerMediumTester tester = new ScannerMediumTester() .registerPlugin("xoo", new XooPlugin()) .addRules(new XooRulesDefinition()) .addDefaultQProfile("xoo", "Sonar Way") - .addActiveRule("xoo", "DeprecatedResourceApi", null, "One issue per line", "MAJOR", null, "xoo") - .build(); - - @Before - public void prepare() { - tester.start(); - } - - @After - public void stop() { - tester.stop(); - } + .addActiveRule("xoo", "DeprecatedResourceApi", null, "One issue per line", "MAJOR", null, "xoo"); @Test public void testIssueDetails() throws IOException { @@ -80,7 +69,7 @@ public class DeprecatedApiMediumTest { .put("sonar.projectDescription", "Description of Foo Project") .put("sonar.sources", "src") .build()) - .start(); + .execute(); assertThat(result.issuesFor(result.inputFile("src/sample.xoo"))).extracting("msg", "textRange.startLine").containsOnly( tuple("Issue created using deprecated API", 0), @@ -116,7 +105,7 @@ public class DeprecatedApiMediumTest { .put("sonar.projectDescription", "Description of Foo Project") .put("sonar.sources", ".") .build()) - .start(); + .execute(); assertThat(result.issuesFor(result.inputFile("sample.xoo"))).extracting("msg", "textRange.startLine").containsOnly( tuple("Issue created using deprecated API", 0), 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 55a3234a522..765f8729610 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 @@ -29,7 +29,6 @@ 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; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -57,20 +56,18 @@ public class FileSystemMediumTest { public ExpectedException thrown = ExpectedException.none(); private LogOutputRecorder logs = new LogOutputRecorder(); - private ScannerMediumTester tester; + + @Rule + public ScannerMediumTester tester = new ScannerMediumTester() + .registerPlugin("xoo", new XooPlugin()) + .addDefaultQProfile("xoo", "Sonar Way") + .setLogOutput(logs); private File baseDir; private ImmutableMap.Builder builder; @Before public void prepare() throws IOException { - tester = ScannerMediumTester.builder() - .registerPlugin("xoo", new XooPlugin()) - .addDefaultQProfile("xoo", "Sonar Way") - .setLogOutput(logs) - .build(); - tester.start(); - baseDir = temp.getRoot(); builder = ImmutableMap.builder() @@ -82,15 +79,6 @@ public class FileSystemMediumTest { .put("sonar.projectDescription", "Description of Foo Project"); } - @After - public void stop() { - if (tester != null) { - tester.stop(); - tester = null; - } - logs = new LogOutputRecorder(); - } - private ImmutableMap.Builder createBuilder() { return ImmutableMap.builder() .put("sonar.task", "scan") @@ -115,7 +103,7 @@ public class FileSystemMediumTest { .properties(builder .put("sonar.sources", "src") .build()) - .start(); + .execute(); int ref = result.getReportReader().readMetadata().getRootComponentRef(); assertThat(result.getReportReader().readComponent(ref).getName()).isEmpty(); @@ -150,7 +138,7 @@ public class FileSystemMediumTest { .properties(builder .put("sonar.sources", "src") .build()) - .start(); + .execute(); assertThat(logs.getAllAsString()).contains("Project key: com.foo.project"); assertThat(logs.getAllAsString()).contains("Organization key: my org"); @@ -171,7 +159,7 @@ public class FileSystemMediumTest { .properties(builder .put("sonar.sources", "src") .build()) - .start(); + .execute(); assertThat(logs.getAllAsString()).contains("Project key: com.foo.project"); assertThat(logs.getAllAsString()).contains("Branch key: my-branch"); @@ -190,7 +178,7 @@ public class FileSystemMediumTest { .properties(builder .put("sonar.sources", "src") .build()) - .start(); + .execute(); assertThat(logs.getAllAsString()).contains("Project key: com.foo.project"); assertThat(logs.getAllAsString()).doesNotContain("Organization key"); @@ -214,7 +202,7 @@ public class FileSystemMediumTest { .properties(builder .put("sonar.sources", "src") .build()) - .start(); + .execute(); assertThat(logs.getAllAsString()).contains("2 files indexed"); assertThat(logs.getAllAsString()).contains("'src/sample.xoo' generated metadata"); @@ -240,7 +228,7 @@ public class FileSystemMediumTest { .properties(builder .put("sonar.sources", "src") .build()) - .start(); + .execute(); assertThat(logs.getAllAsString()).contains("2 files indexed"); assertThat(logs.getAllAsString()).contains("'src/sample.xoo' generated metadata"); @@ -271,7 +259,7 @@ public class FileSystemMediumTest { .put("sonar.sources", "src/main") .put("sonar.tests", "src/test") .build()) - .start(); + .execute(); assertThat(logs.getAllAsString()).contains("3 files indexed"); assertThat(logs.getAllAsString()).contains("'src/main/sample.xoo' generated metadata"); @@ -283,16 +271,9 @@ public class FileSystemMediumTest { @Test public void createIssueOnAnyFile() throws IOException { - LogOutputRecorder logs = new LogOutputRecorder(); - stop(); - tester = ScannerMediumTester.builder() - .registerPlugin("xoo", new XooPlugin()) - .addDefaultQProfile("xoo", "Sonar Way") + tester .addRules(new XooRulesDefinition()) - .setLogOutput(logs) - .addActiveRule("xoo", "OneIssuePerUnknownFile", null, "OneIssuePerUnknownFile", "MAJOR", null, "xoo") - .build(); - tester.start(); + .addActiveRule("xoo", "OneIssuePerUnknownFile", null, "OneIssuePerUnknownFile", "MAJOR", null, "xoo"); builder = createBuilder(); @@ -306,7 +287,7 @@ public class FileSystemMediumTest { .properties(builder .put("sonar.sources", "src") .build()) - .start(); + .execute(); assertThat(logs.getAllAsString()).contains("1 file indexed"); assertThat(logs.getAllAsString()).contains("'src/sample.unknown' indexed with language 'null'"); @@ -317,16 +298,9 @@ public class FileSystemMediumTest { @Test public void lazyIssueExclusion() throws IOException { - tester.stop(); - LogOutputRecorder logs = new LogOutputRecorder(); - tester = ScannerMediumTester.builder() - .registerPlugin("xoo", new XooPlugin()) - .addDefaultQProfile("xoo", "Sonar Way") + tester .addRules(new XooRulesDefinition()) - .setLogOutput(logs) - .addActiveRule("xoo", "OneIssuePerFile", null, "OneIssuePerFile", "MAJOR", null, "xoo") - .build(); - tester.start(); + .addActiveRule("xoo", "OneIssuePerFile", null, "OneIssuePerFile", "MAJOR", null, "xoo"); builder = createBuilder(); builder.put("sonar.issue.ignore.allfile", "1") @@ -346,7 +320,7 @@ public class FileSystemMediumTest { .properties(builder .put("sonar.sources", "src") .build()) - .start(); + .execute(); assertThat(logs.getAllAsString()).containsOnlyOnce("'src/myfile.binary' indexed with language 'null'"); assertThat(logs.getAllAsString()).doesNotContain("'src/myfile.binary' generating issue exclusions"); @@ -372,7 +346,7 @@ public class FileSystemMediumTest { .properties(builder .put("sonar.sources", "src") .build()) - .start(); + .execute(); assertThat(logs.getAllAsString()).containsOnlyOnce("- Exclusion pattern 'pattern'"); assertThat(logs.getAllAsString()).containsOnlyOnce("'src/myfile.binary' generating issue exclusions"); @@ -380,14 +354,9 @@ public class FileSystemMediumTest { @Test public void publishFilesWithIssues() throws IOException { - stop(); - tester = ScannerMediumTester.builder() - .registerPlugin("xoo", new XooPlugin()) - .addDefaultQProfile("xoo", "Sonar Way") + tester .addRules(new XooRulesDefinition()) - .addActiveRule("xoo", "OneIssueOnDirPerFile", null, "OneIssueOnDirPerFile", "MAJOR", null, "xoo") - .build(); - tester.start(); + .addActiveRule("xoo", "OneIssueOnDirPerFile", null, "OneIssueOnDirPerFile", "MAJOR", null, "xoo"); builder = createBuilder(); @@ -401,7 +370,7 @@ public class FileSystemMediumTest { .properties(builder .put("sonar.sources", "src") .build()) - .start(); + .execute(); DefaultInputFile file = (DefaultInputFile) result.inputFile("src/sample.xoo"); InputDir dir = result.inputDir("src"); @@ -413,14 +382,9 @@ public class FileSystemMediumTest { @Test public void publishDirsWithIssues() throws IOException { - stop(); - tester = ScannerMediumTester.builder() - .registerPlugin("xoo", new XooPlugin()) - .addDefaultQProfile("xoo", "Sonar Way") + tester .addRules(new XooRulesDefinition()) - .addActiveRule("xoo", "OneIssuePerDirectory", null, "OneIssuePerDirectory", "MAJOR", null, "xoo") - .build(); - tester.start(); + .addActiveRule("xoo", "OneIssuePerDirectory", null, "OneIssuePerDirectory", "MAJOR", null, "xoo"); builder = ImmutableMap.builder() .put("sonar.task", "scan") @@ -442,7 +406,7 @@ public class FileSystemMediumTest { .properties(builder .put("sonar.sources", "src") .build()) - .start(); + .execute(); DefaultInputFile unknownInputFile = (DefaultInputFile) result.inputFile("src/unknown/file.notanalyzed"); InputDir unknownInputDir = result.inputDir("src/unknown"); @@ -470,7 +434,7 @@ public class FileSystemMediumTest { .properties(builder .put("sonar.sources", "src") .build()) - .start(); + .execute(); assertThat(result.inputFiles()).hasSize(1); assertThat(result.inputDirs()).hasSize(1); @@ -495,7 +459,7 @@ public class FileSystemMediumTest { .properties(builder .put("sonar.sources", "src") .build()) - .start(); + .execute(); assertThat(result.inputFiles()).hasSize(100); assertThat(result.inputDirs()).hasSize(1); @@ -514,7 +478,7 @@ public class FileSystemMediumTest { .put("sonar.sources", "") .put("sonar.tests", "test") .build()) - .start(); + .execute(); assertThat(result.inputFiles()).hasSize(1); assertThat(result.inputFile("test/sampleTest.xoo").type()).isEqualTo(InputFile.Type.TEST); @@ -548,7 +512,7 @@ public class FileSystemMediumTest { .put("sonar.sources", "src,another.xoo") .put("sonar.tests", "test,sampleTest2.xoo") .build()) - .start(); + .execute(); assertThat(result.inputFiles()).hasSize(4); assertThat(result.inputDirs()).hasSize(3); @@ -583,7 +547,7 @@ public class FileSystemMediumTest { .put("sonar.test.inclusions", "**/sampleTest*.*") .put("sonar.test.exclusions", "**/sampleTest2.xoo") .build()) - .start(); + .execute(); assertThat(result.inputFiles()).hasSize(2); } @@ -602,7 +566,7 @@ public class FileSystemMediumTest { .properties(builder .put("sonar.sources", "src,src/sample.xoo") .build()) - .start(); + .execute(); } @@ -613,7 +577,7 @@ public class FileSystemMediumTest { File projectDir = new File("src/test/resources/mediumtest/xoo/sample-with-symlink"); TaskResult result = tester .newScanTask(new File(projectDir, "sonar-project.properties")) - .start(); + .execute(); assertThat(result.inputFiles()).hasSize(3); // check that symlink was not resolved to target @@ -630,7 +594,7 @@ public class FileSystemMediumTest { .newScanTask(new File(projectDir, "sonar-project.properties")) .property("sonar.sources", "XOURCES") .property("sonar.tests", "TESTX") - .start(); + .execute(); assertThat(result.inputFiles()).hasSize(3); assertThat(result.inputFiles()).extractingResultOf("relativePath").containsOnly( @@ -655,7 +619,7 @@ public class FileSystemMediumTest { .properties(builder .put("sonar.sources", "src") .build()) - .start(); + .execute(); assertThat(result.inputFiles()).hasSize(2); assertThat(result.inputFile("src/sample.other").type()).isEqualTo(InputFile.Type.MAIN); @@ -668,7 +632,7 @@ public class FileSystemMediumTest { File projectDir = new File("src/test/resources/mediumtest/xoo/multi-modules-sample"); TaskResult result = tester .newScanTask(new File(projectDir, "sonar-project.properties")) - .start(); + .execute(); System.out.println(logs.getAsString()); assertThat(result.inputFiles()).hasSize(4); @@ -700,7 +664,7 @@ public class FileSystemMediumTest { .put("sonar.sources", "src,\"another,2.xoo\"") .put("sonar.tests", "\"test\",\"sampleTest,2.xoo\"") .build()) - .start(); + .execute(); assertThat(result.inputFiles()).hasSize(4); assertThat(result.inputDirs()).hasSize(3); 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 721e4a7af6b..320e8036913 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 @@ -22,8 +22,6 @@ package org.sonar.scanner.mediumtest.fs; import java.io.File; 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; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -38,19 +36,9 @@ public class NoLanguagesPluginsMediumTest { @Rule public ExpectedException exception = ExpectedException.none(); - public ScannerMediumTester tester = ScannerMediumTester.builder() - .setPreviousAnalysisDate(null) - .build(); - - @Before - public void prepare() { - tester.start(); - } - - @After - public void stop() { - tester.stop(); - } + @Rule + public ScannerMediumTester tester = new ScannerMediumTester() + .setPreviousAnalysisDate(null); @Test public void testNoLanguagePluginsInstalled() throws Exception { @@ -61,7 +49,7 @@ public class NoLanguagesPluginsMediumTest { tester .newScanTask(new File(projectDir, "sonar-project.properties")) - .start(); + .execute(); } private File copyProject(String path) throws Exception { 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 ea16deec3cc..35eab16b110 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 @@ -27,8 +27,6 @@ import java.util.List; import org.apache.commons.io.FileUtils; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; -import org.junit.After; -import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -57,18 +55,13 @@ public class ProjectBuilderMediumTest { private ProjectBuilder projectBuilder = mock(ProjectBuilder.class); - public ScannerMediumTester tester = ScannerMediumTester.builder() + @Rule + public ScannerMediumTester tester = new ScannerMediumTester() .registerPlugin("xoo", new XooPluginWithBuilder(projectBuilder)) .addRules(new XooRulesDefinition()) .addDefaultQProfile("xoo", "Sonar Way") .setPreviousAnalysisDate(new Date()) - .addActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", "OneIssuePerLine.internal", "xoo") - .build(); - - @Before - public void prepare() { - tester.start(); - } + .addActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", "OneIssuePerLine.internal", "xoo"); private class XooPluginWithBuilder extends XooPlugin { private ProjectBuilder builder; @@ -84,11 +77,6 @@ public class ProjectBuilderMediumTest { } } - @After - public void stop() { - tester.stop(); - } - @Test public void testProjectReactorValidation() throws IOException { File baseDir = prepareProject(); @@ -123,7 +111,7 @@ public class ProjectBuilderMediumTest { .put("sonar.sources", ".") .put("sonar.xoo.enableProjectBuilder", "true") .build()) - .start(); + .execute(); } @@ -143,7 +131,7 @@ public class ProjectBuilderMediumTest { .put("sonar.verbose", "true") .put("sonar.xoo.enableProjectBuilder", "true") .build()) - .start(); + .execute(); List issues = result.issuesFor(result.inputFile("src/sample.xoo")); assertThat(issues).hasSize(10); @@ -172,7 +160,7 @@ public class ProjectBuilderMediumTest { .put("sonar.sources", ".") .put("sonar.xoo.enableProjectBuilder", "true") .build()) - .start(); + .execute(); } @Test @@ -191,7 +179,7 @@ public class ProjectBuilderMediumTest { .put("sonar.sources", ".") .put("sonar.xoo.enableProjectBuilder", "true") .build()) - .start(); + .execute(); List issues = result.issuesFor(result.inputFile("src/sample.xoo")); assertThat(issues).hasSize(10); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/highlighting/HighlightingMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/highlighting/HighlightingMediumTest.java index 83cb44284f3..1b642997376 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/highlighting/HighlightingMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/highlighting/HighlightingMediumTest.java @@ -25,8 +25,6 @@ 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; @@ -47,20 +45,10 @@ public class HighlightingMediumTest { @Rule public ExpectedException exception = ExpectedException.none(); - public ScannerMediumTester tester = ScannerMediumTester.builder() + @Rule + public ScannerMediumTester tester = new ScannerMediumTester() .registerPlugin("xoo", new XooPlugin()) - .addDefaultQProfile("xoo", "Sonar Way") - .build(); - - @Before - public void prepare() { - tester.start(); - } - - @After - public void stop() { - tester.stop(); - } + .addDefaultQProfile("xoo", "Sonar Way"); @Test public void computeSyntaxHighlightingOnTempProject() throws IOException { @@ -83,7 +71,7 @@ public class HighlightingMediumTest { .put("sonar.projectDescription", "Description of Foo Project") .put("sonar.sources", "src") .build()) - .start(); + .execute(); InputFile file = result.inputFile("src/sample.xoo"); assertThat(result.highlightingTypeFor(file, 1, 0)).containsExactly(TypeOfText.STRING); @@ -113,7 +101,7 @@ public class HighlightingMediumTest { .put("sonar.sources", "src") .put("sonar.it.savedatatwice", "true") .build()) - .start(); + .execute(); } @@ -152,7 +140,7 @@ public class HighlightingMediumTest { .put("sonar.projectDescription", "Description of Foo Project") .put("sonar.sources", "src") .build()) - .start(); + .execute(); } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/ChecksMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/ChecksMediumTest.java index 2f88872bf3b..9b539a27687 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/ChecksMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/ChecksMediumTest.java @@ -27,8 +27,7 @@ import java.util.List; import java.util.Map; import javax.annotation.Nullable; import org.apache.commons.io.FileUtils; -import org.junit.After; -import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.api.rule.RuleKey; @@ -47,25 +46,15 @@ public class ChecksMediumTest { @org.junit.Rule public TemporaryFolder temp = new TemporaryFolder(); - public ScannerMediumTester tester = ScannerMediumTester.builder() + @Rule + public ScannerMediumTester tester = new ScannerMediumTester() .registerPlugin("xoo", new XooPlugin()) .addRules(new XooRulesDefinition()) .addDefaultQProfile("xoo", "Sonar Way") .addRule("TemplateRule_1234", "xoo", "TemplateRule_1234", "A template rule") .addRule("TemplateRule_1235", "xoo", "TemplateRule_1235", "Another template rule") .activateRule(createActiveRuleWithParam("xoo", "TemplateRule_1234", "TemplateRule", "A template rule", "MAJOR", null, "xoo", "line", "1")) - .activateRule(createActiveRuleWithParam("xoo", "TemplateRule_1235", "TemplateRule", "Another template rule", "MAJOR", null, "xoo", "line", "2")) - .build(); - - @Before - public void prepare() { - tester.start(); - } - - @After - public void stop() { - tester.stop(); - } + .activateRule(createActiveRuleWithParam("xoo", "TemplateRule_1235", "TemplateRule", "Another template rule", "MAJOR", null, "xoo", "line", "2")); @Test public void testCheckWithTemplate() throws IOException { @@ -87,7 +76,7 @@ public class ChecksMediumTest { .put("sonar.projectDescription", "Description of Foo Project") .put("sonar.sources", "src") .build()) - .start(); + .execute(); List issues = result.issuesFor(result.inputFile("src/sample.xoo")); assertThat(issues) 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 deleted file mode 100644 index 7eb43a3b100..00000000000 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesIssuesModeMediumTest.java +++ /dev/null @@ -1,99 +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.mediumtest.issues; - -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 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 static org.assertj.core.api.Assertions.assertThat; - -public class IssuesIssuesModeMediumTest { - @org.junit.Rule - public TemporaryFolder temp = new TemporaryFolder(); - - public ScannerMediumTester testerPreview = ScannerMediumTester.builder() - .registerPlugin("xoo", new XooPlugin()) - .addDefaultQProfile("xoo", "Sonar Way") - .addRules(new XooRulesDefinition()) - .bootstrapProperties(ImmutableMap.of(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES)) - .addActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", "OneIssuePerLine.internal", "xoo") - .setLastBuildDate(new Date()) - .build(); - - @Before - public void prepare() { - testerPreview.start(); - } - - @After - public void stop() { - testerPreview.stop(); - } - - @Test - public void testIssueCallback() throws Exception { - File projectDir = new File(IssuesMediumTest.class.getResource("/mediumtest/xoo/sample").toURI()); - File tmpDir = temp.getRoot(); - FileUtils.copyDirectory(projectDir, tmpDir); - IssueRecorder issueListener = new IssueRecorder(); - - TaskResult result1 = testerPreview - .newScanTask(new File(tmpDir, "sonar-project.properties")) - .setIssueListener(issueListener) - .property(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES) - .start(); - - assertThat(result1.trackedIssues()).hasSize(14); - assertThat(issueListener.issueList).hasSize(14); - issueListener = new IssueRecorder(); - - TaskResult result2 = testerPreview - .newScanTask(new File(tmpDir, "sonar-project.properties")) - .setIssueListener(issueListener) - .property(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES) - .start(); - - assertThat(result2.trackedIssues()).hasSize(14); - assertThat(issueListener.issueList).hasSize(14); - } - - private class IssueRecorder implements IssueListener { - List issueList = new LinkedList<>(); - - @Override - public void handle(Issue issue) { - issueList.add(issue); - } - } -} diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesMediumTest.java index 1b700a513e4..2330712466e 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesMediumTest.java @@ -22,14 +22,11 @@ package org.sonar.scanner.mediumtest.issues; import com.google.common.collect.ImmutableMap; import java.io.File; import java.io.IOException; -import java.util.LinkedList; import java.util.List; import org.apache.commons.io.FileUtils; -import org.junit.After; -import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import org.sonar.batch.bootstrapper.IssueListener; import org.sonar.scanner.mediumtest.ScannerMediumTester; import org.sonar.scanner.mediumtest.TaskResult; import org.sonar.scanner.protocol.output.ScannerReport.Issue; @@ -44,38 +41,12 @@ public class IssuesMediumTest { @org.junit.Rule public TemporaryFolder temp = new TemporaryFolder(); - public ScannerMediumTester tester = ScannerMediumTester.builder() + @Rule + public ScannerMediumTester tester = new ScannerMediumTester() .registerPlugin("xoo", new XooPlugin()) .addDefaultQProfile("xoo", "Sonar Way") .addRules(new XooRulesDefinition()) - .addActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", "OneIssuePerLine.internal", "xoo") - .build(); - - @Before - public void prepare() { - tester.start(); - } - - @After - public void stop() { - tester.stop(); - } - - @Test - public void testNoIssueCallbackInNonPreview() throws Exception { - File projectDir = new File(IssuesMediumTest.class.getResource("/mediumtest/xoo/sample").toURI()); - File tmpDir = temp.getRoot(); - FileUtils.copyDirectory(projectDir, tmpDir); - IssueRecorder issueListener = new IssueRecorder(); - - TaskResult result = tester - .newScanTask(new File(tmpDir, "sonar-project.properties")) - .setIssueListener(issueListener) - .start(); - - assertThat(result.issuesFor(result.inputFile("xources/hello/HelloJava.xoo"))).hasSize(8); - assertThat(issueListener.issueList).hasSize(0); - } + .addActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", "OneIssuePerLine.internal", "xoo"); @Test public void testOneIssuePerLine() throws Exception { @@ -85,7 +56,7 @@ public class IssuesMediumTest { TaskResult result = tester .newScanTask(new File(tmpDir, "sonar-project.properties")) - .start(); + .execute(); List issues = result.issuesFor(result.inputFile("xources/hello/HelloJava.xoo")); assertThat(issues).hasSize(8 /* lines */); @@ -103,7 +74,7 @@ public class IssuesMediumTest { TaskResult result = tester .newScanTask(new File(tmpDir, "sonar-project.properties")) .property("sonar.xoo.internalKey", "OneIssuePerLine.internal") - .start(); + .execute(); List issues = result.issuesFor(result.inputFile("xources/hello/HelloJava.xoo")); assertThat(issues).hasSize(8 /* lines */ + 1 /* file */); @@ -118,7 +89,7 @@ public class IssuesMediumTest { TaskResult result = tester .newScanTask(new File(tmpDir, "sonar-project.properties")) .property("sonar.oneIssuePerLine.forceSeverity", "CRITICAL") - .start(); + .execute(); List issues = result.issuesFor(result.inputFile("xources/hello/HelloJava.xoo")); assertThat(issues.get(0).getSeverity()).isEqualTo(org.sonar.scanner.protocol.Constants.Severity.CRITICAL); @@ -134,7 +105,7 @@ public class IssuesMediumTest { .newScanTask(new File(tmpDir, "sonar-project.properties")) .property("sonar.issue.ignore.allfile", "1") .property("sonar.issue.ignore.allfile.1.fileRegexp", "object") - .start(); + .execute(); assertThat(result.issuesFor(result.inputFile("xources/hello/HelloJava.xoo"))).hasSize(8 /* lines */); assertThat(result.issuesFor(result.inputFile("xources/hello/helloscala.xoo"))).isEmpty(); @@ -160,7 +131,7 @@ public class IssuesMediumTest { .put("sonar.projectDescription", "Description of Foo Project") .put("sonar.sources", "src") .build()) - .start(); + .execute(); List issues = result.issuesFor(result.inputFile("src/sample.xoo")); assertThat(issues).hasSize(10); @@ -169,12 +140,4 @@ public class IssuesMediumTest { .contains(tuple("This issue is generated on each line", 1, 0.0)); } - private class IssueRecorder implements IssueListener { - List issueList = new LinkedList<>(); - - @Override - public void handle(Issue issue) { - issueList.add(issue); - } - } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesOnDirMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesOnDirMediumTest.java index e5526aec184..6df04f0bada 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesOnDirMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesOnDirMediumTest.java @@ -23,8 +23,7 @@ import com.google.common.collect.ImmutableMap; import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; -import org.junit.After; -import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.scanner.mediumtest.ScannerMediumTester; @@ -36,25 +35,15 @@ import static org.assertj.core.api.Assertions.assertThat; public class IssuesOnDirMediumTest { - @org.junit.Rule + @Rule public TemporaryFolder temp = new TemporaryFolder(); - public ScannerMediumTester tester = ScannerMediumTester.builder() + @Rule + public ScannerMediumTester tester = new ScannerMediumTester() .registerPlugin("xoo", new XooPlugin()) .addDefaultQProfile("xoo", "Sonar Way") .addRules(new XooRulesDefinition()) - .addActiveRule("xoo", "OneIssueOnDirPerFile", null, "One issue per line", "MINOR", "xoo", "xoo") - .build(); - - @Before - public void prepare() { - tester.start(); - } - - @After - public void stop() { - tester.stop(); - } + .addActiveRule("xoo", "OneIssueOnDirPerFile", null, "One issue per line", "MINOR", "xoo", "xoo"); @Test public void scanTempProject() throws IOException { @@ -79,7 +68,7 @@ public class IssuesOnDirMediumTest { .put("sonar.projectDescription", "Description of Foo Project") .put("sonar.sources", "src") .build()) - .start(); + .execute(); assertThat(result.issuesFor(result.inputDir("src"))).hasSize(2); } @@ -105,7 +94,7 @@ public class IssuesOnDirMediumTest { .put("sonar.projectDescription", "Description of Foo Project") .put("sonar.sources", ".") .build()) - .start(); + .execute(); assertThat(result.issuesFor(result.inputDir(""))).hasSize(2); } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesOnModuleMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesOnModuleMediumTest.java index eeb92c59d4a..748d2537df1 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesOnModuleMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesOnModuleMediumTest.java @@ -23,8 +23,7 @@ import com.google.common.collect.ImmutableMap; import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; -import org.junit.After; -import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.scanner.mediumtest.ScannerMediumTester; @@ -36,25 +35,15 @@ import static org.assertj.core.api.Assertions.assertThat; public class IssuesOnModuleMediumTest { - @org.junit.Rule + @Rule public TemporaryFolder temp = new TemporaryFolder(); - public ScannerMediumTester tester = ScannerMediumTester.builder() + @Rule + public ScannerMediumTester tester = new ScannerMediumTester() .registerPlugin("xoo", new XooPlugin()) .addDefaultQProfile("xoo", "Sonar Way") .addRules(new XooRulesDefinition()) - .addActiveRule("xoo", "OneIssuePerModule", null, "One issue per module", "MINOR", "xoo", "xoo") - .build(); - - @Before - public void prepare() { - tester.start(); - } - - @After - public void stop() { - tester.stop(); - } + .addActiveRule("xoo", "OneIssuePerModule", null, "One issue per module", "MINOR", "xoo", "xoo"); @Test public void scanTempProject() throws IOException { @@ -76,7 +65,7 @@ public class IssuesOnModuleMediumTest { .put("sonar.projectDescription", "Description of Foo Project") .put("sonar.sources", "src") .build()) - .start(); + .execute(); assertThat(result.issuesFor(result.getReportComponent("com.foo.project"))).hasSize(1); } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/MultilineIssuesMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/MultilineIssuesMediumTest.java index 644599bc0dd..e5a4124b9dc 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/MultilineIssuesMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/MultilineIssuesMediumTest.java @@ -22,8 +22,8 @@ package org.sonar.scanner.mediumtest.issues; import java.io.File; import java.util.List; import org.apache.commons.io.FileUtils; -import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.scanner.mediumtest.ScannerMediumTester; @@ -38,34 +38,27 @@ import static org.assertj.core.api.Assertions.assertThat; public class MultilineIssuesMediumTest { - @org.junit.Rule + @Rule public TemporaryFolder temp = new TemporaryFolder(); - public ScannerMediumTester tester = ScannerMediumTester.builder() + @Rule + public ScannerMediumTester tester = new ScannerMediumTester() .registerPlugin("xoo", new XooPlugin()) .addRules(new XooRulesDefinition()) .addDefaultQProfile("xoo", "Sonar Way") - .addActiveRule("xoo", "MultilineIssue", null, "Multinile Issue", "MAJOR", null, "xoo") - .build(); + .addActiveRule("xoo", "MultilineIssue", null, "Multinile Issue", "MAJOR", null, "xoo"); private TaskResult result; @Before public void prepare() throws Exception { - tester.start(); - File projectDir = new File(MultilineIssuesMediumTest.class.getResource("/mediumtest/xoo/sample-multiline").toURI()); File tmpDir = temp.getRoot(); FileUtils.copyDirectory(projectDir, tmpDir); result = tester .newScanTask(new File(tmpDir, "sonar-project.properties")) - .start(); - } - - @After - public void stop() { - tester.stop(); + .execute(); } @Test 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 84434b7f8cb..36120bd1d52 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 @@ -24,8 +24,6 @@ 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; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -47,24 +45,14 @@ public class EmptyFileTest { @Rule public LogTester logTester = new LogTester(); - public ScannerMediumTester tester = ScannerMediumTester.builder() + @Rule + public ScannerMediumTester tester = new ScannerMediumTester() .bootstrapProperties(ImmutableMap.of(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES)) .registerPlugin("xoo", new XooPlugin()) .addRules(new XooRulesDefinition()) .addDefaultQProfile("xoo", "Sonar Way") .addActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", "my/internal/key", "xoo") - .setPreviousAnalysisDate(new Date()) - .build(); - - @Before - public void prepare() { - tester.start(); - } - - @After - public void stop() { - tester.stop(); - } + .setPreviousAnalysisDate(new Date()); @Test public void testIssueTrackingWithIssueOnEmptyFile() throws Exception { @@ -73,12 +61,12 @@ public class EmptyFileTest { TaskResult result = tester .newScanTask(new File(projectDir, "sonar-project.properties")) .property("sonar.xoo.internalKey", "my/internal/key") - .start(); + .execute(); - for(TrackedIssue i : result.trackedIssues()) { + for (TrackedIssue i : result.trackedIssues()) { System.out.println(i.startLine() + " " + i.getMessage()); } - + assertThat(result.trackedIssues()).hasSize(11); } 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 6eb4283c0cf..65e705a838c 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 @@ -25,21 +25,17 @@ import java.io.IOException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; -import java.util.LinkedList; -import java.util.List; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.io.FileUtils; import org.apache.commons.io.filefilter.FileFilterUtils; import org.apache.commons.lang.StringUtils; import org.assertj.core.api.Condition; -import org.junit.After; -import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; 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.issue.tracking.TrackedIssue; import org.sonar.scanner.mediumtest.ScannerMediumTester; import org.sonar.scanner.mediumtest.TaskResult; @@ -69,7 +65,8 @@ public class IssueModeAndReportsMediumTest { } } - public ScannerMediumTester tester = ScannerMediumTester.builder() + @Rule + public ScannerMediumTester tester = new ScannerMediumTester() .bootstrapProperties(ImmutableMap.of(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES)) .registerPlugin("xoo", new XooPlugin()) .addDefaultQProfile("xoo", "Sonar Way") @@ -110,18 +107,7 @@ public class IssueModeAndReportsMediumTest { .setSeverity(Severity.CRITICAL) .setCreationDate(date("14/03/2004")) .setStatus("OPEN") - .build()) - .build(); - - @Before - public void prepare() { - tester.start(); - } - - @After - public void stop() { - tester.stop(); - } + .build()); private File copyProject(String path) throws Exception { File projectDir = temp.newFolder(); @@ -136,7 +122,7 @@ public class IssueModeAndReportsMediumTest { TaskResult result = tester .newScanTask(new File(projectDir, "sonar-project.properties")) - .start(); + .execute(); int newIssues = 0; int openIssues = 0; @@ -157,10 +143,10 @@ public class IssueModeAndReportsMediumTest { assertThat(newIssues).isEqualTo(16); assertThat(openIssues).isEqualTo(2); assertThat(resolvedIssue).isEqualTo(1); - + // progress report String logs = StringUtils.join(logTester.logs(LoggerLevel.INFO), "\n"); - + assertThat(logs).contains("Performing issue tracking"); assertThat(logs).contains("6/6 components tracked"); @@ -183,7 +169,7 @@ public class IssueModeAndReportsMediumTest { tester .newScanTask(new File(projectDir, "sonar-project.properties")) .property("sonar.issuesReport.console.enable", "true") - .start(); + .execute(); assertThat(getReportLog()).contains("+16 issues", "+16 major"); } @@ -195,7 +181,7 @@ public class IssueModeAndReportsMediumTest { tester .newScanTask(new File(projectDir, "sonar-project.properties")) .property("sonar.xoo.enablePostJob", "true") - .start(); + .execute(); assertThat(logTester.logs()).contains("Resolved issues: 1", "Open issues: 18"); } @@ -216,7 +202,7 @@ public class IssueModeAndReportsMediumTest { tester .newScanTask(new File(projectDir, "sonar-project.properties")) .property("sonar.issuesReport.html.enable", "true") - .start(); + .execute(); assertThat(new File(projectDir, ".sonar/issues-report/issues-report.html")).exists(); assertThat(new File(projectDir, ".sonar/issues-report/issues-report-light.html")).exists(); @@ -239,36 +225,12 @@ public class IssueModeAndReportsMediumTest { .put("sonar.sources", "src") .put("sonar.issuesReport.html.enable", "true") .build()) - .start(); + .execute(); assertThat(FileUtils.readFileToString(new File(baseDir, ".sonar/issues-report/issues-report.html"))).contains("No file analyzed"); assertThat(FileUtils.readFileToString(new File(baseDir, ".sonar/issues-report/issues-report-light.html"))).contains("No file analyzed"); } - @Test - public void testIssueCallback() throws Exception { - File projectDir = copyProject("/mediumtest/xoo/sample"); - IssueRecorder issueListener = new IssueRecorder(); - - TaskResult result = tester - .newScanTask(new File(projectDir, "sonar-project.properties")) - .setIssueListener(issueListener) - .property("sonar.verbose", "true") - .start(); - - assertThat(result.trackedIssues()).hasSize(19); - assertThat(issueListener.issueList).hasSize(19); - } - - private class IssueRecorder implements IssueListener { - List issueList = new LinkedList<>(); - - @Override - public void handle(Issue issue) { - issueList.add(issue); - } - } - @Test public void noSyntaxHighlightingInIssuesMode() throws IOException { @@ -290,7 +252,7 @@ public class IssueModeAndReportsMediumTest { .put("sonar.projectDescription", "Description of Foo Project") .put("sonar.sources", "src") .build()) - .start(); + .execute(); assertThat(result.getReportReader().hasSyntaxHighlighting(1)).isFalse(); assertThat(result.getReportReader().hasSyntaxHighlighting(2)).isFalse(); 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 4a81c797e21..49e25833854 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 @@ -23,8 +23,6 @@ import com.google.common.collect.ImmutableMap; import java.io.File; 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; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -44,24 +42,14 @@ public class NoPreviousAnalysisTest { @Rule public LogTester logTester = new LogTester(); - public ScannerMediumTester tester = ScannerMediumTester.builder() + @Rule + public ScannerMediumTester tester = new ScannerMediumTester() .bootstrapProperties(ImmutableMap.of(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES)) .registerPlugin("xoo", new XooPlugin()) .addRules(new XooRulesDefinition()) .addDefaultQProfile("xoo", "Sonar Way") .addActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", "my/internal/key", "xoo") - .setPreviousAnalysisDate(null) - .build(); - - @Before - public void prepare() { - tester.start(); - } - - @After - public void stop() { - tester.stop(); - } + .setPreviousAnalysisDate(null); @Test public void testIssueTrackingWithIssueOnEmptyFile() throws Exception { @@ -69,12 +57,12 @@ public class NoPreviousAnalysisTest { TaskResult result = tester .newScanTask(new File(projectDir, "sonar-project.properties")) - .start(); - + .execute(); + assertThat(result.trackedIssues()).hasSize(14); - + } - + private File copyProject(String path) throws Exception { File projectDir = temp.newFolder(); File originalProjectDir = new File(IssueModeAndReportsMediumTest.class.getResource(path).toURI()); 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 c0043f1ef24..a4ae9502a24 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 @@ -37,7 +37,6 @@ import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.io.FileUtils; import org.apache.commons.io.filefilter.FileFilterUtils; import org.assertj.core.api.Condition; -import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -87,7 +86,15 @@ public class ScanOnlyChangedTest { @Rule public LogTester logTester = new LogTester(); - private ScannerMediumTester tester; + @Rule + public ScannerMediumTester tester = new ScannerMediumTester() + .bootstrapProperties(ImmutableMap.of(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES)) + .registerPlugin("xoo", new XooPlugin()) + .addDefaultQProfile("xoo", "Sonar Way") + .addRules(new XooRulesDefinition()) + .addActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", null, "xoo") + .addActiveRule("xoo", "OneIssueOnDirPerFile", null, "OneIssueOnDirPerFile", "MAJOR", null, "xoo") + .addActiveRule("xoo", "OneIssuePerModule", null, "OneIssuePerModule", "MAJOR", null, "xoo"); @Before public void prepare() throws IOException, URISyntaxException { @@ -97,14 +104,7 @@ public class ScanOnlyChangedTest { .readMetadata(Files.newInputStream(path), StandardCharsets.UTF_8, filePath) .hash(); - tester = ScannerMediumTester.builder() - .bootstrapProperties(ImmutableMap.of(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES)) - .registerPlugin("xoo", new XooPlugin()) - .addDefaultQProfile("xoo", "Sonar Way") - .addRules(new XooRulesDefinition()) - .addActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", null, "xoo") - .addActiveRule("xoo", "OneIssueOnDirPerFile", null, "OneIssueOnDirPerFile", "MAJOR", null, "xoo") - .addActiveRule("xoo", "OneIssuePerModule", null, "OneIssuePerModule", "MAJOR", null, "xoo") + tester // this will cause the file to have status==SAME .addFileData(projectKey, filePath, new FileData(md5sum, null)) .setPreviousAnalysisDate(new Date()) @@ -129,14 +129,7 @@ public class ScanOnlyChangedTest { .setSeverity(Severity.CRITICAL) .setCreationDate(date("14/03/2004")) .setStatus("OPEN") - .build()) - .build(); - tester.start(); - } - - @After - public void stop() { - tester.stop(); + .build()); } private File copyProject(String path) throws Exception { @@ -159,7 +152,7 @@ public class ScanOnlyChangedTest { taskBuilder.property("sonar.projectKey", projectKey); } - TaskResult result = taskBuilder.start(); + TaskResult result = taskBuilder.execute(); /* * We have: * 6 new issues per line (open) in helloscala.xoo @@ -187,7 +180,7 @@ public class ScanOnlyChangedTest { taskBuilder.property("sonar.projectKey", projectKey); } - TaskResult result = taskBuilder.start(); + TaskResult result = taskBuilder.execute(); assertNumberIssues(result, 16, 2, 0); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/log/LogListenerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/log/LogListenerTest.java index ebf463e580a..f724dd0eaa9 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/log/LogListenerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/log/LogListenerTest.java @@ -60,11 +60,11 @@ public class LogListenerTest { private static PrintStream savedStdOut; private static PrintStream savedStdErr; - public ScannerMediumTester tester = ScannerMediumTester.builder() + @Rule + public ScannerMediumTester tester = new ScannerMediumTester() .registerPlugin("xoo", new XooPlugin()) .addDefaultQProfile("xoo", "Sonar Way") - .setLogOutput(new SimpleLogListener()) - .build(); + .setLogOutput(new SimpleLogListener()); private File baseDir; @@ -95,7 +95,6 @@ public class LogListenerTest { // logger from the batch might write to it asynchronously logOutput = Collections.synchronizedList(new LinkedList()); logOutputStr = new StringBuilder(); - tester.start(); baseDir = temp.getRoot(); @@ -143,9 +142,8 @@ public class LogListenerTest { .put("sonar.sources", "src") .put("sonar.verbose", "true") .build()) - .start(); + .execute(); - tester.stop(); for (LogEvent e : logOutput) { savedStdOut.println("[captured]" + e.level + " " + e.msg); } @@ -166,8 +164,7 @@ public class LogListenerTest { .properties(builder .put("sonar.sources", "src") .build()) - .start(); - tester.stop(); + .execute(); assertNoStdOutput(); assertThat(logOutput).isNotEmpty(); @@ -191,8 +188,7 @@ public class LogListenerTest { .properties(builder .put("sonar.sources", "src") .build()) - .start(); - tester.stop(); + .execute(); assertNoStdOutput(); @@ -220,12 +216,11 @@ public class LogListenerTest { .properties(builder .put("sonar.sources", "src") .build()) - .start(); + .execute(); fail("Expected exception"); } catch (Exception e) { assertThat(e.getMessage()).contains("Error processing line 1"); } - tester.stop(); assertNoStdOutput(); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/measures/MeasuresMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/measures/MeasuresMediumTest.java index 5dd45050f3e..f888fbfd714 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/measures/MeasuresMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/measures/MeasuresMediumTest.java @@ -25,7 +25,6 @@ import java.io.IOException; import java.util.List; import java.util.Map; import org.apache.commons.io.FileUtils; -import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -52,20 +51,10 @@ public class MeasuresMediumTest { private File baseDir; private File srcDir; - public ScannerMediumTester tester = ScannerMediumTester.builder() + @Rule + public ScannerMediumTester tester = new ScannerMediumTester() .registerPlugin("xoo", new XooPlugin()) - .addDefaultQProfile("xoo", "Sonar Way") - .build(); - - @Before - public void prepare() { - tester.start(); - } - - @After - public void stop() { - tester.stop(); - } + .addDefaultQProfile("xoo", "Sonar Way"); @Before public void setUp() throws Exception { @@ -92,7 +81,7 @@ public class MeasuresMediumTest { .put("sonar.projectDescription", "Description of Foo Project") .put("sonar.sources", "src") .build()) - .start(); + .execute(); Map> allMeasures = result.allMeasures(); @@ -110,7 +99,7 @@ public class MeasuresMediumTest { .put("sonar.sources", "src") .put("sonar.coverage.exclusions", "src/sample.xoo") .build()) - .start(); + .execute(); allMeasures = result.allMeasures(); assertThat(allMeasures.get("com.foo.project:src/sample.xoo")).extracting("metricKey", "intValue.value") @@ -135,7 +124,7 @@ public class MeasuresMediumTest { .put("sonar.projectDescription", "Description of Foo Project") .put("sonar.sources", "src") .build()) - .start(); + .execute(); Map> allMeasures = result.allMeasures(); @@ -165,7 +154,7 @@ public class MeasuresMediumTest { .put("sonar.projectDescription", "Description of Foo Project") .put("sonar.sources", "src") .build()) - .start(); + .execute(); fail("Expected exception"); } catch (Exception e) { assertThat(e) @@ -192,7 +181,7 @@ public class MeasuresMediumTest { .put("sonar.projectDescription", "Description of Foo Project") .put("sonar.sources", "src") .build()) - .start(); + .execute(); Map> allMeasures = result.allMeasures(); @@ -218,7 +207,7 @@ public class MeasuresMediumTest { .put("sonar.projectDescription", "Description of Foo Project") .put("sonar.sources", "src") .build()) - .start(); + .execute(); Map> allMeasures = result.allMeasures(); 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 dc411eb2e08..fbf81aa0c7e 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 @@ -27,8 +27,6 @@ import java.nio.charset.StandardCharsets; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.io.FileUtils; import org.assertj.core.util.Files; -import org.junit.After; -import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -56,7 +54,7 @@ public class ScmMediumTest { private static final String SAME_CONTENT_NO_SCM_ON_SERVER_XOO = "src/same_content_no_scm_on_server.xoo"; private static final String SAMPLE_XOO_CONTENT = "Sample xoo\ncontent"; - @org.junit.Rule + @Rule public TemporaryFolder temp = new TemporaryFolder(); @Rule @@ -65,7 +63,8 @@ public class ScmMediumTest { @Rule public LogTester logTester = new LogTester(); - public ScannerMediumTester tester = ScannerMediumTester.builder() + @Rule + public ScannerMediumTester tester = new ScannerMediumTester() .registerPlugin("xoo", new XooPlugin()) .addDefaultQProfile("xoo", "Sonar Way") .addRules(new XooRulesDefinition()) @@ -74,18 +73,7 @@ public class ScmMediumTest { .addFileData("com.foo.project", CHANGED_CONTENT_SCM_ON_SERVER_XOO, new FileData(DigestUtils.md5Hex(SAMPLE_XOO_CONTENT), null)) .addFileData("com.foo.project", SAME_CONTENT_NO_SCM_ON_SERVER_XOO, new FileData(DigestUtils.md5Hex(SAMPLE_XOO_CONTENT), null)) .addFileData("com.foo.project", SAME_CONTENT_SCM_ON_SERVER_XOO, new FileData(DigestUtils.md5Hex(SAMPLE_XOO_CONTENT), "1.1")) - .addFileData("com.foo.project", NO_BLAME_SCM_ON_SERVER_XOO, new FileData(DigestUtils.md5Hex(SAMPLE_XOO_CONTENT), "1.1")) - .build(); - - @Before - public void prepare() { - tester.start(); - } - - @After - public void stop() { - tester.stop(); - } + .addFileData("com.foo.project", NO_BLAME_SCM_ON_SERVER_XOO, new FileData(DigestUtils.md5Hex(SAMPLE_XOO_CONTENT), "1.1")); @Test public void testScmMeasure() throws IOException, URISyntaxException { @@ -102,7 +90,7 @@ public class ScmMediumTest { .put("sonar.sources", "src") .put("sonar.scm.provider", "xoo") .build()) - .start(); + .execute(); ScannerReport.Changesets fileScm = getChangesets(baseDir, "src/sample.xoo"); @@ -125,7 +113,7 @@ public class ScmMediumTest { } private ScannerReport.Changesets getChangesets(File baseDir, String path) { - File reportDir = new File(baseDir, ".sonar/batch-report"); + File reportDir = new File(baseDir, ".sonar/scanner-report"); ScannerReportReader reader = new ScannerReportReader(reportDir); Component project = reader.readComponent(reader.readMetadata().getRootComponentRef()); @@ -158,7 +146,7 @@ public class ScmMediumTest { .put("sonar.sources", "src") .put("sonar.scm.provider", "xoo") .build()) - .start(); + .execute(); ScannerReport.Changesets changesets = getChangesets(baseDir, "src/sample.xoo"); @@ -183,7 +171,7 @@ public class ScmMediumTest { .put("sonar.sources", "src") .put("sonar.scm.provider", "xoo") .build()) - .start(); + .execute(); ScannerReport.Changesets file1Scm = getChangesets(baseDir, "src/sample.xoo"); assertThat(file1Scm).isNotNull(); @@ -236,7 +224,7 @@ public class ScmMediumTest { .put("sonar.sources", "src") .put("sonar.scm.provider", "xoo") .build()) - .start(); + .execute(); assertThat(getChangesets(baseDir, "src/sample.xoo")).isNotNull(); @@ -280,7 +268,7 @@ public class ScmMediumTest { .put("sonar.scm.forceReloadAll", "true") .build()); - taskBuilder.start(); + taskBuilder.execute(); ScannerReport.Changesets file1Scm = getChangesets(baseDir, "src/sample.xoo"); assertThat(file1Scm).isNotNull(); @@ -305,7 +293,7 @@ public class ScmMediumTest { .put("sonar.sources", "src") .put("sonar.links.scm_dev", "scm:xoo:foobar") .build()) - .start(); + .execute(); ScannerReport.Changesets file1Scm = getChangesets(baseDir, "src/sample.xoo"); assertThat(file1Scm).isNotNull(); @@ -327,7 +315,7 @@ public class ScmMediumTest { .put("sonar.projectDescription", "Description of Foo Project") .put("sonar.sources", "src") .build()) - .start(); + .execute(); ScannerReport.Changesets file1Scm = getChangesets(baseDir, "src/sample.xoo"); assertThat(file1Scm).isNotNull(); @@ -376,7 +364,7 @@ public class ScmMediumTest { .put("sonar.scm.provider", "xoo") .put("sonar.cpd.xoo.skip", "true") .build()) - .start(); + .execute(); ScannerReport.Changesets changesets = getChangesets(baseDir, "src/sample.xoo"); assertThat(changesets).isNull(); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/symbol/SymbolMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/symbol/SymbolMediumTest.java index 8bf546573ae..dcf9aa8dd68 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/symbol/SymbolMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/symbol/SymbolMediumTest.java @@ -23,8 +23,7 @@ import com.google.common.collect.ImmutableMap; import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; -import org.junit.After; -import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.api.batch.fs.InputFile; @@ -37,23 +36,13 @@ import static org.assertj.core.api.Assertions.assertThat; public class SymbolMediumTest { - @org.junit.Rule + @Rule public TemporaryFolder temp = new TemporaryFolder(); - public ScannerMediumTester tester = ScannerMediumTester.builder() + @Rule + public ScannerMediumTester tester = new ScannerMediumTester() .registerPlugin("xoo", new XooPlugin()) - .addDefaultQProfile("xoo", "Sonar Way") - .build(); - - @Before - public void prepare() { - tester.start(); - } - - @After - public void stop() { - tester.stop(); - } + .addDefaultQProfile("xoo", "Sonar Way"); @Test public void computeSymbolReferencesOnTempProject() throws IOException { @@ -78,7 +67,7 @@ public class SymbolMediumTest { .put("sonar.projectDescription", "Description of Foo Project") .put("sonar.sources", "src") .build()) - .start(); + .execute(); InputFile file = result.inputFile("src/sample.xoo"); assertThat(result.symbolReferencesFor(file, 1, 7)).containsOnly(ScannerReport.TextRange.newBuilder().setStartLine(3).setStartOffset(8).setEndLine(3).setEndOffset(11).build()); @@ -107,7 +96,7 @@ public class SymbolMediumTest { .put("sonar.projectDescription", "Description of Foo Project") .put("sonar.sources", "src") .build()) - .start(); + .execute(); InputFile file = result.inputFile("src/sample.xoo"); assertThat(result.symbolReferencesFor(file, 1, 7)).containsOnly(ScannerReport.TextRange.newBuilder().setStartLine(3).setStartOffset(8).setEndLine(4).setEndOffset(1).build()); 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 8334d079463..2739b76e23e 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 @@ -45,9 +45,9 @@ public class TasksMediumTest { @Rule public LogTester logTester = new LogTester(); - public ScannerMediumTester tester = ScannerMediumTester.builder() - .registerPlugin("faketask", new FakeTaskPlugin()) - .build(); + @Rule + public ScannerMediumTester tester = new ScannerMediumTester() + .registerPlugin("faketask", new FakeTaskPlugin()); private MockHttpServer server = null; @@ -58,18 +58,12 @@ public class TasksMediumTest { } } - @After - public void stop() { - tester.stop(); - } - @Test public void listTasksIncludingBroken() throws Exception { - tester.start(); tester.newTask() .properties(ImmutableMap.builder() .put("sonar.task", "list").build()) - .start(); + .execute(); assertThat(logTester.logs()).haveExactly(1, new Condition() { @@ -82,8 +76,6 @@ public class TasksMediumTest { @Test public void runBroken() throws Exception { - tester.start(); - thrown.expect(IllegalStateException.class); thrown.expectMessage( "Unable to load component class org.sonar.scanner.mediumtest.tasks.TasksMediumTest$BrokenTask"); @@ -91,18 +83,15 @@ public class TasksMediumTest { tester.newTask() .properties(ImmutableMap.builder() .put("sonar.task", "broken").build()) - .start(); + .execute(); } @Test(expected = MessageException.class) public void unsupportedTask() throws Exception { - tester = ScannerMediumTester.builder() - .build(); - tester.start(); tester.newTask() .properties(ImmutableMap.builder() .put("sonar.task", "foo").build()) - .start(); + .execute(); } private static class FakeTaskPlugin extends SonarPlugin { 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 a949587caa1..91eb6ce7ac6 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 @@ -25,8 +25,6 @@ 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; @@ -46,20 +44,10 @@ public class CoveragePerTestMediumTest { @Rule public ExpectedException exception = ExpectedException.none(); - public ScannerMediumTester tester = ScannerMediumTester.builder() + @Rule + public ScannerMediumTester tester = new ScannerMediumTester() .registerPlugin("xoo", new XooPlugin()) - .addDefaultQProfile("xoo", "Sonar Way") - .build(); - - @Before - public void prepare() { - tester.start(); - } - - @After - public void stop() { - tester.stop(); - } + .addDefaultQProfile("xoo", "Sonar Way"); @Test // SONAR-6183 @@ -130,7 +118,7 @@ public class CoveragePerTestMediumTest { .put("sonar.sources", "src") .put("sonar.tests", "test") .build()) - .start(); + .execute(); } private File createTestFiles() throws IOException { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tests/GenericTestExecutionMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tests/GenericTestExecutionMediumTest.java index 462d3d1f7ea..ec83c2e66ef 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tests/GenericTestExecutionMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tests/GenericTestExecutionMediumTest.java @@ -23,8 +23,7 @@ import com.google.common.collect.ImmutableMap; import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; -import org.junit.After; -import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.api.batch.fs.InputFile; @@ -40,23 +39,13 @@ import static org.assertj.core.api.Assertions.tuple; public class GenericTestExecutionMediumTest { - @org.junit.Rule + @Rule public TemporaryFolder temp = new TemporaryFolder(); - public ScannerMediumTester tester = ScannerMediumTester.builder() + @Rule + public ScannerMediumTester tester = new ScannerMediumTester() .registerPlugin("xoo", new XooPlugin()) - .addDefaultQProfile("xoo", "Sonar Way") - .build(); - - @Before - public void prepare() { - tester.start(); - } - - @After - public void stop() { - tester.stop(); - } + .addDefaultQProfile("xoo", "Sonar Way"); @Test public void unitTests() throws IOException { @@ -90,7 +79,7 @@ public class GenericTestExecutionMediumTest { .put("sonar.sources", "src") .put("sonar.tests", "test") .build()) - .start(); + .execute(); InputFile file = result.inputFile("test/sampleTest.xoo"); org.sonar.scanner.protocol.output.ScannerReport.Test success = result.firstTestExecutionForName(file, "success"); @@ -112,7 +101,7 @@ public class GenericTestExecutionMediumTest { TaskResult result = tester .newScanTask(new File(projectDir, "sonar-project.properties")) .property("sonar.testExecutionReportPaths", "unittest.xml") - .start(); + .execute(); InputFile testFile = result.inputFile("testx/ClassOneTest.xoo"); ScannerReport.Test success = result.firstTestExecutionForName(testFile, "test1"); @@ -154,7 +143,7 @@ public class GenericTestExecutionMediumTest { TaskResult result = tester .newScanTask(new File(projectDir, "sonar-project.properties")) .property("sonar.testExecutionReportPaths", "unittest.xml,unittest2.xml") - .start(); + .execute(); InputFile testFile = result.inputFile("testx/ClassOneTest.xoo"); ScannerReport.Test success = result.firstTestExecutionForName(testFile, "test1"); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tests/TestExecutionMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tests/TestExecutionMediumTest.java index aa0df994785..228b349a729 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tests/TestExecutionMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tests/TestExecutionMediumTest.java @@ -23,8 +23,7 @@ import com.google.common.collect.ImmutableMap; import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; -import org.junit.After; -import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.api.batch.fs.InputFile; @@ -40,20 +39,10 @@ public class TestExecutionMediumTest { @org.junit.Rule public TemporaryFolder temp = new TemporaryFolder(); - public ScannerMediumTester tester = ScannerMediumTester.builder() + @Rule + public ScannerMediumTester tester = new ScannerMediumTester() .registerPlugin("xoo", new XooPlugin()) - .addDefaultQProfile("xoo", "Sonar Way") - .build(); - - @Before - public void prepare() { - tester.start(); - } - - @After - public void stop() { - tester.stop(); - } + .addDefaultQProfile("xoo", "Sonar Way"); @Test public void unitTests() throws IOException { @@ -87,7 +76,7 @@ public class TestExecutionMediumTest { .put("sonar.sources", "src") .put("sonar.tests", "test") .build()) - .start(); + .execute(); InputFile file = result.inputFile("test/sampleTest.xoo"); org.sonar.scanner.protocol.output.ScannerReport.Test success = result.firstTestExecutionForName(file, "success"); 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 635f15e74f5..e4d6c615339 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 @@ -19,21 +19,12 @@ */ package org.sonar.scanner.report; -import static org.apache.commons.io.FileUtils.readFileToString; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.entry; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - import java.io.File; import java.io.IOException; import java.io.PipedInputStream; import java.io.PipedOutputStream; import java.nio.file.Files; import java.nio.file.Path; - import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -60,6 +51,14 @@ import org.sonarqube.ws.client.HttpException; import org.sonarqube.ws.client.WsRequest; import org.sonarqube.ws.client.WsResponse; +import static org.apache.commons.io.FileUtils.readFileToString; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.entry; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + public class ReportPublisherTest { @Rule @@ -176,8 +175,8 @@ public class ReportPublisherTest { @Test public void should_not_delete_report_if_property_is_set() throws IOException { - settings.setProperty("sonar.batch.keepReport", true); - Path reportDir = temp.getRoot().toPath().resolve("batch-report"); + settings.setProperty("sonar.scanner.keepReport", true); + Path reportDir = temp.getRoot().toPath().resolve("scanner-report"); Files.createDirectory(reportDir); ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class), new ReportPublisherStep[0]); @@ -189,7 +188,7 @@ public class ReportPublisherTest { @Test public void should_delete_report_by_default() throws IOException { - Path reportDir = temp.getRoot().toPath().resolve("batch-report"); + Path reportDir = temp.getRoot().toPath().resolve("scanner-report"); Files.createDirectory(reportDir); ReportPublisher job = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class), new ReportPublisherStep[0]); diff --git a/tests/src/test/java/org/sonarqube/tests/analysis/ScannerTest.java b/tests/src/test/java/org/sonarqube/tests/analysis/ScannerTest.java index a175bbf6294..4def0e576ab 100644 --- a/tests/src/test/java/org/sonarqube/tests/analysis/ScannerTest.java +++ b/tests/src/test/java/org/sonarqube/tests/analysis/ScannerTest.java @@ -22,7 +22,6 @@ package org.sonarqube.tests.analysis; import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.BuildResult; import com.sonar.orchestrator.build.SonarScanner; -import org.sonarqube.tests.Category3Suite; import java.io.File; import java.io.IOException; import java.util.Map; @@ -34,6 +33,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; +import org.sonarqube.tests.Category3Suite; import org.sonarqube.ws.client.component.SearchWsRequest; import util.ItUtils; @@ -247,7 +247,7 @@ public class ScannerTest { * SONAR-2291 */ @Test - public void batch_should_cache_plugin_jars() throws IOException { + public void scanner_should_cache_plugin_jars() throws IOException { File userHome = temp.newFolder(); BuildResult result = scan("shared/xoo-sample", @@ -268,12 +268,12 @@ public class ScannerTest { } @Test - public void batch_should_keep_report_verbose() { + public void scanner_should_keep_report_verbose() { orchestrator.getServer().provisionProject("sample", "xoo-sample"); orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line"); scanQuietly("shared/xoo-sample", "sonar.verbose", "true"); - File reportDir = new File(new File(ItUtils.projectDir("shared/xoo-sample"), ".sonar"), "batch-report"); + File reportDir = new File(new File(ItUtils.projectDir("shared/xoo-sample"), ".sonar"), "scanner-report"); assertThat(reportDir).isDirectory(); assertThat(reportDir.list()).isNotEmpty(); } -- 2.39.5