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();
}
}
Aggregations