Search in sources :

Example 41 with Description

use of aQute.lib.getopt.Description in project bnd by bndtools.

the class RepoCommand method _diff.

@Description("Diff jars (or show tree)")
public void _diff(diffOptions options) throws UnsupportedEncodingException, IOException, Exception {
    List<String> args = options._arguments();
    String newer = args.remove(0);
    String older = args.size() > 0 ? args.remove(0) : null;
    RepositoryPlugin rnewer = findRepo(newer);
    RepositoryPlugin rolder = older == null ? null : findRepo(older);
    if (rnewer == null) {
        bnd.messages.NoSuchRepository_(newer);
        return;
    }
    if (older != null && rolder == null) {
        bnd.messages.NoSuchRepository_(newer);
        return;
    }
    PrintWriter pw = IO.writer(bnd.out, UTF_8);
    Tree tNewer = RepositoryElement.getTree(rnewer);
    if (rolder == null) {
        if (options.json())
            codec.enc().to(pw).put(tNewer.serialize()).flush();
        else
            DiffCommand.show(pw, tNewer, 0);
    } else {
        Tree tOlder = RepositoryElement.getTree(rolder);
        Diff diff = new DiffImpl(tNewer, tOlder);
        MultiMap<String, String> map = new MultiMap<String, String>();
        for (Diff bsn : diff.getChildren()) {
            for (Diff version : bsn.getChildren()) {
                if (version.getDelta() == Delta.UNCHANGED)
                    continue;
                if (options.remove() == false && options.added() == false || (//
                options.remove() && version.getDelta() == Delta.REMOVED) || (options.added() && version.getDelta() == Delta.ADDED)) {
                    map.add(bsn.getName(), version.getName());
                }
            }
        }
        if (options.json())
            codec.enc().to(pw).put(map).flush();
        else if (!options.diff())
            bnd.printMultiMap(map);
        else
            DiffCommand.show(pw, diff, 0, !options.full());
    }
    pw.flush();
}
Also used : MultiMap(aQute.lib.collections.MultiMap) Diff(aQute.bnd.service.diff.Diff) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) Tree(aQute.bnd.service.diff.Tree) DiffImpl(aQute.bnd.differ.DiffImpl) PrintWriter(java.io.PrintWriter) Description(aQute.lib.getopt.Description)

Example 42 with Description

use of aQute.lib.getopt.Description in project bnd by bndtools.

the class RepoCommand method _repos.

@Description("List the current repositories")
public void _repos(@SuppressWarnings("unused") reposOptions opts) {
    int n = 1;
    for (RepositoryPlugin repo : repos) {
        String location = "";
        try {
            location = repo.getLocation();
        } catch (Throwable e) {
        // Ignore
        }
        bnd.out.printf("%03d: %-20s %4s %-20s %s%n", n++, repo.getName(), repo.canWrite() ? "r/w" : "r/o", Descriptors.getShortName(repo.getClass().getName()), location);
    }
}
Also used : RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) Description(aQute.lib.getopt.Description)

Example 43 with Description

use of aQute.lib.getopt.Description in project bnd by bndtools.

the class RepoCommand method _versions.

@Description("Displays a list of versions for a given bsn that can be found in the current repositories.")
public void _versions(VersionsOptions opts) throws Exception {
    TreeSet<Version> versions = new TreeSet<Version>();
    String bsn = opts._arguments().remove(0);
    for (RepositoryPlugin repo : repos) {
        versions.addAll(repo.versions(bsn));
    }
    bnd.out.println(versions);
}
Also used : Version(aQute.bnd.version.Version) TreeSet(java.util.TreeSet) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) Description(aQute.lib.getopt.Description)

Example 44 with Description

use of aQute.lib.getopt.Description in project bnd by bndtools.

the class bnd method _syntax.

@Description("Access the internal bnd database of keywords and options")
public void _syntax(syntaxOptions opts) throws Exception {
    int w = opts.width() < 80 ? 120 : opts.width();
    Justif justif = new Justif(w, opts.width(), 40, 42, w - 10);
    List<String> args = opts._arguments();
    StringBuilder sb = new StringBuilder();
    Formatter f = new Formatter(sb);
    for (String s : args) {
        f.format(" \n[%s]\n", s);
        Syntax sx = Syntax.HELP.get(s);
        if (s == null)
            f.format("Unknown");
        else {
            print(f, sx, "  ");
        }
    }
    f.flush();
    justif.wrap(sb);
    err.println(sb);
}
Also used : Justif(aQute.lib.justif.Justif) Formatter(java.util.Formatter) Syntax(aQute.bnd.help.Syntax) Description(aQute.lib.getopt.Description)

Example 45 with Description

use of aQute.lib.getopt.Description in project bnd by bndtools.

the class bnd method _package.

/**
	 * Package a bnd or bndrun file for packaging.
	 * 
	 * @throws Exception
	 */
@Description("Package a bnd or bndrun file into a single jar that executes with java -jar <>.jar")
public void _package(packageOptions opts) throws Exception {
    List<String> cmdline = opts._arguments();
    File output = null;
    if (opts.output() != null) {
        output = getFile(opts.output());
    } else
        output = getBase();
    if (opts._arguments().size() > 1) {
        IO.mkdirs(output);
    } else {
        File pf = output.getParentFile();
        IO.mkdirs(pf);
    }
    String profile = opts.profile() == null ? "exec" : opts.profile();
    if (cmdline.isEmpty())
        // default project itself
        cmdline.add(Project.BNDFILE);
    for (String path : cmdline) {
        Run run;
        File file = getFile(path);
        if (file.isDirectory())
            file = new File(file, Project.BNDFILE);
        if (!file.isFile()) {
            messages.NoSuchFile_(file);
            continue;
        }
        File dir = file.getParentFile();
        File workspaceDir = dir.getParentFile();
        if (workspaceDir == null) {
            // We are in the filesystem root?? Create a standalone run.
            run = Run.createRun(null, file);
        } else {
            Workspace ws = Workspace.getWorkspaceWithoutException(workspaceDir);
            run = Run.createRun(ws, file);
        }
        // Tricky because we can be run inside the context of a
        // project (in which case
        // we need to inherit from the project or outside.
        run.setProperty(PROFILE, profile);
        run.use(this);
        if (opts.jpm())
            run.setProperty(Constants.PACKAGE, Constants.PACKAGE_JPM);
        try {
            Jar jar = run.pack(profile);
            path = path.replaceAll(".bnd(run)?$", "") + ".jar";
            File out = output;
            if (output.isDirectory())
                out = new File(output, path);
            jar.write(out);
            jar.close();
        } catch (Exception e) {
            messages.ForProject_File_FailedToCreateExecutableException_(run, path, e);
        }
        getInfo(run);
    }
}
Also used : Run(aQute.bnd.build.Run) Jar(aQute.bnd.osgi.Jar) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) ZipException(java.util.zip.ZipException) Workspace(aQute.bnd.build.Workspace) 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