Пример #1
0
  /**
   * Schedule (or postpone) the job to execute after a given delay. Any previous pending job is
   * canceled.
   */
  public final void reschedule(int delay) {
    final Job newJob =
        new Job(actualJob.getName() + " (Delayed)") {
          protected IStatus run(IProgressMonitor monitor) {
            synchronized (jobLock) {
              if (job == this) {
                actualJob.schedule();
                return Status.OK_STATUS;
              } else {
                return Status.CANCEL_STATUS;
              }
            }
          }
        };
    newJob.setPriority(Job.INTERACTIVE);

    // System jobs are not visible in the GUI. I leave it for now, it's quite
    // interesting to see auto update tasks in the jobs panel.
    //
    // newJob.setSystem(true);

    synchronized (jobLock) {
      /*
       * Cancel previous job, but start the new one regardless of the previous job's
       * running state.
       */
      if (job != null && job.getState() == Job.SLEEPING) {
        job.cancel();
      }

      job = newJob;
      job.schedule(delay);
    }
  }
Пример #2
0
  /**
   * Propagates the markers of the given source file, to the corresponding file at the features
   * folder.
   *
   * @param sourceFile The composed file
   */
  public void addFile(IFile sourceFile) {
    String fileExtension = sourceFile.getFileExtension();
    if (fileExtension == null) {
      return;
    }
    if ("java".equals(fileExtension) || "c".equals(fileExtension) || "h".equals(fileExtension)) {
      if (!composedFiles.contains(sourceFile)) {
        addComposedFile(sourceFile);
      }
      if (job == null) {
        job =
            new Job("Propagate problem markers") {
              @Override
              public IStatus run(IProgressMonitor monitor) {
                propagateMarkers();
                return Status.OK_STATUS;
              }
            };
        job.setPriority(Job.SHORT);
        job.schedule();
      }

      if (job.getState() == Job.NONE) {
        job.schedule();
      }
    }
  }
 private synchronized void refresh(ProjectDependency key) {
   if (dependenciesViewer == null || dependenciesViewer.getTable().isDisposed()) {
     return;
   }
   // dependenciesViewer.refresh();
   try {
     for (TableItem item : dependenciesViewer.getTable().getItems()) {
       @SuppressWarnings("unchecked")
       final ProjectDependency projectDep = (ProjectDependency) item.getData();
       if (projectDep.equals(key)) {
         dependenciesViewer.refresh(projectDep, false);
         // Don't force check when there's an existing dependency, only uncheck if they're is not.
         if (dependencyMap.get(projectDep) == null) {
           Job job = identificationJobs.get(projectDep);
           if (job != null && job.getState() == Job.NONE) {
             dependenciesViewer.setChecked(projectDep, false);
           }
         }
         setPageComplete(hasNoRunningJobs());
         return;
       }
     }
   } finally {
     displayWarning();
     enableIdentificationButtons();
   }
 }
  public Object execute(ExecutionEvent event) throws ExecutionException {

    Job progressJob = UpdateStudioJob.getInstance();

    if ((progressJob != null)
        && ((progressJob.getState() == Job.WAITING) || (progressJob.getState() == Job.RUNNING))) {
      EclipseUtils.showInformationDialog(
          InstallerNLS.UpdateStudio_UpdateAlreadyRunningTitle,
          InstallerNLS.UpdateStudio_UpdateAlreadyRunningMsg);
    } else {
      progressJob =
          UpdateStudioJob.createJob(InstallerNLS.UpdateStudio_CheckingForUpdatesJobDescription);
      progressJob.setUser(true);
      progressJob.schedule();
    }

    return null;
  }
 /** Schedule an update. */
 void scheduleUpdate() {
   if (PlatformUI.isWorkbenchRunning()) {
     // make sure we don't schedule too often
     boolean scheduleUpdate = false;
     synchronized (updateScheduled) {
       if (!updateScheduled.value || updateJob.getState() == Job.NONE) {
         updateScheduled.value = scheduleUpdate = true;
       }
     }
     if (scheduleUpdate) updateJob.schedule(100);
   }
 }
 private boolean isJobInFamilyRunning(Object family) {
   Job[] jobs = Job.getJobManager().find(family);
   if (jobs != null && jobs.length > 0) {
     for (int i = 0; i < jobs.length; i++) {
       Job job = jobs[i];
       if (job.getState() != Job.NONE) {
         return true;
       }
     }
   }
   return false;
 }
