@Override public void runInUI(IRunnableContext context, IRunnableWithProgress runnable, ISchedulingRule rule) throws InvocationTargetException, InterruptedException { final RunnableWithStatus runnableWithStatus = new RunnableWithStatus( context, runnable, rule); uiSynchronize.syncExec(new Runnable() { @Override public void run() { BusyIndicator.showWhile(getDisplay(), runnableWithStatus); } }); IStatus status = runnableWithStatus.getStatus(); if (!status.isOK()) { Throwable exception = status.getException(); if (exception instanceof InvocationTargetException) throw (InvocationTargetException) exception; else if (exception instanceof InterruptedException) throw (InterruptedException) exception; else // should be OperationCanceledException throw new InterruptedException(exception.getMessage()); } }
public void execute(IProgressMonitor monitor) throws SVNException, InterruptedException { Map table = getProviderMapping(getResources()); Set keySet = table.keySet(); monitor.beginTask(null, keySet.size() * 1000); Iterator iterator = keySet.iterator(); while (iterator.hasNext()) { IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1000); SVNTeamProvider provider = (SVNTeamProvider)iterator.next(); List list = (List)table.get(provider); IResource[] providerResources = (IResource[])list.toArray(new IResource[list.size()]); ISchedulingRule rule = getSchedulingRule(provider); try { Job.getJobManager().beginRule(rule, monitor); monitor.setTaskName(getTaskName(provider)); execute(provider, providerResources, subMonitor); } finally { Job.getJobManager().endRule(rule); } } }
/** * 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; }
/** An operation calls this method and it only returns when the operation is free to run. */ public void checkIn(ISchedulingRule rule, IProgressMonitor monitor) throws CoreException { boolean success = false; try { if (workspace.isTreeLocked()) { String msg = Messages.resources_cannotModify; throw new ResourceException(IResourceStatus.WORKSPACE_LOCKED, null, msg, null); } jobManager.beginRule(rule, monitor); lock.acquire(); incrementPreparedOperations(); success = true; } finally { // remember if we failed to check in, so we can avoid check out if (!success) checkInFailed.set(Boolean.TRUE); } }
/** 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 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); }
@Override public boolean isConflicting(ISchedulingRule rule) { if(this == rule){ return true; } if(rule instanceof ExclusiveRule) { ExclusiveRule rule2 = (ExclusiveRule) rule; IJavaElement element = root.getJavaElement(); IJavaElement element2 = rule2.root.getJavaElement(); if(element.equals(element2)){ return true; } if(MULTICORE) { return tooManyJobsThere(); } return true; } return false; }
public void threadChange(Thread thread) { // we must make sure we aren't transferring control away from a thread that // already owns a scheduling rule because this is deadlock prone (bug 105491) if (rule == null) { return; } Job currentJob = Job.getJobManager().currentJob(); if (currentJob == null) { return; } ISchedulingRule currentRule = currentJob.getRule(); if (currentRule == null) { return; } throw new IllegalStateException( "Cannot fork a thread from a thread owning a rule"); // $NON-NLS-1$ }
/** * Performs some general validity checks on the Xtext index. Only intended to be used in tests (e.g. no support for * cancellation). */ protected void assertXtextIndexIsValid() { // ensure no build is running while we examine the Xtext index final ISchedulingRule rule = externalLibraryBuilderHelper.getRule(); try { Job.getJobManager().beginRule(rule, null); assertXtextIndexIsValidInternal(); } finally { Job.getJobManager().endRule(rule); } }
@Override public void storeUpdated(final ExternalLibraryPreferenceStore store, final IProgressMonitor monitor) { final ISchedulingRule rule = builderHelper.getRule(); try { Job.getJobManager().beginRule(rule, monitor); storeUpdatedInternal(store, monitor); } finally { Job.getJobManager().endRule(rule); } }
@Override public void registerProjects(NpmProjectAdaptionResult result, IProgressMonitor monitor, boolean triggerCleanbuild) { final ISchedulingRule rule = builderHelper.getRule(); try { Job.getJobManager().beginRule(rule, monitor); registerProjectsInternal(result, monitor, triggerCleanbuild); } finally { Job.getJobManager().endRule(rule); } }
/** * Reloads the external libraries by re-indexing all registered external projects that are do not exist in the * workspace. * * @param refreshNpmDefinitions * if {@code true}, then the type definition files will be reloaded/refreshed for all {@code npm} * packages. * @param monitor * the monitor for the process. * @throws InvocationTargetException * if any unexpected error occurs during the refresh process. */ public void reloadLibraries(final boolean refreshNpmDefinitions, final IProgressMonitor monitor) throws InvocationTargetException { final ISchedulingRule rule = builderHelper.getRule(); try { Job.getJobManager().beginRule(rule, monitor); reloadLibrariesInternal(refreshNpmDefinitions, monitor); } catch (final OperationCanceledException e) { LOGGER.info("User abort."); } finally { Job.getJobManager().endRule(rule); } }
private static <T> T runWithWorkspaceLock(Supplier<T> operation) { if (Platform.isRunning()) { final ISchedulingRule rule = ResourcesPlugin.getWorkspace().getRoot(); try { Job.getJobManager().beginRule(rule, null); return operation.get(); } finally { Job.getJobManager().endRule(rule); } } else { // locking not available/required in headless case return operation.get(); } }
/** * Returns the scheduling rule to use when creating the resource at the * given container path. The rule should be the creation rule for the * top-most non-existing parent. * * @param resource * The resource being created * @return The scheduling rule for creating the given resource * @since 3.1 * @deprecated As of 3.3, scheduling rules are provided by the undoable * operation that this page creates and executes. */ protected ISchedulingRule createRule(IResource resource) { IResource parent = resource.getParent(); while (parent != null) { if (parent.exists()) { return resource.getWorkspace().getRuleFactory() .createRule(resource); } resource = parent; parent = parent.getParent(); } return resource.getWorkspace().getRoot(); }
/** * 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()]); }
protected ISchedulingRule getSchedulingRule(SVNTeamProvider provider) { ISchedulingRule schedulingRule = super.getSchedulingRule(provider); if (schedulingRule != null && conflictResolver != null) { ((SVNConflictResolver)conflictResolver).setSchedulingRule(schedulingRule); } return schedulingRule; }
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()])); }
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()])); }
@Test public void testSchedulingRule_artifactInWorkspace() throws CoreException { IPath deployArtifact = createFileInProject("in-workspace.war"); StagingDelegate delegate = new FlexExistingDeployArtifactStagingDelegate( deployArtifact, appEngineDirectory); ISchedulingRule rule = delegate.getSchedulingRule(); assertTrue(rule instanceof IFile); IFile file = (IFile) rule; assertTrue(file.exists()); }
@Override public boolean performFinish() { AppProjectGenerator generator = new AppProjectGenerator(getTemplateManifestPath()); generator.setProjectName(mainPage.getProjectName()); if (!mainPage.useDefaults()) { generator.setLocationURI(mainPage.getLocationURI()); } generator.setPackageName("com.example.emptyapp"); generator.setActivityName("MainActivity"); generator.setLayoutName("activity_main"); Map<String, Object> model = new HashMap<>(); try { getContainer().run(true, true, new WorkspaceModifyOperation() { @Override protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { monitor.beginTask("Generating project", 1); //$NON-NLS-1$ generator.generate(model, monitor); monitor.done(); } @Override public ISchedulingRule getRule() { return ResourcesPlugin.getWorkspace().getRoot(); } }); } catch (InterruptedException | InvocationTargetException e) { throw new RuntimeException(e); } return true; }
private ISchedulingRule getMarkerRule(IResource resource) { ISchedulingRule rule = null; if (resource != null) { IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory(); rule = ruleFactory.markerRule(resource); } return rule; }
/** * Retrieves a rule for modifying a resource * @param resource * @return */ public static ISchedulingRule getModifyRule(IResource resource) { IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory(); ISchedulingRule rule = ruleFactory.modifyRule(resource); return rule; }
public boolean isConflicting(ISchedulingRule rule) { if (rule instanceof SerialPerObjectRule) { SerialPerObjectRule serialPerObjectRule = (SerialPerObjectRule) rule; return lockObject == serialPerObjectRule.lockObject; } return false; }
/** * Returns true if the check in for this thread failed, in which case the check out and other end * of operation code should not run. * * <p>The failure flag is reset immediately after calling this method. Subsequent calls to this * method will indicate no failure (unless a new failure has occurred). * * @return <code>true</code> if the checkIn failed, and <code>false</code> otherwise. */ public boolean checkInFailed(ISchedulingRule rule) { if (checkInFailed.get() != null) { // clear the failure flag for this thread checkInFailed.set(null); // must still end the rule even in the case of failure if (!workspace.isTreeLocked()) jobManager.endRule(rule); return true; } return false; }
@Override public void setContents(InputStream content, int updateFlags, IProgressMonitor monitor) throws CoreException { monitor = Policy.monitorFor(monitor); try { String message = NLS.bind(Messages.resources_settingContents, getFullPath()); monitor.beginTask(message, Policy.totalWork); // if (workspace.shouldValidate) // workspace.validateSave(this); final ISchedulingRule rule = workspace.getRuleFactory().modifyRule(this); try { workspace.prepareOperation(rule, monitor); ResourceInfo info = getResourceInfo(false, false); // checkAccessible(getFlags(info)); workspace.beginOperation(true); // IFileInfo fileInfo = getStore().fetchInfo(); internalSetContents( content, updateFlags, false, Policy.subMonitorFor(monitor, Policy.opWork)); } catch (OperationCanceledException e) { workspace.getWorkManager().operationCanceled(); throw e; } finally { workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork)); } } finally { monitor.done(); FileUtil.safeClose(content); } }
/** Obtains the scheduling rule from the appropriate factories for a move operation. */ public ISchedulingRule moveRule(IResource source, IResource destination) { if (source.getType() == IResource.ROOT || destination.getType() == IResource.ROOT) return root; // treat a move across projects as a create on the destination and a delete on the source if (!source.getFullPath().segment(0).equals(destination.getFullPath().segment(0))) return MultiRule.combine( modifyRule(source.getProject()), modifyRule(destination.getProject())); return factoryFor(source).moveRule(source, destination); }
@Override public void run( IWorkspaceRunnable action, ISchedulingRule rule, int options, IProgressMonitor monitor) throws CoreException { monitor = Policy.monitorFor(monitor); try { monitor.beginTask("", Policy.totalWork); // $NON-NLS-1$ int depth = -1; boolean avoidNotification = (options & IWorkspace.AVOID_UPDATE) != 0; try { prepareOperation(rule, monitor); beginOperation(true); // if (avoidNotification) // avoidNotification = notificationManager.beginAvoidNotify(); depth = getWorkManager().beginUnprotected(); action.run( Policy.subMonitorFor( monitor, Policy.opWork, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK)); } catch (OperationCanceledException e) { getWorkManager().operationCanceled(); throw e; } finally { // if (avoidNotification) // notificationManager.endAvoidNotify(); if (depth >= 0) { getWorkManager().endUnprotected(depth); } endOperation(rule, false, Policy.subMonitorFor(monitor, Policy.endOpWork)); } } finally { monitor.done(); } }
/** * @param resource * @return */ private static ISchedulingRule getMarkerRule(Object resource) { if (resource instanceof IResource) { return ResourcesPlugin.getWorkspace().getRuleFactory().markerRule((IResource) resource); } return null; }
/** * Convenience method to return the parent of the given resource, or the resource itself for * projects and the workspace root. * * @param resource the resource to compute the parent of * @return the parent resource for folders and files, and the resource itself for projects and the * workspace root. */ protected final ISchedulingRule parent(IResource resource) { switch (resource.getType()) { case IResource.ROOT: case IResource.PROJECT: return resource; default: return resource.getParent(); } }
/** * Default implementation of <code>IResourceRuleFactory#validateEditRule</code>. This default * implementation returns a rule that combines the parents of all read-only resources, or <code> * null</code> if there are no read-only resources. * * <p>Subclasses may override this method. The rule provided by an overriding method must at least * contain the rule from this default implementation. * * @see * org.eclipse.core.runtime.jobs.ISchedulingRule#contains(org.eclipse.core.runtime.jobs.ISchedulingRule) * @see org.eclipse.core.resources.IResourceRuleFactory#validateEditRule(IResource[]) */ public ISchedulingRule validateEditRule(IResource[] resources) { if (resources.length == 0) return null; // optimize rule for single file if (resources.length == 1) return isReadOnly(resources[0]) ? parent(resources[0]) : null; // need a lock on the parents of all read-only files HashSet<ISchedulingRule> rules = new HashSet<ISchedulingRule>(); for (int i = 0; i < resources.length; i++) if (isReadOnly(resources[i])) rules.add(parent(resources[i])); 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); }
public boolean isConflicting(ISchedulingRule rule) { if (rule instanceof SerialPerObjectRule) { SerialPerObjectRule vup = (SerialPerObjectRule) rule; return fObject == vup.fObject; } return false; }
/** * 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); }