aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2016-05-11 12:21:22 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2016-05-12 08:49:09 +0200
commit42dc2978d58ca7f0860a62e6184dcc8e64d21346 (patch)
tree4602a1105050a1a0b604c2780fde335a903cf33b /sonar-scanner-engine
parentd04b0fde3f735f89e37b15bcef26b44379a13e6e (diff)
downloadsonarqube-42dc2978d58ca7f0860a62e6184dcc8e64d21346.tar.gz
sonarqube-42dc2978d58ca7f0860a62e6184dcc8e64d21346.zip
SONAR-7612 Apply feedback
Diffstat (limited to 'sonar-scanner-engine')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/postjob/DefaultPostJobContext.java19
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/postjob/DefaultPostJobContextTest.java9
2 files changed, 23 insertions, 5 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/postjob/DefaultPostJobContext.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/postjob/DefaultPostJobContext.java
index 341bc7991a8..1e66067fded 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/postjob/DefaultPostJobContext.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/postjob/DefaultPostJobContext.java
@@ -23,6 +23,7 @@ import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import javax.annotation.Nullable;
+import org.sonar.api.batch.AnalysisMode;
import org.sonar.api.batch.fs.InputComponent;
import org.sonar.api.batch.postjob.PostJobContext;
import org.sonar.api.batch.postjob.issue.PostJobIssue;
@@ -39,11 +40,13 @@ public class DefaultPostJobContext implements PostJobContext {
private final Settings settings;
private final IssueCache cache;
private final BatchComponentCache resourceCache;
+ private final AnalysisMode analysisMode;
- public DefaultPostJobContext(Settings settings, IssueCache cache, BatchComponentCache resourceCache) {
+ public DefaultPostJobContext(Settings settings, IssueCache cache, BatchComponentCache resourceCache, AnalysisMode analysisMode) {
this.settings = settings;
this.cache = cache;
this.resourceCache = resourceCache;
+ this.analysisMode = analysisMode;
}
@Override
@@ -52,12 +55,23 @@ public class DefaultPostJobContext implements PostJobContext {
}
@Override
+ public AnalysisMode analysisMode() {
+ return analysisMode;
+ }
+
+ @Override
public Iterable<PostJobIssue> issues() {
+ if (!analysisMode.isIssues()) {
+ throw new UnsupportedOperationException("Issues are only available to PostJobs in 'issues' mode.");
+ }
return Iterables.transform(Iterables.filter(cache.all(), new ResolvedPredicate(false)), new IssueTransformer());
}
@Override
public Iterable<PostJobIssue> resolvedIssues() {
+ if (!analysisMode.isIssues()) {
+ throw new UnsupportedOperationException("Resolved issues are only available to PostJobs in 'issues' mode.");
+ }
return Iterables.transform(Iterables.filter(cache.all(), new ResolvedPredicate(true)), new IssueTransformer());
}
@@ -102,8 +116,7 @@ public class DefaultPostJobContext implements PostJobContext {
@Override
public Severity severity() {
- String severity = wrapped.severity();
- return severity != null ? Severity.valueOf(severity) : null;
+ return Severity.valueOf(wrapped.severity());
}
@Override
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/postjob/DefaultPostJobContextTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/postjob/DefaultPostJobContextTest.java
index 5f9916919ec..803b6177eb7 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/postjob/DefaultPostJobContextTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/postjob/DefaultPostJobContextTest.java
@@ -22,6 +22,7 @@ package org.sonar.batch.postjob;
import java.util.Arrays;
import org.junit.Before;
import org.junit.Test;
+import org.sonar.api.batch.AnalysisMode;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.postjob.issue.PostJobIssue;
import org.sonar.api.batch.rule.Severity;
@@ -41,17 +42,21 @@ public class DefaultPostJobContextTest {
private BatchComponentCache resourceCache;
private DefaultPostJobContext context;
private Settings settings;
+ private AnalysisMode analysisMode;
@Before
public void prepare() {
issueCache = mock(IssueCache.class);
resourceCache = new BatchComponentCache();
settings = new Settings();
- context = new DefaultPostJobContext(settings, issueCache, resourceCache);
+ analysisMode = mock(AnalysisMode.class);
+ context = new DefaultPostJobContext(settings, issueCache, resourceCache, analysisMode);
}
@Test
- public void test() {
+ public void testIssues() {
+ when(analysisMode.isIssues()).thenReturn(true);
+
assertThat(context.settings()).isSameAs(settings);
TrackedIssue defaultIssue = new TrackedIssue();