Пример #7
0
 @Override
 public String getFailureMessage() {
   String message = "---JOB RUN ERROR---";
   if (allJobs != null) {
     message += "\nJobs in family \"" + family + "\" still running at time of last test:";
     for (Job job : allJobs) {
       message += "\n\"" + job.getName() + "\" with state " + job.getState();
     }
   } else {
     message += "\nTimeout happened before first test.";
   }
   return message;
 }
Пример #8
0
 private String getStatus(Job job) {
   int status = job.getState();
   switch (status) {
     case Job.RUNNING:
       return "running";
     case Job.SLEEPING:
       return "sleeping";
     case Job.WAITING:
       return "waiting";
     case Job.NONE:
       return "none";
   }
   return StringUtils.EMPTY;
 }
Пример #9
0
 @Override
 public void dispose() {
   if (job != null) {
     if (job.getState() == Job.RUNNING) job.cancel();
     job = null;
   }
   getSite().getPage().removePartListener(editorListener);
   if (featureModelEditor != null) {
     featureModelEditor.getOriginalFeatureModel().removeListener(modelListener);
     featureModelEditor.getFeatureModel().removeListener(modelListener);
     featureModelEditor = null;
   }
   super.dispose();
 }
 public static String stateString(Job job) {
   int state = job.getState();
   switch (state) {
     case Job.RUNNING:
       return "RUNNING";
     case Job.SLEEPING:
       return "SLEEPING";
     case Job.WAITING:
       return "WAITING";
     case Job.NONE:
       return "NONE";
     default:
       return "" + state;
   }
 }
Пример #11
0
  private void refresh() {
    if (job != null && job.getState() == Job.RUNNING) job.cancel();

    job =
        new Job("Updating Feature Model Edits") {
          @Override
          protected IStatus run(IProgressMonitor monitor) {
            if (featureModelEditor == null) contentProvider.defaultContent();
            else
              contentProvider.calculateContent(
                  featureModelEditor.getOriginalFeatureModel(),
                  featureModelEditor.getFeatureModel());
            return Status.OK_STATUS;
          }
        };
    job.setPriority(Job.LONG);
    job.schedule();
  }
Пример #12
0
  public static boolean serve(
      HgRoot hgRoot,
      int port,
      String prefixPath,
      String name,
      String webdirConf,
      boolean stdio,
      boolean ipv6) {

    Job[] jobs = Job.getJobManager().find(HgServeClient.class);
    for (Job job : jobs) {
      ServeRule rule = (ServeRule) job.getRule();
      if (rule != null && rule.port == port && job.getState() == Job.RUNNING) {
        return false;
      }
    }

    new HgServeJob(hgRoot, port, prefixPath, name, webdirConf, ipv6, stdio).schedule();
    return true;
  }
Пример #13
0
  /**
   * Wait untill will not be empty for timeout
   *
   * @param timeout
   * @throws InterruptedException
   */
  public void join(long timeout) throws InterruptedException {
    SWTTeslaActivator.debugLog("UIJobCollector is going to join");
    long startTime = System.currentTimeMillis();
    // Context ctx = ContextManagement.currentContext();
    while (true) {
      removeCanceledJobs();
      long delta = System.currentTimeMillis() - startTime;
      if (delta > timeout) {
        break;
      }
      if (isJoinEmpty()) {
        break;
      }

      List<Job> jobs2 = getJobs();
      for (Job job : jobs2) {
        SWTTeslaActivator.debugLog("Waiting for job:" + job.getName() + " " + job.getState());
      }
      SWTTeslaActivator.debugLog("UIJobCollector is going to join");
      Thread.sleep(50);
    }
  }
