author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 57705 | 7cf02b2c1455 |
permissions | -rw-r--r-- |
53261
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
1 |
/* |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
4 |
* |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
8 |
* |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
13 |
* accompanied this code). |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
14 |
* |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
18 |
* |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
21 |
* questions. |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
22 |
* |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
23 |
*/ |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
24 |
|
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
25 |
/* |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
26 |
* @test |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
27 |
* @summary Test the handling of long path to the classlist file. |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
28 |
* @requires vm.cds |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
29 |
* @library /test/lib |
57705
7cf02b2c1455
8229267: [TESTBUG] Remove unnecessary @modules dependencies in CDS tests
iklam
parents:
57567
diff
changeset
|
30 |
* @modules jdk.jartool/sun.tools.jar |
53261
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
31 |
* @compile test-classes/Hello.java |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
32 |
* @run driver LongClassListPath |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
33 |
*/ |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
34 |
|
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
35 |
import java.io.File; |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
36 |
import java.nio.file.Files; |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
37 |
import java.nio.file.Path; |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
38 |
import java.nio.file.Paths; |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
39 |
import java.nio.file.StandardCopyOption; |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
40 |
import java.util.Arrays; |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
41 |
import jdk.test.lib.cds.CDSOptions; |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
42 |
import jdk.test.lib.cds.CDSTestUtils; |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
43 |
import jdk.test.lib.process.OutputAnalyzer; |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
44 |
|
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
45 |
public class LongClassListPath { |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
46 |
private static final int MAX_PATH = 260; |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
47 |
public static void main(String[] args) throws Exception { |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
48 |
String[] classes = {"hello"}; |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
49 |
String classList = |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
50 |
CDSTestUtils.makeClassList(classes).getPath(); |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
51 |
String archiveName = "LongClassListPath.jsa"; |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
52 |
|
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
53 |
// Create a directory with long path and copy the classlist file to |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
54 |
// the directory. |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
55 |
Path classDir = Paths.get(System.getProperty("test.classes")); |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
56 |
Path destDir = classDir; |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
57 |
int subDirLen = MAX_PATH - classDir.toString().length() - 2; |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
58 |
if (subDirLen > 0) { |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
59 |
char[] chars = new char[subDirLen]; |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
60 |
Arrays.fill(chars, 'x'); |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
61 |
String subPath = new String(chars); |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
62 |
destDir = Paths.get(System.getProperty("test.classes"), subPath); |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
63 |
} |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
64 |
File longDir = destDir.toFile(); |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
65 |
longDir.mkdir(); |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
66 |
String destClassList = longDir.getPath() + File.separator + "LongClassListPath.classlist"; |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
67 |
Files.copy(Paths.get(classList), Paths.get(destClassList), StandardCopyOption.REPLACE_EXISTING); |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
68 |
|
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
69 |
CDSOptions opts = (new CDSOptions()) |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
70 |
.addPrefix("-XX:ExtraSharedClassListFile=" + destClassList, "-cp", JarBuilder.getOrCreateHelloJar()) |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
71 |
.setArchiveName(archiveName); |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
72 |
CDSTestUtils.createArchiveAndCheck(opts); |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
73 |
} |
b7dca420fa0c
8216184: CDS/appCDS tests failed on Windows due to long path to a classlist file
ccheung
parents:
diff
changeset
|
74 |
} |