org.apache.tools.ant.taskdefs.ExecTask Java Examples

The following examples show how to use org.apache.tools.ant.taskdefs.ExecTask. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MakeNBM.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private boolean pack200(final File sourceFile, final File targetFile) throws IOException {
    try (JarFile jarFile = new JarFile(sourceFile)) {
        if (isSigned(jarFile)) {
            return false;
        }

        try {
            String pack200Executable = new File(System.getProperty("java.home"),
                    "bin/pack200" + (isWindows() ? ".exe" : "")).getAbsolutePath();

            ExecTask et = (ExecTask) getProject().createTask("exec");
            et.setExecutable(pack200Executable);
            et.createArg().setFile(targetFile);
            et.createArg().setFile(sourceFile);
            et.setTaskName("pack200");
            et.setDir(sourceFile.getParentFile());
            et.execute();
            return true;
        } finally {
            if (targetFile.exists())  {
                targetFile.setLastModified(sourceFile.lastModified());
            }
        }
    }
}
 
Example #2
Source File: PluginTask.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void installPlugins(Set<CordovaPlugin> pluginsToInstall) {
    for (CordovaPlugin plugin : pluginsToInstall) {
        log(getCordovaCommand() + " -d plugin add " + plugin.getUrl());
        ExecTask exec = (ExecTask) getProject().createTask("exec");
        final Environment.Variable variable = new Environment.Variable();
        variable.setKey(getProject().getProperty("cordova.path.key"));
        variable.setValue(getProject().getProperty("cordova.path.value"));
        exec.addEnv(variable);

        exec.setExecutable(getCordovaCommand());
        exec.createArg().setValue("-d");
        exec.createArg().setValue("plugin");
        exec.createArg().setValue("add");
        for (String arg : plugin.getUrl().split("\\s+")) {
            exec.createArg().setValue(arg);
        }
        exec.setFailonerror(true);
        exec.setResolveExecutable(true);
        exec.setSearchPath(true);
        exec.execute();
    }
}
 
Example #3
Source File: PluginTask.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void uninstallPlugins(Set<CordovaPlugin> pluginsToUninstall) {
    for (CordovaPlugin plugin : pluginsToUninstall) {
        log(getCordovaCommand() + " -d plugin remove " + plugin.getId());
        ExecTask exec = (ExecTask) getProject().createTask("exec");
        final Environment.Variable variable = new Environment.Variable();
        variable.setKey(getProject().getProperty("cordova.path.key"));
        variable.setValue(getProject().getProperty("cordova.path.value"));
        exec.addEnv(variable);
        exec.setResolveExecutable(true);
        exec.setSearchPath(true);

        exec.setExecutable(getCordovaCommand());
        exec.createArg().setValue("-d");
        exec.createArg().setValue("plugin");
        exec.createArg().setValue("remove");
        exec.createArg().setValue(plugin.getId());
        exec.execute();
    }
}
 
Example #4
Source File: ReadConfigTask.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private String getMacPath(String path) {
    ExecTask exec = (ExecTask) getProject().createTask("exec");
    exec.setExecutable("/bin/bash");
    exec.createArg().setLine("-lc env");
    exec.setOutputproperty("mac.path");
    exec.execute();
    String property = getProperty("mac.path");
    if (property != null) {
        for (String line : property.split(System.getProperty("line.separator"))) {
            if (line.startsWith("PATH=")) {
                return line.substring(5);
            }
        }
    }
    return getProperty(path);
}
 
Example #5
Source File: PluginTask.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void initCurrent() {
    currentPlugins = new HashSet<CordovaPlugin>();

    log(getCordovaCommand() + " plugins ");

    ExecTask exec = (ExecTask) getProject().createTask("exec");
    final Environment.Variable variable = new Environment.Variable();
    final String key = getProject().getProperty("cordova.path.key");
    variable.setKey(key);
    final String val = getProject().getProperty("cordova.path.value");
    variable.setValue(val);
    exec.addEnv(variable);
    exec.setResolveExecutable(true);
    exec.setSearchPath(true);

    exec.setExecutable(getCordovaCommand());
    exec.createArg().setValue("plugins");
    exec.setOutputproperty("cordova.current.plugins");
    exec.execute();

    String plugins = getProject().getProperty("cordova.current.plugins");
    if (compareCordovaVersion("3.5.0") >= 0) {
        try {
            BufferedReader r = new BufferedReader(new StringReader(plugins));
            String line;
            while((line=r.readLine()) != null) {
                if (line.startsWith("No plugins added")) {
                    break;
                }
                currentPlugins.add(new CordovaPlugin(line.substring(0, line.indexOf(" ")), ""));
            }
        } catch (IOException ex) {
            log(ex, Project.MSG_ERR);
        }
    } else {
        final int startPar = plugins.indexOf("[");
        if (startPar < 0) {
            //empty
            return;
        }
        plugins = plugins.substring(startPar + 1, plugins.lastIndexOf("]")).trim();
        StringTokenizer tokenizer = new StringTokenizer(plugins, ",");
        while (tokenizer.hasMoreTokens()) {
            String name = tokenizer.nextToken().trim();
            currentPlugins.add(new CordovaPlugin(name.substring(name.indexOf("'") + 1, name.lastIndexOf("'")), ""));
        }
    }
}