Java Code Examples for org.eclipse.core.resources.IResource#exists()
The following examples show how to use
org.eclipse.core.resources.IResource#exists() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReorgPolicyFactory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public boolean canEnable() throws JavaModelException { IResource[] resources= getResources(); for (int i= 0; i < resources.length; i++) { IResource resource= resources[i]; if (!resource.exists() || resource.isPhantom() || !resource.isAccessible()) return false; } IJavaElement[] javaElements= getJavaElements(); for (int i= 0; i < javaElements.length; i++) { IJavaElement element= javaElements[i]; if (!element.exists()) return false; } return resources.length > 0 || javaElements.length > 0; }
Example 2
Source File: ReorgPolicyFactory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override protected RefactoringStatus verifyDestination(IResource resource) throws JavaModelException { Assert.isNotNull(resource); if (!resource.exists() || resource.isPhantom()) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_phantom); if (!resource.isAccessible()) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_inaccessible); if (resource.getType() == IResource.ROOT) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_not_this_resource); if (isChildOfOrEqualToAnyFolder(resource)) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_not_this_resource); if (containsLinkedResources() && !ReorgUtils.canBeDestinationForLinkedResources(resource)) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_linked); return new RefactoringStatus(); }
Example 3
Source File: ShowPropertiesSynchronizeAction.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
protected FastSyncInfoFilter getSyncInfoFilter() { return new FastSyncInfoFilter() { public boolean select(SyncInfo info) { SyncInfoDirectionFilter outgoingFilter = new SyncInfoDirectionFilter(new int[] {SyncInfo.OUTGOING}); if (!outgoingFilter.select(info)) return false; IStructuredSelection selection = getStructuredSelection(); if (selection.size() != 1) return false; ISynchronizeModelElement element = (ISynchronizeModelElement)selection.getFirstElement(); IResource resource = element.getResource(); if (resource == null) return false; ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resource); try { return !svnResource.getStatus().isDeleted() && svnResource.getStatus().isManaged() && resource.exists(); } catch (SVNException e) { return false; } } }; }
Example 4
Source File: RenameResourceAndCloseEditorAction.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
public void run() { IResource currentResource = getCurrentResource(); if (currentResource == null || !currentResource.exists()) { return; } if (LTKLauncher.openRenameWizard(getStructuredSelection())) { return; } if (this.navigatorTree == null) { // Do a quick read only and null check if (!checkReadOnlyAndNull(currentResource)) { return; } String newName = queryNewResourceName(currentResource); if (newName == null || newName.equals("")) { //$NON-NLS-1$ return; } newPath = currentResource.getFullPath().removeLastSegments(1) .append(newName); super.run(); } else { runWithInlineEditor(); } }
Example 5
Source File: TmfTraceManager.java From tracecompass with Eclipse Public License 2.0 | 6 votes |
/** * Refresh the supplementary files resources for a trace, so it can pick up * new files that got created. * * @param trace * The trace for which to refresh the supplementary files */ public static void refreshSupplementaryFiles(ITmfTrace trace) { IResource resource = trace.getResource(); if (resource != null && resource.exists()) { String supplFolderPath = getSupplementaryFileDir(trace); IProject project = resource.getProject(); /* Remove the project's path from the supplementary path dir */ if (!supplFolderPath.startsWith(project.getLocation().toOSString())) { Activator.logWarning(String.format("Supplementary files folder for trace %s is not within the project.", trace.getName())); //$NON-NLS-1$ return; } IFolder supplFolder = project.getFolder(supplFolderPath.substring(project.getLocationURI().getPath().length())); if (supplFolder.exists()) { try { supplFolder.refreshLocal(IResource.DEPTH_INFINITE, null); } catch (CoreException e) { Activator.logError("Error refreshing resources", e); //$NON-NLS-1$ } } } }
Example 6
Source File: JarEntryAwareTrace.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
protected AbsoluteURI resolvePath(IJavaProject javaProject, SourceRelativeURI path) { try { for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { IResource resource = root.getResource(); if (resource instanceof IFolder) { IFolder folder = (IFolder) resource; String decodedPath = URI.decode(path.toString()); IResource candidate = folder.findMember(decodedPath); if (candidate != null && candidate.exists()) return new AbsoluteURI(URI.createPlatformResourceURI(resource.getFullPath() + "/" + decodedPath, true)); } } } catch (JavaModelException e) { log.error("Error resolving path", e); } return null; }
Example 7
Source File: PropertyConflict.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
public static String getConflictSummary(ISVNLocalResource svnResource) throws Exception { String conflictSummary = null; IResource resource = svnResource.getResource(); IResource conflictFile = null; if (resource instanceof IContainer) { conflictFile = ((IContainer)resource).getFile(new Path("dir_conflicts.prej")); } else { IContainer parent = resource.getParent(); if (parent != null) { conflictFile = parent.getFile(new Path(resource.getName() + ".prej")); } } if (conflictFile != null && conflictFile.exists()) { conflictSummary = getConflictFileContents(new File(conflictFile.getLocation().toString())); } return conflictSummary; }
Example 8
Source File: CrossflowDocumentProvider.java From scava with Eclipse Public License 2.0 | 6 votes |
/** * @generated */ private ISchedulingRule computeSchedulingRule(IResource toCreateOrModify) { if (toCreateOrModify.exists()) return ResourcesPlugin.getWorkspace().getRuleFactory().modifyRule(toCreateOrModify); IResource parent = toCreateOrModify; do { /* * XXX This is a workaround for * https://bugs.eclipse.org/bugs/show_bug.cgi?id=67601 * IResourceRuleFactory.createRule should iterate the hierarchy * itself. */ toCreateOrModify = parent; parent = toCreateOrModify.getParent(); } while (parent != null && !parent.exists()); return ResourcesPlugin.getWorkspace().getRuleFactory().createRule(toCreateOrModify); }
Example 9
Source File: JdtClasspathUriResolver.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
private URI findResourceInProjectRoot(IJavaProject javaProject, String path, Set<String> visited) throws CoreException { boolean includeAll = visited.isEmpty(); if (visited.add(javaProject.getElementName())) { IProject project = javaProject.getProject(); IResource resourceFromProjectRoot = project.findMember(path); if (resourceFromProjectRoot != null && resourceFromProjectRoot.exists()) { return createPlatformResourceURI(resourceFromProjectRoot); } for(IClasspathEntry entry: javaProject.getResolvedClasspath(true)) { if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { if (includeAll || entry.isExported()) { IResource referencedProject = project.getWorkspace().getRoot().findMember(entry.getPath()); if (referencedProject != null && referencedProject.getType() == IResource.PROJECT) { IJavaProject referencedJavaProject = JavaCore.create((IProject) referencedProject); if (referencedJavaProject.exists()) { URI result = findResourceInProjectRoot(referencedJavaProject, path, visited); if (result != null) { return result; } } } break; } } } } return null; }
Example 10
Source File: ResourceUtils.java From xds-ide with Eclipse Public License 1.0 | 5 votes |
public static int findMaxProblemSeverity(IResource[] resources, String type, boolean includeSubtypes, int depth) throws CoreException { int max = -1; for (IResource res : resources) { if (res.getProject().isOpen() && res.exists()) { max = Math.max(max, res.findMaxProblemSeverity(type, includeSubtypes, depth)); if (max >= IMarker.SEVERITY_ERROR) { break; } } } return max; }
Example 11
Source File: ProjectResourceSaveControl.java From depan with Apache License 2.0 | 5 votes |
public IFile getResourceLocation() throws CoreException { String containerName = getContainerName(); String inputName = getInputName(); IResource resource = WorkspaceTools.buildWorkspaceResource(new Path(containerName)); if (!(resource instanceof IContainer) || !resource.exists()) { String msg = MessageFormat.format( "Container \'{0}\' does not exist.", containerName); PlatformTools.throwCoreException( msg, "com.google.devtools.depan.platform.ui"); } return PlatformTools.buildResourceFile( (IContainer) resource, inputName); }
Example 12
Source File: AbstractFileStore.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
@Override public byte[] toByteArray() throws IOException { final IResource resource = getResource(); if (resource.exists()) { final File file = resource.getLocation().toFile(); if (file.isFile()) { return Files.toByteArray(file); } } throw new FileNotFoundException(String.format("%s not found", resource.getLocation().toOSString())); }
Example 13
Source File: JavaWorkingSetUpdater.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void checkElementExistence(IWorkingSet workingSet) { List<IAdaptable> elements= new ArrayList<IAdaptable>(Arrays.asList(workingSet.getElements())); boolean changed= false; for (Iterator<IAdaptable> iter= elements.iterator(); iter.hasNext();) { IAdaptable element= iter.next(); boolean remove= false; if (element instanceof IJavaElement) { IJavaElement jElement= (IJavaElement)element; // If we have directly a project then remove it when it // doesn't exist anymore. However if we have a sub element // under a project only remove the element if the parent // project is open. Otherwise we would remove all elements // in closed projects. if (jElement instanceof IJavaProject) { remove= !jElement.exists(); } else { final IJavaProject javaProject= jElement.getJavaProject(); final boolean isProjectOpen= javaProject != null ? javaProject.getProject().isOpen() : true; remove= isProjectOpen && !jElement.exists(); } } else if (element instanceof IResource) { IResource resource= (IResource)element; // See comments above if (resource instanceof IProject) { remove= !resource.exists(); } else { IProject project= resource.getProject(); remove= (project != null ? project.isOpen() : true) && !resource.exists(); } } if (remove) { iter.remove(); changed= true; } } if (changed) { workingSet.setElements(elements.toArray(new IAdaptable[elements.size()])); } }
Example 14
Source File: RenameSourceFolderChange.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static RefactoringStatus checkIfModifiable(IPackageFragmentRoot root) throws CoreException { RefactoringStatus result= new RefactoringStatus(); if (root == null) { result.addFatalError(RefactoringCoreMessages.DynamicValidationStateChange_workspace_changed); return result; } if (!root.exists()) { result.addFatalError(Messages.format(RefactoringCoreMessages.Change_does_not_exist, getRootLabel(root))); return result; } if (result.hasFatalError()) return result; if (root.isArchive()) { result.addFatalError(Messages.format(RefactoringCoreMessages.RenameSourceFolderChange_rename_archive, getRootLabel(root))); return result; } if (root.isExternal()) { result.addFatalError(Messages.format(RefactoringCoreMessages.RenameSourceFolderChange_rename_external, getRootLabel(root))); return result; } IResource correspondingResource= root.getCorrespondingResource(); if (correspondingResource == null || !correspondingResource.exists()) { result.addFatalError(Messages.format(RefactoringCoreMessages.RenameSourceFolderChange_error_underlying_resource_not_existing, getRootLabel(root))); return result; } if (correspondingResource.isLinked()) { result.addFatalError(Messages.format(RefactoringCoreMessages.RenameSourceFolderChange_rename_linked, getRootLabel(root))); return result; } return result; }
Example 15
Source File: ClasspathResourceUtilities.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
/** * Determines if a resource is available on a project's classpath. This method searches both source paths and JAR/ZIP * files. */ public static boolean isResourceOnClasspath(IJavaProject javaProject, IPath resourcePath) throws JavaModelException { String pckg = JavaUtilities.getPackageNameFromPath(resourcePath.removeLastSegments(1)); String fileName = resourcePath.lastSegment(); for (IPackageFragment pckgFragment : JavaModelSearch.getPackageFragments(javaProject, pckg)) { if (ClasspathResourceUtilities.isFileOnPackageFragment(fileName, pckgFragment)) { return true; } } // If the resource doesn't follow normal java naming convention for resources, such as /resources/folder-name/file-name.js for (IPackageFragmentRoot root : javaProject.getAllPackageFragmentRoots()) { IPackageFragment folderFragment = root.getPackageFragment(pckg); IResource folder = folderFragment.getResource(); if (folder == null || !folder.exists() || !(folder instanceof IContainer)) { continue; } IResource resource = ((IContainer) folder).findMember(fileName); if (resource != null && resource.exists()) { return true; } } // Not there return false; }
Example 16
Source File: Animator.java From txtUML with Eclipse Public License 1.0 | 5 votes |
private void addAnimationMarker(EObject eobject) { IResource resource = null; IWorkspace workspace = ResourcesPlugin.getWorkspace(); if (workspace != null) { URI uri = eobject.eResource().getURI(); if (uri.isPlatform()) { resource = workspace.getRoot().getFile(new Path(uri.toPlatformString(true))); } else { IPath fs = new Path(uri.toFileString()); for (IProject proj : workspace.getRoot().getProjects()) { if (proj.getLocation().isPrefixOf(fs)) { IPath relative = fs.makeRelativeTo(proj.getLocation()); resource = proj.findMember(relative); } } } } if (resource != null && resource.exists()) { IMarker imarker = null; try { imarker = resource.createMarker(AnimationConfig.TXTUML_ANIMATION_MARKER_ID); imarker.setAttribute(EValidator.URI_ATTRIBUTE, URI.createPlatformResourceURI(resource.getFullPath().toString(), true) + "#" + EcoreUtil.getURI(eobject).fragment()); } catch (CoreException e) { e.printStackTrace(); } if (imarker != null) { IPapyrusMarker marker = PapyrusMarkerAdapter.wrap(eobject.eResource(), imarker); eobjectToMarker.put(eobject, marker); } } }
Example 17
Source File: SolcBuilderPreferencePage.java From uml2solidity with Eclipse Public License 1.0 | 4 votes |
/** * */ private void validateInput() { if (isPropertyPage()) { Path srcDir = new Path(sourceDirectory.getStringValue()); IResource member = project.findMember(srcDir); if (member == null) member = ResourcesPlugin.getWorkspace().getRoot().findMember(srcDir); if (member == null || !member.exists()) { setErrorMessage("source directory does not exist"); return; } if (member.getType() != IResource.FOLDER) { setErrorMessage("source must be a folder"); return; } String stringValue = compilerTarget.getStringValue(); Path ct = new Path(stringValue); IResource resource = project.findMember(ct); if (resource == null) resource = project.findMember(ct.removeLastSegments(1)); if (resource == null) resource = ResourcesPlugin.getWorkspace().getRoot().findMember(ct); if (resource == null) resource = ResourcesPlugin.getWorkspace().getRoot().findMember(ct.removeLastSegments(1)); if (resource == null || !resource.exists()) { setErrorMessage("target file or dir not found:" + stringValue); return; } } String fileName = editor.getStringValue(); File file = new File(fileName); if (!file.exists()) { setErrorMessage("The selected compiles does not exitst."); return; } if (!file.canExecute()) { setErrorMessage("The selected compiler can not be executed."); return; } }
Example 18
Source File: LibrariesWorkbookPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private void editElementEntry(CPListElement elem) { CPListElement[] res= null; switch (elem.getEntryKind()) { case IClasspathEntry.CPE_CONTAINER: res= openContainerSelectionDialog(elem); break; case IClasspathEntry.CPE_LIBRARY: IResource resource= elem.getResource(); if (resource == null) { File file= elem.getPath().toFile(); if (file.isDirectory()) { res= openExternalClassFolderDialog(elem); } else { res= openExtJarFileDialog(elem); } } else if (resource.getType() == IResource.FOLDER) { if (resource.exists()) { res= openClassFolderDialog(elem); } else { res= openNewClassFolderDialog(elem); } } else if (resource.getType() == IResource.FILE) { res= openJarFileDialog(elem); } break; case IClasspathEntry.CPE_VARIABLE: res= openVariableSelectionDialog(elem); break; } if (res != null && res.length > 0) { CPListElement curr= res[0]; curr.setExported(elem.isExported()); curr.setAttributesFromExisting(elem); fLibrariesList.replaceElement(elem, curr); if (elem.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { fLibrariesList.refresh(); } } }
Example 19
Source File: TLAParsingBuilder.java From tlaplus with MIT License | 4 votes |
private void build(String moduleFileName, IResource rootFile, IProgressMonitor monitor) { // if the changed file is a root file - run the spec build if (rootFile != null && (rootFile.getName().equals(moduleFileName))) { monitor.beginTask("Invoking the SANY to re-parse the spec", IProgressMonitor.UNKNOWN); // this will rebuild the spec starting from root, and change the // spec status // still, we want to continue and keep the dependency information // about other files ParserHelper.rebuildSpec(new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN)); monitor.done(); } else { // retrieve a resource IProject project = getProject(); // get the file IResource moduleFile = project.getFile(moduleFileName); /* * At this point of time, all modules should have been linked if * (!moduleFile.exists()) { moduleFile = * ResourceHelper.getLinkedFile(project, moduleFileName, false); } */ if (moduleFile == null || !moduleFile.exists()) { throw new IllegalStateException("Resource not found during build: " + moduleFileName); } // never build derived resources if (!moduleFile.isDerived()) { monitor.beginTask("Invoking SANY to re-parse a module " + moduleFileName, IProgressMonitor.UNKNOWN); // run the module build ParserHelper.rebuildModule(moduleFile, new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN)); monitor.done(); } else { Activator.getDefault().logDebug("Skipping resource: " + moduleFileName); } } }
Example 20
Source File: ValidationMarkerContentProvider.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
private Object[] processMarkers(final IResource resource) throws CoreException { if (resource != null && resource.exists()) { return resource.findMarkers(ProcessMarkerNavigationProvider.MARKER_TYPE, false, IResource.DEPTH_INFINITE); } return new Object[0]; }