org.eclipse.core.runtime.jobs.MultiRule Java Examples

The following examples show how to use org.eclipse.core.runtime.jobs.MultiRule. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CrossflowDocumentProvider.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
/**
* @generated
*/
protected ISchedulingRule getSaveRule(Object element) {
	ResourceSetInfo info = getResourceSetInfo(element);
	if (info != null) {
		LinkedList<ISchedulingRule> rules = new LinkedList<ISchedulingRule>();
		for (Iterator<Resource> it = info.getLoadedResourcesIterator(); it.hasNext();) {
			Resource nextResource = it.next();
			IFile file = WorkspaceSynchronizer.getFile(nextResource);
			if (file != null) {
				rules.add(computeSchedulingRule(file));
			}
		}
		return new MultiRule((ISchedulingRule[]) rules.toArray(new ISchedulingRule[rules.size()]));
	}
	return null;
}
 
Example #2
Source File: ProcessDocumentProvider.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
* @generated
*/
protected ISchedulingRule getSynchronizeRule(Object element) {
	ResourceSetInfo info = getResourceSetInfo(element);
	if (info != null) {
		LinkedList<ISchedulingRule> rules = new LinkedList<ISchedulingRule>();
		for (Iterator<Resource> it = info.getLoadedResourcesIterator(); it.hasNext();) {
			Resource nextResource = it.next();
			IFile file = WorkspaceSynchronizer.getFile(nextResource);
			if (file != null) {
				rules.add(ResourcesPlugin.getWorkspace().getRuleFactory().refreshRule(file));
			}
		}
		return new MultiRule((ISchedulingRule[]) rules.toArray(new ISchedulingRule[rules.size()]));
	}
	return null;
}
 
Example #3
Source File: ProcessDocumentProvider.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
* @generated
*/
protected ISchedulingRule getSaveRule(Object element) {
	ResourceSetInfo info = getResourceSetInfo(element);
	if (info != null) {
		LinkedList<ISchedulingRule> rules = new LinkedList<ISchedulingRule>();
		for (Iterator<Resource> it = info.getLoadedResourcesIterator(); it.hasNext();) {
			Resource nextResource = it.next();
			IFile file = WorkspaceSynchronizer.getFile(nextResource);
			if (file != null) {
				rules.add(computeSchedulingRule(file));
			}
		}
		return new MultiRule((ISchedulingRule[]) rules.toArray(new ISchedulingRule[rules.size()]));
	}
	return null;
}
 
Example #4
Source File: ProcessDocumentProvider.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
* @generated
*/
protected ISchedulingRule getResetRule(Object element) {
	ResourceSetInfo info = getResourceSetInfo(element);
	if (info != null) {
		LinkedList<ISchedulingRule> rules = new LinkedList<ISchedulingRule>();
		for (Iterator<Resource> it = info.getLoadedResourcesIterator(); it.hasNext();) {
			Resource nextResource = it.next();
			IFile file = WorkspaceSynchronizer.getFile(nextResource);
			if (file != null) {
				rules.add(ResourcesPlugin.getWorkspace().getRuleFactory().modifyRule(file));
			}
		}
		return new MultiRule((ISchedulingRule[]) rules.toArray(new ISchedulingRule[rules.size()]));
	}
	return null;
}
 
Example #5
Source File: CopyResourceElementsOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
protected ISchedulingRule getSchedulingRule() {
	if (this.elementsToProcess == null)
		return null;
	int length = this.elementsToProcess.length;
	if (length == 1)
		return getSchedulingRule(this.elementsToProcess[0]);
	ISchedulingRule[] rules = new ISchedulingRule[length];
	int index = 0;
	for (int i = 0; i < length; i++) {
		ISchedulingRule rule = getSchedulingRule(this.elementsToProcess[i]);
		if (rule != null) {
			rules[index++] = rule;
		}
	}
	if (index != length)
		System.arraycopy(rules, 0, rules = new ISchedulingRule[index], 0, index);
	return new MultiRule(rules);
}
 
Example #6
Source File: RepositoryProviderOperation.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Retgurn the scheduling rule to be obtained before work
 * begins on the given provider. By default, it is the provider's project.
 * This can be changed by subclasses.
 * @param provider
 * @return
 */
