org.eclipse.core.resources.IResource Java Examples
The following examples show how to use
org.eclipse.core.resources.IResource.
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: RefactoringAvailabilityTester.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
public static boolean isMoveAvailable(final IResource[] resources, final IJavaElement[] elements) throws JavaModelException { if (elements != null) { for (int index = 0; index < elements.length; index++) { IJavaElement element = elements[index]; if (element == null || !element.exists()) { return false; } if ((element instanceof IType) && ((IType) element).isLocal()) { return false; } if ((element instanceof IPackageDeclaration)) { return false; } if (element instanceof IField && JdtFlags.isEnum((IMember) element)) { return false; } } } return ReorgPolicyFactory.createMovePolicy(resources, elements).canEnable(); }
Example #2
Source File: GroovyFileStore.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
@Override protected void doSave(final Object content) { if (content instanceof String) { if (getResource().exists() && content != null && content.equals(getContent())) { return; } try { final String scriptContent = (String) content; final InputStream is = new ByteArrayInputStream(scriptContent.getBytes(UTF_8)); final IFile sourceFile = getResource(); if (sourceFile.exists() && FileActionDialog.overwriteQuestion(getName())) { sourceFile.setContents(is, IResource.FOLDER, Repository.NULL_PROGRESS_MONITOR); } else { sourceFile.create(is, true, Repository.NULL_PROGRESS_MONITOR); } if (!UTF_8.equals(sourceFile.getCharset())) { sourceFile.setCharset(UTF_8, Repository.NULL_PROGRESS_MONITOR); } } catch (final Exception e) { BonitaStudioLog.error(e); } } }
Example #3
Source File: ResolveActionWithChoices.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
private SVNTreeConflict getTreeConflict(final IResource resource) { BusyIndicator.showWhile(Display.getDefault(), new Runnable() { public void run() { ISVNClientAdapter client = null; try { client = SVNWorkspaceRoot.getSVNResourceFor(resource).getRepository().getSVNClient(); ISVNStatus[] statuses = client.getStatus(resource.getLocation().toFile(), true, true, true); for (int i = 0; i < statuses.length; i++) { if (statuses[i].hasTreeConflict()) { treeConflict = new SVNTreeConflict(statuses[i]); break; } } } catch (Exception e) { SVNUIPlugin.log(IStatus.ERROR, e.getMessage(), e); } finally { SVNWorkspaceRoot.getSVNResourceFor(resource).getRepository().returnSVNClient(client); } } }); return treeConflict; }
Example #4
Source File: ModelHelper.java From tlaplus with MIT License | 6 votes |
public static void copyModuleFiles(IFile specRootFile, IPath targetFolderPath, IProgressMonitor monitor, int STEP, IProject project, Collection<String> extendedModules, final Predicate<String> p) throws CoreException { // iterate and copy modules that are needed for the spec IFile moduleFile = null; final Iterator<String> iterator = extendedModules.iterator(); while (iterator.hasNext()) { String module = iterator.next(); // only take care of user modules if (p.test(module)) { moduleFile = ResourceHelper.getLinkedFile(project, module, false); if (moduleFile != null && moduleFile.exists()) { moduleFile.copy(targetFolderPath.append(moduleFile.getProjectRelativePath()), IResource.DERIVED | IResource.FORCE, new SubProgressMonitor(monitor, STEP / extendedModules.size())); } // TODO check the existence of copied files } } }
Example #5
Source File: Storage2UriMapperJdtImplTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void testBug463258_03c() throws Exception { IJavaProject project = createJavaProject("foo"); IFile file = project.getProject().getFile("foo.jar"); file.create(jarInputStream(new TextFile("foo/bar.notindexed", "//empty")), true, monitor()); addJarToClasspath(project, file); Storage2UriMapperJavaImpl impl = getStorage2UriMapper(); IPackageFragmentRoot root = JarPackageFragmentRootTestUtil.getJarPackageFragmentRoot(file, (JavaProject) project); IPackageFragment foo = root.getPackageFragment("foo"); JarEntryFile fileInJar = new JarEntryFile("bar.notindexed"); fileInJar.setParent(foo); File jarFile = file.getLocation().toFile(); assertTrue("exists", jarFile.exists()); assertTrue("delete", jarFile.delete()); // simulate an automated refresh file.refreshLocal(IResource.DEPTH_ONE, null); URI uri = impl.getUri(fileInJar); assertNull(uri); }
Example #6
Source File: BinaryRefactoringHistoryWizard.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Configures the classpath of the project before refactoring. * * @param project * the java project * @param root * the package fragment root to refactor * @param folder * the temporary source folder * @param monitor * the progress monitor to use * @throws IllegalStateException * if the plugin state location does not exist * @throws CoreException * if an error occurs while configuring the class path */ private static void configureClasspath(final IJavaProject project, final IPackageFragmentRoot root, final IFolder folder, final IProgressMonitor monitor) throws IllegalStateException, CoreException { try { monitor.beginTask(JarImportMessages.JarImportWizard_prepare_import, 200); final IClasspathEntry entry= root.getRawClasspathEntry(); final IClasspathEntry[] entries= project.getRawClasspath(); final List<IClasspathEntry> list= new ArrayList<IClasspathEntry>(); list.addAll(Arrays.asList(entries)); final IFileStore store= EFS.getLocalFileSystem().getStore(JavaPlugin.getDefault().getStateLocation().append(STUB_FOLDER).append(project.getElementName())); if (store.fetchInfo(EFS.NONE, new SubProgressMonitor(monitor, 25, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)).exists()) store.delete(EFS.NONE, new SubProgressMonitor(monitor, 25, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)); store.mkdir(EFS.NONE, new SubProgressMonitor(monitor, 25, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)); folder.createLink(store.toURI(), IResource.NONE, new SubProgressMonitor(monitor, 25, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)); addExclusionPatterns(list, folder.getFullPath()); for (int index= 0; index < entries.length; index++) { if (entries[index].equals(entry)) list.add(index, JavaCore.newSourceEntry(folder.getFullPath())); } project.setRawClasspath(list.toArray(new IClasspathEntry[list.size()]), false, new SubProgressMonitor(monitor, 100, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)); } finally { monitor.done(); } }
Example #7
Source File: ModuleFile.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
/** * <p> * Returns whether a package is on the client source path of this module. The source paths include * the paths explicitly declared with <code><source></code> tags and all of their descendant * packages. * </p> * <p> * For example, if a module is located in <code>com.hello</code> and has the default client source * path "client", then <code>com.hello.client</code> and <code>com.hello.client.utils</code> would * both return true. * </p> * * @param pckg package to check * @return <code>true</code> if this package is on a client source path, and <code>false</code> * otherwise */ public boolean isSourcePackage(IPackageFragment pckg) { IResource resource = pckg.getResource(); if (resource.getType() == IResource.FOLDER) { IPath pckgFolderPath = resource.getFullPath(); // Check each source path to see if it's an ancestor of this package for (IFolder clientFolder : getFolders(getSourcePaths())) { IPath clientFolderPath = clientFolder.getFullPath(); if (clientFolderPath.isPrefixOf(pckgFolderPath)) { return true; } } } return false; }
Example #8
Source File: SynchronizerSyncInfoCache.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
/** * Flushes statuses from pending cache. * The method is not synchronized intentionally. */ protected void flushPendingCacheWrites() { if ((pendingCacheWrites.size() > 0) && (!ResourcesPlugin.getWorkspace().isTreeLocked())) { int count = pendingCacheWrites.size(); for (int i = 0; i < count; i++) { Map.Entry cachedEntry = nextFromPendingCache(); if (cachedEntry != null) { IResource resource = (IResource) cachedEntry.getKey(); byte[] value = (byte []) cachedEntry.getValue(); if (value == BYTES_REMOVED) value = null; try { ResourcesPlugin.getWorkspace().getSynchronizer().setSyncInfo(StatusCacheManager.SVN_BC_SYNC_KEY, resource, value); } catch (CoreException e) { SVNProviderPlugin.log(SVNException.wrapException(e)); } removeFromPendingCacheIfEqual((IResource) cachedEntry.getKey(), (byte []) cachedEntry.getValue()); } } } }
Example #9
Source File: Bug486584Test.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void testNoFullBuildWhenClasspathNotReallyChanged_1() throws CoreException, IOException, InterruptedException { IJavaProject project = setupProject(); IFile libaryFile = copyAndGetXtendExampleJar(project); IPath rawLocation = libaryFile.getRawLocation(); IClasspathEntry libraryEntry = JavaCore.newLibraryEntry(rawLocation, null, null); addToClasspath(project, libraryEntry); build(); assertFalse(getEvents().isEmpty()); getEvents().clear(); project.setRawClasspath(project.getRawClasspath(), null); project.getProject().getFile("src/dummy.txt").create(new StringInputStream(""), false, null); project.getProject().refreshLocal(IResource.DEPTH_INFINITE, null); build(); assertEquals(0, getEvents().size()); }
Example #10
Source File: SVNHistoryPageSource.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
public boolean canShowHistoryFor(Object object) { if (object instanceof IResource) { IResource resource = (IResource)object; ISVNLocalResource localResource = SVNWorkspaceRoot.getSVNResourceFor(resource); if (localResource != null) { try { if (!localResource.isManaged()) { return false; } if (localResource.isAdded() && !localResource.getStatus().isCopied()) { return false; } } catch (Exception e) { SVNUIPlugin.log(Status.ERROR, e.getMessage(), e); } } } return (object instanceof IResource && ((IResource) object).getType() != IResource.ROOT) || (object instanceof ISVNRemoteResource); }
Example #11
Source File: AddAction.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
/** * asks the user if he wants to add the resources if some of them are ignored * @return false if he answered no */ private boolean promptForAddOfIgnored() { IResource[] resources = getSelectedResources(); boolean prompt = false; for (int i = 0; i < resources.length; i++) { ISVNLocalResource resource = SVNWorkspaceRoot.getSVNResourceFor(resources[i]); try { if (resource.isIgnored()) { prompt = true; break; } } catch (SVNException e) { handle(e); } } if (prompt) { return MessageDialog.openQuestion(getShell(), Policy.bind("AddAction.addIgnoredTitle"), Policy.bind("AddAction.addIgnoredQuestion")); //$NON-NLS-1$ //$NON-NLS-2$ } return true; }
Example #12
Source File: XbaseBreakpointUtil.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
public IResource getBreakpointResource(IEditorInput input) throws CoreException { IResource resource = Adapters.adapt(input, IResource.class); if (resource != null) return resource; if (input instanceof IStorageEditorInput) { IStorage storage = ((IStorageEditorInput) input).getStorage(); if (storage instanceof IResource) return (IResource) storage; if (storage instanceof IJarEntryResource) { IResource underlyingResource = ((IJarEntryResource) storage).getPackageFragmentRoot().getUnderlyingResource(); if (underlyingResource != null) return underlyingResource; } } else { IClassFile classFile = Adapters.adapt(input, IClassFile.class); if (classFile != null) { return getBreakpointResource(classFile.findPrimaryType()); } } return ResourcesPlugin.getWorkspace().getRoot(); }
Example #13
Source File: ResourceDropAdapterAssistant.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
/** * Returns the resource selection from the LocalSelectionTransfer. * * @return the resource selection from the LocalSelectionTransfer */ private IResource[] getSelectedResources(IStructuredSelection selection) { ArrayList selectedResources = new ArrayList(); for (Iterator i = selection.iterator(); i.hasNext();) { Object o = i.next(); if (o instanceof IResource) { selectedResources.add(o); } else if (o instanceof IAdaptable) { IAdaptable a = (IAdaptable) o; IResource r = (IResource) a.getAdapter(IResource.class); if (r != null) { selectedResources.add(r); } } } return (IResource[]) selectedResources .toArray(new IResource[selectedResources.size()]); }
Example #14
Source File: Tester.java From aCute with Eclipse Public License 2.0 | 5 votes |
public static boolean isDotnetProject(IProject p) { if (p == null || !p.isAccessible()) { return false; } try { for (IResource projItem : p.members()) { if (projItem.getName().equals("project.json") || projItem.getName().matches("^.*\\.csproj$")) { //$NON-NLS-1$ //$NON-NLS-2$ return true; } } } catch (CoreException e) { } return false; }
Example #15
Source File: SvnWizardCommitPage.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
private boolean isChild(IResource resource, IContainer folder) { IContainer container = resource.getParent(); while (container != null) { if (container.getFullPath().toString().equals(folder.getFullPath().toString())) return true; container = container.getParent(); } return false; }
Example #16
Source File: NavigatorResourceDropAssistant.java From gama with GNU General Public License v3.0 | 5 votes |
private boolean allProjects(final IResource[] res) { if (res == null || res.length == 0) { return false; } for (final IResource re : res) { if (re.getType() != IResource.PROJECT) { return false; } } return true; }
Example #17
Source File: BaseParser.java From Pydev with Eclipse Public License 1.0 | 5 votes |
/** * This function will remove the markers related to errors. * @param resource the file that should have the markers removed * @throws CoreException */ public static void deleteErrorMarkers(IResource resource) throws CoreException { IMarker[] markers = resource.findMarkers(IMarker.PROBLEM, false, IResource.DEPTH_ZERO); if (markers.length > 0) { resource.deleteMarkers(IMarker.PROBLEM, false, IResource.DEPTH_ZERO); } }
Example #18
Source File: AnalysisEngineMainTab.java From uima-uimaj with Apache License 2.0 | 5 votes |
private IContainer getContainer(String path) { Path containerPath = new Path(path); IResource resource = getWorkspaceRoot().findMember(containerPath); if (resource instanceof IContainer) return (IContainer) resource; return null; }
Example #19
Source File: PyChange.java From Pydev with Eclipse Public License 1.0 | 5 votes |
@Override public void initializeValidationData(IProgressMonitor pm) { IResource resource = getResource(getModifiedElement()); if (resource != null) { fModificationStamp = getModificationStamp(resource); fReadOnly = isReadOnly(resource); } }
Example #20
Source File: ActiveProjectFinder.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
public void selectionChanged(IAction action, ISelection selection) { IResource selectionResource = ResourceUtils.getSelectionResource(selection); if (selectionResource != null) { selectedProject = selectionResource.getProject(); } else { selectedProject = null; } }
Example #21
Source File: RouteTreeContentProvider.java From eip-designer with Apache License 2.0 | 5 votes |
@Override public boolean hasChildren(Object element) { if (element instanceof IProject) { IProject project = (IProject) element; List<IResource> models = new ArrayList<IResource>(); findEIPModels(models, project.getLocation(), ResourcesPlugin.getWorkspace().getRoot()); return !models.isEmpty(); } if (element instanceof IResource) { return true; } return false; }
Example #22
Source File: GenerateDiffFileOperation.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
GenerateDiffFileOperation(IResource[] resources, IResource[] unaddedResources, File file, boolean toClipboard, boolean recursive, boolean eclipseFormat, boolean projectRelative, Shell shell) { this.resources = resources; this.unaddedResources = unaddedResources; this.outputFile = file; this.eclipseFormat = eclipseFormat; this.projectRelative = projectRelative; this.shell = shell; this.recursive = recursive; this.toClipboard = toClipboard; }
Example #23
Source File: CompilerLaunchShortcut.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
protected ILaunchConfiguration findLaunchConfiguration(IResource resource) throws CoreException { ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); ILaunchConfigurationType typeid = launchManager.getLaunchConfigurationType(CompilerLaunchConfiguration.TYPE_ID); ILaunchConfiguration[] configs = launchManager.getLaunchConfigurations(typeid); return searchMatchingUrlAndProject(resource.getProject(), configs); }
Example #24
Source File: ProjectHelper.java From eclipse-extras with Eclipse Public License 1.0 | 5 votes |
public static void cleanWorkspace() throws CoreException { projects.clear(); IProject[] allProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects( INCLUDE_HIDDEN ); for( IProject project : allProjects ) { delete( project ); project.refreshLocal( IResource.DEPTH_ZERO, new NullProgressMonitor() ); } }
Example #25
Source File: PossibleMatch.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public PossibleMatch(MatchLocator locator, IResource resource, Openable openable, SearchDocument document, boolean mustResolve) { this.resource = resource; this.openable = openable; this.document = document; this.nodeSet = new MatchingNodeSet(mustResolve); char[] qualifiedName = getQualifiedName(); if (qualifiedName != null) this.compoundName = CharOperation.splitOn('.', qualifiedName); }
Example #26
Source File: CopyToClipboardAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static void addFileName(Set<String> fileName, IResource resource){ if (resource == null) return; IPath location = resource.getLocation(); if (location != null) { fileName.add(location.toOSString()); } else { // not a file system path. skip file. } }
Example #27
Source File: JavaMoveProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException { pm.beginTask("", 1); //$NON-NLS-1$ try { RefactoringStatus result= new RefactoringStatus(); result.merge(RefactoringStatus.create(Resources.checkInSync(ReorgUtils.getNotNulls(fMovePolicy.getResources())))); IResource[] javaResources= ReorgUtils.getResources(fMovePolicy.getJavaElements()); result.merge(RefactoringStatus.create(Resources.checkInSync(ReorgUtils.getNotNulls(javaResources)))); return result; } finally { pm.done(); } }
Example #28
Source File: JavaDocLocations.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Returns the location of the Javadoc. * * @param element whose Javadoc location has to be found * @param isBinary <code>true</code> if the Java element is from a binary container * @return the location URL of the Javadoc or <code>null</code> if the location cannot be found * @throws JavaModelException thrown when the Java element cannot be accessed * @since 3.9 */ public static String getBaseURL(IJavaElement element, boolean isBinary) throws JavaModelException { if (isBinary) { // Source attachment usually does not include Javadoc resources // => Always use the Javadoc location as base: URL baseURL= JavaUI.getJavadocLocation(element, false); if (baseURL != null) { if (baseURL.getProtocol().equals(JAR_PROTOCOL)) { // It's a JarURLConnection, which is not known to the browser widget. // Let's start the help web server: URL baseURL2= PlatformUI.getWorkbench().getHelpSystem().resolve(baseURL.toExternalForm(), true); if (baseURL2 != null) { // can be null if org.eclipse.help.ui is not available baseURL= baseURL2; } } return baseURL.toExternalForm(); } } else { IResource resource= element.getResource(); if (resource != null) { /* * Too bad: Browser widget knows nothing about EFS and custom URL handlers, * so IResource#getLocationURI() does not work in all cases. * We only support the local file system for now. * A solution could be https://bugs.eclipse.org/bugs/show_bug.cgi?id=149022 . */ IPath location= resource.getLocation(); if (location != null) return location.toFile().toURI().toString(); } } return null; }
Example #29
Source File: CheckMarkerUpdateJob.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** * Creates the marker on a given file based on the collection of issues. * * @param markerCreator * the marker creator, may be {@code null} * @param file * the EFS file, must not be {@code null} * @param issues * the collection of issues, must not be {@code null} * @throws CoreException */ private void createMarkers(final MarkerCreator markerCreator, final IFile file, final Collection<Issue> issues) throws CoreException { file.deleteMarkers(MarkerTypes.FAST_VALIDATION, true, IResource.DEPTH_ZERO); file.deleteMarkers(MarkerTypes.NORMAL_VALIDATION, true, IResource.DEPTH_ZERO); file.deleteMarkers(MarkerTypes.EXPENSIVE_VALIDATION, true, IResource.DEPTH_ZERO); if (markerCreator != null) { for (final Issue issue : issues) { markerCreator.createMarker(issue, file, MarkerTypes.forCheckType(issue.getType())); } } else { if (LOGGER.isDebugEnabled()) { LOGGER.error("Could not create markers. The marker creator is null."); //$NON-NLS-1$ } } }
Example #30
Source File: JavaMoveProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Override public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException { pm.beginTask("", 1); //$NON-NLS-1$ try { RefactoringStatus result= new RefactoringStatus(); result.merge(RefactoringStatus.create(Resources.checkInSync(ReorgUtils.getNotNulls(fMovePolicy.getResources())))); IResource[] javaResources= ReorgUtils.getResources(fMovePolicy.getJavaElements()); result.merge(RefactoringStatus.create(Resources.checkInSync(ReorgUtils.getNotNulls(javaResources)))); return result; } finally { pm.done(); } }