Search in sources :

Example 1 with Command

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

the class Project method compile.

// TODO test format parametsr
public void compile(boolean test) throws Exception {
    Command javac = getCommonJavac(false);
    javac.add("-d", getOutput().getAbsolutePath());
    StringBuilder buildpath = new StringBuilder();
    String buildpathDel = "";
    Collection<Container> bp = Container.flatten(getBuildpath());
    logger.debug("buildpath {}", getBuildpath());
    for (Container c : bp) {
        buildpath.append(buildpathDel).append(c.getFile().getAbsolutePath());
        buildpathDel = File.pathSeparator;
    }
    if (buildpath.length() != 0) {
        javac.add("-classpath", buildpath.toString());
    }
    List<File> sp = new ArrayList<File>(getAllsourcepath());
    StringBuilder sourcepath = new StringBuilder();
    String sourcepathDel = "";
    for (File sourceDir : sp) {
        sourcepath.append(sourcepathDel).append(sourceDir.getAbsolutePath());
        sourcepathDel = File.pathSeparator;
    }
    javac.add("-sourcepath", sourcepath.toString());
    Glob javaFiles = new Glob("*.java");
    List<File> files = javaFiles.getFiles(getSrc(), true, false);
    for (File file : files) {
        javac.add(file.getAbsolutePath());
    }
    if (files.isEmpty()) {
        logger.debug("Not compiled, no source files");
    } else
        compile(javac, "src");
    if (test) {
        javac = getCommonJavac(true);
        javac.add("-d", getTestOutput().getAbsolutePath());
        Collection<Container> tp = Container.flatten(getTestpath());
        for (Container c : tp) {
            buildpath.append(buildpathDel).append(c.getFile().getAbsolutePath());
            buildpathDel = File.pathSeparator;
        }
        if (buildpath.length() != 0) {
            javac.add("-classpath", buildpath.toString());
        }
        sourcepath.append(sourcepathDel).append(getTestSrc().getAbsolutePath());
        javac.add("-sourcepath", sourcepath.toString());
        javaFiles.getFiles(getTestSrc(), files, true, false);
        for (File file : files) {
            javac.add(file.getAbsolutePath());
        }
        if (files.isEmpty()) {
            logger.debug("Not compiled for test, no test src files");
        } else
            compile(javac, "test");
    }
}
Also used : Command(aQute.libg.command.Command) ArrayList(java.util.ArrayList) Glob(aQute.libg.glob.Glob) File(java.io.File)

Example 2 with Command

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

the class JUnitLauncher method launch.

public int launch() throws Exception {
    java = new Command();
    java.add(project.getProperty("java", "java"));
    java.add("-cp");
    java.add(cp.toString());
    java.addAll(project.getRunVM());
    java.add(getMainTypeName());
    java.addAll(fqns);
    if (timeout != 0)
        java.setTimeout(timeout + 1000, TimeUnit.MILLISECONDS);
    logger.debug("cmd line {}", java);
    try {
        int result = java.execute(System.in, System.err, System.err);
        if (result == Integer.MIN_VALUE)
            return TIMEDOUT;
        reportResult(result);
        return result;
    } finally {
        cleanup();
    }
}
Also used : Command(aQute.libg.command.Command)

Example 3 with Command

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

the class JartoolSigner method sign.

