1 package com.proalpha.pds.gitutils.checks;
6 import org.eclipse.core.runtime.IProgressMonitor;
7 import org.eclipse.core.runtime.IStatus;
8 import org.eclipse.core.runtime.OperationCanceledException;
9 import org.eclipse.core.runtime.Status;
10 import org.eclipse.core.runtime.jobs.IJobManager;
11 import org.eclipse.core.runtime.jobs.Job;
12 import org.eclipse.jface.action.Action;
13 import org.eclipse.jface.resource.ImageDescriptor;
14 import org.eclipse.ui.PlatformUI;
15 import org.eclipse.ui.progress.IProgressConstants;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
19 import com.proalpha.pds.checks.CheckTreeView;
20 import com.proalpha.pds.paconnector.PaProject;
22 class ScanJob
extends Job {
24 private final Logger logger = LoggerFactory.getLogger(ScanJob.class);
26 private List<String> checkList;
27 private PaProject paProject;
28 private File resultFile;
30 public ScanJob(String name, PaProject paProject, List<String> checkList, File resultFile) {
33 this.paProject = paProject;
34 this.checkList = checkList;
35 this.resultFile = resultFile;
37 setProperty(IProgressConstants.ICON_PROPERTY,
38 ImageDescriptor.createFromURL(CheckTreeView.class.getResource(
"/images/bug_yellow_view.png")));
39 setProperty(IProgressConstants.PROPERTY_IN_DIALOG, Boolean.FALSE);
40 setProperty(IProgressConstants.KEEPONE_PROPERTY, Boolean.TRUE);
41 setProperty(IProgressConstants.ACTION_PROPERTY, getReservationCompletedAction());
45 protected IStatus run(IProgressMonitor monitor) {
47 if (this.paProject.isAvailable()) {
48 paProject.getBridge().scanObjects(String.join(
",", checkList));
51 ObserverJob observerJob =
new ObserverJob(
"Wait for check results", resultFile);
52 observerJob.setSystem(
true);
53 observerJob.schedule();
55 IJobManager manager = Job.getJobManager();
57 manager.join(ObserverJob.FAMILY_ID, monitor);
58 }
catch (OperationCanceledException | InterruptedException exception) {
59 logger.error(exception.toString());
60 return Status.CANCEL_STATUS;
63 return new Status(Status.OK, com.proalpha.pds.paconnector.Activator.PLUGIN_ID,
64 "Scan has been completed. Open proALPHA Checks perspective.");
67 protected Action getReservationCompletedAction() {
68 return new Action(
"View scan status") {
71 PlatformUI.getWorkbench().showPerspective(
"com.proalpha.pds.checks.proALPHAChecks",
72 PlatformUI.getWorkbench().getActiveWorkbenchWindow());
74 }
catch (Exception e) {
82 public boolean belongsTo(Object family) {
83 if (family instanceof ScanJob) {
84 return this.getName().equals(((ScanJob) family).getName());