Skip to content

Commit e530fa9

Browse files
Unicode handling changes (#1252)
* first pass at unicode handling * first pass at system-test * updating Jenkins test image * remove MT parts from yaml file' * disabling unicode characaters in system-test causing Jenkins to fail * removing comments * one more try to remove special characters * one more try for unicode and Jenkins * one more try for unicode and Jenkins * replacing lost changes and removing unicode characters from the tests Co-authored-by: Carolyn Rountree <[email protected]>
1 parent 0c75e7a commit e530fa9

File tree

73 files changed

+849
-533
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+849
-533
lines changed

Jenkinsfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pipeline {
3232
docker {
3333
alwaysPull true
3434
reuseNode true
35-
image 'phx.ocir.io/weblogick8s/wdt/jenkinsslave:wls12213'
35+
image 'phx.ocir.io/weblogick8s/wdt/jenkins-slave:122130'
3636
args '-u jenkins -v /var/run/docker.sock:/var/run/docker.sock'
3737
}
3838
}
@@ -57,7 +57,7 @@ pipeline {
5757
docker {
5858
alwaysPull true
5959
reuseNode true
60-
image 'phx.ocir.io/weblogick8s/wdt/jenkinsslave:wls12213'
60+
image 'phx.ocir.io/weblogick8s/wdt/jenkins-slave:122130'
6161
args '-u jenkins -v /var/run/docker.sock:/var/run/docker.sock'
6262
}
6363
}

core/src/main/java/oracle/weblogic/deploy/json/AbstractJsonTranslator.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.python.core.PyLong;
3030
import org.python.core.PyObject;
3131
import org.python.core.PyString;
32+
import org.python.core.PyUnicode;
3233

3334
/**
3435
* This class does the heavy-lifting of walking the parse tree and performing the conversion into a Python dictionary.
@@ -43,6 +44,8 @@ public abstract class AbstractJsonTranslator extends JSONBaseListener {
4344
private PyObject currentScalarValue;
4445
@SuppressWarnings("WeakerAccess")
4546
protected boolean useOrderedDict;
47+
@SuppressWarnings("WeakerAccess")
48+
protected boolean useUnicode;
4649

4750
/**
4851
* This method triggers parsing of the JSON and conversion into the Python dictionary.
@@ -109,7 +112,7 @@ public void exitPair(JSONParser.PairContext ctx) {
109112
getLogger().severe("WLSDPLY-18027", name, valueType);
110113
value = Py.None;
111114
}
112-
container.__setitem__(new PyString(name), value);
115+
container.__setitem__(this.getPythonString(name), value);
113116
}
114117

115118
/**
@@ -135,7 +138,7 @@ public void enterJsonObject(JSONParser.JsonObjectContext ctx) {
135138

136139
String name = currentPairName.peek();
137140
PyDictionary nextDict = currentDict.peek();
138-
if (name != null && nextDict != null && nextDict.has_key(new PyString(name))) {
141+
if (name != null && nextDict != null && nextDict.has_key(this.getPythonString(name))) {
139142
String message = ExceptionHelper.getMessage("WLSDPLY-18028", name);
140143
ParseCancellationException ex =
141144
new ParseCancellationException(message);
@@ -184,7 +187,7 @@ public void exitJsonArray(JSONParser.JsonArrayContext ctx) {
184187
@Override
185188
public void enterJsonString(JSONParser.JsonStringContext ctx) {
186189
String cleanString = resolveEscapeSequences(StringUtils.stripQuotes(ctx.STRING().getText()));
187-
currentScalarValue = new PyString(cleanString);
190+
currentScalarValue = this.getPythonString(cleanString);
188191
currentValueType.push(ValueType.SCALAR);
189192
}
190193

@@ -362,6 +365,14 @@ private void addToArrayIfNeeded() {
362365
}
363366
}
364367

368+
private PyObject getPythonString(String text) {
369+
if (this.useUnicode) {
370+
return new PyUnicode(text);
371+
} else {
372+
return new PyString(text);
373+
}
374+
}
375+
365376
private static String resolveEscapeSequences(String text) {
366377
String result = text;
367378
if (!StringUtils.isEmpty(text)) {

core/src/main/java/oracle/weblogic/deploy/json/JsonStreamTranslator.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates.
2+
* Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates.
33
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
*/
55
package oracle.weblogic.deploy.json;
@@ -43,6 +43,23 @@ public JsonStreamTranslator(String streamFileName, InputStream jsonStream, boole
4343
this.streamFileName = streamFileName;
4444
this.jsonStream = jsonStream;
4545
this.useOrderedDict = useOrderedDict;
46+
this.useUnicode = false;
47+
}
48+
49+
/**
50+
* The constructor used to specify ordering and unicode usage.
51+
*
52+
* @param streamFileName the name of the file used to create the InputStream (used only for logging purposes)
53+
* @param jsonStream the input stream
54+
* @param useOrderedDict whether or not to use an ordered dictionary for storing translation results
55+
* @param useUnicode whether or not to use PyUnicode instead of PyString
56+
*/
57+
public JsonStreamTranslator(String streamFileName, InputStream jsonStream,
58+
boolean useOrderedDict, boolean useUnicode) {
59+
this.streamFileName = streamFileName;
60+
this.jsonStream = jsonStream;
61+
this.useOrderedDict = useOrderedDict;
62+
this.useUnicode = useUnicode;
4663
}
4764

4865
/**

core/src/main/java/oracle/weblogic/deploy/json/JsonTranslator.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates.
2+
* Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates.
33
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
*/
55
package oracle.weblogic.deploy.json;
@@ -44,6 +44,21 @@ public JsonTranslator(String fileName) {
4444
public JsonTranslator(String fileName, boolean useOrdering) {
4545
this.jsonFile = FileUtils.validateExistingFile(fileName);
4646
this.useOrderedDict = useOrdering;
47+
this.useUnicode = false;
48+
}
49+
50+
/**
51+
* Constructor for parsing JSON file into a Python dictionary and control ordering and unicode usage.
52+
*
53+
* @param fileName - the name of the existing JSON file to parse
54+
* @param useOrdering - whether or not to use an ordered dictionary
55+
* @param useUnicode - whether or not to use PyUnicode instead of PyString
56+
* @throws IllegalArgumentException if the file name is null or does not point to a valid, existing file.
57+
*/
58+
public JsonTranslator(String fileName, boolean useOrdering, boolean useUnicode) {
59+
this.jsonFile = FileUtils.validateExistingFile(fileName);
60+
this.useOrderedDict = useOrdering;
61+
this.useUnicode = useUnicode;
4762
}
4863

4964
/**

core/src/main/java/oracle/weblogic/deploy/yaml/AbstractYamlTranslator.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.python.core.PyLong;
2525
import org.python.core.PyObject;
2626
import org.python.core.PyString;
27+
import org.python.core.PyUnicode;
2728

2829
import org.yaml.snakeyaml.DumperOptions;
2930
import org.yaml.snakeyaml.LoaderOptions;
@@ -35,6 +36,7 @@
3536
public abstract class AbstractYamlTranslator {
3637

3738
private final boolean useOrderedDict;
39+
private final boolean useUnicode;
3840
private final String fileName;
3941
private final int codePointsLimit;
4042

@@ -47,9 +49,10 @@ public abstract class AbstractYamlTranslator {
4749
// override to write a list of documents as Python dictionaries to the YAML
4850
public abstract void dumpDocuments(List<?> documents) throws YamlException;
4951

50-
protected AbstractYamlTranslator(String fileName, boolean useOrderedDict, int codePointsLimit) {
52+
protected AbstractYamlTranslator(String fileName, boolean useOrderedDict, boolean useUnicode, int codePointsLimit) {
5153
this.fileName = fileName;
5254
this.useOrderedDict = useOrderedDict;
55+
this.useUnicode = useUnicode;
5356
this.codePointsLimit = codePointsLimit;
5457
}
5558

@@ -268,7 +271,11 @@ private PyObject convertScalarToPythonObject(Object object) throws YamlException
268271
String classname = object.getClass().getName();
269272
switch (classname) {
270273
case "java.lang.String":
271-
result = new PyString((String) object);
274+
if (this.useUnicode) {
275+
result = new PyUnicode((String) object);
276+
} else {
277+
result = new PyString((String) object);
278+
}
272279
break;
273280

274281
case "java.lang.Boolean":

core/src/main/java/oracle/weblogic/deploy/yaml/YamlStreamTranslator.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class YamlStreamTranslator extends AbstractYamlTranslator {
3232
* @param yamlStream the input stream
3333
*/
3434
public YamlStreamTranslator(String streamFileName, InputStream yamlStream) {
35-
this(streamFileName, yamlStream, false);
35+
this(streamFileName, yamlStream, false, false, 0);
3636
}
3737

3838
/**
@@ -43,7 +43,7 @@ public YamlStreamTranslator(String streamFileName, InputStream yamlStream) {
4343
* @param useOrderedDict whether or not to use an ordered dictionary to maintain the order
4444
*/
4545
public YamlStreamTranslator(String streamFileName, InputStream yamlStream, boolean useOrderedDict) {
46-
super(streamFileName, useOrderedDict, 0);
46+
super(streamFileName, useOrderedDict, false, 0);
4747
this.streamFileName = streamFileName;
4848
this.yamlStream = yamlStream;
4949
this.yamlOutputWriter = null;
@@ -57,21 +57,39 @@ public YamlStreamTranslator(String streamFileName, InputStream yamlStream, boole
5757
* @param useOrderedDict whether or not to use an ordered dictionary to maintain the order
5858
* @param maxCodePoints the maximum number of characters that the parser will accept
5959
*/
60-
public YamlStreamTranslator(String streamFileName, InputStream yamlStream, boolean useOrderedDict, int maxCodePoints) {
61-
super(streamFileName, useOrderedDict, maxCodePoints);
60+
public YamlStreamTranslator(String streamFileName, InputStream yamlStream, boolean useOrderedDict,
61+
int maxCodePoints) {
62+
super(streamFileName, useOrderedDict, false, maxCodePoints);
6263
this.streamFileName = streamFileName;
6364
this.yamlStream = yamlStream;
6465
this.yamlOutputWriter = null;
6566
}
6667

68+
/**
69+
* The constructor that allows control of everything.
70+
* @param streamFileName the name of the file used to create the InputStream (used only for logging purposes)
71+
* @param yamlStream the input stream
72+
* @param useOrderedDict whether or not to use an ordered dictionary to maintain the order
73+
* @param useUnicode whether or not to use PyUnicode instead of PyString
74+
* @param maxCodePoints the maximum number of characters that the parser will accept
75+
*/
76+
public YamlStreamTranslator(String streamFileName, InputStream yamlStream, boolean useOrderedDict,
77+
boolean useUnicode, int maxCodePoints) {
78+
super(streamFileName, useOrderedDict, useUnicode, maxCodePoints);
79+
this.streamFileName = streamFileName;
80+
this.yamlStream = yamlStream;
81+
this.yamlOutputWriter = null;
82+
}
83+
84+
6785
/**
6886
* The constructor for writing YAML output.
6987
*
7088
* @param streamFileName the name of the file used to create the OutputStream (used only for logging purposes)
7189
* @param yamlOutputWriter the Writer to use for writing the YAML output
7290
*/
7391
public YamlStreamTranslator(String streamFileName, Writer yamlOutputWriter) {
74-
super(streamFileName, true, 0);
92+
super(streamFileName, true, false, 0);
7593
this.streamFileName = streamFileName;
7694
this.yamlStream = null;
7795
this.yamlOutputWriter = yamlOutputWriter;

core/src/main/java/oracle/weblogic/deploy/yaml/YamlTranslator.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class YamlTranslator extends AbstractYamlTranslator {
3232
* @throws IllegalArgumentException if the file name is null or does not point to a valid, existing file.
3333
*/
3434
public YamlTranslator(String fileName) {
35-
this(fileName, false, 0);
35+
this(fileName, false, false, 0);
3636
}
3737

3838
/**
@@ -43,7 +43,7 @@ public YamlTranslator(String fileName) {
4343
* @throws IllegalArgumentException if the file name is null or does not point to a valid, existing file.
4444
*/
4545
public YamlTranslator(String fileName, boolean useOrderedDict) {
46-
super(fileName, useOrderedDict, 0);
46+
super(fileName, useOrderedDict, false, 0);
4747
this.yamlFile = FileUtils.validateExistingFile(fileName);
4848
}
4949

@@ -57,7 +57,21 @@ public YamlTranslator(String fileName, boolean useOrderedDict) {
5757
* @throws IllegalArgumentException if the file name is null or does not point to a valid, existing file.
5858
*/
5959
public YamlTranslator(String fileName, boolean useOrderedDict, int maxCodePoints) {
60-
super(fileName, useOrderedDict, maxCodePoints);
60+
super(fileName, useOrderedDict, false, maxCodePoints);
61+
this.yamlFile = FileUtils.validateExistingFile(fileName);
62+
}
63+
64+
/**
65+
* Constructor for parsing YAML file into a Python dictionary, controlling everything.
66+
*
67+
* @param fileName the name of the existing YAML file to parse
68+
* @param useOrderedDict whether or not to use an ordered dictionary to maintain the order
69+
* @param useUnicode whether or not to use PyUnicode instead of PyString
70+
* @param maxCodePoints the maximum number of code points for the input file, or zero to accept the default
71+
* @throws IllegalArgumentException if the file name is null or does not point to a valid, existing file.
72+
*/
73+
public YamlTranslator(String fileName, boolean useOrderedDict, boolean useUnicode, int maxCodePoints) {
74+
super(fileName, useOrderedDict, useUnicode, maxCodePoints);
6175
this.yamlFile = FileUtils.validateExistingFile(fileName);
6276
}
6377

0 commit comments

Comments
 (0)