diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-08-10 16:29:02 +0200 |
---|---|---|
committer | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-08-12 16:12:49 +0200 |
commit | d579ae3bca2196d34b94241688e9fcfb2846db53 (patch) | |
tree | 98bcbbdc9a7430b5ba71d05186ea1c9b3c75edb8 /sonar-batch | |
parent | 0ace2688a908fe67eb0fc73d02d5d99dd225b68f (diff) | |
download | sonarqube-d579ae3bca2196d34b94241688e9fcfb2846db53.tar.gz sonarqube-d579ae3bca2196d34b94241688e9fcfb2846db53.zip |
SONAR-6762 - Create 'issues' analysis mode
Diffstat (limited to 'sonar-batch')
7 files changed, 37 insertions, 15 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginPredicate.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginPredicate.java index 5db59c34280..8329e4fb42a 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginPredicate.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginPredicate.java @@ -54,7 +54,7 @@ public class BatchPluginPredicate implements Predicate<String> { public BatchPluginPredicate(Settings settings, GlobalMode mode) { this.mode = mode; - if (mode.isPreview()) { + if (mode.isPreview() || mode.isIssues()) { // These default values are not supported by Settings because the class CorePlugin // is not loaded yet. whites.addAll(propertyValues(settings, diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalSettings.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalSettings.java index a2d39001071..5acd980e3a3 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalSettings.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalSettings.java @@ -71,9 +71,9 @@ public class GlobalSettings extends Settings { @Override protected void doOnGetProperties(String key) { - if (mode.isPreview() && key.endsWith(".secured") && !key.contains(".license")) { + if (mode.isIssues() && key.endsWith(".secured") && !key.contains(".license")) { throw MessageException.of("Access to the secured property '" + key - + "' is not possible in preview mode. The SonarQube plugin which requires this property must be deactivated in preview mode."); + + "' is not possible in issues mode. The SonarQube plugin which requires this property must be deactivated in issues mode."); } } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java b/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java index acb50733362..8a5bfe64152 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java +++ b/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java @@ -55,7 +55,7 @@ public class DefaultProjectRepositoriesLoader extends AbstractServerLoader imple + "' is deprecated and will be dropped in a future SonarQube version. Please configure quality profile used by your project on SonarQube server."); url += "&profile=" + BatchUtils.encodeForUrl(taskProperties.properties().get(ModuleQProfiles.SONAR_PROFILE_PROP)); } - url += "&preview=" + globalMode.isPreview(); + url += "&preview=" + globalMode.isIssues(); ProjectRepositories projectRepositories = ProjectRepositories.fromJson(load(url)); validateProjectRepositories(projectRepositories, reactor.getRoot().getKey()); return projectRepositories; diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectAnalysisMode.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectAnalysisMode.java index 569566093eb..d23a27b3174 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectAnalysisMode.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectAnalysisMode.java @@ -19,7 +19,6 @@ */ package org.sonar.batch.scan; -import org.sonar.batch.mediumtest.FakePluginInstaller; import org.apache.commons.lang.StringUtils; import org.sonar.batch.bootstrap.BootstrapProperties; @@ -28,7 +27,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.api.CoreProperties; import org.sonar.api.batch.AnalysisMode; - +import org.sonar.batch.mediumtest.BatchMediumTester; import java.util.Map; /** @@ -82,7 +81,7 @@ public class ProjectAnalysisMode implements AnalysisMode { validate(mode); preview = CoreProperties.ANALYSIS_MODE_PREVIEW.equals(mode); issues = CoreProperties.ANALYSIS_MODE_ISSUES.equals(mode); - mediumTestMode = "true".equals(getPropertyWithFallback(analysisProps, globalProps, FakePluginInstaller.MEDIUM_TEST_ENABLED)); + mediumTestMode = "true".equals(getPropertyWithFallback(analysisProps, globalProps, BatchMediumTester.MEDIUM_TEST_ENABLED)); if (preview) { LOG.info("Preview mode"); diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/GlobalModeTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/GlobalModeTest.java index 50aaa6f53b5..b4c8f4253bd 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/GlobalModeTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/GlobalModeTest.java @@ -32,18 +32,38 @@ public class GlobalModeTest { public void testPreview() { GlobalMode mode = createMode(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_PREVIEW); assertThat(mode.isPreview()).isTrue(); + assertThat(mode.isIssues()).isFalse(); + assertThat(mode.isPublish()).isFalse(); } @Test public void testOtherProperty() { - GlobalMode mode = createMode(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ANALYSIS); + 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 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<String, String> map = new HashMap<>(); - map.put(key, value); + if (key != null) { + map.put(key, value); + } BootstrapProperties props = new BootstrapProperties(map); return new GlobalMode(props); } } + diff --git a/sonar-batch/src/test/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest.java index 7a17f5f5e56..2d667f8d039 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest.java @@ -61,7 +61,7 @@ public class DefaultProjectRepositoriesLoaderTest { globalMode = mock(GlobalMode.class); loader = new DefaultProjectRepositoriesLoader(wsLoader, globalMode); loader = spy(loader); - when(wsLoader.loadString(anyString())).thenReturn(new WSLoaderResult("{}", true)); + when(wsLoader.loadString(anyString())).thenReturn(new WSLoaderResult<>("{}", true)); taskProperties = new AnalysisProperties(Maps.<String, String>newHashMap(), ""); } @@ -73,7 +73,7 @@ public class DefaultProjectRepositoriesLoaderTest { loader.load(reactor, taskProperties); verify(wsLoader).loadString("/batch/project?key=foo&preview=false"); - when(globalMode.isPreview()).thenReturn(true); + when(globalMode.isIssues()).thenReturn(true); loader.load(reactor, taskProperties); verify(wsLoader).loadString("/batch/project?key=foo&preview=true"); } @@ -101,7 +101,7 @@ public class DefaultProjectRepositoriesLoaderTest { thrown.expectMessage("No quality profiles has been found this project, you probably don't have any language plugin suitable for this analysis."); reactor = new ProjectReactor(ProjectDefinition.create().setKey("foo")); - when(wsLoader.loadString(anyString())).thenReturn(new WSLoaderResult(new ProjectRepositories().toJson(), true)); + when(wsLoader.loadString(anyString())).thenReturn(new WSLoaderResult<>(new ProjectRepositories().toJson(), true)); loader.load(reactor, taskProperties); } @@ -109,7 +109,7 @@ public class DefaultProjectRepositoriesLoaderTest { private void addQualityProfile() { ProjectRepositories projectRepositories = new ProjectRepositories(); projectRepositories.addQProfile(new QProfile("key", "name", "language", new Date())); - when(wsLoader.loadString(anyString())).thenReturn(new WSLoaderResult(projectRepositories.toJson(), true)); + when(wsLoader.loadString(anyString())).thenReturn(new WSLoaderResult<>(projectRepositories.toJson(), true)); } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectAnalysisModeTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectAnalysisModeTest.java index 822e0b88350..1f050b8fc7a 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectAnalysisModeTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectAnalysisModeTest.java @@ -38,6 +38,7 @@ public class ProjectAnalysisModeTest { public void regular_analysis_by_default() { ProjectAnalysisMode mode = createMode(null, null); assertThat(mode.isPreview()).isFalse(); + assertThat(mode.isPublish()).isTrue(); } @Test(expected = IllegalStateException.class) @@ -46,10 +47,11 @@ public class ProjectAnalysisModeTest { } @Test - public void support_analysis_mode() { - ProjectAnalysisMode mode = createMode(CoreProperties.ANALYSIS_MODE_ANALYSIS); + public void support_pulblish_mode() { + ProjectAnalysisMode mode = createMode(CoreProperties.ANALYSIS_MODE_PUBLISH); assertThat(mode.isPreview()).isFalse(); + assertThat(mode.isPublish()).isTrue(); } @Test(expected = IllegalStateException.class) @@ -102,3 +104,4 @@ public class ProjectAnalysisModeTest { } } + |