Skip to content
Snippets Groups Projects
Commit 4f2e94d6 authored by Felix Yang's avatar Felix Yang
Browse files

8166139: Refactor java/net shell cases to java

Reviewed-by: chegar, rriggs
parent f6dbb7ba
No related branches found
No related tags found
No related merge requests found
Showing
with 510 additions and 726 deletions
#
# Copyright (c) 2006, 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
# @bug 6449565
# @run shell/timeout=140 OldSocketImpl.sh
# @summary Pre-1.4 SocketImpl no longer supported
OS=`uname -s`
case "$OS" in
SunOS | Linux | Darwin | AIX )
PS=":"
FS="/"
;;
CYGWIN* )
PS=";"
FS="/"
;;
Windows* )
PS=";"
FS="\\"
;;
* )
echo "Unrecognized system!"
exit 1;
;;
esac
# no need to compile the test. It is already compiled
# with 1.3 and in OldStyleImpl.jar
# run
${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} -cp ${TESTSRC}${FS}OldSocketImpl.jar OldSocketImpl
result=$?
if [ "$result" -ne "0" ]; then
exit 1
fi
# no failures, exit.
exit 0
/*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
* 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
......@@ -21,25 +21,26 @@
* questions.
*/
import java.io.*;
import java.net.*;
import jdk.test.lib.process.ProcessTools;
public class B5077773 {
import java.nio.file.Path;
import java.nio.file.Paths;
public static void main(String[] args) throws Exception {
URLClassLoader loader = new URLClassLoader (new URL[] {new URL("file:foo.jar")});
/* This test will fail if the file below is removed from rt.jar */
InputStream is = loader.getResourceAsStream ("javax/swing/text/rtf/charsets/mac.txt");
if (is == null) {
System.out.println ("could not find mac.txt");
return;
}
int c=0;
while ((is.read()) != -1) {
c++;
}
if (c == 26) /* size of bad file */ {
throw new RuntimeException ("Wrong mac.txt file was loaded");
}
/**
* @test
* @bug 6449565
* @library /test/lib
* @build jdk.test.lib.process.ProcessTools
* @run main OldSocketImplTestDriver
* @summary Test driver for OdlSocketImpl
*/
public class OldSocketImplTestDriver {
public static void main(String[] args) throws Throwable {
Path jar = Paths.get(System.getProperty("test.src"),
"OldSocketImpl.jar");
ProcessTools.executeTestJava("-cp", jar.toString(), "OldSocketImpl")
.outputTo(System.out)
.errorTo(System.out)
.shouldHaveExitValue(0);
}
}
/*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 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,12 +24,13 @@
/**
* @test
* @bug 5086147
* @run shell B5086147.sh
* @requires (os.family == "windows")
* @run main B5086147
* @summary File,URI,URL conversions are strange for UNC path
*/
import java.net.*;
import java.io.*;
import java.io.File;
import java.net.URI;
public class B5086147 {
public static final void main( String[] aaParamters ) throws Exception{
......
#! /bin/sh
#
# Copyright (c) 2005, 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.
#
OS=`uname -s`
case "$OS" in
SunOS | Linux | Darwin | AIX )
exit 0
;;
CYGWIN* )
PS=";"
FS="/"
;;
Windows* )
PS=";"
FS="\\"
;;
* )
echo "Unrecognized system!"
exit 1;
;;
esac
${COMPILEJAVA}${FS}bin${FS}javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d . ${TESTSRC}${FS}B5086147.java
failures=0
echo ''
${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} B5086147
if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
if [ "$failures" != "0" ]; then
echo $failures tests failed
exit 1;
fi
#! /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 5077773
# @summary Change in behaviour w.r.t jdk1.4.2 when loading resourcebundles
#
# ${TESTJAVA} is pointing to the jre
#
# set platform-dependent variables
OS=`uname -s`
case "$OS" in
SunOS | Darwin | AIX )
PS=":"
FS="/"
;;
Linux )
PS=":"
FS="/"
;;
CYGWIN* )
PS=";"
FS="/"
;;
Windows* )
PS=";"
FS="\\"
;;
* )
echo "Unrecognized system!"
exit 1;
;;
esac
cp ${TESTSRC}${FS}foo.jar .
${COMPILEJAVA}${FS}bin${FS}javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d . \
${TESTSRC}${FS}B5077773.java
WD=`pwd`
${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} B5077773
/*
* Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 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
......@@ -26,24 +26,32 @@
* @bug 4167874
* @modules java.logging
* jdk.httpserver
* jdk.compiler
* @library ../../../../com/sun/net/httpserver
* @library /lib/testlibrary
* @build FileServerHandler jdk.testlibrary.FileUtils
* @run shell build.sh
* /lib/testlibrary
* @build FileServerHandler jdk.testlibrary.FileUtils JarUtils CompilerUtils
* @run main/othervm CloseTest
* @summary URL-downloaded jar files can consume all available file descriptors
*/
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URLClassLoader;
import java.net.InetSocketAddress;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import com.sun.net.httpserver.HttpContext;
import com.sun.net.httpserver.HttpServer;
public class CloseTest extends Common {
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
public class CloseTest extends Common {
private static final String WORK_DIR = System.getProperty("user.dir")
+ "/";
//
// needs two jar files test1.jar and test2.jar with following structure
//
......@@ -55,36 +63,28 @@ public class CloseTest extends Common {
// and a directory hierarchy with the same structure/contents
public static void main(String args[]) throws Exception {
setup();
String workdir = System.getProperty("test.classes");
if (workdir == null) {
workdir = args[0];
}
if (!workdir.endsWith("/")) {
workdir = workdir+"/";
}
startHttpServer (workdir+"serverRoot/");
startHttpServer(WORK_DIR + "serverRoot/");
String testjar = workdir + "test.jar";
copyFile (workdir+"test1.jar", testjar);
String testjar = WORK_DIR + "test.jar";
copyFile(WORK_DIR + "test1.jar", testjar);
test(testjar, 1);
// repeat test with different implementation
// of test.jar (whose TestClass.getValue() returns 2
copyFile (workdir+"test2.jar", testjar);
copyFile(WORK_DIR + "test2.jar", testjar);
test(testjar, 2);
// repeat test using a directory of files
String testdir=workdir+"testdir/";
String testdir = WORK_DIR + "testdir/";
rm_minus_rf(new File(testdir));
copyDir (workdir+"test1/", testdir);
copyDir(WORK_DIR + "test1/", testdir);
test(testdir, 1);
testdir=workdir+"testdir/";
testdir = WORK_DIR + "testdir/";
rm_minus_rf(new File(testdir));
copyDir (workdir+"test2/", testdir);
copyDir(WORK_DIR + "test2/", testdir);
test(testdir, 2);
getHttpServer().stop(3);
}
......@@ -99,6 +99,7 @@ public class CloseTest extends Common {
// check boot classes can be loaded
static void test(String name, int expectedValue) throws Exception {
URL url = new URL("file", null, name);
URL url2 = getServerURL();
System.out.println("Doing tests with URL: " + url + " and " + url2);
......@@ -160,4 +161,41 @@ public class CloseTest extends Common {
);
httpServer.start();
}
/**
* Prepare jars files for the tests
*/
private static void setup () throws IOException {
String[] tests = new String[]{"test1", "test2"};
Path workDir = Paths.get(WORK_DIR);
Path testSrc = Paths.get(System.getProperty("test.src"));
for (String test : tests) {
Path testSrcDir = testSrc.resolve(test);
Path testTargetDir = workDir.resolve(test);
// Compile sources for corresponding test
CompilerUtils.compile(testSrcDir, testTargetDir);
// Copy all resources
Path packages = Paths.get("com", "foo");
Path copySrcDir = testSrcDir.resolve(packages);
Path copyTargetDir = testTargetDir.resolve(packages);
Files.createDirectories(copyTargetDir);
Path res1 = Paths.get("Resource1");
Path res2 = Paths.get("Resource2");
Files.copy(copySrcDir.resolve(res1), copyTargetDir.resolve(res1),
REPLACE_EXISTING);
Files.copy(copySrcDir.resolve(res2), copyTargetDir.resolve(res2),
REPLACE_EXISTING);
// Create jar
JarUtils.createJarFile(workDir.resolve(test + ".jar"), testTargetDir);
}
// Copy and compile server test class
Path serverRoot = Paths.get("serverRoot");
Path targetDir = workDir.resolve(serverRoot);
Path file = Paths.get("Test.java");
Files.createDirectories(targetDir);
Files.copy(testSrc.resolve(serverRoot).resolve(file),
targetDir.resolve(file), REPLACE_EXISTING);
CompilerUtils.compile(targetDir, targetDir);
}
}
/*
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 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
......@@ -25,15 +25,24 @@
* @test
* @bug 6899919
* @library /lib/testlibrary
* @build jdk.testlibrary.FileUtils
* @run shell build2.sh
* @modules jdk.compiler
* @build jdk.testlibrary.FileUtils JarUtils CompilerUtils
* @run main/othervm GetResourceAsStream
*/
import java.io.*;
import java.net.*;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption;
public class GetResourceAsStream extends Common {
private static final String WORK_DIR = System.getProperty("user.dir");
/*
* We simply test various scenarios with class/resource files
......@@ -42,17 +51,13 @@ public class GetResourceAsStream extends Common {
* on Windows. It will still run correctly on other platforms
*/
public static void main (String args[]) throws Exception {
String workdir = System.getProperty("test.classes");
if (workdir == null) {
workdir = args[0];
}
setup();
/* the jar we copy for each test */
File srcfile = new File (workdir, "foo.jar");
File srcfile = new File(WORK_DIR, "foo.jar");
/* the jar we use for the test */
File testfile = new File (workdir, "test.jar");
File testfile = new File(WORK_DIR, "test.jar");
copyFile(srcfile, testfile);
test(testfile, false, false);
......@@ -65,12 +70,11 @@ public class GetResourceAsStream extends Common {
// repeat test using a directory of files
File testdir= new File (workdir, "testdir");
File srcdir= new File (workdir, "test3");
File testdir = new File(WORK_DIR, "testdir");
File srcdir = new File(WORK_DIR, "test3");
copyDir(srcdir, testdir);
test(testdir, true, false);
}
// create a loader on jarfile (or directory)
......@@ -82,7 +86,7 @@ public class GetResourceAsStream extends Common {
static void test (File file, boolean loadclass, boolean readall)
throws Exception
{
URL[] urls = new URL[] {file.toURL()};
URL[] urls = new URL[] {file.toURI().toURL()};
System.out.println ("Doing tests with URL: " + urls[0]);
URLClassLoader loader = new URLClassLoader (urls);
if (loadclass) {
......@@ -97,7 +101,7 @@ public class GetResourceAsStream extends Common {
loader.close ();
// shouuld not find bye.txt now
// should not find bye.txt now
InputStream s1 = loader.getResourceAsStream("bye.txt");
if (s1 != null) {
throw new RuntimeException ("closed loader returned resource");
......@@ -107,4 +111,26 @@ public class GetResourceAsStream extends Common {
rm_minus_rf (file);
System.out.println (" ... OK");
}
/**
* Prepare jars files for the tests
*/
private static void setup () throws IOException {
Path classes = Paths.get(WORK_DIR);
Path testSrc = Paths.get(System.getProperty("test.src"),
"test1", "com", "foo", "TestClass.java");
Path targetDir = classes.resolve("test3");
Path testTarget = targetDir.resolve("TestClass.java");
Files.createDirectories(targetDir);
Files.copy(testSrc, testTarget, StandardCopyOption.REPLACE_EXISTING);
// Compile sources for corresponding test
CompilerUtils.compile(targetDir, targetDir);
// Prepare txt files
Files.write(targetDir.resolve("hello.txt"), "Hello world".getBytes(),
StandardOpenOption.CREATE);
Files.write(targetDir.resolve("bye.txt"), "Bye world".getBytes(),
StandardOpenOption.CREATE);
// Create jar
JarUtils.createJarFile(classes.resolve("foo.jar"), targetDir);
}
}
#!/bin/sh
#
# Copyright (c) 2009, 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.
#
#
#
# This script builds the test files for the test
# but not the actual test sources themselves.
#
if [ "${TESTSRC}" = "" ]
then
echo "TESTSRC not set. Test cannot execute. Failed."
exit 1
fi
echo "TESTSRC=${TESTSRC}"
if [ "${TESTJAVA}" = "" ]
then
echo "TESTJAVA not set. Test cannot execute. Failed."
exit 1
fi
echo "TESTJAVA=${TESTJAVA}"
if [ "${COMPILEJAVA}" = "" ]; then
COMPILEJAVA="${TESTJAVA}"
fi
echo "COMPILEJAVA=${COMPILEJAVA}"
if [ "${TESTCLASSES}" = "" ]
then
echo "TESTCLASSES not set. Test cannot execute. Failed."
exit 1
fi
JAVAC="${COMPILEJAVA}/bin/javac"
JAR="${COMPILEJAVA}/bin/jar"
rm -rf ${TESTCLASSES}/test1
rm -rf ${TESTCLASSES}/test2
rm -rf ${TESTCLASSES}/serverRoot
mkdir -p ${TESTCLASSES}/test1/com/foo
mkdir -p ${TESTCLASSES}/test2/com/foo
mkdir -p ${TESTCLASSES}/serverRoot
cd ${TESTSRC}/test1/com/foo
cp * ${TESTCLASSES}/test1/com/foo
cd ${TESTCLASSES}/test1
${JAVAC} ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} com/foo/*.java
${JAR} ${TESTTOOLVMOPTS} cvf ../test1.jar com/foo/*.class com/foo/Resource*
cd ${TESTSRC}/test2/com/foo
cp * ${TESTCLASSES}/test2/com/foo
cd ${TESTCLASSES}/test2
${JAVAC} ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} com/foo/*.java
${JAR} ${TESTTOOLVMOPTS} cvf ../test2.jar com/foo/*.class com/foo/Resource*
cp ${TESTSRC}/serverRoot/Test.java ${TESTCLASSES}/serverRoot
cd ${TESTCLASSES}/serverRoot
${JAVAC} ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} Test.java
#!/bin/sh
#
# Copyright (c) 2011, 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 [ "${TESTSRC}" = "" ]
then
echo "TESTSRC not set. Test cannot execute. Failed."
exit 1
fi
echo "TESTSRC=${TESTSRC}"
if [ "${TESTJAVA}" = "" ]
then
echo "TESTJAVA not set. Test cannot execute. Failed."
exit 1
fi
echo "TESTJAVA=${TESTJAVA}"
if [ "${TESTCLASSES}" = "" ]
then
echo "TESTCLASSES not set. Test cannot execute. Failed."
exit 1
fi
JAVAC="${TESTJAVA}/bin/javac"
JAR="${TESTJAVA}/bin/jar"
rm -rf ${TESTCLASSES}/test3
mkdir -p ${TESTCLASSES}/test3
echo "Hello world" > ${TESTCLASSES}/test3/hello.txt
echo "Bye world" > ${TESTCLASSES}/test3/bye.txt
cp ${TESTSRC}/test1/com/foo/TestClass.java ${TESTCLASSES}/test3
cd ${TESTCLASSES}/test3
${JAVAC} -d . TestClass.java
${JAR} cvf foo.jar hello.txt bye.txt com/foo/TestClass.class
rm -f ../foo.jar
mv foo.jar ..
/*
* 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 5103449
* @summary REGRESSION: getResourceAsStream is broken in JDK1.5.0-rc
* @library /test/lib
* @build jdk.test.lib.JDKToolFinder
* jdk.test.lib.process.ProcessTools
* Test
* @run main/othervm TestDriver
*/
import jdk.test.lib.JDKToolFinder;
import jdk.test.lib.process.ProcessTools;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
public class TestDriver {
private static final String ARCHIVE_NAME = "test.jar";
private static final String TEST_NAME = "Test";
private static final String POLICY_FILE = "policy";
public static void main(String[] args)
throws Throwable {
Path userDir = Paths.get(System.getProperty("user.dir"));
String java = JDKToolFinder.getTestJDKTool("java");
String basename = userDir.getFileName().toString();
setup(userDir);
ProcessBuilder[] tests = new ProcessBuilder[]{
new ProcessBuilder(
java, TEST_NAME, "./" + ARCHIVE_NAME
),
new ProcessBuilder(
java, "-cp", ".",
"-Djava.security.policy=file:./policy",
"-Djava.security.manager",
TEST_NAME, "./" + ARCHIVE_NAME
),
new ProcessBuilder(
java, "-cp", ".",
"-Djava.security.policy=file:./policy",
"-Djava.security.manager",
TEST_NAME, "./" + ARCHIVE_NAME
),
new ProcessBuilder(
java, "-cp", "..",
"-Djava.security.policy=file:../policy",
"-Djava.security.manager",
TEST_NAME, "../" + ARCHIVE_NAME
).directory(userDir.resolve("tmp").toFile()),
new ProcessBuilder(
java, "-cp", basename,
"-Djava.security.policy=file:" + basename + "/policy",
"-Djava.security.manager",
TEST_NAME, basename + "/" + ARCHIVE_NAME
).directory(userDir.resolve("..").toFile())};
for (ProcessBuilder test : tests) {
runTest(test);
}
}
private static void setup(Path userDir) throws IOException {
Path src = Paths.get(System.getProperty("test.src"));
Path testJar = src.resolve(ARCHIVE_NAME);
Path policy = src.resolve(POLICY_FILE);
Path testClass = Paths.get(System.getProperty("test.classes"),
TEST_NAME + ".class");
Files.copy(testJar, userDir.resolve(ARCHIVE_NAME), REPLACE_EXISTING);
Files.copy(policy, userDir.resolve(POLICY_FILE), REPLACE_EXISTING);
Files.copy(testClass, userDir.resolve(TEST_NAME + ".class"),
REPLACE_EXISTING);
Files.createDirectories(userDir.resolve("tmp"));
}
private static void runTest(ProcessBuilder pb) throws Exception {
System.out.println("Testing with command: [" + pb.command() + "]");
ProcessTools.executeProcess(pb)
.outputTo(System.out)
.errorTo(System.err)
.shouldHaveExitValue(0);
}
}
/*
* 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.
*/
grant {
permission java.lang.RuntimePermission "createClassLoader";
};
#!/bin/sh
#
# Copyright (c) 2004, 2013, 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.
#
set -x
# @test
# @bug 5103449
# @run shell test.sh
# @summary REGRESSION: getResourceAsStream is broken in JDK1.5.0-rc
#
cat << POLICY > policy
grant {
permission java.lang.RuntimePermission "createClassLoader";
};
POLICY
checkExit () {
if [ $? != 0 ]; then
exit $1;
fi
}
${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d . ${TESTSRC}/Test.java
cp ${TESTSRC}/test.jar .
${TESTJAVA}/bin/java ${TESTVMOPTS} Test ./test.jar
checkExit 1
# try with security manager
${TESTJAVA}/bin/java ${TESTVMOPTS} -Djava.security.policy=file:./policy \
-Djava.security.manager Test ./test.jar
checkExit 2
mkdir tmp
cd tmp
${TESTJAVA}/bin/java ${TESTVMOPTS} -Djava.security.policy=file:../policy \
-cp .. -Djava.security.manager Test ../test.jar
checkExit 3
cd ..
THISDIR=$(basename $(pwd))
cd ..
${TESTJAVA}/bin/java ${TESTVMOPTS} -Djava.security.policy=file:$THISDIR/policy \
-cp $THISDIR -Djava.security.manager Test $THISDIR/test.jar
checkExit 4
exit 0
/*
* 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,13 +21,6 @@
* questions.
*/
/*
* @test
* @bug 4244970
* @summary Test to see if sealing violation is detected correctly
* @run shell checksealed.sh
*
*/
public class CheckSealed {
public static void main(String[] argv) throws Exception {
......
/*
* 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 4244970
* @summary Test to see if sealing violation is detected correctly
* @library /test/lib
* @build jdk.test.lib.JDKToolFinder
* jdk.test.lib.process.OutputAnalyzer
* @run main CheckSealedTest
*/
import jdk.test.lib.JDKToolFinder;
import jdk.test.lib.process.ProcessTools;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
public class CheckSealedTest {
private static final String ARCHIVE_NAME = "b.jar";
private static final String TEST_NAME = "CheckSealed";
public static void main(String[] args)
throws Throwable {
String baseDir = System.getProperty("user.dir") + File.separator;
String javac = JDKToolFinder.getTestJDKTool("javac");
String java = JDKToolFinder.getTestJDKTool("java");
setup(baseDir);
String srcDir = System.getProperty("test.src");
String cp = srcDir + File.separator + "a" + File.pathSeparator
+ srcDir + File.separator + "b.jar" + File.pathSeparator
+ ".";
List<String[]> allCMDs = List.of(
// Compile command
new String[]{
javac, "-cp", cp, "-d", ".",
srcDir + File.separator + TEST_NAME + ".java"
},
// Run test the first time
new String[]{
java, "-cp", cp, TEST_NAME, "1"
},
// Run test the second time
new String[]{
java, "-cp", cp, TEST_NAME, "2"
}
);
for (String[] cmd : allCMDs) {
ProcessTools.executeCommand(cmd)
.outputTo(System.out)
.errorTo(System.out)
.shouldHaveExitValue(0);
}
}
private static void setup(String baseDir) throws IOException {
Path testJar = Paths.get(System.getProperty("test.src"), ARCHIVE_NAME);
Files.copy(testJar, Paths.get(baseDir, ARCHIVE_NAME), REPLACE_EXISTING);
}
}
#! /bin/sh
#
# Copyright (c) 1999, 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.
#
#
OS=`uname -s`
case "$OS" in
SunOS | Darwin | AIX )
PS=":"
FS="/"
;;
Linux )
PS=":"
FS="/"
;;
CYGWIN* )
PS=";"
FS="/"
;;
Windows* )
PS=";"
FS="\\"
;;
* )
echo "Unrecognized system!"
exit 1;
;;
esac
if [ x"$TESTJAVA" = x ]; then TESTJAVA=$1; fi
if [ x"$COMPILEJAVA" = x ]; then COMPILEJAVA=$1; fi
if [ x"$TESTSRC" = x ]; then TESTSRC=.; fi
CLASSPATH=".${PS}${TESTSRC}${FS}a${PS}${TESTSRC}${FS}b.jar"
${COMPILEJAVA}${FS}bin${FS}javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -classpath "${CLASSPATH}" -d . \
${TESTSRC}${FS}CheckSealed.java
${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} -cp "${CLASSPATH}" CheckSealed 1
if [ $? != 0 ]; then exit 1; fi
${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} -cp "${CLASSPATH}" CheckSealed 2
if [ $? != 0 ]; then exit 1; fi
......@@ -21,27 +21,32 @@
* questions.
*/
import java.net.*;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Paths;
public class Test {
public static void main(String[] args)
throws Exception {
String BASE_DIR = args[0];
String ARCHIVE_NAME = args[1];
String baseDir = args[0];
String archiveName = args[1];
String lProperty = System.getProperty("do.iterations", "5000");
int lRepetitions = new Integer( lProperty ).intValue();
System.out.println ( "Start creating copys of the archive, " + lRepetitions + " times" );
int lRepetitions = Integer.valueOf(lProperty);
System.out.println("Start creating copys of the archive, "
+ lRepetitions + " times");
for (int i = 0; i < lRepetitions; i++) {
// Copy the given jar file and add a prefix
copyFile( BASE_DIR, ARCHIVE_NAME, i);
copyFile(baseDir, archiveName, i);
}
System.out.println ( "Start opening the archives archive, " + lRepetitions + " times" );
System.out.println ( "First URL is jar:file://" + BASE_DIR + "1" + ARCHIVE_NAME + "!/foo/Test.class");
System.out.println("Start opening the archives archive, "
+ lRepetitions + " times");
System.out.println("First URL is jar:" + Paths.get(baseDir,
0 + archiveName).toUri() + "!/foo/Test.class");
for (int i = 0; i < lRepetitions; i++) {
// Create ULR
String lURLPath = "jar:file://" + BASE_DIR + i + ARCHIVE_NAME + "!/foo/Test.class";
// Create URL
String lURLPath = "jar:" + Paths.get(baseDir, i
+ archiveName).toUri() + "!/foo/Test.class";
URL lURL = new URL(lURLPath);
// Open URL Connection
try {
......@@ -53,17 +58,6 @@ public class Test {
throw new RuntimeException("Test failed: " + ze.getMessage());
}
}
//System.out.println ( "Done testing, waiting 20 seconds for checking" );
//System.out.println ( "Cleaning up");
//for( int i = 0; i < lRepetitions; i++ ) {
// Copy the given jar file and add a prefix
//deleteFile( BASE_DIR, i, ARCHIVE_NAME);
////}
}
private static void deleteFile (String BASE_DIR, int pIndex, String pArchiveName) {
java.io.File file = new java.io.File (BASE_DIR, pIndex + pArchiveName );
file.delete ();
}
private static void copyFile( String pBaseDir, String pArchiveName, int pIndex) {
......
/*
* 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 6212146
* @summary URLConnection.connect() fails on JAR Entry it creates
* file handler leak
* @library /test/lib
* @build jdk.test.lib.JDKToolFinder
* jdk.test.lib.process.ProcessTools
* Test
* @run main/othervm TestDriver
*/
import jdk.test.lib.JDKToolFinder;
import jdk.test.lib.process.ProcessTools;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
public class TestDriver {
private static final String BASE_DIR = System.getProperty("user.dir")
+ "/jars/";
private static final String ARCHIVE_NAME = "test.jar";
private static final String CMD_ULIMIT = "ulimit -n 300;";
public static void main(String[] args)
throws Throwable {
setup(BASE_DIR);
String testCMD = CMD_ULIMIT + JDKToolFinder.getTestJDKTool("java")
+ " Test " + BASE_DIR + " " + ARCHIVE_NAME;
boolean isWindows = System.getProperty("os.name").startsWith("Windows");
if (isWindows) {
testCMD = testCMD.replace("\\", "/");
}
ProcessTools.executeCommand("sh", "-c", testCMD)
.outputTo(System.out)
.errorTo(System.err)
.shouldHaveExitValue(0);
}
private static void setup(String baseDir) throws IOException {
Path testJar = Paths.get(System.getProperty("test.src"), ARCHIVE_NAME);
Path targetDir = Paths.get(baseDir);
Files.createDirectories(targetDir);
Files.copy(testJar, targetDir.resolve(ARCHIVE_NAME), REPLACE_EXISTING);
}
}
#!/bin/sh
#
# Copyright (c) 2006, 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
# @run shell/timeout=380 test.sh
# @bug 6212146
# @summary URLConnection.connect() fails on JAR Entry it creates file handler leak
#
# set platform-dependent variables
OS=`uname -s`
case "$OS" in
SunOS | Darwin | AIX )
PS=":"
FS="/"
;;
Linux )
PS=":"
FS="/"
;;
CYGWIN* )
PS=";"
FS="/"
;;
Windows* )
PS=";"
FS="\\"
;;
* )
echo "Unrecognized system!"
exit 1;
;;
esac
if [ -d jars ]; then
rm -rf jars
fi
mkdir jars
cp ${TESTSRC}${FS}test.jar jars
${COMPILEJAVA}${FS}bin${FS}javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d . ${TESTSRC}${FS}Test.java
WD=`pwd`
ulimit -H -n 300
${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} Test ${WD}/jars/ test.jar
result=$?
rm -rf jars
exit $?
/*
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 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,7 +21,16 @@
* questions.
*/
import java.net.*;
/**
* @test
* @bug 4401485
* @requires (os.family == "windows")
* @summary Check that URL.openConnection() doesn't open connection to UNC
* @run main UNCTest file://jdk/LOCAL-JAVA/jdk1.4/win/README.txt
*/
import java.net.URL;
import java.net.URLConnection;
public class UNCTest {
public static void main(String args[]) throws Exception {
......
#!/bin/sh
#
# Copyright (c) 2001, 2002, 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 4401485
# @run shell UNCTest.sh
# @summary Check that URL.openConnection() doesn't open connection
# to UNC.
UNC="file://jdk/LOCAL-JAVA/jdk1.4/win/README.txt"
OS=`uname -s`
case "$OS" in
Windows_95 | Windows_98 | Windows_NT )
${COMPILEJAVA}/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d . ${TESTSRC}\\UNCTest.java
${TESTJAVA}/bin/java ${TESTVMOPTS} UNCTest ${UNC}
exit
;;
* )
echo "This test is not intended for this OS - passing test"
exit 0
;;
esac
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment