private void validateBranchParamsWhenPluginAbsent(List<String> validationMessages) { for (String param : Arrays.asList(BRANCH_NAME, BRANCH_TARGET)) { if (isNotEmpty(settings.get(param).orElse(null))) { validationMessages.add(format("To use the property \"%s\", the branch plugin is required but not installed. " + "See the documentation of branch support: %s.", param, BRANCHES_DOC_LINK)); } } }
private void validatePullRequestParamsWhenPluginAbsent(List<String> validationMessages) { Stream.of(PULL_REQUEST_KEY, PULL_REQUEST_BRANCH, PULL_REQUEST_BASE) .filter(param -> nonNull(settings.get(param).orElse(null))) .forEach(param -> validationMessages.add(format("To use the property \"%s\", the branch plugin is required but not installed. " + "See the documentation of branch support: %s.", param, BRANCHES_DOC_LINK))); }
@Before public void prepare() { mode = mock(AnalysisMode.class); settings = mock(GlobalConfiguration.class); when(settings.get(anyString())).thenReturn(Optional.empty()); validator = new ProjectReactorValidator(mode, settings); }
@Test public void should_load_global_settings() { when(globalServerSettings.properties()).thenReturn(ImmutableMap.of("sonar.cpd.cross", "true")); GlobalConfiguration globalConfig = new GlobalConfigurationProvider().provide(globalServerSettings, scannerProps, new PropertyDefinitions()); assertThat(globalConfig.get("sonar.cpd.cross")).hasValue("true"); } }
@Test public void fail_when_branch_name_is_specified_but_branch_plugin_not_present() { ProjectDefinition def = ProjectDefinition.create().setProperty(CoreProperties.PROJECT_KEY_PROPERTY, "foo"); ProjectReactor reactor = new ProjectReactor(def); when(settings.get(eq(ScannerProperties.BRANCH_NAME))).thenReturn(Optional.of("feature1")); thrown.expect(MessageException.class); thrown.expectMessage("the branch plugin is required but not installed"); validator.validate(reactor); }
@Test public void fail_when_branch_target_is_specified_but_branch_plugin_not_present() { ProjectDefinition def = ProjectDefinition.create().setProperty(CoreProperties.PROJECT_KEY_PROPERTY, "foo"); ProjectReactor reactor = new ProjectReactor(def); when(settings.get(eq(ScannerProperties.BRANCH_TARGET))).thenReturn(Optional.of("feature1")); thrown.expect(MessageException.class); thrown.expectMessage("the branch plugin is required but not installed"); validator.validate(reactor); }
@Test public void fail_when_pull_request_base_specified_but_branch_plugin_not_present() { ProjectDefinition def = ProjectDefinition.create().setProperty(CoreProperties.PROJECT_KEY_PROPERTY, "foo"); ProjectReactor reactor = new ProjectReactor(def); when(settings.get(eq(ScannerProperties.PULL_REQUEST_BASE))).thenReturn(Optional.of("feature1")); thrown.expect(MessageException.class); thrown.expectMessage("the branch plugin is required but not installed"); validator.validate(reactor); }
@Test public void fail_when_pull_request_id_specified_but_branch_plugin_not_present() { ProjectDefinition def = ProjectDefinition.create().setProperty(CoreProperties.PROJECT_KEY_PROPERTY, "foo"); ProjectReactor reactor = new ProjectReactor(def); when(settings.get(eq(ScannerProperties.PULL_REQUEST_KEY))).thenReturn(Optional.of("#1984")); thrown.expect(MessageException.class); thrown.expectMessage("the branch plugin is required but not installed"); validator.validate(reactor); }
@Test public void fail_when_pull_request_branch_is_specified_but_branch_plugin_not_present() { ProjectDefinition def = ProjectDefinition.create().setProperty(CoreProperties.PROJECT_KEY_PROPERTY, "foo"); ProjectReactor reactor = new ProjectReactor(def); when(settings.get(eq(ScannerProperties.PULL_REQUEST_BRANCH))).thenReturn(Optional.of("feature1")); thrown.expect(MessageException.class); thrown.expectMessage("the branch plugin is required but not installed"); validator.validate(reactor); }
@Override public void validate(List<String> validationMessages, @Nullable String deprecatedBranchName) { String branchName = globalConfiguration.get(SONAR_BRANCH_NAME_PROP).orElse(null); String branchTarget = globalConfiguration.get(SONAR_BRANCH_TARGET_PROP).orElse(null); if (StringUtils.isNotEmpty(deprecatedBranchName) && (StringUtils.isNotEmpty(branchName) || StringUtils.isNotEmpty(branchTarget))) { validationMessages.add("Legacy property sonar.branch can't be used together with branch plugin properties"); } } }
private void validateBranchParamsWhenPluginAbsent(List<String> validationMessages) { for (String param : Arrays.asList(BRANCH_NAME, BRANCH_TARGET)) { if (isNotEmpty(settings.get(param).orElse(null))) { validationMessages.add(format("To use the property \"%s\", the branch plugin is required but not installed. " + "See the documentation of branch support: %s.", param, BRANCHES_DOC_LINK)); } } }
private void validatePullRequestParamsWhenPluginAbsent(List<String> validationMessages) { Stream.of(PULL_REQUEST_KEY, PULL_REQUEST_BRANCH, PULL_REQUEST_BASE) .filter(param -> nonNull(settings.get(param).orElse(null))) .forEach(param -> validationMessages.add(format("To use the property \"%s\", the branch plugin is required but not installed. " + "See the documentation of branch support: %s.", param, BRANCHES_DOC_LINK))); }