Java 类org.eclipse.core.resources.IResourceRuleFactory 实例源码

项目:subclipse    文件:RepositoryProviderOperation.java   
/**
 * 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()]));
}
项目:tlaplus    文件:ResourceHelper.java   
/**
 * 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;
}
项目:tlaplus    文件:ResourceHelper.java   
/**
 * 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;
}
项目:tlaplus    文件:ResourceHelper.java   
/**
 * 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;
}
项目:APICloud-Studio    文件:RepositoryProviderOperation.java   
/**
 * 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()]));
}
项目:subclipse    文件:CheckoutAsProjectOperation.java   
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()]));
}
项目:subclipse    文件:BranchTagOperation.java   
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()]));
}
项目:mesfavoris    文件:BookmarksMarkers.java   
private ISchedulingRule getMarkerRule(IResource resource) {
    ISchedulingRule rule = null;
    if (resource != null) {
        IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory();
        rule = ruleFactory.markerRule(resource);
    }
    return rule;
}
项目:tlaplus    文件:ResourceHelper.java   
/**
 * 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;
}
项目:che    文件:Rules.java   
/** Returns the scheduling rule factory for the given resource */
private IResourceRuleFactory factoryFor(IResource destination) {
  IResourceRuleFactory fac = projectsToRules.get(destination.getFullPath().segment(0));
  if (fac == null) {
    // use the default factory if the project is not yet accessible
    if (!destination.getProject().isAccessible()) return defaultFactory;
    // ask the team hook to supply one
    fac = teamHook.getRuleFactory(destination.getProject());
    projectsToRules.put(destination.getFullPath().segment(0), fac);
  }
  return fac;
}
项目:che    文件:Workspace.java   
@Override
public IResourceRuleFactory getRuleFactory() {
  // note that the rule factory is created lazily because it
  // requires loading the teamHook extension
  if (ruleFactory == null) {
    ruleFactory = new Rules(this);
  }
  return ruleFactory;
}
项目:che    文件:Rules.java   
/** Returns the scheduling rule factory for the given resource */
private IResourceRuleFactory factoryFor(IResource destination) {
  IResourceRuleFactory fac = projectsToRules.get(destination.getFullPath().segment(0));
  if (fac == null) {
    // use the default factory if the project is not yet accessible
    if (!destination.getProject().isAccessible()) return defaultFactory;
    // ask the team hook to supply one
    fac = teamHook.getRuleFactory(destination.getProject());
    projectsToRules.put(destination.getFullPath().segment(0), fac);
  }
  return fac;
}
项目:gama    文件:CloseResourceAction.java   
/**
 * 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);
}
项目:APICloud-Studio    文件:CheckoutAsProjectOperation.java   
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()]));
}
项目:APICloud-Studio    文件:BranchTagOperation.java   
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()]));
}
项目:Eclipse-Postfix-Code-Completion    文件:SetClasspathOperation.java   
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();
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:SetClasspathOperation.java   
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();
}
项目:subclipse    文件:SVNTeamProvider.java   
public IResourceRuleFactory getRuleFactory() {
    return RESOURCE_RULE_FACTORY;
}
项目:tlaplus    文件:ResourceHelper.java   
public static ISchedulingRule getCreateRule(IResource resource)
{
    IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory();
    return ruleFactory.createRule(resource);
}
项目:che    文件:Rules.java   
void setRuleFactory(IProject project, IResourceRuleFactory factory) {
  if (factory == null) projectsToRules.remove(project.getName());
  else projectsToRules.put(project.getName(), factory);
}
项目:che    文件:InternalTeamHook.java   
protected void setRuleFactory(IProject project, IResourceRuleFactory factory) {
  Workspace workspace = ((Workspace) project.getWorkspace());
  ((Rules) workspace.getRuleFactory()).setRuleFactory(project, factory);
}
项目:che    文件:Rules.java   
void setRuleFactory(IProject project, IResourceRuleFactory factory) {
  if (factory == null) projectsToRules.remove(project.getName());
  else projectsToRules.put(project.getName(), factory);
}
项目:evosuite    文件:TestGenerationAction.java   
/**
 * Add a new test generation job to the job queue
 * 
 * @param target
 */
