Search in sources :

Example 6 with Command

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

the class MavenDeployCmd 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)

Example 7 with Command

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

the class MavenDeployCmd method javadoc.

private Jar javadoc(File tmp, Project b, Set<String> exports) throws Exception {
    Command command = new Command();
    command.add(b.getProperty("javadoc", "javadoc"));
    command.add("-d");
    command.add(tmp.getAbsolutePath());
    command.add("-sourcepath");
    command.add(Processor.join(b.getSourcePath(), File.pathSeparator));
    for (String packageName : exports) {
        command.add(packageName);
    }
    StringBuilder out = new StringBuilder();
    StringBuilder err = new StringBuilder();
    Command c = new Command();
    c.setTrace();
    int result = c.execute(out, err);
    if (result == 0) {
        Jar jar = new Jar(tmp);
        b.addClose(jar);
        return jar;
    }
    b.error("Error during execution of javadoc command: %s / %s", out, err);
    return null;
}
Also used : Command(aQute.libg.command.Command) Jar(aQute.bnd.osgi.Jar)

Example 8 with Command

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

the class Tool method doJavadoc.

public Jar doJavadoc(Map<String, String> options, boolean exportsOnly) throws Exception {
    if (!hasSources())
        return new Jar("javadoc");
    IO.mkdirs(javadoc);
    List<String> args = new ArrayList<>();
    args.add("-quiet");
    args.add("-protected");
    args.add(String.format("%s '%s'", "-d", fileName(javadoc)));
    args.add("-charset 'UTF-8'");
    args.add(String.format("%s '%s'", "-sourcepath", fileName(sources)));
    Properties pp = new UTF8Properties();
    pp.putAll(options);
    String name = manifest.getBundleName();
    if (name == null)
        name = manifest.getBundleSymbolicName().getKey();
    String version = manifest.getBundleVersion();
    if (version == null)
        version = Version.LOWEST.toString();
    String bundleDescription = manifest.getBundleDescription();
    if (bundleDescription != null && !Strings.trim(bundleDescription).isEmpty()) {
        printOverview(name, version, bundleDescription);
    }
    set(pp, "-doctitle", name);
    set(pp, "-windowtitle", name);
    set(pp, "-header", manifest.getBundleVendor());
    set(pp, "-bottom", manifest.getBundleCopyright());
    set(pp, "-footer", manifest.getBundleDocURL());
    args.add("-tag 'Immutable:t:\"Immutable\"'");
    args.add("-tag 'ThreadSafe:t:\"ThreadSafe\"'");
    args.add("-tag 'NotThreadSafe:t:\"NotThreadSafe\"'");
    args.add("-tag 'GuardedBy:mf:\"Guarded By:\"'");
    args.add("-tag 'security:m:\"Required Permissions\"'");
    args.add("-tag 'noimplement:t:\"Consumers of this API must not implement this interface\"'");
    for (Enumeration<?> e = pp.propertyNames(); e.hasMoreElements(); ) {
        String key = (String) e.nextElement();
        String value = pp.getProperty(key);
        if (key.startsWith("-")) {
            //
            // Allow people to add the same command multiple times
            // by suffixing it with '.' something
            //
            int n = key.lastIndexOf('.');
            if (n > 0) {
                key = key.substring(0, n);
            }
            args.add(String.format("%s '%s'", key, escape(value)));
        }
    }
    FileSet set = new FileSet(sources, "**.java");
    for (File f : set.getFiles()) {
        args.add(String.format("'%s'", fileName(f)));
    }
    if (exportsOnly) {
        Parameters exports = manifest.getExportPackage();
        for (String packageName : exports.keySet()) {
            args.add(String.format("'%s'", packageName));
        }
    }
    StringBuilder sb = new StringBuilder();
    for (String arg : args) {
        sb.append(arg);
        sb.append('\n');
    }
    IO.store(sb, javadocOptions);
    Command command = new Command();
    command.add(getProperty("javadoc", "javadoc"));
    command.add("@" + fileName(javadocOptions));
    StringBuilder out = new StringBuilder();
    StringBuilder err = new StringBuilder();
    int result = command.execute(out, err);
    if (result != 0) {
        warning("Error during execution of javadoc command: %s\n******************\n%s", out, err);
    }
    return new Jar(javadoc);
}
Also used : Parameters(aQute.bnd.header.Parameters) FileSet(aQute.lib.fileset.FileSet) ArrayList(java.util.ArrayList) Properties(java.util.Properties) UTF8Properties(aQute.lib.utf8properties.UTF8Properties) Command(aQute.libg.command.Command) Jar(aQute.bnd.osgi.Jar) File(java.io.File) UTF8Properties(aQute.lib.utf8properties.UTF8Properties)

Example 9 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 10 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)

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