List of usage examples for org.eclipse.jdt.core IClasspathEntry getContentKind
int getContentKind();
From source file:org.ebayopensource.turmeric.eclipse.utils.test.plugin.TestJDTUtil.java
License:Open Source License
/** * Test method for {@link org.ebayopensource.turmeric.eclipse.utils.plugin.JDTUtil#isClasspathContainer(org.eclipse.jdt.core.IClasspathEntry, java.lang.String)}. * Test method for {@link org.ebayopensource.turmeric.eclipse.utils.plugin.JDTUtil#isJREClasspathContainer(org.eclipse.jdt.core.IClasspathEntry)}. * @throws JavaModelException //from w w w .j a v a2 s. c o m */ @Test public void testIsClasspathContainer() throws JavaModelException { for (IClasspathEntry entry : JDTUtil.rawClasspath(project, true)) { switch (entry.getContentKind()) { case IClasspathEntry.CPE_CONTAINER: Assert.assertTrue(JDTUtil.isClasspathContainer(entry, entry.getPath().toString())); break; default: //Assert.assertFalse(JDTUtil.isClasspathContainer(entry, entry.getPath().toString())); break; } } }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
private static String[] internalGetProjectPath(IProject project, IClasspathAttribute attribute, boolean useResolvedPath) { if (isAspectPathAttribute(attribute)) { if (shouldCheckOldStylePath(project, ASPECTPATH)) { String[] old = getOldProjectPath(project, true); if (old != null) { AJLog.log("Migrating aspect path settings for project " + project.getName()); //$NON-NLS-1$ setProjectAspectPath(project, old[0], old[1], old[2]); }// ww w . j av a 2s.c o m markOldStylePathAsRead(project, ASPECTPATH); } } else { // INPATH_ATTRIBUTE if (shouldCheckOldStylePath(project, INPATH)) { String[] old = getOldProjectPath(project, false); if (old != null) { AJLog.log("Migrating aspect path settings for project " + project.getName()); //$NON-NLS-1$ setProjectInPath(project, old[0], old[1], old[2]); } markOldStylePathAsRead(project, INPATH); } } String pathString = ""; //$NON-NLS-1$ String contentString = ""; //$NON-NLS-1$ String entryString = ""; //$NON-NLS-1$ IJavaProject javaProject = JavaCore.create(project); try { IClasspathEntry[] cp = javaProject.getRawClasspath(); for (int i = 0; i < cp.length; i++) { IClasspathAttribute[] attributes = cp[i].getExtraAttributes(); boolean attributeFound = false; for (int j = 0; j < attributes.length; j++) { if (attributes[j].getName().equals(attribute.getName())) { attributeFound = true; List<IClasspathEntry> actualEntries = new ArrayList<IClasspathEntry>(); if (useResolvedPath) { // this entry is on the path. must resolve it if (cp[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) { List<IClasspathEntry> containerEntries = resolveClasspathContainer(cp[i], project); // Bug 273770 - look for the XXXPATH_RESTRICTION_ATTRIBUTE_NAME classpath attribute Set<String> extraPathElements = findContainerRestrictions(cp[i], isAspectPathAttribute(attribute)); if (extraPathElements != null && extraPathElements.size() > 0) { // must filter for (Iterator<IClasspathEntry> cpIter = containerEntries.iterator(); cpIter .hasNext();) { IClasspathEntry containerEntry = cpIter.next(); if (!containsAsPathFragment(extraPathElements, containerEntry)) { cpIter.remove(); } } } actualEntries.addAll(containerEntries); } else if (cp[i].getEntryKind() == IClasspathEntry.CPE_PROJECT) { IProject requiredProj = project.getWorkspace().getRoot() .getProject(cp[i].getPath().makeRelative().toPortableString()); if (!requiredProj.getName().equals(project.getName()) && requiredProj.exists()) { actualEntries.addAll(resolveDependentProjectClasspath(cp[i], requiredProj)); } } else { // resolve the classpath variable IClasspathEntry resolved = JavaCore.getResolvedClasspathEntry(cp[i]); if (resolved != null) { if (resolved.getEntryKind() == IClasspathEntry.CPE_PROJECT) { // must resolve the project actualEntries.addAll( resolveDependentProjectClasspath(resolved, project.getWorkspace() .getRoot().getProject(resolved.getPath().toString()))); } else { actualEntries.add(resolved); } } } // cp[i].getEntryKind() } else { actualEntries.add(cp[i]); } // useResolvedEntry for (IClasspathEntry actualEntry : actualEntries) { // we can get null for actualEntry if the raw entry corresponds to // an unbound classpath variable if (actualEntry != null) { pathString += actualEntry.getPath().toPortableString() + File.pathSeparator; contentString += actualEntry.getContentKind() + File.pathSeparator; entryString += actualEntry.getEntryKind() + File.pathSeparator; } } } // attributes[j].equals(attribute) } // for (int j = 0; j < attributes.length; j++) // there is a special case that we must look inside the classpath container for entries with // attributes if we are returning the resolved path and the container itself isn't already // on the path. if (!attributeFound && useResolvedPath && cp[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) { List<IClasspathEntry> containerEntries = resolveClasspathContainer(cp[i], project); for (IClasspathEntry containerEntry : containerEntries) { if (isOnPath(containerEntry, isAspectPathAttribute(attribute))) { pathString += containerEntry.getPath().toPortableString() + File.pathSeparator; contentString += containerEntry.getContentKind() + File.pathSeparator; entryString += containerEntry.getEntryKind() + File.pathSeparator; } } // for (Iterator cpIter = containerEntries.iterator(); cpIter.hasNext(); ) } // !attributeFound && useResolvedPath && cp[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER } // for (int i = 0; i < cp.length; i++) } catch (JavaModelException e) { } return new String[] { pathString, contentString, entryString }; }
From source file:org.eclipse.ajdt.core.CoreUtils.java
License:Open Source License
/** * Get the output locations for the project * /* w w w. j a v a 2 s .com*/ * @param project * @return list of IPath objects */ public static List<IPath> getOutputLocationPaths(IProject project) { List<IPath> outputLocations = new ArrayList<IPath>(); IJavaProject javaProject = JavaCore.create(project); if (javaProject == null) return outputLocations; try { // Have been unable to create a user scenario where the following // for // loop adds something to outputLocations, therefore always // fall through to the following if loop. However, if a project has // more than one output folder, then this for loop should pick them // up. // Needs testing....... IClasspathEntry[] cpEntry = javaProject.getRawClasspath(); for (int j = 0; j < cpEntry.length; j++) { IClasspathEntry entry = cpEntry[j]; int contentKind = entry.getContentKind(); if (contentKind == ClasspathEntry.K_OUTPUT) { if (entry.getOutputLocation() != null) { outputLocations.add(entry.getOutputLocation()); } } } // If we haven't added anything from reading the .classpath // file, then use the default output location if (outputLocations.size() == 0) { outputLocations.add(javaProject.getOutputLocation()); } } catch (JavaModelException e) { } return outputLocations; }
From source file:org.eclipse.ajdt.internal.ui.wizards.PathBlock.java
License:Open Source License
protected void internalConfigureJavaProject(List pathElements, IProgressMonitor monitor) throws CoreException, InterruptedException { int nEntries = pathElements.size(); List /* IClasspathEntry */<IClasspathEntry> pathEntries = new ArrayList<IClasspathEntry>(); for (int i = 0; i < nEntries; i++) { // Bug 243356 // remove from the list if this is an entry contained in a container // because entries in containers are computed separately CPListElement element = ((CPListElement) pathElements.get(i)); if (!inClasspathContainer(element)) { pathEntries.add(element.getClasspathEntry()); }//from w w w. j a v a2 s .c o m } monitor.worked(2); Map<IPath, String> inpathRestrictions = new HashMap<IPath, String>(); Map<IPath, String> aspectpathRestrictions = new HashMap<IPath, String>(); StringBuffer pathBuffer = new StringBuffer(); StringBuffer contentKindBuffer = new StringBuffer(); StringBuffer entryKindBuffer = new StringBuffer(); for (Iterator<IClasspathEntry> pathIter = pathEntries.iterator(); pathIter.hasNext();) { IClasspathEntry pathEntry = pathIter.next(); pathBuffer.append(pathEntry.getPath()); pathBuffer.append(File.pathSeparator); contentKindBuffer.append(pathEntry.getContentKind()); contentKindBuffer.append(File.pathSeparator); entryKindBuffer.append(pathEntry.getEntryKind()); entryKindBuffer.append(File.pathSeparator); String inpathRestriction = AspectJCorePreferences.getRestriction(pathEntry, AspectJCorePreferences.INPATH_RESTRICTION_ATTRIBUTE_NAME); if (inpathRestriction != null && inpathRestriction.length() > 0) { inpathRestrictions.put(pathEntry.getPath(), inpathRestriction); } String aspectpathRestriction = AspectJCorePreferences.getRestriction(pathEntry, AspectJCorePreferences.ASPECTPATH_RESTRICTION_ATTRIBUTE_NAME); if (aspectpathRestriction != null && aspectpathRestriction.length() > 0) { aspectpathRestrictions.put(pathEntry.getPath(), aspectpathRestriction); } } pathBuffer = removeFinalPathSeparatorChar(pathBuffer); contentKindBuffer = removeFinalPathSeparatorChar(contentKindBuffer); entryKindBuffer = removeFinalPathSeparatorChar(entryKindBuffer); internalSetProjectPath(pathElements, pathBuffer, contentKindBuffer, entryKindBuffer); // update the classpath with the restrictions if (inpathRestrictions.size() > 0 || aspectpathRestrictions.size() > 0) { IClasspathEntry[] entries = getJavaProject().getRawClasspath(); boolean hasChanges = false; if (inpathRestrictions.size() > 0) { hasChanges |= updatePathRestrictions(entries, inpathRestrictions, false); } if (aspectpathRestrictions.size() > 0) { hasChanges |= updatePathRestrictions(entries, aspectpathRestrictions, true); } if (hasChanges) { getJavaProject().setRawClasspath(entries, new NullProgressMonitor()); } } }
From source file:org.eclipse.ajdt.ui.tests.builder.ProjectDependenciesUtils.java
License:Open Source License
public static boolean projectHasClassFolderDependency(IProject project, IProject projectDependedOn) throws JavaModelException { IJavaProject javaProject = JavaCore.create(project); IJavaProject depProject = JavaCore.create(projectDependedOn); if (javaProject == null || depProject == null) return false; // first get the output location for projectDependedOn IPath outputLocation = null;/* w ww . j av a2 s .c o m*/ IClasspathEntry[] cp = depProject.getRawClasspath(); for (int j = 0; j < cp.length; j++) { IClasspathEntry entry = cp[j]; int contentKind = entry.getContentKind(); if (contentKind == ClasspathEntry.K_OUTPUT) { outputLocation = entry.getOutputLocation(); } if (entry.getEntryKind() == ClasspathEntry.K_OUTPUT) { outputLocation = entry.getOutputLocation(); } } if (outputLocation == null) { outputLocation = depProject.getOutputLocation(); } // now check the classpath entries of project for the output // location just calculated IClasspathEntry[] cpEntry = javaProject.getRawClasspath(); for (int j = 0; j < cpEntry.length; j++) { IClasspathEntry entry = cpEntry[j]; int entryKind = entry.getEntryKind(); IPath entryPath = entry.getPath(); if (entryKind == IClasspathEntry.CPE_LIBRARY && entryPath.equals(outputLocation)) { return true; } } return false; }
From source file:org.eclipse.ant.internal.ui.datatransfer.EclipseClasspath.java
License:Open Source License
private void handleSources(IClasspathEntry entry) throws JavaModelException { String projectRoot = ExportUtil.getProjectRoot(project); String defaultClassDir = project.getOutputLocation().toString(); String defaultClassDirAbsolute = ExportUtil.resolve(project.getOutputLocation()); if (entry.getContentKind() == IPackageFragmentRoot.K_SOURCE && entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { // found source path IPath srcDirPath = entry.getPath(); IPath classDirPath = entry.getOutputLocation(); String srcDir = handleLinkedResource(srcDirPath); ExportUtil.removeProjectRoot((srcDirPath != null) ? srcDirPath.toString() : projectRoot, project.getProject());/*from w w w . j a v a2s . c o m*/ String classDir = ExportUtil.removeProjectRoot( (classDirPath != null) ? classDirPath.toString() : defaultClassDir, project.getProject()); srcDirs.add(srcDir); classDirs.add(classDir); String classDirAbsolute = (classDirPath != null) ? ExportUtil.resolve(classDirPath) : defaultClassDirAbsolute; rawClassPathEntries.add(classDir); rawClassPathEntriesAbsolute.add(classDirAbsolute); IPath[] inclusions = entry.getInclusionPatterns(); List<String> inclusionList = new ArrayList<>(); for (int j = 0; j < inclusions.length; j++) { if (inclusions[j] != null) { inclusionList.add(ExportUtil.removeProjectRoot(inclusions[j].toString(), project.getProject())); } } inclusionLists.add(inclusionList); IPath[] exclusions = entry.getExclusionPatterns(); List<String> exclusionList = new ArrayList<>(); for (int j = 0; j < exclusions.length; j++) { if (exclusions[j] != null) { exclusionList.add(ExportUtil.removeProjectRoot(exclusions[j].toString(), project.getProject())); } } exclusionLists.add(exclusionList); } }
From source file:org.eclipse.ant.internal.ui.datatransfer.EclipseClasspath.java
License:Open Source License
private void handleJars(IClasspathEntry entry) { if (entry.getContentKind() == IPackageFragmentRoot.K_BINARY && entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { String jarFile = entry.getPath().toString(); StringBuffer jarFileBuffer = new StringBuffer(); StringBuffer jarFileAbsoluteBuffer = new StringBuffer(); String jarFileAbsolute = ExportUtil.resolve(entry.getPath()); if (jarFileAbsolute == null) { jarFileAbsolute = jarFile; // jarFile was already absolute if (handleSubProjectClassesDirectory(jarFile, jarFileBuffer, jarFileAbsoluteBuffer)) { jarFile = jarFileBuffer.toString(); jarFileAbsolute = jarFileAbsoluteBuffer.toString(); }//w w w . j a v a 2 s . c o m } String jarFileOld = jarFile; jarFile = ExportUtil.removeProjectRoot(jarFile, project.getProject()); if (jarFile.equals(jarFileOld)) { if (handleSubProjectClassesDirectory(jarFile, jarFileBuffer, jarFileAbsoluteBuffer)) { jarFile = jarFileBuffer.toString(); jarFileAbsolute = jarFileAbsoluteBuffer.toString(); } } rawClassPathEntries.add(jarFile); rawClassPathEntriesAbsolute.add(jarFileAbsolute); } }
From source file:org.eclipse.ant.internal.ui.datatransfer.EclipseClasspath.java
License:Open Source License
private void handleVariables(IClasspathEntry entry) { if (entry.getContentKind() == IPackageFragmentRoot.K_SOURCE && entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { // found variable String e = entry.getPath().toString(); int index = e.indexOf('/'); if (index == -1) { index = e.indexOf('\\'); }//from w ww . j a v a 2s . co m String variable = e; String path = IAntCoreConstants.EMPTY_STRING; if (index != -1) { variable = e.substring(0, index); path = e.substring(index); } IPath value = JavaCore.getClasspathVariable(variable); if (value != null) { String projectRoot = ExportUtil.getProjectRoot(project); String relativePath = ExportUtil.getRelativePath(value.toString(), projectRoot); variable2valueMap.put(variable, relativePath); } else if (variable2valueMap.get(variable) == null) { // only add empty value, if variable is new variable2valueMap.put(variable, IAntCoreConstants.EMPTY_STRING); } rawClassPathEntriesAbsolute.add(value + path); rawClassPathEntries.add("${" + variable + "}" + path); //$NON-NLS-1$ //$NON-NLS-2$ } }
From source file:org.eclipse.ant.internal.ui.datatransfer.EclipseClasspath.java
License:Open Source License
private void handleLibraries(IClasspathEntry entry) throws JavaModelException { if (entry.getContentKind() == IPackageFragmentRoot.K_SOURCE && entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { // found library IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), project); if (container == null) { // jar missing (project not compile clean) return; }/*from w ww . j a va2s.c o m*/ String jar = entry.getPath().toString(); String refName; if (jar.startsWith(JavaRuntime.JRE_CONTAINER)) { // JRE System Library refName = "${jre.container}"; //$NON-NLS-1$ } else if (jar.startsWith(JavaCore.USER_LIBRARY_CONTAINER_ID)) { // User Library String libraryName = container.getDescription(); refName = "${" + libraryName + ".userclasspath}"; //$NON-NLS-1$ //$NON-NLS-2$ if (container.getKind() == IClasspathContainer.K_SYSTEM) { refName = "${" + libraryName + ".bootclasspath}"; //$NON-NLS-1$ //$NON-NLS-2$ } } else { // Library dependencies: e.g. Plug-in Dependencies String libraryName = container.getDescription(); refName = "${" + libraryName + ".libraryclasspath}"; //$NON-NLS-1$ //$NON-NLS-2$ } userLibraryCache.put(refName, container); srcDirs.add(refName); classDirs.add(refName); rawClassPathEntries.add(refName); rawClassPathEntriesAbsolute.add(refName); inclusionLists.add(new ArrayList<String>()); exclusionLists.add(new ArrayList<String>()); } }
From source file:org.eclipse.ant.internal.ui.datatransfer.EclipseClasspath.java
License:Open Source License
private void handleProjects(IClasspathEntry entry) { if (entry.getContentKind() == IPackageFragmentRoot.K_SOURCE && entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { // found required project on build path String subProjectRoot = entry.getPath().toString(); IJavaProject subProject = ExportUtil.getJavaProject(subProjectRoot); if (subProject == null) { // project was not loaded in workspace AntUIPlugin.log("project is not loaded in workspace: " + subProjectRoot, null); //$NON-NLS-1$ return; }/*from www.jav a2 s . c om*/ // only add an indicator that this is a project reference String classpathRef = "${" + subProject.getProject().getName() + ".classpath}"; //$NON-NLS-1$ //$NON-NLS-2$ srcDirs.add(classpathRef); classDirs.add(classpathRef); rawClassPathEntries.add(classpathRef); rawClassPathEntriesAbsolute.add(classpathRef); inclusionLists.add(new ArrayList<String>()); exclusionLists.add(new ArrayList<String>()); } }