--- old/src/share/classes/org/openjdk/jigsaw/SimpleLibrary.java Thu Feb 23 10:43:27 2012 +++ new/src/share/classes/org/openjdk/jigsaw/SimpleLibrary.java Thu Feb 23 10:43:26 2012 @@ -498,7 +498,7 @@ for (String cxn : cx.remoteContexts()) { out.writeUTF(cxn); } - + // Local service implementations Map> services = cx.services(); out.writeInt(services.size()); @@ -510,7 +510,7 @@ out.writeUTF(value); } } - + // Remote service suppliers Map> serviceSuppliers = cx.serviceSuppliers(); out.writeInt(serviceSuppliers.size()); @@ -521,7 +521,7 @@ for (String rcxn: remotes) { out.writeUTF(rcxn); } - } + } } } @@ -576,8 +576,8 @@ // Suppliers int nSuppliers = in.readInt(); for (int j = 0; j < nSuppliers; j++) - cx.addSupplier(in.readUTF()); - + cx.addSupplier(in.readUTF()); + // Local service implementations int nServices = in.readInt(); for (int j = 0; j < nServices; j++) { @@ -584,11 +584,11 @@ String sn = in.readUTF(); int nImpl = in.readInt(); for (int k = 0; k < nImpl; k++) { - String cn = in.readUTF(); + String cn = in.readUTF(); cx.putService(sn, cn); } - } - + } + // Remote service suppliers int nRemoteServices = in.readInt(); for (int j = 0; j < nRemoteServices; j++) { @@ -597,8 +597,8 @@ for (int k = 0; k < nRemotes; k++) { String rcxn = in.readUTF(); cx.addServiceSupplier(sn, rcxn); - } - } + } + } } } @@ -1010,16 +1010,18 @@ } }); } else if (cd.isFile()) { - FileInputStream fis = new FileInputStream(cd); - ZipInputStream zis = new ZipInputStream(fis); - ZipEntry ze; - while ((ze = zis.getNextEntry()) != null) { - if (!ze.getName().endsWith(".class")) - continue; - addToIndex(ClassInfo.read(Files.nonClosingStream(zis), - ze.getSize(), - mid + ":" + ze.getName()), - ix); + try (FileInputStream fis = new FileInputStream(cd); + ZipInputStream zis = new ZipInputStream(fis)) + { + ZipEntry ze; + while ((ze = zis.getNextEntry()) != null) { + if (!ze.getName().endsWith(".class")) + continue; + addToIndex(ClassInfo.read(Files.nonClosingStream(zis), + ze.getSize(), + mid + ":" + ze.getName()), + ix); + } } } --- old/test/org/openjdk/jigsaw/TrivialWebServer.java Thu Feb 23 10:43:28 2012 +++ new/test/org/openjdk/jigsaw/TrivialWebServer.java Thu Feb 23 10:43:27 2012 @@ -27,6 +27,7 @@ import java.nio.file.*; import java.nio.file.attribute.*; import java.net.*; +import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; import java.util.concurrent.*; @@ -33,12 +34,12 @@ import com.sun.net.httpserver.*; import static java.lang.System.out; -import static java.lang.System.err; import static java.net.HttpURLConnection.*; +import static java.util.concurrent.TimeUnit.*; public class TrivialWebServer { - + private boolean debug = System.getenv("TWS_DEBUG") != null; private final PrintStream log; @@ -55,15 +56,18 @@ log.format(" %s : %s%n", e.getKey(), e.getValue()); } } + + private static final String pattern = "EEE, dd MMM yyyy HH:mm:ss zzz"; + private static final TimeZone gmtTZ = TimeZone.getTimeZone("GMT"); + private static final ThreadLocal HTTP_DATE = + new ThreadLocal() { + @Override protected DateFormat initialValue() { + DateFormat df = new SimpleDateFormat(pattern, Locale.US); + df.setTimeZone(gmtTZ); + return df; + } + }; - private static final SimpleDateFormat HTTP_DATE; - - static { - HTTP_DATE = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", - Locale.US); - HTTP_DATE.setTimeZone(TimeZone.getTimeZone("GMT")); - } - private class Handler implements HttpHandler { @@ -80,6 +84,8 @@ private void notFound(HttpExchange hx, URI hxu) throws IOException { + if (debug) + log.format("HTTP_NOT_FOUND"); byte[] err = ("Not found: " + hxu + "").getBytes("ASCII"); hx.sendResponseHeaders(HTTP_NOT_FOUND, err.length); @@ -100,7 +106,7 @@ URI u = root.resolve(BARE_ROOT.relativize(hxu)); Path p = Paths.get(u); if (debug) { - log.format("%s --> %s%n", hxu, p); + log.format("%s %s --> %s%n", hx.getRequestMethod(), hxu, p); dump("req", hx.getRequestHeaders()); } if (!Files.exists(p)) { @@ -117,6 +123,8 @@ if (!us.endsWith("/")) { Headers ahs = hx.getResponseHeaders(); ahs.put("Location", Arrays.asList(us + "/")); + if (debug) + dump("HTTP_MOVED_PERM", ahs); hx.sendResponseHeaders(HTTP_MOVED_PERM, -1); return; } @@ -132,7 +140,8 @@ // Check Last-Modified/ETag headers // - long mtime = ba.lastModifiedTime().toMillis(); + DateFormat df = HTTP_DATE.get(); + long mtime = ba.lastModifiedTime().to(TimeUnit.SECONDS); String etag = etag(ba.fileKey()); Headers rhs = hx.getRequestHeaders(); String rmtime = rhs.getFirst("If-Modified-Since"); @@ -140,16 +149,18 @@ boolean sendit = false; if (rmtime != null) { condget = true; - long rmt = HTTP_DATE.parse(rmtime).getTime(); + long rmt = SECONDS.convert(df.parse(rmtime).getTime(), + MILLISECONDS); sendit = mtime > rmt; } String retag = rhs.getFirst("If-None-Match"); - boolean tagChanged = true; if (retag != null) { condget = true; sendit = sendit || !retag.equals(etag); } if (condget && !sendit) { + if (debug) + out.format("HTTP_NOT_MODIFIED%n"); hx.sendResponseHeaders(HTTP_NOT_MODIFIED, -1); return; } @@ -159,14 +170,19 @@ Headers ahs = hx.getResponseHeaders(); ahs.set("Content-Type", "application/octet-stream"); ahs.set("Last-Modified", - HTTP_DATE.format(new Date(mtime))); + df.format(new Date(MILLISECONDS.convert(mtime, SECONDS)))); if (etag != null) ahs.set("ETag", etag); if (debug) - dump("ans", hx.getResponseHeaders()); - hx.sendResponseHeaders(HTTP_OK, ba.size()); - Files.copy(p, hx.getResponseBody()); - + dump("HTTP_OK", ahs); + if ("HEAD".equalsIgnoreCase(hx.getRequestMethod())) { + // HEAD: manually set the c-l and write no response body + ahs.set("Content-length", Long.toString(ba.size())); + hx.sendResponseHeaders(HTTP_OK, -1); + } else { + hx.sendResponseHeaders(HTTP_OK, ba.size()); + Files.copy(p, hx.getResponseBody()); + } } catch (Exception x) { x.printStackTrace(out); } finally { --- old/test/org/openjdk/jigsaw/_RemoteRepository.java Thu Feb 23 10:43:29 2012 +++ new/test/org/openjdk/jigsaw/_RemoteRepository.java Thu Feb 23 10:43:28 2012 @@ -105,6 +105,9 @@ check(rr, pr); ModuleId mid = mids.iterator().next(); mids.remove(mid); + // Ensure time stamp of catelog after removal is at least one second > + // This is the minimum increment represented by the Last-modified header + Thread.sleep(2000); pr.remove(mid); rr.updateCatalog(false); check(rr, pr); --- old/test/org/openjdk/jigsaw/_RemoteRepositoryList.java Thu Feb 23 10:43:29 2012 +++ new/test/org/openjdk/jigsaw/_RemoteRepositoryList.java Thu Feb 23 10:43:29 2012 @@ -124,7 +124,7 @@ static URI local(int port, String path) throws Exception { if (localHost == null) - localHost = InetAddress.getLocalHost().getHostName(); + localHost = InetAddress.getLocalHost().getCanonicalHostName(); return URI.create("http://" + localHost + ":" + port + path); } --- old/test/org/openjdk/jigsaw/cli/JpkgArgsTest.java Thu Feb 23 10:43:30 2012 +++ new/test/org/openjdk/jigsaw/cli/JpkgArgsTest.java Thu Feb 23 10:43:30 2012 @@ -120,6 +120,11 @@ private void testIfFileArgIsNotReadable(boolean natlib, boolean natcmd, boolean config) throws Exception { + // File readability cannot be set to false in Windows + if (System.getProperty("os.name").startsWith("Windows")) { + return; + } + setUp("NPE if file argument is not readable: " + (natlib? " --natlib " : "") + (natcmd? " --natcmd " : "") @@ -170,7 +175,7 @@ throws Exception { setUp("Check if module path argument is not a directory"); - File aFile = new File("tmp", "aFile"); + File aFile = new File(testDir, "aFile"); aFile.createNewFile(); try { String [] args = {"-m", aFile.toString(), "jmod", "hello"}; @@ -217,12 +222,15 @@ private void testIfModulePathArgIsNotReadable() throws Exception { + // File readability cannot be set to false in Windows + if (System.getProperty("os.name").startsWith("Windows")) { + return; + } setUp("Check if module path argument is not readable"); - File dir = new File("tmp", "notReadableDir"); + File dir = new File(testDir, "notReadableDir"); if (! (dir.mkdir() && dir.setReadable(false))) throw new Exception("Can't set up test"); - try { String [] args = {"-m", dir.toString(), "jmod", "hello"}; Packager.run(args); @@ -420,10 +428,10 @@ private int count; private int errors; - // use "tmp" to help avoid accidents - private File srcDir = new File("tmp", "src"); - private File classesDir = new File("tmp", "classes"); - private File moduleDir = new File("tmp", "modules"); + private File testDir = new File(System.getProperty("test.dir", "tmp")); + private File srcDir = new File(testDir, "src"); + private File classesDir = new File(testDir, "classes"); + private File moduleDir = new File(testDir, "modules"); private File natlibDir = new File(srcDir, "natlib"); private File natcmdDir = new File(srcDir, "natcmd"); private File configDir = new File(srcDir, "config"); --- old/test/org/openjdk/jigsaw/cli/TimestampTest.java Thu Feb 23 10:43:31 2012 +++ new/test/org/openjdk/jigsaw/cli/TimestampTest.java Thu Feb 23 10:43:31 2012 @@ -78,8 +78,6 @@ }; private String[] jpkgArgs = { - "-L", - "z.lib", "-m", "z.modules/" + MNAME, "jmod", @@ -146,6 +144,10 @@ void reset() { if (moduleDir.exists()) deleteAll(moduleDir); + + if (moduleDir.exists()) { + System.err.println("WARNING: removal of " + moduleDir + " failed."); + } } /** @@ -268,7 +270,7 @@ Calendar cal = Calendar.getInstance(); tst.putGeneralizedTime(cal.getTime()); } else { - // expired-signed is Valid from: Sat Jan 01 11:32:36 EST 2005 + // expired-signed is Valid from: Sat Jan 01 11:32:36 EST 2005 // until: Sun Jan 01 11:32:36 EST 2006 // timestamp with a date within that validity period tst.putGeneralizedTime(new Date(1120190400000l)); // 07/01/2005 --- old/test/org/openjdk/jigsaw/cli/signed-modular-jar.sh Thu Feb 23 10:43:32 2012 +++ new/test/org/openjdk/jigsaw/cli/signed-modular-jar.sh Thu Feb 23 10:43:32 2012 @@ -73,7 +73,7 @@ mk signed-module.policy <>mfile; - if (match($0, /^ +class +([a-zA-Z.]+) *;/)) print module >toPath(tdir, "main"); + if (match($0, /^ +class +([a-zA-Z.]+) *;/)) { + if (moduleclassFound == 0) { + print module >toPath(tdir, "main"); + moduleclassFound = 1; + } + } } if (class) print $0 >>cfile; next; @@ -244,9 +250,11 @@ BIN=../$BIN; fi for t in *; do - cd $t - run `echo $t | cut -c4-` || /bin/true - cd .. + if [ -d $t ] ; then + cd $t + run `echo $t | cut -c4-` || /bin/true + cd .. + fi done fi