EmbeddedScanner { void initSourceEncoding(Map<String, String> p) { boolean onProject = Utils.taskRequiresProject(p); if (onProject) { String sourceEncoding = Optional.ofNullable(p.get(ScanProperties.PROJECT_SOURCE_ENCODING)).orElse(""); boolean platformDependent = false; if ("".equals(sourceEncoding)) { sourceEncoding = Charset.defaultCharset().name(); platformDependent = true; p.put(ScanProperties.PROJECT_SOURCE_ENCODING, sourceEncoding); } logger.info("Default locale: \"" + Locale.getDefault() + "\", source code encoding: \"" + sourceEncoding + "\"" + (platformDependent ? " (analysis is platform dependent)" : "")); } } EmbeddedScanner(IsolatedLauncherFactory bl, Logger logger, LogOutput logOutput, System2 system); static EmbeddedScanner create(String app, String version, final LogOutput logOutput, System2 system2); static EmbeddedScanner create(String app, String version, final LogOutput logOutput); Map<String, String> globalProperties(); EmbeddedScanner unmask(String fqcnPrefix); EmbeddedScanner mask(String fqcnPrefix); EmbeddedScanner addGlobalProperties(Map<String, String> p); EmbeddedScanner setGlobalProperty(String key, String value); String globalProperty(String key, @Nullable String defaultValue); String app(); String appVersion(); void start(); String serverVersion(); void execute(Map<String, String> taskProps);  }
@Test public void should_set_default_platform_encoding() throws Exception { Map<String, String> p = new HashMap<>(); p.put("sonar.task", "scan"); scanner.initSourceEncoding(p); assertThat(p.get("sonar.sourceEncoding")).isEqualTo(Charset.defaultCharset().name()); verify(logger).info("Default locale: \"" + Locale.getDefault() + "\", source code encoding: \"" + Charset.defaultCharset().name() + "\" (analysis is platform dependent)"); }
@Test public void should_set_default_platform_encoding_when_empty() throws Exception { Map<String, String> p = new HashMap<>(); p.put("sonar.task", "scan"); p.put("sonar.sourceEncoding", ""); scanner.initSourceEncoding(p); assertThat(p.get("sonar.sourceEncoding")).isEqualTo(Charset.defaultCharset().name()); verify(logger).info("Default locale: \"" + Locale.getDefault() + "\", source code encoding: \"" + Charset.defaultCharset().name() + "\" (analysis is platform dependent)"); }
@Test public void should_use_parameterized_encoding() throws Exception { Map<String, String> p = new HashMap<>(); p.put("sonar.task", "scan"); p.put("sonar.sourceEncoding", "THE_ISO_1234"); scanner.initSourceEncoding(p); assertThat(p.get("sonar.sourceEncoding")).isEqualTo("THE_ISO_1234"); }
@Test public void should_not_init_encoding_if_not_project_task() throws Exception { Map<String, String> p = new HashMap<>(); p.put("sonar.task", "views"); scanner.initSourceEncoding(p); assertThat(p.get("sonar.sourceEncoding")).isNull(); }