]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9606 Clean scanner-engine entry point
authorJulien HENRY <julien.henry@sonarsource.com>
Thu, 27 Jul 2017 13:44:32 +0000 (15:44 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Fri, 28 Jul 2017 09:58:37 +0000 (11:58 +0200)
38 files changed:
sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/Batch.java
sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/IssueListener.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultIssueCallback.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssueCallback.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/IssuesPhaseExecutor.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ReportPublisher.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DefaultIssueCallbackTest.java [deleted file]
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/branch/BranchMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/coverage/CoverageMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/coverage/GenericCoverageMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/cpd/CpdMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/deprecated/DeprecatedApiMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/NoLanguagesPluginsMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/ProjectBuilderMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/highlighting/HighlightingMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/ChecksMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesIssuesModeMediumTest.java [deleted file]
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesOnDirMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesOnModuleMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/MultilineIssuesMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issuesmode/EmptyFileTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issuesmode/IssueModeAndReportsMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issuesmode/NoPreviousAnalysisTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issuesmode/ScanOnlyChangedTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/log/LogListenerTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/measures/MeasuresMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/scm/ScmMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/symbol/SymbolMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tasks/TasksMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tests/CoveragePerTestMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tests/GenericTestExecutionMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tests/TestExecutionMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java
tests/src/test/java/org/sonarqube/tests/analysis/ScannerTest.java

index 07540030654b860f7c02a6a58b99870c68df1d51..9d745c5300819be62540a9956ac23e18936b563a 100644 (file)
@@ -39,7 +39,7 @@ public final class Batch {
   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) {
@@ -48,11 +48,11 @@ public final class Batch {
     if (builder.environment != null) {
       components.add(builder.environment);
     }
-    if (builder.bootstrapProperties != null) {
-      bootstrapProperties.putAll(builder.bootstrapProperties);
+    if (builder.globalProperties != null) {
+      globalProperties.putAll(builder.globalProperties);
     }
     if (builder.isEnableLoggingConfiguration()) {
-      loggingConfig = new LoggingConfiguration(builder.environment).setProperties(bootstrapProperties);
+      loggingConfig = new LoggingConfiguration(builder.environment).setProperties(globalProperties);
 
       if (builder.logOutput != null) {
         loggingConfig.setLogOutput(builder.logOutput);
@@ -64,39 +64,35 @@ public final class Batch {
     return loggingConfig;
   }
 
-  /**
-   * @deprecated since 4.4 use {@link #start()}, {@link #executeTask(Map)} and then {@link #stop()}
-   */
-  @Deprecated
   public synchronized Batch execute() {
     configureLogging();
-    start();
+    doStart();
     boolean threw = true;
     try {
-      executeTask(bootstrapProperties);
+      doExecuteTask(globalProperties);
       threw = false;
     } finally {
       doStop(threw);
     }
-
     return this;
   }
 
   /**
    * @since 4.4
+   * @deprecated since 6.6 use {@link #execute()}
    */
+  @Deprecated
   public synchronized Batch start() {
-    return start(false);
-  }
-
-  public synchronized Batch start(boolean preferCache) {
     if (started) {
-      throw new IllegalStateException("Batch is already started");
+      throw new IllegalStateException("Scanner Engine is already started");
     }
-
     configureLogging();
+    return doStart();
+  }
+
+  private Batch doStart() {
     try {
-      bootstrapContainer = GlobalContainer.create(bootstrapProperties, components);
+      bootstrapContainer = GlobalContainer.create(globalProperties, components);
       bootstrapContainer.startComponents();
     } catch (RuntimeException e) {
       throw handleException(e);
@@ -108,26 +104,18 @@ public final class Batch {
 
   /**
    * @since 4.4
+   * @deprecated since 6.6 use {@link #execute()}
    */
+  @Deprecated
   public Batch executeTask(Map<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);
     }
@@ -154,26 +142,18 @@ public final class Batch {
     return t;
   }
 
-  /**
-   * @since 5.2
-   * @deprecated since 5.6
-   */
-  @Deprecated
-  public Batch syncProject(String projectKey) {
-    checkStarted();
-    return this;
-  }
-
   /**
    * @since 4.4
+   * @deprecated since 6.6 use {@link #execute()}
    */
+  @Deprecated
   public synchronized void stop() {
+    checkStarted();
+    configureLogging();
     doStop(false);
   }
 
   private void doStop(boolean swallowException) {
-    checkStarted();
-    configureLogging();
     try {
       bootstrapContainer.stopComponents(swallowException);
     } catch (RuntimeException e) {
@@ -184,14 +164,14 @@ public final class Batch {
 
   private void configureLogging() {
     if (loggingConfig != null) {
-      loggingConfig.setProperties(bootstrapProperties);
+      loggingConfig.setProperties(globalProperties);
       LoggingConfigurator.apply(loggingConfig);
     }
   }
 
   private void configureTaskLogging(Map<String, String> taskProperties) {
     if (loggingConfig != null) {
-      loggingConfig.setProperties(taskProperties, bootstrapProperties);
+      loggingConfig.setProperties(taskProperties, globalProperties);
       LoggingConfigurator.apply(loggingConfig);
     }
   }
@@ -201,7 +181,7 @@ public final class Batch {
   }
 
   public static final class Builder {
-    private Map<String, String> bootstrapProperties;
+    private Map<String, String> globalProperties;
     private EnvironmentInformation environment;
     private List<Object> components = new ArrayList<>();
     private boolean enableLoggingConfiguration = true;
@@ -225,17 +205,17 @@ public final class Batch {
       return this;
     }
 
-    /**
-     * @deprecated since 3.7 use {@link #setBootstrapProperties(Map)}
-     */
-    @Deprecated
     public Builder setGlobalProperties(Map<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;
     }
 
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/IssueListener.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/IssueListener.java
deleted file mode 100644 (file)
index 5255126..0000000
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.batch.bootstrapper;
-
-/**
- * @deprecated since 6.2 was used by initial version of SonarLint. No more used.
- */
-@Deprecated
-@FunctionalInterface
-public interface IssueListener {
-  void handle(Issue issue);
-
-  class Issue {
-    /** @since 5.3 */
-    private Integer startLine;
-    /** @since 5.3 */
-    private Integer startLineOffset;
-    /** @since 5.3 */
-    private Integer endLine;
-    /** @since 5.3 */
-    private Integer endLineOffset;
-
-    private String key;
-    private String componentKey;
-    private String message;
-    private String ruleKey;
-    private String ruleName;
-    private String status;
-    private String resolution;
-    private boolean isNew;
-    private String assigneeLogin;
-    private String assigneeName;
-    private String severity;
-
-    public String getSeverity() {
-      return severity;
-    }
-
-    public void setSeverity(String severity) {
-      this.severity = severity;
-    }
-
-    public String getKey() {
-      return key;
-    }
-
-    public void setKey(String key) {
-      this.key = key;
-    }
-
-    public String getComponentKey() {
-      return componentKey;
-    }
-
-    public void setComponentKey(String componentKey) {
-      this.componentKey = componentKey;
-    }
-
-    public Integer getStartLine() {
-      return startLine;
-    }
-
-    public void setStartLine(Integer startLine) {
-      this.startLine = startLine;
-    }
-
-    public Integer getStartLineOffset() {
-      return startLineOffset;
-    }
-
-    public void setStartLineOffset(Integer startLineOffset) {
-      this.startLineOffset = startLineOffset;
-    }
-
-    public Integer getEndLine() {
-      return endLine;
-    }
-
-    public void setEndLine(Integer endLine) {
-      this.endLine = endLine;
-    }
-
-    public Integer getEndLineOffset() {
-      return endLineOffset;
-    }
-
-    public void setEndLineOffset(Integer endLineOffset) {
-      this.endLineOffset = endLineOffset;
-    }
-
-    public String getMessage() {
-      return message;
-    }
-
-    public void setMessage(String message) {
-      this.message = message;
-    }
-
-    public String getRuleKey() {
-      return ruleKey;
-    }
-
-    public void setRuleKey(String ruleKey) {
-      this.ruleKey = ruleKey;
-    }
-
-    public String getRuleName() {
-      return ruleName;
-    }
-
-    public void setRuleName(String ruleName) {
-      this.ruleName = ruleName;
-    }
-
-    public String getStatus() {
-      return status;
-    }
-
-    public void setStatus(String status) {
-      this.status = status;
-    }
-
-    public String getResolution() {
-      return resolution;
-    }
-
-    public void setResolution(String resolution) {
-      this.resolution = resolution;
-    }
-
-    public boolean isNew() {
-      return isNew;
-    }
-
-    public void setNew(boolean isNew) {
-      this.isNew = isNew;
-    }
-
-    public String getAssigneeLogin() {
-      return assigneeLogin;
-    }
-
-    public void setAssigneeLogin(String assigneeLogin) {
-      this.assigneeLogin = assigneeLogin;
-    }
-
-    public String getAssigneeName() {
-      return assigneeName;
-    }
-
-    public void setAssigneeName(String assigneeName) {
-      this.assigneeName = assigneeName;
-    }
-  }
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultIssueCallback.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultIssueCallback.java
deleted file mode 100644 (file)
index ca0c2ca..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.scanner.issue;
-
-import org.sonar.api.batch.rule.Rule;
-import org.sonar.api.batch.rule.Rules;
-import org.sonar.api.rule.RuleKey;
-import org.sonar.batch.bootstrapper.IssueListener;
-import org.sonar.scanner.issue.tracking.TrackedIssue;
-
-public class DefaultIssueCallback implements IssueCallback {
-  private final IssueCache issues;
-  private final IssueListener listener;
-  private final Rules rules;
-
-  public DefaultIssueCallback(IssueCache issues, IssueListener listener, Rules rules) {
-    this.issues = issues;
-    this.listener = listener;
-    this.rules = rules;
-  }
-
-  /**
-   * If no listener exists, this constructor will be used by pico.
-   */
-  public DefaultIssueCallback(IssueCache issues, Rules rules) {
-    this(issues, null, rules);
-  }
-
-  @Override
-  public void execute() {
-    if (listener == null) {
-      return;
-    }
-
-    for (TrackedIssue issue : issues.all()) {
-      IssueListener.Issue newIssue = new IssueListener.Issue();
-      newIssue.setAssigneeLogin(issue.assignee());
-      newIssue.setAssigneeName(issue.assignee());
-      newIssue.setComponentKey(issue.componentKey());
-      newIssue.setKey(issue.key());
-      newIssue.setMessage(issue.getMessage());
-      newIssue.setNew(issue.isNew());
-      newIssue.setResolution(issue.resolution());
-      newIssue.setRuleKey(issue.getRuleKey().toString());
-      newIssue.setRuleName(getRuleName(issue.getRuleKey()));
-      newIssue.setSeverity(issue.severity());
-      newIssue.setStatus(issue.status());
-      newIssue.setStartLine(issue.startLine());
-      newIssue.setStartLineOffset(issue.startLineOffset());
-      newIssue.setEndLine(issue.endLine());
-      newIssue.setEndLineOffset(issue.endLineOffset());
-
-      listener.handle(newIssue);
-    }
-  }
-
-  private String getRuleName(RuleKey ruleKey) {
-    Rule rule = rules.find(ruleKey);
-    return rule != null ? rule.name() : null;
-  }
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssueCallback.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssueCallback.java
deleted file mode 100644 (file)
index 297604b..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.scanner.issue;
-
-@FunctionalInterface
-public interface IssueCallback {
-  void execute();
-}
index e2fd0aea9ff178928272c226120f78050d9eb6d5..b82ca8961a719bbe91ccdff084a60ff3798c1012 100644 (file)
@@ -25,7 +25,6 @@ import org.sonar.api.batch.SensorContext;
 import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
 import org.sonar.scanner.events.BatchStepEvent;
 import org.sonar.scanner.events.EventBus;
-import org.sonar.scanner.issue.IssueCallback;
 import org.sonar.scanner.issue.ignore.scanner.IssueExclusionsLoader;
 import org.sonar.scanner.issue.tracking.IssueTransition;
 import org.sonar.scanner.rule.QProfileVerifier;
@@ -40,22 +39,19 @@ public final class IssuesPhaseExecutor extends AbstractPhaseExecutor {
   private final EventBus eventBus;
   private final IssuesReports issuesReport;
   private final IssueTransition localIssueTracking;
-  private final IssueCallback issueCallback;
 
   public IssuesPhaseExecutor(InitializersExecutor initializersExecutor, PostJobsExecutor postJobsExecutor, SensorsExecutor sensorsExecutor, SensorContext sensorContext,
     EventBus eventBus, FileSystemLogger fsLogger, IssuesReports jsonReport, DefaultModuleFileSystem fs, QProfileVerifier profileVerifier,
-    IssueExclusionsLoader issueExclusionsLoader, IssueTransition localIssueTracking, IssueCallback issueCallback, InputModuleHierarchy moduleHierarchy) {
+    IssueExclusionsLoader issueExclusionsLoader, IssueTransition localIssueTracking, InputModuleHierarchy moduleHierarchy) {
     super(initializersExecutor, postJobsExecutor, sensorsExecutor, sensorContext, moduleHierarchy, eventBus, fsLogger, fs, profileVerifier, issueExclusionsLoader);
     this.eventBus = eventBus;
     this.issuesReport = jsonReport;
     this.localIssueTracking = localIssueTracking;
-    this.issueCallback = issueCallback;
   }
 
   @Override
   protected void executeOnRoot() {
     localIssueTracking();
-    issuesCallback();
     issuesReport();
     LOG.info("ANALYSIS SUCCESSFUL");
   }
@@ -67,13 +63,6 @@ public final class IssuesPhaseExecutor extends AbstractPhaseExecutor {
     eventBus.fireEvent(new BatchStepEvent(stepName, false));
   }
 
-  private void issuesCallback() {
-    String stepName = "Issues Callback";
-    eventBus.fireEvent(new BatchStepEvent(stepName, true));
-    issueCallback.execute();
-    eventBus.fireEvent(new BatchStepEvent(stepName, false));
-  }
-
   private void issuesReport() {
     String stepName = "Issues Reports";
     eventBus.fireEvent(new BatchStepEvent(stepName, true));
index 54fd94ca9236d72a55b32c6486c994251dfa1674..a909a9a4acaf3791133e9a55f288546deb9de154 100644 (file)
@@ -19,8 +19,8 @@
  */
 package org.sonar.scanner.report;
 
-import static org.sonar.core.util.FileUtils.deleteQuietly;
-
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Throwables;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
@@ -31,9 +31,8 @@ import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.LinkedHashMap;
 import java.util.Map;
-
 import javax.annotation.Nullable;
-
+import okhttp3.HttpUrl;
 import org.apache.commons.io.FileUtils;
 import org.picocontainer.Startable;
 import org.sonar.api.CoreProperties;
@@ -55,17 +54,14 @@ import org.sonarqube.ws.client.HttpException;
 import org.sonarqube.ws.client.PostRequest;
 import org.sonarqube.ws.client.WsResponse;
 
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Throwables;
-
-import okhttp3.HttpUrl;
+import static org.sonar.core.util.FileUtils.deleteQuietly;
 
 @ScannerSide
 public class ReportPublisher implements Startable {
 
   private static final Logger LOG = Loggers.get(ReportPublisher.class);
 
-  public static final String KEEP_REPORT_PROP_KEY = "sonar.batch.keepReport";
+  public static final String KEEP_REPORT_PROP_KEY = "sonar.scanner.keepReport";
   public static final String VERBOSE_KEY = "sonar.verbose";
   public static final String METADATA_DUMP_FILENAME = "report-task.txt";
 
@@ -95,7 +91,7 @@ public class ReportPublisher implements Startable {
 
   @Override
   public void start() {
-    reportDir = new File(moduleHierarchy.root().getWorkDir(), "batch-report");
+    reportDir = new File(moduleHierarchy.root().getWorkDir(), "scanner-report");
     writer = new ScannerReportWriter(reportDir);
     contextPublisher.init(writer);
 
index 458239cc526ffb799c5e4b2e98834b6e7c92490b..291630228c7acb45e4a1309867a8c539a523e346 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.scanner.scan;
 
+import com.google.common.annotations.VisibleForTesting;
 import org.apache.commons.lang.StringUtils;
 import org.sonar.api.CoreProperties;
 import org.sonar.api.batch.InstantiationStrategy;
@@ -47,7 +48,6 @@ import org.sonar.scanner.deprecated.test.TestPlanBuilder;
 import org.sonar.scanner.deprecated.test.TestableBuilder;
 import org.sonar.scanner.events.EventBus;
 import org.sonar.scanner.index.DefaultIndex;
-import org.sonar.scanner.issue.DefaultIssueCallback;
 import org.sonar.scanner.issue.DefaultProjectIssues;
 import org.sonar.scanner.issue.IssueCache;
 import org.sonar.scanner.issue.tracking.DefaultServerLineHashesLoader;
@@ -92,8 +92,6 @@ import org.sonar.scanner.scan.measure.DeprecatedMetricFinder;
 import org.sonar.scanner.scan.measure.MeasureCache;
 import org.sonar.scanner.storage.Storages;
 
-import com.google.common.annotations.VisibleForTesting;
-
 public class ProjectScanContainer extends ComponentContainer {
 
   private static final Logger LOG = Loggers.get(ProjectScanContainer.class);
@@ -157,7 +155,6 @@ public class ProjectScanContainer extends ComponentContainer {
       new QualityProfileProvider(),
 
       // issues
-      DefaultIssueCallback.class,
       IssueCache.class,
       DefaultProjectIssues.class,
       IssueTransition.class,
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DefaultIssueCallbackTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DefaultIssueCallbackTest.java
deleted file mode 100644 (file)
index c5f606f..0000000
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.scanner.issue;
-
-import com.google.common.collect.ImmutableList;
-import java.util.LinkedList;
-import java.util.List;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.sonar.api.batch.rule.Rule;
-import org.sonar.api.batch.rule.Rules;
-import org.sonar.api.rule.RuleKey;
-import org.sonar.batch.bootstrapper.IssueListener;
-import org.sonar.batch.bootstrapper.IssueListener.Issue;
-import org.sonar.scanner.issue.tracking.TrackedIssue;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class DefaultIssueCallbackTest {
-  @Mock
-  private IssueCache issueCache;
-  @Mock
-  private Rules rules;
-
-  private TrackedIssue issue;
-
-  @Before
-  public void setUp() {
-    MockitoAnnotations.initMocks(this);
-
-    RuleKey ruleKey = RuleKey.of("repo", "key");
-    issue = new TrackedIssue();
-    issue.setKey("key");
-    issue.setAssignee("user");
-    issue.setRuleKey(ruleKey);
-
-    when(issueCache.all()).thenReturn(ImmutableList.of(issue));
-
-    Rule r = mock(Rule.class);
-    when(r.name()).thenReturn("rule name");
-    when(rules.find(ruleKey)).thenReturn(r);
-  }
-
-  @Test
-  public void testWithoutListener() {
-    DefaultIssueCallback issueCallback = new DefaultIssueCallback(issueCache, rules);
-    issueCallback.execute();
-  }
-
-  @Test
-  public void testWithListener() {
-    final List<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();
-  }
-}
index 065dc0bcc4b02f2f266a5a0f66d73566b24870e0..92d0cd0598f913bd6d40f3de9d7ee55fcb5530c1 100644 (file)
@@ -39,7 +39,7 @@ import java.util.Properties;
 import java.util.function.Consumer;
 import javax.annotation.Nullable;
 import org.apache.commons.io.FileUtils;
-import org.sonar.api.CoreProperties;
+import org.junit.rules.ExternalResource;
 import org.sonar.api.Plugin;
 import org.sonar.api.batch.debt.internal.DefaultDebtModel;
 import org.sonar.api.measures.CoreMetrics;
@@ -50,7 +50,6 @@ import org.sonar.api.server.rule.RulesDefinition.Repository;
 import org.sonar.api.utils.DateUtils;
 import org.sonar.batch.bootstrapper.Batch;
 import org.sonar.batch.bootstrapper.EnvironmentInformation;
-import org.sonar.batch.bootstrapper.IssueListener;
 import org.sonar.batch.bootstrapper.LogOutput;
 import org.sonar.scanner.bootstrap.GlobalMode;
 import org.sonar.scanner.issue.tracking.ServerLineHashesLoader;
@@ -74,226 +73,170 @@ import org.sonarqube.ws.Rules.ListResponse.Rule;
  * Main utility class for writing scanner medium tests.
  * 
  */
-public class ScannerMediumTester {
-
-  private Batch batch;
-  private static Path workingDir = null;
-  private static Path globalWorkingDir = null;
+public class ScannerMediumTester extends ExternalResource {
+
+  private static Path userHome = null;
+  private Map<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() {
@@ -318,21 +261,34 @@ public class ScannerMediumTester {
   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;
     }
 
@@ -346,10 +302,6 @@ public class ScannerMediumTester {
       return this;
     }
 
-    public TaskBuilder setIssueListener(IssueListener issueListener) {
-      this.issueListener = issueListener;
-      return this;
-    }
   }
 
   private static class FakeRulesLoader implements RulesLoader {
index 8cddb21d14f7c29f07bfd743c887c5a5c1920b2d..5c0c0351fc29d3882634d37c4b52a921a33a06a6 100644 (file)
@@ -26,7 +26,6 @@ import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.Map;
 import org.apache.commons.io.FileUtils;
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -48,13 +47,13 @@ public class BranchMediumTest {
   @Rule
   public ExpectedException thrown = ExpectedException.none();
 
-  public ScannerMediumTester tester = ScannerMediumTester.builder()
+  @Rule
+  public ScannerMediumTester tester = new ScannerMediumTester()
     .registerPlugin("xoo", new XooPlugin())
     .addRules(new XooRulesDefinition())
     // active a rule just to be sure that xoo files are published
     .addActiveRule("xoo", "xoo:OneIssuePerFile", null, "One Issue Per File", null, null, null)
-    .addDefaultQProfile("xoo", "Sonar Way")
-    .build();
+    .addDefaultQProfile("xoo", "Sonar Way");
 
   private File baseDir;
 
@@ -62,8 +61,6 @@ public class BranchMediumTest {
 
   @Before
   public void prepare() throws IOException {
-    tester.start();
-
     baseDir = temp.getRoot();
 
     commonProps = ImmutableMap.<String, String>builder()
@@ -77,11 +74,6 @@ public class BranchMediumTest {
       .build();
   }
 
-  @After
-  public void stop() {
-    tester.stop();
-  }
-
   @Test
   public void scanProjectWithBranch() throws IOException {
     File srcDir = new File(baseDir, "src");
@@ -95,7 +87,7 @@ public class BranchMediumTest {
         .putAll(commonProps)
         .put("sonar.branch", "branch")
         .build())
-      .start();
+      .execute();
 
     assertThat(result.inputFiles()).hasSize(1);
     assertThat(result.inputFile("src/sample.xoo").key()).isEqualTo("com.foo.project:src/sample.xoo");
@@ -110,7 +102,7 @@ public class BranchMediumTest {
         .putAll(commonProps)
         .put("sonar.branch", "")
         .build())
-      .start();
+      .execute();
 
     assertThat(result.inputFiles()).hasSize(1);
     assertThat(result.inputFile("src/sample.xoo").key()).isEqualTo("com.foo.project:src/sample.xoo");
@@ -130,7 +122,7 @@ public class BranchMediumTest {
         .put("sonar.branch", "branch")
         .put("sonar.modules", "moduleA")
         .build())
-      .start();
+      .execute();
 
     assertThat(result.inputFiles()).hasSize(1);
     assertThat(result.inputFile("src/sample.xoo").key()).isEqualTo("com.foo.project:moduleA:src/sample.xoo");
@@ -150,7 +142,7 @@ public class BranchMediumTest {
         .put("sonar.branch", "")
         .put("sonar.modules", "moduleA")
         .build())
-      .start();
+      .execute();
 
     assertThat(result.inputFiles()).hasSize(1);
     assertThat(result.inputFile("src/sample.xoo").key()).isEqualTo("com.foo.project:moduleA:src/sample.xoo");
index f31b3205390a60116fabc5f4a7d71bd1bdffeab5..e840ef3cda421e4ee9ed24caae705fc8dbe58d9d 100644 (file)
@@ -25,8 +25,7 @@ import java.io.IOException;
 import java.util.List;
 import java.util.Map;
 import org.apache.commons.io.FileUtils;
-import org.junit.After;
-import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.fs.InputFile;
@@ -43,20 +42,10 @@ public class CoverageMediumTest {
   @org.junit.Rule
   public TemporaryFolder temp = new TemporaryFolder();
 
-  public ScannerMediumTester tester = ScannerMediumTester.builder()
+  @Rule
+  public ScannerMediumTester tester = new ScannerMediumTester()
     .registerPlugin("xoo", new XooPlugin())
-    .addDefaultQProfile("xoo", "Sonar Way")
-    .build();
-
-  @Before
-  public void prepare() {
-    tester.start();
-  }
-
-  @After
-  public void stop() {
-    tester.stop();
-  }
+    .addDefaultQProfile("xoo", "Sonar Way");
 
   @Test
   public void singleReport() throws IOException {
@@ -80,7 +69,7 @@ public class CoverageMediumTest {
         .put("sonar.projectDescription", "Description of Foo Project")
         .put("sonar.sources", "src")
         .build())
-      .start();
+      .execute();
 
     InputFile file = result.inputFile("src/sample.xoo");
     assertThat(result.coverageFor(file, 2).getHits()).isTrue();
@@ -119,7 +108,7 @@ public class CoverageMediumTest {
         .put("sonar.projectDescription", "Description of Foo Project")
         .put("sonar.sources", "src")
         .build())
-      .start();
+      .execute();
 
     InputFile file = result.inputFile("src/sample.xoo");
     assertThat(result.coverageFor(file, 2).getHits()).isTrue();
@@ -161,7 +150,7 @@ public class CoverageMediumTest {
         .put("sonar.sources", "src")
         .put("sonar.coverage.exclusions", "**/sample.xoo")
         .build())
-      .start();
+      .execute();
 
     InputFile file = result.inputFile("src/sample.xoo");
     assertThat(result.coverageFor(file, 2)).isNull();
@@ -194,7 +183,7 @@ public class CoverageMediumTest {
         .put("sonar.projectDescription", "Description of Foo Project")
         .put("sonar.sources", "src")
         .build())
-      .start();
+      .execute();
 
     InputFile file = result.inputFile("src/sample.xoo");
     assertThat(result.coverageFor(file, 1)).isNull();
index 1b82927bcd07324b35d7b5e5cf28ae4b00fc3eeb..1ea18e7f70f99fd8d9baf4b28046d366b534af35 100644 (file)
@@ -21,8 +21,7 @@ package org.sonar.scanner.mediumtest.coverage;
 
 import java.io.File;
 import java.io.IOException;
-import org.junit.After;
-import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.measures.CoreMetrics;
@@ -35,20 +34,10 @@ import static org.assertj.core.api.Assertions.tuple;
 
 public class GenericCoverageMediumTest {
 
-  public ScannerMediumTester tester = ScannerMediumTester.builder()
+  @Rule
+  public ScannerMediumTester tester = new ScannerMediumTester()
     .registerPlugin("xoo", new XooPlugin())
-    .addDefaultQProfile("xoo", "Sonar Way")
-    .build();
-
-  @Before
-  public void prepare() {
-    tester.start();
-  }
-
-  @After
-  public void stop() {
-    tester.stop();
-  }
+    .addDefaultQProfile("xoo", "Sonar Way");
 
   @Test
   public void singleReport() throws IOException {
@@ -58,7 +47,7 @@ public class GenericCoverageMediumTest {
     TaskResult result = tester
       .newScanTask(new File(projectDir, "sonar-project.properties"))
       .property("sonar.coverageReportPaths", "coverage.xml")
-      .start();
+      .execute();
 
     InputFile noConditions = result.inputFile("xources/hello/NoConditions.xoo");
     assertThat(result.coverageFor(noConditions, 6).getHits()).isTrue();
@@ -99,7 +88,7 @@ public class GenericCoverageMediumTest {
     TaskResult result = tester
       .newScanTask(new File(projectDir, "sonar-project.properties"))
       .property("sonar.coverageReportPaths", "coverage.xml,coverage2.xml")
-      .start();
+      .execute();
 
     InputFile noConditions = result.inputFile("xources/hello/NoConditions.xoo");
     assertThat(result.coverageFor(noConditions, 6).getHits()).isTrue();
index 31d259acd116c48393afc1e981ef6494d81e8210..00c1ca1042a27e309da9335a9e8af371b29ca2fb 100644 (file)
@@ -26,7 +26,6 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 import org.apache.commons.io.FileUtils;
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -65,14 +64,14 @@ public class CpdMediumTest {
 
   private LogOutputRecorder logRecorder = new LogOutputRecorder();
 
-  public ScannerMediumTester tester = ScannerMediumTester.builder()
+  @Rule
+  public ScannerMediumTester tester = new ScannerMediumTester()
     .registerPlugin("xoo", new XooPlugin())
     .addDefaultQProfile("xoo", "Sonar Way")
     .addRules(new XooRulesDefinition())
     // active a rule just to be sure that xoo files are published
     .addActiveRule("xoo", "xoo:OneIssuePerFile", null, "One Issue Per File", null, null, null)
-    .setLogOutput(logRecorder)
-    .build();
+    .setLogOutput(logRecorder);
 
   private File baseDir;
 
@@ -89,7 +88,6 @@ public class CpdMediumTest {
   @Before
   public void prepare() throws IOException {
     logRecorder.getAll().clear();
-    tester.start();
 
     baseDir = temp.getRoot();
 
@@ -105,11 +103,6 @@ public class CpdMediumTest {
     }
   }
 
-  @After
-  public void stop() {
-    tester.stop();
-  }
-
   @Test
   public void testCrossModuleDuplications() throws IOException {
     builder.put("sonar.modules", "module1,module2")
@@ -145,7 +138,7 @@ public class CpdMediumTest {
     File xooFile2 = new File(module2Dir, "sample2.xoo");
     FileUtils.write(xooFile2, duplicatedStuff);
 
-    TaskResult result = tester.newTask().properties(builder.build()).start();
+    TaskResult result = tester.newTask().properties(builder.build()).execute();
 
     assertThat(result.inputFiles()).hasSize(2);
 
@@ -197,7 +190,7 @@ public class CpdMediumTest {
         .put("sonar.cpd.xoo.minimumTokens", "10")
         .put("sonar.verbose", "true")
         .build())
-      .start();
+      .execute();
 
     assertThat(result.inputFiles()).hasSize(2);
 
@@ -251,7 +244,7 @@ public class CpdMediumTest {
         .put("sonar.cpd.xoo.minimumTokens", "10")
         .put("sonar.verbose", "true")
         .build())
-      .start();
+      .execute();
 
     assertThat(result.inputFiles()).hasSize(2);
 
@@ -283,7 +276,7 @@ public class CpdMediumTest {
         .put("sonar.cpd.xoo.minimumTokens", "10")
         .put("sonar.cpd.exclusions", "src/sample1.xoo")
         .build())
-      .start();
+      .execute();
 
     assertThat(result.inputFiles()).hasSize(2);
 
@@ -315,7 +308,7 @@ public class CpdMediumTest {
         .put("sonar.verbose", "true")
         .put("sonar.cpd.cross_project", "true")
         .build())
-      .start();
+      .execute();
 
     InputFile inputFile1 = result.inputFile("src/sample1.xoo");
 
@@ -357,7 +350,7 @@ public class CpdMediumTest {
         .put("sonar.cpd.xoo.minimumLines", "2")
         .put("sonar.verbose", "true")
         .build())
-      .start();
+      .execute();
 
     InputFile inputFile = result.inputFile("src/sample.xoo");
     // One clone group
index 87642aac97fd2ce4f0284f9bb576036607a51bdb..3c0eed0694c23102e9dc214b8549fad8fe05e86e 100644 (file)
@@ -23,8 +23,7 @@ import com.google.common.collect.ImmutableMap;
 import java.io.File;
 import java.io.IOException;
 import org.apache.commons.io.FileUtils;
-import org.junit.After;
-import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.scanner.mediumtest.ScannerMediumTester;
@@ -37,25 +36,15 @@ import static org.assertj.core.groups.Tuple.tuple;
 
 public class DeprecatedApiMediumTest {
 
-  @org.junit.Rule
+  @Rule
   public TemporaryFolder temp = new TemporaryFolder();
 
-  public ScannerMediumTester tester = ScannerMediumTester.builder()
+  @Rule
+  public ScannerMediumTester tester = new ScannerMediumTester()
     .registerPlugin("xoo", new XooPlugin())
     .addRules(new XooRulesDefinition())
     .addDefaultQProfile("xoo", "Sonar Way")
-    .addActiveRule("xoo", "DeprecatedResourceApi", null, "One issue per line", "MAJOR", null, "xoo")
-    .build();
-
-  @Before
-  public void prepare() {
-    tester.start();
-  }
-
-  @After
-  public void stop() {
-    tester.stop();
-  }
+    .addActiveRule("xoo", "DeprecatedResourceApi", null, "One issue per line", "MAJOR", null, "xoo");
 
   @Test
   public void testIssueDetails() throws IOException {
@@ -80,7 +69,7 @@ public class DeprecatedApiMediumTest {
         .put("sonar.projectDescription", "Description of Foo Project")
         .put("sonar.sources", "src")
         .build())
-      .start();
+      .execute();
 
     assertThat(result.issuesFor(result.inputFile("src/sample.xoo"))).extracting("msg", "textRange.startLine").containsOnly(
       tuple("Issue created using deprecated API", 0),
@@ -116,7 +105,7 @@ public class DeprecatedApiMediumTest {
         .put("sonar.projectDescription", "Description of Foo Project")
         .put("sonar.sources", ".")
         .build())
-      .start();
+      .execute();
 
     assertThat(result.issuesFor(result.inputFile("sample.xoo"))).extracting("msg", "textRange.startLine").containsOnly(
       tuple("Issue created using deprecated API", 0),
index 55a3234a5224399414f38ded4bca0c4796f7bc39..765f8729610d8a8e7abcf00c34215314a7064da0 100644 (file)
@@ -29,7 +29,6 @@ import java.nio.file.Paths;
 import java.util.Random;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.StringUtils;
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -57,20 +56,18 @@ public class FileSystemMediumTest {
   public ExpectedException thrown = ExpectedException.none();
 
   private LogOutputRecorder logs = new LogOutputRecorder();
-  private ScannerMediumTester tester;
+
+  @Rule
+  public ScannerMediumTester tester = new ScannerMediumTester()
+    .registerPlugin("xoo", new XooPlugin())
+    .addDefaultQProfile("xoo", "Sonar Way")
+    .setLogOutput(logs);
 
   private File baseDir;
   private ImmutableMap.Builder<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()
@@ -82,15 +79,6 @@ public class FileSystemMediumTest {
       .put("sonar.projectDescription", "Description of Foo Project");
   }
 
-  @After
-  public void stop() {
-    if (tester != null) {
-      tester.stop();
-      tester = null;
-    }
-    logs = new LogOutputRecorder();
-  }
-
   private ImmutableMap.Builder<String, String> createBuilder() {
     return ImmutableMap.<String, String>builder()
       .put("sonar.task", "scan")
@@ -115,7 +103,7 @@ public class FileSystemMediumTest {
       .properties(builder
         .put("sonar.sources", "src")
         .build())
-      .start();
+      .execute();
 
     int ref = result.getReportReader().readMetadata().getRootComponentRef();
     assertThat(result.getReportReader().readComponent(ref).getName()).isEmpty();
@@ -150,7 +138,7 @@ public class FileSystemMediumTest {
       .properties(builder
         .put("sonar.sources", "src")
         .build())
-      .start();
+      .execute();
 
     assertThat(logs.getAllAsString()).contains("Project key: com.foo.project");
     assertThat(logs.getAllAsString()).contains("Organization key: my org");
@@ -171,7 +159,7 @@ public class FileSystemMediumTest {
       .properties(builder
         .put("sonar.sources", "src")
         .build())
-      .start();
+      .execute();
 
     assertThat(logs.getAllAsString()).contains("Project key: com.foo.project");
     assertThat(logs.getAllAsString()).contains("Branch key: my-branch");
@@ -190,7 +178,7 @@ public class FileSystemMediumTest {
       .properties(builder
         .put("sonar.sources", "src")
         .build())
-      .start();
+      .execute();
 
     assertThat(logs.getAllAsString()).contains("Project key: com.foo.project");
     assertThat(logs.getAllAsString()).doesNotContain("Organization key");
@@ -214,7 +202,7 @@ public class FileSystemMediumTest {
       .properties(builder
         .put("sonar.sources", "src")
         .build())
-      .start();
+      .execute();
 
     assertThat(logs.getAllAsString()).contains("2 files indexed");
     assertThat(logs.getAllAsString()).contains("'src/sample.xoo' generated metadata");
@@ -240,7 +228,7 @@ public class FileSystemMediumTest {
       .properties(builder
         .put("sonar.sources", "src")
         .build())
-      .start();
+      .execute();
 
     assertThat(logs.getAllAsString()).contains("2 files indexed");
     assertThat(logs.getAllAsString()).contains("'src/sample.xoo' generated metadata");
@@ -271,7 +259,7 @@ public class FileSystemMediumTest {
         .put("sonar.sources", "src/main")
         .put("sonar.tests", "src/test")
         .build())
-      .start();
+      .execute();
 
     assertThat(logs.getAllAsString()).contains("3 files indexed");
     assertThat(logs.getAllAsString()).contains("'src/main/sample.xoo' generated metadata");
@@ -283,16 +271,9 @@ public class FileSystemMediumTest {
 
   @Test
   public void createIssueOnAnyFile() throws IOException {
-    LogOutputRecorder logs = new LogOutputRecorder();
-    stop();
-    tester = ScannerMediumTester.builder()
-      .registerPlugin("xoo", new XooPlugin())
-      .addDefaultQProfile("xoo", "Sonar Way")
+    tester
       .addRules(new XooRulesDefinition())
-      .setLogOutput(logs)
-      .addActiveRule("xoo", "OneIssuePerUnknownFile", null, "OneIssuePerUnknownFile", "MAJOR", null, "xoo")
-      .build();
-    tester.start();
+      .addActiveRule("xoo", "OneIssuePerUnknownFile", null, "OneIssuePerUnknownFile", "MAJOR", null, "xoo");
 
     builder = createBuilder();
 
@@ -306,7 +287,7 @@ public class FileSystemMediumTest {
       .properties(builder
         .put("sonar.sources", "src")
         .build())
-      .start();
+      .execute();
 
     assertThat(logs.getAllAsString()).contains("1 file indexed");
     assertThat(logs.getAllAsString()).contains("'src/sample.unknown' indexed with language 'null'");
@@ -317,16 +298,9 @@ public class FileSystemMediumTest {
 
   @Test
   public void lazyIssueExclusion() throws IOException {
-    tester.stop();
-    LogOutputRecorder logs = new LogOutputRecorder();
-    tester = ScannerMediumTester.builder()
-      .registerPlugin("xoo", new XooPlugin())
-      .addDefaultQProfile("xoo", "Sonar Way")
+    tester
       .addRules(new XooRulesDefinition())
-      .setLogOutput(logs)
-      .addActiveRule("xoo", "OneIssuePerFile", null, "OneIssuePerFile", "MAJOR", null, "xoo")
-      .build();
-    tester.start();
+      .addActiveRule("xoo", "OneIssuePerFile", null, "OneIssuePerFile", "MAJOR", null, "xoo");
 
     builder = createBuilder();
     builder.put("sonar.issue.ignore.allfile", "1")
@@ -346,7 +320,7 @@ public class FileSystemMediumTest {
       .properties(builder
         .put("sonar.sources", "src")
         .build())
-      .start();
+      .execute();
 
     assertThat(logs.getAllAsString()).containsOnlyOnce("'src/myfile.binary' indexed with language 'null'");
     assertThat(logs.getAllAsString()).doesNotContain("'src/myfile.binary' generating issue exclusions");
@@ -372,7 +346,7 @@ public class FileSystemMediumTest {
       .properties(builder
         .put("sonar.sources", "src")
         .build())
-      .start();
+      .execute();
 
     assertThat(logs.getAllAsString()).containsOnlyOnce("- Exclusion pattern 'pattern'");
     assertThat(logs.getAllAsString()).containsOnlyOnce("'src/myfile.binary' generating issue exclusions");
@@ -380,14 +354,9 @@ public class FileSystemMediumTest {
 
   @Test
   public void publishFilesWithIssues() throws IOException {
-    stop();
-    tester = ScannerMediumTester.builder()
-      .registerPlugin("xoo", new XooPlugin())
-      .addDefaultQProfile("xoo", "Sonar Way")
+    tester
       .addRules(new XooRulesDefinition())
-      .addActiveRule("xoo", "OneIssueOnDirPerFile", null, "OneIssueOnDirPerFile", "MAJOR", null, "xoo")
-      .build();
-    tester.start();
+      .addActiveRule("xoo", "OneIssueOnDirPerFile", null, "OneIssueOnDirPerFile", "MAJOR", null, "xoo");
 
     builder = createBuilder();
 
@@ -401,7 +370,7 @@ public class FileSystemMediumTest {
       .properties(builder
         .put("sonar.sources", "src")
         .build())
-      .start();
+      .execute();
 
     DefaultInputFile file = (DefaultInputFile) result.inputFile("src/sample.xoo");
     InputDir dir = result.inputDir("src");
@@ -413,14 +382,9 @@ public class FileSystemMediumTest {
 
   @Test
   public void publishDirsWithIssues() throws IOException {
-    stop();
-    tester = ScannerMediumTester.builder()
-      .registerPlugin("xoo", new XooPlugin())
-      .addDefaultQProfile("xoo", "Sonar Way")
+    tester
       .addRules(new XooRulesDefinition())
-      .addActiveRule("xoo", "OneIssuePerDirectory", null, "OneIssuePerDirectory", "MAJOR", null, "xoo")
-      .build();
-    tester.start();
+      .addActiveRule("xoo", "OneIssuePerDirectory", null, "OneIssuePerDirectory", "MAJOR", null, "xoo");
 
     builder = ImmutableMap.<String, String>builder()
       .put("sonar.task", "scan")
@@ -442,7 +406,7 @@ public class FileSystemMediumTest {
       .properties(builder
         .put("sonar.sources", "src")
         .build())
-      .start();
+      .execute();
 
     DefaultInputFile unknownInputFile = (DefaultInputFile) result.inputFile("src/unknown/file.notanalyzed");
     InputDir unknownInputDir = result.inputDir("src/unknown");
@@ -470,7 +434,7 @@ public class FileSystemMediumTest {
       .properties(builder
         .put("sonar.sources", "src")
         .build())
-      .start();
+      .execute();
 
     assertThat(result.inputFiles()).hasSize(1);
     assertThat(result.inputDirs()).hasSize(1);
@@ -495,7 +459,7 @@ public class FileSystemMediumTest {
       .properties(builder
         .put("sonar.sources", "src")
         .build())
-      .start();
+      .execute();
 
     assertThat(result.inputFiles()).hasSize(100);
     assertThat(result.inputDirs()).hasSize(1);
@@ -514,7 +478,7 @@ public class FileSystemMediumTest {
         .put("sonar.sources", "")
         .put("sonar.tests", "test")
         .build())
-      .start();
+      .execute();
 
     assertThat(result.inputFiles()).hasSize(1);
     assertThat(result.inputFile("test/sampleTest.xoo").type()).isEqualTo(InputFile.Type.TEST);
@@ -548,7 +512,7 @@ public class FileSystemMediumTest {
         .put("sonar.sources", "src,another.xoo")
         .put("sonar.tests", "test,sampleTest2.xoo")
         .build())
-      .start();
+      .execute();
 
     assertThat(result.inputFiles()).hasSize(4);
     assertThat(result.inputDirs()).hasSize(3);
@@ -583,7 +547,7 @@ public class FileSystemMediumTest {
         .put("sonar.test.inclusions", "**/sampleTest*.*")
         .put("sonar.test.exclusions", "**/sampleTest2.xoo")
         .build())
-      .start();
+      .execute();
 
     assertThat(result.inputFiles()).hasSize(2);
   }
@@ -602,7 +566,7 @@ public class FileSystemMediumTest {
       .properties(builder
         .put("sonar.sources", "src,src/sample.xoo")
         .build())
-      .start();
+      .execute();
 
   }
 
@@ -613,7 +577,7 @@ public class FileSystemMediumTest {
       File projectDir = new File("src/test/resources/mediumtest/xoo/sample-with-symlink");
       TaskResult result = tester
         .newScanTask(new File(projectDir, "sonar-project.properties"))
-        .start();
+        .execute();
 
       assertThat(result.inputFiles()).hasSize(3);
       // check that symlink was not resolved to target
@@ -630,7 +594,7 @@ public class FileSystemMediumTest {
         .newScanTask(new File(projectDir, "sonar-project.properties"))
         .property("sonar.sources", "XOURCES")
         .property("sonar.tests", "TESTX")
-        .start();
+        .execute();
 
       assertThat(result.inputFiles()).hasSize(3);
       assertThat(result.inputFiles()).extractingResultOf("relativePath").containsOnly(
@@ -655,7 +619,7 @@ public class FileSystemMediumTest {
       .properties(builder
         .put("sonar.sources", "src")
         .build())
-      .start();
+      .execute();
 
     assertThat(result.inputFiles()).hasSize(2);
     assertThat(result.inputFile("src/sample.other").type()).isEqualTo(InputFile.Type.MAIN);
@@ -668,7 +632,7 @@ public class FileSystemMediumTest {
     File projectDir = new File("src/test/resources/mediumtest/xoo/multi-modules-sample");
     TaskResult result = tester
       .newScanTask(new File(projectDir, "sonar-project.properties"))
-      .start();
+      .execute();
 
     System.out.println(logs.getAsString());
     assertThat(result.inputFiles()).hasSize(4);
@@ -700,7 +664,7 @@ public class FileSystemMediumTest {
         .put("sonar.sources", "src,\"another,2.xoo\"")
         .put("sonar.tests", "\"test\",\"sampleTest,2.xoo\"")
         .build())
-      .start();
+      .execute();
 
     assertThat(result.inputFiles()).hasSize(4);
     assertThat(result.inputDirs()).hasSize(3);
index 721e4a7af6b52735ce18a29ab252334e5f2894ce..320e80369138335bdc1d866b013d1c3e8344411d 100644 (file)
@@ -22,8 +22,6 @@ package org.sonar.scanner.mediumtest.fs;
 import java.io.File;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.filefilter.FileFilterUtils;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -38,19 +36,9 @@ public class NoLanguagesPluginsMediumTest {
   @Rule
   public ExpectedException exception = ExpectedException.none();
 
-  public ScannerMediumTester tester = ScannerMediumTester.builder()
-    .setPreviousAnalysisDate(null)
-    .build();
-
-  @Before
-  public void prepare() {
-    tester.start();
-  }
-
-  @After
-  public void stop() {
-    tester.stop();
-  }
+  @Rule
+  public ScannerMediumTester tester = new ScannerMediumTester()
+    .setPreviousAnalysisDate(null);
 
   @Test
   public void testNoLanguagePluginsInstalled() throws Exception {
@@ -61,7 +49,7 @@ public class NoLanguagesPluginsMediumTest {
 
     tester
       .newScanTask(new File(projectDir, "sonar-project.properties"))
-      .start();
+      .execute();
   }
 
   private File copyProject(String path) throws Exception {
index ea16deec3cc51c103ec3d9030ea104d35d8e7a6f..35eab16b110adedb2c1cc1ea5eec88d2b252e166 100644 (file)
@@ -27,8 +27,6 @@ import java.util.List;
 import org.apache.commons.io.FileUtils;
 import org.hamcrest.BaseMatcher;
 import org.hamcrest.Description;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -57,18 +55,13 @@ public class ProjectBuilderMediumTest {
 
   private ProjectBuilder projectBuilder = mock(ProjectBuilder.class);
 
-  public ScannerMediumTester tester = ScannerMediumTester.builder()
+  @Rule
+  public ScannerMediumTester tester = new ScannerMediumTester()
     .registerPlugin("xoo", new XooPluginWithBuilder(projectBuilder))
     .addRules(new XooRulesDefinition())
     .addDefaultQProfile("xoo", "Sonar Way")
     .setPreviousAnalysisDate(new Date())
-    .addActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", "OneIssuePerLine.internal", "xoo")
-    .build();
-
-  @Before
-  public void prepare() {
-    tester.start();
-  }
+    .addActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", "OneIssuePerLine.internal", "xoo");
 
   private class XooPluginWithBuilder extends XooPlugin {
     private ProjectBuilder builder;
@@ -84,11 +77,6 @@ public class ProjectBuilderMediumTest {
     }
   }
 
-  @After
-  public void stop() {
-    tester.stop();
-  }
-
   @Test
   public void testProjectReactorValidation() throws IOException {
     File baseDir = prepareProject();
@@ -123,7 +111,7 @@ public class ProjectBuilderMediumTest {
         .put("sonar.sources", ".")
         .put("sonar.xoo.enableProjectBuilder", "true")
         .build())
-      .start();
+      .execute();
 
   }
 
@@ -143,7 +131,7 @@ public class ProjectBuilderMediumTest {
         .put("sonar.verbose", "true")
         .put("sonar.xoo.enableProjectBuilder", "true")
         .build())
-      .start();
+      .execute();
     List<Issue> issues = result.issuesFor(result.inputFile("src/sample.xoo"));
     assertThat(issues).hasSize(10);
 
@@ -172,7 +160,7 @@ public class ProjectBuilderMediumTest {
         .put("sonar.sources", ".")
         .put("sonar.xoo.enableProjectBuilder", "true")
         .build())
-      .start();
+      .execute();
   }
 
   @Test
@@ -191,7 +179,7 @@ public class ProjectBuilderMediumTest {
         .put("sonar.sources", ".")
         .put("sonar.xoo.enableProjectBuilder", "true")
         .build())
-      .start();
+      .execute();
 
     List<Issue> issues = result.issuesFor(result.inputFile("src/sample.xoo"));
     assertThat(issues).hasSize(10);
index 83cb44284f3fc167884271b5e648b72f03aa96bc..1b642997376463cf9a311db56e74c374542d8396 100644 (file)
@@ -25,8 +25,6 @@ import java.io.IOException;
 import org.apache.commons.io.FileUtils;
 import org.hamcrest.Description;
 import org.hamcrest.TypeSafeMatcher;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -47,20 +45,10 @@ public class HighlightingMediumTest {
   @Rule
   public ExpectedException exception = ExpectedException.none();
 
-  public ScannerMediumTester tester = ScannerMediumTester.builder()
+  @Rule
+  public ScannerMediumTester tester = new ScannerMediumTester()
     .registerPlugin("xoo", new XooPlugin())
-    .addDefaultQProfile("xoo", "Sonar Way")
-    .build();
-
-  @Before
-  public void prepare() {
-    tester.start();
-  }
-
-  @After
-  public void stop() {
-    tester.stop();
-  }
+    .addDefaultQProfile("xoo", "Sonar Way");
 
   @Test
   public void computeSyntaxHighlightingOnTempProject() throws IOException {
@@ -83,7 +71,7 @@ public class HighlightingMediumTest {
         .put("sonar.projectDescription", "Description of Foo Project")
         .put("sonar.sources", "src")
         .build())
-      .start();
+      .execute();
 
     InputFile file = result.inputFile("src/sample.xoo");
     assertThat(result.highlightingTypeFor(file, 1, 0)).containsExactly(TypeOfText.STRING);
@@ -113,7 +101,7 @@ public class HighlightingMediumTest {
         .put("sonar.sources", "src")
         .put("sonar.it.savedatatwice", "true")
         .build())
-      .start();
+      .execute();
 
   }
 
@@ -152,7 +140,7 @@ public class HighlightingMediumTest {
         .put("sonar.projectDescription", "Description of Foo Project")
         .put("sonar.sources", "src")
         .build())
-      .start();
+      .execute();
   }
 
 }
index 2f88872bf3bca632434b1ad5113ccaa8561f6e7f..9b539a27687d217a3d68e90989e61223234c7616 100644 (file)
@@ -27,8 +27,7 @@ import java.util.List;
 import java.util.Map;
 import javax.annotation.Nullable;
 import org.apache.commons.io.FileUtils;
-import org.junit.After;
-import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.rule.RuleKey;
@@ -47,25 +46,15 @@ public class ChecksMediumTest {
   @org.junit.Rule
   public TemporaryFolder temp = new TemporaryFolder();
 
-  public ScannerMediumTester tester = ScannerMediumTester.builder()
+  @Rule
+  public ScannerMediumTester tester = new ScannerMediumTester()
     .registerPlugin("xoo", new XooPlugin())
     .addRules(new XooRulesDefinition())
     .addDefaultQProfile("xoo", "Sonar Way")
     .addRule("TemplateRule_1234", "xoo", "TemplateRule_1234", "A template rule")
     .addRule("TemplateRule_1235", "xoo", "TemplateRule_1235", "Another template rule")
     .activateRule(createActiveRuleWithParam("xoo", "TemplateRule_1234", "TemplateRule", "A template rule", "MAJOR", null, "xoo", "line", "1"))
-    .activateRule(createActiveRuleWithParam("xoo", "TemplateRule_1235", "TemplateRule", "Another template rule", "MAJOR", null, "xoo", "line", "2"))
-    .build();
-
-  @Before
-  public void prepare() {
-    tester.start();
-  }
-
-  @After
-  public void stop() {
-    tester.stop();
-  }
+    .activateRule(createActiveRuleWithParam("xoo", "TemplateRule_1235", "TemplateRule", "Another template rule", "MAJOR", null, "xoo", "line", "2"));
 
   @Test
   public void testCheckWithTemplate() throws IOException {
@@ -87,7 +76,7 @@ public class ChecksMediumTest {
         .put("sonar.projectDescription", "Description of Foo Project")
         .put("sonar.sources", "src")
         .build())
-      .start();
+      .execute();
 
     List<Issue> issues = result.issuesFor(result.inputFile("src/sample.xoo"));
     assertThat(issues)
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesIssuesModeMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesIssuesModeMediumTest.java
deleted file mode 100644 (file)
index 7eb43a3..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.scanner.mediumtest.issues;
-
-import com.google.common.collect.ImmutableMap;
-import java.io.File;
-import java.util.Date;
-import java.util.LinkedList;
-import java.util.List;
-import org.apache.commons.io.FileUtils;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.sonar.api.CoreProperties;
-import org.sonar.batch.bootstrapper.IssueListener;
-import org.sonar.scanner.mediumtest.ScannerMediumTester;
-import org.sonar.scanner.mediumtest.TaskResult;
-import org.sonar.xoo.XooPlugin;
-import org.sonar.xoo.rule.XooRulesDefinition;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class IssuesIssuesModeMediumTest {
-  @org.junit.Rule
-  public TemporaryFolder temp = new TemporaryFolder();
-
-  public ScannerMediumTester testerPreview = ScannerMediumTester.builder()
-    .registerPlugin("xoo", new XooPlugin())
-    .addDefaultQProfile("xoo", "Sonar Way")
-    .addRules(new XooRulesDefinition())
-    .bootstrapProperties(ImmutableMap.of(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES))
-    .addActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", "OneIssuePerLine.internal", "xoo")
-    .setLastBuildDate(new Date())
-    .build();
-
-  @Before
-  public void prepare() {
-    testerPreview.start();
-  }
-
-  @After
-  public void stop() {
-    testerPreview.stop();
-  }
-
-  @Test
-  public void testIssueCallback() throws Exception {
-    File projectDir = new File(IssuesMediumTest.class.getResource("/mediumtest/xoo/sample").toURI());
-    File tmpDir = temp.getRoot();
-    FileUtils.copyDirectory(projectDir, tmpDir);
-    IssueRecorder issueListener = new IssueRecorder();
-
-    TaskResult result1 = testerPreview
-      .newScanTask(new File(tmpDir, "sonar-project.properties"))
-      .setIssueListener(issueListener)
-      .property(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES)
-      .start();
-
-    assertThat(result1.trackedIssues()).hasSize(14);
-    assertThat(issueListener.issueList).hasSize(14);
-    issueListener = new IssueRecorder();
-
-    TaskResult result2 = testerPreview
-      .newScanTask(new File(tmpDir, "sonar-project.properties"))
-      .setIssueListener(issueListener)
-      .property(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES)
-      .start();
-
-    assertThat(result2.trackedIssues()).hasSize(14);
-    assertThat(issueListener.issueList).hasSize(14);
-  }
-
-  private class IssueRecorder implements IssueListener {
-    List<Issue> issueList = new LinkedList<>();
-
-    @Override
-    public void handle(Issue issue) {
-      issueList.add(issue);
-    }
-  }
-}
index 1b700a513e4b6023410e539b967c9f703f5b5786..2330712466ed5c873b4e2e04ce782befc5f2e04e 100644 (file)
@@ -22,14 +22,11 @@ package org.sonar.scanner.mediumtest.issues;
 import com.google.common.collect.ImmutableMap;
 import java.io.File;
 import java.io.IOException;
-import java.util.LinkedList;
 import java.util.List;
 import org.apache.commons.io.FileUtils;
-import org.junit.After;
-import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
-import org.sonar.batch.bootstrapper.IssueListener;
 import org.sonar.scanner.mediumtest.ScannerMediumTester;
 import org.sonar.scanner.mediumtest.TaskResult;
 import org.sonar.scanner.protocol.output.ScannerReport.Issue;
@@ -44,38 +41,12 @@ public class IssuesMediumTest {
   @org.junit.Rule
   public TemporaryFolder temp = new TemporaryFolder();
 
-  public ScannerMediumTester tester = ScannerMediumTester.builder()
+  @Rule
+  public ScannerMediumTester tester = new ScannerMediumTester()
     .registerPlugin("xoo", new XooPlugin())
     .addDefaultQProfile("xoo", "Sonar Way")
     .addRules(new XooRulesDefinition())
-    .addActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", "OneIssuePerLine.internal", "xoo")
-    .build();
-
-  @Before
-  public void prepare() {
-    tester.start();
-  }
-
-  @After
-  public void stop() {
-    tester.stop();
-  }
-
-  @Test
-  public void testNoIssueCallbackInNonPreview() throws Exception {
-    File projectDir = new File(IssuesMediumTest.class.getResource("/mediumtest/xoo/sample").toURI());
-    File tmpDir = temp.getRoot();
-    FileUtils.copyDirectory(projectDir, tmpDir);
-    IssueRecorder issueListener = new IssueRecorder();
-
-    TaskResult result = tester
-      .newScanTask(new File(tmpDir, "sonar-project.properties"))
-      .setIssueListener(issueListener)
-      .start();
-
-    assertThat(result.issuesFor(result.inputFile("xources/hello/HelloJava.xoo"))).hasSize(8);
-    assertThat(issueListener.issueList).hasSize(0);
-  }
+    .addActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", "OneIssuePerLine.internal", "xoo");
 
   @Test
   public void testOneIssuePerLine() throws Exception {
@@ -85,7 +56,7 @@ public class IssuesMediumTest {
 
     TaskResult result = tester
       .newScanTask(new File(tmpDir, "sonar-project.properties"))
-      .start();
+      .execute();
 
     List<Issue> issues = result.issuesFor(result.inputFile("xources/hello/HelloJava.xoo"));
     assertThat(issues).hasSize(8 /* lines */);
@@ -103,7 +74,7 @@ public class IssuesMediumTest {
     TaskResult result = tester
       .newScanTask(new File(tmpDir, "sonar-project.properties"))
       .property("sonar.xoo.internalKey", "OneIssuePerLine.internal")
-      .start();
+      .execute();
 
     List<Issue> issues = result.issuesFor(result.inputFile("xources/hello/HelloJava.xoo"));
     assertThat(issues).hasSize(8 /* lines */ + 1 /* file */);
@@ -118,7 +89,7 @@ public class IssuesMediumTest {
     TaskResult result = tester
       .newScanTask(new File(tmpDir, "sonar-project.properties"))
       .property("sonar.oneIssuePerLine.forceSeverity", "CRITICAL")
-      .start();
+      .execute();
 
     List<Issue> issues = result.issuesFor(result.inputFile("xources/hello/HelloJava.xoo"));
     assertThat(issues.get(0).getSeverity()).isEqualTo(org.sonar.scanner.protocol.Constants.Severity.CRITICAL);
@@ -134,7 +105,7 @@ public class IssuesMediumTest {
       .newScanTask(new File(tmpDir, "sonar-project.properties"))
       .property("sonar.issue.ignore.allfile", "1")
       .property("sonar.issue.ignore.allfile.1.fileRegexp", "object")
-      .start();
+      .execute();
 
     assertThat(result.issuesFor(result.inputFile("xources/hello/HelloJava.xoo"))).hasSize(8 /* lines */);
     assertThat(result.issuesFor(result.inputFile("xources/hello/helloscala.xoo"))).isEmpty();
@@ -160,7 +131,7 @@ public class IssuesMediumTest {
         .put("sonar.projectDescription", "Description of Foo Project")
         .put("sonar.sources", "src")
         .build())
-      .start();
+      .execute();
 
     List<Issue> issues = result.issuesFor(result.inputFile("src/sample.xoo"));
     assertThat(issues).hasSize(10);
@@ -169,12 +140,4 @@ public class IssuesMediumTest {
       .contains(tuple("This issue is generated on each line", 1, 0.0));
   }
 
-  private class IssueRecorder implements IssueListener {
-    List<Issue> issueList = new LinkedList<>();
-
-    @Override
-    public void handle(Issue issue) {
-      issueList.add(issue);
-    }
-  }
 }
index e5526aec1849fab88eb7b9e430c30346d5f35d39..6df04f0badae114d93e23f90724dc2a145e38684 100644 (file)
@@ -23,8 +23,7 @@ import com.google.common.collect.ImmutableMap;
 import java.io.File;
 import java.io.IOException;
 import org.apache.commons.io.FileUtils;
-import org.junit.After;
-import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.scanner.mediumtest.ScannerMediumTester;
@@ -36,25 +35,15 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 public class IssuesOnDirMediumTest {
 
-  @org.junit.Rule
+  @Rule
   public TemporaryFolder temp = new TemporaryFolder();
 
-  public ScannerMediumTester tester = ScannerMediumTester.builder()
+  @Rule
+  public ScannerMediumTester tester = new ScannerMediumTester()
     .registerPlugin("xoo", new XooPlugin())
     .addDefaultQProfile("xoo", "Sonar Way")
     .addRules(new XooRulesDefinition())
-    .addActiveRule("xoo", "OneIssueOnDirPerFile", null, "One issue per line", "MINOR", "xoo", "xoo")
-    .build();
-
-  @Before
-  public void prepare() {
-    tester.start();
-  }
-
-  @After
-  public void stop() {
-    tester.stop();
-  }
+    .addActiveRule("xoo", "OneIssueOnDirPerFile", null, "One issue per line", "MINOR", "xoo", "xoo");
 
   @Test
   public void scanTempProject() throws IOException {
@@ -79,7 +68,7 @@ public class IssuesOnDirMediumTest {
         .put("sonar.projectDescription", "Description of Foo Project")
         .put("sonar.sources", "src")
         .build())
-      .start();
+      .execute();
 
     assertThat(result.issuesFor(result.inputDir("src"))).hasSize(2);
   }
@@ -105,7 +94,7 @@ public class IssuesOnDirMediumTest {
         .put("sonar.projectDescription", "Description of Foo Project")
         .put("sonar.sources", ".")
         .build())
-      .start();
+      .execute();
 
     assertThat(result.issuesFor(result.inputDir(""))).hasSize(2);
   }
index eeb92c59d4a6e729e04e94c5a22130e042f5d4c9..748d2537df1b3bd4dd958a2dc6929e6dd6f4a3a0 100644 (file)
@@ -23,8 +23,7 @@ import com.google.common.collect.ImmutableMap;
 import java.io.File;
 import java.io.IOException;
 import org.apache.commons.io.FileUtils;
-import org.junit.After;
-import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.scanner.mediumtest.ScannerMediumTester;
@@ -36,25 +35,15 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 public class IssuesOnModuleMediumTest {
 
-  @org.junit.Rule
+  @Rule
   public TemporaryFolder temp = new TemporaryFolder();
 
-  public ScannerMediumTester tester = ScannerMediumTester.builder()
+  @Rule
+  public ScannerMediumTester tester = new ScannerMediumTester()
     .registerPlugin("xoo", new XooPlugin())
     .addDefaultQProfile("xoo", "Sonar Way")
     .addRules(new XooRulesDefinition())
-    .addActiveRule("xoo", "OneIssuePerModule", null, "One issue per module", "MINOR", "xoo", "xoo")
-    .build();
-
-  @Before
-  public void prepare() {
-    tester.start();
-  }
-
-  @After
-  public void stop() {
-    tester.stop();
-  }
+    .addActiveRule("xoo", "OneIssuePerModule", null, "One issue per module", "MINOR", "xoo", "xoo");
 
   @Test
   public void scanTempProject() throws IOException {
@@ -76,7 +65,7 @@ public class IssuesOnModuleMediumTest {
         .put("sonar.projectDescription", "Description of Foo Project")
         .put("sonar.sources", "src")
         .build())
-      .start();
+      .execute();
 
     assertThat(result.issuesFor(result.getReportComponent("com.foo.project"))).hasSize(1);
   }
index 644599bc0dd3613a08e9016873900e27c46dc564..e5a4124b9dcfca0960f467b6a3f909f9dabd835a 100644 (file)
@@ -22,8 +22,8 @@ package org.sonar.scanner.mediumtest.issues;
 import java.io.File;
 import java.util.List;
 import org.apache.commons.io.FileUtils;
-import org.junit.After;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.scanner.mediumtest.ScannerMediumTester;
@@ -38,34 +38,27 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 public class MultilineIssuesMediumTest {
 
-  @org.junit.Rule
+  @Rule
   public TemporaryFolder temp = new TemporaryFolder();
 
-  public ScannerMediumTester tester = ScannerMediumTester.builder()
+  @Rule
+  public ScannerMediumTester tester = new ScannerMediumTester()
     .registerPlugin("xoo", new XooPlugin())
     .addRules(new XooRulesDefinition())
     .addDefaultQProfile("xoo", "Sonar Way")
-    .addActiveRule("xoo", "MultilineIssue", null, "Multinile Issue", "MAJOR", null, "xoo")
-    .build();
+    .addActiveRule("xoo", "MultilineIssue", null, "Multinile Issue", "MAJOR", null, "xoo");
 
   private TaskResult result;
 
   @Before
   public void prepare() throws Exception {
-    tester.start();
-
     File projectDir = new File(MultilineIssuesMediumTest.class.getResource("/mediumtest/xoo/sample-multiline").toURI());
     File tmpDir = temp.getRoot();
     FileUtils.copyDirectory(projectDir, tmpDir);
 
     result = tester
       .newScanTask(new File(tmpDir, "sonar-project.properties"))
-      .start();
-  }
-
-  @After
-  public void stop() {
-    tester.stop();
+      .execute();
   }
 
   @Test
index 84434b7f8cb6879267c02f3c0e4afb6b26606491..36120bd1d52796c37b7160877a55b2364cd458b9 100644 (file)
@@ -24,8 +24,6 @@ import java.io.File;
 import java.util.Date;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.filefilter.FileFilterUtils;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
@@ -47,24 +45,14 @@ public class EmptyFileTest {
   @Rule
   public LogTester logTester = new LogTester();
 
-  public ScannerMediumTester tester = ScannerMediumTester.builder()
+  @Rule
+  public ScannerMediumTester tester = new ScannerMediumTester()
     .bootstrapProperties(ImmutableMap.of(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES))
     .registerPlugin("xoo", new XooPlugin())
     .addRules(new XooRulesDefinition())
     .addDefaultQProfile("xoo", "Sonar Way")
     .addActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", "my/internal/key", "xoo")
-    .setPreviousAnalysisDate(new Date())
-    .build();
-
-  @Before
-  public void prepare() {
-    tester.start();
-  }
-
-  @After
-  public void stop() {
-    tester.stop();
-  }
+    .setPreviousAnalysisDate(new Date());
 
   @Test
   public void testIssueTrackingWithIssueOnEmptyFile() throws Exception {
@@ -73,12 +61,12 @@ public class EmptyFileTest {
     TaskResult result = tester
       .newScanTask(new File(projectDir, "sonar-project.properties"))
       .property("sonar.xoo.internalKey", "my/internal/key")
-      .start();
+      .execute();
 
-    for(TrackedIssue i : result.trackedIssues()) {
+    for (TrackedIssue i : result.trackedIssues()) {
       System.out.println(i.startLine() + " " + i.getMessage());
     }
-    
+
     assertThat(result.trackedIssues()).hasSize(11);
   }
 
index 6eb4283c0cf305925d72657c67415d556ae86b8e..65e705a838c1bf43626cf1748740342782256200 100644 (file)
@@ -25,21 +25,17 @@ import java.io.IOException;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
-import java.util.LinkedList;
-import java.util.List;
 import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.filefilter.FileFilterUtils;
 import org.apache.commons.lang.StringUtils;
 import org.assertj.core.api.Condition;
-import org.junit.After;
-import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.CoreProperties;
 import org.sonar.api.utils.log.LogTester;
 import org.sonar.api.utils.log.LoggerLevel;
-import org.sonar.batch.bootstrapper.IssueListener;
 import org.sonar.scanner.issue.tracking.TrackedIssue;
 import org.sonar.scanner.mediumtest.ScannerMediumTester;
 import org.sonar.scanner.mediumtest.TaskResult;
@@ -69,7 +65,8 @@ public class IssueModeAndReportsMediumTest {
     }
   }
 
-  public ScannerMediumTester tester = ScannerMediumTester.builder()
+  @Rule
+  public ScannerMediumTester tester = new ScannerMediumTester()
     .bootstrapProperties(ImmutableMap.of(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES))
     .registerPlugin("xoo", new XooPlugin())
     .addDefaultQProfile("xoo", "Sonar Way")
@@ -110,18 +107,7 @@ public class IssueModeAndReportsMediumTest {
       .setSeverity(Severity.CRITICAL)
       .setCreationDate(date("14/03/2004"))
       .setStatus("OPEN")
-      .build())
-    .build();
-
-  @Before
-  public void prepare() {
-    tester.start();
-  }
-
-  @After
-  public void stop() {
-    tester.stop();
-  }
+      .build());
 
   private File copyProject(String path) throws Exception {
     File projectDir = temp.newFolder();
@@ -136,7 +122,7 @@ public class IssueModeAndReportsMediumTest {
 
     TaskResult result = tester
       .newScanTask(new File(projectDir, "sonar-project.properties"))
-      .start();
+      .execute();
 
     int newIssues = 0;
     int openIssues = 0;
@@ -157,10 +143,10 @@ public class IssueModeAndReportsMediumTest {
     assertThat(newIssues).isEqualTo(16);
     assertThat(openIssues).isEqualTo(2);
     assertThat(resolvedIssue).isEqualTo(1);
-    
+
     // progress report
     String logs = StringUtils.join(logTester.logs(LoggerLevel.INFO), "\n");
-    
+
     assertThat(logs).contains("Performing issue tracking");
     assertThat(logs).contains("6/6 components tracked");
 
@@ -183,7 +169,7 @@ public class IssueModeAndReportsMediumTest {
     tester
       .newScanTask(new File(projectDir, "sonar-project.properties"))
       .property("sonar.issuesReport.console.enable", "true")
-      .start();
+      .execute();
 
     assertThat(getReportLog()).contains("+16 issues", "+16 major");
   }
@@ -195,7 +181,7 @@ public class IssueModeAndReportsMediumTest {
     tester
       .newScanTask(new File(projectDir, "sonar-project.properties"))
       .property("sonar.xoo.enablePostJob", "true")
-      .start();
+      .execute();
 
     assertThat(logTester.logs()).contains("Resolved issues: 1", "Open issues: 18");
   }
@@ -216,7 +202,7 @@ public class IssueModeAndReportsMediumTest {
     tester
       .newScanTask(new File(projectDir, "sonar-project.properties"))
       .property("sonar.issuesReport.html.enable", "true")
-      .start();
+      .execute();
 
     assertThat(new File(projectDir, ".sonar/issues-report/issues-report.html")).exists();
     assertThat(new File(projectDir, ".sonar/issues-report/issues-report-light.html")).exists();
@@ -239,36 +225,12 @@ public class IssueModeAndReportsMediumTest {
         .put("sonar.sources", "src")
         .put("sonar.issuesReport.html.enable", "true")
         .build())
-      .start();
+      .execute();
 
     assertThat(FileUtils.readFileToString(new File(baseDir, ".sonar/issues-report/issues-report.html"))).contains("No file analyzed");
     assertThat(FileUtils.readFileToString(new File(baseDir, ".sonar/issues-report/issues-report-light.html"))).contains("No file analyzed");
   }
 
-  @Test
-  public void testIssueCallback() throws Exception {
-    File projectDir = copyProject("/mediumtest/xoo/sample");
-    IssueRecorder issueListener = new IssueRecorder();
-
-    TaskResult result = tester
-      .newScanTask(new File(projectDir, "sonar-project.properties"))
-      .setIssueListener(issueListener)
-      .property("sonar.verbose", "true")
-      .start();
-
-    assertThat(result.trackedIssues()).hasSize(19);
-    assertThat(issueListener.issueList).hasSize(19);
-  }
-
-  private class IssueRecorder implements IssueListener {
-    List<Issue> issueList = new LinkedList<>();
-
-    @Override
-    public void handle(Issue issue) {
-      issueList.add(issue);
-    }
-  }
-
   @Test
   public void noSyntaxHighlightingInIssuesMode() throws IOException {
 
@@ -290,7 +252,7 @@ public class IssueModeAndReportsMediumTest {
         .put("sonar.projectDescription", "Description of Foo Project")
         .put("sonar.sources", "src")
         .build())
-      .start();
+      .execute();
 
     assertThat(result.getReportReader().hasSyntaxHighlighting(1)).isFalse();
     assertThat(result.getReportReader().hasSyntaxHighlighting(2)).isFalse();
index 4a81c797e21225056b68034c55cd00c595179ac2..49e258338543f73c620ae0848dc66fc5c7e113cc 100644 (file)
@@ -23,8 +23,6 @@ import com.google.common.collect.ImmutableMap;
 import java.io.File;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.filefilter.FileFilterUtils;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
@@ -44,24 +42,14 @@ public class NoPreviousAnalysisTest {
   @Rule
   public LogTester logTester = new LogTester();
 
-  public ScannerMediumTester tester = ScannerMediumTester.builder()
+  @Rule
+  public ScannerMediumTester tester = new ScannerMediumTester()
     .bootstrapProperties(ImmutableMap.of(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES))
     .registerPlugin("xoo", new XooPlugin())
     .addRules(new XooRulesDefinition())
     .addDefaultQProfile("xoo", "Sonar Way")
     .addActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", "my/internal/key", "xoo")
-    .setPreviousAnalysisDate(null)
-    .build();
-
-  @Before
-  public void prepare() {
-    tester.start();
-  }
-
-  @After
-  public void stop() {
-    tester.stop();
-  }
+    .setPreviousAnalysisDate(null);
 
   @Test
   public void testIssueTrackingWithIssueOnEmptyFile() throws Exception {
@@ -69,12 +57,12 @@ public class NoPreviousAnalysisTest {
 
     TaskResult result = tester
       .newScanTask(new File(projectDir, "sonar-project.properties"))
-      .start();
-    
+      .execute();
+
     assertThat(result.trackedIssues()).hasSize(14);
-    
+
   }
-  
+
   private File copyProject(String path) throws Exception {
     File projectDir = temp.newFolder();
     File originalProjectDir = new File(IssueModeAndReportsMediumTest.class.getResource(path).toURI());
index c0043f1ef24d1ddb52d2f95c1d77edb5775090e6..a4ae9502a24363a6be184b69e3f933229312ff0b 100644 (file)
@@ -37,7 +37,6 @@ import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.filefilter.FileFilterUtils;
 import org.assertj.core.api.Condition;
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -87,7 +86,15 @@ public class ScanOnlyChangedTest {
   @Rule
   public LogTester logTester = new LogTester();
 
-  private ScannerMediumTester tester;
+  @Rule
+  public ScannerMediumTester tester = new ScannerMediumTester()
+    .bootstrapProperties(ImmutableMap.of(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES))
+    .registerPlugin("xoo", new XooPlugin())
+    .addDefaultQProfile("xoo", "Sonar Way")
+    .addRules(new XooRulesDefinition())
+    .addActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", null, "xoo")
+    .addActiveRule("xoo", "OneIssueOnDirPerFile", null, "OneIssueOnDirPerFile", "MAJOR", null, "xoo")
+    .addActiveRule("xoo", "OneIssuePerModule", null, "OneIssuePerModule", "MAJOR", null, "xoo");
 
   @Before
   public void prepare() throws IOException, URISyntaxException {
@@ -97,14 +104,7 @@ public class ScanOnlyChangedTest {
       .readMetadata(Files.newInputStream(path), StandardCharsets.UTF_8, filePath)
       .hash();
 
-    tester = ScannerMediumTester.builder()
-      .bootstrapProperties(ImmutableMap.of(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES))
-      .registerPlugin("xoo", new XooPlugin())
-      .addDefaultQProfile("xoo", "Sonar Way")
-      .addRules(new XooRulesDefinition())
-      .addActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", null, "xoo")
-      .addActiveRule("xoo", "OneIssueOnDirPerFile", null, "OneIssueOnDirPerFile", "MAJOR", null, "xoo")
-      .addActiveRule("xoo", "OneIssuePerModule", null, "OneIssuePerModule", "MAJOR", null, "xoo")
+    tester
       // this will cause the file to have status==SAME
       .addFileData(projectKey, filePath, new FileData(md5sum, null))
       .setPreviousAnalysisDate(new Date())
@@ -129,14 +129,7 @@ public class ScanOnlyChangedTest {
         .setSeverity(Severity.CRITICAL)
         .setCreationDate(date("14/03/2004"))
         .setStatus("OPEN")
-        .build())
-      .build();
-    tester.start();
-  }
-
-  @After
-  public void stop() {
-    tester.stop();
+        .build());
   }
 
   private File copyProject(String path) throws Exception {
@@ -159,7 +152,7 @@ public class ScanOnlyChangedTest {
       taskBuilder.property("sonar.projectKey", projectKey);
     }
 
-    TaskResult result = taskBuilder.start();
+    TaskResult result = taskBuilder.execute();
     /*
      * We have:
      * 6 new issues per line (open) in helloscala.xoo
@@ -187,7 +180,7 @@ public class ScanOnlyChangedTest {
       taskBuilder.property("sonar.projectKey", projectKey);
     }
 
-    TaskResult result = taskBuilder.start();
+    TaskResult result = taskBuilder.execute();
 
     assertNumberIssues(result, 16, 2, 0);
 
index ebf463e580a79da13547451bb64cea003073e6e3..f724dd0eaa97675de99e0e3c383e59ad2b281690 100644 (file)
@@ -60,11 +60,11 @@ public class LogListenerTest {
   private static PrintStream savedStdOut;
   private static PrintStream savedStdErr;
 
-  public ScannerMediumTester tester = ScannerMediumTester.builder()
+  @Rule
+  public ScannerMediumTester tester = new ScannerMediumTester()
     .registerPlugin("xoo", new XooPlugin())
     .addDefaultQProfile("xoo", "Sonar Way")
-    .setLogOutput(new SimpleLogListener())
-    .build();
+    .setLogOutput(new SimpleLogListener());
 
   private File baseDir;
 
@@ -95,7 +95,6 @@ public class LogListenerTest {
     // logger from the batch might write to it asynchronously
     logOutput = Collections.synchronizedList(new LinkedList<LogEvent>());
     logOutputStr = new StringBuilder();
-    tester.start();
 
     baseDir = temp.getRoot();
 
@@ -143,9 +142,8 @@ public class LogListenerTest {
         .put("sonar.sources", "src")
         .put("sonar.verbose", "true")
         .build())
-      .start();
+      .execute();
 
-    tester.stop();
     for (LogEvent e : logOutput) {
       savedStdOut.println("[captured]" + e.level + " " + e.msg);
     }
@@ -166,8 +164,7 @@ public class LogListenerTest {
       .properties(builder
         .put("sonar.sources", "src")
         .build())
-      .start();
-    tester.stop();
+      .execute();
 
     assertNoStdOutput();
     assertThat(logOutput).isNotEmpty();
@@ -191,8 +188,7 @@ public class LogListenerTest {
       .properties(builder
         .put("sonar.sources", "src")
         .build())
-      .start();
-    tester.stop();
+      .execute();
 
     assertNoStdOutput();
 
@@ -220,12 +216,11 @@ public class LogListenerTest {
         .properties(builder
           .put("sonar.sources", "src")
           .build())
-        .start();
+        .execute();
       fail("Expected exception");
     } catch (Exception e) {
       assertThat(e.getMessage()).contains("Error processing line 1");
     }
-    tester.stop();
 
     assertNoStdOutput();
 
index 5dd45050f3e0676210cd463b0d27409bfddafe98..f888fbfd714054e66189351089dbc293a3af8f9a 100644 (file)
@@ -25,7 +25,6 @@ import java.io.IOException;
 import java.util.List;
 import java.util.Map;
 import org.apache.commons.io.FileUtils;
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -52,20 +51,10 @@ public class MeasuresMediumTest {
   private File baseDir;
   private File srcDir;
 
-  public ScannerMediumTester tester = ScannerMediumTester.builder()
+  @Rule
+  public ScannerMediumTester tester = new ScannerMediumTester()
     .registerPlugin("xoo", new XooPlugin())
-    .addDefaultQProfile("xoo", "Sonar Way")
-    .build();
-
-  @Before
-  public void prepare() {
-    tester.start();
-  }
-
-  @After
-  public void stop() {
-    tester.stop();
-  }
+    .addDefaultQProfile("xoo", "Sonar Way");
 
   @Before
   public void setUp() throws Exception {
@@ -92,7 +81,7 @@ public class MeasuresMediumTest {
         .put("sonar.projectDescription", "Description of Foo Project")
         .put("sonar.sources", "src")
         .build())
-      .start();
+      .execute();
 
     Map<String, List<Measure>> allMeasures = result.allMeasures();
 
@@ -110,7 +99,7 @@ public class MeasuresMediumTest {
         .put("sonar.sources", "src")
         .put("sonar.coverage.exclusions", "src/sample.xoo")
         .build())
-      .start();
+      .execute();
 
     allMeasures = result.allMeasures();
     assertThat(allMeasures.get("com.foo.project:src/sample.xoo")).extracting("metricKey", "intValue.value")
@@ -135,7 +124,7 @@ public class MeasuresMediumTest {
         .put("sonar.projectDescription", "Description of Foo Project")
         .put("sonar.sources", "src")
         .build())
-      .start();
+      .execute();
 
     Map<String, List<Measure>> allMeasures = result.allMeasures();
 
@@ -165,7 +154,7 @@ public class MeasuresMediumTest {
           .put("sonar.projectDescription", "Description of Foo Project")
           .put("sonar.sources", "src")
           .build())
-        .start();
+        .execute();
       fail("Expected exception");
     } catch (Exception e) {
       assertThat(e)
@@ -192,7 +181,7 @@ public class MeasuresMediumTest {
         .put("sonar.projectDescription", "Description of Foo Project")
         .put("sonar.sources", "src")
         .build())
-      .start();
+      .execute();
 
     Map<String, List<Measure>> allMeasures = result.allMeasures();
 
@@ -218,7 +207,7 @@ public class MeasuresMediumTest {
         .put("sonar.projectDescription", "Description of Foo Project")
         .put("sonar.sources", "src")
         .build())
-      .start();
+      .execute();
 
     Map<String, List<Measure>> allMeasures = result.allMeasures();
 
index dc411eb2e088d67f000aefc683d00751daba04b5..fbf81aa0c7e1325f2c1164770583299e55d21bae 100644 (file)
@@ -27,8 +27,6 @@ import java.nio.charset.StandardCharsets;
 import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.commons.io.FileUtils;
 import org.assertj.core.util.Files;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -56,7 +54,7 @@ public class ScmMediumTest {
   private static final String SAME_CONTENT_NO_SCM_ON_SERVER_XOO = "src/same_content_no_scm_on_server.xoo";
   private static final String SAMPLE_XOO_CONTENT = "Sample xoo\ncontent";
 
-  @org.junit.Rule
+  @Rule
   public TemporaryFolder temp = new TemporaryFolder();
 
   @Rule
@@ -65,7 +63,8 @@ public class ScmMediumTest {
   @Rule
   public LogTester logTester = new LogTester();
 
-  public ScannerMediumTester tester = ScannerMediumTester.builder()
+  @Rule
+  public ScannerMediumTester tester = new ScannerMediumTester()
     .registerPlugin("xoo", new XooPlugin())
     .addDefaultQProfile("xoo", "Sonar Way")
     .addRules(new XooRulesDefinition())
@@ -74,18 +73,7 @@ public class ScmMediumTest {
     .addFileData("com.foo.project", CHANGED_CONTENT_SCM_ON_SERVER_XOO, new FileData(DigestUtils.md5Hex(SAMPLE_XOO_CONTENT), null))
     .addFileData("com.foo.project", SAME_CONTENT_NO_SCM_ON_SERVER_XOO, new FileData(DigestUtils.md5Hex(SAMPLE_XOO_CONTENT), null))
     .addFileData("com.foo.project", SAME_CONTENT_SCM_ON_SERVER_XOO, new FileData(DigestUtils.md5Hex(SAMPLE_XOO_CONTENT), "1.1"))
-    .addFileData("com.foo.project", NO_BLAME_SCM_ON_SERVER_XOO, new FileData(DigestUtils.md5Hex(SAMPLE_XOO_CONTENT), "1.1"))
-    .build();
-
-  @Before
-  public void prepare() {
-    tester.start();
-  }
-
-  @After
-  public void stop() {
-    tester.stop();
-  }
+    .addFileData("com.foo.project", NO_BLAME_SCM_ON_SERVER_XOO, new FileData(DigestUtils.md5Hex(SAMPLE_XOO_CONTENT), "1.1"));
 
   @Test
   public void testScmMeasure() throws IOException, URISyntaxException {
@@ -102,7 +90,7 @@ public class ScmMediumTest {
         .put("sonar.sources", "src")
         .put("sonar.scm.provider", "xoo")
         .build())
-      .start();
+      .execute();
 
     ScannerReport.Changesets fileScm = getChangesets(baseDir, "src/sample.xoo");
 
@@ -125,7 +113,7 @@ public class ScmMediumTest {
   }
 
   private ScannerReport.Changesets getChangesets(File baseDir, String path) {
-    File reportDir = new File(baseDir, ".sonar/batch-report");
+    File reportDir = new File(baseDir, ".sonar/scanner-report");
     ScannerReportReader reader = new ScannerReportReader(reportDir);
 
     Component project = reader.readComponent(reader.readMetadata().getRootComponentRef());
@@ -158,7 +146,7 @@ public class ScmMediumTest {
         .put("sonar.sources", "src")
         .put("sonar.scm.provider", "xoo")
         .build())
-      .start();
+      .execute();
 
     ScannerReport.Changesets changesets = getChangesets(baseDir, "src/sample.xoo");
 
@@ -183,7 +171,7 @@ public class ScmMediumTest {
         .put("sonar.sources", "src")
         .put("sonar.scm.provider", "xoo")
         .build())
-      .start();
+      .execute();
 
     ScannerReport.Changesets file1Scm = getChangesets(baseDir, "src/sample.xoo");
     assertThat(file1Scm).isNotNull();
@@ -236,7 +224,7 @@ public class ScmMediumTest {
         .put("sonar.sources", "src")
         .put("sonar.scm.provider", "xoo")
         .build())
-      .start();
+      .execute();
 
     assertThat(getChangesets(baseDir, "src/sample.xoo")).isNotNull();
 
@@ -280,7 +268,7 @@ public class ScmMediumTest {
         .put("sonar.scm.forceReloadAll", "true")
         .build());
 
-    taskBuilder.start();
+    taskBuilder.execute();
 
     ScannerReport.Changesets file1Scm = getChangesets(baseDir, "src/sample.xoo");
     assertThat(file1Scm).isNotNull();
@@ -305,7 +293,7 @@ public class ScmMediumTest {
         .put("sonar.sources", "src")
         .put("sonar.links.scm_dev", "scm:xoo:foobar")
         .build())
-      .start();
+      .execute();
 
     ScannerReport.Changesets file1Scm = getChangesets(baseDir, "src/sample.xoo");
     assertThat(file1Scm).isNotNull();
@@ -327,7 +315,7 @@ public class ScmMediumTest {
         .put("sonar.projectDescription", "Description of Foo Project")
         .put("sonar.sources", "src")
         .build())
-      .start();
+      .execute();
 
     ScannerReport.Changesets file1Scm = getChangesets(baseDir, "src/sample.xoo");
     assertThat(file1Scm).isNotNull();
@@ -376,7 +364,7 @@ public class ScmMediumTest {
         .put("sonar.scm.provider", "xoo")
         .put("sonar.cpd.xoo.skip", "true")
         .build())
-      .start();
+      .execute();
 
     ScannerReport.Changesets changesets = getChangesets(baseDir, "src/sample.xoo");
     assertThat(changesets).isNull();
index 8bf546573ae304b731c7911d53123493e43ce1cd..dcf9aa8dd689cde2c6b73234dd69e5fb8c7f946f 100644 (file)
@@ -23,8 +23,7 @@ import com.google.common.collect.ImmutableMap;
 import java.io.File;
 import java.io.IOException;
 import org.apache.commons.io.FileUtils;
-import org.junit.After;
-import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.fs.InputFile;
@@ -37,23 +36,13 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 public class SymbolMediumTest {
 
-  @org.junit.Rule
+  @Rule
   public TemporaryFolder temp = new TemporaryFolder();
 
-  public ScannerMediumTester tester = ScannerMediumTester.builder()
+  @Rule
+  public ScannerMediumTester tester = new ScannerMediumTester()
     .registerPlugin("xoo", new XooPlugin())
-    .addDefaultQProfile("xoo", "Sonar Way")
-    .build();
-
-  @Before
-  public void prepare() {
-    tester.start();
-  }
-
-  @After
-  public void stop() {
-    tester.stop();
-  }
+    .addDefaultQProfile("xoo", "Sonar Way");
 
   @Test
   public void computeSymbolReferencesOnTempProject() throws IOException {
@@ -78,7 +67,7 @@ public class SymbolMediumTest {
         .put("sonar.projectDescription", "Description of Foo Project")
         .put("sonar.sources", "src")
         .build())
-      .start();
+      .execute();
 
     InputFile file = result.inputFile("src/sample.xoo");
     assertThat(result.symbolReferencesFor(file, 1, 7)).containsOnly(ScannerReport.TextRange.newBuilder().setStartLine(3).setStartOffset(8).setEndLine(3).setEndOffset(11).build());
@@ -107,7 +96,7 @@ public class SymbolMediumTest {
         .put("sonar.projectDescription", "Description of Foo Project")
         .put("sonar.sources", "src")
         .build())
-      .start();
+      .execute();
 
     InputFile file = result.inputFile("src/sample.xoo");
     assertThat(result.symbolReferencesFor(file, 1, 7)).containsOnly(ScannerReport.TextRange.newBuilder().setStartLine(3).setStartOffset(8).setEndLine(4).setEndOffset(1).build());
index 8334d079463d9da2413c5c1705701ed953d4b840..2739b76e23e5d831b6c706b05011902affb657c7 100644 (file)
@@ -45,9 +45,9 @@ public class TasksMediumTest {
   @Rule
   public LogTester logTester = new LogTester();
 
-  public ScannerMediumTester tester = ScannerMediumTester.builder()
-    .registerPlugin("faketask", new FakeTaskPlugin())
-    .build();
+  @Rule
+  public ScannerMediumTester tester = new ScannerMediumTester()
+    .registerPlugin("faketask", new FakeTaskPlugin());
 
   private MockHttpServer server = null;
 
@@ -58,18 +58,12 @@ public class TasksMediumTest {
     }
   }
 
-  @After
-  public void stop() {
-    tester.stop();
-  }
-
   @Test
   public void listTasksIncludingBroken() throws Exception {
-    tester.start();
     tester.newTask()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "list").build())
-      .start();
+      .execute();
 
     assertThat(logTester.logs()).haveExactly(1, new Condition<String>() {
 
@@ -82,8 +76,6 @@ public class TasksMediumTest {
 
   @Test
   public void runBroken() throws Exception {
-    tester.start();
-
     thrown.expect(IllegalStateException.class);
     thrown.expectMessage(
       "Unable to load component class org.sonar.scanner.mediumtest.tasks.TasksMediumTest$BrokenTask");
@@ -91,18 +83,15 @@ public class TasksMediumTest {
     tester.newTask()
       .properties(ImmutableMap.<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 {
index a949587caa11a6a4052c2862395a93cc6ac02196..91eb6ce7ac68bf258ddafda3425a56260ca77c49 100644 (file)
@@ -25,8 +25,6 @@ import java.io.IOException;
 import org.apache.commons.io.FileUtils;
 import org.hamcrest.Description;
 import org.hamcrest.TypeSafeMatcher;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -46,20 +44,10 @@ public class CoveragePerTestMediumTest {
   @Rule
   public ExpectedException exception = ExpectedException.none();
 
-  public ScannerMediumTester tester = ScannerMediumTester.builder()
+  @Rule
+  public ScannerMediumTester tester = new ScannerMediumTester()
     .registerPlugin("xoo", new XooPlugin())
-    .addDefaultQProfile("xoo", "Sonar Way")
-    .build();
-
-  @Before
-  public void prepare() {
-    tester.start();
-  }
-
-  @After
-  public void stop() {
-    tester.stop();
-  }
+    .addDefaultQProfile("xoo", "Sonar Way");
 
   @Test
   // SONAR-6183
@@ -130,7 +118,7 @@ public class CoveragePerTestMediumTest {
         .put("sonar.sources", "src")
         .put("sonar.tests", "test")
         .build())
-      .start();
+      .execute();
   }
 
   private File createTestFiles() throws IOException {
index 462d3d1f7eae0671288ecf9a5489048b375c17a9..ec83c2e66efc41849ce4155ba042e767d2663b5b 100644 (file)
@@ -23,8 +23,7 @@ import com.google.common.collect.ImmutableMap;
 import java.io.File;
 import java.io.IOException;
 import org.apache.commons.io.FileUtils;
-import org.junit.After;
-import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.fs.InputFile;
@@ -40,23 +39,13 @@ import static org.assertj.core.api.Assertions.tuple;
 
 public class GenericTestExecutionMediumTest {
 
-  @org.junit.Rule
+  @Rule
   public TemporaryFolder temp = new TemporaryFolder();
 
-  public ScannerMediumTester tester = ScannerMediumTester.builder()
+  @Rule
+  public ScannerMediumTester tester = new ScannerMediumTester()
     .registerPlugin("xoo", new XooPlugin())
-    .addDefaultQProfile("xoo", "Sonar Way")
-    .build();
-
-  @Before
-  public void prepare() {
-    tester.start();
-  }
-
-  @After
-  public void stop() {
-    tester.stop();
-  }
+    .addDefaultQProfile("xoo", "Sonar Way");
 
   @Test
   public void unitTests() throws IOException {
@@ -90,7 +79,7 @@ public class GenericTestExecutionMediumTest {
         .put("sonar.sources", "src")
         .put("sonar.tests", "test")
         .build())
-      .start();
+      .execute();
 
     InputFile file = result.inputFile("test/sampleTest.xoo");
     org.sonar.scanner.protocol.output.ScannerReport.Test success = result.firstTestExecutionForName(file, "success");
@@ -112,7 +101,7 @@ public class GenericTestExecutionMediumTest {
     TaskResult result = tester
       .newScanTask(new File(projectDir, "sonar-project.properties"))
       .property("sonar.testExecutionReportPaths", "unittest.xml")
-      .start();
+      .execute();
 
     InputFile testFile = result.inputFile("testx/ClassOneTest.xoo");
     ScannerReport.Test success = result.firstTestExecutionForName(testFile, "test1");
@@ -154,7 +143,7 @@ public class GenericTestExecutionMediumTest {
     TaskResult result = tester
       .newScanTask(new File(projectDir, "sonar-project.properties"))
       .property("sonar.testExecutionReportPaths", "unittest.xml,unittest2.xml")
-      .start();
+      .execute();
 
     InputFile testFile = result.inputFile("testx/ClassOneTest.xoo");
     ScannerReport.Test success = result.firstTestExecutionForName(testFile, "test1");
index aa0df994785da198c249a431ecffe33fb9af9650..228b349a729c22b61c1df8d5f039aadc05256d64 100644 (file)
@@ -23,8 +23,7 @@ import com.google.common.collect.ImmutableMap;
 import java.io.File;
 import java.io.IOException;
 import org.apache.commons.io.FileUtils;
-import org.junit.After;
-import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.fs.InputFile;
@@ -40,20 +39,10 @@ public class TestExecutionMediumTest {
   @org.junit.Rule
   public TemporaryFolder temp = new TemporaryFolder();
 
-  public ScannerMediumTester tester = ScannerMediumTester.builder()
+  @Rule
+  public ScannerMediumTester tester = new ScannerMediumTester()
     .registerPlugin("xoo", new XooPlugin())
-    .addDefaultQProfile("xoo", "Sonar Way")
-    .build();
-
-  @Before
-  public void prepare() {
-    tester.start();
-  }
-
-  @After
-  public void stop() {
-    tester.stop();
-  }
+    .addDefaultQProfile("xoo", "Sonar Way");
 
   @Test
   public void unitTests() throws IOException {
@@ -87,7 +76,7 @@ public class TestExecutionMediumTest {
         .put("sonar.sources", "src")
         .put("sonar.tests", "test")
         .build())
-      .start();
+      .execute();
 
     InputFile file = result.inputFile("test/sampleTest.xoo");
     org.sonar.scanner.protocol.output.ScannerReport.Test success = result.firstTestExecutionForName(file, "success");
index 635f15e74f515a7a59d6d7e99ee6ef59502d75ff..e4d6c615339565d6e135cc87153f71c68cc531cb 100644 (file)
  */
 package org.sonar.scanner.report;
 
-import static org.apache.commons.io.FileUtils.readFileToString;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.entry;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
 import java.io.File;
 import java.io.IOException;
 import java.io.PipedInputStream;
 import java.io.PipedOutputStream;
 import java.nio.file.Files;
 import java.nio.file.Path;
-
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -60,6 +51,14 @@ import org.sonarqube.ws.client.HttpException;
 import org.sonarqube.ws.client.WsRequest;
 import org.sonarqube.ws.client.WsResponse;
 
+import static org.apache.commons.io.FileUtils.readFileToString;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.entry;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
 public class ReportPublisherTest {
 
   @Rule
@@ -176,8 +175,8 @@ public class ReportPublisherTest {
 
   @Test
   public void should_not_delete_report_if_property_is_set() throws IOException {
-    settings.setProperty("sonar.batch.keepReport", true);
-    Path reportDir = temp.getRoot().toPath().resolve("batch-report");
+    settings.setProperty("sonar.scanner.keepReport", true);
+    Path reportDir = temp.getRoot().toPath().resolve("scanner-report");
     Files.createDirectory(reportDir);
     ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class),
       new ReportPublisherStep[0]);
@@ -189,7 +188,7 @@ public class ReportPublisherTest {
 
   @Test
   public void should_delete_report_by_default() throws IOException {
-    Path reportDir = temp.getRoot().toPath().resolve("batch-report");
+    Path reportDir = temp.getRoot().toPath().resolve("scanner-report");
     Files.createDirectory(reportDir);
     ReportPublisher job = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class), new ReportPublisherStep[0]);
 
index a175bbf629484465f51e10dddb1b7e6ea6db588d..4def0e576ab95c749d1d2248feeb4274a0f59a9f 100644 (file)
@@ -22,7 +22,6 @@ package org.sonarqube.tests.analysis;
 import com.sonar.orchestrator.Orchestrator;
 import com.sonar.orchestrator.build.BuildResult;
 import com.sonar.orchestrator.build.SonarScanner;
-import org.sonarqube.tests.Category3Suite;
 import java.io.File;
 import java.io.IOException;
 import java.util.Map;
@@ -34,6 +33,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
+import org.sonarqube.tests.Category3Suite;
 import org.sonarqube.ws.client.component.SearchWsRequest;
 import util.ItUtils;
 
@@ -247,7 +247,7 @@ public class ScannerTest {
    * SONAR-2291
    */
   @Test
-  public void batch_should_cache_plugin_jars() throws IOException {
+  public void scanner_should_cache_plugin_jars() throws IOException {
     File userHome = temp.newFolder();
 
     BuildResult result = scan("shared/xoo-sample",
@@ -268,12 +268,12 @@ public class ScannerTest {
   }
 
   @Test
-  public void batch_should_keep_report_verbose() {
+  public void scanner_should_keep_report_verbose() {
     orchestrator.getServer().provisionProject("sample", "xoo-sample");
     orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
 
     scanQuietly("shared/xoo-sample", "sonar.verbose", "true");
-    File reportDir = new File(new File(ItUtils.projectDir("shared/xoo-sample"), ".sonar"), "batch-report");
+    File reportDir = new File(new File(ItUtils.projectDir("shared/xoo-sample"), ".sonar"), "scanner-report");
     assertThat(reportDir).isDirectory();
     assertThat(reportDir.list()).isNotEmpty();
   }