Пример #14
0
 public void enable() {
   this.state = true;
   this.needDisable = false;
   // Add all current jobs to wait queue
   Job[] find = Job.getJobManager().find(null);
   for (Job job : find) {
     if ((job instanceof UIJob && job.getState() != Job.SLEEPING)
         || job.belongsTo(getFamilyAutoBuild())
         || job.isUser()) {
       JobStatus status = calcJobStatus(job, (long) 0);
       if (JobStatus.REQUIRED.equals(status)) {
         if (job.belongsTo(TeslaSWTAccess.getDecoratorManagerFamily())) {
           JobsManager.getInstance().nulifyTime(job);
         }
         JobInfo jobInfo = getOrCreateJobInfo(job);
         if (jobInfo.rescheduleCounter < TeslaLimits.getJobNullifyRescheduleMaxValue()) {
           JobsManager.getInstance().nulifyTime(job);
         }
       }
     }
   }
 }
  private void compileAndDownloadAppLoader(final String id) {

    job =
        new WorkspaceJob(Messages.CUSTOMERLOADER) {
          private String androidST;
          private String iosST;

          @Override
          public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
            monitor.beginTask("package Resource:", 101);
            monitor.setTaskName(Messages.LOADERPATH);
            int i = 0;
            try {
              while (true) {
                if (monitor.isCanceled()) {
                  return close();
                }
                String message = network_instance.getLoaderState(pkgId, cookie, ip);
                JSONObject json;
                json = new JSONObject(message);
                String status = json.getString("status");
                if (status.equals("0")) {
                  final String errorStr = json.getString("msg");
                  Display.getDefault()
                      .asyncExec(
                          new Runnable() {

                            @Override
                            public void run() {
                              MessageDialog.openError(
                                  Display.getCurrent().getActiveShell(), "\u5931\u8D25", errorStr);
                            }
                          });
                  return Status.CANCEL_STATUS;
                } else {
                  String body = json.getString("body");
                  JSONObject result = new JSONObject(body);
                  androidST = result.getString("androidST");
                  iosST = result.getString("iosST");

                  if (androidST.equals("0") || iosST.equals("0")) {
                    monitor.subTask(Messages.UNPACKINFO);
                    if (i == 50) {
                      continue;
                    } else {
                      i++;
                      Thread.sleep(10000);
                      monitor.worked(1);
                    }
                  } else if (androidST.equals("7") || iosST.equals("7")) {

                    Display.getDefault()
                        .syncExec(
                            new Runnable() {

                              @Override
                              public void run() {
                                MessageDialog.openError(
                                    Display.getCurrent().getActiveShell(),
                                    "Error",
                                    Messages.COMMITTOCLOUD);
                              }
                            });
                    isTrue = false;
                    break;
                  } else if (androidST.equals("1") && iosST.equals("1")) {
                    android_log = result.getString("android_log");
                    ios_log = result.getString("ios_log");
                    String apkPath = result.getString("apkPath");
                    String ipaPath = result.getString("ipaPath");
                    apackageName = result.getString("packageName");
                    ipackageName = result.getString("iosAppIds");
                    version = result.getString("version");
                    if (i != 50) {
                      i++;
                      monitor.worked(1);
                      continue;
                    }
                    File file = new File(IDEUtil.getInstallPath() + "/apploader");
                    if (!file.exists()) {
                      file.mkdirs();
                    }
                    DownLoadUtil.downZip1(
                        apkPath,
                        IDEUtil.getInstallPath()
                            + "/apploader/"
                            + id
                            + "/load.apk", // 下载路径需要修改为/apploder/appid/load.apk
                        new SubProgressMonitor(monitor, 25));
                    DownLoadUtil.downZip1(
                        ipaPath,
                        IDEUtil.getInstallPath() + "/apploader/" + id + "/load.ipa",
                        new SubProgressMonitor(monitor, 25));
                    saveApploaderInfo();
                    isTrue = true;
                    break;
                  } else {
                    Display.getDefault()
                        .asyncExec(
                            new Runnable() {
                              @Override
                              public void run() {
                                String androidMessage =
                                    compileInfo.get(androidST) == null
                                        ? ""
                                        : compileInfo.get(androidST);
                                String iosMessage =
                                    compileInfo.get(iosST) == null ? "" : compileInfo.get(iosST);
                                String message = androidMessage + iosMessage;
                                if (message.equals("")) {
                                  message = Messages.UNKNOWERROR;
                                }
                                MessageDialog.openError(
                                    Display.getCurrent().getActiveShell(),
                                    Messages.ERROR,
                                    message + Messages.BROWSERERROR);
                                if (!androidMessage.equals("")) {
                                  openErrorMessage(android_log);
                                }
                                if (!iosMessage.equals("")) {
                                  openErrorMessage(ios_log);
                                }
                              }
                            });

                    return Status.CANCEL_STATUS;
                  }
                }
              }
              monitor.worked(1);
              monitor.done();
            } catch (UnsupportedEncodingException e) {
              return closeAndShowMessage(Messages.SERVICEBUSY);
            } catch (JSONException e1) {
              return closeAndShowMessage(Messages.DATAANALYSISERROR);
            } catch (IOException e) {
              return closeAndShowMessage(Messages.SERVICEDATAERROR);
            } catch (InterruptedException e) {
              e.printStackTrace();
            }

            return Status.OK_STATUS;
          }

          private IStatus close() {
            return Status.CANCEL_STATUS;
          }

          private IStatus closeAndShowMessage(final String errorMessage) {
            return Status.CANCEL_STATUS;
          }
        };
    job.setUser(true);
    job.schedule();
    job.getState();

    job.addJobChangeListener(
        new JobChangeAdapter() {
          public void done(IJobChangeEvent event) {
            if (event.getResult().isOK() && isTrue)
              Display.getDefault()
                  .syncExec(
                      new Runnable() {
                        public void run() {
                          MessageDialog.openInformation(
                              null, Messages.PackageAppItemDialog_SUCESS, Messages.COMPILESUCCESS);
                        }
                      });
            else
              Display.getDefault()
                  .syncExec(
                      new Runnable() {
                        public void run() {
                          MessageDialog.openError(
                              null, Messages.PackageAppItemDialog_EXCEPTION, Messages.COMPILERROR);
                        }
                      });
          }
        });
  }