protected void addTestJob(final IResource target) {
    IJavaElement element = JavaCore.create(target);
    if (element == null) {
        return;
    }
    IJavaElement packageElement = element.getParent();

    String packageName = packageElement.getElementName();

    final String targetClass = (!packageName.isEmpty() ? packageName + "." : "")
            + target.getName().replace(".java", "").replace(File.separator, ".");
    System.out.println("* Scheduling new automated job for " + targetClass);
    final String targetClassWithoutPackage = target.getName().replace(".java", "");

    final String suiteClassName = targetClass + Properties.JUNIT_SUFFIX;

    final String suiteFileName = target.getProject().getLocation() + "/evosuite-tests/" + 
                                    suiteClassName.replace('.', File.separatorChar) + ".java";
    System.out.println("Checking for " + suiteFileName);
    File suiteFile = new File(suiteFileName);
    Job job = null;
    if (suiteFile.exists()) {

        MessageDialog dialog = new MessageDialog(
                shell,
                "Existing test suite found",
                null, // image
                "A test suite for class \""
                        + targetClass
                        + "\" already exists. EvoSuite will overwrite this test suite. Do you really want to proceed?",
                MessageDialog.QUESTION_WITH_CANCEL, new String[] { "Overwrite", "Extend",
                        "Rename Original", "Cancel" }, 0);

        int returnCode = dialog.open();
        // 0 == overwrite
        // 1 == extend
        if(returnCode == 1) {
            IWorkspaceRoot wroot = target.getWorkspace().getRoot();
            IResource suiteResource = wroot.getFileForLocation(new Path(suiteFileName));
            job = new TestExtensionJob(shell, suiteResource, targetClass, suiteClassName);
        }
        else if (returnCode == 2) {
            // 2 == Rename
            renameSuite(target, packageName, targetClassWithoutPackage + Properties.JUNIT_SUFFIX + ".java");
        } else if (returnCode > 2) {
            // Cancel
            return;
        }
    }

    if(job == null)
        job = new TestGenerationJob(shell, target, targetClass, suiteClassName);

    job.setPriority(Job.SHORT);
    IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory();
    ISchedulingRule rule = ruleFactory.createRule(target.getProject());

    //IFolder folder = proj.getFolder(ResourceUtil.EVOSUITE_FILES);
    job.setRule(rule);
    job.setUser(true);
    job.schedule(); // start as soon as possible
}
项目:APICloud-Studio    文件:SVNTeamProvider.java   
public IResourceRuleFactory getRuleFactory() {
    return RESOURCE_RULE_FACTORY;
}
项目:idecore    文件:MarkerUtils.java   
private static ISchedulingRule getRule(IResource resource) {
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IResourceRuleFactory ruleFactory = workspace.getRuleFactory();
    ISchedulingRule rule = ruleFactory.markerRule(resource.getProject());
    return rule;
}
项目:team-explorer-everywhere    文件:TFSRepositoryProvider.java   
/**
 * This must be overridden to prevent an error dialog appearing in newer
 * versions of Eclipse when a TFS-bound project is opened via the "Open"
 * context menu from package explorer.
 *
 * Background:
 *
 * Eclipse uses a mutual exclusion structures named "rules" to prevent
 * multiple workspace jobs from running at once and messing up each other's
 * resources. Rules are created with different scopes (whole workspace, just
 * one project, just one file, etc.) depending on the type of job being run
 * inside the lock. This method returns an {@link IResourceRuleFacctory},
 * which Eclipse calls the right method on to get the correctly scoped lock.
 *
 * An important thing to know about rules: once one rules is in effect, a
 * job can begin more rules, but only if the new rule's scope is equal to or
 * smaller than the old rule.
 *
 * Around Eclipse 3.0, opening a project would cause Eclipse to call
 * {@link IResourceRuleFactory#modifyRule(org.eclipse.core.resources.IResource)}
 * and get back a rule scoped to just the project that was being opened.
 * This sounds like the right scope for opening a project, but it turns out
 * it's common to change project the project description in the job inside
 * the rule (like for CVS Import), but changing the description requires a
 * whole workspace rule! This was reported as bug 127562
 * (https://bugs.eclipse.org/bugs/show_bug.cgi?id=127562) and fixed in CVS
 * revision 1.10 of ResourceRuleFactory.java, which was released in Eclipse
 * 3.2 M5. The fix special-cased the project case and returned a workspace
 * root rule instead of the old project scope rule.
 *
 * But a few years later bug 128709 was logged
 * (https://bugs.eclipse.org/bugs/show_bug.cgi?id=128709) and this special
 * case for the project was removed at CVS revision 1.12. This fix shipped
 * in Eclipse 3.4 M5.
 *
 * So after Eclipse 3.4, project scope is now used for the rule when Eclipse
 * opens a project. Remember how when a rule is open, new rules opened by
 * the same job must be of equal or narrower scope. Well, after Eclipse
 * creates the project scope rule for opening a project, it loads our
 * {@link TFSRepositoryProvider} and calls {@link #getRuleFactory()} to get
 * a second rule (to connect the project to TFS). The default implementation
 * of {@link #getRuleFactory()} is {@link PessimisticResourceRuleFactory}
 * and returns a workspace root rule for the connect action! A workspace
 * root rule is broader in scope than a project rule, and this causes an
 * error!
 *
 * So we override the method to return the same rule factory Eclipse uses to
 * open the project in the first place, which will return a project scoped
 * rule in the second case.
 *
 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=230533#c4
 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=128709
 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=129045
 */
