view patches/openjdk/7199153-try_with_resources_pushed_to_6.patch @ 2598:fdde7e12b1e5 icedtea6-1.10.10

S7199153: TEST_BUG: try-with-resources syntax pushed to 6-open repo 2012-10-15 Andrew John Hughes <gnu.andrew@redhat.com> * Makefile.am: (ICEDTEA_PATCHES): Add new patch. * NEWS: Mention S7199153. * patches/openjdk/7199153-try_with_resources_pushed_to_6.patch: Added to fix tests from previous commit.
author Andrew John Hughes <ahughes@redhat.com>
date Tue, 16 Oct 2012 16:13:14 +0100
parents
children
line wrap: on
line source

# HG changeset patch
# User coffeys
# Date 1348007758 -3600
# Node ID 0abac47de6d12023982e35effe00ea028d613b5e
# Parent  5998d43cb08ce2477ad9ba7970a26ef5be1f175c
7199153: TEST_BUG: try-with-resources syntax pushed to 6-open repo
Reviewed-by: ohair

diff --git a/test/sun/tools/native2ascii/Permission.java b/test/sun/tools/native2ascii/Permission.java
--- openjdk/jdk/test/sun/tools/native2ascii/Permission.java
+++ openjdk/jdk/test/sun/tools/native2ascii/Permission.java
@@ -21,25 +21,43 @@
  * questions.
  */
 
-/**
+/*
  * @test
- * @bug 7177216
+ * @bug 7177216 7199153
  * @summary resulting file of native2ascii should have normal permission
  */
 
 import java.io.*;
-import java.nio.file.*;
-import java.nio.file.attribute.*;
 import sun.tools.native2ascii.Main;
 
 public class Permission {
 
     private static void cleanup(String... fnames) throws Throwable {
         for (String fname : fnames) {
-            Files.deleteIfExists(Paths.get(fname)); 
+            File f = new File(fname);
+            if (f.exists())
+                f.delete();
         }
     }
 
+    private static String permission(String fname) throws Throwable {
+        Process p = Runtime.getRuntime().exec("ls -l " + fname);
+        InputStream is = null;
+        String ret = null;
+        if (p != null && (is = p.getInputStream()) != null) {
+            p.waitFor();
+            BufferedReader br = new BufferedReader(new InputStreamReader(is, "ISO-8859-1"));
+            try {
+                ret = br.readLine();
+                if (ret != null)
+                    ret = ret.split(" ")[0];
+            } finally {
+                br.close();
+            }
+        }
+        return ret;
+    }
+
     public static void realMain(String[] args) throws Throwable {
         if (!System.getProperty("os.name").startsWith("Windows")) {
             String src = "native2ascii_permtest_src";
@@ -47,21 +65,22 @@
 
             cleanup(src, dst);
             try {
-                try (FileOutputStream fos = new FileOutputStream(src)) {
+                FileOutputStream fos = new FileOutputStream(src);
+                try {
                     fos.write('a'); fos.write('b'); fos.write('c');
+                } finally {
+                    fos.close();
                 }
                 String[] n2aArgs = new String[] {"-encoding", "utf8", src, dst};
                 if (!new Main().convert(n2aArgs)) {
                     fail("n2a failed.");
                 }
-                equal(Files.getPosixFilePermissions(Paths.get(src)),
-                      Files.getPosixFilePermissions(Paths.get(dst)));
+                equal(permission(src), permission(dst));
                 String[] a2nArgs = new String[] {"-reverse", "-encoding", "utf8", dst, src};
                 if (!new Main().convert(a2nArgs)) {
                     fail("a2n failed.");
                 }
-                equal(Files.getPosixFilePermissions(Paths.get(src)),
-                      Files.getPosixFilePermissions(Paths.get(dst)));
+                equal(permission(src), permission(dst));
             } finally {
                 cleanup(src, dst);
             }
diff --git a/test/tools/jar/UpdateJar.java b/test/tools/jar/UpdateJar.java
--- openjdk/jdk/test/tools/jar/UpdateJar.java
+++ openjdk/jdk/test/tools/jar/UpdateJar.java
@@ -23,48 +23,76 @@
 
 /**
  * @test
- * @bug 7175845
+ * @bug 7175845 7199153
  * @summary jar -uf should not change file permission
  */
 
 import java.io.*;
-import java.nio.file.*;
-import java.nio.file.attribute.*;
-import java.util.Set;
 import sun.tools.jar.Main;
 
 public class UpdateJar {
 
-    private static void cleanup(String... fnames) throws Throwable {
-        for (String fname : fnames) {
-            Files.deleteIfExists(Paths.get(fname)); 
+    private static void cleanup(File f) throws Throwable {
+        if (f.exists())
+            f.delete();
+    }
+
+    private static String permission(String fname) throws Throwable {
+        Process p = Runtime.getRuntime().exec("ls -l " + fname);
+        InputStream is = null;
+        String ret = null;
+        if (p != null && (is = p.getInputStream()) != null) {
+            p.waitFor();
+            BufferedReader br = new BufferedReader(new InputStreamReader(is, "ISO-8859-1"));
+            try {
+                ret = br.readLine();
+                if (ret != null)
+                    ret = ret.split(" ")[0];
+            } finally {
+                br.close();
+            }
         }
+        return ret;
     }
 
     public static void realMain(String[] args) throws Throwable {
         if (!System.getProperty("os.name").startsWith("Windows")) {
-            String jar = "testUpdateJar.jar";
-            String e0  = "testUpdateJar_entry0.txt";
-            String e1  = "testUpdateJar_entry1.txt";
-            cleanup(jar, e0, e1);
+            String jarName = "testUpdateJar.jar";
+            String e0Name = "testUpdateJar_entry0.txt";
+            String e1Name = "testUpdateJar_entry1.txt";
+
+            File jar = new File(jarName);
+            File e0 = new File(e0Name);
+            File e1 = new File(e1Name);
             try {
-                try (FileOutputStream fos0 = new FileOutputStream(e0);
-                     FileOutputStream fos1 = new FileOutputStream(e1)) {
-                    fos0.write(0);
-                    fos1.write(0);
-                }
-                String[] jarArgs = new String[] {"cfM0", jar, e0};
+                cleanup(jar);
+                cleanup(e0);
+                cleanup(e1);
+
+                FileOutputStream fos = new FileOutputStream(e0Name);
+                fos.write(0);
+                fos.close();
+
+                fos = new FileOutputStream(e1Name);
+                fos.write(0);
+                fos.close();
+
+                String[] jarArgs = new String[] {"cfM0", jarName, e0Name};
                 if (!new Main(System.out, System.err, "jar").run(jarArgs)) {
                     fail("Could not create jar file.");
                 }
-                Set<PosixFilePermission> pm = Files.getPosixFilePermissions(Paths.get(jar));
-                jarArgs = new String[] {"uf", jar, e1};
+                String pm = permission(jarName);
+                jarArgs = new String[] {"uf", jarName, e1Name};
                 if (!new Main(System.out, System.err, "jar").run(jarArgs)) {
                     fail("Could not create jar file.");
                 }
-                equal(pm, Files.getPosixFilePermissions(Paths.get(jar)));
+                equal(pm, permission(jarName));
+
             } finally {
-                cleanup(jar, e0, e1);
+                cleanup(jar);
+                cleanup(e0);
+                cleanup(e1);
+
             }
         }
     }
@@ -84,4 +112,3 @@
         System.out.println("\nPassed = " + passed + " failed = " + failed);
         if (failed > 0) throw new AssertionError("Some tests failed");}
 }
-