Search in sources :

Example 56 with Description

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;
    }
}
Also used : Project(aQute.bnd.build.Project) Action(aQute.bnd.service.action.Action) ArrayList(java.util.ArrayList) Description(aQute.lib.getopt.Description)

Example 57 with Description

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;
    }
}
Also used : Project(aQute.bnd.build.Project) CommandLine(aQute.lib.getopt.CommandLine) Workspace(aQute.bnd.build.Workspace) Description(aQute.lib.getopt.Description)

Example 58 with Description

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");
}
Also used : JarInputStream(java.util.jar.JarInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) Attributes(java.util.jar.Attributes) UTF8Properties(aQute.lib.utf8properties.UTF8Properties) Properties(java.util.Properties) Manifest(java.util.jar.Manifest) PomFromManifest(aQute.bnd.maven.PomFromManifest) File(java.io.File) MultiMap(aQute.lib.collections.MultiMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) PrintWriter(java.io.PrintWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) UTF8Properties(aQute.lib.utf8properties.UTF8Properties) Description(aQute.lib.getopt.Description)

Example 59 with Description

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);
}
Also used : ArrayList(java.util.ArrayList) FileResource(aQute.bnd.osgi.FileResource) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar) Manifest(java.util.jar.Manifest) PomFromManifest(aQute.bnd.maven.PomFromManifest) Domain(aQute.bnd.osgi.Domain) File(java.io.File) Description(aQute.lib.getopt.Description)

Example 60 with Description

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();
    }
}
Also used : EclipseClasspath(aQute.bnd.osgi.eclipse.EclipseClasspath) File(java.io.File) Description(aQute.lib.getopt.Description)

Aggregations

Description (aQute.lib.getopt.Description)63 File (java.io.File)31 Jar (aQute.bnd.osgi.Jar)14 Project (aQute.bnd.build.Project)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 Instructions (aQute.bnd.osgi.Instructions)10 CommandLine (aQute.lib.getopt.CommandLine)10 Justif (aQute.lib.justif.Justif)8 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 Workspace (aQute.bnd.build.Workspace)7 PomFromManifest (aQute.bnd.maven.PomFromManifest)7 Service (aQute.jpm.lib.Service)7 Manifest (java.util.jar.Manifest)7 FileResource (aQute.bnd.osgi.FileResource)6 Resource (aQute.bnd.osgi.Resource)6 Analyzer (aQute.bnd.osgi.Analyzer)5 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)5 CommandData (aQute.jpm.lib.CommandData)5 ServiceData (aQute.jpm.lib.ServiceData)5