/** * Unpack a jar file into a directory. * * This version unpacks all files inside the jar regardless of filename. * * @param jarFile the .jar file to unpack * @param toDir the destination directory into which to unpack the jar * * @throws IOException if an I/O error has occurred or toDir * cannot be created and does not already exist */ public void unJar(File jarFile, File toDir) throws IOException { unJar(jarFile, toDir, MATCH_ANY); }
/** * Unpack matching files from a jar. Entries inside the jar that do * not match the given pattern will be skipped. Keep also a copy * of the entire jar in the same directory for backward compatibility. * TODO remove this feature in a new release and do only unJar * * @param inputStream the jar stream to unpack * @param toDir the destination directory into which to unpack the jar * @param unpackRegex the pattern to match jar entries against * * @throws IOException if an I/O error has occurred or toDir * cannot be created and does not already exist */ @Deprecated public static void unJarAndSave(InputStream inputStream, File toDir, String name, Pattern unpackRegex) throws IOException{ File file = new File(toDir, name); ensureDirectory(toDir); try (OutputStream jar = new FileOutputStream(file); TeeInputStream teeInputStream = new TeeInputStream(inputStream, jar)) { unJar(teeInputStream, toDir, unpackRegex); } }
RunJar.unJar(archiveFile, dstPath); else if (archiveNameLC.endsWith(FilePageStoreManager.ZIP_SUFFIX)) FileUtil.unZip(archiveFile, dstPath);
unJar(file, workDir);
/** * Unpack a jar file into a directory. * * This version unpacks all files inside the jar regardless of filename. */ public static void unJar(File jarFile, File toDir) throws IOException { unJar(jarFile, toDir, MATCH_ANY); }
/** * Unpack a jar file into a directory. * * This version unpacks all files inside the jar regardless of filename. */ public static void unJar(File jarFile, File toDir) throws IOException { unJar(jarFile, toDir, MATCH_ANY); }
/** * Unpack a jar file into a directory. * * This version unpacks all files inside the jar regardless of filename. */ public static void unJar(File jarFile, File toDir) throws IOException { unJar(jarFile, toDir, MATCH_ANY); }
/** * Unpack a jar file into a directory. * * This version unpacks all files inside the jar regardless of filename. */ public static void unJar(File jarFile, File toDir) throws IOException { unJar(jarFile, toDir, MATCH_ANY); }
/** * Test unjarring a specific regex */ public void testUnJarWithPattern() throws Exception { File unjarDir = new File(TEST_ROOT_DIR, "unjar-pattern"); assertFalse("unjar dir shouldn't exist at test start", new File(unjarDir, "foobar.txt").exists()); // Unjar only a regex RunJar.unJar(new File(TEST_ROOT_DIR, TEST_JAR_NAME), unjarDir, Pattern.compile(".*baz.*")); assertFalse("foobar not unpacked", new File(unjarDir, "foobar.txt").exists()); assertTrue("foobaz unpacked", new File(unjarDir, "foobaz.txt").exists()); } }
private static String assembleClasspath(BSPJob jobConf, File workDir) { StringBuffer classPath = new StringBuffer(); // start with same classpath as parent process classPath.append(System.getProperty("java.class.path")); classPath.append(SYSTEM_PATH_SEPARATOR); String jar = jobConf.getJar(); if (jar != null) { // if jar exists, it into workDir try { RunJar.unJar(new File(jar), workDir); } catch (IOException ioe) { LOG.error("Unable to uncompressing file to " + workDir.toString(), ioe); } File[] libs = new File(workDir, "lib").listFiles(); if (libs != null) { for (File lib : libs) { // add libs from jar to classpath classPath.append(SYSTEM_PATH_SEPARATOR); classPath.append(lib); } } classPath.append(SYSTEM_PATH_SEPARATOR); classPath.append(new File(workDir, "classes")); classPath.append(SYSTEM_PATH_SEPARATOR); classPath.append(workDir); } return classPath.toString(); }
private static String assembleClasspath(BSPJob jobConf, File workDir) { StringBuffer classPath = new StringBuffer(); // start with same classpath as parent process classPath.append(System.getProperty("java.class.path")); classPath.append(SYSTEM_PATH_SEPARATOR); String jar = jobConf.getJar(); if (jar != null) { // if jar exists, it into workDir try { RunJar.unJar(new File(jar), workDir); } catch (IOException ioe) { LOG.error("Unable to uncompressing file to " + workDir.toString(), ioe); } File[] libs = new File(workDir, "lib").listFiles(); if (libs != null) { for (File lib : libs) { // add libs from jar to classpath classPath.append(SYSTEM_PATH_SEPARATOR); classPath.append(lib); } } classPath.append(SYSTEM_PATH_SEPARATOR); classPath.append(new File(workDir, "classes")); classPath.append(SYSTEM_PATH_SEPARATOR); classPath.append(workDir); } return classPath.toString(); }
/** * Test default unjarring behavior - unpack everything */ @Test public void testUnJar() throws Exception { File unjarDir = new File(TEST_ROOT_DIR, "unjar-all"); assertFalse("unjar dir shouldn't exist at test start", new File(unjarDir, "foobar.txt").exists()); // Unjar everything RunJar.unJar(new File(TEST_ROOT_DIR, TEST_JAR_NAME), unjarDir); assertTrue("foobar unpacked", new File(unjarDir, "foobar.txt").exists()); assertTrue("foobaz unpacked", new File(unjarDir, "foobaz.txt").exists()); }
/** * Extract an archive to the temp directory. * Code borrowed from Hadoop's TrackerDistributedCacheManager * * @param cacheArchive the cache archive to extract * @param tmpDir root location of temp directory * @return the path to the extracted archive * @throws IOException */ public static Path extractArchiveToTemp(Path cacheArchive, File tmpDir) throws IOException { String tmpArchive = cacheArchive.getName().toLowerCase(); File srcFile = new File(cacheArchive.toString()); File destDir = new File(tmpDir, srcFile.getName()); LOG.debug(String.format("Extracting %s to %s", srcFile.toString(), destDir.toString())); if (tmpArchive.endsWith(".jar")) { RunJar.unJar(srcFile, destDir); } else if (tmpArchive.endsWith(".zip")) { FileUtil.unZip(srcFile, destDir); } else if (isTarFile(tmpArchive)) { FileUtil.unTar(srcFile, destDir); } else { LOG.warn(String.format( "Cache file %s specified as archive, but not valid extension.", srcFile.toString())); return cacheArchive; } return new Path(destDir.toString()); }
RunJar.unJar(new File(jar_), wd, MATCH_ANY);
RunJar.unJar(new File(jar_), wd);
/** * Test unjarring a specific regex */ public void testUnJarWithPattern() throws Exception { File unjarDir = new File(TEST_ROOT_DIR, "unjar-pattern"); assertFalse("unjar dir shouldn't exist at test start", new File(unjarDir, "foobar.txt").exists()); // Unjar only a regex RunJar.unJar(new File(TEST_ROOT_DIR, TEST_JAR_NAME), unjarDir, Pattern.compile(".*baz.*")); assertFalse("foobar not unpacked", new File(unjarDir, "foobar.txt").exists()); assertTrue("foobaz unpacked", new File(unjarDir, "foobaz.txt").exists()); }
RunJar.unJar( new File(localJarFile.toString()), new File(localJarFile.getParent().toString()),
/** * Test unjarring a specific regex */ public void testUnJarWithPattern() throws Exception { File unjarDir = new File(TEST_ROOT_DIR, "unjar-pattern"); assertFalse("unjar dir shouldn't exist at test start", new File(unjarDir, "foobar.txt").exists()); // Unjar only a regex RunJar.unJar(new File(TEST_ROOT_DIR, TEST_JAR_NAME), unjarDir, Pattern.compile(".*baz.*")); assertFalse("foobar not unpacked", new File(unjarDir, "foobar.txt").exists()); assertTrue("foobaz unpacked", new File(unjarDir, "foobaz.txt").exists()); }
/** * Test default unjarring behavior - unpack everything */ @Test public void testUnJar() throws Exception { File unjarDir = new File(TEST_ROOT_DIR, "unjar-all"); assertFalse("unjar dir shouldn't exist at test start", new File(unjarDir, "foobar.txt").exists()); // Unjar everything RunJar.unJar(new File(TEST_ROOT_DIR, TEST_JAR_NAME), unjarDir); assertTrue("foobar unpacked", new File(unjarDir, "foobar.txt").exists()); assertTrue("foobaz unpacked", new File(unjarDir, "foobaz.txt").exists()); }
/** * Test default unjarring behavior - unpack everything */ @Test public void testUnJar() throws Exception { File unjarDir = new File(TEST_ROOT_DIR, "unjar-all"); assertFalse("unjar dir shouldn't exist at test start", new File(unjarDir, "foobar.txt").exists()); // Unjar everything RunJar.unJar(new File(TEST_ROOT_DIR, TEST_JAR_NAME), unjarDir); assertTrue("foobar unpacked", new File(unjarDir, "foobar.txt").exists()); assertTrue("foobaz unpacked", new File(unjarDir, "foobaz.txt").exists()); }