/** * {@inheritDoc} * * @see org.eclim.command.Command#execute(CommandLine) */ public String execute(CommandLine commandLine) throws Exception { Object family = getFamily(commandLine.getValue(Options.FAMILY_OPTION)); IJobManager manager = Job.getJobManager(); Job[] jobs = manager.find(family); StringBuffer buffer = new StringBuffer(); int maxlength = 0; for (Job job : jobs) { int length = job.toString().length(); if (length > maxlength) { maxlength = length; } } for (Job job : jobs) { if (buffer.length() > 0) { buffer.append('\n'); } buffer .append(StringUtils.rightPad(job.toString(), maxlength)) .append(" - ") .append(getStatus(job)); } return buffer.toString(); }
private static List<IBackgroundProcessingQueue> getProcessingQueues(IJobManager jobManager) { ArrayList<IBackgroundProcessingQueue> queues = new ArrayList<IBackgroundProcessingQueue>(); for (Job job : jobManager.find(null)) { if (job instanceof IBackgroundProcessingQueue) { queues.add((IBackgroundProcessingQueue) job); } } return queues; }
private void waitJobsToFinish(final Object family) { final IJobManager jobMan = Job.getJobManager(); final Job[] build = jobMan.find(family); if (build.length == 1) { try { build[0].join(); } catch (final InterruptedException e) { } } }
public static void waitForJobsToComplete(IProgressMonitor monitor) throws InterruptedException, CoreException { waitForBuildJobs(); /* * First, make sure refresh job gets all resource change events * * Resource change events are delivered after WorkspaceJob#runInWorkspace returns * and during IWorkspace#run. Each change notification is delivered by * only one thread/job, so we make sure no other workspaceJob is running then * call IWorkspace#run from this thread. * * Unfortunately, this does not catch other jobs and threads that call IWorkspace#run * so we have to hard-code workarounds * * See http://www.eclipse.org/articles/Article-Resource-deltas/resource-deltas.html */ IWorkspace workspace = ResourcesPlugin.getWorkspace(); IJobManager jobManager = Job.getJobManager(); jobManager.suspend(); try { Job[] jobs = jobManager.find(null); for (int i = 0; i < jobs.length; i++) { if (jobs[i] instanceof WorkspaceJob || jobs[i].getClass().getName().endsWith("JREUpdateJob")) { jobs[i].join(); } } workspace.run( new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) {} }, workspace.getRoot(), 0, monitor); // Now we flush all background processing queues boolean processed = flushProcessingQueues(jobManager, monitor); for (int i = 0; i < 10 && processed; i++) { processed = flushProcessingQueues(jobManager, monitor); try { Thread.sleep(10); } catch (InterruptedException e) { } } Assert.assertFalse( "Could not flush background processing queues: " + getProcessingQueues(jobManager), processed); } finally { jobManager.resume(); } waitForBuildJobs(); }
public static void assertJobManagerIdle() { final IJobManager jm = Job.getJobManager(); if (jm.isIdle()) { return; // OK! } // Make a nice message listing all the jobs and their present state. Job[] allJobs = jm.find(null); StringBuffer msg = new StringBuffer("JobManager not idle: \n"); for (Job job : allJobs) { msg.append(" Job: " + job.getName() + " State: " + stateString(job) + "\n"); } throw new AssertionFailedError(msg.toString()); }