author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 58533 | 46b0b7fe255c |
permissions | -rw-r--r-- |
43464 | 1 |
/* |
58533 | 2 |
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. |
43464 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
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 |
*/ |
|
46949 | 23 |
|
51436 | 24 |
|
25 |
||
43464 | 26 |
package jdk.tools.jaotc.collect; |
27 |
||
28 |
import java.io.IOException; |
|
51436 | 29 |
import java.net.MalformedURLException; |
30 |
import java.net.URI; |
|
31 |
import java.net.URISyntaxException; |
|
32 |
import java.net.URL; |
|
33 |
import java.net.URLClassLoader; |
|
34 |
import java.nio.file.DirectoryStream; |
|
35 |
import java.nio.file.FileSystem; |
|
36 |
import java.nio.file.FileSystems; |
|
37 |
import java.nio.file.Files; |
|
38 |
import java.nio.file.Path; |
|
43464 | 39 |
import java.util.HashMap; |
40 |
||
41 |
public class FileSupport { |
|
46949 | 42 |
public boolean exists(Path path) { |
43464 | 43 |
return Files.exists(path); |
44 |
} |
|
45 |
||
46 |
public boolean isDirectory(Path path) { |
|
47 |
return Files.isDirectory(path); |
|
48 |
} |
|
49 |
||
46949 | 50 |
private static FileSystem makeJarFileSystem(Path path) { |
43464 | 51 |
try { |
52 |
return FileSystems.newFileSystem(makeJarFileURI(path), new HashMap<>()); |
|
53 |
} catch (IOException e) { |
|
54 |
throw new InternalError(e); |
|
55 |
} |
|
56 |
} |
|
57 |
||
46949 | 58 |
private static URI makeJarFileURI(Path path) { |
43464 | 59 |
try { |
46583
873282753046
8182052: Test compiler/aot/cli/jaotc/CompileJarTest.java fails in JPRT
bobv
parents:
43464
diff
changeset
|
60 |
String name = path.toAbsolutePath().toString(); |
46949 | 61 |
name = name.replace('\\', '/'); |
58387
c5b80da6b561
8231431: JAOTC issues with JAR path containing spaces
bobv
parents:
52910
diff
changeset
|
62 |
return new URI("jar:file", null, "///" + name + "!/", null); |
43464 | 63 |
} catch (URISyntaxException e) { |
64 |
throw new InternalError(e); |
|
65 |
} |
|
66 |
} |
|
67 |
||
68 |
public ClassLoader createClassLoader(Path path, ClassLoader parent) { |
|
69 |
try { |
|
70 |
return URLClassLoader.newInstance(buildUrls(path), parent); |
|
71 |
} catch (MalformedURLException e) { |
|
72 |
throw new InternalError(e); |
|
73 |
} |
|
74 |
} |
|
75 |
||
76 |
public ClassLoader createClassLoader(Path path) throws MalformedURLException { |
|
77 |
return URLClassLoader.newInstance(buildUrls(path)); |
|
78 |
} |
|
79 |
||
46949 | 80 |
private static URL[] buildUrls(Path path) throws MalformedURLException { |
81 |
return new URL[]{path.toUri().toURL()}; |
|
43464 | 82 |
} |
83 |
||
84 |
public Path getJarFileSystemRoot(Path jarFile) { |
|
85 |
FileSystem fileSystem = makeJarFileSystem(jarFile); |
|
86 |
return fileSystem.getPath("/"); |
|
87 |
} |
|
88 |
||
89 |
public boolean isAbsolute(Path entry) { |
|
90 |
return entry.isAbsolute(); |
|
91 |
} |
|
92 |
||
93 |
public Path getSubDirectory(FileSystem fileSystem, Path root, Path path) throws IOException { |
|
46949 | 94 |
DirectoryStream<Path> paths = fileSystem.provider().newDirectoryStream(root, null); |
43464 | 95 |
for (Path entry : paths) { |
96 |
Path relative = root.relativize(entry); |
|
97 |
if (relative.equals(path)) { |
|
98 |
return entry; |
|
99 |
} |
|
100 |
} |
|
101 |
return null; |
|
102 |
} |
|
103 |
} |