protected ISchedulingRule getSchedulingRule(SVNTeamProvider provider) {
	IResourceRuleFactory ruleFactory = provider.getRuleFactory();
	HashSet rules = new HashSet();
	IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
	for (int i = 0; i < resources.length; i++) {			
		IResource[] pathResources = SVNWorkspaceRoot.getResourcesFor(new Path(resources[i].getLocation().toOSString()), false);
		for (IResource pathResource : pathResources) {
			IProject resourceProject = pathResource.getProject();				
			rules.add(ruleFactory.modifyRule(resourceProject));
			if (resourceProject.getLocation() != null) {
				// Add nested projects
				for (IProject project : projects) {
					if (project.getLocation() != null) {
						if (!project.getLocation().equals(resourceProject.getLocation()) && resourceProject.getLocation().isPrefixOf(project.getLocation())) {
							rules.add(ruleFactory.modifyRule(project));
						}
					}
				}	
			}
		}
	}
	return MultiRule.combine((ISchedulingRule[]) rules.toArray(new ISchedulingRule[rules.size()]));
}
 
Example #7
Source File: ResourceHelper.java    From tlaplus with MIT License 6 votes vote down vote up
/**
 * Retrieves a combined rule for creating resource
 * @param resource
 * @return
 */
public static ISchedulingRule getCreateRule(IResource[] resources)
{
    if (resources == null)
    {
        return null;
    }
    ISchedulingRule combinedRule = null;
    IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory();
    for (int i = 0; i < resources.length; i++)
    {
        ISchedulingRule rule = ruleFactory.createRule(resources[i]);
        combinedRule = MultiRule.combine(rule, combinedRule);
    }
    return combinedRule;
}
 
Example #8
Source File: ResourceHelper.java    From tlaplus with MIT License 6 votes vote down vote up
/**
 * Retrieves a combined rule for deleting resource
 * @param resource
 * @return
 */
public static ISchedulingRule getDeleteRule(IResource[] resources)
{
    if (resources == null)
    {
        return null;
    }
    ISchedulingRule combinedRule = null;
    IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory();
    for (int i = 0; i < resources.length; i++)
    {
        ISchedulingRule rule = ruleFactory.deleteRule(resources[i]);
        combinedRule = MultiRule.combine(rule, combinedRule);
    }
    return combinedRule;
}
 
Example #9
Source File: ResourceHelper.java    From tlaplus with MIT License 6 votes vote down vote up
/**
 * Retrieves a combined rule for modifying the resources
 * @param resources set of resources
 * @return a combined rule
 */
public static ISchedulingRule getModifyRule(IResource[] resources)
{
    if (resources == null)
    {
        return null;
    }
    ISchedulingRule combinedRule = null;
    IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory();
    for (int i = 0; i < resources.length; i++)
    {
        // if one of the resources does not exist
        // something is screwed up
        if (resources[i] == null || !resources[i].exists())
        {
            return null;
        }
        ISchedulingRule rule = ruleFactory.modifyRule(resources[i]);
        combinedRule = MultiRule.combine(rule, combinedRule);
    }
    return combinedRule;
}
 
Example #10
Source File: TodoTaskMarkerBuilder.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
private void performSearchOnResources(Iterator<IResource> resourcesIterator) {
	List<IResource> targetResources = new ArrayList<IResource>();
	
	for (; resourcesIterator.hasNext(); ) {
		IResource resource = resourcesIterator.next();
		if (resource != null) { 
			// resource can be null at the moment, when path to file
			// belongs to the external compilation unit, and it not yet have been mapped to the
			// workspace by builder.
			// @see com.excelsior.xds.core.compiler.compset.ICompilationSetListener
			
			// add resource even if it is not IXdsWorkspaceCompilationUnit, because we avoid accessing the XdsModel in this thread.
			targetResources.add(resource);
		}
	}
	
	if (!targetResources.isEmpty()) {
		TodoTaskSearchJob todoTaskSearchJob = new TodoTaskSearchJob(targetResources);
		todoTaskSearchJob.setRule(MultiRule.combine(targetResources.toArray(new IResource[0])));
		todoTaskSearchJob.schedule();
	}
}
 
