mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-01 14:08:24 +00:00
Merge
This commit is contained in:
commit
99552a1c2f
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2014, 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
|
||||
@ -35,7 +35,6 @@ import java.nio.file.FileSystemNotFoundException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.ProviderNotFoundException;
|
||||
import java.nio.file.spi.FileSystemProvider;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
@ -94,11 +93,6 @@ public class JRTIndex {
|
||||
*/
|
||||
private final FileSystem jrtfs;
|
||||
|
||||
/**
|
||||
* The set of module directories within the jrt: file system.
|
||||
*/
|
||||
private final Set<Path> jrtModules;
|
||||
|
||||
/**
|
||||
* A lazily evaluated set of entries about the contents of the jrt: file system.
|
||||
*/
|
||||
@ -183,14 +177,6 @@ public class JRTIndex {
|
||||
*/
|
||||
private JRTIndex() throws IOException {
|
||||
jrtfs = FileSystems.getFileSystem(URI.create("jrt:/"));
|
||||
jrtModules = new LinkedHashSet<>();
|
||||
Path root = jrtfs.getPath("/");
|
||||
try (DirectoryStream<Path> stream = Files.newDirectoryStream(root)) {
|
||||
for (Path entry: stream) {
|
||||
if (Files.isDirectory(entry))
|
||||
jrtModules.add(entry);
|
||||
}
|
||||
}
|
||||
entries = new HashMap<>();
|
||||
}
|
||||
|
||||
@ -204,18 +190,29 @@ public class JRTIndex {
|
||||
if (e == null) {
|
||||
Map<String, Path> files = new LinkedHashMap<>();
|
||||
Set<RelativeDirectory> subdirs = new LinkedHashSet<>();
|
||||
for (Path module: jrtModules) {
|
||||
Path p = rd.getFile(module);
|
||||
if (!Files.exists(p))
|
||||
continue;
|
||||
try (DirectoryStream<Path> stream = Files.newDirectoryStream(p)) {
|
||||
for (Path entry: stream) {
|
||||
String name = entry.getFileName().toString();
|
||||
if (Files.isRegularFile(entry)) {
|
||||
// TODO: consider issue of files with same name in different modules
|
||||
files.put(name, entry);
|
||||
} else if (Files.isDirectory(entry)) {
|
||||
subdirs.add(new RelativeDirectory(rd, name));
|
||||
Path dir;
|
||||
if (rd.path.isEmpty()) {
|
||||
dir = jrtfs.getPath("/modules");
|
||||
} else {
|
||||
Path pkgs = jrtfs.getPath("/packages");
|
||||
dir = pkgs.resolve(rd.getPath().replaceAll("/$", "").replace("/", "."));
|
||||
}
|
||||
if (Files.exists(dir)) {
|
||||
try (DirectoryStream<Path> modules = Files.newDirectoryStream(dir)) {
|
||||
for (Path module: modules) {
|
||||
Path p = rd.getFile(module);
|
||||
if (!Files.exists(p))
|
||||
continue;
|
||||
try (DirectoryStream<Path> stream = Files.newDirectoryStream(p)) {
|
||||
for (Path entry: stream) {
|
||||
String name = entry.getFileName().toString();
|
||||
if (Files.isRegularFile(entry)) {
|
||||
// TODO: consider issue of files with same name in different modules
|
||||
files.put(name, entry);
|
||||
} else if (Files.isDirectory(entry)) {
|
||||
subdirs.add(new RelativeDirectory(rd, name));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2009, 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
|
||||
@ -104,8 +104,8 @@ public abstract class PathFileObject implements JavaFileObject {
|
||||
return new PathFileObject(fileManager, path) {
|
||||
@Override
|
||||
public String inferBinaryName(Iterable<? extends Path> paths) {
|
||||
// use subpath to ignore the leading component containing the module name
|
||||
return toBinaryName(path.subpath(1, path.getNameCount()));
|
||||
// use subpath to ignore the leading /modules/MODULE-NAME
|
||||
return toBinaryName(path.subpath(2, path.getNameCount()));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -97,23 +97,32 @@ class PlatformClassPath {
|
||||
}
|
||||
|
||||
static class ImageHelper {
|
||||
private static boolean isJrtAvailable() {
|
||||
try {
|
||||
FileSystems.getFileSystem(URI.create("jrt:/"));
|
||||
return true;
|
||||
} catch (ProviderNotFoundException | FileSystemNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static ImageHelper getInstance(Path mpath) throws IOException {
|
||||
if (mpath != null) {
|
||||
return new ImageHelper(mpath);
|
||||
}
|
||||
Path home = Paths.get(System.getProperty("java.home"));
|
||||
Path mlib = home.resolve("lib").resolve("modules");
|
||||
if (Files.isDirectory(mlib)) {
|
||||
// jimage
|
||||
|
||||
if (isJrtAvailable()) {
|
||||
// jrt file system
|
||||
FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
|
||||
return new ImageHelper(fs, fs.getPath("/"));
|
||||
return new ImageHelper(fs, fs.getPath("/modules"));
|
||||
} else {
|
||||
// exploded modules
|
||||
mlib = home.resolve("modules");
|
||||
if (!Files.isDirectory(mlib)) {
|
||||
throw new InternalError(home + " not a modular image");
|
||||
String home = System.getProperty("java.home");
|
||||
Path exploded = Paths.get(home, "modules");
|
||||
if (!Files.isDirectory(exploded)) {
|
||||
throw new InternalError(home + " not a modular image");
|
||||
}
|
||||
return new ImageHelper(mlib);
|
||||
return new ImageHelper(exploded);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2013, 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
|
||||
@ -1594,15 +1594,20 @@ public class ToolBox {
|
||||
}
|
||||
|
||||
/*
|
||||
* A jar: URL is of the form jar:URL!/entry where URL is a URL for the .jar file itself.
|
||||
* A jar: URL is of the form jar:URL!/<entry> where URL is a URL for the .jar file itself.
|
||||
* In Symbol files (i.e. ct.sym) the underlying entry is prefixed META-INF/sym/<base>.
|
||||
*/
|
||||
private final Pattern jarEntry = Pattern.compile(".*!/(?:META-INF/sym/[^/]+/)?(.*)");
|
||||
|
||||
/*
|
||||
* A jrt: URL is of the form jrt:/module/package/file
|
||||
* A jrt: URL is of the form jrt:/modules/<module>/<package>/<file>
|
||||
*/
|
||||
private final Pattern jrtEntry = Pattern.compile("/([^/]+)/(.*)");
|
||||
private final Pattern jrtEntry = Pattern.compile("/modules/([^/]+)/(.*)");
|
||||
|
||||
/*
|
||||
* A file: URL is of the form file:/path/to/modules/<module>/<package>/<file>
|
||||
*/
|
||||
private final Pattern fileEntry = Pattern.compile(".*/modules/([^/]+)/(.*)");
|
||||
|
||||
private String guessPath(FileObject fo) {
|
||||
URI u = fo.toUri();
|
||||
@ -1621,6 +1626,13 @@ public class ToolBox {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "file": {
|
||||
Matcher m = fileEntry.matcher(u.getSchemeSpecificPart());
|
||||
if (m.matches()) {
|
||||
return m.group(2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException(fo.getName() + "--" + fo.toUri());
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user