/** * 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; }
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()])); }
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; }
/** 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; }
@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; }
/** * 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); }
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(); }
public IResourceRuleFactory getRuleFactory() { return RESOURCE_RULE_FACTORY; }
public static ISchedulingRule getCreateRule(IResource resource) { IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory(); return ruleFactory.createRule(resource); }
void setRuleFactory(IProject project, IResourceRuleFactory factory) { if (factory == null) projectsToRules.remove(project.getName()); else projectsToRules.put(project.getName(), factory); }
protected void setRuleFactory(IProject project, IResourceRuleFactory factory) { Workspace workspace = ((Workspace) project.getWorkspace()); ((Rules) workspace.getRuleFactory()).setRuleFactory(project, factory); }
/** * 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 }
private static ISchedulingRule getRule(IResource resource) { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IResourceRuleFactory ruleFactory = workspace.getRuleFactory(); ISchedulingRule rule = ruleFactory.markerRule(resource.getProject()); return rule; }
/** * 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(); }
/** * 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; }
/** * 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); }