@Override @TaskAction public void compile() { final Job<Void> job = new Job<Void>(getName(), new Task<Void>() { @Override public void run(@NonNull Job<Void> job, @NonNull JobContext<Void> context) throws IOException { try { JackTask.this.doMinification(); } catch (ProcessException e) { throw new IOException(e); } } }); try { SimpleWorkQueue.push(job); // wait for the task completion. job.await(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } }
while (aaptProcessJob != null) { mLogger.verbose("Thread(%1$s) : wait for {%2$s)", Thread.currentThread().getName(), aaptProcessJob.toString()); try { aaptProcessJob.awaitRethrowExceptions(); } catch (ExecutionException e) { mLogger.verbose("Exception while crunching png : " + aaptProcessJob.toString() + " : " + e.getCause()); hasExceptions = true; while((aaptProcessJob = jobs.poll()) != null) { try { aaptProcessJob.awaitRethrowExceptions(); } catch (ExecutionException e) { mLogger.verbose("Exception while crunching png : " + aaptProcessJob.toString() + " : " + e.getCause()); hasExceptions = true;
private void waitForAll(int key) throws InterruptedException { mLogger.verbose("Thread(%1$s): begin waitForAll", Thread.currentThread().getName()); ConcurrentLinkedQueue<Job<AaptProcess>> jobs = mOutstandingJobs.get(key); Job<AaptProcess> aaptProcessJob = jobs.poll(); while (aaptProcessJob != null) { mLogger.verbose("Thread(%1$s) : wait for {%2$s)", Thread.currentThread().getName(), aaptProcessJob.toString()); if (!aaptProcessJob.await()) { throw new RuntimeException( "Crunching " + aaptProcessJob.getJobTitle() + " failed, see logs"); } aaptProcessJob = jobs.poll(); } mLogger.verbose("Thread(%1$s): end waitForAll", Thread.currentThread().getName()); }
return; verbose("Thread(%1$s): scheduling %2$s", threadName, job.getJobTitle()); } catch (Exception e) { Logger.getAnonymousLogger().log(Level.WARNING, "Exception while processing task ", e); job.error(); return; job.await(); verbose("Thread(%1$s): job %2$s finished", threadName, job.getJobTitle());
@Override public void out(@Nullable String line) { if (line != null) { mLogger.verbose("AAPT notify(%1$s): %2$s", mJob, line); if (line.equalsIgnoreCase("Done")) { mOwner.reset(); mJob.finished(); } else if (line.equalsIgnoreCase("Error")) { mOwner.reset(); mJob.error(); } else { mLogger.verbose("AAPT(%1$s) discarded: %2$s", mJob, line); } } }
@Override public void runTask(@NonNull Job<ExecutionRecordWriter> job) throws Exception { job.runTask(singletonJobContext); }
final Job<Void> job = new Job<>(getName(), new com.android.builder.tasks.Task<Void>() { @Override job.awaitRethrowExceptions(); } catch (ExecutionException e) { throw new RuntimeException("Job failed, see logs for details", e.getCause());
@Override public void run(@NonNull Job<ExecutionRecordWriter> job, @NonNull JobContext<ExecutionRecordWriter> context) throws IOException { context.getPayload().write(executionRecord); job.finished(); } }));
void writeRecord(@NonNull final ExecutionRecord executionRecord) { try { workQueue.push(new Job<ExecutionRecordWriter>("recordWriter", new Task<ExecutionRecordWriter>() { @Override public void run(@NonNull Job<ExecutionRecordWriter> job, @NonNull JobContext<ExecutionRecordWriter> context) throws IOException { context.getPayload().write(executionRecord); job.finished(); } })); } catch (InterruptedException e) { e.printStackTrace(); Thread.currentThread().interrupt(); } }
@Override public void run(@NonNull Job<AaptProcess> job, @NonNull JobContext<AaptProcess> context) throws IOException { mLogger.verbose("Thread(%1$s): begin executing job %2$s", Thread.currentThread().getName(), job.getJobTitle()); context.getPayload().crunch(from, to, job); mLogger.verbose("Thread(%1$s): done executing job %2$s", Thread.currentThread().getName(), job.getJobTitle()); }
throws IOException { mLogger.verbose("Process(%1$d) %2$s job:%3$s", + hashCode(), in.getName(), job.toString()); if (!mReady.get()) { throw new RuntimeException("AAPT process not ready to receive commands"); mWriter.write("\n"); mWriter.flush(); mLogger.verbose("Processed(%1$d) %2$s job:%3$s", hashCode(), in.getName(), job.toString()); mMessages.add(String.format("Process(%1$d) processed %2$s, job: %3$s", hashCode(), in.getName(), job.toString()));
return; verbose("Thread(%1$s): scheduling %2$s", threadName, job.getJobTitle()); } catch (Exception e) { mLogger.warning("Exception while processing task %1$s", e); job.error(e); return; boolean result = job.await(); verbose("Thread(%1$s): job %2$s finished, result=%3$b", threadName, job.getJobTitle(), result);
@Override public void out(@Nullable String line) { if (line != null) { mLogger.verbose("AAPT notify(%1$s): %2$s", mJob, line); if (line.equalsIgnoreCase("Done")) { mOwner.reset(); if (mInError.get()) { mLogger.verbose("Job is in error mode, cause : %1$s", mErrorBuilder.toString()); mJob.error(new ProcessException(mErrorBuilder.toString())); } else { mJob.finished(); } } else if (line.equalsIgnoreCase("Error")) { mInError.set(true); } else { mLogger.verbose("AAPT(%1$s) discarded: %2$s", mJob, line); } } }
@Override public void runTask(@NonNull Job<AaptProcess> job) throws Exception { job.runTask(new JobContext<>(mAaptProcesses.get(Thread.currentThread().getName()))); mOutstandingJobs.get(((QueuedJob) job).key).remove(job); ConcurrentLinkedQueue<Job<AaptProcess>> jobs = mDoneJobs.get(((QueuedJob) job).key); synchronized (mDoneJobs) { if (jobs == null) { jobs = new ConcurrentLinkedQueue<>(); mDoneJobs.put(((QueuedJob) job).key, jobs); } } jobs.add(job); }
@Override public void run(@NonNull Job<AaptProcess> job, @NonNull JobContext<AaptProcess> context) throws IOException { AaptProcess aapt = context.getPayload(); if (aapt == null) { mLogger.error(null /* throwable */, "Thread(%1$s) has a null payload", Thread.currentThread().getName()); return; } mLogger.verbose("Thread(%1$s): submitting job %2$s to %3$d", Thread.currentThread().getName(), job.getJobTitle(), aapt.hashCode()); aapt.crunch(from, to, job); mLogger.verbose("Thread(%1$s): submitted job %2$s", Thread.currentThread().getName(), job.getJobTitle()); }
"job: " + job.toString()); if (!mReady.get()) { throw new RuntimeException("AAPT process not ready to receive commands"); mWriter.flush(); mLogger.verbose("Processed(" + mProcess.hashCode() + ")" + in.getName() + "job: " + job.toString()); mMessages.add("Process(" + mProcess.hashCode() + ") processed " + in.getName() + "job: " + job.toString());
@Override @TaskAction public void proguard() throws IOException, ParseException { final Job<Void> job = new Job<Void>(getName(), new com.android.builder.tasks.Task<Void>() { @Override public void run(@NonNull Job<Void> job, @NonNull JobContext<Void> context) throws IOException { try { AndroidProGuardTask.this.doMinification(); } catch (ParseException e) { throw new IOException(e); } } }); try { SimpleWorkQueue.push(job); // wait for the task completion. job.await(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } }
@Override public void runTask(@NonNull Job<AaptProcess> job) throws Exception { job.runTask( new JobContext<AaptProcess>( mAaptProcesses.get(Thread.currentThread().getName()))); mOutstandingJobs.get(((QueuedJob) job).key).remove(job); }