/** * 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()])); }
/** * 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; }
/** * 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; }
/** * 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; }
/** * @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; }
/** * @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; }
/** * @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; }
/** Combines rules for each parameter to validateEdit from the corresponding rule factories. */ public ISchedulingRule validateEditRule(IResource[] resources) { if (resources.length == 0) return null; // optimize rule for single file if (resources.length == 1) { if (resources[0].getType() == IResource.ROOT) return root; return factoryFor(resources[0]).validateEditRule(resources); } // gather rules for each resource from appropriate factory HashSet<ISchedulingRule> rules = new HashSet<ISchedulingRule>(); IResource[] oneResource = new IResource[1]; for (int i = 0; i < resources.length; i++) { if (resources[i].getType() == IResource.ROOT) return root; oneResource[0] = resources[i]; ISchedulingRule rule = factoryFor(resources[i]).validateEditRule(oneResource); if (rule != null) rules.add(rule); } if (rules.isEmpty()) return null; if (rules.size() == 1) return rules.iterator().next(); ISchedulingRule[] ruleArray = rules.toArray(new ISchedulingRule[rules.size()]); return new MultiRule(ruleArray); }
@Override public boolean contains(ISchedulingRule rule) { if (this == rule) return true; // must allow notifications to nest in all resource rules if (rule.getClass().equals(WorkManager.NotifyRule.class)) return true; if (rule instanceof MultiRule) { MultiRule multi = (MultiRule) rule; ISchedulingRule[] children = multi.getChildren(); for (int i = 0; i < children.length; i++) if (!contains(children[i])) return false; return true; } if (!(rule instanceof IResource)) return false; IResource resource = (IResource) rule; if (!workspace.equals(resource.getWorkspace())) return false; return path.isPrefixOf(resource.getFullPath()); }
@Override public boolean isConflicting(ISchedulingRule rule) { if (this == rule) return true; // must not schedule at same time as notification if (rule.getClass().equals(WorkManager.NotifyRule.class)) return true; if (rule instanceof MultiRule) { MultiRule multi = (MultiRule) rule; ISchedulingRule[] children = multi.getChildren(); for (int i = 0; i < children.length; i++) if (isConflicting(children[i])) return true; return false; } if (!(rule instanceof IResource)) return false; IResource resource = (IResource) rule; if (!workspace.equals(resource.getWorkspace())) return false; IPath otherPath = resource.getFullPath(); return path.isPrefixOf(otherPath) || otherPath.isPrefixOf(path); }
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); }
/** * @generated */ protected ISchedulingRule getResetRule(Object element) { ResourceSetInfo info = getResourceSetInfo(element); if (info != null) { Collection/*<org.eclipse.core.runtime.jobs.ISchedulingRule>*/rules = new ArrayList/*<org.eclipse.core.runtime.jobs.ISchedulingRule>*/(); for (Iterator/*<org.eclipse.emf.ecore.resource.Resource>*/it = info .getLoadedResourcesIterator(); it.hasNext();) { Resource nextResource = (Resource) 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; }
/** * @generated */ protected ISchedulingRule getSaveRule(Object element) { ResourceSetInfo info = getResourceSetInfo(element); if (info != null) { Collection/*<org.eclipse.core.runtime.jobs.ISchedulingRule>*/rules = new ArrayList/*<org.eclipse.core.runtime.jobs.ISchedulingRule>*/(); for (Iterator/*<org.eclipse.emf.ecore.resource.Resource>*/it = info .getLoadedResourcesIterator(); it.hasNext();) { Resource nextResource = (Resource) 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; }
/** * @generated */ protected ISchedulingRule getSynchronizeRule(Object element) { ResourceSetInfo info = getResourceSetInfo(element); if (info != null) { Collection/*<org.eclipse.core.runtime.jobs.ISchedulingRule>*/rules = new ArrayList/*<org.eclipse.core.runtime.jobs.ISchedulingRule>*/(); for (Iterator/*<org.eclipse.emf.ecore.resource.Resource>*/it = info .getLoadedResourcesIterator(); it.hasNext();) { Resource nextResource = (Resource) 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; }
/** * @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; }
/** * @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; }
/** * @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; }