Search in sources :

Example 1 with Forker

use of aQute.libg.forker.Forker in project bnd by bndtools.

the class bnd method __par.

/**
	 * Lets see if we can build in parallel
	 * 
	 * @throws Exception
	 */
public void __par(final ParallelBuildOptions options) throws Exception {
    ExecutorService pool = Executors.newCachedThreadPool();
    final AtomicBoolean quit = new AtomicBoolean();
    try {
        final Project p = getProject(options.project());
        final Workspace workspace = p == null || options.full() ? Workspace.getWorkspace(getBase()) : p.getWorkspace();
        if (!workspace.exists()) {
            error("cannot find workspace");
            return;
        }
        final Collection<Project> targets = p == null ? workspace.getAllProjects() : p.getDependson();
        final Forker<Project> forker = new Forker<Project>(pool);
        for (final Project dep : targets) {
            forker.doWhen(dep.getDependson(), dep, new Runnable() {

                public void run() {
                    if (!quit.get()) {
                        try {
                            dep.compile(false);
                            if (!quit.get())
                                dep.build();
                            if (!dep.isOk())
                                quit.set(true);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
            });
        }
        System.err.flush();
        forker.start(20000);
        for (Project dep : targets) {
            getInfo(dep, dep + ": ");
        }
        if (p != null && p.isOk() && !options.full()) {
            p.compile(options.test());
            p.build();
            if (options.test() && p.isOk())
                p.test();
            getInfo(p);
        }
        workspace.close();
    } finally {
        pool.shutdownNow();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Project(aQute.bnd.build.Project) ExecutorService(java.util.concurrent.ExecutorService) Forker(aQute.libg.forker.Forker) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) ZipException(java.util.zip.ZipException) Workspace(aQute.bnd.build.Workspace)

Aggregations

Project (aQute.bnd.build.Project)1 Workspace (aQute.bnd.build.Workspace)1 Forker (aQute.libg.forker.Forker)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ZipException (java.util.zip.ZipException)1 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1