1
1
/*
2
- * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
28
28
* @library /tools/lib
29
29
* @modules jdk.compiler/com.sun.tools.javac.api
30
30
* jdk.compiler/com.sun.tools.javac.main
31
+ * jdk.compiler/com.sun.tools.javac.file
31
32
* @build toolbox.ToolBox toolbox.JavacTask toolbox.TestRunner
32
33
* @run main BCPOrSystemNotSpecified
33
34
*/
43
44
import java .util .EnumSet ;
44
45
import javax .tools .JavaFileManager ;
45
46
import javax .tools .JavaFileObject ;
47
+ import javax .tools .StandardJavaFileManager ;
46
48
import javax .tools .StandardLocation ;
47
49
import javax .tools .ToolProvider ;
48
50
import toolbox .JavacTask ;
51
53
import toolbox .TestRunner ;
52
54
import toolbox .ToolBox ;
53
55
56
+ import com .sun .tools .javac .file .PathFileObject ;
57
+
54
58
public class BCPOrSystemNotSpecified extends TestRunner {
55
59
56
60
private final ToolBox tb = new ToolBox ();
@@ -192,7 +196,7 @@ protected void runTests() throws Exception {
192
196
}
193
197
194
198
private void prepareBCP (Path target ) throws IOException {
195
- try (JavaFileManager jfm = ToolProvider .getSystemJavaCompiler ()
199
+ try (StandardJavaFileManager jfm = ToolProvider .getSystemJavaCompiler ()
196
200
.getStandardFileManager (null , null , null )) {
197
201
for (String pack : new String [] {"" , "java.lang" , "java.lang.annotation" , "jdk.internal.javac" }) {
198
202
JavaFileManager .Location javaBase =
@@ -206,7 +210,9 @@ private void prepareBCP(Path target) throws IOException {
206
210
Files .createDirectories (targetDir );
207
211
try (InputStream in = file .openInputStream ()) {
208
212
String sourcePath = file .getName ();
209
- int sepPos = sourcePath .lastIndexOf (fileSep );
213
+ // Here, we should use file system separator instead of the operating system separator.
214
+ String fileSystemSep = jfm .asPath (file ).getFileSystem ().getSeparator ();
215
+ int sepPos = sourcePath .lastIndexOf (fileSystemSep );
210
216
String fileName = sourcePath .substring (sepPos + 1 );
211
217
Files .copy (in , targetDir .resolve (fileName ));
212
218
}
0 commit comments