List of usage examples for org.eclipse.jdt.core IClasspathEntry getEntryKind
int getEntryKind();
From source file:net.sf.fjep.fatjar.wizards.export.JProjectConfiguration.java
License:Open Source License
public void getChildProjects(Vector projects, boolean exportedOnly) { IClasspathEntry[] cpes = this.getRawClasspathEntries(); if (cpes != null) { for (int i = 0; i < cpes.length; i++) { IClasspathEntry cpe = JavaCore.getResolvedClasspathEntry(cpes[i]); if (cpe == null) { System.err.println("Error: cpes[" + i + "]=" + cpes[i] + " does not resolve"); continue; }/*from w ww. ja v a 2 s. c o m*/ int kind = cpe.getEntryKind(); String name = relPath(cpe.getPath()); if (kind == IClasspathEntry.CPE_CONTAINER) { try { IClasspathContainer container = JavaCore.getClasspathContainer(cpe.getPath(), jproject); if ((container.getKind() == IClasspathContainer.K_APPLICATION) || (container.getKind() == IClasspathContainer.K_SYSTEM)) { IClasspathEntry[] cpes2 = container.getClasspathEntries(); for (int j = 0; j < cpes2.length; j++) { IClasspathEntry cpe2 = cpes2[j]; int kind2 = cpe2.getEntryKind(); String name2 = relPath(cpe2.getPath()); if (name2 == null) { System.err.println("invalid classpath entry: " + cpe2.toString()); } else { if (kind2 == IClasspathEntry.CPE_PROJECT) { if (!exportedOnly || cpe2.isExported()) { if (!projects.contains(name2)) { IJavaProject jChildProject2 = jproject.getJavaModel() .getJavaProject(name2); JProjectConfiguration jpcChild2 = new JProjectConfiguration( jChildProject2, null); projects.add(jpcChild2); jpcChild2.getChildProjects(projects, true); } } } } } } } catch (JavaModelException e) { } } else if (kind == IClasspathEntry.CPE_PROJECT) { if (name == null) { System.err.println("invalid classpath entry: " + cpe.toString()); } else { if (!exportedOnly || cpe.isExported()) { if (!projects.contains(name)) { IJavaProject jChildProject = jproject.getJavaModel().getJavaProject(name); JProjectConfiguration jpcChild = new JProjectConfiguration(jChildProject, null); projects.add(jpcChild); jpcChild.getChildProjects(projects, true); } } } } } } }
From source file:net.sf.j2s.core.builder.JavaBuilder.java
License:Open Source License
private IProject[] getRequiredProjects(boolean includeBinaryPrerequisites) { if (this.javaProject == null || this.workspaceRoot == null) return new IProject[0]; ArrayList projects = new ArrayList(); ExternalFoldersManager externalFoldersManager = JavaModelManager.getExternalManager(); try {//www .j av a 2 s . c o m IClasspathEntry[] entries = this.javaProject.getExpandedClasspath(); for (int i = 0, l = entries.length; i < l; i++) { IClasspathEntry entry = entries[i]; IPath path = entry.getPath(); IProject p = null; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_PROJECT: p = this.workspaceRoot.getProject(path.lastSegment()); // missing projects are considered too if (((ClasspathEntry) entry).isOptional() && !JavaProject.hasJavaNature(p)) // except if entry is optional p = null; break; case IClasspathEntry.CPE_LIBRARY: if (includeBinaryPrerequisites && path.segmentCount() > 0) { // some binary resources on the class path can come from projects that are not included in the project references IResource resource = this.workspaceRoot.findMember(path.segment(0)); if (resource instanceof IProject) { p = (IProject) resource; } else { resource = externalFoldersManager.getFolder(path); if (resource != null) p = resource.getProject(); } } } if (p != null && !projects.contains(p)) projects.add(p); } } catch (JavaModelException e) { return new IProject[0]; } IProject[] result = new IProject[projects.size()]; projects.toArray(result); return result; }
From source file:net.sf.j2s.core.builder.NameEnvironment.java
License:Open Source License
private void computeClasspathLocations(IWorkspaceRoot root, JavaProject javaProject, SimpleLookupTable binaryLocationsPerProject) throws CoreException { /* Update cycle marker */ IMarker cycleMarker = javaProject.getCycleMarker(); if (cycleMarker != null) { int severity = JavaCore.ERROR.equals(javaProject.getOption(JavaCore.CORE_CIRCULAR_CLASSPATH, true)) ? IMarker.SEVERITY_ERROR : IMarker.SEVERITY_WARNING; if (severity != cycleMarker.getAttribute(IMarker.SEVERITY, severity)) cycleMarker.setAttribute(IMarker.SEVERITY, severity); }/*from w ww.j ava2 s . c om*/ IClasspathEntry[] classpathEntries = javaProject.getExpandedClasspath(); ArrayList sLocations = new ArrayList(classpathEntries.length); ArrayList bLocations = new ArrayList(classpathEntries.length); nextEntry: for (int i = 0, l = classpathEntries.length; i < l; i++) { ClasspathEntry entry = (ClasspathEntry) classpathEntries[i]; IPath path = entry.getPath(); Object target = JavaModel.getTarget(path, true); if (target == null) continue nextEntry; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: if (!(target instanceof IContainer)) continue nextEntry; IPath outputPath = entry.getOutputLocation() != null ? entry.getOutputLocation() : javaProject.getOutputLocation(); IContainer outputFolder; if (outputPath.segmentCount() == 1) { outputFolder = javaProject.getProject(); } else { outputFolder = root.getFolder(outputPath); if (!outputFolder.exists()) createOutputFolder(outputFolder); } sLocations.add(ClasspathLocation.forSourceFolder((IContainer) target, outputFolder, entry.fullInclusionPatternChars(), entry.fullExclusionPatternChars(), entry.ignoreOptionalProblems())); continue nextEntry; case IClasspathEntry.CPE_PROJECT: if (!(target instanceof IProject)) continue nextEntry; IProject prereqProject = (IProject) target; if (!JavaProject.hasJavaNature(prereqProject)) continue nextEntry; // if project doesn't have java nature or is not accessible JavaProject prereqJavaProject = (JavaProject) JavaCore.create(prereqProject); IClasspathEntry[] prereqClasspathEntries = prereqJavaProject.getRawClasspath(); ArrayList seen = new ArrayList(); nextPrereqEntry: for (int j = 0, m = prereqClasspathEntries.length; j < m; j++) { IClasspathEntry prereqEntry = prereqClasspathEntries[j]; if (prereqEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { Object prereqTarget = JavaModel.getTarget(prereqEntry.getPath(), true); if (!(prereqTarget instanceof IContainer)) continue nextPrereqEntry; IPath prereqOutputPath = prereqEntry.getOutputLocation() != null ? prereqEntry.getOutputLocation() : prereqJavaProject.getOutputLocation(); IContainer binaryFolder = prereqOutputPath.segmentCount() == 1 ? (IContainer) prereqProject : (IContainer) root.getFolder(prereqOutputPath); if (binaryFolder.exists() && !seen.contains(binaryFolder)) { seen.add(binaryFolder); ClasspathLocation bLocation = ClasspathLocation.forBinaryFolder(binaryFolder, true, entry.getAccessRuleSet()); bLocations.add(bLocation); if (binaryLocationsPerProject != null) { // normal builder mode ClasspathLocation[] existingLocations = (ClasspathLocation[]) binaryLocationsPerProject .get(prereqProject); if (existingLocations == null) { existingLocations = new ClasspathLocation[] { bLocation }; } else { int size = existingLocations.length; System.arraycopy(existingLocations, 0, existingLocations = new ClasspathLocation[size + 1], 0, size); existingLocations[size] = bLocation; } binaryLocationsPerProject.put(prereqProject, existingLocations); } } } } continue nextEntry; case IClasspathEntry.CPE_LIBRARY: if (target instanceof IResource) { IResource resource = (IResource) target; ClasspathLocation bLocation = null; if (resource instanceof IFile) { AccessRuleSet accessRuleSet = (JavaCore.IGNORE .equals(javaProject.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, true)) && JavaCore.IGNORE.equals( javaProject.getOption(JavaCore.COMPILER_PB_DISCOURAGED_REFERENCE, true))) ? null : entry.getAccessRuleSet(); bLocation = ClasspathLocation.forLibrary((IFile) resource, accessRuleSet); } else if (resource instanceof IContainer) { AccessRuleSet accessRuleSet = (JavaCore.IGNORE .equals(javaProject.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, true)) && JavaCore.IGNORE.equals( javaProject.getOption(JavaCore.COMPILER_PB_DISCOURAGED_REFERENCE, true))) ? null : entry.getAccessRuleSet(); bLocation = ClasspathLocation.forBinaryFolder((IContainer) target, false, accessRuleSet); // is library folder not output folder } bLocations.add(bLocation); if (binaryLocationsPerProject != null) { // normal builder mode IProject p = resource.getProject(); // can be the project being built ClasspathLocation[] existingLocations = (ClasspathLocation[]) binaryLocationsPerProject .get(p); if (existingLocations == null) { existingLocations = new ClasspathLocation[] { bLocation }; } else { int size = existingLocations.length; System.arraycopy(existingLocations, 0, existingLocations = new ClasspathLocation[size + 1], 0, size); existingLocations[size] = bLocation; } binaryLocationsPerProject.put(p, existingLocations); } } else if (target instanceof File) { AccessRuleSet accessRuleSet = (JavaCore.IGNORE .equals(javaProject.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, true)) && JavaCore.IGNORE.equals( javaProject.getOption(JavaCore.COMPILER_PB_DISCOURAGED_REFERENCE, true))) ? null : entry.getAccessRuleSet(); bLocations.add(ClasspathLocation.forLibrary(path.toString(), accessRuleSet)); } continue nextEntry; } } // now split the classpath locations... place the output folders ahead of the other .class file folders & jars ArrayList outputFolders = new ArrayList(1); this.sourceLocations = new ClasspathMultiDirectory[sLocations.size()]; if (!sLocations.isEmpty()) { sLocations.toArray(this.sourceLocations); // collect the output folders, skipping duplicates next: for (int i = 0, l = this.sourceLocations.length; i < l; i++) { ClasspathMultiDirectory md = this.sourceLocations[i]; IPath outputPath = md.binaryFolder.getFullPath(); for (int j = 0; j < i; j++) { // compare against previously walked source folders if (outputPath.equals(this.sourceLocations[j].binaryFolder.getFullPath())) { md.hasIndependentOutputFolder = this.sourceLocations[j].hasIndependentOutputFolder; continue next; } } outputFolders.add(md); // also tag each source folder whose output folder is an independent folder & is not also a source folder for (int j = 0, m = this.sourceLocations.length; j < m; j++) if (outputPath.equals(this.sourceLocations[j].sourceFolder.getFullPath())) continue next; md.hasIndependentOutputFolder = true; } } // combine the output folders with the binary folders & jars... place the output folders before other .class file folders & jars this.binaryLocations = new ClasspathLocation[outputFolders.size() + bLocations.size()]; int index = 0; for (int i = 0, l = outputFolders.size(); i < l; i++) this.binaryLocations[index++] = (ClasspathLocation) outputFolders.get(i); for (int i = 0, l = bLocations.size(); i < l; i++) this.binaryLocations[index++] = (ClasspathLocation) bLocations.get(i); }
From source file:net.sf.jasperreports.eclipse.classpath.container.JRClasspathContainerPage.java
License:Open Source License
@Override public void initialize(IJavaProject project, IClasspathEntry[] currentEntries) { jrcc = new JRClasspathContainer(null, project); for (int i = 0; i < currentEntries.length; i++) { IClasspathEntry curr = currentEntries[i]; if (curr.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { fUsedPaths.add(curr.getPath()); }/*ww w . j ava2 s . co m*/ } }
From source file:net.sf.jasperreports.eclipse.classpath.JavaProjectClassLoader.java
License:Open Source License
private void resolveClasspathEntries(Set<URL> urls, IWorkspaceRoot root, IClasspathEntry[] entries) throws JavaModelException { for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath path = entry.getPath(); if (path.segmentCount() >= 2) { IFolder sourceFolder = root.getFolder(path); try { urls.add(new URL("file:///" + sourceFolder.getRawLocation().toOSString() + "/")); } catch (MalformedURLException e) { }// w ww . j av a2 s. c o m } } else if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath sourcePath = entry.getPath(); covertPathToUrl(javaProject.getProject(), urls, sourcePath); IPath sourceOutputPath = entry.getOutputLocation(); covertPathToUrl(javaProject.getProject(), urls, sourceOutputPath); } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (entry.getPath().equals(JRClasspathContainer.ID)) continue; IClasspathContainer cont = JavaCore.getClasspathContainer(entry.getPath(), javaProject); resolveClasspathEntries(urls, root, cont.getClasspathEntries()); } } }
From source file:net.sf.refactorit.eclipse.vfs.EclipseClassPath.java
License:Open Source License
public ClassPathElement[] createElements() { if (project == null || !project.isOpen()) { return new ClassPathElement[0]; }//w w w .ja v a 2 s.c o m ArrayList result; if (options.isAutoDetect()) { IJavaProject jProject = JavaCore.create(project); try { IClasspathEntry[] pathEntries = jProject.getResolvedClasspath(true); result = new ArrayList(pathEntries.length); for (int i = 0; i < pathEntries.length; i++) { IClasspathEntry entry = pathEntries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath path = entry.getPath(); if (debug) { log.debug("creating classpath entry for path " + path); } File file = path.toFile(); if (!file.exists()) { // FIXME: hack, improve // lib under workspace IFile f = project.getWorkspace().getRoot().getFile(path); file = f.getRawLocation().toFile(); } addClasspathElement(result, file); } } } catch (JavaModelException e) { throw new SystemException(ErrorCodes.ECLIPSE_INTERNAL_ERROR, "resolving classpath failed", e); } } else { log.debug("creating customized classpath elements"); PathItem[] items = options.getClassPath().getItems(); result = new ArrayList(items.length); for (int i = 0; i < items.length; i++) { File file = new File(items[i].getAbsolutePath()); addClasspathElement(result, file); } } return (ClassPathElement[]) result.toArray(new ClassPathElement[result.size()]); }
From source file:net.sf.refactorit.eclipse.vfs.EclipseSourcePath.java
License:Open Source License
private IClasspathEntry[] getSourcePathEntries() throws JavaModelException { IJavaProject jProject = getJavaProject(); List result = new ArrayList(); IClasspathEntry[] pathEntries = jProject.getResolvedClasspath(true); for (int i = 0; i < pathEntries.length; i++) { IClasspathEntry entry = pathEntries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE /*|| entry.getEntryKind() == IClasspathEntry.CPE_PROJECT*/) { result.add(entry);/*from www .j ava 2 s . c o m*/ if (debug) { log.debug("exclusion patterns = " + Arrays.asList(entry.getExclusionPatterns())); } } } return (IClasspathEntry[]) result.toArray(new IClasspathEntry[result.size()]); }
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 {/*from w w w . j ava 2 s . co m*/ 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:net.sourceforge.floggy.eclipse.builder.DefaultBuilder.java
License:Open Source License
/** * DOCUMENT ME!/*from w ww . ja v a 2s.c om*/ * * @param project DOCUMENT ME! * @param monitor DOCUMENT ME! * * @return DOCUMENT ME! * * @throws Exception DOCUMENT ME! */ public IProject[] build(IProject project, IProgressMonitor monitor) throws Exception { IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); List classpathList = new ArrayList(); ClassPool classPool = new ClassPool(); IClasspathEntry classpathEntry; String pathName; for (int i = 0; i < entries.length; i++) { classpathEntry = JavaCore.getResolvedClasspathEntry(entries[i]); pathName = classpathEntry.getPath().toFile().toString(); if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { if (!classpathEntry.getPath().toFile().exists()) { IFile pathIFile = project.getWorkspace().getRoot().getFile(classpathEntry.getPath()); pathName = pathIFile.getLocationURI().getPath(); } } classpathList.add(pathName); classPool.appendClassPath(pathName); } if (validateClasspath(project, classPool)) { Weaver weaver = new Weaver(classPool); IPath root = project.getLocation(); File input = root.removeLastSegments(1).append(javaProject.getOutputLocation()).toFile(); IFolder floggyTemp = project.getFolder(".floggy.tmp"); if (!floggyTemp.exists()) { floggyTemp.create(IResource.DERIVED, true, monitor); } IFile configurationFile = project .getFile(project.getPersistentProperty(ConfigurationFileAction.PROPERTY_NAME)); weaver.setOutputFile(floggyTemp.getLocation().toFile()); weaver.setInputFile(input); weaver.setClasspath((String[]) classpathList.toArray(new String[classpathList.size()])); if (!configurationFile.exists()) { weaver.setConfiguration(createWeaverConfiguration(project)); } else { weaver.setConfigurationFile(configurationFile.getLocation().toFile()); } weaver.execute(); IPath path = javaProject.getOutputLocation(); if (path.segmentCount() > 1) { path = path.removeFirstSegments(1); } IFolder outputLocation = project.getFolder(path); floggyTemp.refreshLocal(IResource.DEPTH_INFINITE, monitor); copyFiles(floggyTemp, outputLocation, monitor); outputLocation.refreshLocal(IResource.DEPTH_INFINITE, monitor); cleanFolder(floggyTemp, monitor); } return new IProject[0]; }
From source file:net.sourceforge.floggy.eclipse.builder.MTJBuilder.java
License:Open Source License
/** * This is where the classpool is actually set. The typical case only requires adding the required jar files * to the classpool (classPool and classPoolList), however if the project is dependent on other projects then * not only do we need the jar files from these dependencies but we also need the output folders. * @TODO EXPERIMENTAL - Dependencies support should be considered experimental at this time because it isn't fully tested ! *//*from w w w .ja v a 2s. co m*/ private void configureClassPool(ClassPool classPool, List classPoolList, IClasspathEntry[] entries, IProject project, boolean isRootProject) throws NotFoundException, JavaModelException { IClasspathEntry classpathEntry; String pathName; for (int i = 0; i < entries.length; i++) { classpathEntry = JavaCore.getResolvedClasspathEntry(entries[i]); IPath classIPath = classpathEntry.getPath(); if ((isRootProject || classpathEntry.isExported()) && classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { pathName = getAccessablePathName(classIPath, project); } else if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { classIPath = classpathEntry.getOutputLocation(); if (classIPath == null) { classIPath = JavaCore.create(project).getOutputLocation(); } pathName = getAccessablePathName(classIPath, project); } else { // Currently we only add : All source folders, All libs in the root project & Exported libs in other projects continue; } if (pathName.contains("floggy-persistence-framework-impl.jar")) { continue; } if (pathName != null && !classPoolList.contains(pathName)) { LOG.debug(pathName + " added to classPool"); classPoolList.add(pathName); classPool.appendClassPath(pathName); } else { LOG.debug(pathName + " alreaded added to classPool"); } } }