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; }
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; } }
@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; }
/** 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); } } }
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 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); } }
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)); } }
/** * 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 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()); } } }
/* * 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); } } }
/** Goes over the given projects and converts them */ private void processProjects(final IProject[] projects) throws CoreException, ModelException { ProjectsIterate: for (IProject project : projects) { // skip unaccessible projects if (!project.isAccessible()) { continue ProjectsIterate; } // verify that the project is a PHP project if (PHPToolkitUtil.isPhpProject(project)) { IProjectDescription projectDescription = project.getDescription(); ICommand[] commands = projectDescription.getBuildSpec(); // check if the Script Builder is installed for (int i = 0; i < commands.length; ++i) { if (commands[i].getBuilderName().equals(DLTKCore.BUILDER_ID)) { // when the builder exists - continue to the next // project continue ProjectsIterate; } } // perform modifications only if the builder is not installed modifyProject(project); } } }
Preferences getPreferences( IProject project, boolean create, boolean isDerived, boolean isDerivedEncodingStoredSeparately) { boolean localIsDerived = isDerivedEncodingStoredSeparately ? isDerived : false; String qualifier = localIsDerived ? ProjectPreferences.PREFS_DERIVED_QUALIFIER : ProjectPreferences.PREFS_REGULAR_QUALIFIER; if (create) // create all nodes down to the one we are interested in return new ProjectScope(project).getNode(qualifier).node(ResourcesPlugin.PREF_ENCODING); // 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 + // IPath.SEPARATOR + ENCODING_PREF_NODE; // return node.nodeExists(path) ? node.node(path) : null; // for now, take the long way if (!node.nodeExists(project.getName())) return null; node = node.node(project.getName()); if (!node.nodeExists(qualifier)) return null; node = node.node(qualifier); if (!node.nodeExists(ResourcesPlugin.PREF_ENCODING)) return null; return node.node(ResourcesPlugin.PREF_ENCODING); } catch (BackingStoreException e) { // nodeExists failed String message = Messages.resources_readingEncoding; Policy.log( new ResourceStatus( IResourceStatus.FAILED_GETTING_CHARSET, project.getFullPath(), message, e)); } return null; }
private void addProjectSourceContainers(IProject project, ArrayList result) throws CoreException { if (project == null || !project.hasNature(JavaCore.NATURE_ID)) return; IJavaProject jProject = JavaCore.create(project); result.add(JavaRuntime.newProjectRuntimeClasspathEntry(jProject)); IClasspathEntry[] entries = jProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IRuntimeClasspathEntry rte = convertClasspathEntry(entry); if (rte != null) result.add(rte); } } }
private void createBuildProperties(IProject project) { IFile file = PDEProject.getBuildProperties(project); if (!file.exists()) { WorkspaceBuildModel model = new WorkspaceBuildModel(file); IBuildEntry ientry = model.getFactory().createEntry("bin.includes"); // $NON-NLS-1$ try { IResource[] res = project.members(); for (int i = 0; i < res.length; i++) { String path = res[i].getProjectRelativePath().toString(); if (!path.equals(".project")) // $NON-NLS-1$ ientry.addToken(path); } model.getBuild().add(ientry); model.save(); } catch (CoreException e) { } } }
private boolean moveSettingsIfDerivedChanged( IResourceDelta parent, IProject currentProject, Preferences projectPrefs, String[] affectedResources) { boolean resourceChanges = false; if ((parent.getFlags() & IResourceDelta.DERIVED_CHANGED) != 0) { // if derived changed, move encoding to correct preferences IPath parentPath = parent.getResource().getProjectRelativePath(); for (int i = 0; i < affectedResources.length; i++) { IPath affectedPath = new Path(affectedResources[i]); // if parentPath is an ancestor of affectedPath if (parentPath.isPrefixOf(affectedPath)) { IResource member = currentProject.findMember(affectedPath); if (member != null) { Preferences targetPrefs = getPreferences(currentProject, true, member.isDerived(IResource.CHECK_ANCESTORS)); // if new preferences are different than current if (!projectPrefs.absolutePath().equals(targetPrefs.absolutePath())) { // remove encoding from old preferences and save in correct preferences String currentValue = projectPrefs.get(affectedResources[i], null); projectPrefs.remove(affectedResources[i]); targetPrefs.put(affectedResources[i], currentValue); resourceChanges = true; } } } } } IResourceDelta[] children = parent.getAffectedChildren(); for (int i = 0; i < children.length; i++) { resourceChanges = moveSettingsIfDerivedChanged( children[i], currentProject, projectPrefs, affectedResources) || resourceChanges; } return resourceChanges; }
public void resourceChanged(IResourceChangeEvent event) { if (event.getBuildKind() == IncrementalProjectBuilder.CLEAN_BUILD) { Object source = event.getSource(); try { if (source instanceof IProject) { IProject project = (IProject) source; ProjectIndexerManager.removeProject(project.getFullPath()); ProjectIndexerManager.indexProject(project); } else if (source instanceof IWorkspace) { IWorkspace workspace = (IWorkspace) source; IProject[] projects = workspace.getRoot().getProjects(); // remove from index: for (IProject project : projects) { if (!project.isAccessible()) { continue; } IScriptProject scriptProject = DLTKCore.create(project); if (scriptProject.isOpen()) { IProjectFragment[] projectFragments = scriptProject.getProjectFragments(); for (IProjectFragment projectFragment : projectFragments) { ProjectIndexerManager.removeProjectFragment( scriptProject, projectFragment.getPath()); } ProjectIndexerManager.removeProject(project.getFullPath()); } } // add to index: for (IProject project : projects) { if (!project.isAccessible()) { continue; } ProjectIndexerManager.indexProject(project); } } } catch (CoreException e) { Logger.logException(e); } } }
/** * Tries to delete a closed project containing an unremovable file. Works only for Linux with * natives. * * <p>TODO: enable this test once bug 48321 is fixed. */ public void testDeleteClosedProjectLinux() { if (!(Platform.getOS().equals(Platform.OS_LINUX))) return; IProject project = null; File projectRoot = null; IFolder folder = null; try { IWorkspace workspace = getWorkspace(); project = workspace.getRoot().getProject(getUniqueString()); folder = project.getFolder("a_folder"); IFile file1 = folder.getFile("file1.txt"); IFile file2 = project.getFile("file2.txt"); IFile projectFile = project.getFile(new Path(".project")); ensureExistsInWorkspace(new IResource[] {file1, file2}, true); projectRoot = project.getLocation().toFile(); // marks folder as read-only so its files cannot be removed on Linux setReadOnly(folder, true); try { project.close(getMonitor()); } catch (CoreException e) { fail("1.0", e); } try { project.delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, getMonitor()); fail("2.0 - should have failed"); } catch (CoreException ce) { // success - a file couldn't be removed } assertTrue("3.0", project.exists()); assertTrue("3.1", project.isSynchronized(IResource.DEPTH_INFINITE)); assertExistsInFileSystem("3.2", projectFile); try { project.open(getMonitor()); } catch (CoreException e) { fail("4.0", e); } setReadOnly(folder, false); try { project.delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, getMonitor()); } catch (CoreException ce) { ce.printStackTrace(); fail("5.0", ce); } assertTrue("6.0", !project.exists()); assertTrue("6.1", project.isSynchronized(IResource.DEPTH_INFINITE)); assertTrue("6.2", !projectRoot.exists()); assertDoesNotExistInFileSystem("6.3", projectFile); } finally { if (folder != null && folder.exists()) setReadOnly(folder, false); if (projectRoot != null) ensureDoesNotExistInFileSystem(projectRoot); } }
/** * Creates a locale specific properties file within the fragment project based on the content of * the host plug-in's properties file. * * @param fragmentProject * @param locale * @throws CoreException * @throws IOException */ private void createLocaleSpecificPropertiesFile( final IProject fragmentProject, IPluginModelBase plugin, final Locale locale) throws CoreException, IOException { final IFolder localeResourceFolder = fragmentProject.getFolder(RESOURCE_FOLDER_PARENT).getFolder(locale.toString()); // Case 1: External plug-in if (plugin instanceof ExternalPluginModelBase) { final String installLocation = plugin.getInstallLocation(); // Case 1a: External plug-in is a jar file if (new File(installLocation).isFile()) { ZipFile zf = new ZipFile(installLocation); for (Enumeration e = zf.entries(); e.hasMoreElements(); ) { worked(); ZipEntry zfe = (ZipEntry) e.nextElement(); String name = zfe.getName(); String[] segments = name.split(SLASH); IPath path = Path.fromPortableString(join(SLASH, segments, 0, segments.length - 1)); String resourceName = segments[segments.length - 1]; String localizedResourceName = localeSpecificName(resourceName, locale); if (propertiesFilter.include(name)) { createParents(fragmentProject, path); IFile file = fragmentProject.getFile(path.append(localizedResourceName)); InputStream is = zf.getInputStream(zfe); file.create(is, false, getProgressMonitor()); } else if (resourceFilter.include(name)) { IPath target = localeResourceFolder.getFullPath().append(path).append(resourceName); createParents(fragmentProject, target.removeLastSegments(1).removeFirstSegments(1)); IFile file = fragmentProject.getFile(target.removeFirstSegments(1)); file.create(zf.getInputStream(zfe), false, getProgressMonitor()); } } } // Case 1b: External plug-in has a folder structure else { Visitor visitor = new Visitor() { public void visit(File file) throws CoreException, FileNotFoundException { worked(); String relativePath = file.getAbsolutePath() .substring(installLocation.length()) .replaceAll(File.separator, SLASH); String[] segments = relativePath.split(SLASH); IPath path = Path.fromPortableString(join(SLASH, segments, 0, segments.length - 1)); String resourceName = segments[segments.length - 1]; String localizedResourceName = localeSpecificName(resourceName, locale); if (propertiesFilter.include( relativePath + (file.isDirectory() ? SLASH : EMPTY_STRING))) { createParents(fragmentProject, path); IFile iFile = fragmentProject.getFile(path.append(localizedResourceName)); iFile.create(new FileInputStream(file), false, getProgressMonitor()); } else if (resourceFilter.include( relativePath + (file.isDirectory() ? SLASH : EMPTY_STRING))) { IPath target = localeResourceFolder.getFullPath().append(relativePath); createParents( fragmentProject, target.removeLastSegments(1).removeFirstSegments(1)); IFile iFile = fragmentProject.getFile(target.removeFirstSegments(1)); iFile.create(new FileInputStream(file), false, getProgressMonitor()); } if (file.isDirectory()) { File[] children = file.listFiles(); for (int i = 0; i < children.length; i++) { visit(children[i]); } } } }; visitor.visit(new File(installLocation)); } } // Case 2: Workspace plug-in else { final IProject project = plugin.getUnderlyingResource().getProject(); project.accept( new IResourceVisitor() { public boolean visit(IResource resource) throws CoreException { worked(); IPath parent = resource.getFullPath().removeLastSegments(1).removeFirstSegments(1); if (propertiesFilter.include(resource)) { String segment = localeSpecificName(resource.getFullPath().lastSegment(), locale); IPath fragmentResource = fragmentProject.getFullPath().append(parent).append(segment); createParents(fragmentProject, parent); resource.copy(fragmentResource, true, getProgressMonitor()); } else if (resourceFilter.include(resource)) { IPath target = localeResourceFolder .getFullPath() .append(parent) .append(resource.getFullPath().lastSegment()); createParents(fragmentProject, target.removeLastSegments(1).removeFirstSegments(1)); resource.copy(target, true, getProgressMonitor()); } return true; } }); } }
/** * The worker method. It will create a new project, then create the appropriate Soar heirarchy and * files. */ private void doFinish(String projectName, IProgressMonitor monitor) throws CoreException { monitor.beginTask("Creating " + projectName, 7); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject newProject = root.getProject(projectName); // creation of the project if (newProject.exists()) { throwCoreException("Project \"" + projectName + "\" already exists"); } else { newProject.create(monitor); newProject.open(monitor); try { IProjectDescription description = newProject.getDescription(); String[] natures = description.getNatureIds(); String[] newNatures = new String[natures.length + 1]; System.arraycopy(natures, 0, newNatures, 0, natures.length); newNatures[natures.length] = SoarProjectNature.NATURE_ID; description.setNatureIds(newNatures); newProject.setDescription(description, IResource.FORCE, monitor); newProject.setPersistentProperty(DataMap.VERTEX_ID, "0"); } catch (CoreException e) { e.printStackTrace(); } // catch } // else monitor.worked(2); // Create the contents of the project's root directory IFolder folderAll = newProject.getFolder("all"); if (!folderAll.exists()) { folderAll.create(true, true, monitor); } // if FileMarker.markResource(folderAll, "file"); IFolder folderElaborations = newProject.getFolder("elaborations"); if (!folderElaborations.exists()) { folderElaborations.create(true, true, monitor); } // if FileMarker.markResource(folderElaborations, "file"); IFile file_firstload = newProject.getFile("_firstload.soar"); if (!file_firstload.exists()) { file_firstload.create( Utility.getFileTemplate(file_firstload, "_firstload.soar"), true, monitor); } // if FileMarker.markResource(file_firstload, "file"); IFile filedatamap = newProject.getFile("datamap.xdm"); if (!filedatamap.exists()) { filedatamap.create(Utility.getFileTemplate(filedatamap, "datamap.xdm"), true, monitor); } // if monitor.worked(3); // Create the contents of the elaborations folder IFile file_all = folderElaborations.getFile("_all.soar"); if (!file_all.exists()) { file_all.create(Utility.getFileTemplate(file_all, "_all.soar"), true, monitor); } // if FileMarker.markResource(file_all, "file"); IFile filetopstate = folderElaborations.getFile("top-state.soar"); if (!filetopstate.exists()) { filetopstate.create(Utility.getFileTemplate(filetopstate, "top-state.soar"), true, monitor); } // if FileMarker.markResource(filetopstate, "file"); SourcingFile.createSourcingFile(newProject, monitor); newProject.close(monitor); newProject.open(monitor); monitor.worked(2); monitor.done(); } // void doFinish(...)
/** Tries to delete a closed project containing an unremovable file. Works only for Windows. */ public void testDeleteClosedProjectWindows() { if (!isWindows()) return; IProject project = null; InputStream input = null; File projectRoot = null; IFile file1 = null; try { IWorkspace workspace = getWorkspace(); project = workspace.getRoot().getProject(getUniqueString()); IFolder folder = project.getFolder("a_folder"); file1 = folder.getFile("file1.txt"); IFile file2 = project.getFile("file2.txt"); IFile file3 = folder.getFile("file3.txt"); IFile projectFile = project.getFile(new Path(".project")); ensureExistsInWorkspace(new IResource[] {file1, file2, 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 { project.close(getMonitor()); } catch (CoreException e) { fail("1.1", e); } try { project.delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, getMonitor()); fail("2.0 - should have failed"); } catch (CoreException ce) { // success - a file couldn't be removed } assertTrue("2.1", project.exists()); assertTrue("2.7", project.isSynchronized(IResource.DEPTH_INFINITE)); assertExistsInFileSystem("2.8", projectFile); assertClose(input); assertTrue("3.5", project.isSynchronized(IResource.DEPTH_INFINITE)); try { project.delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, getMonitor()); } catch (CoreException ce) { ce.printStackTrace(); fail("4.0", ce); } assertTrue("5.1", !project.exists()); assertTrue("5.3", project.isSynchronized(IResource.DEPTH_INFINITE)); assertTrue("6.0", !projectRoot.exists()); assertDoesNotExistInFileSystem("7.0", projectFile); } finally { try { if (input != null) input.close(); } catch (IOException e) { fail("8.0", e); } finally { if (projectRoot != null) ensureDoesNotExistInFileSystem(projectRoot); } } }
/** Tries to delete an open project containing an unremovable file. Works only for Windows. */ public void testDeleteOpenProjectWindows() { 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 file2 = project.getFile("file2.txt"); IFile file3 = folder.getFile("file3.txt"); IFile projectFile = project.getFile(new Path(".project")); ensureExistsInWorkspace(new IResource[] {file1, file2, file3}, true); projectRoot = project.getLocation().toFile(); assertExistsInFileSystem("0.0", file1); assertExistsInFileSystem("0.1", file2); assertExistsInFileSystem("0.2", file3); assertExistsInFileSystem("0.3", folder); assertExistsInFileSystem("0.4", projectFile); // opens a file so it cannot be removed on Windows try { input = file1.getContents(); } catch (CoreException ce) { ce.printStackTrace(); fail("1.0"); } assertTrue("1.2", projectFile.exists()); assertTrue("1.3", projectFile.isSynchronized(IResource.DEPTH_INFINITE)); try { project.delete(IResource.FORCE, getMonitor()); fail("2.0 - should have failed"); } catch (CoreException ce) { // success - a file couldn't be removed } // Delete is best-case so check all the files. // Do a check on disk and in the workspace in case something is out of sync. assertExistsInWorkspace("2.1.1", project); assertExistsInFileSystem("2.1.2", project); assertExistsInWorkspace("2.2.1", file1); assertExistsInFileSystem("2.2.2", file1); assertTrue("2.2.3", file1.isSynchronized(IResource.DEPTH_INFINITE)); assertDoesNotExistInWorkspace("2.3.1", file2); assertDoesNotExistInFileSystem("2.3.2", file2); assertTrue("2.3.3", file2.isSynchronized(IResource.DEPTH_INFINITE)); assertDoesNotExistInWorkspace("2.4.1", file3); assertDoesNotExistInFileSystem("2.4.2", file3); assertTrue("2.4.3", file3.isSynchronized(IResource.DEPTH_INFINITE)); assertExistsInWorkspace("2.5.1", folder); assertExistsInFileSystem("2.5.2", folder); assertTrue("2.5.3", folder.isSynchronized(IResource.DEPTH_INFINITE)); assertExistsInWorkspace("2.6.1", projectFile); assertExistsInFileSystem("2.6.2", projectFile); assertTrue("2.6.3", projectFile.isSynchronized(IResource.DEPTH_INFINITE)); assertTrue("2.7.0", project.isSynchronized(IResource.DEPTH_ZERO)); assertTrue("2.7.1", project.isSynchronized(IResource.DEPTH_INFINITE)); assertClose(input); assertTrue("3.5", project.isSynchronized(IResource.DEPTH_INFINITE)); try { project.delete(IResource.FORCE, getMonitor()); } catch (CoreException e) { fail("4.0", e); } assertTrue("5.1", !project.exists()); assertTrue("5.2", !file1.exists()); assertTrue("5.3", file1.isSynchronized(IResource.DEPTH_INFINITE)); assertTrue("5.4", project.isSynchronized(IResource.DEPTH_INFINITE)); assertTrue("6.0", !projectRoot.exists()); } finally { try { assertClose(input); } finally { if (projectRoot != null) ensureDoesNotExistInFileSystem(projectRoot); } } }