From 6c1cf2b3f49c04efa5b31271cd5affb793525299 Mon Sep 17 00:00:00 2001 From: Janos Gyerik Date: Mon, 11 Sep 2017 10:50:28 +0200 Subject: SONAR-9670 Introduce sonar.branch.longLivedBranches.regex --- .../scanner/analysis/DefaultAnalysisModeTest.java | 127 +++++++-------------- .../scanner/bootstrap/ExtensionInstallerTest.java | 11 +- .../scanner/bootstrap/GlobalAnalysisModeTest.java | 104 +++++++++++++++++ .../bootstrap/GlobalConfigurationProviderTest.java | 4 +- .../sonar/scanner/bootstrap/GlobalModeTest.java | 88 -------------- .../bootstrap/ScannerPluginPredicateTest.java | 2 +- .../bootstrap/ScannerWsClientProviderTest.java | 8 +- .../scanner/bootstrap/ScannerWsClientTest.java | 10 +- .../scanner/config/DefaultConfigurationTest.java | 10 +- .../org/sonar/scanner/cpd/CpdExecutorTest.java | 6 +- .../scanner/mediumtest/ScannerMediumTester.java | 16 +-- .../mediumtest/branch/BranchMediumTest.java | 6 +- .../scanner/mediumtest/tasks/TasksMediumTest.java | 9 ++ .../scanner/postjob/DefaultPostJobContextTest.java | 5 +- .../scanner/report/ComponentsPublisherTest.java | 4 +- .../scanner/report/CoveragePublisherTest.java | 6 +- .../scanner/report/MeasuresPublisherTest.java | 6 +- .../scanner/report/MetadataPublisherTest.java | 11 +- .../sonar/scanner/report/ReportPublisherTest.java | 35 +++--- .../sonar/scanner/report/SourcePublisherTest.java | 14 +-- .../ProjectRepositoriesProviderTest.java | 6 +- .../settings/DefaultSettingsLoaderTest.java | 19 +++ .../scan/BranchConfigurationProviderTest.java | 64 ----------- .../org/sonar/scanner/scan/ModuleIndexerTest.java | 5 +- .../scanner/scan/MutableModuleSettingsTest.java | 10 +- .../scanner/scan/MutableProjectSettingsTest.java | 21 ++-- .../scanner/scan/ProjectReactorValidatorTest.java | 9 +- .../branch/BranchConfigurationProviderTest.java | 65 +++++++++++ .../scan/branch/ProjectBranchesProviderTest.java | 66 +++++++++++ .../scan/filesystem/InputComponentStoreTest.java | 8 +- .../filesystem/ModuleInputComponentStoreTest.java | 6 +- .../sonar/scanner/scan/report/JSONReportTest.java | 6 +- .../scanner/sensor/DefaultSensorContextTest.java | 2 +- .../scanner/source/ZeroCoverageSensorTest.java | 8 +- 34 files changed, 428 insertions(+), 349 deletions(-) create mode 100644 sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalAnalysisModeTest.java delete mode 100644 sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalModeTest.java delete mode 100644 sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/BranchConfigurationProviderTest.java create mode 100644 sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/branch/BranchConfigurationProviderTest.java create mode 100644 sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/branch/ProjectBranchesProviderTest.java (limited to 'sonar-scanner-engine/src/test/java/org') diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/analysis/DefaultAnalysisModeTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/analysis/DefaultAnalysisModeTest.java index 8841dd881c6..5b68fd567a4 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/analysis/DefaultAnalysisModeTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/analysis/DefaultAnalysisModeTest.java @@ -19,122 +19,83 @@ */ package org.sonar.scanner.analysis; -import java.util.HashMap; -import java.util.Map; -import javax.annotation.Nullable; +import java.util.Collections; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.sonar.api.CoreProperties; -import org.sonar.scanner.bootstrap.GlobalProperties; -import org.sonar.scanner.scan.BranchConfiguration; -import org.sonar.scanner.scan.DefaultBranchConfiguration; +import org.sonar.scanner.bootstrap.GlobalAnalysisMode; +import org.sonar.scanner.repository.ProjectRepositories; +import org.sonar.scanner.scan.branch.BranchConfiguration; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class DefaultAnalysisModeTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void regular_analysis_by_default() { - DefaultAnalysisMode mode = createMode(null, null); - assertThat(mode.isPreview()).isFalse(); - assertThat(mode.isPublish()).isTrue(); - } - - @Test(expected = IllegalStateException.class) - public void fail_if_inconsistent() { - createMode(null, CoreProperties.ANALYSIS_MODE_ISSUES); + private BranchConfiguration branchConfig; + private ProjectRepositories projectRepos; + private GlobalAnalysisMode globalMode; + private ValidateIncremental validateIncremental; + + @Before + public void setUp() { + branchConfig = mock(BranchConfiguration.class); + projectRepos = mock(ProjectRepositories.class); + globalMode = mock(GlobalAnalysisMode.class); + validateIncremental = mock(ValidateIncremental.class); } - @Test - public void support_publish_mode() { - DefaultAnalysisMode mode = createMode(CoreProperties.ANALYSIS_MODE_PUBLISH); - - assertThat(mode.isPreview()).isFalse(); - assertThat(mode.isPublish()).isTrue(); - } - - @Test - public void incremental_mode_no_longer_valid() { - thrown.expect(IllegalStateException.class); - thrown.expectMessage("This mode was removed in SonarQube 5.2"); - - createMode(CoreProperties.ANALYSIS_MODE_INCREMENTAL); - } + @Rule + public ExpectedException thrown = ExpectedException.none(); @Test - public void invalidate_mode() { - thrown.expect(IllegalStateException.class); - thrown.expectMessage("[preview, publish, issues]"); + public void dont_scan_all_if_short_lived_branch() { + AnalysisProperties analysisProps = new AnalysisProperties(Collections.singletonMap("sonar.scanAllFiles", "true")); + when(branchConfig.isShortLivingBranch()).thenReturn(true); + DefaultAnalysisMode mode = createmode(analysisProps); - createMode("invalid"); + assertThat(mode.scanAllFiles()).isFalse(); } @Test - public void preview_mode_fallback_issues() { - DefaultAnalysisMode mode = createMode(CoreProperties.ANALYSIS_MODE_PREVIEW); + public void reuse_global_mode() { + when(globalMode.isIssues()).thenReturn(true); + when(globalMode.isPublish()).thenReturn(true); + when(globalMode.isPreview()).thenReturn(true); + DefaultAnalysisMode mode = createmode(new AnalysisProperties(Collections.emptyMap())); assertThat(mode.isIssues()).isTrue(); - assertThat(mode.isPreview()).isFalse(); + assertThat(mode.isPublish()).isTrue(); + assertThat(mode.isPreview()).isTrue(); } @Test - public void scan_all() { - Map props = new HashMap<>(); - props.put(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES); - GlobalProperties globalProps = new GlobalProperties(props); - BranchConfiguration branchConfig = new DefaultBranchConfiguration(); - - AnalysisProperties analysisProps = new AnalysisProperties(new HashMap()); - DefaultAnalysisMode mode = new DefaultAnalysisMode(globalProps, analysisProps, branchConfig); - assertThat(mode.scanAllFiles()).isFalse(); - - props.put("sonar.scanAllFiles", "true"); - analysisProps = new AnalysisProperties(props); - - mode = new DefaultAnalysisMode(globalProps, analysisProps, branchConfig); - assertThat(mode.scanAllFiles()).isTrue(); - - props.put(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_PUBLISH); - analysisProps = new AnalysisProperties(props); + public void scan_all_if_publish() { + when(globalMode.isIssues()).thenReturn(false); + DefaultAnalysisMode mode = createmode(new AnalysisProperties(Collections.emptyMap())); - mode = new DefaultAnalysisMode(globalProps, analysisProps, branchConfig); assertThat(mode.scanAllFiles()).isTrue(); } @Test - public void default_publish_mode() { - DefaultAnalysisMode mode = createMode(null); - assertThat(mode.isPublish()).isTrue(); + public void scan_all_if_property_set() { + AnalysisProperties analysisProps = new AnalysisProperties(Collections.singletonMap("sonar.scanAllFiles", "true")); + DefaultAnalysisMode mode = createmode(analysisProps); + assertThat(mode.scanAllFiles()).isTrue(); } @Test - public void support_issues_mode() { - DefaultAnalysisMode mode = createMode(CoreProperties.ANALYSIS_MODE_ISSUES); + public void dont_scan_all_if_issues_mode() { + when(globalMode.isIssues()).thenReturn(true); + DefaultAnalysisMode mode = createmode(new AnalysisProperties(Collections.emptyMap())); - assertThat(mode.isIssues()).isTrue(); assertThat(mode.scanAllFiles()).isFalse(); } - private static DefaultAnalysisMode createMode(@Nullable String mode) { - return createMode(mode, mode); - } - - private static DefaultAnalysisMode createMode(@Nullable String bootstrapMode, @Nullable String analysisMode) { - Map bootstrapMap = new HashMap<>(); - Map analysisMap = new HashMap<>(); - BranchConfiguration branchConfig = new DefaultBranchConfiguration(); - - if (bootstrapMode != null) { - bootstrapMap.put(CoreProperties.ANALYSIS_MODE, bootstrapMode); - } - if (analysisMode != null) { - analysisMap.put(CoreProperties.ANALYSIS_MODE, analysisMode); - } - return new DefaultAnalysisMode(new GlobalProperties(bootstrapMap), new AnalysisProperties(analysisMap), branchConfig); + private DefaultAnalysisMode createmode(AnalysisProperties analysisProps) { + return new DefaultAnalysisMode(analysisProps, branchConfig, globalMode, projectRepos, validateIncremental); } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ExtensionInstallerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ExtensionInstallerTest.java index 927e9629959..618edbd4295 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ExtensionInstallerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ExtensionInstallerTest.java @@ -28,7 +28,6 @@ import org.sonar.api.BatchExtension; import org.sonar.api.ExtensionProvider; import org.sonar.api.SonarPlugin; import org.sonar.api.SonarRuntime; -import org.sonar.api.batch.AnalysisMode; import org.sonar.core.platform.ComponentContainer; import org.sonar.core.platform.PluginInfo; @@ -38,7 +37,7 @@ import static org.mockito.Mockito.when; public class ExtensionInstallerTest { - GlobalMode mode; + GlobalAnalysisMode mode; ScannerPluginRepository pluginRepository = mock(ScannerPluginRepository.class); private static SonarPlugin newPluginInstance(final Object... extensions) { @@ -51,7 +50,7 @@ public class ExtensionInstallerTest { @Before public void setUp() { - mode = mock(GlobalMode.class); + mode = mock(GlobalAnalysisMode.class); } @Test @@ -60,7 +59,7 @@ public class ExtensionInstallerTest { when(pluginRepository.getPluginInstance("foo")).thenReturn(newPluginInstance(Foo.class, Bar.class)); ComponentContainer container = new ComponentContainer(); - ExtensionInstaller installer = new ExtensionInstaller(mock(SonarRuntime.class), pluginRepository, mock(AnalysisMode.class)); + ExtensionInstaller installer = new ExtensionInstaller(mock(SonarRuntime.class), pluginRepository, mock(GlobalAnalysisMode.class)); installer.install(container, new FooMatcher()); assertThat(container.getComponentByType(Foo.class)).isNotNull(); @@ -72,7 +71,7 @@ public class ExtensionInstallerTest { when(pluginRepository.getPluginInfos()).thenReturn(Arrays.asList(new PluginInfo("foo"))); when(pluginRepository.getPluginInstance("foo")).thenReturn(newPluginInstance(new FooProvider(), new BarProvider())); ComponentContainer container = new ComponentContainer(); - ExtensionInstaller installer = new ExtensionInstaller(mock(SonarRuntime.class), pluginRepository, mock(AnalysisMode.class)); + ExtensionInstaller installer = new ExtensionInstaller(mock(SonarRuntime.class), pluginRepository, mock(GlobalAnalysisMode.class)); installer.install(container, new FooMatcher()); @@ -85,7 +84,7 @@ public class ExtensionInstallerTest { when(pluginRepository.getPluginInfos()).thenReturn(Arrays.asList(new PluginInfo("foo"))); when(pluginRepository.getPluginInstance("foo")).thenReturn(newPluginInstance(new FooBarProvider())); ComponentContainer container = new ComponentContainer(); - ExtensionInstaller installer = new ExtensionInstaller(mock(SonarRuntime.class), pluginRepository, mock(AnalysisMode.class)); + ExtensionInstaller installer = new ExtensionInstaller(mock(SonarRuntime.class), pluginRepository, mock(GlobalAnalysisMode.class)); installer.install(container, new TrueMatcher()); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalAnalysisModeTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalAnalysisModeTest.java new file mode 100644 index 00000000000..0581e431f88 --- /dev/null +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalAnalysisModeTest.java @@ -0,0 +1,104 @@ +/* + * 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.bootstrap; + +import java.util.HashMap; +import java.util.Map; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.api.CoreProperties; + +import static org.assertj.core.api.Assertions.assertThat; + +public class GlobalAnalysisModeTest { + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void testModeNotSupported() { + thrown.expect(IllegalStateException.class); + thrown.expectMessage("[preview, publish, issues]"); + + createMode(CoreProperties.ANALYSIS_MODE, "invalid"); + } + + @Test + public void incremental_mode_no_longer_valid() { + thrown.expect(IllegalStateException.class); + thrown.expectMessage("This mode was removed in SonarQube 5.2"); + + createMode(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_INCREMENTAL); + } + + @Test + public void invalidate_mode() { + thrown.expect(IllegalStateException.class); + thrown.expectMessage("[preview, publish, issues]"); + + createMode(CoreProperties.ANALYSIS_MODE, "invalid"); + } + + @Test + public void testOtherProperty() { + GlobalAnalysisMode mode = createMode(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_PUBLISH); + assertThat(mode.isPreview()).isFalse(); + assertThat(mode.isIssues()).isFalse(); + assertThat(mode.isPublish()).isTrue(); + } + + @Test + public void testIssuesMode() { + GlobalAnalysisMode mode = createMode(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES); + assertThat(mode.isPreview()).isFalse(); + assertThat(mode.isIssues()).isTrue(); + assertThat(mode.isPublish()).isFalse(); + } + + @Test + public void preview_mode_fallback_issues() { + GlobalAnalysisMode mode = createMode(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_PREVIEW); + + assertThat(mode.isIssues()).isTrue(); + assertThat(mode.isPreview()).isFalse(); + } + + @Test + public void testDefault() { + GlobalAnalysisMode mode = createMode(null, null); + assertThat(mode.isPreview()).isFalse(); + assertThat(mode.isIssues()).isFalse(); + assertThat(mode.isPublish()).isTrue(); + } + + @Test(expected = IllegalStateException.class) + public void testInvalidMode() { + createMode(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ANALYSIS); + } + + private GlobalAnalysisMode createMode(String key, String value) { + Map map = new HashMap<>(); + if (key != null) { + map.put(key, value); + } + GlobalProperties props = new GlobalProperties(map); + return new GlobalAnalysisMode(props); + } +} diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalConfigurationProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalConfigurationProviderTest.java index 0ee71d91ecf..6dba27c160a 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalConfigurationProviderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalConfigurationProviderTest.java @@ -45,13 +45,13 @@ public class GlobalConfigurationProviderTest { SettingsLoader settingsLoader; GlobalProperties bootstrapProps; - private GlobalMode mode; + private GlobalAnalysisMode mode; @Before public void prepare() { settingsLoader = mock(SettingsLoader.class); bootstrapProps = new GlobalProperties(Collections.emptyMap()); - mode = mock(GlobalMode.class); + mode = mock(GlobalAnalysisMode.class); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalModeTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalModeTest.java deleted file mode 100644 index fed2ba5aa92..00000000000 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalModeTest.java +++ /dev/null @@ -1,88 +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.bootstrap; - -import java.util.HashMap; -import java.util.Map; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.sonar.api.CoreProperties; - -import static org.assertj.core.api.Assertions.assertThat; - -public class GlobalModeTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void testModeNotSupported() { - thrown.expect(IllegalStateException.class); - thrown.expectMessage("[preview, publish, issues]"); - - createMode(CoreProperties.ANALYSIS_MODE, "invalid"); - } - - @Test - public void testOtherProperty() { - GlobalMode mode = createMode(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_PUBLISH); - assertThat(mode.isPreview()).isFalse(); - assertThat(mode.isIssues()).isFalse(); - assertThat(mode.isPublish()).isTrue(); - } - - @Test - public void testIssuesMode() { - GlobalMode mode = createMode(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES); - assertThat(mode.isPreview()).isFalse(); - assertThat(mode.isIssues()).isTrue(); - assertThat(mode.isPublish()).isFalse(); - } - - @Test - public void preview_mode_fallback_issues() { - GlobalMode mode = createMode(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_PREVIEW); - - assertThat(mode.isIssues()).isTrue(); - assertThat(mode.isPreview()).isFalse(); - } - - @Test - public void testDefault() { - GlobalMode mode = createMode(null, null); - assertThat(mode.isPreview()).isFalse(); - assertThat(mode.isIssues()).isFalse(); - assertThat(mode.isPublish()).isTrue(); - } - - @Test(expected = IllegalStateException.class) - public void testInvalidMode() { - createMode(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ANALYSIS); - } - - private GlobalMode createMode(String key, String value) { - Map map = new HashMap<>(); - if (key != null) { - map.put(key, value); - } - GlobalProperties props = new GlobalProperties(map); - return new GlobalMode(props); - } -} diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginPredicateTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginPredicateTest.java index 6ae96de59e8..cdc5938ef35 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginPredicateTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginPredicateTest.java @@ -30,7 +30,7 @@ import static org.mockito.Mockito.when; public class ScannerPluginPredicateTest { private MapSettings settings = new MapSettings(); - private GlobalMode mode = mock(GlobalMode.class); + private GlobalAnalysisMode mode = mock(GlobalAnalysisMode.class); @Test public void accept_if_no_inclusions_nor_exclusions() { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerWsClientProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerWsClientProviderTest.java index 07c68101a65..7a9a490476b 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerWsClientProviderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerWsClientProviderTest.java @@ -37,7 +37,7 @@ public class ScannerWsClientProviderTest { public void provide_client_with_default_settings() { GlobalProperties settings = new GlobalProperties(new HashMap<>()); - ScannerWsClient client = underTest.provide(settings, env, new GlobalMode(new GlobalProperties(Collections.emptyMap()))); + ScannerWsClient client = underTest.provide(settings, env, new GlobalAnalysisMode(new GlobalProperties(Collections.emptyMap()))); assertThat(client).isNotNull(); assertThat(client.baseUrl()).isEqualTo("http://localhost:9000/"); @@ -57,7 +57,7 @@ public class ScannerWsClientProviderTest { props.put("sonar.ws.timeout", "42"); GlobalProperties settings = new GlobalProperties(props); - ScannerWsClient client = underTest.provide(settings, env, new GlobalMode(new GlobalProperties(Collections.emptyMap()))); + ScannerWsClient client = underTest.provide(settings, env, new GlobalAnalysisMode(new GlobalProperties(Collections.emptyMap()))); assertThat(client).isNotNull(); HttpConnector httpConnector = (HttpConnector) client.wsConnector(); @@ -68,8 +68,8 @@ public class ScannerWsClientProviderTest { @Test public void build_singleton() { GlobalProperties settings = new GlobalProperties(new HashMap<>()); - ScannerWsClient first = underTest.provide(settings, env, new GlobalMode(new GlobalProperties(Collections.emptyMap()))); - ScannerWsClient second = underTest.provide(settings, env, new GlobalMode(new GlobalProperties(Collections.emptyMap()))); + ScannerWsClient first = underTest.provide(settings, env, new GlobalAnalysisMode(new GlobalProperties(Collections.emptyMap()))); + ScannerWsClient second = underTest.provide(settings, env, new GlobalAnalysisMode(new GlobalProperties(Collections.emptyMap()))); assertThat(first).isSameAs(second); } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerWsClientTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerWsClientTest.java index 3b58773dd66..fa7c8b08916 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerWsClientTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerWsClientTest.java @@ -55,7 +55,7 @@ public class ScannerWsClientTest { when(wsClient.wsConnector().call(request)).thenReturn(response); logTester.setLevel(LoggerLevel.DEBUG); - ScannerWsClient underTest = new ScannerWsClient(wsClient, false, new GlobalMode(new GlobalProperties(Collections.emptyMap()))); + ScannerWsClient underTest = new ScannerWsClient(wsClient, false, new GlobalAnalysisMode(new GlobalProperties(Collections.emptyMap()))); WsResponse result = underTest.call(request); @@ -78,7 +78,7 @@ public class ScannerWsClientTest { WsResponse response = newResponse().setCode(401); when(wsClient.wsConnector().call(request)).thenReturn(response); - new ScannerWsClient(wsClient, false, new GlobalMode(new GlobalProperties(Collections.emptyMap()))).call(request); + new ScannerWsClient(wsClient, false, new GlobalAnalysisMode(new GlobalProperties(Collections.emptyMap()))).call(request); } @Test @@ -90,7 +90,7 @@ public class ScannerWsClientTest { WsResponse response = newResponse().setCode(401); when(wsClient.wsConnector().call(request)).thenReturn(response); - new ScannerWsClient(wsClient, /* credentials are configured */true, new GlobalMode(new GlobalProperties(Collections.emptyMap()))).call(request); + new ScannerWsClient(wsClient, /* credentials are configured */true, new GlobalAnalysisMode(new GlobalProperties(Collections.emptyMap()))).call(request); } @Test @@ -104,7 +104,7 @@ public class ScannerWsClientTest { .setContent("{\"errors\":[{\"msg\":\"missing scan permission\"}, {\"msg\":\"missing another permission\"}]}"); when(wsClient.wsConnector().call(request)).thenReturn(response); - new ScannerWsClient(wsClient, true, new GlobalMode(new GlobalProperties(Collections.emptyMap()))).call(request); + new ScannerWsClient(wsClient, true, new GlobalAnalysisMode(new GlobalProperties(Collections.emptyMap()))).call(request); } @Test @@ -118,7 +118,7 @@ public class ScannerWsClientTest { .setContent("{\"errors\":[{\"msg\":\"Boo! bad request! bad!\"}]}"); when(wsClient.wsConnector().call(request)).thenReturn(response); - new ScannerWsClient(wsClient, true, new GlobalMode(new GlobalProperties(Collections.emptyMap()))).call(request); + new ScannerWsClient(wsClient, true, new GlobalAnalysisMode(new GlobalProperties(Collections.emptyMap()))).call(request); } private MockWsResponse newResponse() { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/config/DefaultConfigurationTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/config/DefaultConfigurationTest.java index 0432e2511a0..adf55780f1d 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/config/DefaultConfigurationTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/config/DefaultConfigurationTest.java @@ -23,7 +23,6 @@ import com.google.common.collect.ImmutableMap; import java.util.Arrays; import org.junit.Rule; import org.junit.Test; -import org.sonar.api.batch.AnalysisMode; import org.sonar.api.config.Configuration; import org.sonar.api.config.Encryption; import org.sonar.api.config.PropertyDefinition; @@ -31,6 +30,7 @@ import org.sonar.api.config.PropertyDefinitions; import org.sonar.api.config.PropertyFieldDefinition; import org.sonar.api.utils.log.LogTester; import org.sonar.api.utils.log.LoggerLevel; +import org.sonar.scanner.bootstrap.GlobalAnalysisMode; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; @@ -46,7 +46,7 @@ public class DefaultConfigurationTest { Configuration config = new DefaultConfiguration(new PropertyDefinitions(Arrays.asList( PropertyDefinition.builder("single").multiValues(false).build(), PropertyDefinition.builder("multiA").multiValues(true).build())), new Encryption(null), - mock(AnalysisMode.class), + mock(GlobalAnalysisMode.class), ImmutableMap.of("single", "foo", "multiA", "a,b", "notDeclared", "c,d")) { }; @@ -74,7 +74,7 @@ public class DefaultConfigurationTest { Configuration config = new DefaultConfiguration(new PropertyDefinitions(Arrays.asList( PropertyDefinition.builder("props").fields(PropertyFieldDefinition.build("foo1").name("Foo1").build(), PropertyFieldDefinition.build("foo2").name("Foo2").build()).build())), new Encryption(null), - mock(AnalysisMode.class), + mock(GlobalAnalysisMode.class), ImmutableMap.of("props", "1,2", "props.1.foo1", "a", "props.1.foo2", "b")) { }; @@ -94,7 +94,7 @@ public class DefaultConfigurationTest { Configuration config = new DefaultConfiguration(new PropertyDefinitions(Arrays.asList( PropertyDefinition.builder("single").multiValues(false).defaultValue("default").build(), PropertyDefinition.builder("multiA").multiValues(true).defaultValue("foo,bar").build())), new Encryption(null), - mock(AnalysisMode.class), + mock(GlobalAnalysisMode.class), ImmutableMap.of()) { }; @@ -125,7 +125,7 @@ public class DefaultConfigurationTest { private String[] getStringArray(String value) { return new DefaultConfiguration(new PropertyDefinitions(Arrays.asList( PropertyDefinition.builder("multi").multiValues(true).build())), new Encryption(null), - mock(AnalysisMode.class), + mock(GlobalAnalysisMode.class), ImmutableMap.of("multi", value)) { }.getStringArray("multi"); } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdExecutorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdExecutorTest.java index 0d0ead878ab..2ef29f1d751 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdExecutorTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdExecutorTest.java @@ -30,7 +30,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; -import org.sonar.api.batch.AnalysisMode; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.fs.internal.DefaultInputModule; @@ -42,13 +41,14 @@ import org.sonar.duplications.block.Block; import org.sonar.duplications.block.ByteArray; import org.sonar.duplications.index.CloneGroup; import org.sonar.duplications.index.ClonePart; +import org.sonar.scanner.analysis.DefaultAnalysisMode; import org.sonar.scanner.cpd.index.SonarCpdBlockIndex; import org.sonar.scanner.protocol.output.ScannerReport.Duplicate; import org.sonar.scanner.protocol.output.ScannerReport.Duplication; import org.sonar.scanner.protocol.output.ScannerReportReader; import org.sonar.scanner.protocol.output.ScannerReportWriter; import org.sonar.scanner.report.ReportPublisher; -import org.sonar.scanner.scan.BranchConfiguration; +import org.sonar.scanner.scan.branch.BranchConfiguration; import org.sonar.scanner.scan.filesystem.InputComponentStore; import static org.assertj.core.api.Assertions.assertThat; @@ -90,7 +90,7 @@ public class CpdExecutorTest { index = new SonarCpdBlockIndex(publisher, settings); DefaultInputModule inputModule = TestInputFileBuilder.newDefaultInputModule("foo", baseDir); - componentStore = new InputComponentStore(inputModule, mock(AnalysisMode.class), mock(BranchConfiguration.class)); + componentStore = new InputComponentStore(inputModule, mock(DefaultAnalysisMode.class), mock(BranchConfiguration.class)); executor = new CpdExecutor(settings, index, publisher, componentStore, branchConfig); reader = new ScannerReportReader(outputDir); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java index df04b69b62e..ffd845e3479 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java @@ -52,8 +52,7 @@ import org.sonar.api.utils.DateUtils; import org.sonar.batch.bootstrapper.Batch; import org.sonar.batch.bootstrapper.EnvironmentInformation; import org.sonar.batch.bootstrapper.LogOutput; -import org.sonar.scanner.bootstrap.GlobalConfiguration; -import org.sonar.scanner.bootstrap.GlobalMode; +import org.sonar.scanner.bootstrap.GlobalAnalysisMode; import org.sonar.scanner.issue.tracking.ServerLineHashesLoader; import org.sonar.scanner.protocol.input.ScannerInput.ServerIssue; import org.sonar.scanner.report.ReportPublisher; @@ -68,8 +67,11 @@ import org.sonar.scanner.repository.settings.SettingsLoader; import org.sonar.scanner.rule.ActiveRulesLoader; import org.sonar.scanner.rule.LoadedActiveRule; import org.sonar.scanner.rule.RulesLoader; -import org.sonar.scanner.scan.BranchConfiguration; -import org.sonar.scanner.scan.BranchConfigurationLoader; +import org.sonar.scanner.scan.ProjectSettings; +import org.sonar.scanner.scan.branch.BranchConfiguration; +import org.sonar.scanner.scan.branch.BranchConfigurationLoader; +import org.sonar.scanner.scan.branch.BranchType; +import org.sonar.scanner.scan.branch.ProjectBranches; import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile; import org.sonarqube.ws.Rules.ListResponse.Rule; @@ -239,7 +241,7 @@ public class ScannerMediumTester extends ExternalResource { throw new IllegalStateException(e); } registerCoreMetrics(); - globalProperties.put(GlobalMode.MEDIUM_TEST_ENABLED, "true"); + globalProperties.put(GlobalAnalysisMode.MEDIUM_TEST_ENABLED, "true"); globalProperties.put(ReportPublisher.KEEP_REPORT_PROP_KEY, "true"); globalProperties.put("sonar.userHome", userHome.toString()); } @@ -420,7 +422,7 @@ public class ScannerMediumTester extends ExternalResource { } } - public ScannerMediumTester setBranchType(BranchConfiguration.BranchType branchType) { + public ScannerMediumTester setBranchType(BranchType branchType) { branchConfiguration.branchType = branchType; return this; } @@ -437,7 +439,7 @@ public class ScannerMediumTester extends ExternalResource { private class FakeBranchConfigurationLoader implements BranchConfigurationLoader { @Override - public BranchConfiguration load(String projectKey, GlobalConfiguration settings) { + public BranchConfiguration load(ProjectSettings settings, ProjectBranches branches) { return branchConfiguration; } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/branch/BranchMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/branch/BranchMediumTest.java index 58d9133dddc..2461e5ea786 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/branch/BranchMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/branch/BranchMediumTest.java @@ -34,7 +34,7 @@ import org.sonar.scanner.mediumtest.ScannerMediumTester; import org.sonar.scanner.mediumtest.TaskResult; import org.sonar.scanner.protocol.output.ScannerReport; import org.sonar.scanner.repository.FileData; -import org.sonar.scanner.scan.BranchConfiguration; +import org.sonar.scanner.scan.branch.BranchType; import org.sonar.xoo.XooPlugin; import org.sonar.xoo.rule.XooRulesDefinition; @@ -80,7 +80,7 @@ public class BranchMediumTest { assertThat(result.getReportReader().readFileSource(fileId)).isNotNull(); // file is skipped for short branches (no report, no coverage, no duplications) - TaskResult result2 = getResult(tester.setBranchType(BranchConfiguration.BranchType.SHORT)); + TaskResult result2 = getResult(tester.setBranchType(BranchType.SHORT)); assertThat(result2.getReportComponent(result2.inputFile(FILE_PATH).key())).isNull(); assertThat(result2.getReportReader().readChangesets(fileId)).isNull(); assertThat(result2.getReportReader().hasCoverage(fileId)).isFalse(); @@ -95,7 +95,7 @@ public class BranchMediumTest { TaskResult result = getResult(tester .setBranchName(branchName) .setBranchTarget(branchTarget) - .setBranchType(BranchConfiguration.BranchType.SHORT)); + .setBranchType(BranchType.SHORT)); ScannerReport.Metadata metadata = result.getReportReader().readMetadata(); assertThat(metadata.getBranchName()).isEqualTo(branchName); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tasks/TasksMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tasks/TasksMediumTest.java index 8d679016b61..d7cb80f787e 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tasks/TasksMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tasks/TasksMediumTest.java @@ -21,6 +21,7 @@ package org.sonar.scanner.mediumtest.tasks; import static org.assertj.core.api.Assertions.assertThat; +import java.io.File; import java.util.Arrays; import java.util.List; @@ -28,6 +29,7 @@ import org.assertj.core.api.Condition; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.junit.rules.TemporaryFolder; import org.sonar.api.SonarPlugin; import org.sonar.api.task.Task; import org.sonar.api.task.TaskDefinition; @@ -45,6 +47,9 @@ public class TasksMediumTest { @Rule public LogTester logTester = new LogTester(); + @Rule + public TemporaryFolder temp = new TemporaryFolder(); + @Rule public ScannerMediumTester tester = new ScannerMediumTester() .registerPlugin("faketask", new FakeTaskPlugin()); @@ -87,12 +92,16 @@ public class TasksMediumTest { @Test public void incrementalNotFound() throws Exception { + File baseDir = temp.newFolder(); thrown.expect(MessageException.class); thrown.expectMessage( "Incremental mode is not available. Please contact your administrator."); tester.newTask() .properties(ImmutableMap.builder() + .put("sonar.projectKey", "key") + .put("sonar.projectBaseDir", baseDir.getAbsolutePath()) + .put("sonar.sources", ".") .put("sonar.incremental", "true").build()) .execute(); } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.java index f39cafcadb7..1bbd510f6e7 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.java @@ -31,9 +31,10 @@ import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.api.batch.postjob.issue.PostJobIssue; import org.sonar.api.batch.rule.Severity; import org.sonar.api.config.internal.MapSettings; +import org.sonar.scanner.analysis.DefaultAnalysisMode; import org.sonar.scanner.issue.IssueCache; import org.sonar.scanner.issue.tracking.TrackedIssue; -import org.sonar.scanner.scan.BranchConfiguration; +import org.sonar.scanner.scan.branch.BranchConfiguration; import org.sonar.scanner.scan.filesystem.InputComponentStore; import static org.assertj.core.api.Assertions.assertThat; @@ -55,7 +56,7 @@ public class DefaultPostJobContextTest { public void setUp() throws IOException { issueCache = mock(IssueCache.class); DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule("foo", temp.newFolder()); - componentStore = new InputComponentStore(rootModule, mock(AnalysisMode.class), mock(BranchConfiguration.class)); + componentStore = new InputComponentStore(rootModule, mock(DefaultAnalysisMode.class), mock(BranchConfiguration.class)); settings = new MapSettings(); analysisMode = mock(AnalysisMode.class); context = new DefaultPostJobContext(settings.asConfig(), settings, issueCache, componentStore, analysisMode); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java index a03afd14359..5ebfeb7e852 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java @@ -45,8 +45,8 @@ import org.sonar.scanner.protocol.output.ScannerReport.Component.FileStatus; import org.sonar.scanner.protocol.output.ScannerReport.ComponentLink.ComponentLinkType; import org.sonar.scanner.protocol.output.ScannerReportReader; import org.sonar.scanner.protocol.output.ScannerReportWriter; -import org.sonar.scanner.scan.BranchConfiguration; -import org.sonar.scanner.scan.BranchConfiguration.BranchType; +import org.sonar.scanner.scan.branch.BranchConfiguration; +import org.sonar.scanner.scan.branch.BranchType; import org.sonar.scanner.scan.DefaultComponentTree; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/CoveragePublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/CoveragePublisherTest.java index f2a0e614bae..b517367c309 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/CoveragePublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/CoveragePublisherTest.java @@ -25,17 +25,17 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import org.sonar.api.batch.AnalysisMode; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure; import org.sonar.api.measures.CoreMetrics; import org.sonar.core.util.CloseableIterator; +import org.sonar.scanner.analysis.DefaultAnalysisMode; import org.sonar.scanner.protocol.output.ScannerReport.LineCoverage; import org.sonar.scanner.protocol.output.ScannerReportReader; import org.sonar.scanner.protocol.output.ScannerReportWriter; -import org.sonar.scanner.scan.BranchConfiguration; +import org.sonar.scanner.scan.branch.BranchConfiguration; import org.sonar.scanner.scan.filesystem.InputComponentStore; import org.sonar.scanner.scan.measure.MeasureCache; @@ -59,7 +59,7 @@ public class CoveragePublisherTest { String moduleKey = "foo"; inputFile = new TestInputFileBuilder(moduleKey, "src/Foo.php").setLines(5).build(); DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule(moduleKey, temp.newFolder()); - InputComponentStore componentCache = new InputComponentStore(rootModule, mock(AnalysisMode.class), mock(BranchConfiguration.class)); + InputComponentStore componentCache = new InputComponentStore(rootModule, mock(DefaultAnalysisMode.class), mock(BranchConfiguration.class)); componentCache.put(inputFile); measureCache = mock(MeasureCache.class); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MeasuresPublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MeasuresPublisherTest.java index 31a60b633c8..b42567c73cc 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MeasuresPublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MeasuresPublisherTest.java @@ -28,18 +28,18 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; -import org.sonar.api.batch.AnalysisMode; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure; import org.sonar.api.measures.CoreMetrics; import org.sonar.core.util.CloseableIterator; +import org.sonar.scanner.analysis.DefaultAnalysisMode; import org.sonar.scanner.deprecated.test.TestPlanBuilder; import org.sonar.scanner.protocol.output.ScannerReport; import org.sonar.scanner.protocol.output.ScannerReportReader; import org.sonar.scanner.protocol.output.ScannerReportWriter; -import org.sonar.scanner.scan.BranchConfiguration; +import org.sonar.scanner.scan.branch.BranchConfiguration; import org.sonar.scanner.scan.filesystem.InputComponentStore; import org.sonar.scanner.scan.measure.MeasureCache; @@ -70,7 +70,7 @@ public class MeasuresPublisherTest { String moduleKey = "foo"; inputModule = TestInputFileBuilder.newDefaultInputModule(moduleKey, temp.newFolder()); inputFile = new TestInputFileBuilder(moduleKey, "src/Foo.php").setPublish(true).build(); - InputComponentStore componentCache = new InputComponentStore(inputModule, mock(AnalysisMode.class), mock(BranchConfiguration.class)); + InputComponentStore componentCache = new InputComponentStore(inputModule, mock(DefaultAnalysisMode.class), mock(BranchConfiguration.class)); componentCache.put(inputFile); measureCache = mock(MeasureCache.class); when(measureCache.byComponentKey(anyString())).thenReturn(Collections.>emptyList()); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MetadataPublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MetadataPublisherTest.java index 3bc70f9c875..f00269ac4b1 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MetadataPublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MetadataPublisherTest.java @@ -28,7 +28,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.api.CoreProperties; -import org.sonar.api.batch.AnalysisMode; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.batch.fs.internal.InputModuleHierarchy; @@ -36,6 +35,7 @@ import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.api.config.internal.MapSettings; import org.sonar.core.config.ScannerProperties; import org.sonar.scanner.ProjectAnalysisInfo; +import org.sonar.scanner.analysis.DefaultAnalysisMode; import org.sonar.scanner.bootstrap.ScannerPlugin; import org.sonar.scanner.bootstrap.ScannerPluginRepository; import org.sonar.scanner.cpd.CpdSettings; @@ -44,7 +44,8 @@ import org.sonar.scanner.protocol.output.ScannerReportReader; import org.sonar.scanner.protocol.output.ScannerReportWriter; import org.sonar.scanner.rule.ModuleQProfiles; import org.sonar.scanner.rule.QProfile; -import org.sonar.scanner.scan.BranchConfiguration; +import org.sonar.scanner.scan.branch.BranchConfiguration; +import org.sonar.scanner.scan.branch.BranchType; import static java.util.Arrays.asList; import static java.util.Collections.emptyMap; @@ -65,7 +66,7 @@ public class MetadataPublisherTest { private ProjectAnalysisInfo projectAnalysisInfo; private CpdSettings cpdSettings; private InputModuleHierarchy inputModuleHierarchy; - private AnalysisMode analysisMode; + private DefaultAnalysisMode analysisMode; private ScannerPluginRepository pluginRepository; private BranchConfiguration branches; @@ -85,7 +86,7 @@ public class MetadataPublisherTest { rootModule = new DefaultInputModule(def.setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder()), TestInputFileBuilder.nextBatchId()); inputModuleHierarchy = mock(InputModuleHierarchy.class); when(inputModuleHierarchy.root()).thenReturn(rootModule); - analysisMode = mock(AnalysisMode.class); + analysisMode = mock(DefaultAnalysisMode.class); branches = mock(BranchConfiguration.class); underTest = new MetadataPublisher(projectAnalysisInfo, inputModuleHierarchy, settings.asConfig(), qProfiles, cpdSettings, analysisMode, pluginRepository, branches); @@ -168,7 +169,7 @@ public class MetadataPublisherTest { public void write_long_lived_branch_info() throws Exception { String branchName = "long-lived"; when(branches.branchName()).thenReturn(branchName); - when(branches.branchType()).thenReturn(BranchConfiguration.BranchType.LONG); + when(branches.branchType()).thenReturn(BranchType.LONG); File outputDir = temp.newFolder(); underTest.publish(new ScannerReportWriter(outputDir)); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java index e7da36601b0..e3bccbd64ff 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java @@ -45,8 +45,9 @@ import org.sonar.api.utils.log.LoggerLevel; import org.sonar.core.config.CorePropertyDefinitions; import org.sonar.core.config.ScannerProperties; import org.sonar.scanner.analysis.DefaultAnalysisMode; +import org.sonar.scanner.bootstrap.GlobalAnalysisMode; import org.sonar.scanner.bootstrap.ScannerWsClient; -import org.sonar.scanner.scan.BranchConfiguration; +import org.sonar.scanner.scan.branch.BranchConfiguration; import org.sonarqube.ws.WsCe; import org.sonarqube.ws.client.HttpException; import org.sonarqube.ws.client.WsRequest; @@ -59,7 +60,7 @@ 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 static org.sonar.scanner.scan.BranchConfiguration.BranchType.SHORT; +import static org.sonar.scanner.scan.branch.BranchType.SHORT; public class ReportPublisherTest { @@ -72,7 +73,8 @@ public class ReportPublisherTest { @Rule public ExpectedException exception = ExpectedException.none(); - DefaultAnalysisMode mode = mock(DefaultAnalysisMode.class); + DefaultAnalysisMode analysisFlags = mock(DefaultAnalysisMode.class); + GlobalAnalysisMode mode = mock(GlobalAnalysisMode.class); MapSettings settings = new MapSettings(new PropertyDefinitions(CorePropertyDefinitions.all())); ScannerWsClient wsClient; Server server = mock(Server.class); @@ -92,8 +94,8 @@ public class ReportPublisherTest { @Test public void log_and_dump_information_about_report_uploading() throws IOException { - ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class), - new ReportPublisherStep[0], branchConfiguration); + ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, analysisFlags, moduleHierarchy, mode, + mock(TempFolder.class), new ReportPublisherStep[0], branchConfiguration); settings.setProperty(ScannerProperties.ORGANIZATION, "MyOrg"); underTest.logSuccess("TASK-123"); @@ -116,8 +118,8 @@ public class ReportPublisherTest { @Test public void parse_upload_error_message() throws IOException { - ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class), - new ReportPublisherStep[0], branchConfiguration); + ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, analysisFlags, moduleHierarchy, mode, + mock(TempFolder.class), new ReportPublisherStep[0], branchConfiguration); HttpException ex = new HttpException("url", 404, "{\"errors\":[{\"msg\":\"Organization with key 'MyOrg' does not exist\"}]}"); WsResponse response = mock(WsResponse.class); when(response.failIfNotSuccessful()).thenThrow(ex); @@ -131,7 +133,7 @@ public class ReportPublisherTest { @Test public void log_public_url_if_defined() throws IOException { when(server.getPublicRootUrl()).thenReturn("https://publicserver/sonarqube"); - ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class), + ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, analysisFlags, moduleHierarchy, mode, mock(TempFolder.class), new ReportPublisherStep[0], branchConfiguration); underTest.logSuccess("TASK-123"); @@ -153,7 +155,7 @@ public class ReportPublisherTest { @Test public void fail_if_public_url_malformed() throws IOException { when(server.getPublicRootUrl()).thenReturn("invalid"); - ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class), + ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, analysisFlags, moduleHierarchy, mode, mock(TempFolder.class), new ReportPublisherStep[0], branchConfiguration); exception.expect(MessageException.class); @@ -163,7 +165,7 @@ public class ReportPublisherTest { @Test public void log_but_not_dump_information_when_report_is_not_uploaded() { - ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class), + ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, analysisFlags, moduleHierarchy, mode, mock(TempFolder.class), new ReportPublisherStep[0], branchConfiguration); underTest.logSuccess(/* report not uploaded, no server task */null); @@ -181,7 +183,7 @@ public class ReportPublisherTest { 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), + ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, analysisFlags, moduleHierarchy, mode, mock(TempFolder.class), new ReportPublisherStep[0], branchConfiguration); underTest.start(); @@ -193,7 +195,8 @@ public class ReportPublisherTest { public void should_delete_report_by_default() throws IOException { 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], + ReportPublisher job = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, analysisFlags, moduleHierarchy, mode, mock(TempFolder.class), + new ReportPublisherStep[0], branchConfiguration); job.start(); @@ -203,7 +206,7 @@ public class ReportPublisherTest { @Test public void test_ws_parameters() throws Exception { - ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class), + ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, analysisFlags, moduleHierarchy, mode, mock(TempFolder.class), new ReportPublisherStep[0], branchConfiguration); settings.setProperty(ScannerProperties.ORGANIZATION, "MyOrg"); @@ -232,10 +235,10 @@ public class ReportPublisherTest { @Test public void test_send_incremental_characteristic() throws Exception { - ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class), + ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, analysisFlags, moduleHierarchy, mode, mock(TempFolder.class), new ReportPublisherStep[0], branchConfiguration); - when(mode.isIncremental()).thenReturn(true); + when(analysisFlags.isIncremental()).thenReturn(true); String orgName = "MyOrg"; settings.setProperty(ScannerProperties.ORGANIZATION, orgName); @@ -265,7 +268,7 @@ public class ReportPublisherTest { @Test public void test_send_branches_characteristics() throws Exception { - ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class), + ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, analysisFlags, moduleHierarchy, mode, mock(TempFolder.class), new ReportPublisherStep[0], branchConfiguration); String orgName = "MyOrg"; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/SourcePublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/SourcePublisherTest.java index b859b3962e8..a343584a911 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/SourcePublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/SourcePublisherTest.java @@ -27,13 +27,13 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import org.sonar.api.batch.AnalysisMode; import org.sonar.api.batch.fs.InputFile.Status; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; +import org.sonar.scanner.analysis.DefaultAnalysisMode; import org.sonar.scanner.protocol.output.ScannerReportWriter; -import org.sonar.scanner.scan.BranchConfiguration; +import org.sonar.scanner.scan.branch.BranchConfiguration; import org.sonar.scanner.scan.filesystem.InputComponentStore; import static org.assertj.core.api.Assertions.assertThat; @@ -48,7 +48,7 @@ public class SourcePublisherTest { private File sourceFile; private ScannerReportWriter writer; private DefaultInputFile inputFile; - private AnalysisMode analysisMode; + private DefaultAnalysisMode analysisFlags; @Before public void prepare() throws IOException { @@ -62,8 +62,8 @@ public class SourcePublisherTest { .build(); DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule(moduleKey, baseDir); - analysisMode = mock(AnalysisMode.class); - InputComponentStore componentStore = new InputComponentStore(rootModule, analysisMode, mock(BranchConfiguration.class)); + analysisFlags = mock(DefaultAnalysisMode.class); + InputComponentStore componentStore = new InputComponentStore(rootModule, analysisFlags, mock(BranchConfiguration.class)); componentStore.put(inputFile); publisher = new SourcePublisher(componentStore); @@ -124,7 +124,7 @@ public class SourcePublisherTest { @Test public void publishChangedSourceInIncrementalMode() throws Exception { - when(analysisMode.isIncremental()).thenReturn(true); + when(analysisFlags.isIncremental()).thenReturn(true); FileUtils.write(sourceFile, "1\n2\n3\n4\n5", StandardCharsets.ISO_8859_1); inputFile.setStatus(Status.CHANGED); @@ -136,7 +136,7 @@ public class SourcePublisherTest { @Test public void dontPublishUnchangedSourceInIncrementalMode() throws Exception { - when(analysisMode.isIncremental()).thenReturn(true); + when(analysisFlags.isIncremental()).thenReturn(true); FileUtils.write(sourceFile, "foo", StandardCharsets.ISO_8859_1); inputFile.setStatus(Status.SAME); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/ProjectRepositoriesProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/ProjectRepositoriesProviderTest.java index e7c5b810a10..1935ab503d7 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/ProjectRepositoriesProviderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/ProjectRepositoriesProviderTest.java @@ -27,8 +27,8 @@ import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.sonar.api.batch.bootstrap.ProjectKey; -import org.sonar.scanner.analysis.DefaultAnalysisMode; -import org.sonar.scanner.scan.BranchConfiguration; +import org.sonar.scanner.bootstrap.GlobalAnalysisMode; +import org.sonar.scanner.scan.branch.BranchConfiguration; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.any; @@ -47,7 +47,7 @@ public class ProjectRepositoriesProviderTest { @Mock private ProjectKey projectKey; @Mock - private DefaultAnalysisMode mode; + private GlobalAnalysisMode mode; @Mock private BranchConfiguration branchConfiguration; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/settings/DefaultSettingsLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/settings/DefaultSettingsLoaderTest.java index f2ecbe4d5fb..2171a2b8809 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/settings/DefaultSettingsLoaderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/settings/DefaultSettingsLoaderTest.java @@ -19,7 +19,11 @@ */ package org.sonar.scanner.repository.settings; +import java.io.IOException; +import org.junit.Before; import org.junit.Test; +import org.sonar.scanner.WsTestUtil; +import org.sonar.scanner.bootstrap.ScannerWsClient; import org.sonarqube.ws.Settings.FieldValues; import org.sonarqube.ws.Settings.FieldValues.Value; import org.sonarqube.ws.Settings.FieldValues.Value.Builder; @@ -29,8 +33,17 @@ import org.sonarqube.ws.Settings.Values; import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; +import static org.mockito.Mockito.mock; public class DefaultSettingsLoaderTest { + private ScannerWsClient wsClient; + private DefaultSettingsLoader loader; + + @Before + public void prepare() throws IOException { + wsClient = mock(ScannerWsClient.class); + loader = new DefaultSettingsLoader(wsClient); + } @Test public void should_load_global_multivalue_settings() { @@ -69,4 +82,10 @@ public class DefaultSettingsLoaderTest { entry("sonar.issue.exclusions.multicriteria.2.rulepattern", "*:S456")); } + @Test + public void continue_on_error() { + WsTestUtil.mockException(wsClient, DefaultSettingsLoader.URL + "?component=project", new IllegalStateException()); + assertThat(loader.load("project")).isEmpty(); + } + } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/BranchConfigurationProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/BranchConfigurationProviderTest.java deleted file mode 100644 index 41c3f9a17be..00000000000 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/BranchConfigurationProviderTest.java +++ /dev/null @@ -1,64 +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.scan; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import org.junit.Before; -import org.junit.Test; -import org.sonar.scanner.bootstrap.GlobalConfiguration; -import org.sonar.scanner.scan.BranchConfiguration.BranchType; - -public class BranchConfigurationProviderTest { - private BranchConfigurationProvider provider = new BranchConfigurationProvider(); - private GlobalConfiguration globalConfiguration; - private BranchConfigurationLoader loader; - private BranchConfiguration config; - - @Before - public void setUp() { - globalConfiguration = mock(GlobalConfiguration.class); - loader = mock(BranchConfigurationLoader.class); - config = mock(BranchConfiguration.class); - } - - @Test - public void should_cache_config() { - BranchConfiguration configuration = provider.provide(null, () -> "project", globalConfiguration); - assertThat(provider.provide(null, () -> "project", globalConfiguration)).isSameAs(configuration); - } - - @Test - public void should_use_loader() { - when(loader.load("key", globalConfiguration)).thenReturn(config); - BranchConfiguration branchConfig = provider.provide(loader, () -> "key", globalConfiguration); - - assertThat(branchConfig).isSameAs(config); - } - - @Test - public void should_return_default_if_no_loader() { - BranchConfiguration configuration = provider.provide(null, () -> "project", globalConfiguration); - assertThat(configuration.branchTarget()).isNull(); - assertThat(configuration.branchType()).isEqualTo(BranchType.LONG); - } -} diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ModuleIndexerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ModuleIndexerTest.java index e9d075d327e..fbaca69eeca 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ModuleIndexerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ModuleIndexerTest.java @@ -21,10 +21,11 @@ package org.sonar.scanner.scan; import java.util.Arrays; import org.junit.Test; -import org.sonar.api.batch.AnalysisMode; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.fs.InputModule; import org.sonar.api.batch.fs.internal.DefaultInputModule; +import org.sonar.scanner.analysis.DefaultAnalysisMode; +import org.sonar.scanner.scan.branch.BranchConfiguration; import org.sonar.scanner.scan.filesystem.InputComponentStore; import static org.assertj.core.api.Assertions.assertThat; @@ -38,7 +39,7 @@ public class ModuleIndexerTest { private InputComponentStore componentStore; public void createIndexer(DefaultInputModule rootModule) { - componentStore = new InputComponentStore(rootModule, mock(AnalysisMode.class), mock(BranchConfiguration.class)); + componentStore = new InputComponentStore(rootModule, mock(DefaultAnalysisMode.class), mock(BranchConfiguration.class)); tree = new DefaultComponentTree(); moduleHierarchy = mock(DefaultInputModuleHierarchy.class); indexer = new ModuleIndexer(tree, componentStore, moduleHierarchy); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/MutableModuleSettingsTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/MutableModuleSettingsTest.java index c0e4d487632..317849838b3 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/MutableModuleSettingsTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/MutableModuleSettingsTest.java @@ -29,13 +29,13 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.sonar.api.batch.AnalysisMode; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.config.PropertyDefinitions; import org.sonar.api.utils.MessageException; -import org.sonar.scanner.analysis.DefaultAnalysisMode; import org.sonar.scanner.bootstrap.GlobalConfiguration; import org.sonar.scanner.bootstrap.GlobalConfigurationProvider; -import org.sonar.scanner.bootstrap.GlobalMode; +import org.sonar.scanner.bootstrap.GlobalAnalysisMode; import org.sonar.scanner.bootstrap.GlobalProperties; import org.sonar.scanner.bootstrap.MutableGlobalSettings; import org.sonar.scanner.repository.FileData; @@ -51,11 +51,11 @@ public class MutableModuleSettingsTest { @Rule public ExpectedException thrown = ExpectedException.none(); - private DefaultAnalysisMode mode; + private AnalysisMode mode; @Before public void before() { - mode = mock(DefaultAnalysisMode.class); + mode = mock(AnalysisMode.class); } private ProjectRepositories createSettings(String module, Map settingsMap) { @@ -157,6 +157,6 @@ public class MutableModuleSettingsTest { private GlobalConfiguration newGlobalSettings(Map props) { GlobalProperties globalProps = new GlobalProperties(props); return new GlobalConfigurationProvider().provide(mock(SettingsLoader.class), globalProps, new PropertyDefinitions(), - new GlobalMode(globalProps)); + new GlobalAnalysisMode(globalProps)); } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/MutableProjectSettingsTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/MutableProjectSettingsTest.java index 0087e27fede..707e4b33a23 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/MutableProjectSettingsTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/MutableProjectSettingsTest.java @@ -33,10 +33,9 @@ import org.sonar.api.batch.bootstrap.ProjectReactor; import org.sonar.api.config.PropertyDefinitions; import org.sonar.api.utils.MessageException; import org.sonar.api.utils.log.LogTester; -import org.sonar.scanner.analysis.DefaultAnalysisMode; import org.sonar.scanner.bootstrap.GlobalConfiguration; import org.sonar.scanner.bootstrap.GlobalConfigurationProvider; -import org.sonar.scanner.bootstrap.GlobalMode; +import org.sonar.scanner.bootstrap.GlobalAnalysisMode; import org.sonar.scanner.bootstrap.GlobalProperties; import org.sonar.scanner.bootstrap.MutableGlobalSettings; import org.sonar.scanner.repository.FileData; @@ -60,16 +59,14 @@ public class MutableProjectSettingsTest { private Table emptyFileData; private Table emptySettings; - private GlobalMode globalMode; - private DefaultAnalysisMode mode; + private GlobalAnalysisMode globalMode; @Before public void prepare() { emptyFileData = ImmutableTable.of(); emptySettings = ImmutableTable.of(); project = ProjectDefinition.create().setKey("struts"); - globalMode = mock(GlobalMode.class); - mode = mock(DefaultAnalysisMode.class); + globalMode = mock(GlobalAnalysisMode.class); bootstrapProps = new GlobalConfigurationProvider().provide(mock(SettingsLoader.class), new GlobalProperties(Collections.emptyMap()), new PropertyDefinitions(), globalMode); } @@ -79,7 +76,7 @@ public class MutableProjectSettingsTest { project.setProperty("project.prop", "project"); projectRef = new ProjectRepositories(emptySettings, emptyFileData, null); - MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), new MutableGlobalSettings(bootstrapProps), projectRef, mode); + MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), new MutableGlobalSettings(bootstrapProps), projectRef, globalMode); assertThat(batchSettings.getString("project.prop")).isEqualTo("project"); } @@ -91,7 +88,7 @@ public class MutableProjectSettingsTest { settings.put("struts", "sonar.java.coveragePlugin", "jacoco"); projectRef = new ProjectRepositories(settings, emptyFileData, null); - MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), new MutableGlobalSettings(bootstrapProps), projectRef, mode); + MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), new MutableGlobalSettings(bootstrapProps), projectRef, globalMode); assertThat(batchSettings.getString("sonar.java.coveragePlugin")).isEqualTo("jacoco"); } @@ -105,7 +102,7 @@ public class MutableProjectSettingsTest { projectRef = new ProjectRepositories(settings, emptyFileData, null); - MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), new MutableGlobalSettings(bootstrapProps), projectRef, mode); + MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), new MutableGlobalSettings(bootstrapProps), projectRef, globalMode); assertThat(batchSettings.getString("sonar.java.coveragePlugin")).isEqualTo("jacoco"); } @@ -117,7 +114,7 @@ public class MutableProjectSettingsTest { settings.put("struts", "sonar.foo.license.secured", "bar2"); projectRef = new ProjectRepositories(settings, emptyFileData, null); - MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), new MutableGlobalSettings(bootstrapProps), projectRef, mode); + MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), new MutableGlobalSettings(bootstrapProps), projectRef, globalMode); assertThat(batchSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2"); assertThat(batchSettings.getString("sonar.foo.secured")).isEqualTo("bar"); @@ -129,10 +126,10 @@ public class MutableProjectSettingsTest { settings.put("struts", "sonar.foo.secured", "bar"); settings.put("struts", "sonar.foo.license.secured", "bar2"); - when(mode.isIssues()).thenReturn(true); + when(globalMode.isIssues()).thenReturn(true); projectRef = new ProjectRepositories(settings, emptyFileData, null); - MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), new MutableGlobalSettings(bootstrapProps), projectRef, mode); + MutableProjectSettings batchSettings = new MutableProjectSettings(new ProjectReactor(project), new MutableGlobalSettings(bootstrapProps), projectRef, globalMode); assertThat(batchSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2"); thrown.expect(MessageException.class); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorValidatorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorValidatorTest.java index 896b3a9fd06..5c88bd4406a 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorValidatorTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorValidatorTest.java @@ -24,6 +24,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.api.CoreProperties; +import org.sonar.api.batch.AnalysisMode; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.bootstrap.ProjectReactor; import org.sonar.api.utils.MessageException; @@ -37,13 +38,15 @@ public class ProjectReactorValidatorTest { @Rule public ExpectedException thrown = ExpectedException.none(); - private DefaultAnalysisMode mode; + private AnalysisMode mode; + private DefaultAnalysisMode analysisFlags; private ProjectReactorValidator validator; @Before public void prepare() { - mode = mock(DefaultAnalysisMode.class); - validator = new ProjectReactorValidator(mode); + mode = mock(AnalysisMode.class); + analysisFlags = mock(DefaultAnalysisMode.class); + validator = new ProjectReactorValidator(mode, analysisFlags); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/branch/BranchConfigurationProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/branch/BranchConfigurationProviderTest.java new file mode 100644 index 00000000000..7201374fa78 --- /dev/null +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/branch/BranchConfigurationProviderTest.java @@ -0,0 +1,65 @@ +/* + * 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.scan.branch; + +import org.junit.Before; +import org.junit.Test; +import org.sonar.scanner.scan.ProjectSettings; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class BranchConfigurationProviderTest { + private BranchConfigurationProvider provider = new BranchConfigurationProvider(); + private ProjectSettings projectSettings; + private BranchConfigurationLoader loader; + private BranchConfiguration config; + private ProjectBranches branches; + + @Before + public void setUp() { + projectSettings = mock(ProjectSettings.class); + loader = mock(BranchConfigurationLoader.class); + config = mock(BranchConfiguration.class); + branches = mock(ProjectBranches.class); + } + + @Test + public void should_cache_config() { + BranchConfiguration configuration = provider.provide(null, projectSettings, branches); + assertThat(provider.provide(null, projectSettings, branches)).isSameAs(configuration); + } + + @Test + public void should_use_loader() { + when(loader.load(projectSettings, branches)).thenReturn(config); + BranchConfiguration branchConfig = provider.provide(loader, projectSettings, branches); + + assertThat(branchConfig).isSameAs(config); + } + + @Test + public void should_return_default_if_no_loader() { + BranchConfiguration configuration = provider.provide(null, projectSettings, branches); + assertThat(configuration.branchTarget()).isNull(); + assertThat(configuration.branchType()).isEqualTo(BranchType.LONG); + } +} diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/branch/ProjectBranchesProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/branch/ProjectBranchesProviderTest.java new file mode 100644 index 00000000000..3a227987a39 --- /dev/null +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/branch/ProjectBranchesProviderTest.java @@ -0,0 +1,66 @@ +/* + * 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.scan.branch; + +import java.util.Optional; +import org.junit.Before; +import org.junit.Test; +import org.sonar.api.config.Configuration; +import org.sonar.scanner.bootstrap.GlobalConfiguration; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class ProjectBranchesProviderTest { + private ProjectBranchesProvider provider = new ProjectBranchesProvider(); + private ProjectBranchesLoader mockLoader; + private ProjectBranches mockBranches; + private GlobalConfiguration mockSettings; + + @Before + public void setUp() { + mockLoader = mock(ProjectBranchesLoader.class); + mockBranches = mock(ProjectBranches.class); + mockSettings = mock(GlobalConfiguration.class); + } + + @Test + public void should_cache_branches() { + ProjectBranches branches = provider.provide(null, () -> "project", mockSettings); + assertThat(provider.provide(null, () -> "project", mockSettings)).isSameAs(branches); + } + + @Test + public void should_use_loader() { + when(mockLoader.load("key")).thenReturn(mockBranches); + when(mockSettings.get(anyString())).thenReturn(Optional.of("somebranch")); + ProjectBranches branches = provider.provide(mockLoader, () -> "key", mockSettings); + + assertThat(branches).isSameAs(mockBranches); + } + + @Test + public void should_return_default_if_no_loader() { + ProjectBranches branches = provider.provide(null, () -> "project", mockSettings); + assertThat(branches.isEmpty()).isTrue(); + } +} diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/InputComponentStoreTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/InputComponentStoreTest.java index aacfb609f52..9d96bd65dfb 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/InputComponentStoreTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/InputComponentStoreTest.java @@ -27,7 +27,6 @@ import java.util.List; import org.junit.ClassRule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import org.sonar.api.batch.AnalysisMode; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.InputFile.Status; @@ -36,7 +35,8 @@ import org.sonar.api.batch.fs.InputPath; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; -import org.sonar.scanner.scan.BranchConfiguration; +import org.sonar.scanner.analysis.DefaultAnalysisMode; +import org.sonar.scanner.scan.branch.BranchConfiguration; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -60,7 +60,7 @@ public class InputComponentStoreTest { DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule(rootDef); DefaultInputModule subModule = TestInputFileBuilder.newDefaultInputModule(moduleDef); - InputComponentStore cache = new InputComponentStore(rootModule, mock(AnalysisMode.class), mock(BranchConfiguration.class)); + InputComponentStore cache = new InputComponentStore(rootModule, mock(DefaultAnalysisMode.class), mock(BranchConfiguration.class)); cache.put(subModule); DefaultInputFile fooFile = new TestInputFileBuilder(rootModuleKey, "src/main/java/Foo.java") @@ -104,7 +104,7 @@ public class InputComponentStoreTest { static class InputComponentStoreTester extends InputComponentStore { InputComponentStoreTester() throws IOException { - super(TestInputFileBuilder.newDefaultInputModule("root", temp.newFolder()), mock(AnalysisMode.class), mock(BranchConfiguration.class)); + super(TestInputFileBuilder.newDefaultInputModule("root", temp.newFolder()), mock(DefaultAnalysisMode.class), mock(BranchConfiguration.class)); } InputFile addFile(String moduleKey, String relpath, String language) { 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 9856377a92c..a50f8de9572 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 @@ -24,13 +24,13 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import org.sonar.api.batch.AnalysisMode; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.InputModule; import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.batch.fs.internal.SensorStrategy; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; -import org.sonar.scanner.scan.BranchConfiguration; +import org.sonar.scanner.analysis.DefaultAnalysisMode; +import org.sonar.scanner.scan.branch.BranchConfiguration; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.any; @@ -49,7 +49,7 @@ public class ModuleInputComponentStoreTest { @Before public void setUp() throws IOException { DefaultInputModule root = TestInputFileBuilder.newDefaultInputModule(moduleKey, temp.newFolder()); - componentStore = new InputComponentStore(root, mock(AnalysisMode.class), mock(BranchConfiguration.class)); + componentStore = new InputComponentStore(root, mock(DefaultAnalysisMode.class), mock(BranchConfiguration.class)); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/report/JSONReportTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/report/JSONReportTest.java index 4b005062ddb..1819252ae3c 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/report/JSONReportTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/report/JSONReportTest.java @@ -31,7 +31,6 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import org.sonar.api.batch.AnalysisMode; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.DefaultFileSystem; @@ -46,10 +45,11 @@ import org.sonar.api.config.internal.MapSettings; import org.sonar.api.issue.Issue; import org.sonar.api.platform.Server; import org.sonar.api.rule.RuleKey; +import org.sonar.scanner.analysis.DefaultAnalysisMode; import org.sonar.scanner.issue.IssueCache; import org.sonar.scanner.issue.tracking.TrackedIssue; -import org.sonar.scanner.scan.BranchConfiguration; import org.sonar.scanner.scan.DefaultComponentTree; +import org.sonar.scanner.scan.branch.BranchConfiguration; import org.sonar.scanner.scan.filesystem.InputComponentStore; import static net.javacrumbs.jsonunit.assertj.JsonAssert.assertThatJson; @@ -84,7 +84,7 @@ public class JSONReportTest { DefaultComponentTree inputComponentTree = new DefaultComponentTree(); ProjectDefinition def = ProjectDefinition.create().setBaseDir(projectBaseDir).setWorkDir(temp.newFolder()).setKey("struts"); DefaultInputModule rootModule = new DefaultInputModule(def, 1); - InputComponentStore inputComponentStore = new InputComponentStore(rootModule, mock(AnalysisMode.class), mock(BranchConfiguration.class)); + InputComponentStore inputComponentStore = new InputComponentStore(rootModule, mock(DefaultAnalysisMode.class), mock(BranchConfiguration.class)); DefaultInputModule moduleA = new DefaultInputModule(ProjectDefinition.create().setKey("struts-core").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder())); inputComponentTree.index(moduleA, rootModule); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorContextTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorContextTest.java index aa62800ee91..afe8a413d98 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorContextTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorContextTest.java @@ -37,7 +37,7 @@ import org.sonar.api.config.internal.MapSettings; import org.sonar.api.internal.SonarRuntimeImpl; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.utils.Version; -import org.sonar.scanner.scan.BranchConfiguration; +import org.sonar.scanner.scan.branch.BranchConfiguration; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/source/ZeroCoverageSensorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/source/ZeroCoverageSensorTest.java index 09a347f71dc..ab3295ac409 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/source/ZeroCoverageSensorTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/source/ZeroCoverageSensorTest.java @@ -21,9 +21,9 @@ package org.sonar.scanner.source; import org.junit.Rule; import org.junit.Test; -import org.sonar.api.batch.AnalysisMode; import org.sonar.api.utils.log.LogTester; import org.sonar.api.utils.log.LoggerLevel; +import org.sonar.scanner.analysis.DefaultAnalysisMode; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -36,9 +36,9 @@ public class ZeroCoverageSensorTest { @Test public void dontForceCoverageInIncrementalMode() { - AnalysisMode analysisMode = mock(AnalysisMode.class); - when(analysisMode.isIncremental()).thenReturn(true); - ZeroCoverageSensor zeroCoverageSensor = new ZeroCoverageSensor(null, analysisMode); + DefaultAnalysisMode analysisFlags = mock(DefaultAnalysisMode.class); + when(analysisFlags.isIncremental()).thenReturn(true); + ZeroCoverageSensor zeroCoverageSensor = new ZeroCoverageSensor(null, analysisFlags); zeroCoverageSensor.execute(null); assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("Incremental mode: not forcing coverage to zero"); } -- cgit v1.2.3