Skip to content

Commit 1af1e2b

Browse files
committed
Better comments and fix broken test.
1 parent b710a7e commit 1af1e2b

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

java/org/apache/tomcat/buildutil/translate/Utils.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ static Properties load(File f) {
7171
}
7272

7373

74+
/*
75+
* This is the formatting applied when exporting values from Tomcat to POE.
76+
*
77+
* The values have been read from Tomcat's property files (so the input is the actual value with none of the
78+
* escaping required to represent that value in a property file) and are being written back out in a single file to
79+
* be imported into POEditor. The padding for blank lines needs to be added followed by the common formatting
80+
* required to convert a property value to the representation of that value in a file.
81+
*/
7482
static String formatValueExport(String in) {
7583
String result;
7684

@@ -84,6 +92,14 @@ static String formatValueExport(String in) {
8492
}
8593

8694

95+
/*
96+
* This is the formatting applied when importing values to Tomcat from POE.
97+
*
98+
* The values have been read from POE's property files (so the input is the actual value with none of the
99+
* escaping required to represent that value in a property file) and are being written back out to individual files
100+
* in Tomcat. The padding for blank lines needs to be removed followed by the common formatting required to convert
101+
* a property value to the representation of that value in a file.
102+
*/
87103
static String formatValueImport(String in) {
88104
String result;
89105

@@ -111,7 +127,13 @@ static String fixUnnecessaryEscaping(String key, String value) {
111127

112128

113129
/*
114-
* Common formatting to convert a String for storage as a value in a property file.
130+
* Common formatting to convert a String value for storage as a value in a property file. Values that contain
131+
* line-breaks need the line-break in the value to be replaced with the correct representation of a line-break in a
132+
* property file. Leading space needs to be escaped with a '\' and horizontal tabs need to be converted to "\t".
133+
*
134+
* Note that a single '\' needs to be escaped both in a Java string and in a property file so if a property value
135+
* needs to contain a single `\` (e.g. to escape white space at the start of a line) that will appear as "\\\\" in
136+
* the Java code.
115137
*/
116138
static String formatValueCommon(String in) {
117139
String result = in.replace("\n", "\\n\\\n");

test/org/apache/tomcat/buildutil/translate/TestUtils.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,36 @@ public class TestUtils {
2323

2424
@Test
2525
public void testFormatValue01() {
26-
// Import from Tomcat
27-
Assert.assertEquals("\\n\\\n</web-fragment>\\n", Utils.formatValueImport("\\n\\\n</web-fragment>\\n"));
26+
// Import from POE
27+
Assert.assertEquals("line1\\n\\\nline2\\n\\\nline3", Utils.formatValueImport("line1\nline2\nline3"));
2828
}
2929

3030
@Test
3131
public void testFormatValue02() {
32-
// Import from POEditor
33-
Assert.assertEquals("\\n\\\n</web-fragment>\\n", Utils.formatValueImport("\\n</web-fragment>\\n"));
32+
// Import from POE
33+
Assert.assertEquals("\\n\\\nline2\\n\\\nline3", Utils.formatValueImport(Utils.PADDING + "\nline2\nline3"));
3434
}
3535

3636
@Test
3737
public void testFormatValue03() {
38+
// Import from POE
39+
Assert.assertEquals("line1\\n\\\n\\tline2\\n\\\n\\tline3", Utils.formatValueImport("line1\n\tline2\n\tline3"));
40+
}
41+
42+
@Test
43+
public void testFormatValue04() {
3844
// Export from Tomcat
3945
Assert.assertEquals("line1\\n\\\nline2\\n\\\nline3", Utils.formatValueExport("line1\nline2\nline3"));
4046
}
4147

4248
@Test
43-
public void testFormatValue04() {
49+
public void testFormatValue05() {
4450
// Export from Tomcat
4551
Assert.assertEquals(Utils.PADDING + "\\n\\\nline2\\n\\\nline3", Utils.formatValueExport("\nline2\nline3"));
4652
}
4753

4854
@Test
49-
public void testFormatValue05() {
55+
public void testFormatValue06() {
5056
// Export from Tomcat
5157
Assert.assertEquals("line1\\n\\\n\\tline2\\n\\\n\\tline3", Utils.formatValueExport("line1\n\tline2\n\tline3"));
5258
}

0 commit comments

Comments
 (0)