@Override protected IProject[] build(int kind, Map<String, String> args, IProgressMonitor monitor) throws CoreException { IProject project = getProject(); if (project == null) return null; if ((kind == INCREMENTAL_BUILD) || (kind == AUTO_BUILD)) { IResourceDelta delta = getDelta(project); if (delta == null) { project.accept(new PDDLVisitor()); } else { delta.accept(new PDDLVisitor()); } } else if (kind == FULL_BUILD) { project.accept(new PDDLVisitor()); } else if (kind == CLEAN_BUILD) { IPDDLNature nature = PDDLNature.getPDDLNature(project); if (nature != null) { IPDDLProjectIndex index = nature.getPDDLProjectIndex(); if (index != null) index.clear(); } } return null; }
/** * Return the IResource instance that matches the stringified UUID. If the stringified UUID is * null, empty, or does not have a UUID.PROTOCOL prefix then null is returned. If no IResource * instance is found that matches this UUID then null is returned. * * @param stringifiedUuid the stringified form of a UUID instance * @return the IResource */ public static IResource findIResourceByUUID(final String stringifiedUuid) { if (CoreStringUtil.isEmpty(stringifiedUuid) || !stringifiedUuid.startsWith(UUID.PROTOCOL) || getWorkspace() == null) return null; // Collect all IResources within all IProjects final FileResourceCollectorVisitor visitor = new FileResourceCollectorVisitor(); if (getWorkspace() != null && getWorkspace().getRoot() != null) { final IProject[] projects = getWorkspace().getRoot().getProjects(); for (final IProject project : projects) try { project.accept(visitor); } catch (final CoreException e) { // do nothing } } final IFile[] fileResources = visitor.getFileResources(); for (final IFile fileResource : fileResources) { final IFile iResource = fileResource; if (iResource != null && !ModelUtil.isXsdFile(iResource)) { final XMIHeader header = ModelUtil.getXmiHeader(iResource); if (header != null && stringifiedUuid.equals(header.getUUID())) return iResource; } } return null; }
/** * Return the IResource instance that matches the specified path. The path is the relative path in * the workspace. If no IResource instance is found that match this path a null is returned. * * @param name the path to the IResource * @return the IResource */ public static IResource findIResourceByPath(final IPath workspacePath) { if (workspacePath == null || workspacePath.isEmpty() || getWorkspace() == null) return null; // Collect all IResources within all IProjects final FileResourceCollectorVisitor visitor = new FileResourceCollectorVisitor(); if (getWorkspace() != null && getWorkspace().getRoot() != null) { final IProject[] projects = getWorkspace().getRoot().getProjects(); for (final IProject project : projects) try { project.accept(visitor); } catch (final CoreException e) { // do nothing } } final IFile[] fileResources = visitor.getFileResources(); for (final IFile fileResource : fileResources) if (fileResource != null) { final IPath path = fileResource.getFullPath(); // Do not process file names staring with '.' since these // are considered reserved for Eclipse specific files if (path.lastSegment().charAt(0) == '.') continue; if (path.equals(workspacePath)) return fileResource; } return null; }
private void buildIndexHeadDiffList(IProject[] selectedProjects, IProgressMonitor monitor) throws IOException, OperationCanceledException { monitor.beginTask(UIText.CommitActionHandler_calculatingChanges, 1000); EclipseGitProgressTransformer jgitMonitor = new EclipseGitProgressTransformer(monitor); CountingVisitor counter = new CountingVisitor(); for (IProject p : selectedProjects) { try { p.accept(counter); } catch (CoreException e) { // ignore } } WorkingTreeIterator it = IteratorService.createInitialIterator(repo); if (it == null) throw new OperationCanceledException(); // workspace is closed indexDiff = new IndexDiff(repo, Constants.HEAD, it); indexDiff.diff( jgitMonitor, counter.count, 0, NLS.bind(UIText.CommitActionHandler_repository, repo.getDirectory().getPath())); includeList(indexDiff.getAdded(), indexChanges); includeList(indexDiff.getChanged(), indexChanges); includeList(indexDiff.getRemoved(), indexChanges); includeList(indexDiff.getMissing(), notIndexed); includeList(indexDiff.getModified(), notIndexed); includeList(indexDiff.getUntracked(), notTracked); if (monitor.isCanceled()) throw new OperationCanceledException(); monitor.done(); }
public Set<BuildResource> getAffectedResources( @SuppressWarnings("rawtypes") final Map args, final IProject project, final IProgressMonitor monitor) throws CoreException { final Set<BuildResource> result = Sets.newHashSet(); project.accept(new BuilderVisitor(result, monitor, this)); return result; }
private void scanResources(IProject project) throws CoreException { project.accept( new IResourceVisitor() { @Override public boolean visit(IResource resource) throws CoreException { checkName(resource.getName()); return true; } }); }
public void validate(IValidationContext helper, IReporter reporter) throws ValidationException { /* Added by BC ---- */ // if(true) return; /* end Added by BC ---- */ String[] uris = helper.getURIs(); if (uris.length > 0) { IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); IFile currentFile = null; for (int i = 0; i < uris.length && !reporter.isCancelled(); i++) { currentFile = wsRoot.getFile(new Path(uris[i])); reporter.removeAllMessages(this, currentFile); if (currentFile != null && currentFile.exists()) { if (shouldValidate(currentFile)) { // && fragmentCheck(currentFile)) { int percent = (i * 100) / uris.length + 1; IMessage message = new LocalizedMessage( IMessage.LOW_SEVERITY, percent + "% " + uris[i]); // $NON-NLS-1$ reporter.displaySubtask(this, message); validateFile(currentFile, reporter); } if (DEBUG) { System.out.println("validating: [" + uris[i] + "]"); // $NON-NLS-1$ //$NON-NLS-2$ } } } } else { // if uris[] length 0 -> validate() gets called for each project if (helper instanceof IWorkbenchContext) { IProject project = ((IWorkbenchContext) helper).getProject(); JSFileVisitor visitor = new JSFileVisitor(reporter); try { // collect all jsp files for the project project.accept(visitor, IResource.DEPTH_INFINITE); } catch (CoreException e) { if (DEBUG) { e.printStackTrace(); } } IFile[] files = visitor.getFiles(); for (int i = 0; i < files.length && !reporter.isCancelled(); i++) { int percent = (i * 100) / files.length + 1; IMessage message = new LocalizedMessage( IMessage.LOW_SEVERITY, percent + "% " + files[i].getFullPath().toString()); // $NON-NLS-1$ reporter.displaySubtask(this, message); validateFile(files[i], reporter); if (DEBUG) { System.out.println("validating: [" + files[i] + "]"); // $NON-NLS-1$ //$NON-NLS-2$ } } } } }
/** * Iterates through the list of open projects and fires a {@link ResourceVisitor} over each one. * The monitor is told that the job has started and the visitor starts the process that populates * the database. */ private void loadOpenProjectsIntoDb() { for (IProject proj : openProjects) { try { proj.open(null); monitor.beginTask("Filling IFT database with project content.", countTotalJavaFiles(proj)); proj.accept(new ResourceVisitor()); } catch (CoreException e) { eLog.logException(e); } } }
@Override protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException { Buildlet[] buildlets = createBuildlets(); Worker worker = new Worker(buildlets, false); IProject project = getProject(); if (kind == FULL_BUILD) { project.accept(worker); } else { IResourceDelta delta = getDelta(getProject()); if (delta == null) { project.accept(worker); } else { delta.accept(worker); if (worker.getRebuild()) project.accept(worker); } } worker.run(monitor); return null; }
public static IFile[] getProjectFiles(String[] exts) { IProject project = getProject(); if (project == null) return null; MyFileVisit visitor = new MyFileVisit(exts); try { project.accept(visitor); } catch (CoreException e) { e.printStackTrace(); return null; } return visitor.getFiles(); }
private void scanProxies(IProject project) throws CoreException { project.accept( new IResourceProxyVisitor() { @Override public boolean visit(IResourceProxy proxy) throws CoreException { checkName(proxy.getName()); // proxy.requestFullPath(); // proxy.requestResource(); return true; } }, 0); }
private void scanProxiesAndSource(IProject project) throws CoreException { project.accept( new IResourceProxyVisitor() { @Override public boolean visit(IResourceProxy proxy) throws CoreException { checkName(proxy.getName()); // proxy.requestFullPath(); if (proxy.getType() != IResource.FILE || proxy.getName().endsWith(".dart")) { proxy.requestResource(); } return true; } }, 0); }
private IStatus run( IProject project, Map<String, Collection<IFile>> files, IProgressMonitor monitor) { IStatus status = Status.OK_STATUS; if (monitor.isCanceled()) { // setCanceledState(); return Status.CANCEL_STATUS; } if (DEBUG) System.out.println(" ^ IndexWorkspaceJob started: "); // $NON-NLS-1$ Thread.currentThread().setPriority(Thread.MAX_PRIORITY); long start = System.currentTimeMillis(); try { XMLReferencesFileVisitor visitor = new XMLReferencesFileVisitor(files, monitor); // collect all jsp files if (project != null) { project.accept(visitor, IResource.DEPTH_INFINITE); // IProject[] referencingProjects = project // .getReferencingProjects(); // for (int i = 0; i < referencingProjects.length; i++) { // referencingProjects[i].accept(visitor, // IResource.DEPTH_INFINITE); // } } else { ResourcesPlugin.getWorkspace().getRoot().accept(visitor, IResource.DEPTH_INFINITE); } // request indexing // this is pretty much like faking an entire workspace resource // delta // XMLReferenceIndexManager.getInstance().indexFiles( // visitor.getFiles()); } catch (CoreException e) { if (DEBUG) e.printStackTrace(); } finally { monitor.done(); } long finish = System.currentTimeMillis(); if (DEBUG) System.out.println( " ^ IndexWorkspaceJob finished\n total time running: " + (finish - start)); // $NON-NLS-1$ return status; }
public String getXtextPath() { if (createdProject != null) { FileFinderVisitor odesignProjectVisitor = new FileFinderVisitor("xtext"); try { createdProject.accept(odesignProjectVisitor); IFile odesignIFile = odesignProjectVisitor.getFile(); if (odesignIFile != null) { return "/" + createdProject.getName() + "/" + odesignIFile.getProjectRelativePath().toString(); } } catch (CoreException e) { Activator.error(e.getMessage(), e); } } return ""; }
private static IFile[] getAllProjectsFileResources() { // Collect all IResources within all IProjects final FileResourceCollectorVisitor visitor = new FileResourceCollectorVisitor(); final IWorkspace workSpace = getWorkspace(); if (workSpace != null && workSpace.getRoot() != null) { final IWorkspaceRoot wsRoot = workSpace.getRoot(); final IProject[] projects = wsRoot.getProjects(); for (final IProject project : projects) if (project.isOpen()) try { project.accept(visitor); } catch (final CoreException e) { // do nothing ModelerCore.Util.log(e); } } return visitor.getFileResources(); }
public ToBeBuilt updateProject(IProject project, IProgressMonitor monitor) throws CoreException { final SubMonitor progress = SubMonitor.convert(monitor, Messages.ToBeBuiltComputer_CollectingReosurces, 1); progress.subTask(Messages.ToBeBuiltComputer_CollectingReosurces); final ToBeBuilt toBeBuilt = removeProject(project, progress.newChild(1)); if (!project.isAccessible()) return toBeBuilt; if (progress.isCanceled()) throw new OperationCanceledException(); project.accept( new IResourceVisitor() { public boolean visit(IResource resource) throws CoreException { if (progress.isCanceled()) throw new OperationCanceledException(); if (resource instanceof IStorage) { return updateStorage(null, toBeBuilt, (IStorage) resource); } return true; } }); return toBeBuilt; }
public void testReadFiles() throws MalformedURLException, CoreException, FileNotFoundException { File dir = new File( getTestFilesDirectory()); // new // File("D:/eclipsedev/eclipse-M7/eclipse/workspace/org.eclipse.jst.jsp.tests.encoding/testfiles/jsp"); if (dir.exists() && dir.isDirectory()) { IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("sp"); project.create(null); project.open(null); copy(dir, project); joinBackgroundJobs(); final List files = new ArrayList(); project.accept( new IResourceProxyVisitor() { public boolean visit(IResourceProxy proxy) throws CoreException { if (proxy.getName().endsWith(".jsp")) { files.add(proxy.requestResource()); } return true; } }, IContainer.INCLUDE_PHANTOMS); tagAsSummary( "Open JSP Editor", new Dimension[] {Dimension.ELAPSED_PROCESS, Dimension.WORKING_SET}); startMeasuring(); IFile file = (IFile) files.get(0); for (int i = 0; i < ITERATIONS; i++) { openEditor(file); closeAllEditors(); // System.out.println("run #:" + i); } stopMeasuring(); commitMeasurements(); // assert heap usage assertPerformance(); } else fail(dir.toString()); }
private void configureTeamPrivateResource(IProject project) { try { project.accept( new IResourceVisitor() { public boolean visit(IResource resource) throws CoreException { if ((resource.getType() == IResource.FOLDER) && (resource .getName() .equals(SVNProviderPlugin.getPlugin().getAdminDirectoryName())) && (!resource.isTeamPrivateMember())) { resource.setTeamPrivateMember(true); return false; } else { return true; } } }, IResource.DEPTH_INFINITE, IContainer.INCLUDE_PHANTOMS | IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS); } catch (CoreException e) { SVNProviderPlugin.log(SVNException.wrapException(e)); } }
/** * For a full build, we grab all files inside the project and then call build on each file. * * @param monitor * @throws CoreException */ private void fullBuild(List<IBuildParticipant> participants, IProgressMonitor monitor) throws CoreException { SubMonitor sub = SubMonitor.convert(monitor, 100); indexProjectBuildPaths(sub.newChild(50)); // Index files contributed... // TODO Remove these special "contributed" files? IProject project = getProjectHandle(); URI uri = project.getLocationURI(); Set<IFileStore> contributedFiles = getContributedFiles(uri); sub.worked(2); buildContributedFiles(participants, contributedFiles, sub.newChild(6)); // Now index the actual files in the project CollectingResourceVisitor visitor = new CollectingResourceVisitor(); project.accept(visitor); visitor.files.trimToSize(); // shrink it down to size when we're done sub.worked(2); buildFiles(participants, visitor.files, sub.newChild(40)); sub.done(); }
public static Collection getAllWorkspaceResources(final ResourceFilter filter) { // Collect all IResources within all IProjects final FileResourceCollectorVisitor visitor = new FileResourceCollectorVisitor(filter); final IProject[] projects = ModelerCore.getWorkspace().getRoot().getProjects(); for (final IProject project : projects) try { project.accept(visitor); } catch (final CoreException e) { // do nothing } final Collection fileResources = visitor.getFileResourcesCollection(); final Iterator itor = fileResources.iterator(); while (itor.hasNext()) { final IFile fileResource = (IFile) itor.next(); final IPath path = fileResource.getFullPath(); // Do not process file names starting with '.' since these // are considered reserved for Eclipse specific files if (path.lastSegment().charAt(0) == '.') itor.remove(); } // endwhile return fileResources; }
/** * Return the array of IResource instances that match the specified name. The name must consist of * only one path segment and may or may not have a file extension. If no IResource instances are * found that match this name an empty array is returned. * * @param name the name of the IResource * @return the IResource[] */ public static IResource[] findIResourceByName(final String name) { if (name == null || name.length() == 0 || getWorkspace() == null) return EMPTY_IRESOURCE_ARRAY; // Collect all IResources within all IProjects final FileResourceCollectorVisitor visitor = new FileResourceCollectorVisitor(); if (getWorkspace() != null && getWorkspace().getRoot() != null) { final IProject[] projects = getWorkspace().getRoot().getProjects(); for (final IProject project : projects) try { project.accept(visitor); } catch (final CoreException e) { // do nothing } } // Try to match the specified resource name with one of the IResource instances final boolean removeExtension = (name.indexOf('.') == -1); final IFile[] fileResources = visitor.getFileResources(); final ArrayList tmp = new ArrayList(); for (final IFile fileResource : fileResources) if (fileResource != null) { IPath path = fileResource.getFullPath(); // Do not process file names staring with '.' since these // are considered reserved for Eclipse specific files if (path.lastSegment().charAt(0) == '.') continue; if (removeExtension) path = path.removeFileExtension(); if (name.equalsIgnoreCase(path.lastSegment())) tmp.add(fileResource); } // If no matching resources are found return an empty array if (tmp.size() == 0) return EMPTY_IRESOURCE_ARRAY; final IResource[] result = new IResource[tmp.size()]; tmp.toArray(result); return result; }
private void renamePatternDefinitionFiles(IProject project) throws CoreException { final IProgressMonitor monitor = new NullProgressMonitor(); project.accept( new IResourceVisitor() { @Override public boolean visit(IResource resource) throws CoreException { if (resource instanceof IFile && "eiq".equals(resource.getFileExtension())) { ((IFile) resource) .move( resource.getFullPath().removeFileExtension().addFileExtension("vql"), false, monitor); } else if (resource instanceof IFile && "eiqgen".equals(resource.getFileExtension())) { ((IFile) resource) .move( resource.getFullPath().removeFileExtension().addFileExtension("vqgen"), false, monitor); } return true; } }); }
protected void createNewXTextProject() { /* * MessageDialog.openWarning( * PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), * "Gemoc Language Workbench UI", * "Action not completly implemented yet"); */ // create xtext project from existing ecore model // wizard id = // org.eclipse.xtext.xtext.ui.wizard.ecore2xtext.NewXtextProjectFromEcoreWizard // launch the appropriate wizard IWizardDescriptor descriptor = WizardFinder.findNewWizardDescriptor( "org.eclipse.xtext.xtext.ui.wizard.ecore2xtext.NewXtextProjectFromEcoreWizard"); // Then if we have a wizard, open it. if (descriptor != null) { // add a listener to capture the creation of the resulting project NewProjectWorkspaceListener workspaceListener = new NewProjectWorkspaceListener(); ResourcesPlugin.getWorkspace().addResourceChangeListener(workspaceListener); try { IWizard wizard; wizard = descriptor.createWizard(); // this wizard need some dedicated initialization // ((EcoreModelerWizard )wizard).init(PlatformUI.getWorkbench(), // (IStructuredSelection) // PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection()); // ((EcoreModelWizard)wizard).init(PlatformUI.getWorkbench(), // (IStructuredSelection) selection); WizardDialog wd = new WizardDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), wizard); wd.create(); wd.setTitle(wizard.getWindowTitle()); int res = wd.open(); if (res == WizardDialog.OK) { ResourcesPlugin.getWorkspace().removeResourceChangeListener(workspaceListener); ArrayList<IProject> newlyCreatedProjects = workspaceListener.getNewlyCreatedProjects(); // find the created project with xtext files in it FileFinderVisitor fileFinder = new FileFinderVisitor("xtext"); for (Iterator<IProject> iterator = newlyCreatedProjects.iterator(); iterator.hasNext(); ) { IProject iProject = (IProject) iterator.next(); iProject.accept(fileFinder); if (fileFinder.getFile() != null) { createdProject = iProject; break; } } // update the project configuration model if (createdProject != null) { XTextEditorProject editorProject = Xdsml_baseFactoryImpl.eINSTANCE.createXTextEditorProject(); editorProject.setProjectName(createdProject.getName()); addOrUpdateProjectToConf(editorProject); } else { Activator.error("not able to detect which project was created by wizard", null); } } } catch (CoreException e) { Activator.error(e.getMessage(), e); } finally { // make sure to remove listener in all situations ResourcesPlugin.getWorkspace().removeResourceChangeListener(workspaceListener); } } else { Activator.error( "wizard with id=org.eclipse.xtext.xtext.ui.wizard.ecore2xtext.NewXtextProjectFromEcoreWizard not found", null); } }
/** * 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; } }); } }
@Override public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException { final Map<IFile, TextChange> fileChanges = new HashMap<IFile, TextChange>(); IResourceProxyVisitor visitor = new IResourceProxyVisitor() { public boolean visit(IResourceProxy proxy) throws CoreException { if ((proxy.getType() == IResource.FOLDER) || (proxy.getType() == IResource.PROJECT)) { return true; } if (!((proxy.getType() == IResource.FILE) && proxy.getName().toLowerCase().endsWith(".bnd"))) { return false; } /* we're dealing with a *.bnd file */ /* get the proxied file */ IFile resource = (IFile) proxy.requestResource(); /* read the file as a single string */ String bndFileText = null; try { bndFileText = FileUtils.readFully(resource).get(); } catch (Exception e) { String str = "Could not read file " + proxy.getName(); logger.logError(str, e); throw new OperationCanceledException(str); } /* * get the previous change for this file if it exists, or otherwise create a new change for it, but do * not store it yet: wait until we know if there are actually changes in the file */ TextChange fileChange = getTextChange(resource); final boolean fileChangeIsNew = (fileChange == null); if (fileChange == null) { fileChange = new TextFileChange(proxy.getName(), resource); fileChange.setEdit(new MultiTextEdit()); } TextEdit rootEdit = fileChange.getEdit(); /* loop over all renames to perform */ for (Map.Entry<IPackageFragment, RenameArguments> entry : pkgFragments.entrySet()) { IPackageFragment pkgFragment = entry.getKey(); RenameArguments arguments = entry.getValue(); final String oldName = pkgFragment.getElementName(); final String newName = arguments.getNewName(); Pattern pattern = Pattern.compile( /* match start boundary */ "(^|" + grammarSeparator + ")" + /* match itself / package name */ "(" + Pattern.quote(oldName) + ")" + /* match end boundary */ "(" + grammarSeparator + "|" + Pattern.quote(".*") + "|" + Pattern.quote("\\") + "|$)"); /* find all matches to replace and add them to the root edit */ Matcher matcher = pattern.matcher(bndFileText); while (matcher.find()) { rootEdit.addChild( new ReplaceEdit(matcher.start(2), matcher.group(2).length(), newName)); } pattern = Pattern.compile( /* match start boundary */ "(^|" + grammarSeparator + ")" + /* match bundle activator */ "(Bundle-Activator\\s*:\\s*)" + /* match itself / package name */ "(" + Pattern.quote(oldName) + ")" + /* match class name */ "(\\.[^\\.]+)" + /* match end boundary */ "(" + grammarSeparator + "|" + Pattern.quote("\\") + "|$)"); /* find all matches to replace and add them to the root edit */ matcher = pattern.matcher(bndFileText); while (matcher.find()) { rootEdit.addChild( new ReplaceEdit(matcher.start(3), matcher.group(3).length(), newName)); } } /* * only store the changes when no changes were stored before for this file and when there are actually * changes. */ if (fileChangeIsNew && rootEdit.hasChildren()) { fileChanges.put(resource, fileChange); } return false; } }; /* determine which projects have to be visited */ Set<IProject> projectsToVisit = new HashSet<IProject>(); for (IPackageFragment pkgFragment : pkgFragments.keySet()) { projectsToVisit.add(pkgFragment.getResource().getProject()); for (IProject projectToVisit : pkgFragment.getResource().getProject().getReferencingProjects()) { projectsToVisit.add(projectToVisit); } for (IProject projectToVisit : pkgFragment.getResource().getProject().getReferencedProjects()) { projectsToVisit.add(projectToVisit); } } /* visit the projects */ for (IProject projectToVisit : projectsToVisit) { projectToVisit.accept(visitor, IContainer.NONE); } if (fileChanges.isEmpty()) { /* no changes at all */ return null; } /* build a composite change with all changes */ CompositeChange cs = new CompositeChange(changeTitle); for (TextChange fileChange : fileChanges.values()) { cs.add(fileChange); } return cs; }