2222import java .io .BufferedWriter ;
2323import java .io .File ;
2424import java .io .IOException ;
25- import java .nio . charset . StandardCharsets ;
25+ import java .io . OutputStream ;
2626import java .nio .file .Files ;
2727import java .nio .file .Paths ;
28- import java .util .Comparator ;
28+ import java .util .Collections ;
29+ import java .util .Enumeration ;
2930import java .util .Map ;
3031import java .util .Map .Entry ;
32+ import java .util .Properties ;
33+ import java .util .TreeSet ;
3134import org .sonarsource .scanner .api .internal .batch .IsolatedLauncher ;
3235import org .sonarsource .scanner .api .internal .batch .LogOutput ;
3336import org .sonarsource .scanner .api .internal .cache .Logger ;
@@ -49,11 +52,16 @@ public void execute(Map<String, String> props, LogOutput logOutput) {
4952 }
5053
5154 private static void writeProperties (String filePath , Map <String , String > p ) {
52- try (BufferedWriter output = Files .newBufferedWriter (Paths .get (filePath ), StandardCharsets .ISO_8859_1 )) {
53- output .write ("# Generated by a SonarQube Scanner" );
54- output .newLine ();
55- p .entrySet ().stream ().sorted (Comparator .comparing (Map .Entry ::getKey )).forEach (e -> writeProp (output , e ));
56-
55+ // This is to have output file content sorted by key
56+ Properties props = new Properties () {
57+ @ Override
58+ public synchronized Enumeration <Object > keys () {
59+ return Collections .enumeration (new TreeSet <Object >(super .keySet ()));
60+ }
61+ };
62+ props .putAll (p );
63+ try (OutputStream outputStream = Files .newOutputStream (Paths .get (filePath ))) {
64+ props .store (outputStream , "# Generated by a SonarQube Scanner" );
5765 } catch (Exception e ) {
5866 throw new IllegalStateException ("Fail to export scanner properties" , e );
5967 }
0 commit comments