Example #11
Source File: XtextBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public ISchedulingRule getRule(int kind, Map<String, String> args) {
	switch (preferences.schedulingOption) {
		case NULL: return null;
		case WORKSPACE: return getProject().getWorkspace().getRoot();
		case PROJECT: return getProject();
		case ALL_XTEXT_PROJECTS: return new MultiRule(Arrays.stream(
				getProject().getWorkspace().getRoot().getProjects())
				.filter(XtextProjectHelper::hasNature)
				.toArray(ISchedulingRule[]::new));
		case ALL_XTEXT_PROJECTS_AND_JDTEXTFOLDER: return new MultiRule(Arrays.stream(
				getProject().getWorkspace().getRoot().getProjects())
				.filter(p->
					XtextProjectHelper.hasNature(p)
					|| EXTERNAL_PROJECT_NAME.equals(p.getName())
				)
				.toArray(ISchedulingRule[]::new));
		default: throw new IllegalArgumentException();
	}
}
 
Example #12
Source File: CrossflowDocumentProvider.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
/**
* @generated
*/
protected ISchedulingRule getSynchronizeRule(Object element) {
	ResourceSetInfo info = getResourceSetInfo(element);
	if (info != null) {
		LinkedList<ISchedulingRule> rules = new LinkedList<ISchedulingRule>();
		for (Iterator<Resource> it = info.getLoadedResourcesIterator(); it.hasNext();) {
			Resource nextResource = it.next();
			IFile file = WorkspaceSynchronizer.getFile(nextResource);
			if (file != null) {
				rules.add(ResourcesPlugin.getWorkspace().getRuleFactory().refreshRule(file));
			}
		}
		return new MultiRule((ISchedulingRule[]) rules.toArray(new ISchedulingRule[rules.size()]));
	}
	return null;
}
 
Example #13
Source File: CrossflowDocumentProvider.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
/**
* @generated
*/
protected ISchedulingRule getResetRule(Object element) {
	ResourceSetInfo info = getResourceSetInfo(element);
	if (info != null) {
		LinkedList<ISchedulingRule> rules = new LinkedList<ISchedulingRule>();
		for (Iterator<Resource> it = info.getLoadedResourcesIterator(); it.hasNext();) {
			Resource nextResource = it.next();
			IFile file = WorkspaceSynchronizer.getFile(nextResource);
			if (file != null) {
				rules.add(ResourcesPlugin.getWorkspace().getRuleFactory().modifyRule(file));
			}
		}
		return new MultiRule((ISchedulingRule[]) rules.toArray(new ISchedulingRule[rules.size()]));
	}
	return null;
}
 
Example #14
Source File: ResourceUtils.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
public static ISchedulingRule createRule(Collection<? extends IResource> resources) {
      ISchedulingRule combinedRule = null;
      IResourceRuleFactory ruleFactory = 
            ResourcesPlugin.getWorkspace().getRuleFactory();
      
      for (IResource r : resources) {
      	ISchedulingRule rule = ruleFactory.createRule(r);
          combinedRule = MultiRule.combine(rule, combinedRule);
}
      
      return combinedRule;
   }
 
Example #15
Source File: CloseResourceAction.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * The implementation of this <code>WorkspaceAction</code> method method saves and closes the resource's dirty
 * editors before closing it.
 */
@Override
public void run() {
	// Get the items to close.
	final List<? extends IResource> projects = getSelectedResources();
	if (projects == null || projects.isEmpty()) {
		// no action needs to be taken since no projects are selected
		return;
	}

	final IResource[] projectArray = projects.toArray(new IResource[projects.size()]);

	if (!IDE.saveAllEditors(projectArray, true)) { return; }
	if (!validateClose()) { return; }

	closeMatchingEditors(projects, false);

	// be conservative and include all projects in the selection - projects
	// can change state between now and when the job starts
	ISchedulingRule rule = null;
	final IResourceRuleFactory factory = ResourcesPlugin.getWorkspace().getRuleFactory();
	for (final IResource element : projectArray) {
		final IProject project = (IProject) element;
		rule = MultiRule.combine(rule, factory.modifyRule(project));
	}
	runInBackground(rule);
}
 
Example #16
Source File: BaseDocumentLifeCycleHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private ISchedulingRule getRule(Set<ICompilationUnit> units) {
	ISchedulingRule result = null;
	IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory();
	for (ICompilationUnit unit : units) {
		if (unit.getResource() != null) {
			ISchedulingRule rule = ruleFactory.createRule(unit.getResource());
			result = MultiRule.combine(rule, result);
		}
	}
	return result;
}
 
