@@ -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 |
@@ -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 | |||
} | |||
} |
@@ -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); |