private Resource createPomFromFile(File file) throws Exception { if (!file.isFile()) return null; return new FileResource(file); }
/** * Turn a resource into a file so that anything in the conversion is properly caught * @param r * @throws Exception */ public FileResource(Resource r) throws Exception { this.file = File.createTempFile("fileresource", ".resource"); deleteOnClose(true); this.file.deleteOnExit(); IO.copy(r.openInputStream(), this.file); }
public Jar(String name, File dirOrFile, Pattern doNotCopy) throws ZipException, IOException { this(name); source = dirOrFile; if (dirOrFile.isDirectory()) FileResource.build(this, dirOrFile, doNotCopy); else if (dirOrFile.isFile()) { zipFile = ZipResource.build(this, dirOrFile); } else { throw new IllegalArgumentException("A Jar can only accept a valid file or directory: " + dirOrFile); } }
static void traverse(Jar jar, int rootlength, File directory, Pattern doNotCopy) { if (doNotCopy != null && doNotCopy.matcher(directory.getName()).matches()) return; jar.updateModified(directory.lastModified(), "Dir change"); File files[] = directory.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) traverse(jar, rootlength, files[i], doNotCopy); else { String path = files[i].getAbsolutePath().substring(rootlength + 1); if (File.separatorChar != '/') path = path.replace(File.separatorChar, '/'); jar.putResource(path, new FileResource(files[i]), true); } } }
public void write(OutputStream out) throws Exception { FileResource.copy(this, out); }
public static void build(Jar jar, File directory, Pattern doNotCopy) { traverse(jar, directory.getAbsolutePath().length(), directory, doNotCopy); }
@Override public void write(OutputStream out) throws Exception { if (buffer != null) { IO.copy(buffer(), out); } else { IO.copy(file, out); } }
@SuppressWarnings("resource") public static Jar fromResource(String name, Resource resource) throws Exception { if (resource instanceof JarResource) { return ((JarResource) resource).getJar(); } else if (resource instanceof FileResource) { return new Jar(name, ((FileResource) resource).getFile()); } return new Jar(name).buildFromResource(resource); }
static void traverse(Jar jar, int rootlength, File directory, Pattern doNotCopy) { if (doNotCopy != null && doNotCopy.matcher(directory.getName()).matches()) return; jar.updateModified(directory.lastModified(), "Dir change " + directory); File files[] = directory.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) traverse(jar, rootlength, files[i], doNotCopy); else { String path = files[i].getAbsolutePath().substring(rootlength + 1); if (File.separatorChar != '/') path = path.replace(File.separatorChar, '/'); jar.putResource(path, new FileResource(files[i]), true); } } }
public void write(OutputStream out) throws Exception { copy(this, out); }
public static void build(Jar jar, File directory, Pattern doNotCopy) { traverse(jar, directory.getAbsolutePath().length(), directory, doNotCopy); }
@Override public InputStream openInputStream() throws Exception { if (buffer != null) { return IO.stream(buffer()); } else { return IO.stream(file); } }
@SuppressWarnings("resource") public static Jar fromResource(String name, Resource resource) throws Exception { if (resource instanceof JarResource) { return ((JarResource) resource).getJar(); } else if (resource instanceof FileResource) { return new Jar(name, ((FileResource) resource).getFile()); } return new Jar(name).buildFromResource(resource); }
private Resource createPomFromFile(File file) throws Exception { if (!file.isFile()) return null; return new FileResource(file); }
static void traverse(Jar jar, int rootlength, File directory, Pattern doNotCopy) { if (doNotCopy != null && doNotCopy.matcher(directory.getName()).matches()) return; jar.updateModified(directory.lastModified(), "Dir change " + directory); File files[] = directory.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) traverse(jar, rootlength, files[i], doNotCopy); else { String path = files[i].getAbsolutePath().substring(rootlength + 1); if (File.separatorChar != '/') path = path.replace(File.separatorChar, '/'); jar.putResource(path, new FileResource(files[i]), true); } } }
/** * Turn a resource into a file so that anything in the conversion is properly caught * @param r * @throws Exception */ public FileResource(Resource r) throws Exception { this.file = File.createTempFile("fileresource", ".resource"); deleteOnClose(true); this.file.deleteOnExit(); IO.copy(r.openInputStream(), this.file); }
public void write(OutputStream out) throws Exception { copy(this, out); }
public Jar(String name, File dirOrFile, Pattern doNotCopy) throws ZipException, IOException { this(name); source = dirOrFile; if (dirOrFile.isDirectory()) FileResource.build(this, dirOrFile, doNotCopy); else if (dirOrFile.isFile()) { zipFile = ZipResource.build(this, dirOrFile); } else { throw new IllegalArgumentException("A Jar can only accept a valid file or directory: " + dirOrFile); } }
public static void build(Jar jar, File directory, Pattern doNotCopy) { traverse(jar, directory.getAbsolutePath().length(), directory, doNotCopy); }
@Override public void write(OutputStream out) throws Exception { if (buffer != null) { IO.copy(buffer(), out); } else { IO.copy(file, out); } }