List of usage examples for org.eclipse.jdt.core IJavaProject exists
boolean exists();
From source file:org.sonatype.m2e.plexus.annotations.internal.PlexusBuildParticipant.java
License:Open Source License
@Override public Set<IProject> build(int kind, final IProgressMonitor monitor) throws CoreException { final IProject project = getMavenProjectFacade().getProject(); final IJavaProject javaProject = JavaCore.create(project); if (!javaProject.exists()) { return null; }//w w w . ja va2 s .c o m boolean changed = false; final PlexusMetadata metadata = getPlexusMetadata(); final Set<IResource> processed = new HashSet<IResource>(); for (IClasspathEntry cpe : javaProject.getRawClasspath()) { if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE && isTestEntry(cpe) == testMetadata) { changed = true; // XXX not specific enough! IPath path = cpe.getPath().removeFirstSegments(1); if (IncrementalProjectBuilder.FULL_BUILD == kind || metadata.isFullBuildRequired(project)) { IFolder folder = project.getFolder(path); if (!folder.exists()) { // optional source folders may not exist continue; } folder.accept(new IResourceVisitor() { public boolean visit(IResource resource) throws CoreException { if (!javaProject.isOnClasspath(resource)) { return false; } if (resource instanceof IFile) { IFile file = (IFile) resource; processAnnotations(metadata, javaProject, file, processed, monitor); } return true; // keep visiting } }); } else { IResourceDelta delta = getDelta(project).findMember(path); if (delta == null) { continue; } changed = true; // XXX not specific enough! delta.accept(new IResourceDeltaVisitor() { public boolean visit(IResourceDelta delta) throws CoreException { IResource resource = delta.getResource(); if (!javaProject.isOnClasspath(resource)) { return false; } if (resource instanceof IFile && isInteresting(delta)) { IFile file = (IFile) resource; if (file.isAccessible()) { processAnnotations(metadata, javaProject, file, processed, monitor); } else { metadata.remove(file); } } return true; // keep visiting } }); } } } List<IResource> staleResources = metadata.getStaleResources(project, testMetadata); changed |= !staleResources.isEmpty(); do { for (IResource resource : staleResources) { if (resource instanceof IFile) { processAnnotations(metadata, javaProject, (IFile) resource, processed, monitor); } } staleResources = metadata.getStaleResources(project, testMetadata); // this is actually a bug, but we report it later staleResources.removeAll(processed); } while (!staleResources.isEmpty()); if (changed) { Set<IProject> dependencies = metadata.writeMetadata(project, testMetadata); return dependencies; } return null; }
From source file:org.springframework.ide.eclipse.beans.ui.properties.NonJavaResourceContentProvider.java
License:Open Source License
private Object[] getResources(IContainer container) { try {/*w w w. j a va 2s . co m*/ IResource[] members = container.members(); IJavaProject javaProject = JavaCore.create(container.getProject()); if (javaProject == null || !javaProject.exists()) { return members; } boolean isFolderOnClasspath = javaProject.isOnClasspath(container); List<Object> nonJavaResources = new ArrayList<Object>(); // Can be on classpath but as a member of non-java resource folder for (IResource member : members) { // A resource can also be a java element in the case of // exclusion and inclusion filters. We therefore exclude Java // elements from the list of non-Java resources. if (isFolderOnClasspath) { if (javaProject.findPackageFragmentRoot(member.getFullPath()) == null) { nonJavaResources.add(member); } } else if (!javaProject.isOnClasspath(member)) { nonJavaResources.add(member); } } return nonJavaResources.toArray(); } catch (CoreException e) { return NO_CHILDREN; } }
From source file:org.springframework.ide.eclipse.boot.dash.cloudfoundry.JavaPackageFragmentRootHandler.java
License:Open Source License
protected void getOrderedJavaProjectNames(List<String> sameLevelRequiredProjects, List<String> collectedProjects) { // The order in which required projects are collected is as follows, // with the RHS // being required projects of the LHS // A -> BC // B -> D/*w w w.j a va 2 s . c om*/ // C -> E // = total 5 projects, added in the order that they are encountered. // so final ordered list should be ABCDE if (sameLevelRequiredProjects == null) { return; } List<String> nextLevelRequiredProjects = new ArrayList<String>(); // First add the current level java projects in the order they appear // and also collect each one's required names. for (String name : sameLevelRequiredProjects) { try { IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name); if (project != null) { IJavaProject jvPrj = JavaCore.create(project); if (jvPrj != null && jvPrj.exists()) { if (!collectedProjects.contains(name)) { collectedProjects.add(name); } String[] names = jvPrj.getRequiredProjectNames(); if (names != null && names.length > 0) { for (String reqName : names) { if (!nextLevelRequiredProjects.contains(reqName)) { nextLevelRequiredProjects.add(reqName); } } } } } } catch (JavaModelException e) { BootDashActivator.log(e); } } // Now recurse to fetch the required projects for the // list of java projects that were added at the current level above if (!nextLevelRequiredProjects.isEmpty()) { getOrderedJavaProjectNames(nextLevelRequiredProjects, collectedProjects); } }
From source file:org.springframework.tooling.jdt.ls.commons.classpath.ReusableClasspathListenerHandler.java
License:Open Source License
private boolean projectExists(IJavaProject jp) { //We can't really deal with projects that don't exist in disk. So using this more strict 'exists' check //makes sure anything that looks like it doesn't exist on disk is treated as if it simply doesn't exist //at all. This kind of addresses a issue caused by Eclipse's idiotic behavior when it comes to deleting //a project's files from the file system... Eclipse recreates a 'vanilla' project in the workspace, //simply refusing to accept the fact that the project is actually gone. if (jp.exists()) { try {//from w w w . j a va 2 s . co m URI loc = getProjectLocation(jp); if (loc != null) { File f = new File(loc); return f.isDirectory() && jp.getProject().hasNature(JavaCore.NATURE_ID); } } catch (Exception e) { //Something bogus about this project... so just pretend it doesn't exist. } } return false; }
From source file:org.summer.dsl.builder.impl.javasupport.JdtToBeBuiltComputer.java
License:Open Source License
public void updateProject(ToBeBuilt toBeBuilt, IProject project, IProgressMonitor monitor) throws CoreException { SubMonitor progress = SubMonitor.convert(monitor, 2); if (!project.isAccessible() || progress.isCanceled()) return;/*from ww w. j a v a 2 s . c om*/ IJavaProject javaProject = JavaCore.create(project); if (javaProject.exists()) { IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots(); progress.setWorkRemaining(roots.length); final Map<String, Long> updated = Maps.newHashMap(); ProjectOrder orderedProjects = workspace.computeProjectOrder(workspace.getRoot().getProjects()); for (final IPackageFragmentRoot root : roots) { if (progress.isCanceled()) return; if (shouldHandle(root) && !isBuiltByUpstream(root, project, orderedProjects.projects)) { Map<URI, IStorage> rootData = jdtUriMapperExtension.getAllEntries(root); for (Map.Entry<URI, IStorage> e : rootData.entrySet()) if (uriValidator.canBuild(e.getKey(), e.getValue())) { toBeBuilt.getToBeDeleted().add(e.getKey()); toBeBuilt.getToBeUpdated().add(e.getKey()); } } progress.worked(1); } synchronized (modificationStampCache) { modificationStampCache.projectToModificationStamp.putAll(updated); } } }
From source file:org.summer.dsl.builder.JavaProjectBasedBuilderParticipant.java
License:Open Source License
public void build(IBuildContext context, IProgressMonitor monitor) throws CoreException { final IProject builtProject = context.getBuiltProject(); IJavaProject javaProject = JavaCore.create(builtProject); if (!javaProject.exists()) return;/*from w w w . ja v a2 s .co m*/ final IFolder srcGenFolder = getSrcGenFolder(builtProject); if (!srcGenFolder.exists()) return; if (!isValidOutputFolder(javaProject, srcGenFolder)) return; for (IResourceDescription.Delta delta : context.getDeltas()) { final Set<String> oldFiles = newHashSet(); if (sourceTargetMap.containsKey(delta.getUri())) { oldFiles.addAll(sourceTargetMap.get(delta.getUri())); } final Set<String> newFiles = newHashSet(); IFileSystemAccess fileSystemAccess = getConfiguredFileSystemAccess(srcGenFolder, new IAcceptor<String>() { public void accept(String fileName) { oldFiles.remove(fileName); newFiles.add(fileName); } }); if (delta.getNew() == null) { handleDeletion(delta, context, fileSystemAccess); } else { try { handleChangedContents(delta, context, fileSystemAccess); } catch (Exception e) { logger.error("Error during compilation of '" + delta.getUri() + "'.", e); } } for (String removeFile : oldFiles) { fileSystemAccess.deleteFile(removeFile); } if (!newFiles.isEmpty()) { sourceTargetMap.put(delta.getUri(), newFiles); } } }
From source file:org.summer.dsl.builder.JDTAwareEclipseResourceFileSystemAccess2.java
License:Open Source License
/** * @since 2.4// www .j ava 2s . co m */ @Override protected void createContainer(IContainer container) throws CoreException { super.createContainer(container); // make it a source folder IJavaProject jp = JavaCore.create(container.getProject()); if (jp.exists() && !jp.isOnClasspath(container)) { IClasspathEntry srcFolderClasspathEntry = JavaCore.newSourceEntry(container.getFullPath()); IClasspathEntry[] classPath = jp.getRawClasspath(); IClasspathEntry[] newClassPath = new IClasspathEntry[classPath.length + 1]; System.arraycopy(classPath, 0, newClassPath, 1, classPath.length); newClassPath[0] = srcFolderClasspathEntry; jp.setRawClasspath(newClassPath, getMonitor()); } }
From source file:org.summer.dsl.builder.trace.JarEntryAwareTrace.java
License:Open Source License
public URI tryResolvePath(IStorage localStorage, URI path) { if (localStorage instanceof IFile) { IProject project = ((IFile) localStorage).getProject(); if (project != null) { IJavaProject javaProject = JavaCore.create(project); if (javaProject != null && javaProject.exists()) return resolvePath(javaProject, path); return null; }// w w w . j a v a2s . c o m } else if (localStorage instanceof IJarEntryResource) { return resolvePath((IJarEntryResource) localStorage, path); } return null; }
From source file:org.summer.dsl.ui.shared.JdtHelper.java
License:Open Source License
public boolean isFromOutputPath(IResource resource) { IProject project = resource.getProject(); IJavaProject javaProject = JavaCore.create(project); if (javaProject != null && javaProject.exists()) { try {//from www . j a v a2 s. c o m IPath defaultOutputLocation = javaProject.getOutputLocation(); IPath resourcePath = resource.getFullPath(); if (defaultOutputLocation != null && !defaultOutputLocation.isEmpty() && defaultOutputLocation.isPrefixOf(resourcePath)) { return true; } IClasspathEntry[] classpathEntries = javaProject.getRawClasspath(); for (IClasspathEntry classpathEntry : classpathEntries) { if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath specializedOutputLocation = classpathEntry.getOutputLocation(); if (specializedOutputLocation != null) { if (!specializedOutputLocation.equals(classpathEntry.getPath()) && specializedOutputLocation.isPrefixOf(resourcePath)) { return true; } } } } } catch (CoreException e) { if (log.isDebugEnabled()) log.debug("Error in isJavaTargetFolder():" + e.getMessage(), e); } } return false; }
From source file:org.summer.dsl.xbase.ui.launching.JavaElementDelegate.java
License:Open Source License
protected IJavaElement getJavaElementForXtextEditor(IEditorPart editor) { if (!(editor instanceof XtextEditor)) return null; IJavaProject jp = null; if (editor.getEditorInput() instanceof IFileEditorInput) { IFile file = ((IFileEditorInput) editor.getEditorInput()).getFile(); if (!fileExtensionProvider.isValid(file.getFileExtension())) { return null; }/*from w ww . j a v a 2 s. c om*/ jp = JavaCore.create(file.getProject()); if (jp == null || !jp.exists() || !jp.isOpen()) return null; } else { return null; } XtextEditor xtextEditor = (XtextEditor) editor; ISelection selection = xtextEditor.getSelectionProvider().getSelection(); if (!(selection instanceof ITextSelection)) return null; final int offset = ((ITextSelection) selection).getOffset(); IJavaElement func = xtextEditor.getDocument().readOnly(new IUnitOfWork<IJavaElement, XtextResource>() { public IJavaElement exec(XtextResource state) throws Exception { return findJavaElement(state, offset); } }); return func; }