public void sign(Builder builder, String alias) throws Exception {
    File f = builder.getFile(keystore);
    if (!f.isFile()) {
        builder.error("Invalid keystore %s", f.getAbsolutePath());
        return;
    }
    Jar jar = builder.getJar();
    File tmp = File.createTempFile("signdjar", ".jar");
    tmp.deleteOnExit();
    jar.write(tmp);
    Command command = new Command();
    command.add(path);
    if (keystore != null) {
        command.add("-keystore");
        command.add(f.getAbsolutePath());
    }
    if (storetype != null) {
        command.add("-storetype");
        command.add(storetype);
    }
    if (keypass != null) {
        command.add("-keypass");
        command.add(keypass);
    }
    if (storepass != null) {
        command.add("-storepass");
        command.add(storepass);
    }
    if (sigFile != null) {
        command.add("-sigFile");
        command.add(sigFile);
    }
    if (digestalg != null) {
        command.add("-digestalg");
        command.add(digestalg);
    }
    if (tsa != null) {
        command.add("-tsa");
        command.add(tsa);
    }
    if (tsacert != null) {
        command.add("-tsacert");
        command.add(tsacert);
    }
    if (tsapolicyid != null) {
        command.add("-tsapolicyid");
        command.add(tsapolicyid);
    }
    command.add(tmp.getAbsolutePath());
    command.add(alias);
    logger.debug("Jarsigner command: {}", command);
    command.setTimeout(20, TimeUnit.SECONDS);
    StringBuilder out = new StringBuilder();
    StringBuilder err = new StringBuilder();
    int exitValue = command.execute(out, err);
    if (exitValue != 0) {
        builder.error("Signing Jar out: %s%nerr: %s", out, err);
    } else {
        logger.debug("Signing Jar out: {}\nerr: {}", out, err);
    }
    Jar signed = new Jar(tmp);
    builder.addClose(signed);
    Map<String, Resource> dir = signed.getDirectories().get("META-INF");
    for (Entry<String, Resource> entry : dir.entrySet()) {
        String path = entry.getKey();
        if (path.matches(".*\\.(DSA|RSA|SF|MF)$")) {
            jar.putResource(path, entry.getValue());
        }
    }
    jar.setDoNotTouchManifest();
}
Also used : Command(aQute.libg.command.Command) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar) File(java.io.File)

Example 4 with Command

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

the class MavenCommand method sign.

private void sign(File file, String passphrase) throws Exception {
    logger.debug("signing {}", file);
    File asc = new File(file.getParentFile(), file.getName() + ".asc");
    IO.delete(asc);
    Command command = new Command();
    command.setTrace();
    command.add(getProperty("gpg", "gpg"));
    if (passphrase != null)
        command.add("--passphrase", passphrase);
    // not the -b!!
    command.add("-ab", "--sign");
    command.add(file.getAbsolutePath());
    System.err.println(command);
    StringBuilder stdout = new StringBuilder();
    StringBuilder stderr = new StringBuilder();
    int result = command.execute(stdout, stderr);
    if (result != 0) {
        error("gpg signing %s failed because %s", file, "" + stdout + stderr);
    }
}
Also used : Command(aQute.libg.command.Command) File(java.io.File)

Example 5 with Command

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

the class MavenDeploy method maven_gpg_sign_and_deploy.

// gpg:sign-and-deploy-file \
// -Durl=http://oss.sonatype.org/service/local/staging/deploy/maven2
// \
// -DrepositoryId=sonatype-nexus-staging \
// -DupdateReleaseInfo=true \
// -DpomFile=pom.xml \
// -Dfile=/Ws/bnd/biz.aQute.bndlib/tmp/biz.aQute.bndlib.jar \
// -Dpassphrase=a1k3v3t5x3
private void maven_gpg_sign_and_deploy(Project b, File file, String classifier, File pomFile) throws Exception {
    Command command = new Command();
    command.setTrace();
    command.add(b.getProperty("mvn", "mvn"));
    command.add("gpg:sign-and-deploy-file", "-DreleaseInfo=true", "-DpomFile=pom.xml");
    command.add("-Dfile=" + file.getAbsolutePath());
    command.add("-DrepositoryId=" + repository);
    command.add("-Durl=" + url);
    optional(command, "passphrase", passphrase);
    optional(command, "keyname", keyname);
    optional(command, "homedir", homedir);
    optional(command, "classifier", classifier);
    optional(command, "pomFile", pomFile == null ? null : pomFile.getAbsolutePath());
    StringBuilder stdout = new StringBuilder();
    StringBuilder stderr = new StringBuilder();
    int result = command.execute(stdout, stderr);
    if (result != 0) {
        b.error("Maven deploy to %s failed to sign and transfer %s because %s", repository, file, "" + stdout + stderr);
    }
}
Also used : Command(aQute.libg.command.Command)

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