use of aQute.lib.getopt.Description in project bnd by bndtools.
the class bnd method _source.
/**
* Merge a bundle with its source.
*
* @throws Exception
*/
@Description("Merge a binary jar with its sources. It is possible to specify source path")
public void _source(sourceOptions opts) throws Exception {
List<String> arguments = opts._arguments();
File jarFile = getFile(arguments.remove(0));
if (!jarFile.exists()) {
error("File %s does not exist ", jarFile);
return;
}
File sourceFile = getFile(arguments.remove(0));
if (!sourceFile.exists()) {
error("Source file %s does not exist ", sourceFile);
return;
}
File output = jarFile;
if (opts.output() != null)
output = getFile(opts.output());
File tmp = File.createTempFile("tmp", ".jar", jarFile.getParentFile());
tmp.deleteOnExit();
try (Jar bin = new Jar(jarFile);
Jar src = new Jar(sourceFile)) {
bin.setDoNotTouchManifest();
for (String path : src.getResources().keySet()) bin.putResource("OSGI-OPT/src/" + path, src.getResource(path));
bin.write(tmp);
}
IO.rename(tmp, output);
}
use of aQute.lib.getopt.Description in project bnd by bndtools.
the class bnd method _release.
/**
* Release the project
*
* @throws Exception
*/
@Description("Release this project")
public void _release(releaseOptions options) throws Exception {
Set<Project> projects = new LinkedHashSet<Project>();
Workspace ws = Workspace.findWorkspace(getBase());
if (ws == null) {
error("Workspace option was specified but cannot find a workspace from %s", getBase());
return;
}
if (options.workspace()) {
projects.addAll(ws.getAllProjects());
}
Project project = getProject(options.project());
if (project != null) {
projects.add(project);
}
if (projects.isEmpty()) {
error("Cannot find any projects");
return;
}
String repo = options.repo();
if (repo != null) {
RepositoryPlugin repository = ws.getRepository(repo);
if (repository == null) {
error("No such release repo %s%nFound:%n%s", repository, Strings.join("\n", ws.getRepositories()));
}
}
for (Project p : projects) {
if (repo != null) {
p.setProperty(Constants.RELEASEREPO, repo);
}
p.release(options.test());
}
getInfo(project);
}
use of aQute.lib.getopt.Description in project bnd by bndtools.
the class bnd method _xref.
/**
* Cross reference every class in the jar file to the files it references
*/
@Description("Show a cross references for all classes in a set of jars.")
public void _xref(xrefOptions options) throws IOException, Exception {
Analyzer analyzer = new Analyzer();
final MultiMap<TypeRef, TypeRef> table = new MultiMap<TypeRef, TypeRef>();
final MultiMap<PackageRef, PackageRef> packages = new MultiMap<PackageRef, PackageRef>();
Set<TypeRef> set = Create.set();
Instructions filter = new Instructions(options.match());
for (String arg : options._arguments()) {
try {
File file = new File(arg);
try (Jar jar = new Jar(file.getName(), file)) {
for (Map.Entry<String, Resource> entry : jar.getResources().entrySet()) {
String key = entry.getKey();
Resource r = entry.getValue();
if (key.endsWith(".class")) {
TypeRef ref = analyzer.getTypeRefFromPath(key);
if (filter.matches(ref.toString())) {
set.add(ref);
try (InputStream in = r.openInputStream()) {
Clazz clazz = new Clazz(analyzer, key, r);
// TODO use the proper bcp instead
// of using the default layout
Set<TypeRef> s = clazz.parseClassFile();
for (Iterator<TypeRef> t = s.iterator(); t.hasNext(); ) {
TypeRef tr = t.next();
if (tr.isJava() || tr.isPrimitive())
t.remove();
else
packages.add(ref.getPackageRef(), tr.getPackageRef());
}
table.addAll(ref, s);
set.addAll(s);
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
boolean to = options.to();
boolean from = options.from();
if (to == false && from == false)
to = from = true;
if (options.classes()) {
if (to)
printxref(table, ">");
if (from)
printxref(table.transpose(), "<");
} else {
if (to)
printxref(packages, ">");
if (from)
printxref(packages.transpose(), "<");
}
}
use of aQute.lib.getopt.Description in project bnd by bndtools.
the class bnd method __merge.
@Description("Merge a number of jar files into a new jar file. The used manifest is that of the first" + "given JAR file. The order of the JAR file is the class path order. I.e. earlier resources" + "are preferred over later resources with the same name.")
public void __merge(MergeOptions options) throws Exception {
String name = options.output() == null ? "output.jar" : options.output();
File out = getFile(name);
if (!out.getParentFile().isDirectory()) {
error("Output file is not in a valid directory: %s", out.getParentFile());
}
List<String> list = options._arguments();
Collections.reverse(list);
try (Jar jar = new Jar(name)) {
Jar last = null;
for (String member : list) {
File m = getFile(member);
if (!m.isFile()) {
error("%s is not a file", m.getAbsolutePath());
} else {
Jar jm = new Jar(m);
last = jm;
addClose(jm);
jar.addAll(jm);
}
}
if (last != null) {
jar.setManifest(last.getManifest());
}
jar.write(out);
}
}
use of aQute.lib.getopt.Description in project bnd by bndtools.
the class bnd method _select.
@Description("Helps finding information in a set of JARs by filtering on manifest data and printing out selected information.")
public void _select(selectOptions opts) throws Exception {
PrintStream out = this.out;
Filter filter = null;
if (opts.where() != null) {
String w = opts.where();
if (!w.startsWith("("))
w = "(" + w + ")";
filter = new Filter(w);
}
Instructions instructions = new Instructions(opts.header());
for (String s : opts._arguments()) {
Jar jar = getJar(s);
if (jar == null) {
err.println("no file " + s);
continue;
}
Domain domain = Domain.domain(jar.getManifest());
Hashtable<String, Object> ht = new Hashtable<String, Object>();
Iterator<String> i = domain.iterator();
Set<String> realNames = new HashSet<String>();
while (i.hasNext()) {
String key = i.next();
String value = domain.get(key).trim();
ht.put(key.trim().toLowerCase(), value);
realNames.add(key);
}
ht.put("resources", jar.getResources().keySet());
realNames.add("resources");
if (filter != null) {
if (!filter.match(ht))
continue;
}
Set<Instruction> unused = new HashSet<Instruction>();
Collection<String> select = instructions.select(realNames, unused, true);
for (String h : select) {
if (opts.path()) {
out.print(jar.getSource().getAbsolutePath() + ":");
}
if (opts.name()) {
out.print(jar.getSource().getName() + ":");
}
if (opts.key()) {
out.print(h + ":");
}
out.println(ht.get(h.toLowerCase()));
}
for (Instruction ins : unused) {
String literal = ins.getLiteral();
if (literal.equals("name"))
out.println(jar.getSource().getName());
else if (literal.equals("path"))
out.println(jar.getSource().getAbsolutePath());
else if (literal.equals("size") || literal.equals("length"))
out.println(jar.getSource().length());
else if (literal.equals("modified"))
out.println(new Date(jar.getSource().lastModified()));
}
}
}
Aggregations