void applyPatch(String old, String patch, String newer) throws Exception { Jar a = new Jar(new File(old)); Jar b = new Jar(new File(patch)); Manifest bm = b.getManifest(); String patchDelete = bm.getMainAttributes().getValue("Patch-Delete"); String patchVersion = bm.getMainAttributes().getValue("Patch-Version"); if (patchVersion == null) { error("To patch, you must provide a patch bundle.\nThe given " + patch + " bundle does not contain the Patch-Version header"); return; } Collection<String> delete = split(patchDelete); Set<String> paths = new HashSet<String>(a.getResources().keySet()); paths.removeAll(delete); for (String path : paths) { Resource br = b.getResource(path); if (br == null) b.putResource(path, a.getResource(path)); } bm.getMainAttributes().putValue("Bundle-Version", patchVersion); b.write(new File(newer)); a.close(); b.close(); }
public Set<String> getPackages() throws IOException { if (packages == null) { if (getExtension().equals("jar") || getExtension().equals("zip")) { aQute.lib.osgi.Jar jar = new aQute.lib.osgi.Jar(getJarFile()); try { packages = new HashSet<String>(jar.getPackages()); } finally { jar.close(); } } else { return Collections.emptySet(); } } return packages; }
public boolean rename(String oldPath, String newPath) { Resource resource = remove(oldPath); if (resource == null) return false; return putResource(newPath, resource); }
/** * Cleanup the manifest for writing. Cleaning up consists of adding a space * after any \n to prevent the manifest to see this newline as a delimiter. * * @param out * Output * @throws IOException */ public void writeManifest(OutputStream out) throws Exception { writeManifest(getManifest(), out); }
private void copyInfoResource(Jar source, Jar dest, String type) { if ( source.getResources().containsKey(type) && !dest.getResources().containsKey(type)) dest.putResource(type, source.getResource(type)); }
void createPatch(String old, String newer, String patch) throws Exception { Jar a = new Jar(new File(old)); Manifest am = a.getManifest(); Jar b = new Jar(new File(newer)); Manifest bm = b.getManifest(); Set<String> delete = newSet(); for (String path : a.getResources().keySet()) { Resource br = b.getResource(path); if (br == null) { trace("DELETE %s", path); delete.add(path); } else { Resource ar = a.getResource(path); if (isEqual(ar, br)) { trace("UNCHANGED %s", path); b.remove(path); } else trace("UPDATE %s", path); } } bm.getMainAttributes().putValue("Patch-Delete", join(delete, ", ")); bm.getMainAttributes().putValue("Patch-Version", am.getMainAttributes().getValue("Bundle-Version")); b.write(new File(patch)); a.close(); a.close(); }
/** * Release * * @param name * The respository name * @param test * Run testcases * @throws Exception */ public void release(String name, boolean test) throws Exception { File[] jars = build(test); // If build fails jars will be null if (jars == null) { return; } for (File jar : jars) { Jar j = new Jar(jar); release(name, j); j.close(); } }
/** * Sets the executable class name in the given jar */ protected void setMainClass(ProcessConfig config, File installDir, File jarFile, int id, String mainClass) throws Exception { File tmpFile = File.createTempFile("fuse-process-" + id, ".jar"); Files.copy(jarFile, tmpFile); Jar jar = new Jar(tmpFile); Attributes attributes = jar.getManifest().getMainAttributes(); attributes.putValue("Main-Class", mainClass); jar.write(jarFile); }
public Jar getValidJar(URL url) throws Exception { InputStream in = url.openStream(); try { Jar jar = new Jar(url.getFile().replace('/', '.'), in, System.currentTimeMillis()); return getValidJar(jar, url.toString()); } finally { in.close(); } }
public File saveBuild(Jar jar) throws Exception { try { String bsn = jar.getName(); File f = getOutputFile(bsn); String msg = ""; if (!f.exists() || f.lastModified() < jar.lastModified()) { reportNewer(f.lastModified(), jar); f.delete(); if (!f.getParentFile().isDirectory()) f.getParentFile().mkdirs(); jar.write(f); getWorkspace().changedFile(f); } else { msg = "(not modified since " + new Date(f.lastModified()) + ")"; } trace(jar.getName() + " (" + f.getName() + ") " + jar.getResources().size() + " " + msg); return f; } finally { jar.close(); } }
private void doExpand(Jar jar) throws IOException { if (getClasspath().size() == 0 && (getProperty(EXPORT_PACKAGE) != null || getProperty(PRIVATE_PACKAGE) != null)) warning("Classpath is empty. Private-Package and Export-Package can only expand from the classpath when there is one"); Map<Instruction, Map<String, String>> privateMap = replaceWitInstruction( getHeader(PRIVATE_PACKAGE), PRIVATE_PACKAGE); Map<Instruction, Map<String, String>> exportMap = replaceWitInstruction( getHeader(EXPORT_PACKAGE), EXPORT_PACKAGE); if (isTrue(getProperty(Constants.UNDERTEST))) { privateMap.putAll(replaceWitInstruction(parseHeader(getProperty( Constants.TESTPACKAGES, "test;presence:=optional")), TESTPACKAGES)); } if (!privateMap.isEmpty()) doExpand(jar, "Private-Package, or -testpackages", privateMap, true); if (!exportMap.isEmpty()) { Jar exports = new Jar("exports"); doExpand(exports, "Export-Package", exportMap, true); jar.addAll(exports); exports.close(); } if (privateMap.isEmpty() && exportMap.isEmpty() && !isResourceOnly()) { warning("Neither Export-Package, Private-Package, -testpackages is set, therefore no packages will be included"); } }
try { File file = new File(args[i]); Jar jar = new Jar(file.getName(), file); try { for (Map.Entry<String, Resource> entry : jar.getResources().entrySet()) { String key = entry.getKey(); Resource r = entry.getValue(); jar.close();
jar.write(out); } finally { out.close(); trace("Submitted: %s to %s", jar.getName(), url); Jar result = new Jar(url.toExternalForm(), in); addClose(result); trace("Received: %s", result.getName()); Resource errors = result.getResource("META-INF/errors"); Resource warnings = result.getResource("META-INF/warnings"); if (errors != null) parse(errors.openInputStream(), url.getFile(), getErrors());
/** * Make sure we have a manifest * @throws Exception */ public void ensureManifest() throws Exception { if ( getManifest() != null) return; manifest = new Manifest(); }
/** * @param out * @param file * @throws IOException * @throws Exception */ void doSingleFileLib(File file, Appendable out) throws IOException, Exception { Jar jar = new Jar(file); String bsn = jar.getBsn(); System.out.println(bsn); String version = jar.getVersion(); jar.close(); if (bsn == null) { error("No valid bsn for %s", file); bsn = "not set"; } if (version == null) version = "0"; Version v = new Version(version); v = new Version(v.getMajor(), v.getMinor(), v.getMicro()); out.append(bsn); out.append(";version=" + v + "\n"); // '[" + v + "," + v + "]'\n"); }
dirty = true; Manifest manifest = jar.getManifest(); if (manifest == null) throw new IllegalArgumentException("No manifest in JAR: " + jar); if (!file.exists() || file.lastModified() < jar.lastModified()) { jar.write(file); reporter.progress("Updated " + file.getAbsolutePath()); fireBundleAdded(jar, file); if (latest.exists() && latest.lastModified() < jar.lastModified()) { jar.write(latest); file = latest;
out.println("Classpath used"); for (Jar jar : getClasspath()) { out.printf("File : %s\n", jar.getSource()); out.printf("File abs path : %s\n", jar.getSource() .getAbsolutePath()); out.printf("Name : %s\n", jar.getName()); Map<String, Map<String, Resource>> dirs = jar.getDirectories(); for (Map.Entry<String, Map<String, Resource>> entry : dirs.entrySet()) { Map<String, Resource> dir = entry.getValue(); dot.close(); jar.close();
public void write(OutputStream out) throws IOException { ZipOutputStream jout = nomanifest ? new ZipOutputStream(out) : new JarOutputStream(out); Set<String> done = new HashSet<String>(); Set<String> directories = new HashSet<String>(); if (doNotTouchManifest) { writeResource(jout, directories, "META-INF/MANIFEST.MF", getResource("META-INF/MANIFEST.MF")); done.add("META-INF/MANIFEST.MF"); } else if (!nomanifest) doManifest(done, jout); for (Map.Entry<String, Resource> entry : getResources().entrySet()) { // Skip metainf contents if (!done.contains(entry.getKey())) writeResource(jout, directories, (String) entry.getKey(), (Resource) entry.getValue()); } jout.finish(); }