8181414: Refactor misc test/sun/net/www/protocol/jar shell tests to plain java tests
authorxiaofeya
Sun, 04 Jun 2017 18:42:42 -0700
changeset 45386 eda2fa9ba27e
parent 45385 a71fdce20589
child 45387 179605f4d367
8181414: Refactor misc test/sun/net/www/protocol/jar shell tests to plain java tests Reviewed-by: psandoz
jdk/test/sun/net/www/protocol/jar/B5105410.java
jdk/test/sun/net/www/protocol/jar/B5105410.sh
jdk/test/sun/net/www/protocol/jar/B6449504.java
jdk/test/sun/net/www/protocol/jar/GetContentType.java
jdk/test/sun/net/www/protocol/jar/GetContentTypeTest.java
jdk/test/sun/net/www/protocol/jar/copyin.sh
jdk/test/sun/net/www/protocol/jar/getcontenttype.sh
--- a/jdk/test/sun/net/www/protocol/jar/B5105410.java	Sat Jun 03 03:48:03 2017 +0000
+++ b/jdk/test/sun/net/www/protocol/jar/B5105410.java	Sun Jun 04 18:42:42 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -21,23 +21,43 @@
  * questions.
  */
 
-import java.net.*;
-import java.io.*;
+/**
+ * @test
+ * @bug 5105410
+ * @run main/othervm B5105410
+ * @summary ZipFile$ZipFileInputStream doesn't close handle to zipfile
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
 
 public class B5105410 {
     public static void main (String[] args) throws Exception {
-        URL url = new URL ("jar:file:./foo2.jar!/bar.txt");
-        URLConnection urlc = url.openConnection ();
-        urlc.setUseCaches (false);
+        setup();
+        URL url = new URL("jar:file:./foo2.jar!/bar.txt");
+        URLConnection urlc = url.openConnection();
+        urlc.setUseCaches(false);
         InputStream is = urlc.getInputStream();
         is.read();
         is.close();
-        File file = new File ("foo2.jar");
-        if (!file.delete ()) {
-            throw new RuntimeException ("Could not delete foo2.jar");
+        File file = new File("foo2.jar");
+        if (!file.delete()) {
+            throw new RuntimeException("Could not delete foo2.jar");
         }
         if (file.exists()) {
-            throw new RuntimeException ("foo2.jar still exists");
+            throw new RuntimeException("foo2.jar still exists");
         }
     }
+
+    static void setup() throws IOException {
+        Files.copy(Paths.get(System.getProperty("test.src"), "foo2.jar"),
+                   Paths.get(".", "foo2.jar"), REPLACE_EXISTING);
+    }
 }
+
--- a/jdk/test/sun/net/www/protocol/jar/B5105410.sh	Sat Jun 03 03:48:03 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,55 +0,0 @@
-#! /bin/sh
-
-#
-# Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-#
-# This code is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-# @test
-# @author Michael McMahon
-# @bug 5105410
-# @summary ZipFile$ZipFileInputStream doesn't close handle to zipfile
-#
-
-OS=`uname -s`
-case "$OS" in
-  SunOS | Linux | Darwin | AIX )
-    PS=":"
-    FS="/"
-    ;;
-  CYGWIN* )
-    PS=";"
-    FS="/"
-    ;;
-  Windows* )
-    PS=";"
-    FS="\\"
-    ;;
-  * )
-    echo "Unrecognized system!"
-    exit 1;
-    ;;
-esac
-
-cp ${TESTSRC}${FS}foo2.jar .
-${COMPILEJAVA}${FS}bin${FS}javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d . ${TESTSRC}${FS}B5105410.java
-${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} B5105410
-
--- a/jdk/test/sun/net/www/protocol/jar/B6449504.java	Sat Jun 03 03:48:03 2017 +0000
+++ b/jdk/test/sun/net/www/protocol/jar/B6449504.java	Sun Jun 04 18:42:42 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,63 +24,72 @@
 /**
  * @test
  * @bug 6449504
- * @run shell copyin.sh bar.jar
  * @run main B6449504 caching
  * @run main B6449504 no_caching
  * @summary REGRESSION: ZipException throws when try to read a XML file
  */
 