Пример #16
0
  public boolean isEmpty(Context context, Q7WaitInfoRoot info) {
    // Filter already executed UI jobs with async finish status.
    List<Job> realJobs = new ArrayList<Job>();
    long current = System.currentTimeMillis();
    boolean wasInStepMode = false;
    List<Job> jobsInUI = new ArrayList<Job>();
    synchronized (jobs) {
      // Remove all canceled jobs
      removeCanceledJobs();
      if (jobs.isEmpty()) {
        return logReturnResult(true, realJobs, jobsInUI, info);
      }
      for (JobInfo jobInfo : jobs.values()) {
        if (!jobInfo.isActive()) continue;
        Job job = jobInfo.job;
        IJobCollector[] collectors = JobCollectorExtensions.getDefault().getCollectors();
        boolean allowSkip = true;
        for (IJobCollector ext : collectors) {
          if (ext.noSkipMode(job)) {
            allowSkip = false;
            break;
          }
        }
        if (allowSkip) {
          continue;
        }
        // SWTTeslaActivator.debugLog("Waiting job:" + job.getName() +
        // ": "
        // + job.getClass().getName());
        long jobStartTime = jobInfo.startingTime;

        if (job.getClass().getName().contains("org.eclipse.debug.internal.ui.DebugUIPlugin$")) {
          // It looks like background launching job.
          Thread thread = job.getThread();
          if (thread == null) {
            SWTTeslaActivator.logToReport("Active job " + job.getName() + " has no thread");
            jobInfo.done(false);
          }
          Context ctx = ContextManagement.makeContext(thread.getStackTrace());
          // If Autobuild job is active and on lock and there is Modal
          // Dialog in main thread,
          // lets' skip job from important for us.
          if (ctx.contains("java.util.concurrent.locks.LockSupport", "park")
              || ctx.contains("java.lang.Object", "wait")) {
            // We are waiting some stuff, let's check if main thread
            // have a MessageDialog and if so skip this job right
            // now.
            if (context.contains("org.eclipse.jface.dialogs.MessageDialogWithToggle", "open")
                || context.contains("org.eclipse.jface.dialogs.MessageDialog", "open")) {
              // Skip job from processing since it in lock and
              // waits for a dialog.
              SWTTeslaActivator.logToReport(
                  "Active job "
                      + job.getName()
                      + " has skipped since it in lock state and Message dialog are active");
              continue;
            }
          }
        }

        if (jobInfo.checkForTimeout) {
          if (jobStartTime + TeslaLimits.getStepModeEnableTimeout() < current
              && job.getState() == Job.RUNNING
              && stepModeNext < current) {
            // Job is sleepping to long time already.
            // Check for job are slepping
            // String name = job.getClass().getName();
            // Locate thread
            Thread thread = job.getThread();
            if (thread == null) {
              SWTTeslaActivator.logToReport("Active job " + job.getName() + " has no thread");
              jobInfo.done(false);
            }
            Context ctx = ContextManagement.makeContext(thread.getStackTrace());
            // if (ctx.contains(
            // "org.eclipse.jface.operation.ModalContext$ModalContextThread",
            // "block")) {
            // // Skip model context, since it could
            // continue;
            // }

            if (ctx.contains("java.lang.Thread", "sleep")
                || ctx.contains("java.lang.Object", "wait")
                || ctx.contains("java.util.concurrent.locks.LockSupport", "park")) {
              /*
               * Job are in Thread.sleep(), lets allow one
               * operation.
               */
              if (!jobInfo.jobInStepMode) {
                // Print step information
                SWTTeslaActivator.logToReport(
                    "---->>> Begin step mode for Job: "
                        + getCurrentReportNodeName()
                        + " <<---\n(skipping)"
                        + getJobMessage(jobInfo));
              }
              jobInfo.jobInStepMode = true;
              wasInStepMode = true;
              continue;
            }
          }

          long timeout = TeslaLimits.getJobTimeout();
          if (job.belongsTo(getFamilyAutoBuild())) {
            timeout = TeslaLimits.getAutoBuildJobTimeout();
          }
          if (jobInfo.jobInStepMode) {
            timeout = TeslaLimits.getStepModeTimeout();
          }
          if (job.getClass().getName().contains("org.eclipse.debug.internal.ui.DebugUIPlugin")) {
            timeout = TeslaLimits.getDebugJobTimeout();
          }
          if (jobStartTime + timeout < current) {
            if (context != null && TeslaEventManager.getManager().isJobInSyncExec(job, context)) {
              // Remove from stop waited jobs if called sync
              // exec
              jobInfo.checkForTimeout = false;
            } else {
              printJobTimeoutLogEntry(job);
              continue;
            }
          }
        }
        if (context != null) {
          if (isAsyncSupported()) {
            // If we are executed from async finished job lets
            // filter it
            if (JobsManager.getInstance().isFinishedAsyncJob(job)) {
              if (context.containsClass(job.getClass().getName())) {
                jobsInUI.add(job);
                continue;
              }
            }
          }
          if (isSyncSupported()) {
            // Check for any other job running Display.sleep()
            if (context.contains(Display.class.getName(), "sleep")) {
              if (TeslaEventManager.getManager().isJobInSyncExec(job, context)) {
                // If and only if job is already in synchronizer
                Map<Thread, StackTraceElement[]> traces = Thread.getAllStackTraces();
                Set<String> names = getSuperClassNames(job);
                Thread jobThread = null;
                Context jobContext = null;
                for (Map.Entry<Thread, StackTraceElement[]> thread : traces.entrySet()) {
                  Context ctx = ContextManagement.makeContext(thread.getValue());
                  for (String name : names) {
                    if (ctx.contains("org.eclipse.core.internal.jobs.Worker", "run")
                        && ctx.contains(name, "run")) {
                      jobThread = thread.getKey();
                      jobContext = ctx;
                    }
                  }
                }
                if (jobThread != null && jobContext != null) {
                  if (jobContext.contains("org.eclipse.ui.internal.UISynchronizer", "syncExec")
                      && jobContext.contains("org.eclipse.ui.internal.Semaphore", "acquire")) {
                    if (!SWTUIPlayer.hasRunnables(RWTUtils.findDisplay())) {
                      // also check what sync exec are on
                      // current stack trace
                      List<Context> execs = TeslaEventManager.getManager().getSyncExecs();
                      boolean toContinue = true;
                      for (Context context2 : execs) {
                        StackTraceElement[] stackTrace = context2.getStackTrace();
                        String className = null;
                        for (int i = 0; i < stackTrace.length; i++) {
                          if (stackTrace[i].getClassName().equals("org.eclipse.swt.widgets.Display")
                              && stackTrace[i].getMethodName().equals("syncExec")) {
                            className = stackTrace[i + 1].getClassName();
                            break;
                          }
                        }
                        if (!context.containsClass(className)) {
                          toContinue = false;
                        }
                      }
                      if (toContinue) {
                        jobsInUI.add(job);
                        continue;
                      }
                    }
                  }
                }
              }
            }
          }
        }
        if (jobInfo.isActive()) realJobs.add(job);
      }
    }
    if (!jobsInUI.isEmpty()) {
      if (realJobs.size() == 1 && realJobs.get(0).belongsTo(getFamilyAutoBuild())) {
        realJobs.clear();
      }
    }
    if (realJobs.size() == 1) {
      Job job = realJobs.iterator().next();
      if (job.belongsTo(getFamilyAutoBuild())) {
        // Check for modal dialogs are visible
        int flags = TeslaSWTAccess.getJobFlags(job);
        // Job is alone and blocked
        if ((flags & 0xFF) == 0x08) {
          return logReturnResult(true, realJobs, jobsInUI, info);
        }
        final Display display = RWTUtils.findDisplay();
        final boolean value[] = {false};
        display.syncExec(
            new Runnable() {

              public void run() {
                Shell[] shells = display.getShells();
                for (Shell shell : shells) {
                  if (isModal(shell)) {
                    value[0] = true;
                  }
                }
              }
            });
        if (value[0]) {
          return logReturnResult(true, realJobs, jobsInUI, info);
        }
        if (job.getState() != Job.NONE) {
          return logReturnResult(false, realJobs, jobsInUI, info);
        }
        return logReturnResult(true, realJobs, jobsInUI, info);
      }
    }
    if (wasInStepMode && realJobs.isEmpty()) {
      stepModeNext = current + TeslaLimits.getStepModeStepTime();
    }
    return logReturnResult(realJobs.isEmpty(), realJobs, jobsInUI, info);
  }
