--- old/src/share/classes/org/openjdk/jigsaw/SimpleLibrary.java Mon Dec 12 16:27:57 2011 +++ new/src/share/classes/org/openjdk/jigsaw/SimpleLibrary.java Mon Dec 12 16:27:57 2011 @@ -153,23 +153,33 @@ 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 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, Set opts) { + private Header(File root, File p, File natlibs, File natcmds, + Set 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, Collections.emptySet()); + this(root, null, null, null, Collections.emptySet()); } protected void storeRest(DataOutputStream out) @@ -182,6 +192,12 @@ 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) @@ -194,6 +210,12 @@ 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) @@ -208,8 +230,10 @@ private final File root; private final File canonicalRoot; - private File parentPath = null; - private SimpleLibrary parent = null; + private File parentPath; + private File natlibs; + private File natcmds; + private SimpleLibrary parent; private final Header hd; public String name() { return root.toString(); } @@ -217,6 +241,8 @@ 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; @@ -233,19 +259,25 @@ + ", v" + hd.majorVersion + "." + hd.minorVersion + "]"); } - private SimpleLibrary(File path, boolean create, File parentPath, Set opts) + private SimpleLibrary(File path, boolean create, File parentPath, + File natlibs, File natcmds, Set 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()); - parentPath = 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) @@ -256,20 +288,35 @@ } if (!root.mkdirs()) throw new IOException(root + ": Cannot create library directory"); - hd = new Header(canonicalRoot, this.parentPath, opts); + 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, Set opts) + public static SimpleLibrary create(File path, File parent, File natlibs, + File natcmds, Set opts) throws IOException { - return new SimpleLibrary(path, true, parent, opts); + return new SimpleLibrary(path, true, parent, natlibs, natcmds, opts); } + public static SimpleLibrary create(File path, File parent, + Set opts) + throws IOException + { + return new SimpleLibrary(path, true, parent, null, null, opts); + } + public static SimpleLibrary create(File path, File parent) - throws IOException + throws IOException { - return new SimpleLibrary(path, true, parent, Collections.emptySet()); + return new SimpleLibrary(path, true, parent, null, null, + Collections.emptySet()); } public static SimpleLibrary create(File path, Set opts) @@ -276,13 +323,14 @@ throws IOException { // ## Should default parent to $JAVA_HOME/lib/modules - return new SimpleLibrary(path, true, null, opts); + return new SimpleLibrary(path, true, null, null, null, opts); } public static SimpleLibrary open(File path) throws IOException { - return new SimpleLibrary(path, false, null, Collections.emptySet()); + return new SimpleLibrary(path, false, null, null, null, + Collections.emptySet()); } private static final JigsawModuleSystem jms @@ -829,11 +877,11 @@ * directory. */ private void strip(File md) throws IOException { - File classes = new File(md, "classes"); + File classes = new File(md, "classes"); if (classes.isFile()) { File pf = new File(md, "classes.pack"); try (JarFile jf = new JarFile(classes); - FileOutputStream out = new FileOutputStream(pf)) + FileOutputStream out = new FileOutputStream(pf)) { Pack200.Packer packer = Pack200.newPacker(); Map p = packer.properties(); @@ -969,7 +1017,7 @@ BufferedInputStream bin = new BufferedInputStream(is); DataInputStream in = new DataInputStream(bin); File md = null; - try (ModuleFile.Reader mr = new ModuleFile.Reader(in)) { + try (ModuleFile.Reader mr = new ModuleFile.Reader(in, this)) { byte[] mib = mr.readStart(); ModuleInfo mi = jms.parseModuleInfo(mib); md = moduleDir(mi.id()); @@ -1003,8 +1051,8 @@ } else { mr.readRest(md, isDeflated()); } - - if (strip) + + if (strip) strip(md); reIndex(mid); // ## Could do this while reading module file return mid; @@ -1338,10 +1386,14 @@ 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); + 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;