Example #17
Source File: CheckoutAsProjectOperation.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
protected ISchedulingRule getSchedulingRule(SVNTeamProvider provider) {
	IResourceRuleFactory ruleFactory = provider.getRuleFactory();
	HashSet rules = new HashSet();
	for (int i = 0; i < localFolders.length; i++) {
		rules.add(ruleFactory.modifyRule(localFolders[i].getProject()));
	}
	return MultiRule.combine((ISchedulingRule[]) rules.toArray(new ISchedulingRule[rules.size()]));
}
 
Example #18
Source File: BranchTagOperation.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
protected ISchedulingRule getSchedulingRule(SVNTeamProvider provider) {
	IResource[] resources = getResources();
	if (resources == null) return super.getSchedulingRule(provider);
	IResourceRuleFactory ruleFactory = provider.getRuleFactory();
	HashSet<ISchedulingRule> rules = new HashSet<ISchedulingRule>();
	for (int i = 0; i < resources.length; i++) {
		rules.add(ruleFactory.modifyRule(resources[i].getProject()));
	}
	return MultiRule.combine((ISchedulingRule[]) rules.toArray(new ISchedulingRule[rules.size()]));
}
 
Example #19
Source File: SVNProjectSetCapability.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
   * Checkout projects from the SVN repository
   * 
   * @param projects
   *            the projects to be loaded from the repository
   * @param infoMap
   *            a mapping of project to project load information
   * @param monitor
   *            the progress monitor (not <code>null</code>)
   */
  private IProject[] checkout(IProject[] projects, Map<IProject, LoadInfo> infoMap,
          IProgressMonitor monitor) throws TeamException, MalformedURLException {
      if(projects==null || projects.length==0) {
        return new IProject[0];
      }
      ISchedulingRule[] ruleArray = new ISchedulingRule[projects.length];
      for (int i = 0; i < projects.length; i++) {
          ruleArray[i] = projects[i].getWorkspace().getRuleFactory().modifyRule(projects[i]);
}
      ISchedulingRule rule= MultiRule.combine(ruleArray);
Job.getJobManager().beginRule(rule, monitor);
      monitor.beginTask("", 1000 * projects.length); //$NON-NLS-1$
      List<IProject> result = new ArrayList<IProject>();
      try {
          for (IProject project : projects) {
              if (monitor.isCanceled()) {
                  break;
              }
              LoadInfo info = infoMap.get(project);
              if (info != null
                      && info.checkout(new SubProgressMonitor(monitor, 1000))) {
                  result.add(project);
              }
          }
      } finally {
  		Job.getJobManager().endRule(rule);
          monitor.done();
      }
      return result.toArray(new IProject[result.size()]);
  }
 
Example #20
Source File: SetClasspathOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected ISchedulingRule getSchedulingRule() {
	if (this.canChangeResources) {
		IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory();
		return new MultiRule(new ISchedulingRule[] {
			// use project modification rule as this is needed to create the .classpath file if it doesn't exist yet, or to update project references
			ruleFactory.modifyRule(this.project.getProject()),
			
			// and external project modification rule in case the external folders are modified
			ruleFactory.modifyRule(JavaModelManager.getExternalManager().getExternalFoldersProject())
		});
	}
	return super.getSchedulingRule();
}
 
Example #21
Source File: BuildPath.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a suitable {@link ISchedulingRule scheduling rule} when resolving libraries for a
 * project.
 */
public static ISchedulingRule resolvingRule(IJavaProject javaProject) {
  // Requires both the project modification rule and the Maven project configuration rule
  IWorkspace workspace = javaProject.getProject().getWorkspace();
  ISchedulingRule rule =
      MultiRule.combine(
          workspace.getRuleFactory().modifyRule(javaProject.getProject()),
          MavenUtils.mavenResolvingRule());
  return rule;
}
 
Example #22
Source File: ProverJob.java    From tlaplus with MIT License 4 votes vote down vote up
/**
 * Constructor. This constructor sets the appropriate scheduling rule for this job, so there is no
 * need to call {@link #setRule(org.eclipse.core.runtime.jobs.ISchedulingRule)}.
 * @param module the module on which the prover is being launched.
 * @param offset a character offset on the line of the step or leaf proof on which the prover will be launched. This will
 * launch the prover on the first step on that line, or if the line contains only a leaf proof, it will launch
 * the prover on the step for which that is a leaf proof. If the line does not contain a leaf proof or a step,
 * the prover will be launched on the entire module. Setting the offset to -1 will cause the PM to be launched
 * on the entire module.
 * @param checkStatus true iff the PM should be launched for status checking only
 * @param options the options used to launch the PM in an array, e.g. {"--paranoid","--threads","2"}.
 * The elements in the array would normally be separated by a space in the command line. This
 * array should NOT contain the --toolbox option or the --noproving option. This job will put
 * those options in. The --noproving options should be specified using the checkStatus argument.
 * This argument can be null if no additional options are to be used.
 * @param toolboxMode true iff the
 */
