use of aQute.lib.getopt.Description in project bnd by bndtools.
the class bnd method _project.
@Description("Execute a Project action, or if no parms given, show information about the project")
public void _project(projectOptions options) throws Exception {
Project project = getProject(options.project());
if (project == null) {
messages.NoProject();
return;
}
List<String> l = new ArrayList<String>(options._arguments());
if (l.isEmpty()) {
err.printf("Name %s\n", project.getName());
err.printf("Actions %s\n", project.getActions().keySet());
err.printf("Directory %s\n", project.getBase());
err.printf("Depends on %s\n", project.getDependson());
err.printf("Sub builders %s\n", project.getSubBuilders());
return;
}
String cmd = null;
String arg = null;
if (!l.isEmpty())
cmd = l.remove(0);
if (!l.isEmpty())
arg = l.remove(0);
if (!l.isEmpty()) {
messages.MoreArgumentsThanNeeded_(options._arguments());
return;
}
if (cmd == null) {
messages.NoCommandForProject(project);
return;
}
Action a = project.getActions().get(cmd);
if (a != null) {
a.execute(project, arg);
getInfo(project);
return;
}
}
use of aQute.lib.getopt.Description in project bnd by bndtools.
the class bnd method _remove.
@Description("Remove a project or a plugin from the workspace")
public void _remove(RemoveOptions opts) throws Exception {
List<String> args = opts._arguments();
String what = args.remove(0);
Workspace ws = Workspace.findWorkspace(getBase());
if (ws == null) {
error("No workspace found from %s", getBase());
return;
}
if ("project".equals(what)) {
for (String pname : args) {
Project project = ws.getProject(pname);
if (project == null) {
error("No such project %s", pname);
} else
project.remove();
}
getInfo(ws);
return;
}
if ("workspace".equals(what)) {
error("To delete a workspace, delete the directory");
return;
}
if ("plugin".equals(what)) {
CommandLine cl = new CommandLine(this);
String help = cl.execute(new Plugins(this, ws), "remove", new ExtList<String>(args));
if (help != null)
out.println(help);
return;
}
}
use of aQute.lib.getopt.Description in project bnd by bndtools.
the class bnd method _convert.
@Description("Converter to different formats")
public void _convert(convertOptions opts) throws IOException {
File from = getFile(opts._arguments().get(0));
File to = getFile(opts._arguments().get(1));
if (opts.m2p()) {
try (InputStream in = IO.stream(from)) {
Properties p = new UTF8Properties();
Manifest m = new Manifest(in);
Attributes attrs = m.getMainAttributes();
for (Map.Entry<Object, Object> i : attrs.entrySet()) {
p.put(i.getKey().toString(), i.getValue().toString());
}
try (OutputStream fout = IO.outputStream(to)) {
if (opts.xml())
p.storeToXML(fout, "converted from " + from);
else {
try (Writer osw = IO.writer(fout, UTF_8)) {
p.store(osw, "converted from " + from);
}
}
}
}
return;
}
error("no conversion specified");
}
use of aQute.lib.getopt.Description in project bnd by bndtools.
the class bnd method _flatten.
@Description("Flatten a bundle by expanding all entries on the Bundle-ClassPath")
public void _flatten(FlattenOptions opts) throws Exception {
List<String> inputs = opts._arguments();
String inputPath = inputs.remove(0);
String outputPath = inputs.remove(0);
File source = getFile(inputPath);
if (!source.isFile()) {
error("Not a source file %s", source);
return;
}
File destination = getFile(outputPath);
IO.mkdirs(destination.getParentFile());
if (!destination.getParentFile().isDirectory()) {
error("Could not create directory for output file %s", outputPath);
}
Jar input = new Jar(source);
addClose(input);
Manifest manifest = input.getManifest();
Domain domain = Domain.domain(manifest);
List<String> bundleClassPath = new ArrayList<>(domain.getBundleClasspath().keySet());
if (bundleClassPath.isEmpty()) {
warning("%s has no bundle class path", source);
return;
}
Collections.reverse(bundleClassPath);
Jar output = new Jar(source.getName());
for (String path : bundleClassPath) {
logger.debug("bcp entry {}", path);
Resource r = input.getResource(path);
if (r == null) {
logger.debug("Is directory {}", path);
if (path.equals(".")) {
addAll(output, input, "", bundleClassPath);
} else
addAll(output, input, path, null);
} else {
logger.debug("Is jar {}", path);
Jar sub = new Jar(path, r.openInputStream());
addClose(sub);
addAll(output, sub, "", null);
}
}
domain.setBundleClasspath(".");
output.setManifest(manifest);
output.stripSignatures();
output.write(destination);
}
use of aQute.lib.getopt.Description in project bnd by bndtools.
the class bnd method _eclipse.
@Description("Show info about the current directory's eclipse project")
public void _eclipse(eclipseOptions options) throws Exception {
File dir = getBase();
if (options.dir() != null)
dir = getFile(options.dir());
if (!dir.isDirectory())
error("Eclipse requires a path to a directory: %s", dir.getAbsolutePath());
if (options._arguments().size() != 0)
error("Unnecessary arguments %s", options._arguments());
if (!isOk())
return;
File cp = new File(dir, ".classpath");
if (!cp.exists()) {
error("Cannot find .classpath in project directory: %s", dir.getAbsolutePath());
} else {
EclipseClasspath eclipse = new EclipseClasspath(this, dir.getParentFile(), dir);
err.println("Classpath " + eclipse.getClasspath());
err.println("Dependents " + eclipse.getDependents());
err.println("Sourcepath " + eclipse.getSourcepath());
err.println("Output " + eclipse.getOutput());
err.println();
}
}
Aggregations