public static List<File> collect(final File dir, final String regex) { return collect(dir, Pattern.compile(regex)); }
private static void delete() { for (final String path : delete) { delete(new File(path)); } }
public StandaloneServer(final File home, final File base) { this.home = home; this.base = base; final File lib = readable(dir(exists(new File(home, "lib")))); openejbJar = readable(file(select(lib, "openejb-core.*.jar"))); final File javaagentJar = readable(file(select(lib, "openejb-javaagent.*.jar"))); final File javaHome = readable(dir(exists(new File(System.getProperty("java.home"))))); final boolean isWindows = System.getProperty("os.name").toLowerCase().contains("win"); java = readable(file(Files.path(javaHome, "bin", isWindows ? "java.exe" : "java"))); jvmOpts.add("-XX:+HeapDumpOnOutOfMemoryError"); jvmOpts.add("-javaagent:" + javaagentJar.getAbsolutePath()); }
public static void unzip(final File zipFile, final File destination, final boolean noparent) throws IOException { Files.dir(destination); Files.writable(destination); Files.file(zipFile); Files.readable(zipFile); final InputStream read = IO.read(zipFile); try { unzip(read, destination, noparent); } finally { IO.close(read); } }
Files.deleteOnExit(destinationDir); final File pf = destinationDir.getParentFile(); final String name = destinationDir.getName() + System.currentTimeMillis(); destinationDir = new File(pf, name); destinationDir.deleteOnExit(); Files.deleteOnExit(destinationDir); Files.mkdirs(destinationDir); } catch (final Files.FileRuntimeException e) { throw new IOException("Failed to create: " + destinationDir); } catch (final IOException e) { Files.delete(destinationDir); throw e;
public static File toFile(final URL url) { return Files.toFile(url); }
public static File mkparent(final File file) { mkdirs(file.getParentFile()); return file; }
public ZipService() { SystemInstance.get().setComponent(ZipService.class, this); File tempFolderMutable = new File(System.getProperty("openejb.base", ""), "work"); if (!tempFolderMutable.isDirectory()) { tempFolderMutable = new File(System.getProperty("java.io.tmpdir"), ZipService.class.getName() + "_" + System.nanoTime()); Files.mkdirs(tempFolderMutable); Files.deleteOnExit(tempFolderMutable); } // use a subfolder of work one tmpFolder = Files.mkdirs(new File(tempFolderMutable, ZipService.class.getName())); }
public static File file(final File file) { exists(file); if (!file.isFile()) { throw new FileRuntimeException("Not a file: " + file.getAbsolutePath()); } return file; }
public static File select(final File dir, final String pattern) { final List<File> matches = collect(dir, pattern); if (matches.size() == 0) { throw new IllegalStateException(String.format("Missing '%s'", pattern)); } if (matches.size() > 1) { throw new IllegalStateException(String.format("Too many found '%s': %s", pattern, join(", ", matches))); } return matches.get(0); }
public static File tmpdir() { try { File file; try { file = File.createTempFile("temp", "dir"); } catch (final Throwable e) { //Use a local tmp directory final File tmp = new File("tmp"); hackJDK4715154(); if (!tmp.exists() && !tmp.mkdirs()) { throw new IOException("Failed to create local tmp directory: " + tmp.getAbsolutePath()); } file = File.createTempFile("temp", "dir", tmp); } hackJDK4715154(); if (!file.delete()) { throw new IOException("Failed to create temp dir. Delete failed"); } mkdir(file); deleteOnExit(file); return file; } catch (final IOException e) { throw new FileRuntimeException(e); } }
protected String filteredCommand() { String val = command; int expandStart; while ((expandStart = val.indexOf("@[classpath:")) >= 0) { final int end = val.indexOf("]", expandStart); if (end < 0) { break; } final String expandable = simpleValue(val.substring(expandStart + "@[classpath:".length(), end)); final List<URL> repos = new ArrayList<>(Files.listJars(ProvisioningUtil.realLocation(expandable))); Collections.sort(repos, (o1, o2) -> o1.toExternalForm().compareTo(o2.toExternalForm())); final StringBuilder cp = new StringBuilder(); for (final URL u : repos) { cp.append(Files.toFile(u)).append(System.getProperty("path.separator")); } if (cp.length() > 0) { cp.setLength(cp.length() - System.getProperty("path.separator").length()); } val = val.substring(0, expandStart) + cp.toString() + (end < val.length() ? val.substring(end + 1) : ""); } return simpleValue(val); }
/** * Delete a file and all contents if specified file is a directory. * If the delete fails then the file/s are flagged for delete on exit. * * @param file File */ public static void delete(final File file) { if (null != file && file.exists()) { if (file.isDirectory()) { final File[] files = file.listFiles(); if (null != files) { for (final File f : files) { delete(f); } } } try { hackJDK4715154(); if (!file.delete()) { file.deleteOnExit(); } } catch (final Throwable e) { //Ignore } } }
public static File tmpdir() { try { File file = null; try { file = File.createTempFile("temp", "dir"); } catch (final Throwable e) { //Use a local tmp directory final File tmp = new File("tmp"); if (!tmp.exists() && !tmp.mkdirs()) { throw new IOException("Failed to create local tmp directory: " + tmp.getAbsolutePath()); } file = File.createTempFile("temp", "dir", tmp); } if (!file.delete()) { throw new IOException("Failed to create temp dir. Delete failed"); } mkdir(file); deleteOnExit(file); return file; } catch (final IOException e) { throw new FileRuntimeException(e); } }
public static File mkdirs(final File file) { if (!file.exists()) { hackJDK4715154(); if (!file.mkdirs()) { throw new FileRuntimeException("Cannot mkdirs: " + file.getAbsolutePath()); } return file; } return dir(file); }