8293877: Rewrite MineField test
Reviewed-by: vromero, martin, darcy, jlahoda
This commit is contained in:
parent
4f44fd6308
commit
e137f9f2f0
@ -1,198 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright (c) 2003, 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.
|
||||
#
|
||||
|
||||
|
||||
# @test
|
||||
# @bug 4212732
|
||||
# @summary Test handling of the Class-Path attribute in jar file manifests
|
||||
# @author Martin Buchholz
|
||||
#
|
||||
# @run shell Class-Path.sh
|
||||
|
||||
# To run this test manually, simply do ./Class-Path.sh
|
||||
|
||||
. ${TESTSRC-.}/Util.sh
|
||||
|
||||
set -u
|
||||
|
||||
Cleanup() {
|
||||
Sys rm -rf pkg Main.java Main.class Main.jar jars
|
||||
Sys rm -rf MANIFEST.MF A.jar B.zip
|
||||
}
|
||||
|
||||
Cleanup
|
||||
Sys mkdir pkg
|
||||
|
||||
#----------------------------------------------------------------
|
||||
# Create mutually referential jar files
|
||||
#----------------------------------------------------------------
|
||||
cat >pkg/A.java <<EOF
|
||||
package pkg;
|
||||
import pkg.B;
|
||||
public class A {
|
||||
public static int f() { return B.g(); }
|
||||
public static int g() { return 0; }
|
||||
}
|
||||
EOF
|
||||
|
||||
cat >pkg/B.java <<EOF
|
||||
package pkg;
|
||||
import pkg.A;
|
||||
public class B {
|
||||
public static int f() { return A.g(); }
|
||||
public static int g() { return 0; }
|
||||
}
|
||||
EOF
|
||||
|
||||
Sys "$javac" ${TESTTOOLVMOPTS} pkg/A.java pkg/B.java
|
||||
|
||||
MkManifestWithClassPath "B.zip"
|
||||
Sys "$jar" cmf MANIFEST.MF A.jar pkg/A.class
|
||||
|
||||
MkManifestWithClassPath "A.jar"
|
||||
Sys "$jar" cmf MANIFEST.MF B.zip pkg/B.class
|
||||
|
||||
cat >Main.java <<EOF
|
||||
import pkg.*;
|
||||
public class Main {
|
||||
public static void main(String []a) { System.exit(A.f() + B.f()); }
|
||||
}
|
||||
EOF
|
||||
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -cp "A.jar" Main.java
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -cp "B.zip" Main.java
|
||||
Success "$java" ${TESTVMOPTS} -cp "A.jar${PS}." Main
|
||||
Success "$java" ${TESTVMOPTS} -cp "B.zip${PS}." Main
|
||||
|
||||
#----------------------------------------------------------------
|
||||
# Jar file Class-Path expanded only for jars found on user class path
|
||||
#----------------------------------------------------------------
|
||||
Sys mkdir jars
|
||||
Sys mv A.jar B.zip jars/.
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -cp "jars/A.jar" Main.java
|
||||
Success "$java" ${TESTVMOPTS} -cp "jars/A.jar${PS}." Main
|
||||
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -cp "jars/B.zip" Main.java
|
||||
Success "$java" ${TESTVMOPTS} -cp "jars/B.zip${PS}." Main
|
||||
|
||||
# Success "$javac" ${TESTTOOLVMOPTS} -extdirs "jars" -cp None Main.java
|
||||
# Success "$javac" ${TESTTOOLVMOPTS} -Djava.ext.dirs="jars" -cp None Main.java
|
||||
# Success "$java" ${TESTVMOPTS} -Djava.ext.dirs="jars" -cp . Main
|
||||
|
||||
# Success "$javac" ${TESTTOOLVMOPTS} -endorseddirs "jars" -cp None Main.java
|
||||
# Success "$javac" ${TESTTOOLVMOPTS} -Djava.endorsed.dirs="jars" -cp None Main.java
|
||||
# Success "$java" ${TESTVMOPTS} -Djava.endorsed.dirs="jars" -cp . Main
|
||||
|
||||
Failure "$java" ${TESTVMOPTS} -Xbootclasspath/p:"jars/A.jar" -cp . Main
|
||||
Failure "$java" ${TESTVMOPTS} -Xbootclasspath/a:"jars/B.zip" -cp . Main
|
||||
Failure "$javac" ${TESTTOOLVMOPTS} -Xbootclasspath/p:"jars/A.jar" -cp None Main.java
|
||||
Failure "$javac" ${TESTTOOLVMOPTS} -Xbootclasspath/a:"jars/B.zip" -cp None Main.java
|
||||
Sys mv jars/A.jar jars/B.zip .
|
||||
|
||||
MkManifestWithClassPath "A.jar"
|
||||
echo "Main-Class: Main" >> MANIFEST.MF
|
||||
Sys "$jar" cmf MANIFEST.MF Main.jar Main.class
|
||||
|
||||
Success "$java" ${TESTVMOPTS} -jar Main.jar
|
||||
|
||||
MkManifestWithClassPath "."
|
||||
Sys "$jar" cmf MANIFEST.MF A.jar pkg/A.class
|
||||
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -cp "A.jar" Main.java
|
||||
Success "$java" ${TESTVMOPTS} -jar Main.jar
|
||||
|
||||
MkManifestWithClassPath ""
|
||||
Sys "$jar" cmf MANIFEST.MF A.jar pkg/A.class
|
||||
|
||||
Failure "$javac" ${TESTTOOLVMOPTS} -cp "A.jar" Main.java
|
||||
Failure "$java" ${TESTVMOPTS} -jar Main.jar
|
||||
|
||||
#----------------------------------------------------------------
|
||||
# Test new flag -e (application entry point)
|
||||
#----------------------------------------------------------------
|
||||
|
||||
cat > Hello.java <<EOF
|
||||
import pkg.*;
|
||||
public class Hello {
|
||||
public static void main(String []a) { System.out.println("Hello World!"); }
|
||||
}
|
||||
EOF
|
||||
|
||||
cat > Bye.java <<EOF
|
||||
import pkg.*;
|
||||
public class Bye {
|
||||
public static void main(String []a) { System.out.println("Good Bye!"); }
|
||||
}
|
||||
EOF
|
||||
|
||||
Success "$javac" ${TESTTOOLVMOPTS} Hello.java Bye.java
|
||||
|
||||
# test jar creation without manifest
|
||||
#
|
||||
Success "$jar" cfe "Hello.jar" "Hello" Hello.class
|
||||
Success "$java" ${TESTVMOPTS} -jar Hello.jar
|
||||
|
||||
# test for overriding the manifest during jar creation
|
||||
#
|
||||
echo "Main-Class: Hello" >> MANIFEST.MF
|
||||
|
||||
# test for error: " 'e' flag and manifest with the 'Main-Class'
|
||||
# attribute cannot be specified together, during creation
|
||||
Failure "$jar" cmfe MANIFEST.MF "Bye.jar" "Bye" Bye.class
|
||||
|
||||
# test for overriding the manifest when updating the jar
|
||||
#
|
||||
Success "$jar" cfe "greetings.jar" "Hello" Hello.class
|
||||
Success "$jar" ufe "greetings.jar" "Bye" Bye.class
|
||||
Success "$java" ${TESTVMOPTS} -jar greetings.jar
|
||||
|
||||
# test for error: " 'e' flag and manifest with the 'Main-Class'
|
||||
# attribute cannot be specified together, during update
|
||||
Failure "$jar" umfe MANIFEST.MF "greetings.jar" "Hello"
|
||||
|
||||
# test jar updation when there are no inputfiles
|
||||
#
|
||||
Success "$jar" ufe "Hello.jar" "Bye"
|
||||
Failure "$java" ${TESTVMOPTS} -jar Hello.jar
|
||||
Success "$jar" umf MANIFEST.MF "Hello.jar"
|
||||
|
||||
# test creating jar when the to-be-archived files
|
||||
# do not contain the specified main class, there is no check done
|
||||
# for the presence of the main class, so the test will pass
|
||||
#
|
||||
Success "$jar" cfe "Hello.jar" "Hello" Bye.class
|
||||
|
||||
# Jar creation and update when there is no manifest and inputfiles
|
||||
# specified
|
||||
Failure "$jar" cvf "A.jar"
|
||||
Failure "$jar" uvf "A.jar"
|
||||
|
||||
# error: no such file or directory
|
||||
Failure "$jar" cvf "A.jar" non-existing.file
|
||||
Failure "$jar" uvf "A.jar" non-existing.file
|
||||
|
||||
Cleanup
|
||||
|
||||
Bottom Line
|
@ -1,111 +0,0 @@
|
||||
#!/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.
|
||||
#
|
||||
|
||||
# @test
|
||||
# @bug 4212732 6485027
|
||||
# @summary Test handling of the Class-Path attribute in jar file manifests
|
||||
# @author Martin Buchholz
|
||||
#
|
||||
# @run shell Class-Path2.sh
|
||||
|
||||
# To run this test manually, simply do ./Class-Path2.sh
|
||||
|
||||
. ${TESTSRC-.}/Util.sh
|
||||
|
||||
set -u
|
||||
|
||||
Cleanup() {
|
||||
Sys rm -rf pkg Main.java Main.class Main.jar jars
|
||||
Sys rm -rf MANIFEST.MF A.jar B.zip
|
||||
}
|
||||
|
||||
Cleanup
|
||||
Sys mkdir pkg
|
||||
|
||||
#----------------------------------------------------------------
|
||||
# Create mutually referential jar files
|
||||
#----------------------------------------------------------------
|
||||
cat >pkg/A.java <<EOF
|
||||
package pkg;
|
||||
import pkg.B;
|
||||
public class A {
|
||||
public static int f() { return B.g(); }
|
||||
public static int g() { return 0; }
|
||||
}
|
||||
EOF
|
||||
|
||||
cat >pkg/B.java <<EOF
|
||||
package pkg;
|
||||
import pkg.A;
|
||||
public class B {
|
||||
public static int f() { return A.g(); }
|
||||
public static int g() { return 0; }
|
||||
}
|
||||
EOF
|
||||
|
||||
Sys "$javac" pkg/A.java pkg/B.java
|
||||
|
||||
MkManifestWithClassPath "./sub/B.zip"
|
||||
Sys "$jar" cmf MANIFEST.MF A.jar pkg/A.class
|
||||
|
||||
MkManifestWithClassPath "../A.jar"
|
||||
Sys "$jar" cmf MANIFEST.MF B.zip pkg/B.class
|
||||
|
||||
cat >Main.java <<EOF
|
||||
import pkg.*;
|
||||
public class Main {
|
||||
public static void main(String []a) { System.exit(A.f() + B.f()); }
|
||||
}
|
||||
EOF
|
||||
|
||||
Sys rm -rf pkg
|
||||
|
||||
Sys mkdir jars
|
||||
Sys mkdir jars/sub/
|
||||
Sys mv A.jar jars/.
|
||||
Sys mv B.zip jars/sub/.
|
||||
|
||||
#
|
||||
# Test 1: Compiling
|
||||
#
|
||||
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -cp "jars/A.jar" Main.java
|
||||
Success "$java" ${TESTVMOPTS} -cp "jars/A.jar${PS}." Main
|
||||
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -cp "jars/sub/B.zip" Main.java
|
||||
Success "$java" ${TESTVMOPTS} -cp "jars/sub/B.zip${PS}." Main
|
||||
|
||||
#
|
||||
# Test 2: Use of extension directories is incorrect
|
||||
#
|
||||
|
||||
# Success "$javac" ${TESTTOOLVMOPTS} -extdirs jars -cp None Main.java
|
||||
# Success "$java" ${TESTVMOPTS} -Djava.ext.dirs="jars" -cp . Main
|
||||
|
||||
# Success "$javac" ${TESTTOOLVMOPTS} -extdirs jars/sub -cp None Main.java
|
||||
# Success "$java" ${TESTVMOPTS} -Djava.ext.dirs="jars/sub" -cp . Main
|
||||
|
||||
Cleanup
|
||||
|
||||
Bottom Line
|
218
test/langtools/tools/javac/Paths/ClassPath.java
Normal file
218
test/langtools/tools/javac/Paths/ClassPath.java
Normal file
@ -0,0 +1,218 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2022, 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 4212732 8293877
|
||||
* @summary Test handling of the Class-Path attribute in jar file manifests
|
||||
* @library /tools/lib
|
||||
* @build toolbox.ToolBox Util ClassPath
|
||||
* @run main ClassPath
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Converted from Class-Path.sh, originally written by Martin Buchholz.
|
||||
*
|
||||
* For the last version of the original, Class-Path.sh, see
|
||||
* https://github.com/openjdk/jdk/blob/jdk-19%2B36/test/langtools/tools/javac/Paths/Class-Path.sh
|
||||
*
|
||||
* This class primarily tests that the Class-Path attribute in jar files
|
||||
* is handled the same way by javac and java. It also has various tests
|
||||
* of the jar tool itself.
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.List;
|
||||
|
||||
public class ClassPath extends Util {
|
||||
public static void main(String... args) throws Exception {
|
||||
new ClassPath().run(args);
|
||||
}
|
||||
|
||||
void run(String... args) throws Exception {
|
||||
setup();
|
||||
tests();
|
||||
cleanup();
|
||||
bottomLine();
|
||||
}
|
||||
|
||||
void setup() throws Exception {
|
||||
cleanup();
|
||||
tb.createDirectories("pkg");
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
* Create mutually referential jar files
|
||||
*----------------------------------------------------------------*/
|
||||
|
||||
Files.writeString(Path.of("pkg/A.java"), """
|
||||
package pkg;
|
||||
import pkg.B;
|
||||
public class A {
|
||||
public static int f() { return B.g(); }
|
||||
public static int g() { return 0; }
|
||||
}
|
||||
""");
|
||||
Files.writeString(Path.of("pkg/B.java"), """
|
||||
package pkg;
|
||||
import pkg.A;
|
||||
public class B {
|
||||
public static int f() { return A.g(); }
|
||||
public static int g() { return 0; }
|
||||
}
|
||||
""");
|
||||
|
||||
javac("pkg/A.java", "pkg/B.java");
|
||||
|
||||
makeManifestWithClassPath("B.zip");
|
||||
jar("cmf", "MANIFEST.MF", "A.jar", "pkg/A.class");
|
||||
|
||||
makeManifestWithClassPath("A.jar");
|
||||
jar("cmf", "MANIFEST.MF", "B.zip", "pkg/B.class");
|
||||
|
||||
Files.writeString(Path.of("Main.java"), """
|
||||
import pkg.*;
|
||||
public class Main {
|
||||
public static void main(String[] a) { System.exit(A.f() + B.f()); }
|
||||
}
|
||||
""");
|
||||
}
|
||||
|
||||
void cleanup() throws IOException {
|
||||
deleteFiles("pkg", "Main.java", "Main.class", "Main.jar", "jars");
|
||||
deleteFiles("MANIFEST.MF", "A.jar", "B.zip");
|
||||
}
|
||||
|
||||
void tests() throws Exception {
|
||||
expectPass(JAVAC, "-cp A.jar Main.java");
|
||||
expectPass(JAVAC, "-cp B.zip Main.java");
|
||||
expectPass(JAVA, "-cp A.jar${PS}. Main");
|
||||
expectPass(JAVA, "-cp B.zip${PS}. Main");
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
* Jar file Class-Path expanded only for jars found on user class path
|
||||
*----------------------------------------------------------------*/
|
||||
|
||||
tb.createDirectories("jars");
|
||||
moveFiles(List.of("A.jar", "B.zip"), "jars/.");
|
||||
|
||||
expectPass(JAVAC, "-cp jars/A.jar Main.java");
|
||||
expectPass(JAVA, "-cp jars/A.jar${PS}. Main");
|
||||
|
||||
expectPass(JAVAC, "-cp jars/B.zip Main.java");
|
||||
expectPass(JAVA, "-cp jars/B.zip${PS}. Main");
|
||||
|
||||
expectFail(JAVA, "-Xbootclasspath/p:jars/A.jar -cp . Main");
|
||||
expectFail(JAVA, "-Xbootclasspath/a:jars/B.zip -cp . Main");
|
||||
expectFail(JAVAC, "-Xbootclasspath/p:jars/A.jar -cp None Main.java");
|
||||
expectFail(JAVAC, "-Xbootclasspath/a:jars/B.zip -cp None Main.java");
|
||||
moveFiles(List.of("jars/A.jar", "jars/B.zip"), ".");
|
||||
|
||||
makeManifestWithClassPath("A.jar");
|
||||
Files.writeString(Path.of("MANIFEST.MF"), "Main-Class: Main\n", StandardOpenOption.APPEND);
|
||||
jar("cmf", "MANIFEST.MF", "Main.jar", "Main.class");
|
||||
|
||||
expectPass(JAVA, "-jar Main.jar");
|
||||
|
||||
makeManifestWithClassPath(".");
|
||||
jar("cmf", "MANIFEST.MF", "A.jar", "pkg/A.class");
|
||||
|
||||
expectPass(JAVAC, "-cp A.jar Main.java");
|
||||
expectPass(JAVA, "-jar Main.jar");
|
||||
|
||||
makeManifestWithClassPath("");
|
||||
jar("cmf", "MANIFEST.MF", "A.jar", "pkg/A.class");
|
||||
|
||||
expectFail(JAVAC, "-cp A.jar Main.java");
|
||||
expectFail(JAVA, "-jar Main.jar");
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
* Test new flag -e (application entry point)
|
||||
*----------------------------------------------------------------*/
|
||||
|
||||
Files.writeString(Path.of("Hello.java"), """
|
||||
import pkg.*;
|
||||
public class Hello {
|
||||
public static void main(String[] a) { System.out.println("Hello World!"); }
|
||||
}
|
||||
""");
|
||||
|
||||
Files.writeString(Path.of("Bye.java"), """
|
||||
import pkg.*;
|
||||
public class Bye {
|
||||
public static void main(String[] a) { System.out.println("Good Bye!"); }
|
||||
}
|
||||
""");
|
||||
|
||||
// Set an empty classpath to override any inherited setting of CLASSPATH
|
||||
expectPass(classpath(""), JAVAC, "Hello.java Bye.java");
|
||||
|
||||
// test jar creation without manifest
|
||||
//
|
||||
expectPass(JAR, "cfe Hello.jar Hello Hello.class");
|
||||
expectPass(JAVA, "-jar Hello.jar");
|
||||
|
||||
// test for overriding the manifest during jar creation
|
||||
//
|
||||
Files.writeString(Path.of("MANIFEST.MF"), "Main-Class: Hello\n", StandardOpenOption.APPEND);
|
||||
|
||||
// test for error: " 'e' flag and manifest with the 'Main-Class'
|
||||
// attribute cannot be specified together, during creation
|
||||
expectFail(JAR, "cmfe MANIFEST.MF Bye.jar Bye Bye.class");
|
||||
|
||||
// test for overriding the manifest when updating the jar
|
||||
//
|
||||
expectPass(JAR, "cfe greetings.jar Hello Hello.class");
|
||||
expectPass(JAR, "ufe greetings.jar Bye Bye.class");
|
||||
expectPass(JAVA, "-jar greetings.jar");
|
||||
|
||||
// test for error: " 'e' flag and manifest with the 'Main-Class'
|
||||
// attribute cannot be specified together, during update
|
||||
expectFail(JAR, "umfe MANIFEST.MF greetings.jar Hello");
|
||||
|
||||
// test jar update when there are no input files
|
||||
expectPass(JAR, "ufe Hello.jar Bye");
|
||||
expectFail(JAVA, "-jar Hello.jar");
|
||||
expectPass(JAR, "umf MANIFEST.MF Hello.jar");
|
||||
|
||||
// test creating jar when the to-be-archived files
|
||||
// do not contain the specified main class, there is no check done
|
||||
// for the presence of the main class, so the test will pass
|
||||
//
|
||||
expectPass(JAR, "cfe Hello.jar Hello Bye.class");
|
||||
|
||||
// Jar creation and update when there is no manifest and inputfiles
|
||||
// specified
|
||||
expectFail(JAR, "cvf A.jar");
|
||||
expectFail(JAR, "uvf A.jar");
|
||||
|
||||
// error: no such file or directory
|
||||
expectFail(JAR, "cvf A.jar non-existing.file");
|
||||
expectFail(JAR, "uvf A.jar non-existing.file");
|
||||
|
||||
}
|
||||
}
|
126
test/langtools/tools/javac/Paths/ClassPath2.java
Normal file
126
test/langtools/tools/javac/Paths/ClassPath2.java
Normal file
@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2022, 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 4212732 6485027 8293877
|
||||
* @summary Test handling of the Class-Path attribute in jar file manifests
|
||||
* @library /tools/lib
|
||||
* @build toolbox.ToolBox Util ClassPath
|
||||
* @run main ClassPath2
|
||||
*/
|
||||
|
||||
/*
|
||||
* Converted from Class-Path2.sh, originally written by Martin Buchholz.
|
||||
*
|
||||
* For the last version of the original, Class-Path2.sh, see
|
||||
* https://github.com/openjdk/jdk/blob/jdk-19%2B36/test/langtools/tools/javac/Paths/Class-Path2.sh
|
||||
*
|
||||
* This class provides additional tests for the Class-Path attribute in jar
|
||||
* files, when the entries are not in the same directory.
|
||||
*/
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class ClassPath2 extends Util {
|
||||
public static void main(String... args) throws Exception {
|
||||
new ClassPath2().run(args);
|
||||
}
|
||||
|
||||
void run(String... args) throws Exception {
|
||||
setup();
|
||||
tests();
|
||||
cleanup();
|
||||
bottomLine();
|
||||
}
|
||||
|
||||
void setup() throws Exception {
|
||||
cleanup();
|
||||
|
||||
tb.createDirectories("pkg");
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
* Create mutually referential jar files
|
||||
*----------------------------------------------------------------*/
|
||||
|
||||
Files.writeString(Path.of("pkg/A.java"), """
|
||||
package pkg;
|
||||
import pkg.B;
|
||||
public class A {
|
||||
public static int f() { return B.g(); }
|
||||
public static int g() { return 0; }
|
||||
}
|
||||
""");
|
||||
Files.writeString(Path.of("pkg/B.java"), """
|
||||
package pkg;
|
||||
import pkg.A;
|
||||
public class B {
|
||||
public static int f() { return A.g(); }
|
||||
public static int g() { return 0; }
|
||||
}
|
||||
""");
|
||||
|
||||
javac("pkg/A.java", "pkg/B.java");
|
||||
|
||||
makeManifestWithClassPath("./sub/B.zip");
|
||||
jar("cmf", "MANIFEST.MF", "A.jar", "pkg/A.class");
|
||||
|
||||
makeManifestWithClassPath("../A.jar");
|
||||
jar("cmf", "MANIFEST.MF", "B.zip", "pkg/B.class");
|
||||
|
||||
Files.writeString(Path.of("Main.java"), """
|
||||
import pkg.*;
|
||||
public class Main {
|
||||
public static void main(String[] a) { System.exit(A.f() + B.f()); }
|
||||
}
|
||||
""");
|
||||
|
||||
deleteFiles("pkg");
|
||||
tb.createDirectories("jars");
|
||||
tb.createDirectories("jars/sub");
|
||||
tb.moveFile("A.jar", "jars/.");
|
||||
tb.moveFile("B.zip", "jars/sub/.");
|
||||
}
|
||||
|
||||
void cleanup() throws IOException {
|
||||
deleteFiles("pkg", "Main.java", "Main.class", "Main.jar", "jars");
|
||||
deleteFiles("MANIFEST.MF", "A.jar", "B.zip");
|
||||
}
|
||||
|
||||
void tests() throws Exception {
|
||||
|
||||
/*
|
||||
* Test 1: Compiling
|
||||
*/
|
||||
|
||||
expectPass(JAVAC, "-cp jars/A.jar Main.java");
|
||||
expectPass(JAVA, "-cp jars/A.jar${PS}. Main");
|
||||
|
||||
expectPass(JAVAC, "-cp jars/sub/B.zip Main.java");
|
||||
expectPass(JAVA, "-cp jars/sub/B.zip${PS}. Main");
|
||||
|
||||
}
|
||||
}
|
253
test/langtools/tools/javac/Paths/Diagnostics.java
Normal file
253
test/langtools/tools/javac/Paths/Diagnostics.java
Normal file
@ -0,0 +1,253 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2022, 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 4884487 6295519 6236704 6429613 8293877
|
||||
* @summary Test for proper diagnostics during path manipulation operations
|
||||
* @library /tools/lib
|
||||
* @build toolbox.ToolBox Util Diagnostics
|
||||
* @run main Diagnostics
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Converted from Diagnostics.sh, originally written by Martin Buchholz.
|
||||
*
|
||||
* For the last version of the original, Diagnostics.sh, see
|
||||
* https://github.com/openjdk/jdk/blob/jdk-19%2B36/test/langtools/tools/javac/Paths/Diagnostics.sh
|
||||
*
|
||||
* This class primarily tests that javac generates warnings or errors
|
||||
* as appropriate for various input conditions.
|
||||
*
|
||||
* Note: only the {@code warning:} or {@code error:} prefixes are checked,
|
||||
* and not the subsequent text of the diagnostic.
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Locale;
|
||||
|
||||
public class Diagnostics extends Util {
|
||||
public static void main(String... args) throws Exception {
|
||||
new Diagnostics().run(args);
|
||||
}
|
||||
|
||||
void run(String... args) throws Exception{
|
||||
setup();
|
||||
|
||||
Locale prev = Locale.getDefault();
|
||||
Locale.setDefault(Locale.US); // diagnostics in English, please!
|
||||
try {
|
||||
tests();
|
||||
} finally {
|
||||
Locale.setDefault(prev);
|
||||
}
|
||||
|
||||
cleanup();
|
||||
bottomLine();
|
||||
}
|
||||
|
||||
void setup() throws IOException {
|
||||
cleanup();
|
||||
Files.writeString(Path.of("Main.java"), "public class Main{public static void main(String[]a){}}");
|
||||
}
|
||||
|
||||
void cleanup() throws IOException {
|
||||
deleteFiles("Main.java", "Main.class");
|
||||
deleteFiles("classes", "classes.foo", "classes.jar", "classes.war", "classes.zip");
|
||||
deleteFiles("MANIFEST.MF", "classesRef.jar", "classesRefRef.jar", "jars");
|
||||
}
|
||||
|
||||
void tests() throws Exception {
|
||||
/*----------------------------------------------------------------
|
||||
* No warnings unless -Xlint:path is used
|
||||
*----------------------------------------------------------------*/
|
||||
checkWarning(false, "Main.java");
|
||||
checkWarning(false, "-cp .${PS}classes Main.java");
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
* Warn for missing elts in user-specified paths
|
||||
*----------------------------------------------------------------*/
|
||||
|
||||
// use --source 8 -target 8 with bootclasspath-related options
|
||||
String JDK8 = "-source 8 -target 8 -Xlint:-options ";
|
||||
checkWarning(true, "-Xlint:path -cp .${PS}classes Main.java");
|
||||
checkWarning(true, JDK8 + "-Xlint:path -Xbootclasspath/p:classes Main.java");
|
||||
checkWarning(true, JDK8 + "-Xlint -Xbootclasspath/a:classes Main.java");
|
||||
|
||||
checkWarning(true, JDK8 + "-Xlint:-options -Xlint:path -endorseddirs classes Main.java");
|
||||
checkWarning(true, JDK8 + "-Xlint:-options -Xlint -extdirs classes Main.java");
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
* No warning for missing elts in "system" paths
|
||||
*----------------------------------------------------------------*/
|
||||
// TODO? there are system paths we could check, such as --module-path
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
* No warning if class path element exists
|
||||
*----------------------------------------------------------------*/
|
||||
tb.createDirectories("classes");
|
||||
|
||||
checkWarning(false, "-Xlint:path -cp .${PS}classes Main.java");
|
||||
checkWarning(false, JDK8 + "-Xlint:path -endorseddirs classes Main.java");
|
||||
checkWarning(false, JDK8 + "-Xlint:path -extdirs classes Main.java");
|
||||
checkWarning(false, JDK8 + "-Xlint:path -Xbootclasspath/p:classes Main.java");
|
||||
checkWarning(false, JDK8 + "-Xlint:path -Xbootclasspath/a:classes Main.java");
|
||||
|
||||
jar("cf", "classes.jar", "Main.class");
|
||||
tb.copyFile("classes.jar", "classes.war");
|
||||
tb.copyFile("classes.war", "classes.zip");
|
||||
checkWarning(false, "-Xlint:path -cp .${PS}classes.jar Main.java");
|
||||
checkWarning(true, "-Xlint:path -cp .${PS}classes.war Main.java");
|
||||
checkWarning(false, "-Xlint:path -cp .${PS}classes.zip Main.java");
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
* Warn if -Xlint is used and if class path element refers to
|
||||
* regular file which doesn't look like a zip file, but is
|
||||
*----------------------------------------------------------------*/
|
||||
tb.copyFile("classes.war", "classes.foo");
|
||||
checkWarning(true, "-Xlint:path -cp .${PS}classes.foo Main.java");
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
* No error if class path element refers to regular file which is
|
||||
* not a zip file
|
||||
*----------------------------------------------------------------*/
|
||||
checkError(false, "-cp Main.java Main.java"); // Main.java is NOT a jar file
|
||||
checkError(false, "Main.java");
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
* Warn if -Xlint is used and if class path element refers to
|
||||
* regular file which is not a zip file
|
||||
*----------------------------------------------------------------*/
|
||||
checkWarning(true, "-Xlint -cp Main.java Main.java"); // Main.java is NOT a jar file
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
* Test jar file class path reference recursion
|
||||
*----------------------------------------------------------------*/
|
||||
makeManifestWithClassPath("classesRef.jar");
|
||||
jar("cmf", "MANIFEST.MF", "classesRefRef.jar", "Main.class");
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
* Non-existent recursive Class-Path reference gives warning
|
||||
*----------------------------------------------------------------*/
|
||||
checkWarning(false, " -classpath classesRefRef.jar Main.java");
|
||||
checkWarning(true, " -Xlint -classpath classesRefRef.jar Main.java");
|
||||
checkWarning(false, JDK8 + "-Xlint -Xbootclasspath/p:classesRefRef.jar Main.java");
|
||||
|
||||
createBadJarFiles("classesRef.jar");
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
* Non-jar file recursive Class-Path reference gives error
|
||||
*----------------------------------------------------------------*/
|
||||
|
||||
checkError(true, " -classpath classesRefRef.jar Main.java");
|
||||
checkError(false, JDK8 + "-Xbootclasspath/a:classesRefRef.jar Main.java");
|
||||
|
||||
makeManifestWithClassPath("classes");
|
||||
jar("cmf", "MANIFEST.MF", "classesRef.jar", "Main.class");
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
* Jar file recursive Class-Path reference is OK
|
||||
*----------------------------------------------------------------*/
|
||||
checkWarning(false, " -Xlint -classpath classesRefRef.jar Main.java");
|
||||
checkWarning(false, JDK8 + "-Xlint -Xbootclasspath/p:classesRefRef.jar Main.java");
|
||||
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
* Class-Path attribute followed in extdirs or endorseddirs
|
||||
*----------------------------------------------------------------*/
|
||||
tb.createDirectories("jars");
|
||||
tb.copyFile("classesRefRef.jar", "jars/.");
|
||||
checkWarning(true, JDK8 + "-Xlint -extdirs jars Main.java");
|
||||
checkWarning(true, JDK8 + "-Xlint -endorseddirs jars Main.java");
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
* Bad Jar file in extdirs and endorseddirs should not be ignored
|
||||
*----------------------------------------------------------------*/
|
||||
createBadJarFiles("jars/classesRef.jar");
|
||||
checkError(true, JDK8 + "-Xlint -extdirs jars Main.java");
|
||||
checkError(true, JDK8 + "-Xlint -endorseddirs jars Main.java");
|
||||
}
|
||||
|
||||
void checkWarning(boolean expect, String args) throws Exception {
|
||||
Result result = javac(splitArgs(args));
|
||||
int exitCode = result.exitCode();
|
||||
if (exitCode != 0) {
|
||||
throw new Exception("javac failed: exit code " + exitCode);
|
||||
}
|
||||
String output = result.out();
|
||||
if (output.contains("warning:")) {
|
||||
if (!expect) {
|
||||
out.println("FAIL: Command 'javac " + args + "' printed an unexpected warning");
|
||||
failCount++;
|
||||
} else {
|
||||
passCount++;
|
||||
}
|
||||
} else {
|
||||
if (expect) {
|
||||
out.println("FAIL: Command 'javac " + args + "' did not generate the expected warning");
|
||||
failCount++;
|
||||
} else {
|
||||
passCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void checkError(boolean expect, String args) throws Exception {
|
||||
Result result = javac(splitArgs(args));
|
||||
int exitCode = result.exitCode();
|
||||
boolean ok = true;
|
||||
if (expect) {
|
||||
if (exitCode == 0) {
|
||||
out.println("FAIL: Command 'javac " + args + " was supposed to exit with non-zero return code");
|
||||
ok = false;
|
||||
}
|
||||
if (!result.out().contains("error:")) {
|
||||
out.println("FAIL: Command 'javac " + args + " did not generate any error message");
|
||||
ok = false;
|
||||
}
|
||||
} else {
|
||||
if (exitCode != 0) {
|
||||
out.println("FAIL: Command 'javac " + args + " failed with a non-zero return code");
|
||||
ok = false;
|
||||
}
|
||||
if (result.out().contains("error:")) {
|
||||
out.println("FAIL: Command 'javac " + args + " printed an unexpected error message");
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
if (ok) {
|
||||
passCount++;
|
||||
} else {
|
||||
failCount++;
|
||||
}
|
||||
}
|
||||
|
||||
void createBadJarFiles(String... paths) throws IOException {
|
||||
for (String p : paths) {
|
||||
Files.writeString(Path.of(p), "not a jar file\n");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,210 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright (c) 2003, 2022, 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 4884487 6295519 6236704 6429613
|
||||
# @summary Test for proper diagnostics during path manipulation operations
|
||||
# @author Martin Buchholz
|
||||
#
|
||||
# @run shell/timeout=180 Diagnostics.sh
|
||||
|
||||
# To run this test manually, simply do ./Diagnostics.sh
|
||||
|
||||
. ${TESTSRC-.}/Util.sh
|
||||
|
||||
set -u
|
||||
|
||||
# BCP=`DefaultBootClassPath`
|
||||
|
||||
DiagnosticsInEnglishPlease
|
||||
|
||||
No() { NO="no"; "$@"; NO=""; } # No means NO!
|
||||
|
||||
Warning() {
|
||||
HorizontalRule
|
||||
echo "$@"
|
||||
output=`"$@" 2>&1`; rc="$?"
|
||||
output2=`echo "$output" | grep -v "bootstrap class path not set in conjunction with -source"`
|
||||
test -n "$output2" && echo "$output"
|
||||
test $rc -eq 0 || Fail "Command \"$*\" failed with exitValue $rc";
|
||||
case "$output2" in *warning:*) gotwarning="yes";; *) gotwarning="no";; esac
|
||||
|
||||
if test "$gotwarning" = "yes" -a "$NO" = "no"; then
|
||||
Fail "Command \"$*\" printed an unexpected warning"
|
||||
elif test "$gotwarning" = "no" -a "$NO" != "no"; then
|
||||
Fail "Command \"$*\" did not generate the expected warning"
|
||||
fi
|
||||
}
|
||||
|
||||
Error() {
|
||||
HorizontalRule
|
||||
echo "$@"
|
||||
output=`"$@" 2>&1`; rc="$?"
|
||||
test -n "$output" && echo "$output"
|
||||
case "$output" in *error:*) goterror="yes";; *) goterror="no";; esac
|
||||
|
||||
if test "$NO" = "no"; then
|
||||
test "$rc" -ne 0 && \
|
||||
Fail "Command \"$*\" failed with return code $rc"
|
||||
test "$goterror" = "yes" && \
|
||||
Fail "Command \"$*\" did not generate any error message"
|
||||
else
|
||||
test "$rc" -eq 0 && \
|
||||
Fail "Command \"$*\" was supposed to Die with fatal error";
|
||||
test "$goterror" = "no" && \
|
||||
Fail "Command \"$*\" printed an unexpected error message"
|
||||
fi
|
||||
}
|
||||
|
||||
Cleanup() {
|
||||
Sys rm -rf Main.java Main.class
|
||||
Sys rm -rf classes classes.foo classes.jar classes.war classes.zip
|
||||
Sys rm -rf MANIFEST.MF classesRef.jar classesRefRef.jar jars
|
||||
}
|
||||
|
||||
Cleanup
|
||||
echo "public class Main{public static void main(String[]a){}}" > Main.java
|
||||
|
||||
# We need to set -source 8 -target 8 for those cases where the option is
|
||||
# not legal in 9 and later. However, that triggers an additional warning
|
||||
# about not setting bootclasspath, which is filtered out in Warning.
|
||||
# The alternative would be to extract a minimal rt.jar from JDK and
|
||||
# specify that with -bootclasspath.
|
||||
SRCTRG8="-source 8 -target 8 -Xlint:-options"
|
||||
|
||||
#----------------------------------------------------------------
|
||||
# No warnings unless -Xlint:path is used
|
||||
#----------------------------------------------------------------
|
||||
No Warning "$javac" ${TESTTOOLVMOPTS} Main.java
|
||||
No Warning "$javac" ${TESTTOOLVMOPTS} -cp ".${PS}classes" Main.java
|
||||
|
||||
#----------------------------------------------------------------
|
||||
# Warn for missing elts in user-specified paths
|
||||
#----------------------------------------------------------------
|
||||
Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path -cp ".${PS}classes" Main.java
|
||||
Warning "$javac" ${TESTTOOLVMOPTS} ${SRCTRG8} -Xlint:path "-Xbootclasspath/p:classes" Main.java
|
||||
Warning "$javac" ${TESTTOOLVMOPTS} ${SRCTRG8} -Xlint "-Xbootclasspath/a:classes" Main.java
|
||||
|
||||
Warning "$javac" ${TESTTOOLVMOPTS} ${SRCTRG8} -Xlint:path "-endorseddirs" "classes" Main.java
|
||||
Warning "$javac" ${TESTTOOLVMOPTS} ${SRCTRG8} -Xlint "-extdirs" "classes" Main.java
|
||||
#Warning "$javac" ${TESTTOOLVMOPTS} ${SRCTRG8} -Xlint:path "-Xbootclasspath:classes${PS}${BCP}" Main.java
|
||||
|
||||
#----------------------------------------------------------------
|
||||
# No warning for missing elts in "system" paths
|
||||
#----------------------------------------------------------------
|
||||
# No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path "-J-Djava.endorsed.dirs=classes" Main.java
|
||||
# No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path "-J-Djava.ext.dirs=classes" Main.java
|
||||
# No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path "-J-Xbootclasspath/p:classes" Main.java
|
||||
# No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path "-J-Xbootclasspath/a:classes" Main.java
|
||||
# No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path "-J-Xbootclasspath:classes${PS}${BCP}" Main.java
|
||||
|
||||
#----------------------------------------------------------------
|
||||
# No warning if class path element exists
|
||||
#----------------------------------------------------------------
|
||||
Sys mkdir classes
|
||||
No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path -cp ".${PS}classes" Main.java
|
||||
No Warning "$javac" ${TESTTOOLVMOPTS} ${SRCTRG8} -Xlint:path "-endorseddirs" "classes" Main.java
|
||||
No Warning "$javac" ${TESTTOOLVMOPTS} ${SRCTRG8} -Xlint:path "-extdirs" "classes" Main.java
|
||||
No Warning "$javac" ${TESTTOOLVMOPTS} ${SRCTRG8} -Xlint:path "-Xbootclasspath/p:classes" Main.java
|
||||
No Warning "$javac" ${TESTTOOLVMOPTS} ${SRCTRG8} -Xlint:path "-Xbootclasspath/a:classes" Main.java
|
||||
#No Warning "$javac" ${TESTTOOLVMOPTS} ${SRCTRG8} -Xlint:path "-Xbootclasspath:classes${PS}${BCP}" Main.java
|
||||
|
||||
Sys "$jar" cf classes.jar Main.class
|
||||
Sys cp classes.jar classes.war
|
||||
Sys cp classes.war classes.zip
|
||||
No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path -cp ".${PS}classes.jar" Main.java
|
||||
Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path -cp ".${PS}classes.war" Main.java
|
||||
No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path -cp ".${PS}classes.zip" Main.java
|
||||
|
||||
#----------------------------------------------------------------
|
||||
# Warn if -Xlint is used and if class path element refers to
|
||||
# regular file which doesn't look like a zip file, but is
|
||||
#----------------------------------------------------------------
|
||||
Sys cp classes.war classes.foo
|
||||
Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path -cp ".${PS}classes.foo" Main.java
|
||||
|
||||
|
||||
#----------------------------------------------------------------
|
||||
# No error if class path element refers to regular file which is
|
||||
# not a zip file
|
||||
#----------------------------------------------------------------
|
||||
No Error "$javac" ${TESTTOOLVMOPTS} -cp Main.java Main.java # Main.java is NOT a jar file
|
||||
No Error "$javac" ${TESTTOOLVMOPTS} Main.java
|
||||
|
||||
#----------------------------------------------------------------
|
||||
# Warn if -Xlint is used and if class path element refers to
|
||||
# regular file which is not a zip file
|
||||
#----------------------------------------------------------------
|
||||
Warning "$javac" ${TESTTOOLVMOPTS} -Xlint -cp Main.java Main.java # Main.java is NOT a jar file
|
||||
|
||||
#----------------------------------------------------------------
|
||||
# Test jar file class path reference recursion
|
||||
#----------------------------------------------------------------
|
||||
MkManifestWithClassPath classesRef.jar
|
||||
Sys "$jar" cmf MANIFEST.MF classesRefRef.jar Main.class
|
||||
|
||||
#----------------------------------------------------------------
|
||||
# Non-existent recursive Class-Path reference gives warning
|
||||
#----------------------------------------------------------------
|
||||
No Warning "$javac" ${TESTTOOLVMOPTS} -classpath classesRefRef.jar Main.java
|
||||
Warning "$javac" ${TESTTOOLVMOPTS} -Xlint -classpath classesRefRef.jar Main.java
|
||||
No Warning "$javac" ${TESTTOOLVMOPTS} ${SRCTRG8} -Xlint -Xbootclasspath/p:classesRefRef.jar Main.java
|
||||
|
||||
BadJarFile classesRef.jar
|
||||
|
||||
#----------------------------------------------------------------
|
||||
# Non-jar file recursive Class-Path reference gives error
|
||||
#----------------------------------------------------------------
|
||||
Error "$javac" ${TESTTOOLVMOPTS} -classpath classesRefRef.jar Main.java
|
||||
No Error "$javac" ${TESTTOOLVMOPTS} ${SRCTRG8} -Xbootclasspath/a:classesRefRef.jar Main.java
|
||||
|
||||
MkManifestWithClassPath classes
|
||||
Sys "$jar" cmf MANIFEST.MF classesRef.jar Main.class
|
||||
|
||||
#----------------------------------------------------------------
|
||||
# Jar file recursive Class-Path reference is OK
|
||||
#----------------------------------------------------------------
|
||||
No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint -classpath classesRefRef.jar Main.java
|
||||
No Warning "$javac" ${TESTTOOLVMOPTS} ${SRCTRG8} -Xlint -Xbootclasspath/p:classesRefRef.jar Main.java
|
||||
|
||||
#----------------------------------------------------------------
|
||||
# Class-Path attribute followed in extdirs or endorseddirs
|
||||
#----------------------------------------------------------------
|
||||
Sys mkdir jars
|
||||
Sys cp classesRefRef.jar jars/.
|
||||
Warning "$javac" ${TESTTOOLVMOPTS} ${SRCTRG8} -Xlint -extdirs jars Main.java
|
||||
Warning "$javac" ${TESTTOOLVMOPTS} ${SRCTRG8} -Xlint -endorseddirs jars Main.java
|
||||
|
||||
#----------------------------------------------------------------
|
||||
# Bad Jar file in extdirs and endorseddirs should not be ignored
|
||||
#----------------------------------------------------------------
|
||||
BadJarFile jars/classesRef.jar
|
||||
Error "$javac" ${TESTTOOLVMOPTS} ${SRCTRG8} -Xlint -extdirs jars Main.java
|
||||
Error "$javac" ${TESTTOOLVMOPTS} ${SRCTRG8} -Xlint -endorseddirs jars Main.java
|
||||
|
||||
Cleanup
|
||||
|
||||
Bottom Line
|
82
test/langtools/tools/javac/Paths/Help.java
Normal file
82
test/langtools/tools/javac/Paths/Help.java
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2022, 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 4940642 8293877
|
||||
* @summary Check for -help and -X flags
|
||||
*/
|
||||
|
||||
/*
|
||||
* Converted from Help.sh, originally written by Martin Buchholz
|
||||
*
|
||||
* For the last version of the original, Help.sh, see
|
||||
* https://github.com/openjdk/jdk/blob/jdk-19%2B36/test/langtools/tools/javac/Paths/Help.sh
|
||||
*
|
||||
* This class provides rudimentary tests of the javac command-line help.
|
||||
*/
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.spi.ToolProvider;
|
||||
|
||||
public class Help {
|
||||
public static void main(String... args) throws Exception {
|
||||
new Help().run(args);
|
||||
}
|
||||
|
||||
void run(String... args) throws Exception {
|
||||
String helpText = javac("-help");
|
||||
check(helpText,
|
||||
"-X ", "-J", "-classpath ", "-cp ", "-bootclasspath ", "-sourcepath ");
|
||||
|
||||
String xText = javac("-X");
|
||||
check(xText, "-Xbootclasspath/p:");
|
||||
}
|
||||
|
||||
void check(String text, String... options) throws Exception {
|
||||
for (String opt : options) {
|
||||
System.err.println("Checking '" + opt + "'");
|
||||
if (!text.contains(opt)) {
|
||||
text.lines().forEach(System.err::println);
|
||||
throw new Exception("Bad help output");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String javac(String... args) throws Exception {
|
||||
var javac = ToolProvider.findFirst("javac")
|
||||
.orElseThrow(() -> new Exception("cannot find javac"));
|
||||
try (StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw)) {
|
||||
int rc = javac.run(pw, pw, args);
|
||||
if (rc != 0) {
|
||||
throw new Error("unexpected exit from javac: " + rc);
|
||||
}
|
||||
pw.flush();
|
||||
return sw.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,69 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright (c) 2003, 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.
|
||||
#
|
||||
|
||||
#
|
||||
# @test
|
||||
# @bug 4940642
|
||||
# @summary Check for -help and -X flags
|
||||
# @author Martin Buchholz
|
||||
#
|
||||
# @run shell Help.sh
|
||||
|
||||
# To run this test manually, simply do ./MineField.sh
|
||||
|
||||
|
||||
. ${TESTSRC-.}/Util.sh
|
||||
|
||||
set -u
|
||||
|
||||
DiagnosticsInEnglishPlease
|
||||
|
||||
HELP="`\"$javac\" ${TESTTOOLVMOPTS} -help 2>&1`"
|
||||
XHELP="`\"$javac\" ${TESTTOOLVMOPTS} -X 2>&1`"
|
||||
|
||||
#----------------------------------------------------------------
|
||||
# Standard options
|
||||
#----------------------------------------------------------------
|
||||
for opt in \
|
||||
"-X " \
|
||||
"-J" \
|
||||
"-classpath " \
|
||||
"-cp " \
|
||||
"-bootclasspath " \
|
||||
"-sourcepath ";
|
||||
do
|
||||
case "$HELP" in *"$opt"*) ;; *) Fail "Bad help output" ;; esac
|
||||
done
|
||||
|
||||
#----------------------------------------------------------------
|
||||
# Non-standard options
|
||||
#----------------------------------------------------------------
|
||||
for opt in \
|
||||
"-Xbootclasspath/p:";
|
||||
do
|
||||
case "$XHELP" in *"$opt"*) ;; *) Fail "Bad help output" ;; esac
|
||||
done
|
||||
|
||||
Bottom Line
|
352
test/langtools/tools/javac/Paths/MineField.java
Normal file
352
test/langtools/tools/javac/Paths/MineField.java
Normal file
@ -0,0 +1,352 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2022, 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 4758537 4809833 8149599 8293877
|
||||
* @summary Test that javac and java find files in similar ways
|
||||
* @library /tools/lib
|
||||
* @build toolbox.ToolBox Util MineField
|
||||
* @run main MineField
|
||||
*/
|
||||
|
||||
/*
|
||||
* Converted from MineField.sh, originally written by Martin Buchholz.
|
||||
*
|
||||
* For the last version of the original, MineField.sh, see
|
||||
* https://github.com/openjdk/jdk/blob/jdk-19%2B36/test/langtools/tools/javac/Paths/MineField.sh
|
||||
*
|
||||
* This class primarily tests that javac and the java launcher provide
|
||||
* equivalent handling of all path-related options, like {@code -classpath}.
|
||||
*/
|
||||
|
||||
/*
|
||||
#----------------------------------------------------------------
|
||||
# The search order for classes used by both java and javac is:
|
||||
#
|
||||
# -Xbootclasspath/p:<path>
|
||||
# -endorseddirs <dirs> or -Djava.endorsed.dirs=<dirs> (search for jar/zip only)
|
||||
# -bootclasspath <path> or -Xbootclasspath:<path>
|
||||
# -Xbootclasspath/a:<path>
|
||||
# -extdirs <dirs> or -Djava.ext.dirs=<dirs> (search for jar/zip only)
|
||||
# -classpath <path>, -cp <path>, env CLASSPATH=<path>
|
||||
#
|
||||
# Peculiarities of the class file search:
|
||||
# - Empty elements of the (user) classpath default to ".",
|
||||
# while empty elements of other paths are ignored.
|
||||
# - Only for the user classpath is an empty string value equivalent to "."
|
||||
# - Specifying a bootclasspath on the command line obliterates any
|
||||
# previous -Xbootclasspath/p: or -Xbootclasspath/a: command line flags.
|
||||
#
|
||||
# JDK 9 update:
|
||||
# java: The java launcher does not support any of the following:
|
||||
# * -Xbootclasspath/p: -Xbootclasspath:
|
||||
# * -endorseddirs -Djava.endorsed.dirs
|
||||
# * -extdirs -Djava.ext.dirs
|
||||
# All test cases exercising these features have been removed.
|
||||
# javac: The following features are only supported when compiling
|
||||
# for older releases:
|
||||
# * -Xbootclasspath/p: -Xbootclasspath: -bootclasspath -Xbootclasspath/a:
|
||||
# * -endorseddirs -Djava.endorsed.dirs
|
||||
# * -extdirs -Djava.ext.dirs
|
||||
# All test cases exercising these features have been modified to
|
||||
# use -source 8 -target 8. In addition, javac test cases involving
|
||||
# use of the runtime properties java.endorsed.dirs and java.extdirs
|
||||
# (by means of -J-Dname=value) have been removed.
|
||||
# Although the primary purpose of the test cases in this file is to
|
||||
# compare javac and java behavior, some tests remain for javac for
|
||||
# which there is no java equivalent. However, the cases remain as useful
|
||||
# test cases for javac handling of the paths involved.
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class MineField extends Util {
|
||||
public static void main(String... args) throws Exception {
|
||||
new MineField().run(args);
|
||||
}
|
||||
|
||||
void run(String... args) throws Exception{
|
||||
setup();
|
||||
tests();
|
||||
cleanup();
|
||||
bottomLine();
|
||||
}
|
||||
|
||||
void cleanup() throws IOException {
|
||||
deleteFiles("GooSrc", "GooJar", "GooZip", "GooClass");
|
||||
deleteFiles("BadSrc", "BadJar", "BadZip", "BadClass");
|
||||
deleteFiles("OneDir", "Main.java", "MANIFEST.MF");
|
||||
deleteFiles(listFiles(Path.of("."), "*.class"));
|
||||
deleteFiles("java-lang.jar");
|
||||
}
|
||||
|
||||
/**
|
||||
* "Prepare the minefield".
|
||||
*/
|
||||
void setup() throws Exception {
|
||||
cleanup();
|
||||
|
||||
tb.createDirectories("GooSrc", "GooJar", "GooZip", "GooClass");
|
||||
tb.createDirectories("BadSrc", "BadJar", "BadZip", "BadClass");
|
||||
|
||||
Files.writeString(Path.of("Lib.java"),
|
||||
"public class Lib {public static void f(){}}");
|
||||
javac("Lib.java");
|
||||
jar("cf", "GooJar/Lib.jar", "Lib.class");
|
||||
jar("cf", "GooZip/Lib.zip", "Lib.class");
|
||||
tb.moveFile("Lib.class", "GooClass/.");
|
||||
tb.moveFile("Lib.java", "GooSrc/.");
|
||||
checkFiles("GooZip/Lib.zip", "GooJar/Lib.jar", "GooSrc/Lib.java");
|
||||
|
||||
Files.writeString(Path.of("Lib.java"),
|
||||
"public class Lib {/* Bad */}");
|
||||
javac("Lib.java");
|
||||
jar("cf", "BadJar/Lib.jar", "Lib.class");
|
||||
jar("cf", "BadZip/Lib.zip", "Lib.class");
|
||||
tb.moveFile("Lib.class", "BadClass/.");
|
||||
tb.moveFile("Lib.java", "BadSrc/.");
|
||||
checkFiles("BadZip/Lib.zip", "BadJar/Lib.jar", "BadSrc/Lib.java");
|
||||
|
||||
Files.writeString(Path.of("Main.java"),
|
||||
"public class Main {public static void main(String[] a) {Lib.f();}}");
|
||||
Path libModules = javaHome.resolve("lib").resolve("modules");
|
||||
if (Files.isReadable(libModules)) {
|
||||
jimage("extract", "--dir", "modules", libModules.toString());
|
||||
jar("cf", "java-lang.jar", "-C", "modules/java.base", "java/lang");
|
||||
deleteFiles("modules");
|
||||
} else {
|
||||
Path modules = javaHome.resolve("modules");
|
||||
if (Files.isDirectory(modules)) {
|
||||
jar("cf", "java-lang.jar", "-C", modules.resolve("java.base").toString(), "java/lang");
|
||||
} else {
|
||||
throw new Exception("Cannot create java-lang.jar");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void tests() throws Exception {
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// Verify that javac class search order is the same as java's
|
||||
//----------------------------------------------------------------
|
||||
|
||||
expectFail(JAVAC, """
|
||||
-source 8 -target 8
|
||||
-Xbootclasspath/p:GooClass
|
||||
-bootclasspath java-lang.jar${PS}BadZip/Lib.zip
|
||||
Main.java""");
|
||||
|
||||
expectPass(JAVAC, """
|
||||
-source 8 -target 8
|
||||
-Xbootclasspath/p:BadClass${PS}GooClass
|
||||
-bootclasspath java-lang.jar${PS}GooZip/Lib.zip${PS}BadClass
|
||||
Main.java""");
|
||||
|
||||
expectPass(JAVAC, """
|
||||
-source 8 -target 8
|
||||
-Xbootclasspath/p:BadJar/Lib.jar
|
||||
-Xbootclasspath:java-lang.jar${PS}GooClass
|
||||
Main.java""");
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
||||
expectFail(JAVAC, """
|
||||
-source 8 -target 8
|
||||
-bootclasspath java-lang.jar${PS}GooZip/Lib.zip
|
||||
-Xbootclasspath/p:BadClass
|
||||
Main.java""");
|
||||
|
||||
expectPass(JAVAC, """
|
||||
-source 8 -target 8
|
||||
-bootclasspath java-lang.jar${PS}BadZip/Lib.zip
|
||||
-Xbootclasspath/p:GooClass${PS}BadJar/Lib.jar
|
||||
Main.java""");
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
||||
expectFail(JAVAC, """
|
||||
-source 8 -target 8
|
||||
-Xbootclasspath/p:BadClass
|
||||
-Xbootclasspath/a:GooClass
|
||||
Main.java""");
|
||||
|
||||
expectPass(JAVAC, """
|
||||
-source 8 -target 8
|
||||
-Xbootclasspath/p:GooClass${PS}BadClass
|
||||
-Xbootclasspath/a:BadClass
|
||||
Main.java""");
|
||||
|
||||
expectPass(JAVA, """
|
||||
-Xbootclasspath/a:GooClass
|
||||
Main""");
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
||||
expectFail(JAVAC, """
|
||||
-source 8 -target 8
|
||||
-Xbootclasspath/p:GooClass
|
||||
-Xbootclasspath:BadClass${PS}java-lang.jar
|
||||
-Xbootclasspath/a:GooClass
|
||||
Main.java""");
|
||||
|
||||
expectPass(JAVAC, """
|
||||
-source 8 -target 8
|
||||
-Xbootclasspath/p:BadClass
|
||||
-Xbootclasspath:GooClass${PS}BadClass${PS}java-lang.jar
|
||||
-Xbootclasspath/a:BadClass
|
||||
Main.java""");
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
||||
expectPass(JAVAC, """
|
||||
-source 8 -target 8
|
||||
-endorseddirs BadClass${PS}GooZip${PS}BadJar
|
||||
-Xbootclasspath:"BadClass${PS}java-lang.jar
|
||||
Main.java""");
|
||||
|
||||
expectPass(JAVAC, """
|
||||
-source 8 -target 8
|
||||
-Djava.endorsed.dirs=BadClass${PS}GooZip${PS}BadJar
|
||||
-Xbootclasspath:BadClass${PS}java-lang.jar
|
||||
Main.java""");
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
||||
expectFail(JAVAC, """
|
||||
-source 8 -target 8
|
||||
-Xbootclasspath/a:BadClass
|
||||
-extdirs GooZip
|
||||
Main.java""");
|
||||
|
||||
expectPass(JAVAC, """
|
||||
-source 8 -target 8
|
||||
-Xbootclasspath/a:GooClass${PS}BadClass
|
||||
-extdirs BadZip
|
||||
Main.java""");
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
||||
expectFail(JAVAC, """
|
||||
-source 8 -target 8
|
||||
-extdirs GooClass${PS}BadZip
|
||||
-cp GooZip/Lib.zip
|
||||
Main.java""");
|
||||
|
||||
expectPass(JAVAC, """
|
||||
-source 8 -target 8
|
||||
-extdirs BadClass${PS}GooZip${PS}BadJar
|
||||
-cp BadZip/Lib.zip
|
||||
Main.java""");
|
||||
|
||||
expectPass(JAVAC, """
|
||||
-source 8 -target 8
|
||||
-Djava.ext.dirs=GooZip${PS}BadJar
|
||||
-classpath BadZip/Lib.zip
|
||||
Main.java""");
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
||||
expectFail(JAVAC, "-classpath BadClass${PS}GooClass Main.java");
|
||||
expectPass(JAVAC, "-classpath GooClass${PS}BadClass Main.java");
|
||||
expectFail(JAVA, "-classpath BadClass${PS}GooClass${PS}. Main");
|
||||
expectPass(JAVA, "-classpath GooClass${PS}BadClass${PS}. Main");
|
||||
|
||||
expectFail(JAVAC, "-cp BadJar/Lib.jar${PS}GooZip/Lib.zip Main.java");
|
||||
expectPass(JAVAC, "-cp GooJar/Lib.jar${PS}BadZip/Lib.zip Main.java");
|
||||
expectFail(JAVA, "-cp BadJar/Lib.jar${PS}${PS}GooZip/Lib.zip Main");
|
||||
expectPass(JAVA, "-cp GooJar/Lib.jar${PS}${PS}BadZip/Lib.zip Main");
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
||||
expectFail(classpath("BadZip/Lib.zip${PS}GooJar/Lib.jar"), JAVAC,"Main.java");
|
||||
expectPass(classpath("GooZip/Lib.zip${PS}BadJar/Lib.jar"), JAVAC, "Main.java");
|
||||
expectFail(classpath("${PS}BadZip/Lib.zip${PS}GooJar/Lib.jar"), JAVA, "Main");
|
||||
expectPass(classpath("${PS}GooZip/Lib.zip${PS}BadJar/Lib.jar"), JAVA, "Main");
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// Check behavior of empty paths and empty path elements
|
||||
//----------------------------------------------------------------
|
||||
|
||||
Path GooClass = Path.of("GooClass");
|
||||
Path GooJar = Path.of("GooJar");
|
||||
|
||||
expectFail(GooClass, JAVAC, "-cp .. ../Main.java");
|
||||
expectFail(GooClass, JAVA, "-cp .. Main");
|
||||
|
||||
// Unspecified classpath defaults to "."
|
||||
Path OneDir = Path.of("OneDir");
|
||||
tb.createDirectories(OneDir);
|
||||
tb.copyFile(Path.of("Main.java"), OneDir);
|
||||
tb.copyFile(GooClass.resolve("Lib.class"), OneDir);
|
||||
expectPass(OneDir, JAVAC, "Main.java");
|
||||
expectPass(OneDir, JAVA, "Main");
|
||||
|
||||
// Empty classpath elements mean "."
|
||||
expectPass(GooClass, JAVAC, "-cp ${PS}.. ../Main.java");
|
||||
expectPass(GooClass, JAVA, "-cp ${PS}.. Main");
|
||||
|
||||
expectPass(GooClass, JAVAC, "-cp ..${PS} ../Main.java");
|
||||
expectPass(GooClass, JAVA, "-cp ..${PS} Main");
|
||||
|
||||
expectPass(GooClass, JAVAC, "-cp ..${PS}${PS}/xyzzy ../Main.java");
|
||||
expectPass(GooClass, JAVA, "-cp ..${PS}${PS}/xyzzy Main");
|
||||
|
||||
// All other empty path elements are ignored.
|
||||
|
||||
// note presence of empty arg in this invocation
|
||||
expectFail(GooJar, null, JAVAC, "-source", "8", "-target", "8", "-extdirs", "", "-cp", "..", "../Main.java");
|
||||
|
||||
expectFail(GooJar, JAVAC, "-source 8 -target 8 -extdirs ${PS} -cp .. ../Main.java");
|
||||
expectFail(GooJar, JAVAC, "-source 8 -target 8 -Djava.ext.dirs=${PS} -cp .. ../Main.java");
|
||||
|
||||
expectPass(GooJar, JAVAC, "-source 8 -target 8 -extdirs . -cp .. ../Main.java");
|
||||
expectPass(GooJar, JAVAC, "-source 8 -target 8 -Djava.ext.dirs=. -cp .. ../Main.java");
|
||||
|
||||
expectFail(GooJar, JAVAC, "-source 8 -target 8 -Djava.endorsed.dirs= -cp .. ../Main.java");
|
||||
|
||||
expectFail(GooJar, JAVAC, "-source 8 -target 8 -endorseddirs ${PS} -cp .. ../Main.java");
|
||||
|
||||
expectPass(GooJar, JAVAC, "-source 8 -target 8 -Djava.endorsed.dirs=. -cp .. ../Main.java");
|
||||
|
||||
expectFail(GooClass, JAVAC, "-source 8 -target 8 -Xbootclasspath/p: -cp .. ../Main.java");
|
||||
|
||||
expectPass(GooClass, JAVAC, "-source 8 -target 8 -Xbootclasspath/p:. -cp .. ../Main.java");
|
||||
|
||||
expectFail(GooClass, JAVAC, "-source 8 -target 8 -Xbootclasspath:../java-lang.jar -cp .. ../Main.java");
|
||||
|
||||
expectPass(GooClass, JAVAC, "-source 8 -target 8 -Xbootclasspath:../java-lang.jar${PS}. -cp .. ../Main.java");
|
||||
|
||||
expectFail(GooClass, JAVAC, "-source 8 -target 8 -Xbootclasspath/a: -cp .. ../Main.java");
|
||||
expectFail(GooClass, JAVA, "-Xbootclasspath/a: -cp .. Main");
|
||||
|
||||
expectPass(GooClass, JAVAC, "-source 8 -target 8 -Xbootclasspath/a:. -cp .. ../Main.java");
|
||||
expectPass(GooClass, JAVA, "-Xbootclasspath/a:. -cp .. Main");
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,277 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright (c) 2003, 2016, 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 4758537 4809833 8149599
|
||||
# @summary Test that javac and java find files in similar ways
|
||||
# @author Martin Buchholz
|
||||
#
|
||||
# @run shell/timeout=600 MineField.sh
|
||||
|
||||
# To run this test manually, simply do ./MineField.sh
|
||||
|
||||
#----------------------------------------------------------------
|
||||
# The search order for classes used by both java and javac is:
|
||||
#
|
||||
# -Xbootclasspath/p:<path>
|
||||
# -endorseddirs <dirs> or -Djava.endorsed.dirs=<dirs> (search for jar/zip only)
|
||||
# -bootclasspath <path> or -Xbootclasspath:<path>
|
||||
# -Xbootclasspath/a:<path>
|
||||
# -extdirs <dirs> or -Djava.ext.dirs=<dirs> (search for jar/zip only)
|
||||
# -classpath <path>, -cp <path>, env CLASSPATH=<path>
|
||||
#
|
||||
# Peculiarities of the class file search:
|
||||
# - Empty elements of the (user) classpath default to ".",
|
||||
# while empty elements of other paths are ignored.
|
||||
# - Only for the user classpath is an empty string value equivalent to "."
|
||||
# - Specifying a bootclasspath on the command line obliterates any
|
||||
# previous -Xbootclasspath/p: or -Xbootclasspath/a: command line flags.
|
||||
#
|
||||
# JDK 9 update:
|
||||
# java: The java launcher does not support any of the following:
|
||||
# * -Xbootclasspath/p: -Xbootclasspath:
|
||||
# * -endorseddirs -Djava.endorsed.dirs
|
||||
# * -extdirs -Djava.ext.dirs
|
||||
# All test cases exercising these features have been removed.
|
||||
# javac: The following features are only supported when compiling
|
||||
# for older releases:
|
||||
# * -Xbootclasspath/p: -Xbootclasspath: -bootclasspath -Xbootclasspath/a:
|
||||
# * -endorseddirs -Djava.endorsed.dirs
|
||||
# * -extdirs -Djava.ext.dirs
|
||||
# All test cases exercising these features have been modified to
|
||||
# use -source 8 -target 8. In addition, javac test cases involving
|
||||
# use of the runtime properties java.endorsed.dirs and java.extdirs
|
||||
# (by means of -J-Dname=value) have been removed.
|
||||
# Although the primary purpose of the test cases in this file is to
|
||||
# compare javac and java behavior, some tests remain for javac for
|
||||
# which there is no java equivalent. However, the cases remain as useful
|
||||
# test cases for javac handling of the paths involved.
|
||||
|
||||
#----------------------------------------------------------------
|
||||
|
||||
. ${TESTSRC-.}/Util.sh
|
||||
|
||||
set -u
|
||||
|
||||
#----------------------------------------------------------------
|
||||
# Prepare the "Minefield"
|
||||
#----------------------------------------------------------------
|
||||
Cleanup() {
|
||||
Sys rm -rf GooSrc GooJar GooZip GooClass
|
||||
Sys rm -rf BadSrc BadJar BadZip BadClass
|
||||
Sys rm -rf OneDir *.class Main.java MANIFEST.MF
|
||||
Sys rm -f java-lang.jar
|
||||
}
|
||||
|
||||
Cleanup
|
||||
Sys mkdir GooSrc GooJar GooZip GooClass
|
||||
Sys mkdir BadSrc BadJar BadZip BadClass
|
||||
|
||||
echo 'public class Lib {public static void f(){}}' > Lib.java
|
||||
Sys "$javac" ${TESTTOOLVMOPTS} Lib.java
|
||||
Sys "$jar" cf GooJar/Lib.jar Lib.class
|
||||
Sys "$jar" cf GooZip/Lib.zip Lib.class
|
||||
Sys mv Lib.class GooClass/.
|
||||
Sys mv Lib.java GooSrc/.
|
||||
CheckFiles GooZip/Lib.zip GooJar/Lib.jar GooSrc/Lib.java
|
||||
|
||||
echo 'public class Lib {/* Bad */}' > Lib.java
|
||||
Sys "$javac" ${TESTTOOLVMOPTS} Lib.java
|
||||
Sys "$jar" cf BadJar/Lib.jar Lib.class
|
||||
Sys "$jar" cf BadZip/Lib.zip Lib.class
|
||||
Sys mv Lib.class BadClass/.
|
||||
Sys mv Lib.java BadSrc/.
|
||||
CheckFiles BadZip/Lib.zip BadJar/Lib.jar BadSrc/Lib.java
|
||||
|
||||
echo 'public class Main {public static void main(String[] a) {Lib.f();}}' > Main.java
|
||||
|
||||
# Create a jar file that is good enough to put on the javac boot class path (i.e. contains java.lang.**)
|
||||
if [ -r ${TESTJAVA}/lib/modules ]; then
|
||||
Sys "$jimage" extract --dir modules ${TESTJAVA}/lib/modules
|
||||
Sys "$jar" cf java-lang.jar -C modules/java.base java/lang
|
||||
Sys rm -rf modules
|
||||
elif [ -d ${TESTJAVA}/modules ]; then
|
||||
Sys "$jar" cf java-lang.jar -C ${TESTJAVA}/modules/java.base java/lang
|
||||
else
|
||||
echo 'cannot create java-lang.jar' ; exit 1
|
||||
fi
|
||||
|
||||
#----------------------------------------------------------------
|
||||
# Verify that javac class search order is the same as java's
|
||||
#----------------------------------------------------------------
|
||||
Failure "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} \
|
||||
-Xbootclasspath/p:"GooClass" \
|
||||
-bootclasspath "java-lang.jar${PS}BadZip/Lib.zip" \
|
||||
Main.java
|
||||
Success "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} \
|
||||
-Xbootclasspath/p:"BadClass${PS}GooClass" \
|
||||
-bootclasspath "java-lang.jar${PS}GooZip/Lib.zip${PS}BadClass" \
|
||||
Main.java
|
||||
Success "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} \
|
||||
-Xbootclasspath/p:"BadJar/Lib.jar" \
|
||||
-Xbootclasspath:"java-lang.jar${PS}GooClass" \
|
||||
Main.java
|
||||
|
||||
#----------------------------------------------------------------
|
||||
Failure "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} \
|
||||
-bootclasspath "java-lang.jar${PS}GooZip/Lib.zip" \
|
||||
-Xbootclasspath/p:"BadClass" \
|
||||
Main.java
|
||||
Success "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} \
|
||||
-bootclasspath "java-lang.jar${PS}BadZip/Lib.zip" \
|
||||
-Xbootclasspath/p:"GooClass${PS}BadJar/Lib.jar" \
|
||||
Main.java
|
||||
|
||||
#----------------------------------------------------------------
|
||||
Failure "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} \
|
||||
-Xbootclasspath/p:"BadClass" \
|
||||
-Xbootclasspath/a:"GooClass" \
|
||||
Main.java
|
||||
Success "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} \
|
||||
-Xbootclasspath/p:"GooClass${PS}BadClass" \
|
||||
-Xbootclasspath/a:"BadClass" \
|
||||
Main.java
|
||||
Success "$java" ${TESTVMOPTS} \
|
||||
-Xbootclasspath/a:"GooClass" \
|
||||
Main
|
||||
|
||||
#----------------------------------------------------------------
|
||||
Failure "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} \
|
||||
-Xbootclasspath/p:"GooClass" \
|
||||
-Xbootclasspath:"BadClass${PS}java-lang.jar" \
|
||||
-Xbootclasspath/a:"GooClass" \
|
||||
Main.java
|
||||
Success "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} \
|
||||
-Xbootclasspath/p:"BadClass" \
|
||||
-Xbootclasspath:"GooClass${PS}BadClass${PS}java-lang.jar" \
|
||||
-Xbootclasspath/a:"BadClass" \
|
||||
Main.java
|
||||
|
||||
#----------------------------------------------------------------
|
||||
Success "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} \
|
||||
-endorseddirs "BadClass${PS}GooZip${PS}BadJar" \
|
||||
-Xbootclasspath:"BadClass${PS}java-lang.jar" \
|
||||
Main.java
|
||||
Success "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} \
|
||||
-Djava.endorsed.dirs="BadClass${PS}GooZip${PS}BadJar" \
|
||||
-Xbootclasspath:"BadClass${PS}java-lang.jar" \
|
||||
Main.java
|
||||
|
||||
#----------------------------------------------------------------
|
||||
Failure "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} \
|
||||
-Xbootclasspath/a:"BadClass" \
|
||||
-extdirs "GooZip" \
|
||||
Main.java
|
||||
Success "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} \
|
||||
-Xbootclasspath/a:"GooClass${PS}BadClass" \
|
||||
-extdirs "BadZip" \
|
||||
Main.java
|
||||
|
||||
#----------------------------------------------------------------
|
||||
Failure "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} \
|
||||
-extdirs "GooClass${PS}BadZip" \
|
||||
-cp "GooZip/Lib.zip" \
|
||||
Main.java
|
||||
Success "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} \
|
||||
-extdirs "BadClass${PS}GooZip${PS}BadJar" \
|
||||
-cp "BadZip/Lib.zip" \
|
||||
Main.java
|
||||
Success "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} \
|
||||
-Djava.ext.dirs="GooZip${PS}BadJar" \
|
||||
-classpath "BadZip/Lib.zip" \
|
||||
Main.java
|
||||
|
||||
#----------------------------------------------------------------
|
||||
Failure "$javac" ${TESTTOOLVMOPTS} -classpath "BadClass${PS}GooClass" Main.java
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -classpath "GooClass${PS}BadClass" Main.java
|
||||
Failure "$java" ${TESTVMOPTS} -classpath "BadClass${PS}GooClass${PS}." Main
|
||||
Success "$java" ${TESTVMOPTS} -classpath "GooClass${PS}BadClass${PS}." Main
|
||||
|
||||
Failure "$javac" ${TESTTOOLVMOPTS} -cp "BadJar/Lib.jar${PS}GooZip/Lib.zip" Main.java
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -cp "GooJar/Lib.jar${PS}BadZip/Lib.zip" Main.java
|
||||
Failure "$java" ${TESTVMOPTS} -cp "BadJar/Lib.jar${PS}${PS}GooZip/Lib.zip" Main
|
||||
Success "$java" ${TESTVMOPTS} -cp "GooJar/Lib.jar${PS}${PS}BadZip/Lib.zip" Main
|
||||
|
||||
Failure env CLASSPATH="BadZip/Lib.zip${PS}GooJar/Lib.jar" "$javac" ${TESTTOOLVMOPTS} Main.java
|
||||
Success env CLASSPATH="GooZip/Lib.zip${PS}BadJar/Lib.jar" "$javac" ${TESTTOOLVMOPTS} Main.java
|
||||
Failure env CLASSPATH="${PS}BadZip/Lib.zip${PS}GooJar/Lib.jar" "$java" ${TESTVMOPTS} Main
|
||||
Success env CLASSPATH="${PS}GooZip/Lib.zip${PS}BadJar/Lib.jar" "$java" ${TESTVMOPTS} Main
|
||||
|
||||
#----------------------------------------------------------------
|
||||
# Check behavior of empty paths and empty path elements
|
||||
#----------------------------------------------------------------
|
||||
In() { cd "$1"; shift; "$@"; cd ..; }
|
||||
|
||||
In GooClass Failure "$javac" ${TESTTOOLVMOPTS} -cp ".." ../Main.java
|
||||
In GooClass Failure "$java" ${TESTVMOPTS} -cp ".." Main
|
||||
|
||||
# Unspecified classpath defaults to "."
|
||||
Sys mkdir OneDir; Sys cp Main.java GooClass/Lib.class OneDir/.
|
||||
In OneDir Success "$javac" ${TESTTOOLVMOPTS} Main.java
|
||||
In OneDir Success "$java" ${TESTVMOPTS} Main
|
||||
|
||||
# Empty classpath elements mean "."
|
||||
In GooClass Success "$javac" ${TESTTOOLVMOPTS} -cp "${PS}.." ../Main.java
|
||||
In GooClass Success "$java" ${TESTVMOPTS} -cp "${PS}.." Main
|
||||
|
||||
In GooClass Success "$javac" ${TESTTOOLVMOPTS} -cp "..${PS}" ../Main.java
|
||||
In GooClass Success "$java" ${TESTVMOPTS} -cp "..${PS}" Main
|
||||
|
||||
In GooClass Success "$javac" ${TESTTOOLVMOPTS} -cp "..${PS}${PS}/xyzzy" ../Main.java
|
||||
In GooClass Success "$java" ${TESTVMOPTS} -cp "..${PS}${PS}/xyzzy" Main
|
||||
|
||||
# All other empty path elements are ignored.
|
||||
In GooJar Failure "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} -extdirs "" -cp ".." ../Main.java
|
||||
|
||||
In GooJar Failure "$javac" -source 8 -targt 8 ${TESTTOOLVMOPTS} -extdirs "${PS}" -cp ".." ../Main.java
|
||||
In GooJar Failure "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} -Djava.ext.dirs="${PS}" -cp ".." ../Main.java
|
||||
|
||||
In GooJar Success "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} -extdirs "." -cp ".." ../Main.java
|
||||
In GooJar Success "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} -Djava.ext.dirs="." -cp ".." ../Main.java
|
||||
|
||||
In GooJar Failure "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} -Djava.endorsed.dirs="" -cp ".." ../Main.java
|
||||
|
||||
In GooJar Failure "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} -endorseddirs "${PS}" -cp ".." ../Main.java
|
||||
|
||||
In GooJar Success "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} -Djava.endorsed.dirs="." -cp ".." ../Main.java
|
||||
|
||||
In GooClass Failure "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} -Xbootclasspath/p: -cp ".." ../Main.java
|
||||
|
||||
In GooClass Success "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} -Xbootclasspath/p:. -cp ".." ../Main.java
|
||||
|
||||
In GooClass Failure "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} -Xbootclasspath:"../java-lang.jar" -cp ".." ../Main.java
|
||||
|
||||
In GooClass Success "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} -Xbootclasspath:"../java-lang.jar${PS}." -cp ".." ../Main.java
|
||||
|
||||
In GooClass Failure "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} -Xbootclasspath/a: -cp ".." ../Main.java
|
||||
In GooClass Failure "$java" ${TESTVMOPTS} -Xbootclasspath/a: -cp ".." Main
|
||||
|
||||
In GooClass Success "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} -Xbootclasspath/a:. -cp ".." ../Main.java
|
||||
In GooClass Success "$java" ${TESTVMOPTS} -Xbootclasspath/a:. -cp ".." Main
|
||||
|
||||
Cleanup
|
||||
|
||||
Bottom Line
|
560
test/langtools/tools/javac/Paths/Util.java
Normal file
560
test/langtools/tools/javac/Paths/Util.java
Normal file
@ -0,0 +1,560 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 2022, 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.
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.nio.file.DirectoryStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.spi.ToolProvider;
|
||||
|
||||
import toolbox.ToolBox;
|
||||
|
||||
/**
|
||||
* Utility methods for use by tests in the `Paths` directory.
|
||||
*/
|
||||
class Util {
|
||||
|
||||
ToolBox tb = new ToolBox();
|
||||
PrintStream out = tb.out;
|
||||
|
||||
Path javaHome = Path.of(System.getProperty("java.home"));
|
||||
String PS = File.pathSeparator;
|
||||
Path curDir = Path.of(".");
|
||||
|
||||
static final String JAR = "jar";
|
||||
static final String JAVA = "java";
|
||||
static final String JAVAC = "javac";
|
||||
static final String JIMAGE = "jimage";
|
||||
|
||||
/** The number of test-case failures. */
|
||||
int failCount = 0;
|
||||
/** The number of test-case passes. */
|
||||
int passCount = 0;
|
||||
/** A map recording how often each tool is executed in a separate process. */
|
||||
Map<String, Integer> execCounts = new TreeMap<>();
|
||||
/** A map recording how often each tool is invoked via its ToolProvider API. */
|
||||
Map<String, Integer> toolCounts = new TreeMap<>();
|
||||
|
||||
/**
|
||||
* Reports a summary of the overall test statistics, and throws an exception
|
||||
* if any test cases failed.
|
||||
*
|
||||
* @throws Exception if any test cases failed
|
||||
*/
|
||||
void bottomLine() throws Exception {
|
||||
out.println();
|
||||
out.println("-- Summary --");
|
||||
out.println("Passed: " + passCount);
|
||||
out.println("Failed: " + failCount);
|
||||
out.println("exec: " + execCounts);
|
||||
out.println("tool: " + toolCounts);
|
||||
|
||||
if (failCount > 0) {
|
||||
throw new Exception(failCount + " tests failed");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The result of executing a tool, either in a separate process, or via its ToolProvider API.
|
||||
*
|
||||
* @param exitCode the exit code from the tool: 0 for success
|
||||
* @param out the output from the tool
|
||||
*/
|
||||
record Result(int exitCode, String out) { }
|
||||
|
||||
/**
|
||||
* Executes a tool with given arguments and verifies that it passes.
|
||||
*
|
||||
* @param command the name of a JDK tool: java, javac or jar
|
||||
* @param args a string containing whitespace separated arguments
|
||||
* @throws Exception if there was an issue trying to execute the tool
|
||||
* @see #passCount
|
||||
* @see #failCount
|
||||
* @see #splitArgs(String)
|
||||
*/
|
||||
void expectPass(String command, String args) throws Exception {
|
||||
expectPass(null, null, command, splitArgs(args));
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a tool in a specific directory with given arguments and verifies that it passes.
|
||||
* In order to set the directory, the tool will be executed in a separate process.
|
||||
*
|
||||
* @param dir the directory
|
||||
* @param command the name of a JDK tool: java, javac or jar
|
||||
* @param args a string containing whitespace separated arguments
|
||||
* @throws Exception if there was an issue trying to execute the tool
|
||||
* @see #passCount
|
||||
* @see #failCount
|
||||
* @see #splitArgs(String)
|
||||
*/
|
||||
void expectPass(Path dir, String command, String args) throws Exception {
|
||||
expectPass(dir, null, command, splitArgs(args));
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a tool with additional env variables with given arguments and verifies that it passes.
|
||||
* In order to set the env variables, the tool will be executed in a separate process.
|
||||
* Note that any value of {@code CLASSPATH} inherited from this process will always be removed.
|
||||
*
|
||||
* @param env the additional env variables
|
||||
* @param command the name of a JDK tool: java, javac or jar
|
||||
* @param args a string containing whitespace separated arguments
|
||||
* @throws Exception if there was an issue trying to execute the tool
|
||||
* @see #passCount
|
||||
* @see #failCount
|
||||
* @see #splitArgs(String)
|
||||
*/
|
||||
void expectPass(Map<String, String> env, String command, String args) throws Exception {
|
||||
expectPass(null, env, command, splitArgs(args));
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a tool in a given directory with additional env variables with given arguments
|
||||
* and verifies that it passes.
|
||||
* In order to set any directory and env variables, the tool will be executed in a separate process.
|
||||
* Note that any value of {@code CLASSPATH} inherited from this process will always be removed.
|
||||
*
|
||||
* @param dir the directory, or {@code null}
|
||||
* @param env the additional env variables, or {@code null}
|
||||
* @param command the name of a JDK tool: java, javac or jar
|
||||
* @param args the arguments
|
||||
* @throws Exception if there was an issue trying to execute the tool
|
||||
* @see #passCount
|
||||
* @see #failCount
|
||||
*/
|
||||
void expectPass(Path dir, Map<String, String> env, String command, String... args) throws Exception {
|
||||
Result result = switch (command) {
|
||||
case JAR -> jar(args);
|
||||
case JAVAC -> javac(dir, env, args);
|
||||
case JAVA -> java(dir, env, args);
|
||||
default -> throw new Exception("unknown command: " + command);
|
||||
};
|
||||
|
||||
if (result.exitCode == 0) {
|
||||
out.println("PASS: test passed as expected");
|
||||
passCount++;
|
||||
} else {
|
||||
out.println("FAIL: test failed unexpectedly");
|
||||
failCount++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a tool with given arguments and verifies that it fails.
|
||||
*
|
||||
* @param command the name of a JDK tool: java, javac or jar
|
||||
* @param args a string containing whitespace separated arguments
|
||||
* @throws Exception if there was an issue trying to execute the tool
|
||||
* @see #passCount
|
||||
* @see #failCount
|
||||
* @see #splitArgs(String)
|
||||
*/
|
||||
void expectFail(String command, String args) throws Exception {
|
||||
expectFail(null, null, command, splitArgs(args));
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a tool in a specific directory with given arguments and verifies that it fails.
|
||||
* In order to set the directory, the tool will be executed in a separate process.
|
||||
*
|
||||
* @param dir the directory
|
||||
* @param command the name of a JDK tool: java, javac or jar
|
||||
* @param args a string containing whitespace separated arguments
|
||||
* @throws Exception if there was an issue trying to execute the tool
|
||||
* @see #passCount
|
||||
* @see #failCount
|
||||
* @see #splitArgs(String)
|
||||
*/
|
||||
void expectFail(Path dir, String command, String args) throws Exception {
|
||||
expectFail(dir, null, command, splitArgs(args));
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a tool with additional env variables with given arguments and verifies that it passes.
|
||||
* In order to set the env variables, the tool will be executed in a separate process.
|
||||
* Note that any value of {@code CLASSPATH} inherited from this process will always be removed.
|
||||
*
|
||||
* @param env the additional env variables
|
||||
* @param command the name of a JDK tool: java, javac or jar
|
||||
* @param args a string containing whitespace separated arguments
|
||||
* @throws Exception if there was an issue trying to execute the tool
|
||||
* @see #passCount
|
||||
* @see #failCount
|
||||
* @see #splitArgs(String)
|
||||
*/
|
||||
void expectFail(Map<String, String> env, String command, String args) throws Exception {
|
||||
expectFail(null, env, command, splitArgs(args));
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a tool in a given directory with additional env variables with given arguments
|
||||
* and verifies that it passes.
|
||||
* In order to set any directory and env variables, the tool will be executed in a separate process.
|
||||
* Note that any value of {@code CLASSPATH} inherited from this process will always be removed.
|
||||
*
|
||||
* @param dir the directory, or {@code null}
|
||||
* @param env the additional env variables, or {@code null}
|
||||
* @param command the name of a JDK tool: java, javac or jar
|
||||
* @param args the arguments
|
||||
* @throws Exception if there was an issue trying to execute the tool
|
||||
* @see #passCount
|
||||
* @see #failCount
|
||||
*/
|
||||
void expectFail(Path dir, Map<String, String> env, String command, String... args) throws Exception {
|
||||
Result result = switch (command) {
|
||||
case JAR -> jar(args);
|
||||
case JAVAC -> javac(dir, env, args);
|
||||
case JAVA -> java(dir, env, args);
|
||||
default -> throw new Exception("unknown command: " + command);
|
||||
};
|
||||
|
||||
if (result.exitCode == 0) {
|
||||
out.println("FAIL: test passed unexpectedly");
|
||||
failCount++;
|
||||
} else {
|
||||
out.println("PASS: failed as expected");
|
||||
passCount++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits a string into a list of strings that were separated by whitespace.
|
||||
* Leading and trailing whitespace is removed.
|
||||
* The character sequence {@code ${PS}} is replaced by the platform path separator.
|
||||
* Note, quotes are not supported, and so there is no support for embedded whitespace
|
||||
* or empty strings in the output.
|
||||
*
|
||||
* @param args a string of tokens separated by whitespace
|
||||
* @return an array of the tokens that were separated by whitespace
|
||||
*/
|
||||
String[] splitArgs(String args) {
|
||||
return args.trim()
|
||||
.replace("${PS}", PS)
|
||||
.split("\\s+");
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes {@code javac} using its ToolProvider API.
|
||||
*
|
||||
* @param args the arguments
|
||||
* @return an object containing the output and exit code from the tool
|
||||
* @throws Exception if there is an issue executing the tool
|
||||
*/
|
||||
Result javac(String... args) throws Exception {
|
||||
return runTool(JAVAC, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes {@code javac} in either a separate process or using its ToolProvider API.
|
||||
* The ToolProvider API is used if the directory and env parameters are {@code null},
|
||||
* and if the arguments definitely do not use "classpath wildcards", which are
|
||||
* only supported when the tool is invoked by the launcher.
|
||||
*
|
||||
* @param dir the directory, or {@code null}
|
||||
* @param env any additional environment variables, or {@code null}
|
||||
* @param args the arguments
|
||||
* @return an object containing the output and exit code from the tool
|
||||
* @throws Exception if there is an issue executing the tool
|
||||
*/
|
||||
Result javac(Path dir, Map<String, String> env, String... args) throws Exception {
|
||||
return (env != null || dir != null || hasWildcardClassPath(args))
|
||||
? execTool(dir, env, JAVAC, args)
|
||||
: runTool(JAVAC, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return true if the arguments may contain a classpath option using a "classpath wildcard"}
|
||||
*
|
||||
* The result is {@code true} if there is any form of a classpath option whose value contains {@code *}.
|
||||
* Note: this may include "false positives", where the {@code *} is not at the end of
|
||||
* any element in the path, such as when the character is part of the filename.
|
||||
* However, in context, the approximation is safe, and just means that we may sometimes
|
||||
* execute javac in a separate process when it would be sufficient to use its ToolProvider API.
|
||||
*
|
||||
* A more refined implementation could split apart the path elements and looking for
|
||||
* an element that is {@code *} or which ends in {@code *}.
|
||||
*
|
||||
* @param args the arguments to be checked
|
||||
*/
|
||||
private boolean hasWildcardClassPath(String... args) {
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
String arg = args[i];
|
||||
switch (arg) {
|
||||
case "-classpath", "--class-path", "-cp" -> {
|
||||
if (i + 1 < args.length && args[i + 1].contains("*")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
default -> {
|
||||
if (arg.startsWith("--class-path=") && arg.contains("*")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes {@code jar} using its ToolProvider API.
|
||||
*
|
||||
* @param args the arguments
|
||||
* @return an object containing the output and exit code from the tool
|
||||
* @throws Exception if there is an issue executing the tool
|
||||
*/
|
||||
Result jar(String... args) throws Exception {
|
||||
return runTool(JAR, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes {@code jimage} using its ToolProvider API.
|
||||
*
|
||||
* @param args the arguments
|
||||
* @return an object containing the output and exit code from the tool
|
||||
* @throws Exception if there is an issue executing the tool
|
||||
*/
|
||||
Result jimage(String... args) throws Exception {
|
||||
return execTool(null, null, JIMAGE, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes {@code java} in a separate process.
|
||||
*
|
||||
* @param dir the directory, or {@code null}
|
||||
* @param env any additional environment variables, or {@code null}
|
||||
* @param args the arguments
|
||||
* @return an object containing the output and exit code from the launcher
|
||||
* @throws Exception if there is an issue executing the tool
|
||||
*/
|
||||
Result java(Path dir, Map<String, String> env, String... args) throws Exception {
|
||||
return execTool(dir, env, JAVA, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a tool using its ToolProvider API.
|
||||
*
|
||||
* @param args the arguments
|
||||
* @return an object containing the output and exit code from the launcher
|
||||
* @throws Exception if there is an issue executing the tool
|
||||
*/
|
||||
Result runTool(String name, String... args) throws Exception {
|
||||
out.println(name + ": " + String.join(" ", args));
|
||||
var tool = ToolProvider.findFirst(name)
|
||||
.orElseThrow(() -> new Exception("cannot find " + name));
|
||||
try (StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw)) {
|
||||
int rc = tool.run(pw, pw, args);
|
||||
pw.flush();
|
||||
String output = sw.toString();
|
||||
output.lines()
|
||||
.forEach(l -> out.println(name + ": " + l));
|
||||
if (rc != 0) {
|
||||
out.println(name + ": exit code " + rc);
|
||||
}
|
||||
toolCounts.put(name, toolCounts.computeIfAbsent(name, n -> 0) + 1);
|
||||
return new Result(rc, output);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a tool in a separate process.
|
||||
*
|
||||
* Note that any value of {@code CLASSPATH} inherited from this process will always be removed.
|
||||
*
|
||||
* @param dir the directory, or {@code null}
|
||||
* @param env any additional environment variables, or {@code null}
|
||||
* @param args the arguments
|
||||
* @return an object containing the output and exit code from the launcher
|
||||
* @throws Exception if there is an issue executing the tool
|
||||
*/
|
||||
Result execTool(Path dir, Map<String, String> env, String name, String... args) throws Exception {
|
||||
out.print(name + ":");
|
||||
if (env != null) {
|
||||
out.print(" " + env);
|
||||
}
|
||||
if (dir != null) {
|
||||
out.print(" (" + dir + ")");
|
||||
}
|
||||
out.println(" " + String.join(" ", args));
|
||||
|
||||
Path tool = javaHome.resolve("bin").resolve(name + (ToolBox.isWindows() ? ".exe" : ""));
|
||||
if (!Files.exists(tool)) {
|
||||
throw new Exception("cannot find " + name);
|
||||
}
|
||||
var cmd = new ArrayList<String>();
|
||||
cmd.add(tool.toString());
|
||||
cmd.addAll(List.of(args));
|
||||
ProcessBuilder pb = new ProcessBuilder(cmd)
|
||||
.redirectErrorStream(true);
|
||||
pb.environment().remove("CLASSPATH"); // always remove default value set by jtreg
|
||||
if (env != null) {
|
||||
pb.environment().putAll(env);
|
||||
}
|
||||
if (dir != null) {
|
||||
pb.directory(dir.toFile());
|
||||
}
|
||||
Process p = pb.start();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
try (var in = p.inputReader()) {
|
||||
in.lines().forEach(l -> {
|
||||
sb.append(l).append("\n");
|
||||
out.println(name + ": " + l);
|
||||
});
|
||||
}
|
||||
p.waitFor();
|
||||
int rc = p.exitValue();
|
||||
if (rc != 0) {
|
||||
out.println(name + ": exit code " + rc);
|
||||
}
|
||||
execCounts.put(name, execCounts.computeIfAbsent(name, n -> 0) + 1);
|
||||
return new Result(rc, sb.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that a series of files exist and are readable.
|
||||
*
|
||||
* @param paths the files
|
||||
* @throws Exception if any of the files are not found or are not readable
|
||||
*/
|
||||
void checkFiles(String... paths) throws Exception {
|
||||
for (String p : paths) {
|
||||
Path path = Path.of(p);
|
||||
if (!Files.isReadable(path) ) {
|
||||
throw new Exception("file not found: " + path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* List the files in a directory that match a "glob" pattern.
|
||||
*
|
||||
* @param dir the directory
|
||||
* @param glob the pattern
|
||||
* @return the list of files
|
||||
* @throws IOException if there is a problem listing the contents of the directory
|
||||
*/
|
||||
List<Path> listFiles(Path dir, String glob) throws IOException {
|
||||
var files = new ArrayList<Path>();
|
||||
try (DirectoryStream<Path> ds = Files.newDirectoryStream(dir, glob)) {
|
||||
for (Path p : ds) {
|
||||
files.add(p);
|
||||
}
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a series of files.
|
||||
* The files are deleted using {@link ToolBox#cleanDirectory(Path)} and
|
||||
* {@code ToolBox#deleteFiles}, which together try hard to delete the files,
|
||||
* even on Windows.
|
||||
*
|
||||
* @param paths the paths
|
||||
* @throws IOException if there is a problem deleting any of the files
|
||||
* @see #deleteFiles(List)
|
||||
*/
|
||||
void deleteFiles(String... paths) throws IOException {
|
||||
deleteFiles(Arrays.stream(paths)
|
||||
.map(Path::of)
|
||||
.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a series of files.
|
||||
* The files are deleted using {@link ToolBox#cleanDirectory(Path)} and
|
||||
* {@code ToolBox#deleteFiles}, which together try hard to delete the files,
|
||||
* even on Windows.
|
||||
*
|
||||
* @param paths the paths
|
||||
* @throws IOException if there is a problem deleting any of the files
|
||||
*/
|
||||
void deleteFiles(List<Path> paths) throws IOException {
|
||||
for (Path path : paths) {
|
||||
if (Files.exists(path)) {
|
||||
if (Files.isDirectory(path)) {
|
||||
tb.cleanDirectory(path);
|
||||
}
|
||||
tb.deleteFiles(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves a series of files into a given directory.
|
||||
*
|
||||
* @param files the files
|
||||
* @param dir the target directory
|
||||
* @throws IOException if there is a problem moving any of the files
|
||||
*/
|
||||
void moveFiles(List<Path> files, Path dir) throws IOException {
|
||||
for (Path p : files) {
|
||||
tb.moveFile(p, dir);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves a series of files into a given directory.
|
||||
*
|
||||
* @param files the files
|
||||
* @param dir the target directory
|
||||
* @throws IOException if there is a problem moving any of the files
|
||||
*/
|
||||
void moveFiles(List<String> files, String dir) throws IOException {
|
||||
for (String p : files) {
|
||||
tb.moveFile(p, dir);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return a map containing a setting for the {@code CLASSPATH} env variable}
|
||||
*
|
||||
* @param classpath the value for the env variable
|
||||
*/
|
||||
Map<String, String> classpath(String classpath) {
|
||||
return Map.of("CLASSPATH", classpath.replace("${PS}", PS));
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a file called {@code MANIFEST.MF} containing a given value for
|
||||
* the {@code Class-Path} entry.
|
||||
*
|
||||
* @param path the value for the {@code Class-Path} entry
|
||||
* @throws IOException if there is a problem writing the file
|
||||
*/
|
||||
void makeManifestWithClassPath(String path) throws IOException {
|
||||
Files.writeString(Path.of("MANIFEST.MF"),
|
||||
"Manifest-Version: 1.0\n"
|
||||
+ "Class-Path: " + path + "\n");
|
||||
}
|
||||
|
||||
}
|
@ -1,115 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2003, 2022, 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.
|
||||
#
|
||||
|
||||
# Utilities for shell tests
|
||||
|
||||
: ${TESTSRC=.} ${TESTCLASSES=.}
|
||||
java="${TESTJAVA+${TESTJAVA}/bin/}java${EXE_SUFFIX}"
|
||||
javac="${TESTJAVA+${TESTJAVA}/bin/}javac${EXE_SUFFIX}"
|
||||
jar="${TESTJAVA+${TESTJAVA}/bin/}jar${EXE_SUFFIX}"
|
||||
jimage="${TESTJAVA+${TESTJAVA}/bin/}jimage${EXE_SUFFIX}"
|
||||
|
||||
case `uname -s` in
|
||||
Windows*|CYGWIN*|MSYS*|MINGW*)
|
||||
WindowsOnly() { "$@"; }
|
||||
UnixOnly() { :; }
|
||||
PS=";" ;;
|
||||
*)
|
||||
UnixOnly() { "$@"; }
|
||||
WindowsOnly() { :; }
|
||||
PS=":";;
|
||||
esac
|
||||
|
||||
failed=""
|
||||
Fail() { echo "FAIL: $1"; failed="${failed}."; }
|
||||
|
||||
Die() { printf "%s\n" "$*"; exit 1; }
|
||||
|
||||
Sys() {
|
||||
printf "%s\n" "$*"; "$@"; rc="$?";
|
||||
test "$rc" -eq 0 || Die "Command \"$*\" failed with exitValue $rc";
|
||||
}
|
||||
|
||||
CheckFiles() {
|
||||
for f in "$@"; do test -r "$f" || Die "File $f not found"; done
|
||||
}
|
||||
|
||||
Report() {
|
||||
test "$#" != 2 && Die "Usage: Report success|failure rc"
|
||||
|
||||
if test "$1" = "success" -a "$2" = 0; then
|
||||
echo "PASS: succeeded as expected"
|
||||
elif test "$1" = "failure" -a "$2" != 0; then
|
||||
echo "PASS: failed as expected"
|
||||
elif test "$1" = "success" -a "$2" != 0; then
|
||||
Fail "test failed unexpectedly"
|
||||
elif test "$1" = "failure" -a "$2" = 0; then
|
||||
Fail "test succeeded unexpectedly"
|
||||
else
|
||||
Die "Usage: Report success|failure rc"
|
||||
fi
|
||||
}
|
||||
|
||||
MkManifestWithClassPath() {
|
||||
(echo "Manifest-Version: 1.0"; echo "Class-Path: $*") > MANIFEST.MF
|
||||
}
|
||||
|
||||
HorizontalRule() {
|
||||
echo "-----------------------------------------------------------------"
|
||||
}
|
||||
|
||||
Test() {
|
||||
HorizontalRule
|
||||
expectedResult="$1"; shift
|
||||
printf "%s\n" "$*"
|
||||
"$@"
|
||||
Report "$expectedResult" "$?"
|
||||
}
|
||||
|
||||
Failure() { Test failure "$@"; }
|
||||
Success() { Test success "$@"; }
|
||||
|
||||
Bottom() {
|
||||
test "$#" = 1 -a "$1" = "Line" || Die "Usage: Bottom Line"
|
||||
|
||||
if test -n "$failed"; then
|
||||
count=`printf "%s" "$failed" | wc -c | tr -d ' '`
|
||||
echo "FAIL: $count tests failed"
|
||||
exit 1
|
||||
else
|
||||
echo "PASS: all tests gave expected results"
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
BadJarFile() {
|
||||
for jarfilename in "$@"; do pwd > "$jarfilename"; done
|
||||
}
|
||||
|
||||
|
||||
#----------------------------------------------------------------
|
||||
# Foil message localization
|
||||
#----------------------------------------------------------------
|
||||
DiagnosticsInEnglishPlease() {
|
||||
LANG="C" LC_ALL="C" LC_MESSAGES="C"; export LANG LC_ALL LC_MESSAGES
|
||||
}
|
340
test/langtools/tools/javac/Paths/WildcardMineField.java
Normal file
340
test/langtools/tools/javac/Paths/WildcardMineField.java
Normal file
@ -0,0 +1,340 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2022, 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 6268383 8172309 8293877
|
||||
* @summary Test classpath wildcards for javac and java -classpath option.
|
||||
* @library /tools/lib
|
||||
* @build toolbox.ToolBox Util WildcardMineField
|
||||
* @run main WildcardMineField
|
||||
*/
|
||||
|
||||
/*
|
||||
* Converted from wcMineField.sh, originally written by Martin Buchholz.
|
||||
*
|
||||
* For the last version of the original, wcMineField.sh, see
|
||||
* https://github.com/openjdk/jdk/blob/jdk-19%2B36/test/langtools/tools/javac/Paths/wcMineField.sh
|
||||
*
|
||||
* This class primarily tests support for "classpath wildcards", which is a feature
|
||||
* by which elements of a classpath option ending in {@code *} are expanded into
|
||||
* the set of jar files found in the directory preceding the {@code *}.
|
||||
*
|
||||
* Note that this feature is only implemented in the launcher, even for javac,
|
||||
* and so is only available when running javac via its launcher, in a separate process.
|
||||
*
|
||||
* Note that this feature does not affect the use of {@code *} elsewhere in any path,
|
||||
* classpath or otherwise, and so this class also tests the use of {@code *} and other special
|
||||
* characters (like {@code ,} and {@code ;}) in filenames. Some of these tests,
|
||||
* labelled in the original code as "UnixOnly", do not apply to Windows.
|
||||
*
|
||||
* For information on the launcher support for the {@code -classpath} option,
|
||||
* see the java man page. As of September 2022, there is no equivalent documentation
|
||||
* for javac, except to say that the support is only in the native launcher for javac,
|
||||
* and not in the main javac source code.
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import toolbox.ToolBox;
|
||||
|
||||
public class WildcardMineField extends Util {
|
||||
public static void main(String... args) throws Exception {
|
||||
new WildcardMineField().run(args);
|
||||
}
|
||||
|
||||
void run(String... args) throws Exception {
|
||||
setup();
|
||||
tests();
|
||||
cleanup();
|
||||
bottomLine();
|
||||
}
|
||||
|
||||
void setup() throws Exception {
|
||||
cleanup();
|
||||
tb.createDirectories("GooSrc", "GooJar", "GooZip", "GooClass", "GooJar/SubDir");
|
||||
tb.createDirectories("BadSrc", "BadJar", "BadZip", "BadClass");
|
||||
tb.createDirectories("SpeSrc", "SpeJar", "SpeZip", "SpeClass");
|
||||
tb.createDirectories("JarNClass", "StarJar", "MixJar");
|
||||
Files.writeString(Path.of("Lib.java"), "public class Lib {public static void f(){}}");
|
||||
Files.writeString(Path.of("Lib2.java"), "public class Lib2 {public static void g(){}}");
|
||||
Files.writeString(Path.of("Lib3.java"), "public class Lib3 {public static void h(){}}");
|
||||
javac("Lib.java", "Lib2.java", "Lib3.java");
|
||||
tb.copyFile("Lib.class", "JarNClass/.");
|
||||
jar("cf", "GooJar/Lib.jar", "Lib.class");
|
||||
jar("cf", "GooJar/SubDir/Lib2.jar", "Lib2.class");
|
||||
jar("cf", "JarNClass/Lib.jar", "Lib.class");
|
||||
|
||||
jar("cf", "GooZip/Lib.zip", "Lib.class");
|
||||
tb.moveFile("Lib.class", "GooClass/.");
|
||||
tb.moveFile("Lib2.class", "GooClass/.");
|
||||
tb.moveFile("Lib3.class", "GooClass/.");
|
||||
tb.moveFile("Lib.java", "GooSrc/.");
|
||||
tb.moveFile("Lib2.java", "GooSrc/.");
|
||||
tb.moveFile("Lib3.java", "GooSrc/.");
|
||||
|
||||
checkFiles("GooZip/Lib.zip", "GooJar/Lib.jar", "GooSrc/Lib.java");
|
||||
checkFiles("GooSrc/Lib2.java", "GooSrc/Lib3.java", "GooJar/SubDir/Lib2.jar");
|
||||
|
||||
Files.writeString(Path.of("Spe1.java"), "public class Spe1 {public static void f(){}}");
|
||||
Files.writeString(Path.of("Spe2.java"), "public class Spe2 {public static void f(){}}");
|
||||
Files.writeString(Path.of("Spe3.java"), "public class Spe3 {public static void f(){}}");
|
||||
Files.writeString(Path.of("Spe4.java"), "public class Spe4 {public static void f(){}}");
|
||||
javac("Spe1.java", "Spe2.java", "Spe3.java", "Spe4.java");
|
||||
|
||||
if (!ToolBox.isWindows()) {
|
||||
jar("cf", "SpeJar/Spe:Colon.jar", "Spe1.class");
|
||||
jar("cf", "SpeJar/Spe*wc.jar", "Spe4.class");
|
||||
checkFiles("SpeJar/Spe*wc.jar");
|
||||
|
||||
jar("cf", "StarJar/*jar.jar", "Spe2.class");
|
||||
jar("cf", "StarJar/jar*.jar", "Spe3.class");
|
||||
jar("cf", "StarJar/*jar*.jar", "Spe4.class");
|
||||
checkFiles("StarJar/*jar.jar", "StarJar/jar*.jar", "StarJar/*jar*.jar");
|
||||
}
|
||||
|
||||
jar("cf", "SpeJar/Spe,Comma.jar", "Spe2.class");
|
||||
jar("cf", "SpeJar/Spe;Semi.jar", "Spe3.class");
|
||||
|
||||
jar("cf", "MixJar/mix.jAr", "Spe1.class");
|
||||
jar("cf", "MixJar/mix2.JAR", "Spe2.class");
|
||||
jar("cf", "MixJar/mix3.zip", "Spe3.class");
|
||||
jar("cf", "MixJar/.hiddenjar.jar", "Spe4.class");
|
||||
|
||||
moveFiles(listFiles(curDir, "Spe*.class"), Path.of("SpeClass/."));
|
||||
moveFiles(listFiles(curDir, "Spe*.java"), Path.of("SpeSrc/."));
|
||||
checkFiles("SpeJar/Spe,Comma.jar", "SpeJar/Spe;Semi.jar", "SpeSrc/Spe2.java", "SpeSrc/Spe3." +
|
||||
"java", "SpeSrc/Spe4.java");
|
||||
checkFiles("MixJar/mix.jAr", "MixJar/mix2.JAR", "MixJar/mix3.zip", "MixJar/.hiddenjar.jar");
|
||||
|
||||
Files.writeString(Path.of("Main.java"), "public class Main {public static void main(String[] a) {Lib.f();}}");
|
||||
Files.writeString(Path.of("Main1.java"), "public class Main1 {public static void main(String[] a) {Lib2.g();}}");
|
||||
Files.writeString(Path.of("Main1b.java"), "public class Main1b {public static void main(String[] a) {Spe1.f();}}");
|
||||
Files.writeString(Path.of("Main2.java"), "public class Main2 {public static void main(String[] a) {Spe2.f();}}");
|
||||
Files.writeString(Path.of("Main3.java"), "public class Main3 {public static void main(String[] a) {Spe3.f();}}");
|
||||
Files.writeString(Path.of("Main4.java"), "public class Main4 {public static void main(String[] a) {Spe4.f();}}");
|
||||
Files.writeString(Path.of("Main5.java"), "public class Main5 {public static void main(String[] a) {Spe2.f(); Lib.f();}}");
|
||||
Files.writeString(Path.of("Main6.java"), "public class Main6 {public static void main(String[] a) {Lib3.h();}}");
|
||||
}
|
||||
|
||||
void cleanup() throws IOException {
|
||||
deleteFiles("GooSrc", "GooJar", "GooZip", "GooClass");
|
||||
deleteFiles("SpeSrc", "SpeJar", "SpeZip", "SpeClass");
|
||||
deleteFiles("BadSrc", "BadJar", "BadZip", "BadClass");
|
||||
deleteFiles("JarNClass", "StarJar", "MixJar", "StarDir");
|
||||
deleteFiles("OneDir", "MANIFEST.MF");
|
||||
deleteFiles(listFiles(curDir, "*.class"));
|
||||
deleteFiles(listFiles(curDir, "Main*.java"));
|
||||
}
|
||||
|
||||
void tests() throws Exception {
|
||||
if (!ToolBox.isWindows()) {
|
||||
starDirTests();
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
* Verify the basic jar file works
|
||||
*----------------------------------------------------------------*/
|
||||
|
||||
// baseline test to verify it works.
|
||||
expectPass(JAVAC, "-cp GooJar/Lib.jar Main.java");
|
||||
expectPass(JAVAC, "-classpath GooJar/Lib.jar Main.java");
|
||||
expectPass(JAVA, "-classpath GooJar/Lib.jar${PS}. Main");
|
||||
expectPass(JAVA, "-cp GooJar/Lib.jar${PS}. Main");
|
||||
|
||||
// basic test of one jar to be loaded
|
||||
if (!ToolBox.isWindows()) {
|
||||
expectPass(JAVAC, "-classpath GooJar/* Main.java");
|
||||
}
|
||||
expectPass(JAVAC, "-classpath GooJar/*${PS}. Main.java");
|
||||
expectPass(JAVA, "-classpath GooJar/*${PS}. Main");
|
||||
|
||||
// in a subdir. First * should not load jars in subdirectories unless specified
|
||||
expectFail(JAVAC, "-classpath GooJar/* Main1.java");
|
||||
expectFail(JAVAC, " -classpath GooJar/*${PS}. Main1.java");
|
||||
expectPass(JAVAC, "-cp GooJar/SubDir/* Main1.java");
|
||||
expectPass(JAVAC, "-classpath GooJar/SubDir/* Main1.java");
|
||||
expectPass(JAVAC, "--class-path GooJar/SubDir/* Main1.java");
|
||||
expectPass(JAVAC, "--class-path=GooJar/SubDir/* Main1.java");
|
||||
|
||||
// Same with launcher. Should not load jar in subdirectories unless specified
|
||||
expectFail(JAVA, "-classpath GooJar/*${PS}. Main1");
|
||||
expectPass(JAVA, "-classpath GooJar/SubDir/*${PS}. Main1");
|
||||
expectPass(JAVA, "-cp GooJar/SubDir/*${PS}. Main1");
|
||||
|
||||
expectPass(classpath("GooJar/SubDir/*"), JAVAC, "Main1.java");
|
||||
expectPass(classpath("GooJar/SubDir/*${PS}."), JAVA, "Main1");
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
* Verify the jar files in 2 directories
|
||||
*----------------------------------------------------------------*/
|
||||
|
||||
expectPass(JAVAC, "-classpath GooJar/Lib.jar${PS}SpeJar/Spe,Comma.jar Main5.java");
|
||||
expectPass(JAVA, "-classpath GooJar/Lib.jar${PS}SpeJar/Spe,Comma.jar${PS}. Main5");
|
||||
|
||||
expectPass(JAVAC, "-classpath GooJar/*${PS}SpeJar/* Main5.java");
|
||||
expectPass(JAVA, "-classpath GooJar/*${PS}SpeJar/*${PS}. Main5");
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
* Verify jar file and class file in same directory.
|
||||
*----------------------------------------------------------------*/
|
||||
|
||||
expectPass(JAVAC, "-classpath JarNClass/*${PS} Main.java");
|
||||
expectPass(JAVA, "-classpath JarNClass/*${PS}. Main");
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
* Verify these odd jar files work explicitly on classpath, kind of
|
||||
* a baseline. Last one is also a test with * in a jar name.
|
||||
*----------------------------------------------------------------*/
|
||||
|
||||
expectFail(JAVAC, "-classpath SpeJar/Spe:Colon.jar Main1.java");
|
||||
|
||||
expectPass(JAVAC, "-classpath SpeJar/Spe,Comma.jar Main2.java");
|
||||
expectPass(JAVA, "-classpath SpeJar/Spe,Comma.jar${PS}. Main2");
|
||||
|
||||
if (!ToolBox.isWindows()) {
|
||||
expectPass(JAVAC, "-classpath SpeJar/Spe;Semi.jar Main3.java");
|
||||
expectPass(JAVA, "-classpath SpeJar/Spe;Semi.jar${PS}. Main3");
|
||||
|
||||
expectPass(JAVAC, "-classpath SpeJar/Spe*wc.jar Main4.java");
|
||||
expectPass(JAVA, "-classpath SpeJar/Spe*wc.jar${PS}. Main4");
|
||||
}
|
||||
|
||||
if (!ToolBox.isWindows()) {
|
||||
speJar();
|
||||
}
|
||||
|
||||
if (!ToolBox.isWindows()) {
|
||||
starJar();
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
* Verify these jar files with varying extensions
|
||||
*----------------------------------------------------------------*/
|
||||
|
||||
// Mixed case extensions should not be loaded.
|
||||
expectFail(JAVAC, "-classpath MixJar/* Main1b.java");
|
||||
expectPass(JAVAC, "-classpath MixJar/mix.jAr Main1b.java");
|
||||
expectFail(JAVAC, "-classpath MixJar/* Main1b");
|
||||
|
||||
// upper case, .JAR, extension should be loaded
|
||||
if (!ToolBox.isWindows()) {
|
||||
expectPass(JAVAC, "-classpath MixJar/* Main2.java");
|
||||
}
|
||||
expectPass(JAVAC, "-classpath .${PS}MixJar/* Main2.java");
|
||||
|
||||
expectPass(JAVA, "-classpath MixJar/*${PS}. Main2");
|
||||
|
||||
// zip extensions should not be loaded
|
||||
expectFail(JAVAC, "-classpath MixJar/* Main3.java");
|
||||
expectPass(JAVAC, "-classpath MixJar/mix3.zip Main3.java");
|
||||
expectFail(JAVA, "-classpath MixJar/*${PS}. Main3");
|
||||
|
||||
// unix "hidden" file
|
||||
if (!ToolBox.isWindows()) {
|
||||
expectPass(JAVAC, "-classpath MixJar/* Main4.java");
|
||||
expectPass(JAVA, "-classpath MixJar/*${PS}. Main4");
|
||||
}
|
||||
}
|
||||
|
||||
void starDirTests() throws Exception {
|
||||
out.println("Running tests with directory named \"*\"");
|
||||
deleteFiles("./StarDir");
|
||||
tb.createDirectories("StarDir/*");
|
||||
tb.copyFile("GooClass/Lib2.class", "StarDir/*/Lib2.class");
|
||||
jar("cf", "StarDir/Lib3.jar", "-C", "GooClass", "Lib3.class");
|
||||
jar("cf", "StarDir/*/Lib.jar", "-C", "GooClass", "Lib.class");
|
||||
checkFiles("StarDir/*/Lib.jar", "StarDir/*/Lib2.class", "StarDir/Lib3.jar");
|
||||
tb.copyFile("Main6.java", "./StarDir/.");
|
||||
tb.copyFile("Main.java", "./StarDir/*/.");
|
||||
tb.copyFile("Main1.java", "./StarDir/*/.");
|
||||
Path StarDir = Path.of("StarDir");
|
||||
expectFail(StarDir, JAVAC, "-classpath * Main6.java");
|
||||
expectFail(StarDir, JAVAC, "-classpath ./* Main6.java");
|
||||
deleteFiles(listFiles(StarDir, "Main6.*"));
|
||||
Path StarDir_star = StarDir.resolve("*");
|
||||
expectPass(StarDir_star, JAVAC, "-classpath * Main.java");
|
||||
expectPass(StarDir_star, JAVA, "-classpath .${PS}* Main");
|
||||
expectPass(StarDir_star, JAVAC, "Main1.java");
|
||||
expectPass(StarDir_star, JAVA, "-classpath . Main1");
|
||||
|
||||
expectFail(JAVAC, "-classpath StarDir/* Main6.java");
|
||||
|
||||
expectPass(JAVAC, "-classpath StarDir/* Main1.java");
|
||||
expectPass(JAVA, "-classpath StarDir/*:. Main1");
|
||||
|
||||
expectPass(JAVAC, "-classpath StarDir/* Main1.java");
|
||||
expectPass(JAVA, "-classpath .${PS}StarDir/* Main1");
|
||||
|
||||
expectFail(JAVAC, "-classpath StarDir/\\*/* Main.java");
|
||||
expectPass(JAVAC, "-classpath StarDir/*/* Main.java");
|
||||
|
||||
expectPass(JAVA, "-classpath .${PS}StarDir/*/* Main");
|
||||
expectFail(JAVA, "-classpath .${PS}StarDir/\\*/* Main");
|
||||
|
||||
expectPass(JAVAC, "-classpath StarDir/Lib3.jar Main6.java");
|
||||
expectPass(JAVA, "-classpath .${PS}StarDir/Lib3.jar Main6");
|
||||
|
||||
expectPass(JAVAC, "-classpath StarDir/*/Lib.jar Main.java");
|
||||
expectPass(JAVA, "-classpath .${PS}StarDir/*/Lib.jar Main");
|
||||
}
|
||||
|
||||
void speJar() throws Exception {
|
||||
out.println("Running tests with jar file names containing special characters");
|
||||
|
||||
expectPass(JAVAC, "-classpath SpeJar/* Main2.java");
|
||||
expectPass(JAVA, "-classpath SpeJar/*${PS}. Main2");
|
||||
|
||||
expectPass(JAVAC, "-classpath SpeJar/* Main3.java");
|
||||
expectPass(JAVA, "-classpath SpeJar/*${PS}. Main3");
|
||||
|
||||
expectPass(JAVAC, "-classpath SpeJar/* Main4.java");
|
||||
expectPass(JAVA, "-classpath SpeJar/*${PS}. Main4");
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
* Verify these jar files with asterisk in jar file name
|
||||
*----------------------------------------------------------------*/
|
||||
void starJar() throws Exception {
|
||||
out.println("Running tests with jar file names containing \"*\"");
|
||||
expectPass(JAVAC, "-classpath StarJar/*jar.jar Main2.java");
|
||||
expectPass(JAVA, "-classpath StarJar/*jar.jar${PS}. Main2");
|
||||
|
||||
expectPass(JAVAC, "-classpath StarJar/jar*.jar Main3.java");
|
||||
expectPass(JAVA, "-classpath StarJar/jar*.jar${PS}. Main3");
|
||||
|
||||
expectPass(JAVAC, "-classpath StarJar/*jar*.jar Main4.java");
|
||||
expectPass(JAVA, "-classpath StarJar/*jar*.jar${PS}. Main4");
|
||||
|
||||
expectPass(JAVAC, "-classpath StarJar/* Main2.java");
|
||||
expectPass(JAVA, "-classpath StarJar/*${PS}. Main2");
|
||||
|
||||
expectPass(JAVAC, "-classpath StarJar/* Main3.java");
|
||||
expectPass(JAVA, "-classpath StarJar/*${PS}. Main3");
|
||||
|
||||
expectPass(JAVAC, "-classpath StarJar/* Main4.java");
|
||||
expectPass(JAVA, "-classpath StarJar/*${PS}. Main4");
|
||||
}
|
||||
}
|
@ -1,296 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright (c) 2005, 2015, 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
|
||||
# @summary Test classpath wildcards for javac and java -classpath option.
|
||||
# @bug 6268383 8172309
|
||||
# @run shell/timeout=600 wcMineField.sh
|
||||
|
||||
# To run this test manually, simply do ./wcMineField.sh
|
||||
#----------------------------------------------------------------
|
||||
|
||||
. ${TESTSRC-.}/Util.sh
|
||||
|
||||
set -u
|
||||
|
||||
#----------------------------------------------------------------
|
||||
# Note that, on Windows only, the launcher also includes another
|
||||
# kind of command-line wildcard expansion, via setargv.obj
|
||||
# http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccelng/htm/progs_11.asp
|
||||
# Therefore, on Windows, -classpath "foo/*" is treated differently
|
||||
# from -classpath ".${PS}foo/*"
|
||||
#----------------------------------------------------------------
|
||||
|
||||
#----------------------------------------------------------------
|
||||
# Prepare the "Minefield"
|
||||
#----------------------------------------------------------------
|
||||
Cleanup() {
|
||||
Sys rm -rf GooSrc GooJar GooZip GooClass
|
||||
Sys rm -rf SpeSrc SpeJar SpeZip SpeClass
|
||||
Sys rm -rf BadSrc BadJar BadZip BadClass
|
||||
Sys rm -rf JarNClass StarJar MixJar StarDir
|
||||
Sys rm -rf OneDir *.class Main*.java MANIFEST.MF
|
||||
}
|
||||
|
||||
Cleanup
|
||||
Sys mkdir GooSrc GooJar GooZip GooClass GooJar/SubDir
|
||||
Sys mkdir BadSrc BadJar BadZip BadClass
|
||||
Sys mkdir SpeSrc SpeJar SpeZip SpeClass
|
||||
Sys mkdir JarNClass StarJar MixJar
|
||||
echo 'public class Lib {public static void f(){}}' > Lib.java
|
||||
echo 'public class Lib2 {public static void g(){}}' > Lib2.java
|
||||
echo 'public class Lib3 {public static void h(){}}' > Lib3.java
|
||||
Sys "$javac" ${TESTTOOLVMOPTS} Lib.java Lib2.java Lib3.java
|
||||
Sys cp Lib.class JarNClass/.
|
||||
Sys "$jar" cf GooJar/Lib.jar Lib.class
|
||||
Sys "$jar" cf GooJar/SubDir/Lib2.jar Lib2.class
|
||||
Sys "$jar" cf JarNClass/Lib.jar Lib.class
|
||||
|
||||
Sys "$jar" cf GooZip/Lib.zip Lib.class
|
||||
Sys mv Lib.class GooClass/.
|
||||
Sys mv Lib2.class GooClass/.
|
||||
Sys mv Lib3.class GooClass/.
|
||||
Sys mv Lib.java GooSrc/.
|
||||
Sys mv Lib2.java GooSrc/.
|
||||
Sys mv Lib3.java GooSrc
|
||||
CheckFiles GooZip/Lib.zip GooJar/Lib.jar GooSrc/Lib.java
|
||||
CheckFiles GooSrc/Lib2.java GooSrc/Lib3.java GooJar/SubDir/Lib2.jar
|
||||
|
||||
echo 'public class Spe1 {public static void f(){}}' > Spe1.java
|
||||
echo 'public class Spe2 {public static void f(){}}' > Spe2.java
|
||||
echo 'public class Spe3 {public static void f(){}}' > Spe3.java
|
||||
echo 'public class Spe4 {public static void f(){}}' > Spe4.java
|
||||
Sys "$javac" ${TESTTOOLVMOPTS} Spe1.java
|
||||
Sys "$javac" ${TESTTOOLVMOPTS} Spe2.java
|
||||
Sys "$javac" ${TESTTOOLVMOPTS} Spe3.java
|
||||
Sys "$javac" ${TESTTOOLVMOPTS} Spe4.java
|
||||
|
||||
UnixOnly Sys "$jar" cf "SpeJar/Spe:Colon.jar" Spe1.class
|
||||
UnixOnly Sys "$jar" cf "SpeJar/Spe*wc.jar" Spe4.class
|
||||
UnixOnly CheckFiles "SpeJar/Spe*wc.jar"
|
||||
|
||||
UnixOnly Sys "$jar" cf "StarJar/*jar.jar" Spe2.class
|
||||
UnixOnly Sys "$jar" cf "StarJar/jar*.jar" Spe3.class
|
||||
UnixOnly Sys "$jar" cf "StarJar/*jar*.jar" Spe4.class
|
||||
UnixOnly CheckFiles "StarJar/*jar.jar" "StarJar/jar*.jar" "StarJar/*jar*.jar"
|
||||
|
||||
Sys "$jar" cf "SpeJar/Spe,Comma.jar" Spe2.class
|
||||
Sys "$jar" cf "SpeJar/Spe;Semi.jar" Spe3.class
|
||||
|
||||
Sys "$jar" cf "MixJar/mix.jAr" Spe1.class
|
||||
Sys "$jar" cf "MixJar/mix2.JAR" Spe2.class
|
||||
Sys "$jar" cf "MixJar/mix3.zip" Spe3.class
|
||||
Sys "$jar" cf "MixJar/.hiddenjar.jar" Spe4.class
|
||||
|
||||
Sys mv Spe*.class SpeClass/.
|
||||
Sys mv Spe*.java SpeSrc/.
|
||||
CheckFiles "SpeJar/Spe,Comma.jar" "SpeJar/Spe;Semi.jar" "SpeSrc/Spe2.java" "SpeSrc/Spe3.java" "SpeSrc/Spe4.java"
|
||||
CheckFiles "MixJar/mix.jAr" "MixJar/mix2.JAR" "MixJar/mix3.zip" "MixJar/.hiddenjar.jar"
|
||||
|
||||
echo 'public class Main {public static void main(String[] a) {Lib.f();}}' > Main.java
|
||||
echo 'public class Main1 {public static void main(String[] a) {Lib2.g();}}' > Main1.java
|
||||
echo 'public class Main1b {public static void main(String[] a) {Spe1.f();}}' > Main1b.java
|
||||
echo 'public class Main2 {public static void main(String[] a) {Spe2.f();}}' > Main2.java
|
||||
echo 'public class Main3 {public static void main(String[] a) {Spe3.f();}}' > Main3.java
|
||||
echo 'public class Main4 {public static void main(String[] a) {Spe4.f();}}' > Main4.java
|
||||
echo 'public class Main5 {public static void main(String[] a) {Spe2.f(); Lib.f();}}' > Main5.java
|
||||
echo 'public class Main6 {public static void main(String[] a) {Lib3.h();}}' > Main6.java
|
||||
|
||||
|
||||
#----------------------------------------------------------------
|
||||
# Verify expected behaviour with directory named "*"
|
||||
#----------------------------------------------------------------
|
||||
starDir() {
|
||||
printf "Running tests with directory named \"*\"\n"
|
||||
Sys rm -rf ./StarDir
|
||||
Sys mkdir -p StarDir/"*"
|
||||
Sys cp "GooClass/Lib2.class" "StarDir/*/Lib2.class"
|
||||
Sys "$jar" cf "StarDir/Lib3.jar" -C GooClass "Lib3.class"
|
||||
Sys "$jar" cf "StarDir/*/Lib.jar" -C GooClass "Lib.class"
|
||||
CheckFiles "StarDir/*/Lib.jar" "StarDir/*/Lib2.class" "StarDir/Lib3.jar"
|
||||
Sys cp Main6.java ./StarDir/.
|
||||
Sys cp Main.java ./StarDir/"*"/.
|
||||
Sys cp Main1.java ./StarDir/"*"/.
|
||||
CPWC_DIR=`pwd`
|
||||
Sys cd StarDir
|
||||
Failure "$javac" ${TESTTOOLVMOPTS} -classpath "*" Main6.java
|
||||
Failure "$javac" ${TESTTOOLVMOPTS} -classpath "./*" Main6.java
|
||||
Sys rm -f Main6.*
|
||||
Sys cd "*"
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -classpath "*" Main.java
|
||||
Success "$java" ${TESTVMOPTS} -classpath .${PS}"*" Main
|
||||
Success "$javac" ${TESTTOOLVMOPTS} Main1.java
|
||||
Success "$java" ${TESTVMOPTS} -classpath "." Main1
|
||||
Sys cd $CPWC_DIR
|
||||
|
||||
Failure "$javac" ${TESTTOOLVMOPTS} -classpath "StarDir/*" Main6.java
|
||||
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -classpath StarDir/\* Main1.java
|
||||
Success "$java" ${TESTVMOPTS} -classpath StarDir/\*:. Main1
|
||||
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -classpath "StarDir/*" Main1.java
|
||||
Success "$java" ${TESTVMOPTS} -classpath ".${PS}StarDir/*" Main1
|
||||
|
||||
Failure "$javac" ${TESTTOOLVMOPTS} -classpath StarDir/"\*/*" Main.java
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -classpath StarDir/"*/*" Main.java
|
||||
|
||||
Success "$java" ${TESTVMOPTS} -classpath .${PS}StarDir/"*/*" Main
|
||||
Failure "$java" ${TESTVMOPTS} -classpath .${PS}StarDir/"\*/*" Main
|
||||
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -classpath "StarDir/Lib3.jar" Main6.java
|
||||
Success "$java" ${TESTVMOPTS} -classpath ".${PS}StarDir/Lib3.jar" Main6
|
||||
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -classpath StarDir/"*"/Lib.jar Main.java
|
||||
Success "$java" ${TESTVMOPTS} -classpath .${PS}StarDir/"*"/Lib.jar Main
|
||||
}
|
||||
UnixOnly starDir
|
||||
|
||||
#----------------------------------------------------------------
|
||||
# Verify the basic jar file works
|
||||
#----------------------------------------------------------------
|
||||
#baseline test to verify it works.
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -cp "GooJar/Lib.jar" Main.java
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -classpath "GooJar/Lib.jar" Main.java
|
||||
Success "$java" ${TESTVMOPTS} -classpath "GooJar/Lib.jar${PS}." Main
|
||||
Success "$java" ${TESTVMOPTS} -cp "GooJar/Lib.jar${PS}." Main
|
||||
|
||||
#basic test of one jar to be loaded
|
||||
UnixOnly Success "$javac" ${TESTTOOLVMOPTS} -classpath "GooJar/*" Main.java
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -classpath "GooJar/*${PS}." Main.java
|
||||
Success "$java" ${TESTVMOPTS} -classpath "GooJar/*${PS}." Main
|
||||
#in a subdir. First * should not load jars in subdirectories unless specified
|
||||
Failure "$javac" ${TESTTOOLVMOPTS} -classpath "GooJar/*" Main1.java
|
||||
Failure "$javac" ${TESTTOOLVMOPTS} -classpath "GooJar/*${PS}." Main1.java
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -cp "GooJar/SubDir/*" Main1.java
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -classpath "GooJar/SubDir/*" Main1.java
|
||||
Success "$javac" ${TESTTOOLVMOPTS} --class-path "GooJar/SubDir/*" Main1.java
|
||||
Success "$javac" ${TESTTOOLVMOPTS} --class-path="GooJar/SubDir/*" Main1.java
|
||||
#Same with launcher. Should not load jar in subdirectories unless specified
|
||||
Failure "$java" ${TESTVMOPTS} -classpath "GooJar/*${PS}." Main1
|
||||
Success "$java" ${TESTVMOPTS} -classpath "GooJar/SubDir/*${PS}." Main1
|
||||
Success "$java" ${TESTVMOPTS} -cp "GooJar/SubDir/*${PS}." Main1
|
||||
|
||||
Success env CLASSPATH="GooJar/SubDir/*" "$javac" ${TESTTOOLVMOPTS} Main1.java
|
||||
Success env CLASSPATH="GooJar/SubDir/*${PS}." "$java" ${TESTVMOPTS} Main1
|
||||
#----------------------------------------------------------------
|
||||
# Verify the jar files in 2 directories
|
||||
#----------------------------------------------------------------
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -classpath "GooJar/Lib.jar${PS}SpeJar/Spe,Comma.jar" Main5.java
|
||||
Success "$java" ${TESTVMOPTS} -classpath "GooJar/Lib.jar${PS}SpeJar/Spe,Comma.jar${PS}." Main5
|
||||
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -classpath "GooJar/*${PS}SpeJar/*" Main5.java
|
||||
Success "$java" ${TESTVMOPTS} -classpath "GooJar/*${PS}SpeJar/*${PS}." Main5
|
||||
|
||||
#----------------------------------------------------------------
|
||||
# Verify jar file and class file in same directory.
|
||||
#----------------------------------------------------------------
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -classpath "JarNClass/*${PS}" Main.java
|
||||
Success "$java" ${TESTVMOPTS} -classpath "JarNClass/*${PS}." Main
|
||||
|
||||
#----------------------------------------------------------------
|
||||
# Verify these odd jar files work explicitly on classpath, kind of
|
||||
# a baseline. Last one is also a test with * in a jar name.
|
||||
#----------------------------------------------------------------
|
||||
Failure "$javac" ${TESTTOOLVMOPTS} -classpath "SpeJar/Spe:Colon.jar" Main1.java
|
||||
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -classpath "SpeJar/Spe,Comma.jar" Main2.java
|
||||
Success "$java" ${TESTVMOPTS} -classpath "SpeJar/Spe,Comma.jar${PS}." Main2
|
||||
|
||||
UnixOnly Success "$javac" ${TESTTOOLVMOPTS} -classpath "SpeJar/Spe;Semi.jar" Main3.java
|
||||
UnixOnly Success "$java" ${TESTVMOPTS} -classpath "SpeJar/Spe;Semi.jar${PS}." Main3
|
||||
|
||||
UnixOnly Success "$javac" ${TESTTOOLVMOPTS} -classpath "SpeJar/Spe*wc.jar" Main4.java
|
||||
UnixOnly Success "$java" ${TESTVMOPTS} -classpath "SpeJar/Spe*wc.jar${PS}." Main4
|
||||
#----------------------------------------------------------------
|
||||
# Verify these odd jar files work with classpath wildcard.
|
||||
#----------------------------------------------------------------
|
||||
|
||||
speJar() {
|
||||
printf "Running tests with jar file names containing special characters\n"
|
||||
# Failure "$javac" ${TESTTOOLVMOPTS} -classpath "SpeJar/*" Main1.java
|
||||
# Success "$java" ${TESTVMOPTS} -classpath "SpeJar/*" Main1
|
||||
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -classpath "SpeJar/*" Main2.java
|
||||
Success "$java" ${TESTVMOPTS} -classpath "SpeJar/*${PS}." Main2
|
||||
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -classpath "SpeJar/*" Main3.java
|
||||
Success "$java" ${TESTVMOPTS} -classpath "SpeJar/*${PS}." Main3
|
||||
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -classpath "SpeJar/*" Main4.java
|
||||
Success "$java" ${TESTVMOPTS} -classpath "SpeJar/*${PS}." Main4
|
||||
}
|
||||
UnixOnly speJar
|
||||
|
||||
#----------------------------------------------------------------
|
||||
# Verify these jar files with asterisk in jar file name
|
||||
#----------------------------------------------------------------
|
||||
starJar() {
|
||||
printf "Running tests with jar file names containing \"*\"\n"
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -classpath "StarJar/*jar.jar" Main2.java
|
||||
Success "$java" ${TESTVMOPTS} -classpath "StarJar/*jar.jar${PS}." Main2
|
||||
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -classpath "StarJar/jar*.jar" Main3.java
|
||||
Success "$java" ${TESTVMOPTS} -classpath "StarJar/jar*.jar${PS}." Main3
|
||||
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -classpath "StarJar/*jar*.jar" Main4.java
|
||||
Success "$java" ${TESTVMOPTS} -classpath "StarJar/*jar*.jar${PS}." Main4
|
||||
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -classpath "StarJar/*" Main2.java
|
||||
Success "$java" ${TESTVMOPTS} -classpath "StarJar/*${PS}." Main2
|
||||
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -classpath "StarJar/*" Main3.java
|
||||
Success "$java" ${TESTVMOPTS} -classpath "StarJar/*${PS}." Main3
|
||||
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -classpath "StarJar/*" Main4.java
|
||||
Success "$java" ${TESTVMOPTS} -classpath "StarJar/*${PS}." Main4
|
||||
}
|
||||
UnixOnly starJar
|
||||
|
||||
#----------------------------------------------------------------
|
||||
# Verify these jar files with varying extensions
|
||||
#----------------------------------------------------------------
|
||||
# Mixed case extensions should not be loaded.
|
||||
Failure "$javac" ${TESTTOOLVMOPTS} -classpath "MixJar/*" Main1b.java
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -classpath "MixJar/mix.jAr" Main1b.java
|
||||
Failure "$javac" ${TESTTOOLVMOPTS} -classpath "MixJar/*" Main1b
|
||||
|
||||
#upper case, .JAR, extension should be loaded
|
||||
UnixOnly Success "$javac" ${TESTTOOLVMOPTS} -classpath "MixJar/*" Main2.java
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -classpath ".${PS}MixJar/*" Main2.java
|
||||
|
||||
Success "$java" ${TESTVMOPTS} -classpath "MixJar/*${PS}." Main2
|
||||
# zip extensions should not be loaded
|
||||
Failure "$javac" ${TESTTOOLVMOPTS} -classpath "MixJar/*" Main3.java
|
||||
Success "$javac" ${TESTTOOLVMOPTS} -classpath "MixJar/mix3.zip" Main3.java
|
||||
Failure "$java" ${TESTVMOPTS} -classpath "MixJar/*${PS}." Main3
|
||||
# unix "hidden" file
|
||||
UnixOnly Success "$javac" ${TESTTOOLVMOPTS} -classpath "MixJar/*" Main4.java
|
||||
UnixOnly Success "$java" ${TESTVMOPTS} -classpath "MixJar/*${PS}." Main4
|
||||
|
||||
Cleanup
|
||||
|
||||
Bottom Line
|
||||
#----------------------------------------------------------------
|
@ -245,7 +245,7 @@ public class ToolBox {
|
||||
public void copyFile(Path from, Path to) throws IOException {
|
||||
if (Files.isDirectory(to)) {
|
||||
to = to.resolve(from.getFileName());
|
||||
} else {
|
||||
} else if (to.getParent() != null) {
|
||||
Files.createDirectories(to.getParent());
|
||||
}
|
||||
Files.copy(from, to, StandardCopyOption.REPLACE_EXISTING);
|
||||
|
Loading…
Reference in New Issue
Block a user