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)); } } }
public MutableProjectSettings(GlobalConfiguration globalConfig) { super(globalConfig.getDefinitions(), globalConfig.getEncryption()); addProperties(globalConfig.getProperties()); }
public GlobalConfiguration provide(GlobalServerSettings globalServerSettings, ScannerProperties scannerProps, PropertyDefinitions propertyDefinitions) { if (globalConfig == null) { Map<String, String> mergedSettings = new LinkedHashMap<>(); mergedSettings.putAll(globalServerSettings.properties()); mergedSettings.putAll(scannerProps.properties()); globalConfig = new GlobalConfiguration(propertyDefinitions, scannerProps.getEncryption(), mergedSettings); } return globalConfig; } }
public ProjectConfiguration provide(DefaultInputProject project, GlobalConfiguration globalConfig, GlobalServerSettings globalServerSettings, ProjectServerSettings projectServerSettings, MutableProjectSettings projectSettings) { if (projectConfig == null) { Map<String, String> settings = new LinkedHashMap<>(); settings.putAll(globalServerSettings.properties()); settings.putAll(projectServerSettings.properties()); settings.putAll(project.properties()); projectConfig = new ProjectConfiguration(globalConfig.getDefinitions(), globalConfig.getEncryption(), settings); projectSettings.complete(projectConfig); } return projectConfig; } }
@Before public void setUp() { MockitoAnnotations.initMocks(this); when(globalConfiguration.getProperties()).thenReturn(globalPropertiesMap); when(reactor.getRoot()).thenReturn(root); }
public ModuleConfiguration provide(GlobalConfiguration globalConfig, DefaultInputModule module, GlobalServerSettings globalServerSettings, ProjectServerSettings projectServerSettings) { if (moduleConfiguration == null) { Map<String, String> settings = new LinkedHashMap<>(); settings.putAll(globalServerSettings.properties()); settings.putAll(projectServerSettings.properties()); addScannerSideProperties(settings, module.definition()); moduleConfiguration = new ModuleConfiguration(globalConfig.getDefinitions(), globalConfig.getEncryption(), settings); } return moduleConfiguration; }
@Test public void settings_should_include_command_line_args_with_highest_priority() { when(globalConfiguration.getProperties()).thenReturn(Collections.singletonMap("key", "global")); when(projectServerSettings.properties()).thenReturn(Collections.singletonMap("key", "settings")); when(root.properties()).thenReturn(Collections.singletonMap("key", "root")); provider.provide(loader, globalConfiguration, reactor, globalServerSettings, projectServerSettings, branches, pullRequests); verify(loader).load(anyMap(), settingsCaptor.capture(), any(ProjectBranches.class), any(ProjectPullRequests.class)); Map<String, String> map = settingsCaptor.getValue().get(); assertThat(map.get("key")).isEqualTo("root"); }
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))); }
public MutableProjectSettings(GlobalConfiguration globalConfig) { super(globalConfig.getDefinitions(), globalConfig.getEncryption()); addProperties(globalConfig.getProperties()); }
public ModuleConfiguration provide(GlobalConfiguration globalConfig, DefaultInputModule module, GlobalServerSettings globalServerSettings, ProjectServerSettings projectServerSettings) { if (moduleConfiguration == null) { Map<String, String> settings = new LinkedHashMap<>(); settings.putAll(globalServerSettings.properties()); settings.putAll(projectServerSettings.properties()); addScannerSideProperties(settings, module.definition()); moduleConfiguration = new ModuleConfiguration(globalConfig.getDefinitions(), globalConfig.getEncryption(), settings); } return moduleConfiguration; }
public BranchConfiguration provide(@Nullable BranchConfigurationLoader loader, GlobalConfiguration globalConfiguration, ProjectReactor reactor, GlobalServerSettings globalServerSettings, ProjectServerSettings projectServerSettings, ProjectBranches branches, ProjectPullRequests pullRequests) { if (branchConfiguration == null) { if (loader == null) { branchConfiguration = new DefaultBranchConfiguration(); } else { Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG); Supplier<Map<String, String>> settingsSupplier = createSettingsSupplier(reactor.getRoot(), globalServerSettings, projectServerSettings); branchConfiguration = loader.load(globalConfiguration.getProperties(), settingsSupplier, branches, pullRequests); profiler.stopInfo(); } } return branchConfiguration; }
public GlobalConfiguration provide(GlobalServerSettings globalServerSettings, ScannerProperties scannerProps, PropertyDefinitions propertyDefinitions) { if (globalConfig == null) { Map<String, String> mergedSettings = new LinkedHashMap<>(); mergedSettings.putAll(globalServerSettings.properties()); mergedSettings.putAll(scannerProps.properties()); globalConfig = new GlobalConfiguration(propertyDefinitions, scannerProps.getEncryption(), mergedSettings); } return globalConfig; } }
@Before public void prepare() { mode = mock(AnalysisMode.class); settings = mock(GlobalConfiguration.class); when(settings.get(anyString())).thenReturn(Optional.empty()); validator = new ProjectReactorValidator(mode, settings); }
public ProjectConfiguration provide(DefaultInputProject project, GlobalConfiguration globalConfig, GlobalServerSettings globalServerSettings, ProjectServerSettings projectServerSettings, MutableProjectSettings projectSettings) { if (projectConfig == null) { Map<String, String> settings = new LinkedHashMap<>(); settings.putAll(globalServerSettings.properties()); settings.putAll(projectServerSettings.properties()); settings.putAll(project.properties()); projectConfig = new ProjectConfiguration(globalConfig.getDefinitions(), globalConfig.getEncryption(), settings); projectSettings.complete(projectConfig); } return projectConfig; } }
public BranchConfiguration provide(@Nullable BranchConfigurationLoader loader, GlobalConfiguration globalConfiguration, ProjectReactor reactor, GlobalServerSettings globalServerSettings, ProjectServerSettings projectServerSettings, ProjectBranches branches, ProjectPullRequests pullRequests) { if (branchConfiguration == null) { if (loader == null) { branchConfiguration = new DefaultBranchConfiguration(); } else { Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG); Supplier<Map<String, String>> settingsSupplier = createSettingsSupplier(reactor.getRoot(), globalServerSettings, projectServerSettings); branchConfiguration = loader.load(globalConfiguration.getProperties(), settingsSupplier, branches, pullRequests); profiler.stopInfo(); } } return branchConfiguration; }
@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_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); }
@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); }