@Override public void execute() throws BuildException { try { if (!this.bundlesLocation.exists()) { fail(this.bundlesLocation.toString() + " does not exist!"); } if (this.bundlesLocation.exists()) { for (File location : this.bundlesLocation.listFiles()) { if (BundleInfo.isValidBundle(location)) { final String originalExportPackage = ManifestUtil.readManifestEntry(location, PROP_EXPORT_PACKAGE); if (originalExportPackage != null) { final String bundleVersion = ManifestUtil.readManifestEntry(location, PROP_BUNDLE_VERSION); if (bundleVersion == null) { fail( "Bundle located at \"" + location.toString() + "\" does not specify Bundle-Version."); } final StringBuilder modifiedExportPackage = new StringBuilder(); for (ManifestBundlesListEntry entry : ManifestBundlesListEntry.parse(originalExportPackage)) { for (String attr : entry.attributes()) { if (attr.startsWith("version=")) { fail( "Bundle located at \"" + location.toString() + "\" manually specifies an exported package version for \"" + entry.bundle() + "\"."); } } entry.attributes().add(0, "version=\"" + bundleVersion + "\""); if (modifiedExportPackage.length() > 0) { modifiedExportPackage.append(','); } modifiedExportPackage.append(entry); } final File manifestFile = new File(location, ManifestUtil.MANIFEST_PATH); ManifestUtil.setManifestEntry( manifestFile, PROP_EXPORT_PACKAGE, modifiedExportPackage.toString()); } } } } } catch (IOException e) { throw new BuildException(e); } }
// Implements Task public void execute() throws BuildException { if (filesets.size() == 0) { throw new BuildException("No fileset specified"); } jarMap = new HashMap(); System.out.println("loading bundle info..."); try { for (int i = 0; i < filesets.size(); i++) { FileSet fs = (FileSet) filesets.elementAt(i); DirectoryScanner ds = fs.getDirectoryScanner(getProject()); File projDir = fs.getDir(getProject()); String[] srcFiles = ds.getIncludedFiles(); for (int j = 0; j < srcFiles.length; j++) { File file = new File(projDir, srcFiles[j]); if (file.getName().endsWith(".jar")) { jarMap.put(file, new BundleInfo(file)); } } } Set removeSet = new HashSet(); for (Iterator it = jarMap.keySet().iterator(); it.hasNext(); ) { File file = (File) it.next(); String name = file.getAbsolutePath(); if (-1 != name.indexOf("_all-")) { File f2 = new File(Util.replace(name, "_all-", "-")); removeSet.add(f2); System.out.println("skip " + f2); } } if (removeSet.size() > 0) { System.out.println("skipping " + removeSet.size() + " bundles"); } for (Iterator it = removeSet.iterator(); it.hasNext(); ) { File f = (File) it.next(); jarMap.remove(f); } System.out.println("analyzing " + jarMap.size() + " bundles"); for (Iterator it = jarMap.keySet().iterator(); it.hasNext(); ) { File file = (File) it.next(); BundleInfo info = (BundleInfo) jarMap.get(file); info.load(); } System.out.println("writing bundle OBR to " + outFile); OutputStream out = null; try { out = new FileOutputStream(outFile); PrintStream ps = new PrintStream(out); ps.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); if (repoXSLURL != null && !"".equals(repoXSLURL)) { ps.println("<?xml-stylesheet type=\"text/xsl\" href=\"" + repoXSLURL + "\"?>"); } ps.println(""); ps.println("<!-- Generated by " + getClass().getName() + " -->"); ps.println(""); ps.println("<bundles>"); ps.println(" <dtd-version>1.0</dtd-version>"); ps.println(" <repository>"); ps.println(" <name>" + repoName + "</name>"); ps.println(" <date>" + (new Date()) + "</date>"); if (externRepoURLs != null && 0 < externRepoURLs.length()) { StringTokenizer st = new StringTokenizer(externRepoURLs, ","); ps.println(" <extern-repositories>"); while (st.hasMoreTokens()) { String repoURL = st.nextToken().trim(); ps.println(" <url>" + repoURL + "</url>"); } ps.println(" </extern-repositories>"); } ps.println(" </repository>"); for (Iterator it = jarMap.keySet().iterator(); it.hasNext(); ) { File file = (File) it.next(); BundleInfo info = (BundleInfo) jarMap.get(file); info.writeBundleXML(ps); } ps.println("</bundles>"); ps.close(); } catch (Exception e) { e.printStackTrace(); } finally { try { out.close(); } catch (Exception ignored) { } } } catch (Exception e) { e.printStackTrace(); throw new BuildException("Failed to extract bundle info: " + e, e); } }