12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @summary JVM should be able to handle full path (directory path plus
27 * class name) or directory path longer than MAX_PATH specified
28 * in -Xbootclasspath/a on windows.
29 * @library /test/lib
30 * @modules java.base/jdk.internal.misc
31 * java.management
32 * @run main LongBCP
33 */
34
35 import java.io.File;
36 import java.nio.file.Files;
37 import java.nio.file.FileStore;
38 import java.nio.file.Path;
39 import java.nio.file.Paths;
40 import java.util.Arrays;
41 import jdk.test.lib.Platform;
42 import jdk.test.lib.compiler.CompilerUtils;
43 import jdk.test.lib.process.ProcessTools;
44 import jdk.test.lib.process.OutputAnalyzer;
45
46 public class LongBCP {
47
48 private static final int MAX_PATH = 260;
49
50 public static void main(String args[]) throws Exception {
51 Path sourceDir = Paths.get(System.getProperty("test.src"), "test-classes");
60 Arrays.fill(chars, 'x');
61 String subPath = new String(chars);
62 destDir = Paths.get(System.getProperty("test.classes"), subPath);
63 }
64
65 CompilerUtils.compile(sourceDir, destDir);
66
67 String bootCP = "-Xbootclasspath/a:" + destDir.toString();
68 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
69 bootCP, "Hello");
70
71 OutputAnalyzer output = new OutputAnalyzer(pb.start());
72 output.shouldContain("Hello World")
73 .shouldHaveExitValue(0);
74
75 // increase the length of destDir to slightly over MAX_PATH
76 destDir = Paths.get(destDir.toString(), "xxxxx");
77 CompilerUtils.compile(sourceDir, destDir);
78
79 bootCP = "-Xbootclasspath/a:" + destDir.toString();
80 pb = ProcessTools.createJavaProcessBuilder(
81 bootCP, "Hello");
82
83 output = new OutputAnalyzer(pb.start());
84 output.shouldContain("Hello World")
85 .shouldHaveExitValue(0);
86
87 // relative path tests
88 // We currently cannot handle relative path specified in the
89 // -Xbootclasspath/a on windows.
90 //
91 // relative path length within the file system limit
92 int fn_max_length = 255;
93 // In AUFS file system, the maximal file name length is 242
94 FileStore store = Files.getFileStore(new File(".").toPath());
95 String fs_type = store.type();
96 if ("aufs".equals(fs_type)) {
97 fn_max_length = 242;
98 }
99 char[] chars = new char[fn_max_length];
|
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @summary JVM should be able to handle full path (directory path plus
27 * class name) or directory path longer than MAX_PATH specified
28 * in -Xbootclasspath/a on windows.
29 * @library /test/lib
30 * @modules java.base/jdk.internal.misc
31 * java.management
32 * jdk.jartool/sun.tools.jar
33 * @run main LongBCP
34 */
35
36 import java.io.File;
37 import java.nio.file.Files;
38 import java.nio.file.FileStore;
39 import java.nio.file.Path;
40 import java.nio.file.Paths;
41 import java.util.Arrays;
42 import jdk.test.lib.Platform;
43 import jdk.test.lib.compiler.CompilerUtils;
44 import jdk.test.lib.process.ProcessTools;
45 import jdk.test.lib.process.OutputAnalyzer;
46
47 public class LongBCP {
48
49 private static final int MAX_PATH = 260;
50
51 public static void main(String args[]) throws Exception {
52 Path sourceDir = Paths.get(System.getProperty("test.src"), "test-classes");
61 Arrays.fill(chars, 'x');
62 String subPath = new String(chars);
63 destDir = Paths.get(System.getProperty("test.classes"), subPath);
64 }
65
66 CompilerUtils.compile(sourceDir, destDir);
67
68 String bootCP = "-Xbootclasspath/a:" + destDir.toString();
69 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
70 bootCP, "Hello");
71
72 OutputAnalyzer output = new OutputAnalyzer(pb.start());
73 output.shouldContain("Hello World")
74 .shouldHaveExitValue(0);
75
76 // increase the length of destDir to slightly over MAX_PATH
77 destDir = Paths.get(destDir.toString(), "xxxxx");
78 CompilerUtils.compile(sourceDir, destDir);
79
80 bootCP = "-Xbootclasspath/a:" + destDir.toString();
81 pb = ProcessTools.createJavaProcessBuilder(
82 bootCP, "Hello");
83
84 output = new OutputAnalyzer(pb.start());
85 output.shouldContain("Hello World")
86 .shouldHaveExitValue(0);
87
88 // create a hello.jar
89 sun.tools.jar.Main jarTool = new sun.tools.jar.Main(System.out, System.err, "jar");
90 String helloJar = destDir.toString() + File.separator + "hello.jar";
91 if (!jarTool.run(new String[]
92 {"-cf", helloJar, "-C", destDir.toString(), "Hello.class"})) {
93 throw new RuntimeException("Could not write the Hello jar file");
94 }
95
96 // run with long bootclasspath to hello.jar
97 bootCP = "-Xbootclasspath/a:" + helloJar;
98 pb = ProcessTools.createJavaProcessBuilder(
99 bootCP, "Hello");
100
101 output = new OutputAnalyzer(pb.start());
102 output.shouldContain("Hello World")
103 .shouldHaveExitValue(0);
104
105 // relative path tests
106 // We currently cannot handle relative path specified in the
107 // -Xbootclasspath/a on windows.
108 //
109 // relative path length within the file system limit
110 int fn_max_length = 255;
111 // In AUFS file system, the maximal file name length is 242
112 FileStore store = Files.getFileStore(new File(".").toPath());
113 String fs_type = store.type();
114 if ("aufs".equals(fs_type)) {
115 fn_max_length = 242;
116 }
117 char[] chars = new char[fn_max_length];
|