private void writeGlobalSettings(BufferedWriter fileWriter) throws IOException { fileWriter.append("Global server settings:\n"); Map<String, String> props = globalServerSettings.properties(); for (String prop : new TreeSet<>(props.keySet())) { dumpPropIfNotSensitive(fileWriter, prop, props.get(prop)); } }
public GlobalServerSettings provide(SettingsLoader loader) { if (singleton == null) { Map<String, String> serverSideSettings = loader.loadGlobalSettings(); singleton = new GlobalServerSettings(serverSideSettings); Optional.ofNullable(serverSideSettings.get(CoreProperties.SERVER_ID)).ifPresent(v -> LOG.info("Server id: {}", v)); } return singleton; } }
private static Supplier<Map<String, String>> createSettingsSupplier(ProjectDefinition root, GlobalServerSettings globalServerSettings, ProjectServerSettings projectServerSettings) { // we can't get ProjectConfiguration because it creates a circular dependency. // We create our own settings which will only be loaded if needed. return () -> { Map<String, String> settings = new HashMap<>(); settings.putAll(globalServerSettings.properties()); settings.putAll(projectServerSettings.properties()); settings.putAll(root.properties()); return settings; }; } }
public GlobalServerSettings provide(SettingsLoader loader) { if (singleton == null) { Map<String, String> serverSideSettings = loader.loadGlobalSettings(); singleton = new GlobalServerSettings(serverSideSettings); Optional.ofNullable(serverSideSettings.get(CoreProperties.SERVER_ID)).ifPresent(v -> LOG.info("Server id: {}", v)); } return singleton; } }
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; } }
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 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 dumpServerSideGlobalProps() throws Exception { logTester.setLevel(LoggerLevel.DEBUG); ScannerReportWriter writer = new ScannerReportWriter(temp.newFolder()); when(globalServerSettings.properties()).thenReturn(ImmutableMap.of(COM_FOO, "bar", SONAR_SKIP, "true")); DefaultInputModule rootModule = new DefaultInputModule(ProjectDefinition.create() .setBaseDir(temp.newFolder()) .setWorkDir(temp.newFolder()) .setProperty("sonar.projectKey", "foo")); when(store.allModules()).thenReturn(singletonList(rootModule)); when(hierarchy.root()).thenReturn(rootModule); publisher.init(writer); String content = FileUtils.readFileToString(writer.getFileStructure().analysisLog(), StandardCharsets.UTF_8); assertThat(content).containsOnlyOnce(COM_FOO); assertThat(content).containsOnlyOnce(SONAR_SKIP); }
@Test public void shouldNotDumpSensitiveGlobalProperties() throws Exception { ScannerReportWriter writer = new ScannerReportWriter(temp.newFolder()); when(globalServerSettings.properties()).thenReturn(ImmutableMap.of("sonar.login", "my_token", "sonar.password", "azerty", "sonar.cpp.license.secured", "AZERTY")); DefaultInputModule rootModule = new DefaultInputModule(ProjectDefinition.create() .setBaseDir(temp.newFolder()) .setWorkDir(temp.newFolder()) .setProperty("sonar.projectKey", "foo")); when(store.allModules()).thenReturn(singletonList(rootModule)); when(hierarchy.root()).thenReturn(rootModule); publisher.init(writer); assertThat(FileUtils.readFileToString(writer.getFileStructure().analysisLog(), StandardCharsets.UTF_8)).containsSubsequence( "sonar.cpp.license.secured=******", "sonar.login=******", "sonar.password=******"); }
private void writeGlobalSettings(BufferedWriter fileWriter) throws IOException { fileWriter.append("Global server settings:\n"); Map<String, String> props = globalServerSettings.properties(); for (String prop : new TreeSet<>(props.keySet())) { dumpPropIfNotSensitive(fileWriter, prop, props.get(prop)); } }
private static Supplier<Map<String, String>> createSettingsSupplier(ProjectDefinition root, GlobalServerSettings globalServerSettings, ProjectServerSettings projectServerSettings) { // we can't get ProjectConfiguration because it creates a circular dependency. // We create our own settings which will only be loaded if needed. return () -> { Map<String, String> settings = new HashMap<>(); settings.putAll(globalServerSettings.properties()); settings.putAll(projectServerSettings.properties()); settings.putAll(root.properties()); return settings; }; } }
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; } }
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; }