Search in sources :

Example 26 with Description

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

the class Main method _keys.

@Description("Show the jpm machine keys")
public void _keys(KeysOptions opts) throws Exception {
    boolean any = opts.pem() || opts.extended() || opts.hex();
    if (opts.extended()) {
        PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(settings.getPrivateKey());
        X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(settings.getPublicKey());
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        PrivateKey privateKey = keyFactory.generatePrivate(privateKeySpec);
        PublicKey publicKey = keyFactory.generatePublic(publicKeySpec);
        privateKey.getAlgorithm();
        if (opts.secret())
            out.format("private %s", privateKey);
        out.format("public  %s", publicKey);
    }
    if (opts.hex()) {
        if (opts.secret())
            out.format("private %s", Hex.toHexString(settings.getPrivateKey()));
        out.format("public  %s", Hex.toHexString(settings.getPublicKey()));
    }
    if (opts.pem() || !any) {
        formatKey(settings.getPublicKey(), "PUBLIC");
        if (opts.secret())
            formatKey(settings.getPrivateKey(), "PRIVATE");
    }
}
Also used : PrivateKey(java.security.PrivateKey) PublicKey(java.security.PublicKey) PKCS8EncodedKeySpec(java.security.spec.PKCS8EncodedKeySpec) X509EncodedKeySpec(java.security.spec.X509EncodedKeySpec) KeyFactory(java.security.KeyFactory) Description(aQute.lib.getopt.Description)

Example 27 with Description

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

the class Main method _platform.

/**
	 * Show the platform info.
	 * 
	 * @param opts
	 * @throws IOException
	 * @throws Exception
	 */
@Description("Show platform information")
public void _platform(PlatformOptions opts) throws IOException, Exception {
    CommandLine cli = opts._command();
    List<String> cmds = opts._arguments();
    if (cmds.isEmpty()) {
        if (opts.verbose()) {
            Justif j = new Justif(80, 30, 40, 50, 60);
            jpm.getPlatform().report(j.formatter());
            out.append(j.wrap());
        } else
            out.println(jpm.getPlatform().getName());
    } else {
        String execute = cli.execute(jpm.getPlatform(), cmds.remove(0), cmds);
        if (execute != null) {
            out.append(execute);
        }
    }
}
Also used : CommandLine(aQute.lib.getopt.CommandLine) Justif(aQute.lib.justif.Justif) Description(aQute.lib.getopt.Description)

Example 28 with Description

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

the class Main method _command.

@Description("Manage the jpm4j commands")
public void _command(CommandOptions opts) throws Exception {
    if (opts.remove()) {
        Instructions instrs = new Instructions(opts._arguments());
        for (CommandData cmd : jpm.getCommands()) {
            if (instrs.matches(cmd.name)) {
                jpm.deleteCommand(cmd.name);
            }
        }
        return;
    }
    if (opts._arguments().isEmpty()) {
        print(jpm.getCommands());
        return;
    }
    String cmd = opts._arguments().get(0);
    CommandData data = jpm.getCommand(cmd);
    if (data == null) {
        error("Not found: %s", cmd);
    } else {
        CommandData newer = new CommandData();
        JustAnotherPackageManager.xcopy(data, newer);
        if (updateCommandData(newer, opts)) {
            jpm.deleteCommand(data.name);
            String result = jpm.createCommand(newer, true);
            if (result != null)
                error("Failed to update command %s: %s", cmd, result);
        }
        print(newer);
    }
}
Also used : Instructions(aQute.bnd.osgi.Instructions) CommandData(aQute.jpm.lib.CommandData) Description(aQute.lib.getopt.Description)

Example 29 with Description

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

the class Windows method _path.