Пример #17
0
  private String getJobMessage(JobInfo jobInfo) {
    Job job = jobInfo.job;
    StringBuilder msg = new StringBuilder();
    msg.append("Job: ").append(job.getName()).append("\n");

    msg.append("\tclass: ")
        .append(job.getClass().getName())
        .append(" ")
        .append(DetailUtils.extractSupers(job.getClass()))
        .append("\n");

    Long startTime = jobInfo.startingTime;

    long currentTimeMillis = System.currentTimeMillis();
    long time = 0;
    if (startTime != null) {
      time = currentTimeMillis - startTime.longValue();
    }

    msg.append("\tworking time: ").append(time).append("(ms)\n");
    msg.append("\tstate: ").append(job.getState()).append("\n");

    ISchedulingRule rule = job.getRule();
    if (rule != null) {
      if (rule instanceof IResource) {
        IPath location = ((IResource) rule).getLocation();
        msg.append("\trule is resource: ")
            .append(location != null ? location.toOSString() : "/")
            .append("\n");
      } else {
        msg.append("\trule: ").append(rule.toString()).append("\n");
      }
    } else {
      msg.append("\trule: Empty\n");
    }

    Thread thread = job.getThread();
    if (thread != null) {
      StackTraceElement[] trace = thread.getStackTrace();
      msg.append("\tstack trace: \n");
      // Print 5 lines of stack trace for job
      int c = 0;
      for (StackTraceElement stackTraceElement : trace) {
        if (c > 15) {
          msg.append("\t\t....");
          break;
        }
        c++;
        msg.append(
                "\t\t"
                    + stackTraceElement.getClassName()
                    + "."
                    + stackTraceElement.getMethodName()
                    + ":"
                    + stackTraceElement.getLineNumber()
                    + (stackTraceElement.getFileName() != null
                        ? (" [" + stackTraceElement.getFileName() + "]")
                        : ""))
            .append("\n");
      }
    }
    return msg.toString();
  }