List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_PROJECT
int CPE_PROJECT
To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_PROJECT.
Click Source Link
From source file:org.eclipse.jst.j2ee.internal.common.operations.UpdateJavaBuildPathOperation.java
License:Open Source License
protected void ensureClasspathEntryIsExported(List cp, IClasspathEntry entry) { if (entry.isExported()) return;// w w w. jav a2 s .com int index = getIndex(cp, entry); IClasspathEntry newEntry = null; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_PROJECT: newEntry = JavaCore.newProjectEntry(entry.getPath(), true); break; case IClasspathEntry.CPE_LIBRARY: newEntry = JavaCore.newLibraryEntry(entry.getPath(), entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), true); break; case IClasspathEntry.CPE_VARIABLE: newEntry = JavaCore.newVariableEntry(entry.getPath(), entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath()); } cp.set(index, newEntry); }
From source file:org.eclipse.jst.j2ee.internal.dialogs.TypeJavaSearchScope.java
License:Open Source License
/** * Method addProject. This method adds all the classpath entries for the * current project to the search scope./*from ww w.jav a2 s .c o m*/ * * @param javaProject * @param includesPrereqProjects * @param visitedProjects * @throws JavaModelException */ public void addProject(IJavaProject javaProject, boolean includesPrereqProjects, HashSet visitedProjects) throws JavaModelException { IProject project = javaProject.getProject(); if (!project.isAccessible() || !visitedProjects.add(project)) return; this.addEnclosingProjectOrJar(project.getFullPath()); IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); IJavaModel model = javaProject.getJavaModel(); for (int i = 0, length = entries.length; i < length; i++) { IClasspathEntry entry = entries[i]; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: IPath path = entry.getPath(); this.add(path, true); this.addEnclosingProjectOrJar(path); break; case IClasspathEntry.CPE_PROJECT: if (includesPrereqProjects) { this.add(model.getJavaProject(entry.getPath().lastSegment()), true, visitedProjects); } break; case IClasspathEntry.CPE_SOURCE: this.add(entry.getPath(), true); break; } } }
From source file:org.eclipse.jst.j2ee.internal.dialogs.TypeJavaSearchScope.java
License:Open Source License
/** * Method add. This method filters out all the classpath entries of the * project which are not exported./*from w ww . j a v a 2s. c om*/ * * @param javaProject * @param includesPrereqProjects * @param visitedProjects * @throws JavaModelException */ public void add(IJavaProject javaProject, boolean includesPrereqProjects, HashSet visitedProjects) throws JavaModelException { IProject project = javaProject.getProject(); if (!project.isAccessible() || !visitedProjects.add(project)) return; this.addEnclosingProjectOrJar(project.getFullPath()); IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); IJavaModel model = javaProject.getJavaModel(); for (int i = 0, length = entries.length; i < length; i++) { IClasspathEntry entry = entries[i]; if (includeExportedClassPathEntriesOnly()) { if (!entry.isExported() && entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) continue; } switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: IPath path = entry.getPath(); this.add(path, true); this.addEnclosingProjectOrJar(path); break; case IClasspathEntry.CPE_PROJECT: if (includesPrereqProjects) { this.add(model.getJavaProject(entry.getPath().lastSegment()), true, visitedProjects); } break; case IClasspathEntry.CPE_SOURCE: this.add(entry.getPath(), true); break; } } }
From source file:org.eclipse.jst.j2ee.internal.servertarget.ServerTargetHelper.java
License:Open Source License
public static List getExistingNonServerTargetClasspath(IProject project) { IJavaProject javaProject = null;/*from w w w .j ava2 s .c o m*/ List list = new ArrayList(); try { javaProject = (IJavaProject) project.getNature(JavaCore.NATURE_ID); } catch (Exception e) { } if (javaProject != null) { try { IClasspathEntry[] cp = javaProject.getRawClasspath(); int size = cp.length; for (int i = 0; i < size; i++) { int entryKind = cp[i].getEntryKind(); if (entryKind != IClasspathEntry.CPE_SOURCE && entryKind != IClasspathEntry.CPE_LIBRARY && entryKind != IClasspathEntry.CPE_PROJECT && (entryKind == IClasspathEntry.CPE_VARIABLE && isWASVariable(cp[i])) && (entryKind != IClasspathEntry.CPE_CONTAINER || !cp[i].getPath().segment(0).equals(SERVER_CONTAINER))) { list.add(cp[i]); } } } catch (Exception e) { } return list; } return list; }
From source file:org.eclipse.jst.jsf.core.internal.tld.LoadBundleUtil.java
License:Open Source License
private static IFile getSourceFile(IJavaProject javaProject, String baseName) throws JavaModelException { IClasspathEntry[] classpathEntries = javaProject.getRawClasspath(); for (int i = 0; i < classpathEntries.length; i++) { if (classpathEntries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { final IFile file = getFile(javaProject, baseName, classpathEntries, i); if (file.exists()) { return file; }/*from w w w .j a v a 2 s . co m*/ } else if (classpathEntries[i].getEntryKind() == IClasspathEntry.CPE_PROJECT) { IProject project = ResourcesPlugin.getWorkspace().getRoot() .getProject(classpathEntries[i].getPath().toString()); IJavaProject javaProject3 = JavaCore.create(project); final IFile file = getSourceFile(javaProject3, baseName); if (file != null && file.exists()) { return file; } } else if (classpathEntries[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER && classpathEntries[i] .getPath().equals(new Path("org.eclipse.jst.j2ee.internal.module.container"))) //$NON-NLS-1$ { IClasspathContainer container = JavaCore.getClasspathContainer(classpathEntries[i].getPath(), javaProject); IClasspathEntry[] classpathEntries2 = container.getClasspathEntries(); for (int j = 0; j < classpathEntries2.length; j++) { if (classpathEntries2[j].getEntryKind() == IClasspathEntry.CPE_PROJECT) { IProject project = ResourcesPlugin.getWorkspace().getRoot() .getProject(classpathEntries2[j].getPath().toString()); IJavaProject javaProject3 = JavaCore.create(project); final IFile file = getSourceFile(javaProject3, baseName); if (file != null && file.exists()) { return file; } } } } } return null; }
From source file:org.eclipse.jst.jsp.core.taglib.ProjectDescription.java
License:Open Source License
/** * @param entry//from ww w . j av a 2 s . com */ private void indexClasspath(IClasspathEntry entry) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_CONTAINER: { IClasspathContainer container = (IClasspathContainer) entry; IClasspathEntry[] containedEntries = container.getClasspathEntries(); for (int i = 0; i < containedEntries.length; i++) { indexClasspath(containedEntries[i]); } } break; case IClasspathEntry.CPE_LIBRARY: { /* * Ignore libs in required projects that are not exported */ IPath libPath = entry.getPath(); if (!fClasspathJars.containsKey(libPath.toString())) { final File file = libPath.toFile(); if (file.exists()) { if (file.isDirectory()) { indexDirectory(file, entry.isExported()); } else { updateClasspathLibrary(libPath.toString(), ITaglibIndexDelta.ADDED, entry.isExported()); } } else { /* * Note: .jars on the classpath inside of the project * will have duplicate entries in the JAR references * table that will e returned to * getAvailableTaglibRecords(). */ IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(libPath); if (resource != null && resource.isAccessible()) { if (resource.getType() == IResource.FILE) { if (resource.getLocation() != null) { updateClasspathLibrary(resource.getLocation().toString(), ITaglibIndexDelta.ADDED, entry.isExported()); } } else if (resource.getType() == IResource.FOLDER) { try { resource.accept(new Indexer(), 0); } catch (CoreException e) { Logger.logException(e); } } } } } } break; case IClasspathEntry.CPE_PROJECT: { /* * We're currently ignoring whether the project exports all of * its build path */ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(entry.getPath().lastSegment()); if (project != null) { fClasspathProjects.add(project); } } break; case IClasspathEntry.CPE_SOURCE: { IPath path = entry.getPath(); try { IResource sourceFolder = ResourcesPlugin.getWorkspace().getRoot().findMember(path); // could be a bad .classpath file if (sourceFolder != null) { sourceFolder.accept(new Indexer(), 0); } } catch (CoreException e) { Logger.logException(e); } } break; case IClasspathEntry.CPE_VARIABLE: { IPath libPath = JavaCore.getResolvedVariablePath(entry.getPath()); if (libPath != null) { File file = libPath.toFile(); // file in filesystem if (file.exists() && !file.isDirectory()) { updateClasspathLibrary(libPath.toString(), ITaglibRecordEvent.ADDED, entry.isExported()); } else { // workspace file IFile jarFile = ResourcesPlugin.getWorkspace().getRoot().getFile(libPath); if (jarFile.isAccessible() && jarFile.getType() == IResource.FILE && jarFile.getLocation() != null) { String jarPathString = jarFile.getLocation().toString(); updateClasspathLibrary(jarPathString, ITaglibRecordEvent.ADDED, entry.isExported()); } } } } break; } }
From source file:org.eclipse.jst.server.jetty.core.internal.wst.ModuleTraverser.java
License:Open Source License
private static boolean isValid(final IClasspathEntry entry, final IClasspathAttribute attrib, boolean isWebApp, final IProject project) { int kind = entry.getEntryKind(); boolean isClassFolder = isClassFolderEntry(entry); if (kind == IClasspathEntry.CPE_PROJECT || kind == IClasspathEntry.CPE_SOURCE) { return false; }/* w w w. ja v a 2 s . co m*/ String runtimePath = getRuntimePath(attrib, isWebApp, isClassFolder); if (!isWebApp) { if (!runtimePath.equals("../") && !runtimePath.equals("/")) { return false; } if (isClassFolder && !runtimePath.equals("/")) { return false; } } else { if (runtimePath != null && !runtimePath.equals("/WEB-INF/lib") && !runtimePath.equals("/WEB-INF/classes") && !runtimePath.equals("../")) { return false; } if (isClassFolder && !runtimePath.equals("/WEB-INF/classes")) { return false; } } return true; }
From source file:org.eclipse.jst.ws.internal.axis.consumption.ui.util.ClasspathUtils.java
License:Open Source License
private String[] classpathEntry2String(IClasspathEntry entry, IProject project) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: { return new String[] { path2String(entry.getPath()) }; }/*w w w . j av a2s . c o m*/ case IClasspathEntry.CPE_PROJECT: { return getClasspath(ResourcesPlugin.getWorkspace().getRoot().getProject(entry.getPath().lastSegment()), true); } case IClasspathEntry.CPE_SOURCE: { IPath path = entry.getPath(); if (path.segment(0).equals(project.getName())) path = path.removeFirstSegments(1); return new String[] { path2String(project.getLocation().addTrailingSeparator().append(path)) }; } case IClasspathEntry.CPE_VARIABLE: { return classpathEntry2String(JavaCore.getResolvedClasspathEntry(entry), project); } default: { return new String[] { path2String(entry.getPath()) }; } } }
From source file:org.eclipse.m2e.jdt.internal.ClasspathDescriptor.java
License:Open Source License
public ClasspathEntryDescriptor addProjectEntry(IPath entryPath) { ClasspathEntryDescriptor entry = new ClasspathEntryDescriptor(IClasspathEntry.CPE_PROJECT, entryPath); addEntryDescriptor(entry);//from w w w . j a v a 2 s . co m return entry; }
From source file:org.eclipse.m2e.jdt.internal.ClasspathEntryDescriptor.java
License:Open Source License
public IClasspathEntry toClasspathEntry() { Map<String, String> attributes = new LinkedHashMap<String, String>(this.attributes); if (artifactKey != null) { attributes.put(IClasspathManager.GROUP_ID_ATTRIBUTE, artifactKey.getGroupId()); attributes.put(IClasspathManager.ARTIFACT_ID_ATTRIBUTE, artifactKey.getArtifactId()); attributes.put(IClasspathManager.VERSION_ATTRIBUTE, artifactKey.getVersion()); if (artifactKey.getClassifier() != null) { attributes.put(IClasspathManager.CLASSIFIER_ATTRIBUTE, artifactKey.getClassifier()); }// www . j a v a 2 s . c o m } if (scope != null) { attributes.put(IClasspathManager.SCOPE_ATTRIBUTE, scope); } IClasspathAttribute[] attributesArray = new IClasspathAttribute[attributes.size()]; int attributeIndex = 0; for (Map.Entry<String, String> attribute : attributes.entrySet()) { attributesArray[attributeIndex++] = JavaCore.newClasspathAttribute(attribute.getKey(), attribute.getValue()); } IAccessRule[] accessRulesArray = accessRules.toArray(new IAccessRule[accessRules.size()]); IClasspathEntry entry; switch (entryKind) { case IClasspathEntry.CPE_CONTAINER: entry = JavaCore.newContainerEntry(path, // accessRulesArray, // attributesArray, // exported); break; case IClasspathEntry.CPE_LIBRARY: entry = JavaCore.newLibraryEntry(path, // sourceAttachmentPath, // sourceAttachmentRootPath, // accessRulesArray, // attributesArray, // exported); break; case IClasspathEntry.CPE_SOURCE: entry = JavaCore.newSourceEntry(path, // getInclusionPatterns(), // getExclusionPatterns(), // outputLocation, // attributesArray); break; case IClasspathEntry.CPE_PROJECT: entry = JavaCore.newProjectEntry(path, // accessRulesArray, // combineAccessRules, // attributesArray, // exported); break; default: throw new IllegalArgumentException("Unsupported IClasspathEntry kind=" + entryKind); //$NON-NLS-1$ } return entry; }