private boolean started = false;
private LoggingConfiguration loggingConfig;
private List<Object> components;
- private Map<String, String> bootstrapProperties = new HashMap<>();
+ private Map<String, String> globalProperties = new HashMap<>();
private GlobalContainer bootstrapContainer;
private Batch(Builder builder) {
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);
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);
/**
* @since 4.4
+ * @deprecated since 6.6 use {@link #execute()}
*/
+ @Deprecated
public Batch executeTask(Map<String, String> 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<String, String> analysisProperties, IssueListener issueListener) {
- checkStarted();
- configureTaskLogging(analysisProperties);
+ private Batch doExecuteTask(Map<String, String> analysisProperties, Object... components) {
try {
- bootstrapContainer.executeTask(analysisProperties, components, issueListener);
+ bootstrapContainer.executeTask(analysisProperties, components);
} catch (RuntimeException e) {
throw handleException(e);
}
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) {
private void configureLogging() {
if (loggingConfig != null) {
- loggingConfig.setProperties(bootstrapProperties);
+ loggingConfig.setProperties(globalProperties);
LoggingConfigurator.apply(loggingConfig);
}
}
private void configureTaskLogging(Map<String, String> taskProperties) {
if (loggingConfig != null) {
- loggingConfig.setProperties(taskProperties, bootstrapProperties);
+ loggingConfig.setProperties(taskProperties, globalProperties);
LoggingConfigurator.apply(loggingConfig);
}
}
}
public static final class Builder {
- private Map<String, String> bootstrapProperties;
+ private Map<String, String> globalProperties;
private EnvironmentInformation environment;
private List<Object> components = new ArrayList<>();
private boolean enableLoggingConfiguration = true;
return this;
}
- /**
- * @deprecated since 3.7 use {@link #setBootstrapProperties(Map)}
- */
- @Deprecated
public Builder setGlobalProperties(Map<String, String> globalProperties) {
- this.bootstrapProperties = globalProperties;
+ this.globalProperties = globalProperties;
return this;
}
+ /**
+ * @deprecated since 6.6 use {@link #setGlobalProperties(Map)}
+ */
+ @Deprecated
public Builder setBootstrapProperties(Map<String, String> bootstrapProperties) {
- this.bootstrapProperties = bootstrapProperties;
+ this.globalProperties = bootstrapProperties;
return this;
}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.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;
- }
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.scanner.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;
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.scanner.issue;
-
-@FunctionalInterface
-public interface IssueCallback {
- void execute();
-}
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;
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");
}
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));
*/
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;
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;
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";
@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);
*/
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;
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;
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);
new QualityProfileProvider(),
// issues
- DefaultIssueCallback.class,
IssueCache.class,
DefaultProjectIssues.class,
IssueTransition.class,
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.scanner.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<IssueListener.Issue> 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<IssueListener.Issue> 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<IssueListener.Issue> 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();
- }
-}
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;
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;
* 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<String, String> 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<String, String> 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<Repository> 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<Repository> 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<String, String> 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<String, String> 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() {
public static class TaskBuilder {
private final Map<String, String> 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<String, String> 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;
}
return this;
}
- public TaskBuilder setIssueListener(IssueListener issueListener) {
- this.issueListener = issueListener;
- return this;
- }
}
private static class FakeRulesLoader implements RulesLoader {
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;
@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;
@Before
public void prepare() throws IOException {
- tester.start();
-
baseDir = temp.getRoot();
commonProps = ImmutableMap.<String, String>builder()
.build();
}
- @After
- public void stop() {
- tester.stop();
- }
-
@Test
public void scanProjectWithBranch() throws IOException {
File srcDir = new File(baseDir, "src");
.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");
.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");
.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");
.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");
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;
@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 {
.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();
.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();
.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();
.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();
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;
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 {
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();
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();
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;
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;
@Before
public void prepare() throws IOException {
logRecorder.getAll().clear();
- tester.start();
baseDir = temp.getRoot();
}
}
- @After
- public void stop() {
- tester.stop();
- }
-
@Test
public void testCrossModuleDuplications() throws IOException {
builder.put("sonar.modules", "module1,module2")
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);
.put("sonar.cpd.xoo.minimumTokens", "10")
.put("sonar.verbose", "true")
.build())
- .start();
+ .execute();
assertThat(result.inputFiles()).hasSize(2);
.put("sonar.cpd.xoo.minimumTokens", "10")
.put("sonar.verbose", "true")
.build())
- .start();
+ .execute();
assertThat(result.inputFiles()).hasSize(2);
.put("sonar.cpd.xoo.minimumTokens", "10")
.put("sonar.cpd.exclusions", "src/sample1.xoo")
.build())
- .start();
+ .execute();
assertThat(result.inputFiles()).hasSize(2);
.put("sonar.verbose", "true")
.put("sonar.cpd.cross_project", "true")
.build())
- .start();
+ .execute();
InputFile inputFile1 = result.inputFile("src/sample1.xoo");
.put("sonar.cpd.xoo.minimumLines", "2")
.put("sonar.verbose", "true")
.build())
- .start();
+ .execute();
InputFile inputFile = result.inputFile("src/sample.xoo");
// One clone group
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;
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 {
.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),
.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),
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;
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<String, String> 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.<String, String>builder()
.put("sonar.projectDescription", "Description of Foo Project");
}
- @After
- public void stop() {
- if (tester != null) {
- tester.stop();
- tester = null;
- }
- logs = new LogOutputRecorder();
- }
-
private ImmutableMap.Builder<String, String> createBuilder() {
return ImmutableMap.<String, String>builder()
.put("sonar.task", "scan")
.properties(builder
.put("sonar.sources", "src")
.build())
- .start();
+ .execute();
int ref = result.getReportReader().readMetadata().getRootComponentRef();
assertThat(result.getReportReader().readComponent(ref).getName()).isEmpty();
.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");
.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");
.properties(builder
.put("sonar.sources", "src")
.build())
- .start();
+ .execute();
assertThat(logs.getAllAsString()).contains("Project key: com.foo.project");
assertThat(logs.getAllAsString()).doesNotContain("Organization key");
.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");
.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");
.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");
@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();
.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'");
@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")
.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");
.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");
@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();
.properties(builder
.put("sonar.sources", "src")
.build())
- .start();
+ .execute();
DefaultInputFile file = (DefaultInputFile) result.inputFile("src/sample.xoo");
InputDir dir = result.inputDir("src");
@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.<String, String>builder()
.put("sonar.task", "scan")
.properties(builder
.put("sonar.sources", "src")
.build())
- .start();
+ .execute();
DefaultInputFile unknownInputFile = (DefaultInputFile) result.inputFile("src/unknown/file.notanalyzed");
InputDir unknownInputDir = result.inputDir("src/unknown");
.properties(builder
.put("sonar.sources", "src")
.build())
- .start();
+ .execute();
assertThat(result.inputFiles()).hasSize(1);
assertThat(result.inputDirs()).hasSize(1);
.properties(builder
.put("sonar.sources", "src")
.build())
- .start();
+ .execute();
assertThat(result.inputFiles()).hasSize(100);
assertThat(result.inputDirs()).hasSize(1);
.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);
.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);
.put("sonar.test.inclusions", "**/sampleTest*.*")
.put("sonar.test.exclusions", "**/sampleTest2.xoo")
.build())
- .start();
+ .execute();
assertThat(result.inputFiles()).hasSize(2);
}
.properties(builder
.put("sonar.sources", "src,src/sample.xoo")
.build())
- .start();
+ .execute();
}
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
.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(
.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);
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);
.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);
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;
@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 {
tester
.newScanTask(new File(projectDir, "sonar-project.properties"))
- .start();
+ .execute();
}
private File copyProject(String path) throws Exception {
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;
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;
}
}
- @After
- public void stop() {
- tester.stop();
- }
-
@Test
public void testProjectReactorValidation() throws IOException {
File baseDir = prepareProject();
.put("sonar.sources", ".")
.put("sonar.xoo.enableProjectBuilder", "true")
.build())
- .start();
+ .execute();
}
.put("sonar.verbose", "true")
.put("sonar.xoo.enableProjectBuilder", "true")
.build())
- .start();
+ .execute();
List<Issue> issues = result.issuesFor(result.inputFile("src/sample.xoo"));
assertThat(issues).hasSize(10);
.put("sonar.sources", ".")
.put("sonar.xoo.enableProjectBuilder", "true")
.build())
- .start();
+ .execute();
}
@Test
.put("sonar.sources", ".")
.put("sonar.xoo.enableProjectBuilder", "true")
.build())
- .start();
+ .execute();
List<Issue> issues = result.issuesFor(result.inputFile("src/sample.xoo"));
assertThat(issues).hasSize(10);
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;
@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 {
.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);
.put("sonar.sources", "src")
.put("sonar.it.savedatatwice", "true")
.build())
- .start();
+ .execute();
}
.put("sonar.projectDescription", "Description of Foo Project")
.put("sonar.sources", "src")
.build())
- .start();
+ .execute();
}
}
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;
@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 {
.put("sonar.projectDescription", "Description of Foo Project")
.put("sonar.sources", "src")
.build())
- .start();
+ .execute();
List<Issue> issues = result.issuesFor(result.inputFile("src/sample.xoo"));
assertThat(issues)
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.scanner.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<Issue> issueList = new LinkedList<>();
-
- @Override
- public void handle(Issue issue) {
- issueList.add(issue);
- }
- }
-}
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;
@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 {
TaskResult result = tester
.newScanTask(new File(tmpDir, "sonar-project.properties"))
- .start();
+ .execute();
List<Issue> issues = result.issuesFor(result.inputFile("xources/hello/HelloJava.xoo"));
assertThat(issues).hasSize(8 /* lines */);
TaskResult result = tester
.newScanTask(new File(tmpDir, "sonar-project.properties"))
.property("sonar.xoo.internalKey", "OneIssuePerLine.internal")
- .start();
+ .execute();
List<Issue> issues = result.issuesFor(result.inputFile("xources/hello/HelloJava.xoo"));
assertThat(issues).hasSize(8 /* lines */ + 1 /* file */);
TaskResult result = tester
.newScanTask(new File(tmpDir, "sonar-project.properties"))
.property("sonar.oneIssuePerLine.forceSeverity", "CRITICAL")
- .start();
+ .execute();
List<Issue> issues = result.issuesFor(result.inputFile("xources/hello/HelloJava.xoo"));
assertThat(issues.get(0).getSeverity()).isEqualTo(org.sonar.scanner.protocol.Constants.Severity.CRITICAL);
.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();
.put("sonar.projectDescription", "Description of Foo Project")
.put("sonar.sources", "src")
.build())
- .start();
+ .execute();
List<Issue> issues = result.issuesFor(result.inputFile("src/sample.xoo"));
assertThat(issues).hasSize(10);
.contains(tuple("This issue is generated on each line", 1, 0.0));
}
- private class IssueRecorder implements IssueListener {
- List<Issue> issueList = new LinkedList<>();
-
- @Override
- public void handle(Issue issue) {
- issueList.add(issue);
- }
- }
}
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;
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 {
.put("sonar.projectDescription", "Description of Foo Project")
.put("sonar.sources", "src")
.build())
- .start();
+ .execute();
assertThat(result.issuesFor(result.inputDir("src"))).hasSize(2);
}
.put("sonar.projectDescription", "Description of Foo Project")
.put("sonar.sources", ".")
.build())
- .start();
+ .execute();
assertThat(result.issuesFor(result.inputDir(""))).hasSize(2);
}
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;
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 {
.put("sonar.projectDescription", "Description of Foo Project")
.put("sonar.sources", "src")
.build())
- .start();
+ .execute();
assertThat(result.issuesFor(result.getReportComponent("com.foo.project"))).hasSize(1);
}
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;
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
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;
@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 {
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);
}
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;
}
}
- 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")
.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();
TaskResult result = tester
.newScanTask(new File(projectDir, "sonar-project.properties"))
- .start();
+ .execute();
int newIssues = 0;
int openIssues = 0;
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");
tester
.newScanTask(new File(projectDir, "sonar-project.properties"))
.property("sonar.issuesReport.console.enable", "true")
- .start();
+ .execute();
assertThat(getReportLog()).contains("+16 issues", "+16 major");
}
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");
}
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();
.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<Issue> issueList = new LinkedList<>();
-
- @Override
- public void handle(Issue issue) {
- issueList.add(issue);
- }
- }
-
@Test
public void noSyntaxHighlightingInIssuesMode() throws IOException {
.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();
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;
@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 {
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());
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;
@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 {
.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())
.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 {
taskBuilder.property("sonar.projectKey", projectKey);
}
- TaskResult result = taskBuilder.start();
+ TaskResult result = taskBuilder.execute();
/*
* We have:
* 6 new issues per line (open) in helloscala.xoo
taskBuilder.property("sonar.projectKey", projectKey);
}
- TaskResult result = taskBuilder.start();
+ TaskResult result = taskBuilder.execute();
assertNumberIssues(result, 16, 2, 0);
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;
// logger from the batch might write to it asynchronously
logOutput = Collections.synchronizedList(new LinkedList<LogEvent>());
logOutputStr = new StringBuilder();
- tester.start();
baseDir = temp.getRoot();
.put("sonar.sources", "src")
.put("sonar.verbose", "true")
.build())
- .start();
+ .execute();
- tester.stop();
for (LogEvent e : logOutput) {
savedStdOut.println("[captured]" + e.level + " " + e.msg);
}
.properties(builder
.put("sonar.sources", "src")
.build())
- .start();
- tester.stop();
+ .execute();
assertNoStdOutput();
assertThat(logOutput).isNotEmpty();
.properties(builder
.put("sonar.sources", "src")
.build())
- .start();
- tester.stop();
+ .execute();
assertNoStdOutput();
.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();
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;
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 {
.put("sonar.projectDescription", "Description of Foo Project")
.put("sonar.sources", "src")
.build())
- .start();
+ .execute();
Map<String, List<Measure>> allMeasures = result.allMeasures();
.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")
.put("sonar.projectDescription", "Description of Foo Project")
.put("sonar.sources", "src")
.build())
- .start();
+ .execute();
Map<String, List<Measure>> allMeasures = result.allMeasures();
.put("sonar.projectDescription", "Description of Foo Project")
.put("sonar.sources", "src")
.build())
- .start();
+ .execute();
fail("Expected exception");
} catch (Exception e) {
assertThat(e)
.put("sonar.projectDescription", "Description of Foo Project")
.put("sonar.sources", "src")
.build())
- .start();
+ .execute();
Map<String, List<Measure>> allMeasures = result.allMeasures();
.put("sonar.projectDescription", "Description of Foo Project")
.put("sonar.sources", "src")
.build())
- .start();
+ .execute();
Map<String, List<Measure>> allMeasures = result.allMeasures();
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;
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
@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())
.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 {
.put("sonar.sources", "src")
.put("sonar.scm.provider", "xoo")
.build())
- .start();
+ .execute();
ScannerReport.Changesets fileScm = getChangesets(baseDir, "src/sample.xoo");
}
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());
.put("sonar.sources", "src")
.put("sonar.scm.provider", "xoo")
.build())
- .start();
+ .execute();
ScannerReport.Changesets changesets = getChangesets(baseDir, "src/sample.xoo");
.put("sonar.sources", "src")
.put("sonar.scm.provider", "xoo")
.build())
- .start();
+ .execute();
ScannerReport.Changesets file1Scm = getChangesets(baseDir, "src/sample.xoo");
assertThat(file1Scm).isNotNull();
.put("sonar.sources", "src")
.put("sonar.scm.provider", "xoo")
.build())
- .start();
+ .execute();
assertThat(getChangesets(baseDir, "src/sample.xoo")).isNotNull();
.put("sonar.scm.forceReloadAll", "true")
.build());
- taskBuilder.start();
+ taskBuilder.execute();
ScannerReport.Changesets file1Scm = getChangesets(baseDir, "src/sample.xoo");
assertThat(file1Scm).isNotNull();
.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();
.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();
.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();
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;
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 {
.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());
.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());
@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;
}
}
- @After
- public void stop() {
- tester.stop();
- }
-
@Test
public void listTasksIncludingBroken() throws Exception {
- tester.start();
tester.newTask()
.properties(ImmutableMap.<String, String>builder()
.put("sonar.task", "list").build())
- .start();
+ .execute();
assertThat(logTester.logs()).haveExactly(1, new Condition<String>() {
@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");
tester.newTask()
.properties(ImmutableMap.<String, String>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.<String, String>builder()
.put("sonar.task", "foo").build())
- .start();
+ .execute();
}
private static class FakeTaskPlugin extends SonarPlugin {
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;
@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
.put("sonar.sources", "src")
.put("sonar.tests", "test")
.build())
- .start();
+ .execute();
}
private File createTestFiles() throws IOException {
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;
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 {
.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");
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");
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");
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;
@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 {
.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");
*/
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;
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
@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]);
@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]);
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;
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;
* 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",
}
@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();
}