use of aQute.bnd.osgi.Instructions in project bnd by bndtools.
the class DiffPluginImpl method setIgnore.
public void setIgnore(String diffignore) {
if (diffignore == null) {
localIgnore = null;
return;
}
Parameters p = new Parameters(diffignore);
localIgnore = new Instructions(p);
}
use of aQute.bnd.osgi.Instructions in project bnd by bndtools.
the class BaselineCommands method _schema.
/**
* Create a schema of a set of jars outling the packages and their versions.
* This will create a list of packages with multiple versions, link to their
* specifications, and the deltas between versions.
*
* <pre>
* bnd package schema
* <file.jar>*
* </pre>
*
* @param opts
* @throws Exception
*/
public void _schema(schemaOptions opts) throws Exception {
MultiMap<String, PSpec> map = new MultiMap<String, PSpec>();
Tag top = new Tag("jschema");
int n = 1000;
for (String spec : opts._arguments()) {
File f = bnd.getFile(spec);
if (!f.isFile()) {
bnd.messages.NoSuchFile_(f);
} else {
// For each specification jar we found
logger.debug("spec {}", f);
// spec
Jar jar = new Jar(f);
Manifest m = jar.getManifest();
Attributes main = m.getMainAttributes();
Tag specTag = new Tag(top, "specification");
specTag.addAttribute("jar", spec);
specTag.addAttribute("name", main.getValue("Specification-Name"));
specTag.addAttribute("title", main.getValue("Specification-Title"));
specTag.addAttribute("jsr", main.getValue("Specification-JSR"));
specTag.addAttribute("url", main.getValue("Specification-URL"));
specTag.addAttribute("version", main.getValue("Specification-Version"));
specTag.addAttribute("vendor", main.getValue("Specification-Vendor"));
specTag.addAttribute("id", n);
specTag.addContent(main.getValue(Constants.BUNDLE_DESCRIPTION));
Parameters exports = OSGiHeader.parseHeader(m.getMainAttributes().getValue(Constants.EXPORT_PACKAGE));
// Create a map with versions. Ensure import ranges overwrite
// the
// exported versions
Parameters versions = new Parameters();
versions.putAll(exports);
versions.putAll(OSGiHeader.parseHeader(m.getMainAttributes().getValue(Constants.IMPORT_PACKAGE)));
Analyzer analyzer = new Analyzer();
analyzer.setJar(jar);
analyzer.analyze();
Tree tree = differ.tree(analyzer);
for (Entry<String, Attrs> entry : exports.entrySet()) {
// For each exported package in the specification JAR
Attrs attrs = entry.getValue();
String packageName = entry.getKey();
PackageRef packageRef = analyzer.getPackageRef(packageName);
String version = attrs.get(Constants.VERSION_ATTRIBUTE);
PSpec pspec = new PSpec();
pspec.packageName = packageName;
pspec.version = new Version(version);
pspec.id = n;
pspec.attrs = attrs;
pspec.tree = tree;
Collection<PackageRef> uses = analyzer.getUses().get(packageRef);
if (uses != null) {
for (PackageRef x : uses) {
if (x.isJava())
continue;
String imp = x.getFQN();
if (imp.equals(packageName))
continue;
String v = null;
if (versions.containsKey(imp))
v = versions.get(imp).get(Constants.VERSION_ATTRIBUTE);
pspec.uses.put(imp, v);
}
}
map.add(packageName, pspec);
}
jar.close();
n++;
}
}
// We now gather all the information about all packages in the map.
// Next phase is generating the XML. Sorting the packages is
// important because XSLT is brain dead.
SortedList<String> names = new SortedList<String>(map.keySet());
Tag packagesTag = new Tag(top, "packages");
Tag baselineTag = new Tag(top, "baseline");
for (String pname : names) {
// For each distinct package name
SortedList<PSpec> specs = new SortedList<PSpec>(map.get(pname));
PSpec older = null;
Parameters olderExport = null;
for (PSpec newer : specs) {
// For each package in the total set
Tag pack = new Tag(packagesTag, "package");
pack.addAttribute("name", newer.packageName);
pack.addAttribute("version", newer.version);
pack.addAttribute("spec", newer.id);
Parameters newerExport = new Parameters();
newerExport.put(pname, newer.attrs);
if (older != null) {
String compareId = newer.packageName + "-" + newer.id + "-" + older.id;
pack.addAttribute("delta", compareId);
logger.debug(" newer={} older={}", newerExport, olderExport);
Set<Info> infos = baseline.baseline(newer.tree, newerExport, older.tree, olderExport, new Instructions(pname));
for (Info info : infos) {
Tag tag = getTag(info);
tag.addAttribute("id", compareId);
tag.addAttribute("newerSpec", newer.id);
tag.addAttribute("olderSpec", older.id);
baselineTag.addContent(tag);
}
older.tree = null;
older.attrs = null;
older = newer;
}
for (Entry<String, String> uses : newer.uses.entrySet()) {
Tag reference = new Tag(pack, "import");
reference.addAttribute("name", uses.getKey());
reference.addAttribute("version", uses.getValue());
}
older = newer;
olderExport = newerExport;
}
}
String o = opts.output("schema.xml");
File of = bnd.getFile(o);
File pof = of.getParentFile();
IO.mkdirs(pof);
try (PrintWriter pw = IO.writer(of, UTF_8)) {
pw.print("<?xml version='1.0' encoding='UTF-8'?>\n");
top.print(0, pw);
}
if (opts.xsl() != null) {
URL home = bnd.getBase().toURI().toURL();
URL xslt = new URL(home, opts.xsl());
String path = of.getAbsolutePath();
if (path.endsWith(".xml"))
path = path.substring(0, path.length() - 4);
path = path + ".html";
File html = new File(path);
logger.debug("xslt {} {} {} {}", xslt, of, html, html.exists());
try (OutputStream out = IO.outputStream(html);
InputStream in = xslt.openStream()) {
Transformer transformer = transformerFactory.newTransformer(new StreamSource(in));
transformer.transform(new StreamSource(of), new StreamResult(out));
}
}
}
use of aQute.bnd.osgi.Instructions in project bnd by bndtools.
the class SubsystemExporter method headers.
private void headers(final Project project, Attributes application) {
for (String key : project.getPropertyKeys(true)) {
if (!Verifier.HEADER_PATTERN.matcher(key).matches())
continue;
if (application.getValue(key) != null)
continue;
String value = project.getProperty(key);
if (value == null)
continue;
value = value.trim();
if (value.isEmpty() || Constants.EMPTY_HEADER.equals(value))
continue;
char c = value.charAt(0);
if (Character.isUpperCase(c))
application.putValue(key, value);
}
Instructions instructions = new Instructions(project.mergeProperties(REMOVEHEADERS));
Collection<Object> result = instructions.select(application.keySet(), false);
application.keySet().removeAll(result);
}
use of aQute.bnd.osgi.Instructions in project bnd by bndtools.
the class bnd method _extract.
@Description("Extract files from a JAR file, equivalent jar command x[vf] (syntax supported)")
public void _extract(extractOptions opts) throws Exception {
Jar jar;
if (opts.file() != null) {
File f = getFile(opts.file());
if (!f.isFile()) {
messages.NoSuchFile_(f);
return;
}
jar = new Jar(f);
} else {
jar = new Jar("cin", System.in);
}
try {
Instructions instructions = new Instructions(opts._arguments());
Collection<String> selected = instructions.select(jar.getResources().keySet(), true);
File store = getBase();
if (opts.cdir() != null)
store = getFile(opts.cdir());
IO.mkdirs(store);
Jar.Compression compression = jar.hasCompression();
for (String path : selected) {
if (opts.verbose())
System.err.printf("%8s: %s\n", compression.toString().toLowerCase(), path);
File f = getFile(store, path);
File pf = f.getParentFile();
IO.mkdirs(pf);
Resource r = jar.getResource(path);
IO.copy(r.openInputStream(), f);
}
} finally {
jar.close();
}
}
use of aQute.bnd.osgi.Instructions in project bnd by bndtools.
the class bnd method _type.
@Description("List files int a JAR file, equivalent jar command t[vf] (syntax supported)")
public void _type(typeOptions opts) throws Exception {
Jar jar;
if (opts.file() != null) {
File f = getFile(opts.file());
if (!f.isFile()) {
messages.NoSuchFile_(f);
return;
}
jar = new Jar(f);
} else {
jar = new Jar("cin", System.in);
}
try {
Instructions instructions = new Instructions(opts._arguments());
Collection<String> selected = instructions.select(jar.getResources().keySet(), true);
for (String path : selected) {
if (opts.verbose()) {
Resource r = jar.getResource(path);
err.printf("%8s %-32s %s\n", r.size(), new Date(r.lastModified()), path);
} else
err.printf("%s\n", path);
}
} finally {
jar.close();
}
}
Aggregations