aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2017-11-23 22:01:21 +0100
committerGitHub <noreply@github.com>2017-11-23 22:01:21 +0100
commit4eb8c7f8657ebe5544fcd2283145d175713ab567 (patch)
treedd9e4078d15e052578874234bbb3761e20a448e4 /sonar-scanner-engine
parente02d9d4a80eeb4f5cff53dd057e86df2c48d4f7e (diff)
downloadsonarqube-4eb8c7f8657ebe5544fcd2283145d175713ab567.tar.gz
sonarqube-4eb8c7f8657ebe5544fcd2283145d175713ab567.zip
Support build of SonarQube with JDK 9
Diffstat (limited to 'sonar-scanner-engine')
-rw-r--r--sonar-scanner-engine/pom.xml5
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/IgnoreIssuesFilter.java3
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/QualityProfileProvider.java5
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/DefaultFileLinesContextTest.java4
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/IgnoreIssuesFilterTest.java36
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/log/ExceptionHandlingMediumTest.java4
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/QualityProfileProviderTest.java7
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ModuleInputComponentStoreTest.java7
8 files changed, 30 insertions, 41 deletions
diff --git a/sonar-scanner-engine/pom.xml b/sonar-scanner-engine/pom.xml
index 086a9bec024..f92d507858e 100644
--- a/sonar-scanner-engine/pom.xml
+++ b/sonar-scanner-engine/pom.xml
@@ -109,11 +109,6 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-all</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>${project.groupId}</groupId>
<artifactId>sonar-plugin-api</artifactId>
<type>test-jar</type>
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/IgnoreIssuesFilter.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/IgnoreIssuesFilter.java
index 23c02f54f85..b9468dd8056 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/IgnoreIssuesFilter.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/IgnoreIssuesFilter.java
@@ -41,9 +41,8 @@ public class IgnoreIssuesFilter implements IssueFilter {
public boolean accept(FilterableIssue issue, IssueFilterChain chain) {
if (hasMatchFor(issue)) {
return false;
- } else {
- return chain.accept(issue);
}
+ return chain.accept(issue);
}
private boolean hasMatchFor(FilterableIssue issue) {
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/QualityProfileProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/QualityProfileProvider.java
index 60be7b5140e..6230c5ee925 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/QualityProfileProvider.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/QualityProfileProvider.java
@@ -53,9 +53,8 @@ public class QualityProfileProvider extends ProviderAdapter {
@CheckForNull
private static String getSonarProfile(AnalysisProperties props) {
- String profile = null;
- if (props.properties().containsKey(ModuleQProfiles.SONAR_PROFILE_PROP)) {
- profile = props.property(ModuleQProfiles.SONAR_PROFILE_PROP);
+ String profile = props.property(ModuleQProfiles.SONAR_PROFILE_PROP);
+ if (profile != null) {
LOG.warn("Ability to set quality profile from command line using '" + ModuleQProfiles.SONAR_PROFILE_PROP
+ "' is deprecated and will be dropped in a future SonarQube version. Please configure quality profile used by your project on SonarQube server.");
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/DefaultFileLinesContextTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/DefaultFileLinesContextTest.java
index f3a47b46ec8..93d0e829a65 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/DefaultFileLinesContextTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/DefaultFileLinesContextTest.java
@@ -32,8 +32,8 @@ import org.sonar.api.measures.CoreMetrics;
import org.sonar.scanner.scan.measure.MeasureCache;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/IgnoreIssuesFilterTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/IgnoreIssuesFilterTest.java
index 5dc8a09e511..6753f155734 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/IgnoreIssuesFilterTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/IgnoreIssuesFilterTest.java
@@ -19,8 +19,8 @@
*/
package org.sonar.scanner.issue.ignore;
-import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mockito;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.scan.issue.filter.FilterableIssue;
import org.sonar.api.scan.issue.filter.IssueFilterChain;
@@ -35,32 +35,26 @@ import static org.mockito.Mockito.when;
public class IgnoreIssuesFilterTest {
- private PatternMatcher exclusionPatternMatcher;
- private IgnoreIssuesFilter ignoreFilter;
- private FilterableIssue issue;
- private IssueFilterChain chain;
-
- @Before
- public void init() {
- exclusionPatternMatcher = mock(PatternMatcher.class);
- issue = mock(FilterableIssue.class);
- chain = mock(IssueFilterChain.class);
- when(chain.accept(issue)).thenReturn(true);
-
- ignoreFilter = new IgnoreIssuesFilter(exclusionPatternMatcher);
- }
+ private PatternMatcher exclusionPatternMatcher = mock(PatternMatcher.class);
+ private FilterableIssue issue = mock(FilterableIssue.class, Mockito.RETURNS_DEEP_STUBS);
+ private IssueFilterChain chain = mock(IssueFilterChain.class);
+ private IgnoreIssuesFilter underTest = new IgnoreIssuesFilter(exclusionPatternMatcher);
@Test
public void shouldPassToChainIfMatcherHasNoPatternForIssue() {
- when(exclusionPatternMatcher.getMatchingPattern(anyString(), any(RuleKey.class), any(Integer.class))).thenReturn(null);
-
- assertThat(ignoreFilter.accept(issue, chain)).isTrue();
+ when(exclusionPatternMatcher.getMatchingPattern(anyString(), any(RuleKey.class), any(Integer.class)))
+ .thenReturn(null);
+ when(chain.accept(issue)).thenReturn(true);
+ assertThat(underTest.accept(issue, chain)).isTrue();
}
@Test
- public void shouldAcceptOrRefuseIfMatcherHasPatternForIssue() {
- when(exclusionPatternMatcher.getMatchingPattern(anyString(), any(RuleKey.class), any(Integer.class))).thenReturn(mock(IssuePattern.class));
+ public void shouldRejectIfPatternMatches() {
+ IssuePattern pattern = mock(IssuePattern.class);
+ when(exclusionPatternMatcher.getMatchingPattern(anyString(), any(RuleKey.class), any(Integer.class)))
+ .thenReturn(pattern);
- assertThat(ignoreFilter.accept(issue, chain)).isFalse();
+ assertThat(underTest.accept(issue, chain)).isFalse();
}
+
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/log/ExceptionHandlingMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/log/ExceptionHandlingMediumTest.java
index 677cdfa53d7..a479662cd20 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/log/ExceptionHandlingMediumTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/log/ExceptionHandlingMediumTest.java
@@ -21,8 +21,8 @@ package org.sonar.scanner.mediumtest.log;
import java.util.Collections;
import java.util.Map;
+import org.hamcrest.CoreMatchers;
import org.hamcrest.Description;
-import org.hamcrest.Matchers;
import org.hamcrest.TypeSafeMatcher;
import org.junit.BeforeClass;
import org.junit.Rule;
@@ -64,7 +64,7 @@ public class ExceptionHandlingMediumTest {
loader.withCause = false;
thrown.expect(MessageException.class);
thrown.expectMessage("Error loading settings");
- thrown.expectCause(Matchers.nullValue(Throwable.class));
+ thrown.expectCause(CoreMatchers.nullValue(Throwable.class));
batch.start();
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/QualityProfileProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/QualityProfileProviderTest.java
index 43a4ecbaaad..137a2bcbd05 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/QualityProfileProviderTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/QualityProfileProviderTest.java
@@ -39,7 +39,6 @@ import org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
-import static org.mockito.Matchers.isNull;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
@@ -76,11 +75,11 @@ public class QualityProfileProviderTest {
@Test
public void testProvide() {
- when(loader.load(eq("project"), isNull(String.class))).thenReturn(response);
+ when(loader.load("project", null)).thenReturn(response);
ModuleQProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props);
assertResponse(qps);
- verify(loader).load(eq("project"), isNull(String.class));
+ verify(loader).load("project", null);
verifyNoMoreInteractions(loader);
}
@@ -88,6 +87,7 @@ public class QualityProfileProviderTest {
public void testProjectDoesntExist() {
when(projectRepo.exists()).thenReturn(false);
when(loader.loadDefault(anyString())).thenReturn(response);
+ when(props.property(ModuleQProfiles.SONAR_PROFILE_PROP)).thenReturn("profile");
ModuleQProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props);
assertResponse(qps);
@@ -127,7 +127,6 @@ public class QualityProfileProviderTest {
}
private void assertResponse(ModuleQProfiles qps) {
- assertThat(qps.findAll()).hasSize(1);
assertThat(qps.findAll()).extracting("key").containsExactly("profile");
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ModuleInputComponentStoreTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ModuleInputComponentStoreTest.java
index 51c36adc739..5e663c4b57a 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ModuleInputComponentStoreTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ModuleInputComponentStoreTest.java
@@ -36,6 +36,7 @@ import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class ModuleInputComponentStoreTest {
@Rule
@@ -120,10 +121,12 @@ public class ModuleInputComponentStoreTest {
public void should_find_module_components_with_non_global_strategy() {
InputComponentStore inputComponentStore = mock(InputComponentStore.class);
SensorStrategy strategy = new SensorStrategy();
- ModuleInputComponentStore store = new ModuleInputComponentStore(mock(InputModule.class), inputComponentStore, strategy);
+ InputModule module = mock(InputModule.class);
+ when(module.key()).thenReturn("foo");
+ ModuleInputComponentStore store = new ModuleInputComponentStore(module, inputComponentStore, strategy);
store.inputFiles();
- verify(inputComponentStore).filesByModule(any(String.class));
+ verify(inputComponentStore).filesByModule("foo");
String relativePath = "somepath";
store.inputFile(relativePath);