@Description("Add the bin directory for this jpm to your PATH in the user's environment variables")
public void _path(PathOptions options) {
    RegistryKey env = RegistryKey.HKEY_CURRENT_USER.getSubKey("Environment");
    if (env == null) {
        reporter.error("Cannot find key for environment HKEY_CURRENT_USER/Environment");
        return;
    }
    String path = env.getString("Path");
    String[] parts = path == null ? new String[0] : path.split(File.pathSeparator);
    List<String> paths = new ArrayList<String>(Arrays.asList(parts));
    boolean save = false;
    if (options.extra() != null) {
        paths.addAll(options.extra());
        save = true;
    }
    for (int i = 0; i < parts.length; i++) {
        System.out.printf("%2d:%s %s %s%n", i, parts[i].toLowerCase().contains("jpm") ? "*" : " ", new File(parts[i]).isDirectory() ? " " : "!", parts[i]);
    }
    if (options.remove()) {
        if (!paths.remove(jpm.getBinDir().getAbsolutePath())) {
            reporter.error("Could not find %s", jpm.getBinDir());
        }
        save = true;
    }
    if (options.delete() != null) {
        Instructions instr = new Instructions(options.delete());
        paths = new ArrayList<String>(instr.select(paths, true));
    }
    if (options.add()) {
        paths.remove(jpm.getBinDir().getAbsolutePath());
        paths.add(jpm.getBinDir().getAbsolutePath());
        save = true;
    }
    if (save) {
        String p = Strings.join(File.pathSeparator, paths);
        env.setString("Path", p);
    }
}
Also used : ArrayList(java.util.ArrayList) Instructions(aQute.bnd.osgi.Instructions) File(java.io.File) RegistryKey(org.boris.winrun4j.RegistryKey) Description(aQute.lib.getopt.Description)

Example 30 with Description

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

the class Unix method _path.

@Description("Add the bin directory for this jpm to your PATH in the user's environment variables")
public void _path(PathOptions options) throws IOException {
    File file = options.profile() == null ? IO.getFile("~/.profile") : IO.getFile(IO.home, options.profile());
    if (!file.isFile()) {
        if (!options.force()) {
            reporter.error("No such file %s", file);
            return;
        }
        IO.store("# created by jpm\n", file);
    }
    String[] parts = System.getenv("PATH").split(":");
    List<String> paths = new ArrayList<String>(Arrays.asList(parts));
    for (int i = 0; i < parts.length; i++) {
        System.out.printf("%2d:%s %s %s%n", i, parts[i].toLowerCase().contains("jpm") ? "*" : " ", new File(parts[i]).isDirectory() ? " " : "!", parts[i]);
    }
    String bd = jpm.getBinDir().getAbsolutePath();
    String s = IO.collect(file);
    //
    if (options.remove() || options.add()) {
        if (!bd.equals(getGlobalBinDir().getAbsolutePath())) {
            s = s.replaceAll("(PATH\\s*=)" + bd + ":(.*\\$PATH)", "$1$2");
            logger.debug("removed {}", bd);
        }
    }
    if (options.delete() != null) {
        for (String delete : options.delete()) {
            s = s.replaceAll("(PATH\\s*=)" + Glob.toPattern(delete) + ":(.*\\$PATH)", "$1$2");
        }
    }
    //
    // Remove any orphans
    //
    s = s.replaceAll("\\s*(set|export)\\s+PATH\\s*=\\$PATH\\s*", "");
    List<String> additions = new ArrayList<String>();
    if (options.add()) {
        if (!bd.equals(getGlobalBinDir().getAbsolutePath())) {
            additions.add(bd);
        }
    }
    if (options.extra() != null)
        for (String add : options.extra()) {
            File f = IO.getFile(add);
            if (!f.isDirectory()) {
                reporter.error("%s is not a directory, not added", f.getAbsolutePath());
            } else {
                if (!paths.contains(f.getAbsolutePath()))
                    additions.add(f.getAbsolutePath());
            }
        }
    if (!additions.isEmpty()) {
        s += "\nexport PATH=" + Strings.join(":", additions) + ":$PATH\n";
        logger.debug("s {}", s);
    }
    IO.store(s, file);
}
Also used : ArrayList(java.util.ArrayList) 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