Java Code Examples for org.eclipse.core.runtime.jobs.MultiRule#combine()

The following examples show how to use org.eclipse.core.runtime.jobs.MultiRule#combine() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
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());
       }
}