Skip to content

Commit 58daa50

Browse files
committed
Changed the way we handles backslashes in the parameter providers.
issue #292 backslashes backslashes
1 parent 08b4e31 commit 58daa50

5 files changed

Lines changed: 9 additions & 66 deletions

File tree

jsystem-core-projects/jsystemApp/src/main/java/jsystem/extensions/paramproviders/GenericObjectParameterProvider.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.util.ArrayList;
2121
import java.util.LinkedHashMap;
2222
import java.util.Properties;
23-
import java.util.Set;
2423
import java.util.logging.Level;
2524
import java.util.logging.Logger;
2625

@@ -80,9 +79,11 @@ public Object getFromString(String stringRepresentation) throws Exception {
8079

8180
// then extract the string to be load as properties object
8281
String propertiesString = stringRepresentation.substring(classEndIndex + 1);
83-
8482
Properties properties = new Properties();
8583
try {
84+
// Since we don't want to lose the backslashes, we need to replace each of the single backslashes with
85+
// double backslashes before loading the string to the properties object
86+
propertiesString = propertiesString.replaceAll("(?<!\\\\)\\\\(?!\\\\)", "\\\\\\\\");
8687
properties.load(new StringReader(propertiesString));
8788
} catch (IOException e1) {
8889
log.log(Level.WARNING, "Fail to load properties: " + propertiesString, e1);
@@ -150,7 +151,6 @@ private static String[] getProeprties(ArrayList<BeanElement> beanElements){
150151
return properties;
151152
}
152153

153-
154154
@Override
155155
public void setProviderConfig(String... args) {
156156
}

jsystem-core-projects/jsystemApp/src/main/java/jsystem/extensions/paramproviders/ObjectArrayParameterProvider.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,11 @@ public Object getFromString(String stringRepresentation) throws Exception {
8585

8686
// then extract the string to be load as properties object
8787
String propertiesString = stringRepresentation.substring(classEndIndex + 1);
88-
8988
Properties properties = new Properties();
9089
try {
90+
// Since we don't want to lose the backslashes, we need to replace each of the single backslashes with
91+
// double backslashes before loading the string to the properties object
92+
propertiesString = propertiesString.replaceAll("(?<!\\\\)\\\\(?!\\\\)", "\\\\\\\\");
9193
properties.load(new StringReader(propertiesString));
9294
} catch (IOException e1) {
9395
log.log(Level.WARNING, "Fail to load properties: " + propertiesString, e1);
@@ -178,7 +180,6 @@ public synchronized Object showUI(Component parent, Scenario currentScenario, Ru
178180
return object;
179181
}
180182

181-
182183
private static LinkedHashMap<String, String> propertiesToMapBeanOrder(Properties properties,
183184
ArrayList<BeanElement> elements) {
184185
LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();

jsystem-core-projects/jsystemCore/src/main/java/jsystem/framework/RunProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public Properties getRunProperties() throws IOException {
112112
private synchronized Properties loadProperties() throws IOException{
113113
Properties p = new Properties();
114114
if (runPropertiesFile.getAbsoluteFile().exists()) {
115-
p = FileUtils.loadBeanPropertiesFromFile(runPropertiesFile.getAbsolutePath());
115+
p = FileUtils.loadPropertiesFromFile(runPropertiesFile.getAbsolutePath());
116116
log.log(java.util.logging.Level.CONFIG,"load run properties at :"+runPropertiesFile.getAbsolutePath());
117117
}else{
118118
log.log(java.util.logging.Level.CONFIG,"the run properties doesn't exist,return new Properties object");

jsystem-core-projects/jsystemCore/src/main/java/jsystem/framework/report/Summary.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public synchronized Properties getProperties() {
107107
File summaryFile = new File(SUMMARY_FILE_NAME);
108108
if (summaryFile.exists()) {
109109
try {
110-
properties = FileUtils.loadBeanPropertiesFromFile(SUMMARY_FILE_NAME);
110+
properties = FileUtils.loadPropertiesFromFile(SUMMARY_FILE_NAME);
111111
} catch (Exception exception) {
112112
log.log(Level.WARNING, "Fail to load summary properties", exception);
113113
}

jsystem-core-projects/jsystemCore/src/main/java/jsystem/utils/FileUtils.java

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import java.io.BufferedInputStream;
77
import java.io.BufferedReader;
88
import java.io.BufferedWriter;
9-
import java.io.ByteArrayInputStream;
10-
import java.io.ByteArrayOutputStream;
119
import java.io.Closeable;
1210
import java.io.File;
1311
import java.io.FileInputStream;
@@ -33,11 +31,9 @@
3331
import java.util.Arrays;
3432
import java.util.Comparator;
3533
import java.util.Enumeration;
36-
import java.util.HashSet;
3734
import java.util.Iterator;
3835
import java.util.List;
3936
import java.util.Properties;
40-
import java.util.Set;
4137
import java.util.Vector;
4238
import java.util.logging.Level;
4339
import java.util.logging.Logger;
@@ -91,8 +87,6 @@ public String toString() {
9187

9288
private static Logger log = Logger.getLogger(FileUtils.class.getName());
9389

94-
private final static Set<String> beansCache = new HashSet<>();
95-
9690
public static void copyDirectory(String sourceDirName, String destinationDirName) throws IOException {
9791

9892
copyDirectory(new File(sourceDirName), new File(destinationDirName), null);
@@ -978,8 +972,6 @@ public static String[] getFilesWithExtension(String directory, String extension)
978972
* @return Properties object of the file
979973
* @throws IOException
980974
*/
981-
982-
983975
public static Properties loadPropertiesFromFile(String fileName) throws IOException {
984976
fileName = replaceSeparator(fileName);
985977
log.finest("Loading properties from file " + fileName);
@@ -990,29 +982,6 @@ public static Properties loadPropertiesFromFile(String fileName) throws IOExcept
990982
input = new FileInputStream(fileName);
991983
inputStreamReader = new InputStreamReader(input, "UTF-8");
992984
p.load(inputStreamReader);
993-
for (Object paramKey : p.keySet()) {
994-
if (paramKey.toString().endsWith("Bean")
995-
&& !beansCache.contains(p.get(paramKey.toString()).toString())) {
996-
beansCache.add(p.get(paramKey.toString()).toString());
997-
String[] beanParamValueProp = p.get(paramKey.toString()).toString().split("\r\n");
998-
StringBuilder beanParamValueFixedSB = new StringBuilder();
999-
for (String line : beanParamValueProp) {
1000-
if (!line.contains("="))
1001-
continue;
1002-
String[] keyValuePairArr = line.split("=", 2);
1003-
1004-
Pattern twoOrMoreBackslashesPattern = Pattern.compile(".*([\\\\])\\1{1,}.*");
1005-
if (twoOrMoreBackslashesPattern.matcher(keyValuePairArr[1]).find()) {
1006-
String fixedParamValBackslash = null;
1007-
fixedParamValBackslash = keyValuePairArr[1].replace("\\\\", "\\");
1008-
beanParamValueFixedSB.append(keyValuePairArr[0] + "=" + fixedParamValBackslash + "\r\n");
1009-
1010-
} else
1011-
beanParamValueFixedSB.append(line + "\r\n");
1012-
}
1013-
p.setProperty(paramKey.toString(), beanParamValueFixedSB.toString());
1014-
}
1015-
}
1016985
return p;
1017986
} finally { // close input stream
1018987
if (inputStreamReader != null) {
@@ -1023,33 +992,6 @@ public static Properties loadPropertiesFromFile(String fileName) throws IOExcept
1023992
}
1024993
}
1025994
}
1026-
1027-
1028-
public static Properties loadBeanPropertiesFromFile(String fileName) throws IOException {
1029-
1030-
Properties properties = new Properties();
1031-
try (FileInputStream input = new FileInputStream(fileName);
1032-
InputStreamReader inputStreamReader = new InputStreamReader(input, "UTF-8");
1033-
BufferedReader bfr = new BufferedReader(inputStreamReader);
1034-
ByteArrayOutputStream out = new ByteArrayOutputStream()) {
1035-
1036-
String readLine = null;
1037-
while ((readLine = bfr.readLine()) != null) {
1038-
//In JsystemApp -> GenericObjectParameterPRovider & array Provider,
1039-
//for some reason, inject this string prop representation into another
1040-
//properties file, in there the 2nd properies file treats every backslash
1041-
//as a special char as well, therefore, were multiplying the backslashes twice on purpose
1042-
1043-
out.write(readLine.replace("\\", "\\\\\\\\").getBytes());
1044-
out.write("\n".getBytes());
1045-
} // while
1046-
1047-
InputStream is = new ByteArrayInputStream(out.toByteArray());
1048-
properties.load(is);
1049-
}
1050-
return properties;
1051-
}
1052-
1053995

1054996
/**
1055997
* save given properties to a file
@@ -1366,4 +1308,4 @@ public static void moveDirectory(String sourceDirectory, String destinationDirec
13661308
}
13671309
}
13681310

1369-
}
1311+
}

0 commit comments

Comments
 (0)