-import java.io.*;
-import java.net.*;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.JarURLConnection;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
 
 public class B6449504 {
 
     public static void main (String[] args) throws Exception {
-
-        boolean caching = args[0].equals ("caching");
-
-        String dirname = System.getProperty ("test.classes");
-        File f = new File (dirname);
+        setup();
+        boolean caching = args[0].equals("caching");
+        String dirname = System.getProperty("test.classes");
+        File f = new File(dirname);
         dirname = f.toURI().toString();
 
-        String u = "jar:"+ dirname + "/bar.jar";
-        URL url = new URL (u+"!/DoesNotExist.txt");
-        System.out.println ("url = " + url);
+        String u = "jar:" + dirname + "/bar.jar";
+        URL url = new URL(u + "!/DoesNotExist.txt");
+        System.out.println("url = " + url);
         JarURLConnection j1 = (JarURLConnection)url.openConnection();
 
-        URL url2 = new URL (u+"!/test.txt");
-        System.out.println ("url2 = " + url2);
+        URL url2 = new URL(u + "!/test.txt");
+        System.out.println("url2 = " + url2);
         JarURLConnection j2 = (JarURLConnection)url2.openConnection();
 
-        j1.setUseCaches (caching);
-        j2.setUseCaches (caching);
+        j1.setUseCaches(caching);
+        j2.setUseCaches(caching);
 
         /* connecting to j2 opens the jar file but does not read it */
 
-        j2.connect ();
+        j2.connect();
 
         try {
             /* attempt to read a non-existing entry in the jar file
              * shows the bug, where the jar file is closed after the
              * attempt fails.
              */
-            InputStream is = j1.getInputStream ();
+            InputStream is = j1.getInputStream();
         } catch (IOException e) {
-            System.out.println ("Got expected exception from j1 ");
+            System.out.println("Got expected exception from j1 ");
         }
 
         /* If bug present, this will fail because we think the jar
          * is ready to be read, after the connect() above, but we
          * get a ZipException because it has been closed
          */
-        InputStream is = j2.getInputStream ();
-        readAndClose (is);
-        System.out.println ("OK");
+        InputStream is = j2.getInputStream();
+        readAndClose(is);
+        System.out.println("OK");
     }
 
-    static void readAndClose (InputStream is) throws IOException {
+    static void readAndClose(InputStream is) throws IOException {
         while (is.read() != -1) ;
         is.close();
     }
 
+    static void setup() throws IOException {
+        Files.copy(Paths.get(System.getProperty("test.src"), "bar.jar"),
+                   Paths.get(System.getProperty("test.classes"), "bar.jar"),
+                   StandardCopyOption.REPLACE_EXISTING);
+    }
 }
--- a/jdk/test/sun/net/www/protocol/jar/GetContentType.java	Sat Jun 03 03:48:03 2017 +0000
+++ b/jdk/test/sun/net/www/protocol/jar/GetContentType.java	Sun Jun 04 18:42:42 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -21,18 +21,8 @@
  * questions.
  */
 
-/*
- * @test
- * @bug 4274624
- * @summary  Test JarURLConnection.getContentType would
- *           would return default "content/unknown"
- *
- * @build GetContentType
- * @run shell getcontenttype.sh
- */
-
+import java.io.InputStream;
 import java.net.URL;
-import java.io.InputStream;
 
 public class GetContentType {
     public static void main(String args[]) throws Exception {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/sun/net/www/protocol/jar/GetContentTypeTest.java	Sun Jun 04 18:42:42 2017 -0700
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 4274624
+ * @library /test/lib
+ * @build GetContentType GetContentTypeTest
+ *        jdk.test.lib.JDKToolFinder
+ *        jdk.test.lib.process.*
+ * @run main/othervm GetContentTypeTest
+ * @summary Test JarURLConnection.getContentType would
+ *          would return default "content/unknown"
+ */
+
+import jdk.test.lib.JDKToolFinder;
+import jdk.test.lib.process.ProcessTools;
+
+import java.io.File;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+public class GetContentTypeTest {
+    public static void main(String[] args) throws Throwable {
+        Path resJar = Paths.get(System.getProperty("test.src"),
+                "resource.jar");
+        Path classes = Paths.get(System.getProperty("test.classes"));
+        ProcessTools.executeCommand(
+                JDKToolFinder.getTestJDKTool("java"),
+                "-cp", resJar + File.pathSeparator + classes, "GetContentType")
+                .outputTo(System.out)
+                .errorTo(System.out)
+                .shouldHaveExitValue(0);
+    }
+}
--- a/jdk/test/sun/net/www/protocol/jar/copyin.sh	Sat Jun 03 03:48:03 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,31 +0,0 @@
-#!/bin/ksh
-
-#
-# Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-#
-# This code is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-echo current directory is `pwd`
-set -x
-for i in $*; do
-    rm -f $TESTCLASSES/$i
-    cp $TESTSRC/$i $TESTCLASSES
-done
--- a/jdk/test/sun/net/www/protocol/jar/getcontenttype.sh	Sat Jun 03 03:48:03 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,51 +0,0 @@
-#! /bin/sh
-
-#
-# Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-#
-# This code is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-#
-
-if [ x"$TESTJAVA" = x ]; then 
-        TESTJAVA=$1 
-        shift 
-fi
-if [ x"$TESTCLASSES" = x ]; then TESTCLASSES=.; fi
-if [ x"$TESTSRC" = x ]; then TESTSRC=.; fi
-
-OS=`uname -s`;
-# Set classpath separator
-case "$OS" in
-        Windows* | CYGWIN* )
-        SEP=";"
-        FS="\\"
-        ;;
-
-        * )
-        SEP=":"
-        FS="/"
-        ;;
-esac
-
-# now start the test
-${TESTJAVA}/bin/java ${TESTVMOPTS} -cp ${TESTSRC}${FS}resource.jar${SEP}${TESTCLASSES} GetContentType
-