test/org/openjdk/jigsaw/cli/ModuleFormatTestLeftOverBytes.java

Print this page

        

*** 57,76 **** void testEmptyModule() throws Exception { System.err.println("Test: Empty module"); count++; reset(); ! List<File> files = new ArrayList<File>(); addFile(files, createFile("module-info.java", moduleinfo)); compile(files); compress(MNAME); append(MNAME, MVER, "These bytes are not made for parsing!"); try { extract(MNAME, MVER); ! } catch (IllegalArgumentException e) { ! /* swallow expected IllegalArgumentException */ ! if (! e.getMessage().startsWith("No SectionType")) throw e; } } void test() throws Exception { --- 57,79 ---- void testEmptyModule() throws Exception { System.err.println("Test: Empty module"); count++; reset(); ! List<File> files = new ArrayList<>(); addFile(files, createFile("module-info.java", moduleinfo)); compile(files); compress(MNAME); append(MNAME, MVER, "These bytes are not made for parsing!"); try { extract(MNAME, MVER); ! } catch (Exception e) { ! // ## We don't need to be so strict here about the specific message ! /* expected ModuleFileParserException wrapped by a CommandException */ ! Throwable cause = e.getCause(); ! if (!(cause instanceof ModuleFileParserException) || ! ! cause.getCause().getMessage().startsWith("No SectionType")) throw e; } } void test() throws Exception {
*** 89,103 **** /** * Append some content at the end of a module file. */ void append(String name, String version, String content) throws Exception { String fname = moduleDir + File.separator + name + "@" + version + ".jmod"; ! RandomAccessFile module = new RandomAccessFile(fname, "rw"); module.seek(module.length()); module.writeUTF(content); - module.close(); } /** * Compress a module. */ void compress(String name) throws Exception { --- 92,106 ---- /** * Append some content at the end of a module file. */ void append(String name, String version, String content) throws Exception { String fname = moduleDir + File.separator + name + "@" + version + ".jmod"; ! try (RandomAccessFile module = new RandomAccessFile(fname, "rw")) { module.seek(module.length()); module.writeUTF(content); } + } /** * Compress a module. */ void compress(String name) throws Exception {
*** 115,125 **** } void compress(String name, boolean haveNatLibs, boolean haveNatCmds, boolean haveConfig) throws Exception { ! List<String> args = new ArrayList<String>(); args.add("-m"); args.add(classesDir.getAbsolutePath()); args.add("-d"); args.add(moduleDir.getAbsolutePath()); if (haveNatLibs) { --- 118,128 ---- } void compress(String name, boolean haveNatLibs, boolean haveNatCmds, boolean haveConfig) throws Exception { ! List<String> args = new ArrayList<>(); args.add("-m"); args.add(classesDir.getAbsolutePath()); args.add("-d"); args.add(moduleDir.getAbsolutePath()); if (haveNatLibs) {
*** 141,160 **** /** * Compile a list of files. */ void compile(List<File> files) { ! List<String> options = new ArrayList<String>(); ! options.addAll(Arrays.asList("-source", "7", "-d", classesDir.getPath())); for (File f: files) options.add(f.getPath()); String[] opts = options.toArray(new String[options.size()]); StringWriter sw = new StringWriter(); ! PrintWriter pw = new PrintWriter(sw); ! int rc = com.sun.tools.javac.Main.compile(opts, pw); ! pw.close(); String out = sw.toString(); if (out.trim().length() > 0) System.err.println(out); if (rc != 0) --- 144,164 ---- /** * Compile a list of files. */ void compile(List<File> files) { ! List<String> options = new ArrayList<>(); ! options.addAll(Arrays.asList("-source", "8", "-d", classesDir.getPath())); for (File f: files) options.add(f.getPath()); String[] opts = options.toArray(new String[options.size()]); StringWriter sw = new StringWriter(); ! int rc; ! try (PrintWriter pw = new PrintWriter(sw)) { ! rc = com.sun.tools.javac.Main.compile(opts, pw); ! } String out = sw.toString(); if (out.trim().length() > 0) System.err.println(out); if (rc != 0)
*** 176,188 **** File createFile(String path, String body) throws IOException { if (body == null) return null; File file = new File(srcDir, path); file.getAbsoluteFile().getParentFile().mkdirs(); ! FileWriter out = new FileWriter(file); out.write(body); ! out.close(); return file; } /** * Set up empty src and classes directories for a test. --- 180,192 ---- File createFile(String path, String body) throws IOException { if (body == null) return null; File file = new File(srcDir, path); file.getAbsoluteFile().getParentFile().mkdirs(); ! try (FileWriter out = new FileWriter(file)) { out.write(body); ! } return file; } /** * Set up empty src and classes directories for a test.