src/share/classes/org/openjdk/jigsaw/SimpleLibrary.java

Print this page

        

*** 151,177 **** private static final int MINOR_VERSION = 1; private static final int DEFLATED = 1 << 0; private File parent; private Set<StorageOption> opts; public File parent() { return parent; } public boolean isDeflated() { return opts.contains(StorageOption.DEFLATED); } ! private Header(File root, File p, Set<StorageOption> opts) { super(MAJOR_VERSION, MINOR_VERSION, FileConstants.Type.LIBRARY_HEADER, new File(root, FILE)); this.parent = p; this.opts = new HashSet<>(opts); } private Header(File root) { ! this(root, null, Collections.<StorageOption>emptySet()); } protected void storeRest(DataOutputStream out) throws IOException { --- 151,187 ---- private static final int MINOR_VERSION = 1; private static final int DEFLATED = 1 << 0; private File parent; + // location of native libs for this library (may be outside the library) + private File natlibs; + // location of native cmds for this library (may be outside the library) + private File natcmds; + private Set<StorageOption> opts; public File parent() { return parent; } + public File natlibs() { return natlibs; } + public File natcmds() { return natcmds; } public boolean isDeflated() { return opts.contains(StorageOption.DEFLATED); } ! private Header(File root, File p, File natlibs, File natcmds, ! Set<StorageOption> opts) { super(MAJOR_VERSION, MINOR_VERSION, FileConstants.Type.LIBRARY_HEADER, new File(root, FILE)); this.parent = p; + this.natlibs = natlibs; + this.natcmds = natcmds; this.opts = new HashSet<>(opts); } private Header(File root) { ! this(root, null, null, null, Collections.<StorageOption>emptySet()); } protected void storeRest(DataOutputStream out) throws IOException {
*** 180,189 **** --- 190,205 ---- flags |= DEFLATED; out.writeShort(flags); out.writeByte((parent != null) ? 1 : 0); if (parent != null) out.writeUTF(parent.toString()); + out.writeByte((natlibs != null) ? 1 : 0); + if (natlibs != null) + out.writeUTF(natlibs.toString()); + out.writeByte((natcmds != null) ? 1 : 0); + if (natcmds != null) + out.writeUTF(natcmds.toString()); } protected void loadRest(DataInputStream in) throws IOException {
*** 192,201 **** --- 208,223 ---- if ((flags & DEFLATED) == DEFLATED) opts.add(StorageOption.DEFLATED); int b = in.readByte(); if (b != 0) parent = new File(in.readUTF()); + b = in.readByte(); + if (b != 0) + natlibs = new File(in.readUTF()); + b = in.readByte(); + if (b != 0) + natcmds = new File(in.readUTF()); } private static Header load(File f) throws IOException {
*** 206,224 **** } private final File root; private final File canonicalRoot; ! private File parentPath = null; ! private SimpleLibrary parent = null; private final Header hd; public String name() { return root.toString(); } public File root() { return canonicalRoot; } public int majorVersion() { return hd.majorVersion; } public int minorVersion() { return hd.minorVersion; } public SimpleLibrary parent() { return parent; } public boolean isDeflated() { return hd.isDeflated(); } private URI location = null; public URI location() { if (location == null) --- 228,250 ---- } private final File root; private final File canonicalRoot; ! private File parentPath; ! private File natlibs; ! private File natcmds; ! private SimpleLibrary parent; private final Header hd; public String name() { return root.toString(); } public File root() { return canonicalRoot; } public int majorVersion() { return hd.majorVersion; } public int minorVersion() { return hd.minorVersion; } public SimpleLibrary parent() { return parent; } + public File natlibs() { return natlibs; } + public File natcmds() { return natcmds; } public boolean isDeflated() { return hd.isDeflated(); } private URI location = null; public URI location() { if (location == null)
*** 231,253 **** return (this.getClass().getName() + "[" + canonicalRoot + ", v" + hd.majorVersion + "." + hd.minorVersion + "]"); } ! private SimpleLibrary(File path, boolean create, File parentPath, Set<StorageOption> opts) throws IOException { root = path; canonicalRoot = root.getCanonicalFile(); if (root.exists()) { if (!root.isDirectory()) throw new IOException(root + ": Exists but is not a directory"); hd = Header.load(root); if (hd.parent() != null) { parent = open(hd.parent()); ! parentPath = hd.parent(); } return; } if (!create) throw new FileNotFoundException(root.toString()); if (parentPath != null) { --- 257,285 ---- return (this.getClass().getName() + "[" + canonicalRoot + ", v" + hd.majorVersion + "." + hd.minorVersion + "]"); } ! private SimpleLibrary(File path, boolean create, File parentPath, ! File natlibs, File natcmds, Set<StorageOption> opts) throws IOException { root = path; canonicalRoot = root.getCanonicalFile(); if (root.exists()) { + //TODO: root exists, but we are creating???? if (!root.isDirectory()) throw new IOException(root + ": Exists but is not a directory"); hd = Header.load(root); if (hd.parent() != null) { parent = open(hd.parent()); ! this.parentPath = hd.parent(); } + if (hd.natlibs() != null) + this.natlibs = hd.natlibs(); + if (hd.natcmds() != null) + this.natcmds = hd.natcmds(); return; } if (!create) throw new FileNotFoundException(root.toString()); if (parentPath != null) {
*** 254,290 **** this.parent = open(parentPath); this.parentPath = this.parent.root(); } if (!root.mkdirs()) throw new IOException(root + ": Cannot create library directory"); ! hd = new Header(canonicalRoot, this.parentPath, opts); hd.store(); } ! public static SimpleLibrary create(File path, File parent, Set<StorageOption> opts) throws IOException { ! return new SimpleLibrary(path, true, parent, opts); } public static SimpleLibrary create(File path, File parent) throws IOException { ! return new SimpleLibrary(path, true, parent, Collections.<StorageOption>emptySet()); } public static SimpleLibrary create(File path, Set<StorageOption> opts) throws IOException { // ## Should default parent to $JAVA_HOME/lib/modules ! return new SimpleLibrary(path, true, null, opts); } public static SimpleLibrary open(File path) throws IOException { ! return new SimpleLibrary(path, false, null, Collections.<StorageOption>emptySet()); } private static final JigsawModuleSystem jms = JigsawModuleSystem.instance(); --- 286,338 ---- this.parent = open(parentPath); this.parentPath = this.parent.root(); } if (!root.mkdirs()) throw new IOException(root + ": Cannot create library directory"); ! if (natlibs != null) ! // resolve against the working dir, and store the absolute path ! this.natlibs = natlibs.getCanonicalFile(); ! if (natcmds != null) ! this.natcmds = natcmds.getCanonicalFile(); ! hd = new Header(canonicalRoot, this.parentPath, this.natlibs, ! this.natcmds, opts); hd.store(); } ! public static SimpleLibrary create(File path, File parent, File natlibs, ! File natcmds, Set<StorageOption> opts) throws IOException { ! return new SimpleLibrary(path, true, parent, natlibs, natcmds, opts); } + public static SimpleLibrary create(File path, File parent, + Set<StorageOption> opts) + throws IOException + { + return new SimpleLibrary(path, true, parent, null, null, opts); + } + public static SimpleLibrary create(File path, File parent) throws IOException { ! return new SimpleLibrary(path, true, parent, null, null, ! Collections.<StorageOption>emptySet()); } public static SimpleLibrary create(File path, Set<StorageOption> opts) throws IOException { // ## Should default parent to $JAVA_HOME/lib/modules ! return new SimpleLibrary(path, true, null, null, null, opts); } public static SimpleLibrary open(File path) throws IOException { ! return new SimpleLibrary(path, false, null, null, null, ! Collections.<StorageOption>emptySet()); } private static final JigsawModuleSystem jms = JigsawModuleSystem.instance();
*** 967,977 **** throws ConfigurationException, IOException, SignatureException { BufferedInputStream bin = new BufferedInputStream(is); DataInputStream in = new DataInputStream(bin); File md = null; ! try (ModuleFile.Reader mr = new ModuleFile.Reader(in)) { byte[] mib = mr.readStart(); ModuleInfo mi = jms.parseModuleInfo(mib); md = moduleDir(mi.id()); ModuleId mid = mi.id(); if (md.exists()) --- 1015,1025 ---- throws ConfigurationException, IOException, SignatureException { BufferedInputStream bin = new BufferedInputStream(is); DataInputStream in = new DataInputStream(bin); File md = null; ! try (ModuleFile.Reader mr = new ModuleFile.Reader(in, this)) { byte[] mib = mr.readStart(); ModuleInfo mi = jms.parseModuleInfo(mib); md = moduleDir(mi.id()); ModuleId mid = mi.id(); if (md.exists())
*** 1336,1349 **** } public File findLocalNativeLibrary(ModuleId mid, String name) throws IOException { ! File md = findModuleDir(mid); ! if (md == null) return null; ! File f = new File(new File(md, "lib"), name); if (!f.exists()) return null; return f; } --- 1384,1401 ---- } public File findLocalNativeLibrary(ModuleId mid, String name) throws IOException { ! File f = natlibs(); ! if (f == null) { ! f = findModuleDir(mid); ! if (f == null) return null; ! f = new File(f, "lib"); ! } ! f = new File(f, name); if (!f.exists()) return null; return f; }