1. David Black
  2. atlassian-processutils

Commits

Michael Heemskerk  committed 7a53532 Merge

Disabled a number of tests that are guaranteed to fail under linux. The jvm appears to always use UTF-8 to encode process cmdline parameters on linux

  • Participants
  • Parent commits f1e0c50, 4381b3f
  • Branches 1.5.x

Comments (0)

Files changed (5)

File .hgtags

View file
 f583ef26fc4ceeefa968683749fa55f22afc59d2 atlassian-processutils-1.5-beta11
 c11b314b02f1c1490024dbc87623cfa0fc5f9e51 atlassian-processutils-1.5-rc1
 0006b2ff8f692eef47b9f5b149ddf02280d8abb6 atlassian-processutils-1.5-rc2
+<<<<<<< local
 1715c02500dc3d99fa1baf5bc361b15b726e03dd atlassian-processutils-1.3.1
 93e69ea723cf82bb98fa2c78a26ad27a441a2efb atlassian-processutils-1.3.2
 974342911be56b2fd61e80a8aab8ee776106fe7f atlassian-processutils-1.3.3
 788d7eacfc99bc2994594fbb5c68b98b6971bb60 atlassian-processutils-1.5-rc3
+=======
+9a018567077cff394c9985146613db5b675d7240 atlassian-processutils-1.5-rc5.stash
+>>>>>>> other

File pom.xml

File contents unchanged.

File src/test/java/com/atlassian/utils/process/CallEcho.java

View file
 package com.atlassian.utils.process;
 
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.io.OutputStreamWriter;
 import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Properties;
      * @return -
      * @throws UnsupportedEncodingException -
      */
-    private static String getBytes(String value) throws UnsupportedEncodingException {
+    public static String getBytes(String value) throws UnsupportedEncodingException {
         if (value == null) {
             return null;
         }
         return builder.toString();
     }
 
+    private static String transcode(String input, String charset) throws IOException {
+        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+        // it's expected that java will use the default encoding to w
+        OutputStreamWriter writer = new OutputStreamWriter(outputStream, Charset.defaultCharset());
+        writer.write(input);
+        writer.close();
+
+        return outputStream.toString(charset);
+    }
+    
     public static void main(String[] args) throws IOException, InterruptedException {
         Properties testStrings = new Properties();
         testStrings.load(CallEcho.class.getResourceAsStream("/echostrings.properties"));
         if (!echo.isEmpty()) {
             final String[] result = new String[1];
             // we're calling yet another java process here because the echo application on windows is doing character conversions as well
-            // using a java process at least gives us control over the encodings it uses. Java will use the default encoding (-Dfile.encoding) 
-            // to convert command line arguments into Java Strings 
+            // using a java process at least gives us control over the encodings it uses. Java will use the default encoding (-Dfile.encoding)
+            // to convert command line arguments into Java Strings
             String encoding = System.getProperty("file.encoding");
             List<String> echoCmd = Arrays.asList("java", "-Dfile.encoding=" + encoding, "com.atlassian.utils.process.Echo", echo);
 
+            // using the error stream to write debug information
+            System.err.println("Call-Echo: real bytes           : " + getBytes(echo));
+            
+            // this is the expected behaviour; the unicode bytes will be 
+            System.err.println("Call-Echo: expected transcode   : " + getBytes(transcode(echo, encoding)) + " - " + encoding);
+            System.err.println("Call-Echo: transcoded to UTF-8  : " + getBytes(transcode(echo, "UTF-8")));
+            System.err.println("Call-Echo: transcoded to 8859-1 : " + getBytes(transcode(echo, "ISO-8859-1")));
+
             // the command line arguments will be converted using the default encoding (file.encoding). 
             // The lineoutputhandler needs to use the same encoding to process the results. Otherwise, encoding errors will occur.
             ExternalProcess process = new ExternalProcessBuilder()

File src/test/java/com/atlassian/utils/process/Echo.java

View file
 package com.atlassian.utils.process;
 
+import java.nio.charset.Charset;
+
 public class Echo {
 	/**
 	 * @param args
 	 */
 	public static void main(String[] args) {
-		System.err.println("Encoding " + System.getProperty("file.encoding"));
-		System.err.println("Platform " + System.getProperty("os.name").toLowerCase());
+        for (String arg : args) {
+            try {
+                // using the error stream to write debug information
+                System.err.println("Echo: received param     " + CallEcho.getBytes(arg) + " in encoding " + Charset.defaultCharset());
+            } catch (Exception e) {
+                // no-op
+            }
+        }
+
 		String sep = "";
 		for (String str : args) {
 			System.out.println(sep + str);

File src/test/java/com/atlassian/utils/process/ProcessBuilderEncodingTest.java

View file
         return System.getProperty("os.name").toLowerCase().contains("windows");
     }
 
+    protected boolean isLinux() {
+        return System.getProperty("os.name").toLowerCase().contains("linux");
+    }
+
     @Test
     public void testIncompatibleCommandLineArgumentsASCII() throws Exception {
         EchoResult result = spawnEcho("ASCII", "iso-8859-1");
 
     @Test
     public void testCommandLineArgumentsWin1252() throws Exception {
-        if (Charset.isSupported("windows-1252")) {
+        if (Charset.isSupported("windows-1252") && !isLinux()) {
+            // test is disabled in linux because (ubuntu) linux always uses UTF-8 to encode parameters, causing this test to fail
             EchoResult result = spawnEcho("windows-1252", "iso-8859-1");
             assertEquals("Windows cp 1252 -  incompatibility detected:", result.input, result.output);
         }
 
     @Test
     public void testCommandLineArgumentsIso88591() throws Exception {
-        EchoResult result = spawnEcho("iso-8859-1", "iso-8859-1");
-        assertEquals("ISO-8859-1 - incompatibility detected:", result.input, result.output);
+        if (!isLinux()) {
+            // test is disabled in linux because (ubuntu) linux always uses UTF-8 to encode parameters, causing this test to fail
+            EchoResult result = spawnEcho("iso-8859-1", "iso-8859-1");
+            assertEquals("ISO-8859-1 - incompatibility detected:", result.input, result.output);
+        }
     }
 
     @Test