Search in sources :

Example 16 with Command

use of aQute.libg.command.Command in project bnd by bndtools.

the class Signer method sign.

public byte[] sign(File f) throws Exception {
    Path tmp = Files.createTempFile("sign", ".asc");
    try {
        Command cmd = new Command();
        cmd.add(this.cmd);
        cmd.add("--batch");
        cmd.add("--passphrase-fd");
        cmd.add("0");
        cmd.add("--output");
        cmd.add(tmp.toAbsolutePath().toString());
        Files.delete(tmp);
        cmd.add("-ab");
        cmd.add(f.getAbsolutePath());
        ByteArrayInputStream bin = new ByteArrayInputStream(this.passphrase);
        StringBuffer out = new StringBuffer();
        int result = cmd.execute(bin, out, System.err);
        if (result != 0)
            return null;
        return IO.read(tmp.toFile());
    } finally {
        IO.delete(tmp.toFile());
    }
}
Also used : Path(java.nio.file.Path) Command(aQute.libg.command.Command) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 17 with Command

use of aQute.libg.command.Command in project bnd by bndtools.

the class RemoteSink method launch.

@Override
public boolean launch(String areaId, Map<String, String> env, List<String> args) throws Exception {
    final AreaImpl area = getArea(areaId);
    if (area == null)
        throw new IllegalArgumentException("No such area");
    if (area.running)
        throw new IllegalStateException("Already running");
    area.command = new Command();
    area.command.addAll(args);
    area.command.setCwd(area.cwd);
    if (env != null) {
        for (Map.Entry<String, String> e : env.entrySet()) {
            area.command.var(e.getKey(), e.getValue());
        }
    }
    area.line = area.command.toString();
    PipedInputStream pin = new PipedInputStream();
    @SuppressWarnings("resource") PipedOutputStream pout = new PipedOutputStream();
    pout.connect(pin);
    area.toStdin = pout;
    area.stdin = pin;
    area.stdout = new Appender(sources, area.id, false);
    area.stderr = new Appender(sources, area.id, true);
    area.thread = new Thread(areaId + "::" + args) {

        public void run() {
            try {
                event(Event.launching, area);
                area.running = true;
                area.command.setCwd(area.cwd);
                area.command.setUseThreadForInput(true);
                area.exitCode = area.command.execute(area.stdin, area.stdout, area.stderr);
            } catch (Throwable e) {
                area.exitCode = -1;
                area.exception = e.toString();
            } finally {
                area.running = false;
                area.toStdin = null;
                area.stderr = null;
                area.stdout = null;
                area.stdin = null;
                area.command = null;
                event(Event.exited, area);
            }
        }
    };
    area.thread.start();
    return true;
}
Also used : PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) Command(aQute.libg.command.Command) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map)

Example 18 with Command

use of aQute.libg.command.Command in project bnd by bndtools.

the class RemoteSink method exit.

@Override
public int exit(String areaId) throws Exception {
    AreaImpl area = getArea(areaId);
    Command c = area.command;
    if (!area.running || c == null)
        throw new IllegalStateException("Area " + areaId + " is not running");
    c.cancel();
    area.thread.join(10000);
    return area.exitCode;
}
Also used : Command(aQute.libg.command.Command)

Example 19 with Command

use of aQute.libg.command.Command in project bnd by bndtools.

the class Project method getCommonJavac.

private Command getCommonJavac(boolean test) throws Exception {
    Command javac = new Command();
    javac.add(getProperty("javac", "javac"));
    String target = getProperty("javac.target", "1.6");
    String profile = getProperty("javac.profile", "");
    String source = getProperty("javac.source", "1.6");
    String debug = getProperty("javac.debug");
    if ("on".equalsIgnoreCase(debug) || "true".equalsIgnoreCase(debug))
        debug = "vars,source,lines";
    Parameters options = new Parameters(getProperty("java.options"), this);
    boolean deprecation = isTrue(getProperty("java.deprecation"));
    javac.add("-encoding", "UTF-8");
    javac.add("-source", source);
    javac.add("-target", target);
    if (!profile.isEmpty())
        javac.add("-profile", profile);
    if (deprecation)
        javac.add("-deprecation");
    if (test || debug == null) {
        javac.add("-g:source,lines,vars" + debug);
    } else {
        javac.add("-g:" + debug);
    }
    for (String option : options.keySet()) javac.add(option);
    StringBuilder bootclasspath = new StringBuilder();
    String bootclasspathDel = "-Xbootclasspath/p:";
    Collection<Container> bcp = Container.flatten(getBootclasspath());
    for (Container c : bcp) {
        bootclasspath.append(bootclasspathDel).append(c.getFile().getAbsolutePath());
        bootclasspathDel = File.pathSeparator;
    }
    if (bootclasspath.length() != 0) {
        javac.add(bootclasspath.toString());
    }
    return javac;
}
Also used : Parameters(aQute.bnd.header.Parameters) Command(aQute.libg.command.Command)

Example 20 with Command

use of aQute.libg.command.Command in project bnd by bndtools.

the class ProjectLauncher method launch.

public int launch() throws Exception {
    prepare();
    java = new Command();
    //
    // Handle the environment
    //
    Map<String, String> env = getRunEnv();
    for (Map.Entry<String, String> e : env.entrySet()) {
        java.var(e.getKey(), e.getValue());
    }
    java.add(project.getProperty("java", getJavaExecutable()));
    String javaagent = project.getProperty(Constants.JAVAAGENT);
    if (Processor.isTrue(javaagent)) {
        for (String agent : agents) {
            java.add("-javaagent:" + agent);
        }
    }
    String jdb = getRunJdb();
    if (jdb != null) {
        int port = 1044;
        try {
            port = Integer.parseInt(project.getProperty(Constants.RUNJDB));
        } catch (Exception e) {
        // ok, value can also be ok, or on, or true
        }
        String suspend = port > 0 ? "y" : "n";
        java.add("-Xrunjdwp:server=y,transport=dt_socket,address=" + Math.abs(port) + ",suspend=" + suspend);
    }
    java.add("-cp");
    java.add(Processor.join(getClasspath(), File.pathSeparator));
    java.addAll(getRunVM());
    java.add(getMainTypeName());
    java.addAll(getRunProgramArgs());
    if (timeout != 0)
        java.setTimeout(timeout + 1000, TimeUnit.MILLISECONDS);
    File cwd = getCwd();
    if (cwd != null)
        java.setCwd(cwd);
    logger.debug("cmd line {}", java);
    try {
        int result = java.execute(in, out, err);
        if (result == Integer.MIN_VALUE)
            return TIMEDOUT;
        reportResult(result);
        return result;
    } finally {
        cleanup();
        listeners.clear();
    }
}
Also used : Command(aQute.libg.command.Command) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) File(java.io.File)

Aggregations

Command (aQute.libg.command.Command)20 File (java.io.File)8 Jar (aQute.bnd.osgi.Jar)5 Parameters (aQute.bnd.header.Parameters)2 UTF8Properties (aQute.lib.utf8properties.UTF8Properties)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Properties (java.util.Properties)2 Resource (aQute.bnd.osgi.Resource)1 FileSet (aQute.lib.fileset.FileSet)1 CommandLine (aQute.lib.getopt.CommandLine)1 Description (aQute.lib.getopt.Description)1 Justif (aQute.lib.justif.Justif)1 Glob (aQute.libg.glob.Glob)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 PipedInputStream (java.io.PipedInputStream)1 PipedOutputStream (java.io.PipedOutputStream)1 RandomAccessFile (java.io.RandomAccessFile)1 Writer (java.io.Writer)1