Search in sources :

Example 1 with RegistryKey

use of org.boris.winrun4j.RegistryKey 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)

Aggregations

Instructions (aQute.bnd.osgi.Instructions)1 Description (aQute.lib.getopt.Description)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 RegistryKey (org.boris.winrun4j.RegistryKey)1