private Map promptForOverwrite(List plugins, List locales) { Map overwrites = new HashMap(); if (overwriteWithoutAsking) return overwrites; for (Iterator iter = plugins.iterator(); iter.hasNext(); ) { IPluginModelBase plugin = (IPluginModelBase) iter.next(); for (Iterator it = locales.iterator(); it.hasNext(); ) { Locale locale = (Locale) it.next(); IProject project = getNLProject(plugin, locale); if (project.exists() && !overwrites.containsKey(project.getName())) { boolean overwrite = MessageDialog.openConfirm( PDEPlugin.getActiveWorkbenchShell(), PDEUIMessages.InternationalizeWizard_NLSFragmentGenerator_overwriteTitle, NLS.bind( PDEUIMessages.InternationalizeWizard_NLSFragmentGenerator_overwriteMessage, pluginName(plugin, locale))); overwrites.put(project.getName(), overwrite ? OVERWRITE : null); } } } return overwrites; }
/** Tests a builder that requests deltas for closed and missing projects. */ public void testRequestMissingProject() { // add builder and do an initial build to get the instance try { addBuilder(project1, DeltaVerifierBuilder.BUILDER_NAME); project1.build(IncrementalProjectBuilder.FULL_BUILD, getMonitor()); } catch (CoreException e) { fail("1.0", e); } final DeltaVerifierBuilder builder = DeltaVerifierBuilder.getInstance(); assertTrue("1.1", builder != null); // always check deltas for all projects final IProject[] allProjects = new IProject[] {project1, project2, project3, project4}; try { project2.close(getMonitor()); project3.delete(IResource.ALWAYS_DELETE_PROJECT_CONTENT, getMonitor()); } catch (CoreException e1) { fail("1.99", e1); } builder.checkDeltas(allProjects); // modify a file in project1 to force an autobuild try { file1.setContents(getRandomContents(), IResource.NONE, getMonitor()); } catch (CoreException e2) { fail("2.99", e2); } }
private boolean isDerivedEncodingStoredSeparately(IProject project) { // be careful looking up for our node so not to create any nodes as side effect Preferences node = Platform.getPreferencesService().getRootNode().node(ProjectScope.SCOPE); try { // TODO once bug 90500 is fixed, should be as simple as this: // String path = project.getName() + IPath.SEPARATOR + ResourcesPlugin.PI_RESOURCES; // return node.nodeExists(path) ? // node.node(path).getBoolean(ResourcesPlugin.PREF_SEPARATE_DERIVED_ENCODINGS, false) : false; // for now, take the long way if (!node.nodeExists(project.getName())) return ResourcesPlugin.DEFAULT_PREF_SEPARATE_DERIVED_ENCODINGS; node = node.node(project.getName()); if (!node.nodeExists(ResourcesPlugin.PI_RESOURCES)) return ResourcesPlugin.DEFAULT_PREF_SEPARATE_DERIVED_ENCODINGS; node = node.node(ResourcesPlugin.PI_RESOURCES); return node.getBoolean( ResourcesPlugin.PREF_SEPARATE_DERIVED_ENCODINGS, ResourcesPlugin.DEFAULT_PREF_SEPARATE_DERIVED_ENCODINGS); } catch (BackingStoreException e) { // nodeExists failed String message = Messages.resources_readingEncoding; Policy.log( new ResourceStatus( IResourceStatus.FAILED_GETTING_CHARSET, project.getFullPath(), message, e)); return ResourcesPlugin.DEFAULT_PREF_SEPARATE_DERIVED_ENCODINGS; } }
/** * Check if model version is changed and rebuild PHP projects if necessary. * * @see PHPCoreConstants.STRUCTURE_VERSION */ private void rebuildProjects() { IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode(ID); String modelVersion = preferences.get(PHPCoreConstants.STRUCTURE_VERSION_PREFERENCE, null); if (PHPCoreConstants.STRUCTURE_VERSION.equals(modelVersion)) { return; } preferences.put( PHPCoreConstants.STRUCTURE_VERSION_PREFERENCE, PHPCoreConstants.STRUCTURE_VERSION); try { preferences.flush(); } catch (BackingStoreException e1) { Logger.logException(e1); } IWorkspace workspace = ResourcesPlugin.getWorkspace(); IProject[] projects = workspace.getRoot().getProjects(); if (workspace.isAutoBuilding()) { try { for (IProject project : projects) { if (PHPToolkitUtil.isPhpProject(project)) { project.build(IncrementalProjectBuilder.CLEAN_BUILD, null); } } } catch (CoreException e) { Logger.logException(e); } } }
/** * Return if the project has the given nature. * * @param project * @param natureId * @return <code>true</code> if project has given nature * @since 1.0.0 */ public static boolean hasRuntime(IProject project, String natureId) { if (project == null || !project.isAccessible()) return false; try { return project.hasNature(natureId); } catch (CoreException e) { return false; } }
/** Tries to delete a folder containing an unremovable file. Works only for Windows. */ public void testDeleteFolderWindows() { if (!isWindows()) return; IProject project = null; InputStream input = null; File projectRoot = null; try { IWorkspace workspace = getWorkspace(); project = workspace.getRoot().getProject(getUniqueString()); IFolder folder = project.getFolder("a_folder"); IFile file1 = folder.getFile("file1.txt"); IFile file3 = folder.getFile("file3.txt"); ensureExistsInWorkspace(new IResource[] {file1, file3}, true); projectRoot = project.getLocation().toFile(); // opens a file so it cannot be removed on Windows try { input = file1.getContents(); } catch (CoreException ce) { ce.printStackTrace(); fail("1.0"); } try { folder.delete(IResource.FORCE, getMonitor()); fail("2.0 - should have failed"); } catch (CoreException ce) { // success - a file couldn't be removed } assertTrue("2.2", file1.exists()); assertTrue("2.4", !file3.exists()); assertTrue("2.5", folder.exists()); assertTrue("2.7", folder.isSynchronized(IResource.DEPTH_INFINITE)); assertClose(input); assertTrue("3.5", project.isSynchronized(IResource.DEPTH_INFINITE)); try { folder.delete(IResource.FORCE, getMonitor()); } catch (CoreException ce) { ce.printStackTrace(); fail("4.0", ce); } assertTrue("5.1", !file1.exists()); assertTrue("5.2", !folder.exists()); assertTrue("5.3", file1.isSynchronized(IResource.DEPTH_INFINITE)); assertTrue("5.4", folder.isSynchronized(IResource.DEPTH_INFINITE)); } finally { try { assertClose(input); } finally { if (projectRoot != null) ensureDoesNotExistInFileSystem(projectRoot); } } }
@Override protected IStatus run(IProgressMonitor monitor) { MultiStatus result = new MultiStatus( ResourcesPlugin.PI_RESOURCES, IResourceStatus.FAILED_SETTING_CHARSET, Messages.resources_updatingEncoding, null); monitor = Policy.monitorFor(monitor); try { monitor.beginTask(Messages.resources_charsetUpdating, Policy.totalWork); final ISchedulingRule rule = workspace.getRuleFactory().modifyRule(workspace.getRoot()); try { workspace.prepareOperation(rule, monitor); workspace.beginOperation(true); Map.Entry<IProject, Boolean> next; while ((next = getNextChange()) != null) { // just exit if the system is shutting down or has been shut down // it is too late to change the workspace at this point anyway if (systemBundle.getState() != Bundle.ACTIVE) return Status.OK_STATUS; IProject project = next.getKey(); try { if (project.isAccessible()) { boolean shouldDisableCharsetDeltaJob = next.getValue().booleanValue(); // flush preferences for non-derived resources flushPreferences( getPreferences(project, false, false, true), shouldDisableCharsetDeltaJob); // flush preferences for derived resources flushPreferences( getPreferences(project, false, true, true), shouldDisableCharsetDeltaJob); } } catch (BackingStoreException e) { // we got an error saving String detailMessage = Messages.resources_savingEncoding; result.add( new ResourceStatus( IResourceStatus.FAILED_SETTING_CHARSET, project.getFullPath(), detailMessage, e)); } } monitor.worked(Policy.opWork); } catch (OperationCanceledException e) { workspace.getWorkManager().operationCanceled(); throw e; } finally { workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork)); } } catch (CoreException ce) { return ce.getStatus(); } finally { monitor.done(); } return result; }
@Override public String getNodeDescription() { try { final IProject project = getProject(); return project == null ? null : project.getDescription().getComment(); } catch (CoreException e) { log.debug(e); return null; } }
private void setProjectNatures(IProject project, IFeatureModel model, IProgressMonitor monitor) throws CoreException { IProjectDescription desc = project.getDescription(); if (needsJavaNature(model)) { desc.setNatureIds(new String[] {JavaCore.NATURE_ID, MDE.FEATURE_NATURE}); } else { desc.setNatureIds(new String[] {MDE.FEATURE_NATURE}); } project.setDescription(desc, new SubProgressMonitor(monitor, 1)); }
public void test01_prepareWorkspace() throws CoreException, URISyntaxException { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IProject project = workspace.getRoot().getProject("project"); ensureExistsInWorkspace(project, true); IFile link = project.getFile("link_to_file"); link.createLink( new URI("bug369177:/dummy_path.txt"), IResource.ALLOW_MISSING_LOCAL, getMonitor()); workspace.save(true, getMonitor()); }
protected IProject getProject(String name) { IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IProject[] projects = workspaceRoot.getProjects(); if (projects == null || projects.length == 0) return null; for (IProject project : projects) { if (project.getName().equals(name)) return project; } return null; }
public static ISharpenProject create(IProject project, IProgressMonitor monitor) throws CoreException { if (!project.hasNature(SharpenNature.NATURE_ID)) { return null; } ISharpenProject cached = (ISharpenProject) project.getSessionProperty(PROJECT_SESSION_KEY); if (null == cached) { cached = new SharpenProject(project); project.setSessionProperty(PROJECT_SESSION_KEY, cached); } return cached; }
/** Tries to delete a folder containing an irremovable file. Works only for Linux with natives. */ public void testDeleteFolderLinux() { if (!(Platform.getOS().equals(Platform.OS_LINUX))) return; IProject project = null; File projectRoot = null; IFolder subFolder = null; try { IWorkspace workspace = getWorkspace(); project = workspace.getRoot().getProject(getUniqueString()); IFolder folder = project.getFolder("a_folder"); subFolder = folder.getFolder("sub-folder"); IFile file1 = subFolder.getFile("file1.txt"); IFile file3 = folder.getFile("file3.txt"); ensureExistsInWorkspace(new IResource[] {file1, file3}, true); projectRoot = project.getLocation().toFile(); // marks sub-folder as read-only so its files cannot be removed on Linux setReadOnly(subFolder, true); try { folder.delete(IResource.FORCE, getMonitor()); fail("2.0 - should have failed"); } catch (CoreException ce) { // success - a file couldn't be removed } assertTrue("2.2", file1.exists()); assertTrue("2.3", subFolder.exists()); assertTrue("2.4", !file3.exists()); assertTrue("2.5", folder.exists()); assertTrue("2.7", folder.isSynchronized(IResource.DEPTH_INFINITE)); setReadOnly(subFolder, false); assertTrue("3.5", project.isSynchronized(IResource.DEPTH_INFINITE)); try { folder.delete(IResource.FORCE, getMonitor()); } catch (CoreException ce) { ce.printStackTrace(); fail("4.0", ce); } assertTrue("5.1", !file1.exists()); assertTrue("5.2", !subFolder.exists()); assertTrue("5.3", !folder.exists()); assertTrue("5.4", file1.isSynchronized(IResource.DEPTH_INFINITE)); assertTrue("5.5", folder.isSynchronized(IResource.DEPTH_INFINITE)); } finally { if (subFolder != null && subFolder.exists()) setReadOnly(subFolder, false); if (projectRoot != null) ensureDoesNotExistInFileSystem(projectRoot); } }
/* * @see TestCase#setUp() */ protected void setUp() throws Exception { super.setUp(); setAutoBuilding(true); IWorkspaceRoot root = getWorkspace().getRoot(); project1 = root.getProject("Project1"); project2 = root.getProject("Project2"); project3 = root.getProject("Project3"); project4 = root.getProject("Project4"); file1 = project1.getFile("File1"); file2 = project2.getFile("File2"); file3 = project3.getFile("File3"); file4 = project4.getFile("File4"); IResource[] resources = {project1, project2, project3, project4, file1, file2, file3, file4}; ensureExistsInWorkspace(resources, true); }
protected void mergeEncodingPreferences(IProject project) { Preferences projectRegularPrefs = null; Preferences projectDerivedPrefs = getPreferences(project, false, true, true); if (projectDerivedPrefs == null) return; try { boolean prefsChanged = false; String[] affectedResources; affectedResources = projectDerivedPrefs.keys(); for (int i = 0; i < affectedResources.length; i++) { String path = affectedResources[i]; String value = projectDerivedPrefs.get(path, null); projectDerivedPrefs.remove(path); // lazy creation of non-derived preferences if (projectRegularPrefs == null) projectRegularPrefs = getPreferences(project, true, false, false); projectRegularPrefs.put(path, value); prefsChanged = true; } if (prefsChanged) { Map<IProject, Boolean> projectsToSave = new HashMap<>(); // this is internal change so do not notify charset delta job projectsToSave.put(project, Boolean.TRUE); job.addChanges(projectsToSave); } } catch (BackingStoreException e) { // problems with the project scope... we will miss the changes (but will log) String message = Messages.resources_readingEncoding; Policy.log( new ResourceStatus( IResourceStatus.FAILED_GETTING_CHARSET, project.getFullPath(), message, e)); } }
protected void setUp() throws Exception { super.setUp(); existingProject = getWorkspace().getRoot().getProject("ExistingProject"); existingVirtualFolderInExistingProject = existingProject.getFolder("existingVirtualFolderInExistingProject"); doCleanup(); }
/** * Creates an NL fragment project along with the locale specific properties files. * * @throws CoreException * @throws IOException * @throws InvocationTargetException * @throws InterruptedException */ private void internationalizePlugins(List plugins, List locales, Map overwrites) throws CoreException, IOException, InvocationTargetException, InterruptedException { Set created = new HashSet(); for (Iterator it = plugins.iterator(); it.hasNext(); ) { IPluginModelBase plugin = (IPluginModelBase) it.next(); for (Iterator iter = locales.iterator(); iter.hasNext(); ) { Locale locale = (Locale) iter.next(); IProject project = getNLProject(plugin, locale); if (created.contains(project) || overwriteWithoutAsking || !project.exists() || OVERWRITE == overwrites.get(project.getName())) { if (!created.contains(project) && project.exists()) { project.delete(true, getProgressMonitor()); } if (!created.contains(project)) { createNLFragment(plugin, project, locale); created.add(project); project.getFolder(RESOURCE_FOLDER_PARENT).create(false, true, getProgressMonitor()); } project .getFolder(RESOURCE_FOLDER_PARENT) .getFolder(locale.toString()) .create(true, true, getProgressMonitor()); createLocaleSpecificPropertiesFile(project, plugin, locale); } } } }
/** * The worker method. It will find the container, create the file if missing or just replace its * contents, and open the editor on the newly created file. */ private void doFinish(String containerName, String fileName, IProgressMonitor monitor) throws CoreException { // create a sample file monitor.beginTask("Creating " + fileName, 2); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IResource resource = root.findMember(new Path(containerName)); // if (!(resource.exists()) || !(resource instanceof IContainer)) { if (resource == null || !(resource.exists()) || !(resource instanceof IContainer)) { // throwCoreException("Container \"" + containerName + // "\" does not exist."); IProject datamapperProject = root.getProject(containerName); datamapperProject.create(null); datamapperProject.open(null); // datamapperProject. } IContainer container = (IContainer) resource; // // // final IFile file = container.getFile(new Path(fileName)); // try { // InputStream stream = openContentStream(); // if (file.exists()) { // // file.setContents(null, true, true, monitor); // } else { // file.create(null, true, monitor); // // } // stream.close();` // } catch (IOException e) { // } // monitor.worked(1); // monitor.setTaskName("Opening file for editing..."); // getShell().getDisplay().asyncExec(new Runnable() { // public void run() { // IWorkbenchPage page = // PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); // try { // IDE.openEditor(page, file); // } catch (PartInitException e) { // } // } // }); // monitor.worked(1); }
/** * Return a list of nature ids based on the natures that have been configured for this project. * * @return list of configured nature ids. * @param project */ public static List getRegisteredRuntimeIDs(IProject project) { List result = null; String natureID = null; if (project != null && project.isAccessible()) { Iterator it = EMFNatureRegistry.singleton().REGISTERED_NATURE_IDS.iterator(); while (it.hasNext()) { natureID = (String) it.next(); try { if (project.hasNature(natureID)) { if (result == null) result = new ArrayList(2); result.add(natureID); } } catch (CoreException e) { } } } return result == null ? Collections.EMPTY_LIST : result; }
private static void setUpProject() throws Exception { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject project = root.getProject("test.rap"); if (!project.exists()) { project.create(null); project.open(null); } IFolder webInf = project.getFolder("WEB-INF"); if (!webInf.exists()) { webInf.create(true, true, null); } IFile file = webInf.getFile("web.xml"); if (!file.exists()) { File tempFile = File.createTempFile("test", ".xml"); FileInputStream stream = new FileInputStream(tempFile); file.create(stream, true, null); } }
public void testIsVirtual() { // create a virtual folder IFolder virtualFolder = existingProject.getFolder(getUniqueString()); try { virtualFolder.create(IResource.VIRTUAL, true, null); } catch (CoreException e) { fail("1.0", e); } assertTrue("2.0", virtualFolder.isVirtual()); }
public void testContainsServletBridgeLibrary() throws Exception { IWARProduct product = createBasicProduct(); IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); IProject project = wsRoot.getProject("warProduct"); if (!project.exists()) { project.create(null); project.open(null); } IFile jar = project.getFile(SERVLETBRIDGE + ".jar"); if (!jar.exists()) { File bridge = File.createTempFile(SERVLETBRIDGE, ".jar"); FileInputStream stream = new FileInputStream(bridge); jar.create(stream, true, null); } product.addLibrary(jar.getFullPath(), false); Validator validator = new Validator(product); Validation validation = validator.validate(); assertTrue(validation.isValid()); }
private void createParents(IProject fragmentProject, IPath parent) throws CoreException { String[] segments = parent.segments(); String path = new String(); for (int i = 0; i < segments.length; i++) { path += SLASH + segments[i]; IFolder folder = fragmentProject.getFolder(path); if (!folder.exists()) { folder.create(true, true, getProgressMonitor()); } } }
public void testDeleteProjectWithVirtualFolderAndLink() { IPath folderLocation = getRandomLocation(); IFolder virtualFolder = existingProject.getFolder(getUniqueString()); IFolder linkedFolder = virtualFolder.getFolder("a_link"); try { try { folderLocation.toFile().mkdir(); virtualFolder.create(IResource.VIRTUAL, true, null); linkedFolder.createLink(folderLocation, IResource.NONE, getMonitor()); existingProject.delete(IResource.NEVER_DELETE_PROJECT_CONTENT, getMonitor()); existingProject.create(getMonitor()); } catch (CoreException e) { fail("1.0", e); } // virtual folder should not exist until the project is open assertTrue("2.0", !virtualFolder.exists()); assertTrue("3.0", !linkedFolder.exists()); try { existingProject.open(getMonitor()); } catch (CoreException e) { fail("4.0", e); } // virtual folder should now exist assertTrue("5.0", virtualFolder.exists()); assertTrue("6.0", virtualFolder.isVirtual()); // link should now exist assertTrue("7.0", linkedFolder.exists()); assertTrue("8.0", linkedFolder.isLinked()); assertEquals("9.0", folderLocation, linkedFolder.getLocation()); } finally { Workspace.clear(folderLocation.toFile()); } }
public void testMoveProjectWithVirtualFolder() { IPath fileLocation = getRandomLocation(); IPath folderLocation = getRandomLocation(); IFile file = existingVirtualFolderInExistingProject.getFile(getUniqueString()); IFolder folder = existingVirtualFolderInExistingProject.getFolder(getUniqueString()); IFile childFile = folder.getFile(getUniqueString()); IResource[] oldResources = new IResource[] {existingProject, file, folder, childFile}; try { assertDoesNotExistInWorkspace("1.0", new IResource[] {folder, file, childFile}); try { createFileInFileSystem(fileLocation); folderLocation.toFile().mkdir(); folder.createLink(folderLocation, IResource.NONE, getMonitor()); file.createLink(fileLocation, IResource.NONE, getMonitor()); childFile.create(getRandomContents(), true, getMonitor()); } catch (CoreException e) { fail("2.0", e); } // move the project IProject destinationProject = getWorkspace().getRoot().getProject("MoveTargetProject"); assertDoesNotExistInWorkspace("3.0", destinationProject); try { existingProject.move(destinationProject.getFullPath(), IResource.SHALLOW, getMonitor()); } catch (CoreException e) { fail("4.0", e); } IFile newFile = destinationProject.getFile(file.getProjectRelativePath()); IFolder newFolder = destinationProject.getFolder(folder.getProjectRelativePath()); IFile newChildFile = newFolder.getFile(childFile.getName()); IResource[] newResources = new IResource[] {destinationProject, newFile, newFolder, newChildFile}; assertExistsInWorkspace("5.0", newResources); assertDoesNotExistInWorkspace("6.1", oldResources); assertTrue("7.0", existingProject.isSynchronized(IResource.DEPTH_INFINITE)); assertTrue("8.0", destinationProject.isSynchronized(IResource.DEPTH_INFINITE)); assertTrue("9.0", newFile.getParent().isVirtual()); assertTrue("10.0", newFile.isLinked()); assertTrue("11.0", newFolder.isLinked()); assertTrue("12.0", newFolder.getParent().isVirtual()); } finally { Workspace.clear(fileLocation.toFile()); Workspace.clear(folderLocation.toFile()); } }
/* * Instruct the build manager that this project is involved in a cycle and * needs to propagate structural changes to the other projects in the cycle. */ void mustPropagateStructuralChanges() { LinkedHashSet cycleParticipants = new LinkedHashSet(3); this.javaProject.updateCycleParticipants( new ArrayList(), cycleParticipants, this.workspaceRoot, new HashSet(3), null); IPath currentPath = this.javaProject.getPath(); Iterator i = cycleParticipants.iterator(); while (i.hasNext()) { IPath participantPath = (IPath) i.next(); if (participantPath != currentPath) { IProject project = this.workspaceRoot.getProject(participantPath.segment(0)); if (hasBeenBuilt(project)) { if (DEBUG) System.out.println( "JavaBuilder: Requesting another build iteration since cycle participant " + project.getName() // $NON-NLS-1$ + " has not yet seen some structural changes"); //$NON-NLS-1$ needRebuild(); return; } } } }
private void registerInWorkspaceIfNeeded() { IPath jarPath = fJarPackage.getAbsolutePharLocation(); IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); for (int i = 0; i < projects.length; i++) { IProject project = projects[i]; // The Jar is always put into the local file system. So it can only be // part of a project if the project is local as well. So using getLocation // is currently save here. IPath projectLocation = project.getLocation(); if (projectLocation != null && projectLocation.isPrefixOf(jarPath)) { try { jarPath = jarPath.removeFirstSegments(projectLocation.segmentCount()); jarPath = jarPath.removeLastSegments(1); IResource containingFolder = project.findMember(jarPath); if (containingFolder != null && containingFolder.isAccessible()) containingFolder.refreshLocal(IResource.DEPTH_ONE, null); } catch (CoreException ex) { // don't refresh the folder but log the problem PHPUiPlugin.log(ex); } } } }
private void setClasspath(IProject project, IFeatureModel model, IProgressMonitor monitor) throws JavaModelException { IJavaProject jProject = JavaCore.create(project); IClasspathEntry jreCPEntry = JavaCore.newContainerEntry( new Path("org.eclipse.jdt.launching.JRE_CONTAINER")); // $NON-NLS-1$ String libName = model.getFeature().getInstallHandler().getLibrary(); IClasspathEntry handlerCPEntry = JavaCore.newLibraryEntry(project.getFullPath().append(libName), null, null); jProject.setRawClasspath(new IClasspathEntry[] {jreCPEntry, handlerCPEntry}, monitor); }
/** * Ensure that the sync info for all the provided resources has been loaded. If an out-of-sync * resource is found, prompt to refresh all the projects involved. */ protected boolean ensureSyncInfoLoaded(IResource[] resources) throws CVSException { boolean keepTrying = true; while (keepTrying) { try { EclipseSynchronizer.getInstance().ensureSyncInfoLoaded(resources, getActionDepth()); keepTrying = false; } catch (CVSException e) { if (e.getStatus().getCode() == IResourceStatus.OUT_OF_SYNC_LOCAL) { // determine the projects of the resources involved Set projects = new HashSet(); for (int i = 0; i < resources.length; i++) { IResource resource = resources[i]; projects.add(resource.getProject()); } // prompt to refresh if (promptToRefresh( getShell(), (IResource[]) projects.toArray(new IResource[projects.size()]), e.getStatus())) { for (Iterator iter = projects.iterator(); iter.hasNext(); ) { IProject project = (IProject) iter.next(); try { project.refreshLocal(IResource.DEPTH_INFINITE, null); } catch (CoreException coreException) { throw CVSException.wrapException(coreException); } } } else { return false; } } else { throw e; } } } return true; }
public void setCharsetFor(IPath resourcePath, String newCharset) throws CoreException { // for the workspace root we just set a preference in the instance scope if (resourcePath.segmentCount() == 0) { IEclipsePreferences resourcesPreferences = InstanceScope.INSTANCE.getNode(ResourcesPlugin.PI_RESOURCES); if (newCharset != null) resourcesPreferences.put(ResourcesPlugin.PREF_ENCODING, newCharset); else resourcesPreferences.remove(ResourcesPlugin.PREF_ENCODING); try { resourcesPreferences.flush(); } catch (BackingStoreException e) { IProject project = workspace.getRoot().getProject(resourcePath.segment(0)); String message = Messages.resources_savingEncoding; throw new ResourceException( IResourceStatus.FAILED_SETTING_CHARSET, project.getFullPath(), message, e); } return; } // for all other cases, we set a property in the corresponding project IResource resource = workspace.getRoot().findMember(resourcePath); if (resource != null) { try { // disable the listener so we don't react to changes made by ourselves Preferences encodingSettings = getPreferences( resource.getProject(), true, resource.isDerived(IResource.CHECK_ANCESTORS)); if (newCharset == null || newCharset.trim().length() == 0) encodingSettings.remove(getKeyFor(resourcePath)); else encodingSettings.put(getKeyFor(resourcePath), newCharset); flushPreferences(encodingSettings, true); } catch (BackingStoreException e) { IProject project = workspace.getRoot().getProject(resourcePath.segment(0)); String message = Messages.resources_savingEncoding; throw new ResourceException( IResourceStatus.FAILED_SETTING_CHARSET, project.getFullPath(), message, e); } } }