Skip to content

Commit 1cda161

Browse files
committed
SCANNERAPI-173 Fix simulation mode
1 parent b245456 commit 1cda161

3 files changed

Lines changed: 18 additions & 10 deletions

File tree

api/src/main/java/org/sonarsource/scanner/api/internal/SimulatedLauncher.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@
2222
import java.io.BufferedWriter;
2323
import java.io.File;
2424
import java.io.IOException;
25-
import java.nio.charset.StandardCharsets;
25+
import java.io.OutputStream;
2626
import java.nio.file.Files;
2727
import java.nio.file.Paths;
28-
import java.util.Comparator;
28+
import java.util.Collections;
29+
import java.util.Enumeration;
2930
import java.util.Map;
3031
import java.util.Map.Entry;
32+
import java.util.Properties;
33+
import java.util.TreeSet;
3134
import org.sonarsource.scanner.api.internal.batch.IsolatedLauncher;
3235
import org.sonarsource.scanner.api.internal.batch.LogOutput;
3336
import 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
}

api/src/test/java/org/sonarsource/scanner/api/internal/SimulatedLauncherTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void failToWriteProperty() throws IOException {
6969
Map<String, String> props = createProperties();
7070
BufferedWriter writer = mock(BufferedWriter.class);
7171
doThrow(new IOException("error")).when(writer).write(anyString());
72-
72+
7373
SimulatedLauncher.writeProp(writer, props.entrySet().iterator().next());
7474
}
7575

@@ -89,7 +89,7 @@ public void error_dump() throws IOException {
8989

9090
private Map<String, String> createProperties() {
9191
Map<String, String> prop = new HashMap<>();
92-
prop.put("key1", "value1");
92+
prop.put("key1:subkey", "value1");
9393
prop.put("key2", "value2");
9494
prop.put(InternalProperties.SCANNER_DUMP_TO_FILE, filename);
9595
return prop;

batch/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<name>SonarQube Scanner API - Batch</name>
1111

1212
<properties>
13-
<sonarQubeVersion>6.4</sonarQubeVersion>
13+
<sonarQubeVersion>6.6</sonarQubeVersion>
1414
</properties>
1515

1616
<dependencies>

0 commit comments

Comments
 (0)