public static File genLocalJarForTest(String pathToClazzFile, String clazzName, Map<File,String>extraContent) throws IOException, InterruptedException { String u = pathToClazzFile; File dir = new File(u); File parentDir = dir.getParentFile(); File f = new File(parentDir, clazzName + JAVA_FILE_EXT); Files.copy(dir, f); executeCmd(new String[] { "javac", clazzName + JAVA_FILE_EXT }, parentDir); f.delete(); File outputJar=new File(parentDir, clazzName + JAR_FILE_EXT); ZipOutputStream zos=new ZipOutputStream(new FileOutputStream(outputJar)); String contentClassName = clazzName + CLAZZ_FILE_EXT; zos.putNextEntry(new ZipEntry(contentClassName)); IOUtils.copy(new FileInputStream(new File(parentDir,contentClassName)), zos); zos.closeEntry(); for (Entry<File, String> entry : extraContent.entrySet()) { zos.putNextEntry(new ZipEntry(entry.getKey().toString())); zos.write(entry.getValue().getBytes()); zos.closeEntry(); } zos.close(); new File(parentDir, contentClassName).delete(); return outputJar; } }
public static File genLocalJarForTest(String pathToClazzFile, String clazzName) throws IOException, InterruptedException { String u = pathToClazzFile; File dir = new File(u); File parentDir = dir.getParentFile(); File f = new File(parentDir, clazzName + JAVA_FILE_EXT); Files.copy(dir, f); executeCmd(new String[] { "javac", clazzName + JAVA_FILE_EXT }, parentDir); executeCmd(new String[] { "jar", "cf", clazzName + JAR_FILE_EXT, clazzName + CLAZZ_FILE_EXT }, parentDir); f.delete(); new File(parentDir, clazzName + CLAZZ_FILE_EXT).delete(); return new File(parentDir, clazzName + JAR_FILE_EXT); } }
public static File genLocalJarForTest(String pathToClazzFile, String clazzName, Map<File,String>extraContent) throws IOException, InterruptedException { String u = pathToClazzFile; File dir = new File(u); File parentDir = dir.getParentFile(); File f = new File(parentDir, clazzName + JAVA_FILE_EXT); Files.copy(dir, f); executeCmd(new String[] { "javac", clazzName + JAVA_FILE_EXT }, parentDir); f.delete(); File outputJar=new File(parentDir, clazzName + JAR_FILE_EXT); ZipOutputStream zos=new ZipOutputStream(new FileOutputStream(outputJar)); String contentClassName = clazzName + CLAZZ_FILE_EXT; zos.putNextEntry(new ZipEntry(contentClassName)); IOUtils.copy(new FileInputStream(new File(parentDir,contentClassName)), zos); zos.closeEntry(); for (Entry<File, String> entry : extraContent.entrySet()) { zos.putNextEntry(new ZipEntry(entry.getKey().toString())); zos.write(entry.getValue().getBytes()); zos.closeEntry(); } zos.close(); new File(parentDir, contentClassName).delete(); return outputJar; } }