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:net.sf.spindle.core.builder.EclipseBuildInfrastructure.java
License:Mozilla Public License
public IProject[] getRequiredProjects(boolean includeBinaryPrerequisites) { if (javaProject == null || workspaceRoot == null) return new IProject[0]; ArrayList<IProject> projects = new ArrayList<IProject>(); try {//w ww. j av a2s. com IClasspathEntry[] entries = ((JavaProject) javaProject).getExpandedClasspath(true); for (int i = 0, length = entries.length; i < length; i++) { IClasspathEntry entry = JavaCore.getResolvedClasspathEntry(entries[i]); if (entry != null) { IPath path = entry.getPath(); IProject p = null; if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IProject workspaceProject = workspaceRoot.getProject(path.lastSegment()); if (workspaceProject.hasNature(TapestryCorePlugin.NATURE_ID)) p = workspaceProject; } if (p != null && !projects.contains(p)) projects.add(p); } } } catch (CoreException e) { return new IProject[0]; } IProject[] result = new IProject[projects.size()]; projects.toArray(result); return result; }
From source file:org.apache.felix.sigil.eclipse.internal.builders.SigilIncrementalProjectBuilder.java
License:Apache License
private void convert(IClasspathEntry cp, ISigilProjectModel sigil, List<File> files) throws CoreException { switch (cp.getEntryKind()) { case IClasspathEntry.CPE_PROJECT: { convertProject(cp, files);//from w w w . ja va 2 s . c o m break; } case IClasspathEntry.CPE_SOURCE: { convertSource(sigil, cp, files); break; } case IClasspathEntry.CPE_LIBRARY: { convertLibrary(sigil, cp, files); break; } case IClasspathEntry.CPE_VARIABLE: convertVariable(cp, files); break; } }
From source file:org.apache.felix.sigil.eclipse.internal.model.project.SigilProject.java
License:Apache License
public boolean isInClasspath(ISigilBundle bundle) { for (String path : getBundle().getClasspathEntrys()) { IClasspathEntry cp = getJavaModel().decodeClasspathEntry(path); switch (cp.getEntryKind()) { case IClasspathEntry.CPE_PROJECT: ISigilProjectModel p = bundle.getAncestor(ISigilProjectModel.class); return p != null && cp.getPath().equals(p.getProject().getFullPath()); case IClasspathEntry.CPE_LIBRARY: return cp.getPath().equals(bundle.getLocation()); }/*from w w w.j av a 2s . com*/ } return false; }
From source file:org.apache.felix.sigil.eclipse.ui.internal.editors.project.ClasspathSection.java
License:Apache License
private static int index(IClasspathEntry o1) { switch (o1.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: return 0; case IClasspathEntry.CPE_PROJECT: return 1; case IClasspathEntry.CPE_LIBRARY: return 2; case IClasspathEntry.CPE_VARIABLE: return 3; case IClasspathEntry.CPE_CONTAINER: return 4; default:/*from ww w . j av a 2 s .com*/ throw new IllegalStateException("Unknown classpath entry type " + o1); } }
From source file:org.apache.ivyde.internal.eclipse.cpcontainer.IvyClasspathContainerSerializer.java
License:Apache License
private IClasspathEntry readCpEntry(Node cpEntryNode) throws IOException { NamedNodeMap attributes = cpEntryNode.getAttributes(); int kind = Integer.parseInt(getMandatoryAttribute(attributes, KIND, CPENTRY)); IPath path = new Path(getMandatoryAttribute(attributes, PATH, CPENTRY)); String source = getAttribute(attributes, SOURCE); IPath sourcePath = null;/*from w ww . j a v a 2 s .co m*/ if (source != null) { sourcePath = new Path(source); } IClasspathAttribute[] cpAttrs = null; IAccessRule[] accessRules = null; NodeList children = cpEntryNode.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node item = children.item(i); if (item.getNodeName().equals(CPATTRS)) { cpAttrs = readCpAttr(item); } else if (item.getNodeName().equals(ACCESS_RULES)) { accessRules = readAccessRules(item); } } IClasspathEntry entry; switch (kind) { case IClasspathEntry.CPE_PROJECT: entry = JavaCore.newProjectEntry(path, accessRules, true, cpAttrs, true); break; case IClasspathEntry.CPE_LIBRARY: IPath sources = ivyAttachementManager.getSourceAttachment(path, sourcePath); IPath sourcesRoot = ivyAttachementManager.getSourceAttachmentRoot(path, sourcePath); entry = JavaCore.newLibraryEntry(path, sources, sourcesRoot, accessRules, cpAttrs, false); break; default: return null; } return entry; }
From source file:org.apache.ivyde.internal.eclipse.IvyDERuntimeClasspathEntryResolver.java
License:Apache License
private static IRuntimeClasspathEntry[] computeDefaultContainerEntries(IvyClasspathContainerImpl ivycp, IRuntimeClasspathEntry entry) throws CoreException { IClasspathEntry[] cpes;// www . ja va 2 s .c om if (ivycp.getClasspathEntries() == null || ivycp.getConf().getInheritedAdvancedSetup().isResolveBeforeLaunch()) { ClasspathEntriesResolver resolver = new ClasspathEntriesResolver(ivycp, false); ResolveRequest request = new ResolveRequest(resolver, ivycp.getState()); request.setForceFailOnError(true); request.setInWorkspace(ivycp.getConf().getInheritedClasspathSetup().isResolveInWorkspace()); request.setTransitive(ivycp.getConf().getInheritedClasspathSetup().isTransitiveResolve()); IvyResolveJob resolveJob = IvyPlugin.getDefault().getIvyResolveJob(); IStatus status = resolveJob.launchRequest(request, new NullProgressMonitor()); if (status.getCode() != IStatus.OK) { throw new CoreException(status); } cpes = resolver.getClasspathEntries(); } else { cpes = ivycp.getClasspathEntries(); } List resolved = new ArrayList(cpes.length); List projects = new ArrayList(); for (int i = 0; i < cpes.length; i++) { IClasspathEntry cpe = cpes[i]; if (cpe.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(cpe.getPath().segment(0)); IJavaProject jp = JavaCore.create(p); if (!projects.contains(jp)) { projects.add(jp); IRuntimeClasspathEntry classpath = JavaRuntime.newProjectRuntimeClasspathEntry(jp); resolved.add(classpath); IRuntimeClasspathEntry[] entries = JavaRuntime.resolveRuntimeClasspathEntry(classpath, jp); for (int j = 0; j < entries.length; j++) { IRuntimeClasspathEntry e = entries[j]; if (!resolved.contains(e)) { resolved.add(entries[j]); } } } } else if (cpe.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IRuntimeClasspathEntry e = JavaRuntime.newArchiveRuntimeClasspathEntry(cpe.getPath()); if (!resolved.contains(e)) { resolved.add(e); } } } // set classpath property IRuntimeClasspathEntry[] result = new IRuntimeClasspathEntry[resolved.size()]; for (int i = 0; i < result.length; i++) { result[i] = (IRuntimeClasspathEntry) resolved.get(i); result[i].setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES); } return result; }
From source file:org.apache.ivyde.internal.eclipse.workspaceresolver.WorkspaceResourceChangeListener.java
License:Apache License
/** * Return the IvyDE container which include the specified project path as ivy dependency *//*from w w w .j a va 2 s .c o m*/ private List getAffectedContainers(IPath projectPath) { List/* <IvyClasspathContainer> */ allContainers = new ArrayList(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IJavaProject[] projects; try { projects = JavaCore.create(root).getJavaProjects(); } catch (JavaModelException e) { // something bad happend in the JDT... IvyPlugin.log(e); return allContainers; } for (int i = 0; i < projects.length; i++) { IJavaProject javaProject = projects[i]; List/* <IvyClasspathContainer> */ containers = IvyClasspathContainerHelper.getContainers(javaProject); Iterator/* <IvyClasspathContainer> */ itContainer = containers.iterator(); while (itContainer.hasNext()) { IvyClasspathContainerImpl ivycp = (IvyClasspathContainerImpl) itContainer.next(); IClasspathEntry[] containerEntries = ivycp.getClasspathEntries(); for (int j = 0; j < containerEntries.length; j++) { IClasspathEntry containerEntry = containerEntries[j]; if (containerEntry == null || containerEntry.getEntryKind() != IClasspathEntry.CPE_PROJECT || !containerEntry.getPath().equals(projectPath)) { continue; } allContainers.add(ivycp); break; } } } return allContainers; }
From source file:org.checkthread.plugin.eclipse.CheckThreadRunner.java
License:Open Source License
private static void loadDirFromProject(HashMap<IProject, Boolean> projectSearchMap, boolean isrecursed, IProject project, ArrayList<IPath> srcDirList, ArrayList<URI> targetFileList, ArrayList<URI> classPathList) { // if we already searched this project if (projectSearchMap.get(project) != null) { return;/*from www .j a v a 2 s. co m*/ // we haven't searched this project yet } else { // add to cache projectSearchMap.put(project, true); } // recursive traverse referenced projects // stopping condition: project already searched try { IProject[] projectList = project.getReferencedProjects(); for (IProject p : projectList) { loadDirFromProject(projectSearchMap, true, p, srcDirList, targetFileList, classPathList); } } catch (Exception e) { e.printStackTrace(); } IJavaProject javaProject = JavaCore.create(project); IPath defaultOutputLocationRelative = null; try { defaultOutputLocationRelative = javaProject.getOutputLocation(); } catch (Exception e) { e.printStackTrace(); return; } sLogger.info("DEFAULT OUTPUT LOCATION RELATIVE: " + defaultOutputLocationRelative); IPath projectLocationAbsolute = project.getLocation(); sLogger.info("PROJECT LOCATION: " + projectLocationAbsolute); // Make path absolute IPath defaultOutputLocationAbsolute = projectLocationAbsolute .append(defaultOutputLocationRelative.removeFirstSegments(1)); sLogger.info("DEFAULT OUTPUT LOCATION ABSOLUTE: " + defaultOutputLocationAbsolute); // Work around, stomp over target java files. Instead, just give the // root directory sLogger.info("WORKAROUND: IGNORE CHANGED CLASS FILES< RECHECK EVERYTHING"); if (!isrecursed) { URI uri = defaultOutputLocationAbsolute.toFile().toURI(); if (uri != null) { targetFileList.add(uri); } } // Add to input URI cURI = defaultOutputLocationAbsolute.toFile().toURI(); if (cURI != null) { classPathList.add(cURI); } // Loop through classpath entries and get src directory list IClasspathEntry[] rawClassPathList = null; try { rawClassPathList = javaProject.getRawClasspath(); } catch (JavaModelException e) { e.printStackTrace(); } if (rawClassPathList != null) { for (IClasspathEntry classPathEntry : rawClassPathList) { switch (classPathEntry.getEntryKind()) { // Source Directory case IClasspathEntry.CPE_SOURCE: { if (!isrecursed) { IPath p = classPathEntry.getPath().removeFirstSegments(1); if (p != null) { srcDirList.add(p); sLogger.info("CPE_SOURCE: " + p); } } break; } // external libraries used case IClasspathEntry.CPE_LIBRARY: { File file = classPathEntry.getPath().toFile(); IPath p; // The entry may be a relative path to the project root // or it could be an absolute path to a library. if (file.isFile() || file.isDirectory()) { p = classPathEntry.getPath(); } else { p = projectLocationAbsolute.append(classPathEntry.getPath().removeFirstSegments(1)); } URI uri = p.toFile().toURI(); if (uri != null) { classPathList.add(uri); } sLogger.info("CPE_LIBRARY: " + uri); break; } // ignore case IClasspathEntry.CPE_CONTAINER: sLogger.info("CPE_CONTAINER: " + classPathEntry); break; //ignore case IClasspathEntry.CPE_PROJECT: sLogger.info("CPE_PROJECT: " + classPathEntry); break; } } } }
From source file:org.codehaus.groovy.eclipse.launchers.AbstractGroovyLaunchShortcut.java
License:Apache License
/** * Need to recursively walk the classpath and visit all dependent projects * Not looking at classpath containers yet. * * @param javaProject/*from w w w . j a v a 2 s. c om*/ * @param entries */ private void addClasspathEntriesForProject(IJavaProject javaProject, SortedSet<String> sourceEntries, SortedSet<String> binEntries) { List<IJavaProject> dependingProjects = new ArrayList<IJavaProject>(); try { IClasspathEntry[] entries = javaProject.getRawClasspath(); for (IClasspathEntry entry : entries) { int kind = entry.getEntryKind(); switch (kind) { case IClasspathEntry.CPE_LIBRARY: IPath libPath = entry.getPath(); if (!isPathInWorkspace(libPath)) { sourceEntries.add(libPath.toOSString()); break; } //$FALL-THROUGH$ case IClasspathEntry.CPE_SOURCE: IPath srcPath = entry.getPath(); String sloc = getProjectLocation(srcPath); if (srcPath.segmentCount() > 1) { sloc += File.separator + srcPath.removeFirstSegments(1).toOSString(); } sourceEntries.add(sloc); IPath outPath = entry.getOutputLocation(); if (outPath != null) { String bloc = getProjectLocation(outPath); if (outPath.segmentCount() > 1) { bloc += File.separator + outPath.removeFirstSegments(1).toOSString(); } binEntries.add(bloc); } break; case IClasspathEntry.CPE_PROJECT: dependingProjects.add(javaProject.getJavaModel().getJavaProject(entry.getPath().lastSegment())); break; } } IPath defaultOutPath = javaProject.getOutputLocation(); if (defaultOutPath != null) { String bloc = getProjectLocation(javaProject); if (defaultOutPath.segmentCount() > 1) { bloc += File.separator + defaultOutPath.removeFirstSegments(1).toOSString(); } binEntries.add(bloc); } } catch (JavaModelException e) { GroovyCore.logException("Exception generating classpath for launching groovy script", e); } // recur through dependent projects for (IJavaProject dependingProject : dependingProjects) { if (dependingProject.getProject().isAccessible()) { addClasspathEntriesForProject(dependingProject, sourceEntries, binEntries); } } }
From source file:org.compiere.mfg_scm.eclipse.db.DbfBootstrap.java
License:Apache License
private void getClassPathEntries(IJavaProject prj, ArrayList data, List selectedPaths, ArrayList visitedProjects) { IClasspathEntry[] entries = null;/*from w w w.j a va 2s . c om*/ IPath outputPath = null; try { outputPath = prj.getOutputLocation(); if (selectedPaths.contains(outputPath.toFile().toString().replace('\\', '/'))) { add(data, prj.getProject().getWorkspace().getRoot().findMember(outputPath)); } entries = prj.getRawClasspath(); } catch (JavaModelException e) { DbfLauncherPlugin.log(e); } if (entries == null) return; for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; IPath path = entry.getPath(); if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { path = entry.getOutputLocation(); if (path == null) continue; } if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { String prjName = entry.getPath().lastSegment(); if (!visitedProjects.contains(prjName)) { visitedProjects.add(prjName); getClassPathEntries(prj.getJavaModel().getJavaProject(prjName), data, selectedPaths, visitedProjects); } continue; } else if (!selectedPaths.contains(path.toFile().toString().replace('\\', '/'))) continue; IClasspathEntry[] tmpEntry = null; if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { try { tmpEntry = JavaCore.getClasspathContainer(path, prj).getClasspathEntries(); } catch (JavaModelException e1) { DbfLauncherPlugin.log(e1); continue; } } else { tmpEntry = new IClasspathEntry[1]; tmpEntry[0] = JavaCore.getResolvedClasspathEntry(entry); } for (int j = 0; j < tmpEntry.length; j++) { if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IResource res = prj.getProject().getWorkspace().getRoot().findMember(tmpEntry[j].getPath()); if (res != null) add(data, res); else add(data, tmpEntry[j].getPath()); } else if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath srcPath = entry.getOutputLocation(); if (srcPath != null && !srcPath.equals(outputPath)) { add(data, prj.getProject().getWorkspace().getRoot().findMember(srcPath)); } } else { add(data, tmpEntry[j].getPath()); } } } }