public ProverJob(IFile module, int offset, boolean checkStatus, String[] options, boolean toolboxMode)
{
    super(checkStatus ? "Status Checking Launch" : "Prover Launch");
    this.checkStatus = checkStatus;
    this.toolboxMode = toolboxMode;
    this.module = module;
    this.offset = offset;
    this.options = options;

    /*
     * Running this job can potentially result in parsing
     * the module. This can result in changes to the workspace (because
     * of markers removed from or placed on parse errors). This must
     * be indicated in the scheduling rule for this job. We do this
     * by using a multi rule that includes the ProverJobRule and the
     * rule associated with the root of the workspace. If this is not done,
     * an exception can be thrown. See the comments for MultiRule
     * and read the article http://www.eclipse.org/articles/Article-Concurrency/jobs-api.html
     * for more information on eclipse Jobs.
     */
    setRule(new MultiRule(new ISchedulingRule[] { new ProverJobRule(), this.module.getWorkspace().getRoot() }));

    /*
     * The following sets the path to tlapm.
     */
    Assert.isTrue(Platform.isRunning(), "Platform is not running when prover was launched. This makes no sense.");
    
    final TLAPMExecutableLocator locator = TLAPMExecutableLocator.INSTANCE;
    this.tlapmPath = locator.getTLAPMPath();
    this.cygwinPath = locator.getCygwinPath();

    /*
     * We create a useless launch object. It is
     * used later to construct a IProcess. This object
     * provides convenience methods for processes.
     * In particular, an IProcess listens for the termination
     * of the underlying process.
     */
    this.launch = new Launch(null, "", null);
}
 
Example #23
Source File: UpdateResourcesCommand.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
public void run(final IProgressMonitor monitor) throws SVNException {
	final ISVNClientAdapter svnClient = root.getRepository().getSVNClient();
	OperationManager.getInstance().beginOperation(svnClient, new OperationProgressNotifyListener(monitor, svnClient));		
	try {		
        List<IProject> projectList = new ArrayList<IProject>();
        for (IResource currentResource : resources) {
        	IProject project = currentResource.getProject();
        	if (!projectList.contains(project)) {
        		projectList.add(project);
        	}        	
        }
		if (conflictResolver != null) {
			svnClient.addConflictResolutionCallback(conflictResolver);
		}
		
        IProject[] projects = new IProject[projectList.size()];
        projectList.toArray(projects);
        ISchedulingRule rule = MultiRule.combine(projects);
        
        SVNProviderPlugin.run(new ISVNRunnable() {
            public void run(final IProgressMonitor pm) throws SVNException {
                try {
                    monitor.beginTask(null, 100 * resources.length);                    

                    svnClient.addNotifyListener(operationResourceCollector);
                    
            		if (resources.length == 1)
            		{
                        monitor.subTask(resources[0].getName());
                        svnClient.update(resources[0].getLocation().toFile(),revision, depth, setDepth, ignoreExternals, force);
                        updatedResources.add(resources[0]);
                        monitor.worked(100);    			
            		}
            		else
            		{
            			File[] files = new File[resources.length];
            			for (int i = 0; i < resources.length; i++) {
        					files[i] = resources[i].getLocation().toFile();
        					updatedResources.add(resources[i]);
        				}
          
           				svnClient.update(files, revision, depth, setDepth, ignoreExternals, force);   				
           				monitor.worked(100);
            		}
                } catch (SVNClientException e) {
                    throw SVNException.wrapException(e);
                } finally {
                	monitor.done();
                	if (svnClient != null) {
	            		if (conflictResolver != null) {
	            			svnClient.addConflictResolutionCallback(null);
	            		}
	            		svnClient.removeNotifyListener(operationResourceCollector);
	            		root.getRepository().returnSVNClient(svnClient);
                	}
                }                    	
            }
        }, rule, Policy.monitorFor(monitor));
       } finally {
       	OperationManager.getInstance().endOperation(true, operationResourceCollector.getOperationResources());
       }
}