Skip to content
Permalink
Browse files

[FIXED JENKINS-22530] Properly parse files with multi-line properties.

  • Loading branch information
xstex authored and orrc committed May 13, 2014
1 parent 875e3b1 commit 1a7a66ef760f5a2da2815f1348ee542df7b40d99
@@ -38,6 +38,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;
@@ -431,25 +432,21 @@ public static void runAndroidTool(Launcher launcher, EnvVars env, OutputStream s
* @return The key-value pairs contained in the file, ignoring any comments or blank lines.
* @throws IOException If the file could not be read.
*/
public static Map<String,String> parseConfigFile(File configFile) throws IOException {
public static Map<String, String> parseConfigFile(File configFile) throws IOException {
FileReader fileReader = new FileReader(configFile);
BufferedReader reader = new BufferedReader(fileReader);
Properties properties = new Properties();
properties.load(reader);
reader.close();

String line;
Map<String,String> values = new HashMap<String,String>();
while ((line = reader.readLine()) != null) {
line = line.trim();
if (line.length() == 0 || line.charAt(0) == '#') {
continue;
}
String[] parts = line.split("=", 2);
values.put(parts[0], parts[1]);
final Map<String, String> values = new HashMap<String, String>();
for (final Map.Entry<Object, Object> entry : properties.entrySet()) {
values.put((String) entry.getKey(), (String) entry.getValue());
}

return values;
}


/**
* Expands the variable in the given string to its value in the environment variables available
* to this build. The Jenkins-specific build variables for this build are then substituted.
@@ -2,6 +2,10 @@

import junit.framework.TestCase;

import java.io.File;
import java.io.PrintWriter;
import java.util.Map;

@SuppressWarnings("static-method")
public class UtilsTest extends TestCase {

@@ -89,4 +93,15 @@ public void testGetApiLevelFromPlatform() {
assertEquals(-1, Utils.getApiLevelFromPlatform("Android 4.2"));
}

public void testReadProperties() throws Exception {
final File temp = File.createTempFile("temp", ".txt");
temp.deleteOnExit();
final PrintWriter writer = new PrintWriter(temp);
writer.println("key=value\\\nsplit\\\nin\\\nlines\n");
writer.close();

final Map<String, String> map = Utils.parseConfigFile(temp);
assertEquals(1, map.size());
}

}

0 comments on commit 1a7a66e

Please sign in to comment.
You can’t perform that action at this time.