/** * 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); }
ClassLoader loader; if (useClientClassLoader()) { StringBuilder sb = new StringBuilder(); sb.append(workDir).append("/"). append(File.pathSeparator).append(workDir).append("/lib/*"); String hadoopClasspath = getHadoopClasspath(); if (hadoopClasspath != null && !hadoopClasspath.isEmpty()) { sb.append(File.pathSeparator).append(hadoopClasspath); String systemClasses = getSystemClasses(); List<String> systemClassesList = systemClasses == null ? null :
/** * 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); } }
ensureDirectory(tmpDir); System.exit(-1); ensureDirectory(workDir); unJar(file, workDir); ClassLoader loader = createClassLoader(file, workDir);
ensureDirectory(tmpDir); System.exit(-1); ensureDirectory(workDir); if (!skipUnjar()) { unJar(file, workDir); ClassLoader loader = createClassLoader(file, workDir);
/** * Tests the client classloader to verify the main class and its dependent * class are loaded correctly by the application classloader, and others are * loaded by the system classloader. */ @Test public void testClientClassLoader() throws Throwable { RunJar runJar = spy(new RunJar()); // enable the client classloader when(runJar.useClientClassLoader()).thenReturn(true); // set the system classes and blacklist the test main class and the test // third class so they can be loaded by the application classloader String mainCls = ClassLoaderCheckMain.class.getName(); String thirdCls = ClassLoaderCheckThird.class.getName(); String systemClasses = "-" + mainCls + "," + "-" + thirdCls + "," + ApplicationClassLoader.SYSTEM_CLASSES_DEFAULT; when(runJar.getSystemClasses()).thenReturn(systemClasses); // create the test jar File testJar = makeClassLoaderTestJar(mainCls, thirdCls); // form the args String[] args = new String[3]; args[0] = testJar.getAbsolutePath(); args[1] = mainCls; // run RunJar runJar.run(args); // it should not throw an exception }
case ARCHIVE: if (lowerDst.endsWith(".jar")) { RunJar.unJar(inputStream, dst, RunJar.MATCH_ANY); } else if (lowerDst.endsWith(".zip")) { FileUtil.unZip(inputStream, dst); throw new IOException("Unable to create directory: [" + dst + "]"); RunJar.unJarAndSave(inputStream, dst, source.getName(), p == null ? RunJar.MATCH_ANY : Pattern.compile(p)); } else if (lowerDst.endsWith(".zip")) {
public static void spawnRemote(String jobName, String cassandraHost, int cassandraPort, String inputKeyspace, String inputColumnFamily, String outputKeyspace, String outputColumnFamily, String source, String params, String mapEmitFlag, String reduceRawDataFlag) throws Throwable { String[] args = JobSpawner.getArgs(jobName, cassandraHost, cassandraPort, inputKeyspace, inputColumnFamily, outputKeyspace, outputColumnFamily, source, params, mapEmitFlag, reduceRawDataFlag, false); RunJar.main(args); } }
+ " would create file outside of " + toDir); ensureDirectory(file.getParentFile()); try (OutputStream out = new FileOutputStream(file)) { IOUtils.copyBytes(in, out, BUFFER_SIZE);
ensureDirectory(tmpDir); System.exit(-1); ensureDirectory(workDir); unJar(file, workDir); ClassLoader loader = createClassLoader(file, workDir);
/** * Tests the client classloader to verify the main class and its dependent * class are loaded correctly by the application classloader, and others are * loaded by the system classloader. */ @Test public void testClientClassLoader() throws Throwable { RunJar runJar = spy(new RunJar()); // enable the client classloader when(runJar.useClientClassLoader()).thenReturn(true); // set the system classes and blacklist the test main class and the test // third class so they can be loaded by the application classloader String mainCls = ClassLoaderCheckMain.class.getName(); String thirdCls = ClassLoaderCheckThird.class.getName(); String systemClasses = "-" + mainCls + "," + "-" + thirdCls + "," + ApplicationClassLoader.SYSTEM_CLASSES_DEFAULT; when(runJar.getSystemClasses()).thenReturn(systemClasses); // create the test jar File testJar = makeClassLoaderTestJar(mainCls, thirdCls); // form the args String[] args = new String[3]; args[0] = testJar.getAbsolutePath(); args[1] = mainCls; // run RunJar runJar.run(args); // it should not throw an exception }
public void testRunjar() throws Throwable { File outFile = new File(TEST_ROOT_DIR, "out"); // delete if output file already exists. if (outFile.exists()) { outFile.delete(); } String[] args = new String[3]; args[0] = "build/test/mapred/testjar/testjob.jar"; args[1] = "testjar.Hello"; args[2] = outFile.toString(); RunJar.main(args); assertTrue("RunJar failed", outFile.exists()); } }
+ " would create file outside of " + toDir); ensureDirectory(file.getParentFile()); try (OutputStream out = new FileOutputStream(file)) { IOUtils.copyBytes(jar, out, BUFFER_SIZE);
RunJar.unJar(archiveFile, dstPath); else if (archiveNameLC.endsWith(FilePageStoreManager.ZIP_SUFFIX)) FileUtil.unZip(archiveFile, dstPath);
ensureDirectory(tmpDir); System.exit(-1); ensureDirectory(workDir); unJar(file, workDir); ClassLoader loader = createClassLoader(file, workDir);
ClassLoader loader; if (useClientClassLoader()) { StringBuilder sb = new StringBuilder(); sb.append(workDir+"/"). append(File.pathSeparator).append(workDir+"/lib/*"); String hadoopClasspath = getHadoopClasspath(); if (hadoopClasspath != null && !hadoopClasspath.isEmpty()) { sb.append(File.pathSeparator).append(hadoopClasspath); String systemClasses = getSystemClasses(); List<String> systemClassesList = systemClasses == null ? null :
public static void runJar(String[] argv) { try { RunJar.main(argv); } catch (Throwable t) { fail(t.getLocalizedMessage()); } }
try { File file = new File(toDir, entry.getName()); ensureDirectory(file.getParentFile()); OutputStream out = new FileOutputStream(file); try {