@Override
public IResourceRuleFactory getRuleFactory() {
    return new TFSRepositoryProviderRuleFactory();
}
项目:che    文件:TeamHook.java   
/**
 * Returns the resource scheduling rule factory that should be used when workspace operations are
 * invoked on resources in that project. The workspace will ask the team hook this question only
 * once per project, per session. The workspace will assume the returned result is valid for the
 * rest of that session, unless the rule is changed by calling <code>setRuleFactory</code>.
 *
 * <p>This method must not return <code>null</code>. If no special rules are required by the team
 * hook for the given project, the value of the <code>defaultFactory</code> field should be
 * returned.
 *
 * <p>This default implementation always returns the value of the <code>defaultFactory</code>
 * field. Subclasses may override and provide a subclass of <code>ResourceRuleFactory</code>.
 *
 * @param project the project to return scheduling rules for
 * @return the resource scheduling rules for a project
 * @see #setRuleFactory(IProject, IResourceRuleFactory)
 * @see ResourceRuleFactory
 * @since 3.0
 */
public IResourceRuleFactory getRuleFactory(IProject project) {
  return defaultFactory;
}
项目:che    文件:TeamHook.java   
/**
 * Sets the resource scheduling rule factory to use for resource modifications in the given
 * project. This method only needs to be called if the factory has changed since the initial call
 * to <code>getRuleFactory</code> for the given project
 *
 * <p>The supplied factory must not be <code>null</code>. If no special rules are required by the
 * team hook for the given project, the value of the <code>defaultFactory</code> field should be
 * used.
 *
 * <p>Note that the new rule factory will only take effect for resource changing operations that
 * begin after this method completes. Care should be taken to avoid calling this method during the
 * invocation of any resource changing operation (in any thread). The best time to change rule
 * factories is during resource change notification when the workspace is locked for modification.
 *
 * @param project the project to change the resource rule factory for
 * @param factory the new resource rule factory
 * @see #getRuleFactory(IProject)
 * @see IResourceRuleFactory
 * @since 3.0
 */
@Override
protected final void setRuleFactory(IProject project, IResourceRuleFactory factory) {
  super.setRuleFactory(project, factory);
}