21
21
22
22
import java .io .FileInputStream ;
23
23
import java .io .IOException ;
24
- import java .io .InputStream ;
24
+ import java .io .InputStreamReader ;
25
25
import java .nio .file .Files ;
26
26
import java .nio .file .Path ;
27
27
import java .nio .file .Paths ;
35
35
import org .slf4j .LoggerFactory ;
36
36
import org .sonarsource .scanner .lib .EnvironmentConfig ;
37
37
38
+ import static java .nio .charset .StandardCharsets .UTF_8 ;
39
+
38
40
class Conf {
39
41
private static final Logger LOG = LoggerFactory .getLogger (Conf .class );
40
42
@@ -46,7 +48,6 @@ class Conf {
46
48
private static final String PROPERTY_PROJECT_BASEDIR = "sonar.projectBaseDir" ;
47
49
private static final String PROPERTY_PROJECT_CONFIG_FILE = "sonar.projectConfigFile" ;
48
50
private static final String SONAR_PROJECT_PROPERTIES_FILENAME = "sonar-project.properties" ;
49
- static final String PROPERTY_SONAR_HOST_URL = "sonar.host.url" ;
50
51
private static final String BOOTSTRAP_START_TIME = "sonar.scanner.bootstrapStartTime" ;
51
52
52
53
private final Cli cli ;
@@ -92,8 +93,7 @@ private Properties loadGlobalProperties() {
92
93
knownPropsAtThatPoint .putAll (loadEnvironmentProperties ());
93
94
knownPropsAtThatPoint .putAll (cli .properties ());
94
95
95
- Path settingsFile = locatePropertiesFile (knownPropsAtThatPoint , SCANNER_HOME , "conf/sonar-scanner.properties" ,
96
- SCANNER_SETTINGS );
96
+ Path settingsFile = locatePropertiesFile (knownPropsAtThatPoint );
97
97
if (settingsFile != null && Files .isRegularFile (settingsFile )) {
98
98
LOG .info ("Scanner configuration file: {}" , settingsFile );
99
99
return toProperties (settingsFile );
@@ -217,14 +217,14 @@ protected static Properties extractModuleProperties(String module, Properties pr
217
217
return moduleProps ;
218
218
}
219
219
220
- private static Path locatePropertiesFile (Properties props , String homeKey , String relativePathFromHome , String settingsKey ) {
220
+ private static Path locatePropertiesFile (Properties props ) {
221
221
Path settingsFile = null ;
222
- String scannerHome = props .getProperty (homeKey , "" );
222
+ String scannerHome = props .getProperty (Conf . SCANNER_HOME , "" );
223
223
if (!"" .equals (scannerHome )) {
224
- settingsFile = Paths .get (scannerHome , relativePathFromHome );
224
+ settingsFile = Paths .get (scannerHome , "conf/sonar-scanner.properties" );
225
225
}
226
226
227
- return locatePropertiesFile (settingsFile , props , settingsKey );
227
+ return locatePropertiesFile (settingsFile , props , Conf . SCANNER_SETTINGS );
228
228
}
229
229
230
230
private static Path locatePropertiesFile (@ Nullable Path defaultPath , Properties props , String settingsKey ) {
@@ -244,8 +244,8 @@ private static Path locatePropertiesFile(@Nullable Path defaultPath, Properties
244
244
245
245
private static Properties toProperties (Path file ) {
246
246
Properties properties = new Properties ();
247
- try (InputStream in = new FileInputStream (file .toFile ())) {
248
- properties .load (in );
247
+ try (InputStreamReader reader = new InputStreamReader ( new FileInputStream (file .toFile ()), UTF_8 )) {
248
+ properties .load (reader );
249
249
// Trim properties
250
250
for (String propKey : properties .stringPropertyNames ()) {
251
251
properties .setProperty (propKey , properties .getProperty (propKey ).trim ());
0 commit comments