Search in sources :

Example 6 with Description

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

the class bnd method _settings.

@Description("Set bnd/jpm global variables")
public void _settings(settingOptions opts) throws Exception {
    try {
        Settings settings = this.settings;
        char[] password = this.password;
        if (opts.location() != null) {
            password = opts.password();
            File f = getFile(opts.location());
            settings = new Settings(f.getAbsolutePath());
            settings.load(password);
            logger.debug("getting settings from {}", f);
        }
        if (opts.clear()) {
            settings.clear();
            logger.debug("clear {}", settings.entrySet());
        }
        if (opts.generate()) {
            logger.debug("Generating new key pair");
            settings.generate(password);
        }
        logger.debug("settings {}", opts.clear());
        List<String> rest = opts._arguments();
        if (opts.publicKey()) {
            out.println(tos(!opts.base64(), settings.getPublicKey()));
        }
        if (opts.secretKey()) {
            out.println(tos(!opts.base64(), settings.getPrivateKey()));
        }
        if (opts.mac()) {
            for (String s : rest) {
                byte[] data = s.getBytes(UTF_8);
                byte[] signature = settings.sign(data);
                out.printf("%s\n", tos(!opts.base64(), signature));
            }
        }
        if (rest.isEmpty()) {
            list(null, settings);
        } else {
            boolean set = false;
            for (String s : rest) {
                s = s.trim();
                Matcher m = ASSIGNMENT.matcher(s);
                logger.debug("try {}", s);
                if (m.matches()) {
                    String key = m.group(1);
                    Instructions instr = new Instructions(key);
                    Collection<String> select = instr.select(settings.keySet(), true);
                    // check if there is a value a='b'
                    String value = m.group(4);
                    if (value == null || value.trim().length() == 0) {
                        // check '=' presence
                        if (m.group(2) == null) {
                            list(select, settings);
                        } else {
                            // we have 'a=', remove
                            for (String k : select) {
                                logger.debug("remove {}={}", k, settings.get(k));
                                settings.remove(k);
                                set = true;
                            }
                        }
                    } else {
                        logger.debug("assignment {}={}", key, value);
                        settings.put(key, value);
                        set = true;
                    }
                } else {
                    err.printf("Cannot assign %s\n", s);
                }
            }
            if (set) {
                logger.debug("saving");
                settings.save(password);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Matcher(java.util.regex.Matcher) Instructions(aQute.bnd.osgi.Instructions) File(java.io.File) Settings(aQute.lib.settings.Settings) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) ZipException(java.util.zip.ZipException) Description(aQute.lib.getopt.Description)

Example 7 with Description

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

the class bnd method _deliverables.

@Description("Show all deliverables from this workspace. with their current version and path.")
public void _deliverables(deliverableOptions options) throws Exception {
    Project project = getProject(options.project());
    if (project == null) {
        messages.NoProject();
        return;
    }
    Collection<Project> projects;
    if (options.limit())
        projects = Arrays.asList(project);
    else
        projects = project.getWorkspace().getAllProjects();
    List<Container> containers = new ArrayList<Container>();
    for (Project p : projects) {
        containers.addAll(p.getDeliverables());
    }
    for (Container c : containers) {
        Version v = new Version(c.getVersion());
        err.printf("%-40s %8s  %s\n", c.getBundleSymbolicName(), v.getWithoutQualifier(), c.getFile());
    }
    getInfo(project);
}
Also used : Project(aQute.bnd.build.Project) Container(aQute.bnd.build.Container) Version(aQute.bnd.version.Version) ArrayList(java.util.ArrayList) Description(aQute.lib.getopt.Description)

Example 8 with Description

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

the class bnd method _bash.

@Description("Generate autocompletion file for bash")
public void _bash(Options options) throws Exception {
    File tmp = File.createTempFile("bnd-completion", ".tmp");
    tmp.deleteOnExit();
    try {
        IO.copy(getClass().getResource("bnd-completion.bash"), tmp);
        Sed sed = new Sed(tmp);
        sed.setBackup(false);
        Reporter r = new ReporterAdapter();
        CommandLine c = new CommandLine(r);
        Map<String, Method> commands = c.getCommands(this);
        StringBuilder sb = new StringBuilder();
        for (String commandName : commands.keySet()) {
            sb.append(" " + commandName);
        }
        sb.append(" help");
        sed.replace("%listCommands%", sb.toString().substring(1));
        sed.doIt();
        IO.copy(tmp, out);
    } finally {
        IO.delete(tmp);
    }
}
Also used : CommandLine(aQute.lib.getopt.CommandLine) Sed(aQute.libg.sed.Sed) ReporterAdapter(aQute.libg.reporter.ReporterAdapter) Reporter(aQute.service.reporter.Reporter) Method(java.lang.reflect.Method) File(java.io.File) Description(aQute.lib.getopt.Description)

Example 9 with Description

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

the class bnd method _bump.

/**
	 * Bump a version number
	 * 
	 * @throws Exception
	 */
@Description("Bumps the version of a project")
public void _bump(bumpoptions options) throws Exception {
    Project project = getProject(options.project());
    if (project == null) {
        messages.NoProject();
        return;
    }
    String mask = null;
    if (!options._arguments().isEmpty()) {
        mask = options._arguments().get(0);
        if (mask.equalsIgnoreCase("major"))
            mask = "+00";
        else if (mask.equalsIgnoreCase("minor"))
            mask = "=+0";
        else if (mask.equalsIgnoreCase("micro"))
            mask = "==+";
        else if (!mask.matches("[+=0]{1,3}")) {
            messages.InvalidBumpMask_(mask);
            return;
        }
    }
    if (mask == null)
        project.bump();
    else
        project.bump(mask);
    getInfo(project);
    err.println(project.getProperty(BUNDLE_VERSION, "No version found"));
}
Also used : Project(aQute.bnd.build.Project) Description(aQute.lib.getopt.Description)

Example 10 with Description

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

the class bnd method _create.

/**
	 * Create jar file
	 * 
	 * <pre>
	 *  jar c[v0M]f jarfile [-C dir] inputfiles [-Joption]
	 * jar c[v0]mf manifest jarfile [-C dir] inputfiles [-Joption] jar c[v0M]
	 * [-C dir] inputfiles [-Joption] jar c[v0]m manifest [-C dir] inputfiles
	 * [-Joption]
	 * </pre>
	 * 
	 * @param options
	 * @throws Exception
	 */
@Description("Create jar, used to support backward compatible java jar commands")
public void _create(createOptions options) throws Exception {
    Jar jar = new Jar("dot");
    File dir = getBase().getAbsoluteFile();
    String sdir = options.cdir();
    if (sdir != null)
        dir = getFile(sdir);
    if (options._arguments().isEmpty())
        add(jar, dir, ".", options.verbose());
    else
        for (String f : options._arguments()) {
            f = f.replace(File.separatorChar, '/');
            add(jar, dir, f, options.verbose());
        }
    String manifest = options.manifest();
    if (manifest != null) {
        if (options.verbose())
            err.printf("Adding manifest from %s\n", manifest);
        jar.setManifest(getFile(manifest));
    }
    if (options.Manifest()) {
        jar.setManifest((Manifest) null);
    } else {
        if (options.wrap()) {
            Analyzer w = new Analyzer(this);
            addClose(w);
            w.setBase(getBase());
            w.use(this);
            w.setDefaults(options.bsn(), options.version());
            w.calcManifest();
            getInfo(w);
            w.setJar((Jar) null);
            w.close();
        }
    }
    if (options.nocompression())
        jar.setCompression(Jar.Compression.STORE);
    if (isOk()) {
        String jarFile = options.file();
        if (jarFile == null)
            jar.write(System.out);
        else
            jar.write(jarFile);
    }
    jar.close();
}
Also used : Jar(aQute.bnd.osgi.Jar) Analyzer(aQute.bnd.osgi.Analyzer) 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