/** * Make sure we have a manifest * @throws Exception */ public void ensureManifest() throws Exception { if ( getManifest() != null) return; manifest = new Manifest(); }
public String getVersion() throws Exception { Manifest m = getManifest(); if (m == null) return null; String s = m.getMainAttributes().getValue(Constants.BUNDLE_VERSION); if (s == null) return null; return s.trim(); }
public String getBsn() throws Exception { Manifest m = getManifest(); if (m == null) return null; String s = m.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME); Matcher matcher = BSN.matcher(s); if (matcher.matches()) { return matcher.group(1); } return null; }
/** * 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); }
@Override public Attributes getManifest() { try { return getOrCreateJar().getManifest().getMainAttributes(); } catch (Exception e) { throw new IllegalStateException(e); } }
@Override public Attributes getManifest() { try { return getOrCreateJar().getManifest().getMainAttributes(); } catch (Exception e) { throw new IllegalStateException(e); } }
/** * 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 IOException { writeManifest(getManifest(), out); }
/** * 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); }
/** * Print the components in this JAR file. * * @param jar */ private void printComponents(PrintStream out, Jar jar) throws IOException { out.println("[COMPONENTS]"); Manifest manifest = jar.getManifest(); if (manifest == null) { out.println("No manifest"); return; } String componentHeader = manifest.getMainAttributes().getValue( Constants.SERVICE_COMPONENT); Map<String, Map<String, String>> clauses = parseHeader(componentHeader); for (String path : clauses.keySet()) { // TODO out.println(path); } out.println(); }
/** * * @param jar */ void checkManifest(Jar jar) { try { Manifest m = jar.getManifest(); if (m != null) { String exportHeader = m.getMainAttributes().getValue(EXPORT_PACKAGE); if (exportHeader != null) { Map<String, Map<String, String>> exported = parseHeader(exportHeader); if (exported != null) { for (Map.Entry<String, Map<String, String>> entry : exported.entrySet()) { if (!classpathExports.containsKey(entry.getKey())) { classpathExports.put(entry.getKey(), entry.getValue()); } } } } } } catch (Exception e) { warning("Erroneous Manifest for " + jar + " " + e); } }
/** * Print the metatypes in this JAR. * * @param jar */ private void printMetatype(PrintStream out, Jar jar) throws Exception { out.println("[METATYPE]"); Manifest manifest = jar.getManifest(); if (manifest == null) { out.println("No manifest"); return; } Map<String, Resource> map = jar.getDirectories().get("OSGI-INF/metatype"); if (map != null) { for (Map.Entry<String, Resource> entry : map.entrySet()) { out.println(entry.getKey()); IO.copy(entry.getValue().openInputStream(), out); out.println(); } out.println(); } }
private void repoPut(RepositoryPlugin writable, Project project, String file, String bsn, String version) throws Exception { File f = getFile(file); if (f.isFile()) { Jar jar = project.getValidJar(f); Manifest manifest = jar.getManifest(); if (bsn != null) manifest.getMainAttributes().putValue( Constants.BUNDLE_SYMBOLICNAME, bsn); if (version != null) manifest.getMainAttributes().putValue(Constants.BUNDLE_VERSION, version); writable.put(jar); } else error("There is no such file: " + f.getAbsolutePath()); }
/** * * @param jar */ void checkManifest(Jar jar) { try { Manifest m = jar.getManifest(); if (m != null) { String exportHeader = m.getMainAttributes().getValue( EXPORT_PACKAGE); if (exportHeader != null) { Map<String, Map<String, String>> exported = parseHeader(exportHeader); if (exported != null) classpathExports.putAll(exported); } } } catch (Exception e) { warning("Erroneous Manifest for " + jar + " " + e); } }
private Map<String, Map<String, String>> buildIndex(File[] plugins) { Map<String, Map<String, String>> map = Create.map(); for (File plugin : plugins) { try { Jar jar = new Jar(plugin); Manifest manifest = jar.getManifest(); String bsn = manifest.getMainAttributes().getValue( Constants.BUNDLE_SYMBOLICNAME); String version = manifest.getMainAttributes().getValue( Constants.BUNDLE_VERSION); if (bsn != null) { if (version == null) version = "0"; Map<String, String> instance = map.get(bsn); if (instance == null) { instance = Create.map(); } instance.put(version, plugin.getAbsolutePath()); } } catch (Exception e) { // Ignore exceptions in the plugins dir. } } return map; }
/** * Get the manifest and write it out separately if -savemanifest is set * * @param dot */ private void doSaveManifest(Jar dot) throws Exception { String output = getProperty(SAVEMANIFEST); if (output == null) return; File f = getFile(output); if (f.isDirectory()) { f = new File(f, "MANIFEST.MF"); } f.delete(); f.getParentFile().mkdirs(); OutputStream out = new FileOutputStream(f); try { Jar.writeManifest(dot.getManifest(), out); } finally { out.close(); } changedFile(f); }
private void repoPut(RepositoryPlugin writable, Project project, String file, String bsn, String version) throws Exception { Jar jar = null; int n = file.indexOf(':'); if (n > 1 && n < 10) { jar = project.getValidJar(new URL(file)); } else { File f = getFile(file); if (f.isFile()) { jar = project.getValidJar(f); } } if (jar != null) { Manifest manifest = jar.getManifest(); if (bsn != null) manifest.getMainAttributes().putValue(Constants.BUNDLE_SYMBOLICNAME, bsn); if (version != null) manifest.getMainAttributes().putValue(Constants.BUNDLE_VERSION, version); writable.put(jar); } else error("There is no such file or url: " + file); }
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 Verifier(Jar jar, Properties properties) throws Exception { this.dot = jar; this.properties = properties; this.manifest = jar.getManifest(); if (manifest == null) { manifest = new Manifest(); error("This file contains no manifest and is therefore not a bundle"); } main = this.manifest.getMainAttributes(); verifyHeaders(main); r3 = getHeader(Analyzer.BUNDLE_MANIFESTVERSION) == null; usesRequire = getHeader(Analyzer.REQUIRE_BUNDLE) != null; fragment = getHeader(Analyzer.FRAGMENT_HOST) != null; bundleClasspath = getBundleClassPath(); mimports = parseHeader(manifest.getMainAttributes().getValue( Analyzer.IMPORT_PACKAGE)); mdynimports = parseHeader(manifest.getMainAttributes().getValue( Analyzer.DYNAMICIMPORT_PACKAGE)); mexports = parseHeader(manifest.getMainAttributes().getValue( Analyzer.EXPORT_PACKAGE)); ignore = parseHeader(manifest.getMainAttributes().getValue( Analyzer.IGNORE_PACKAGE)); }
public Verifier(Jar jar, Properties properties) throws Exception { this.dot = jar; this.properties = properties; this.manifest = jar.getManifest(); if (manifest == null) { manifest = new Manifest(); error("This file contains no manifest and is therefore not a bundle"); } main = this.manifest.getMainAttributes(); verifyHeaders(main); r3 = getHeader(Analyzer.BUNDLE_MANIFESTVERSION) == null; usesRequire = getHeader(Analyzer.REQUIRE_BUNDLE) != null; fragment = getHeader(Analyzer.FRAGMENT_HOST) != null; bundleClasspath = getBundleClassPath(); mimports = parseHeader(manifest.getMainAttributes().getValue( Analyzer.IMPORT_PACKAGE)); mdynimports = parseHeader(manifest.getMainAttributes().getValue( Analyzer.DYNAMICIMPORT_PACKAGE)); mexports = parseHeader(manifest.getMainAttributes().getValue( Analyzer.EXPORT_PACKAGE)); ignore = parseHeader(manifest.getMainAttributes().getValue( Analyzer.IGNORE_PACKAGE)); }
private void copyInfo(Jar source, Jar dest, String type) throws Exception { source.ensureManifest(); dest.ensureManifest(); copyInfoResource( source, dest, "LICENSE"); copyInfoResource( source, dest, "LICENSE.html"); copyInfoResource( source, dest, "about.html"); Manifest sm = source.getManifest(); Manifest dm = dest.getManifest(); copyInfoHeader( sm, dm, "Bundle-Description",""); copyInfoHeader( sm, dm, "Bundle-Vendor",""); copyInfoHeader( sm, dm, "Bundle-Copyright",""); copyInfoHeader( sm, dm, "Bundle-DocURL",""); copyInfoHeader( sm, dm, "Bundle-License",""); copyInfoHeader( sm, dm, "Bundle-Name", " " + type); copyInfoHeader( sm, dm, "Bundle-SymbolicName", "." + type); copyInfoHeader( sm, dm, "Bundle-Version", ""); }