]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10588 Don't import external issues in preview mode
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Fri, 13 Apr 2018 13:53:41 +0000 (15:53 +0200)
committerSonarTech <sonartech@sonarsource.com>
Thu, 26 Apr 2018 18:20:51 +0000 (20:20 +0200)
sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorContext.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/noop/NoOpNewExternalIssue.java [new file with mode: 0644]
sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorContextTest.java

index ff9a7ba1685c2e909f51e35f5b967a0dff8370b0..595a9d126fb8b7e1841a3eba968e2633bf739fa6 100644 (file)
@@ -52,17 +52,19 @@ import org.sonar.scanner.scan.branch.BranchConfiguration;
 import org.sonar.scanner.sensor.noop.NoOpNewAnalysisError;
 import org.sonar.scanner.sensor.noop.NoOpNewCoverage;
 import org.sonar.scanner.sensor.noop.NoOpNewCpdTokens;
+import org.sonar.scanner.sensor.noop.NoOpNewExternalIssue;
 import org.sonar.scanner.sensor.noop.NoOpNewHighlighting;
 import org.sonar.scanner.sensor.noop.NoOpNewSymbolTable;
 
 @ThreadSafe
 public class DefaultSensorContext implements SensorContext {
 
-  private static final NoOpNewHighlighting NO_OP_NEW_HIGHLIGHTING = new NoOpNewHighlighting();
-  private static final NoOpNewSymbolTable NO_OP_NEW_SYMBOL_TABLE = new NoOpNewSymbolTable();
+  static final NoOpNewHighlighting NO_OP_NEW_HIGHLIGHTING = new NoOpNewHighlighting();
+  static final NoOpNewSymbolTable NO_OP_NEW_SYMBOL_TABLE = new NoOpNewSymbolTable();
   static final NoOpNewCpdTokens NO_OP_NEW_CPD_TOKENS = new NoOpNewCpdTokens();
-  private static final NoOpNewAnalysisError NO_OP_NEW_ANALYSIS_ERROR = new NoOpNewAnalysisError();
+  static final NoOpNewAnalysisError NO_OP_NEW_ANALYSIS_ERROR = new NoOpNewAnalysisError();
   static final NoOpNewCoverage NO_OP_NEW_COVERAGE = new NoOpNewCoverage();
+  static final NoOpNewExternalIssue NO_OP_NEW_EXTERNAL_ISSUE = new NoOpNewExternalIssue();
 
   private final Settings mutableSettings;
   private final FileSystem fs;
@@ -134,7 +136,11 @@ public class DefaultSensorContext implements SensorContext {
 
   @Override
   public NewExternalIssue newExternalIssue() {
+    if (analysisMode.isIssues()) {
+      return NO_OP_NEW_EXTERNAL_ISSUE;
+    }
     return new DefaultExternalIssue(sensorStorage);
+
   }
 
   @Override
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/noop/NoOpNewExternalIssue.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/noop/NoOpNewExternalIssue.java
new file mode 100644 (file)
index 0000000..42d4a90
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 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.sensor.noop;
+
+import org.sonar.api.batch.rule.Severity;
+import org.sonar.api.batch.sensor.issue.NewExternalIssue;
+import org.sonar.api.batch.sensor.issue.NewIssueLocation;
+import org.sonar.api.batch.sensor.issue.internal.DefaultIssueLocation;
+import org.sonar.api.rule.RuleKey;
+import org.sonar.api.rules.RuleType;
+
+public class NoOpNewExternalIssue implements NewExternalIssue {
+
+  @Override
+  public NewExternalIssue forRule(RuleKey ruleKey) {
+    // no op
+    return this;
+  }
+
+  @Override
+  public NewExternalIssue type(RuleType type) {
+    // no op
+    return this;
+  }
+
+  @Override
+  public NewExternalIssue remediationEffort(Long effort) {
+    // no op
+    return this;
+  }
+
+  @Override
+  public NewExternalIssue severity(Severity severity) {
+    // no op
+    return this;
+  }
+
+  @Override
+  public NewExternalIssue at(NewIssueLocation primaryLocation) {
+    // no op
+    return this;
+  }
+
+  @Override
+  public NewExternalIssue addLocation(NewIssueLocation secondaryLocation) {
+    // no op
+    return this;
+  }
+
+  @Override
+  public NewExternalIssue descriptionUrl(String url) {
+    // no op
+    return this;
+  }
+
+  @Override
+  public NewExternalIssue addFlow(Iterable<NewIssueLocation> flowLocations) {
+    // no op
+    return this;
+  }
+
+  @Override
+  public NewIssueLocation newLocation() {
+    // no op
+    return new DefaultIssueLocation();
+  }
+
+  @Override
+  public NewExternalIssue ruleTitle(String title) {
+    // no op
+    return this;
+  }
+
+  @Override
+  public void save() {
+    // no op
+  }
+
+}
index 24cc70506bee7a65b0bdab96848e165db0ceabef..ee1c4a348724056ca5687ce2678ccecd9868970a 100644 (file)
@@ -86,10 +86,20 @@ public class DefaultSensorContextTest {
     assertThat(adaptor.newIssue()).isNotNull();
     assertThat(adaptor.newExternalIssue()).isNotNull();
     assertThat(adaptor.newMeasure()).isNotNull();
-
+    assertThat(adaptor.newAnalysisError()).isEqualTo(DefaultSensorContext.NO_OP_NEW_ANALYSIS_ERROR);
     assertThat(adaptor.isCancelled()).isFalse();
   }
 
+  @Test
+  public void shouldSkipSeveralObjectsInPreviewMode() {
+    when(analysisMode.isIssues()).thenReturn(true);
+    when(analysisMode.isPreview()).thenReturn(true);
+    assertThat(adaptor.newCpdTokens()).isEqualTo(DefaultSensorContext.NO_OP_NEW_CPD_TOKENS);
+    assertThat(adaptor.newSymbolTable()).isEqualTo(DefaultSensorContext.NO_OP_NEW_SYMBOL_TABLE);
+    assertThat(adaptor.newExternalIssue()).isEqualTo(DefaultSensorContext.NO_OP_NEW_EXTERNAL_ISSUE);
+    assertThat(adaptor.newHighlighting()).isEqualTo(DefaultSensorContext.NO_OP_NEW_HIGHLIGHTING);
+  }
+
   @Test
   public void shouldSkipDupsAndCoverageOnShortBranches() {
     when(branchConfig.isShortOrPullRequest()).thenReturn(true);