List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_LIBRARY
int CPE_LIBRARY
To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_LIBRARY.
Click Source Link
From source file:com.android.ide.eclipse.editors.resources.manager.ProjectClassLoader.java
License:Open Source License
/** * Returns an array of external jar files used by the project. * @return an array of OS-specific absolute file paths *//* w ww .j a v a2 s . com*/ private final URL[] getExternalJars() { // get a java project from it IJavaProject javaProject = JavaCore.create(mJavaProject.getProject()); IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); ArrayList<URL> oslibraryList = new ArrayList<URL>(); IClasspathEntry[] classpaths = javaProject.readRawClasspath(); if (classpaths != null) { for (IClasspathEntry e : classpaths) { if (e.getEntryKind() == IClasspathEntry.CPE_LIBRARY || e.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { // if this is a classpath variable reference, we resolve it. if (e.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { e = JavaCore.getResolvedClasspathEntry(e); } // get the IPath IPath path = e.getPath(); // check the name ends with .jar if (AndroidConstants.EXT_JAR.equalsIgnoreCase(path.getFileExtension())) { boolean local = false; IResource resource = wsRoot.findMember(path); if (resource != null && resource.exists() && resource.getType() == IResource.FILE) { local = true; try { oslibraryList.add(new File(resource.getLocation().toOSString()).toURL()); } catch (MalformedURLException mue) { // pass } } if (local == false) { // if the jar path doesn't match a workspace resource, // then we get an OSString and check if this links to a valid file. String osFullPath = path.toOSString(); File f = new File(osFullPath); if (f.exists()) { try { oslibraryList.add(f.toURL()); } catch (MalformedURLException mue) { // pass } } } } } } } return oslibraryList.toArray(new URL[oslibraryList.size()]); }
From source file:com.annotatedsql.classlibrary.ClassPathContainerPage.java
License:Open Source License
public void initialize(IJavaProject project, IClasspathEntry[] currentEntries) { for (int i = 0; i < currentEntries.length; i++) { IClasspathEntry curr = currentEntries[i]; if (curr.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { fUsedPaths.add(curr.getPath()); }/*from w ww .jav a2s .c o m*/ } }
From source file:com.cisco.yangide.core.model.YangProject.java
License:Open Source License
@Override protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map<IOpenable, OpenableElementInfo> newElements, IResource underlyingResource) throws YangModelException { final HashSet<IResource> resources = new HashSet<IResource>(); final HashSet<IPath> externalJarsPath = new HashSet<IPath>(); IJavaProject javaProject = JavaCore.create(project); try {/* w w w. java2 s . c om*/ project.accept(new IResourceVisitor() { @Override public boolean visit(IResource resource) throws CoreException { if (CoreUtil.isYangLikeFileName(resource.getName())) { resources.add(resource.getParent()); } return true; } }); if (javaProject.isOpen()) { IClasspathEntry[] classpath = javaProject.getResolvedClasspath(true); for (int i = 0, length = classpath.length; i < length; i++) { IClasspathEntry entry = classpath[i]; IPath entryPath = entry.getPath(); if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { externalJarsPath.add(entryPath); } } } } catch (CoreException e) { throw new YangModelException(e); } ArrayList<IOpenable> result = new ArrayList<IOpenable>(); for (IResource resource : resources) { if (resource.getType() == IResource.FOLDER) { result.add(new YangFolder(resource, this)); } } for (IPath iPath : externalJarsPath) { try (JarFile jarFile = new JarFile(iPath.toFile())) { ZipEntry entry = jarFile.getEntry("META-INF/yang/"); if (entry != null) { result.add(new YangJarFile(iPath, this)); } } catch (IOException e) { YangCorePlugin.log(e); } } info.setChildren(result.toArray(new IOpenable[result.size()])); return javaProject.isOpen(); }
From source file:com.codenvy.ide.ext.java.server.internal.core.ClasspathEntry.java
License:Open Source License
/** * Returns the kind of a <code>PackageFragmentRoot</code> from its <code>String</code> form. *///from w w w . ja v a 2 s . c o m static int kindFromString(String kindStr) { if (kindStr.equalsIgnoreCase("prj")) //$NON-NLS-1$ return IClasspathEntry.CPE_PROJECT; if (kindStr.equalsIgnoreCase("var")) //$NON-NLS-1$ return IClasspathEntry.CPE_VARIABLE; if (kindStr.equalsIgnoreCase("con")) //$NON-NLS-1$ return IClasspathEntry.CPE_CONTAINER; if (kindStr.equalsIgnoreCase("src")) //$NON-NLS-1$ return IClasspathEntry.CPE_SOURCE; if (kindStr.equalsIgnoreCase("lib")) //$NON-NLS-1$ return IClasspathEntry.CPE_LIBRARY; if (kindStr.equalsIgnoreCase("output")) //$NON-NLS-1$ return ClasspathEntry.K_OUTPUT; return -1; }
From source file:com.codenvy.ide.ext.java.server.internal.core.ClasspathEntry.java
License:Open Source License
/** * Returns a <code>String</code> for the kind of a class path entry. *//*from w ww . j av a2s . co m*/ static String kindToString(int kind) { switch (kind) { case IClasspathEntry.CPE_PROJECT: return "src"; // backward compatibility //$NON-NLS-1$ case IClasspathEntry.CPE_SOURCE: return "src"; //$NON-NLS-1$ case IClasspathEntry.CPE_LIBRARY: return "lib"; //$NON-NLS-1$ case IClasspathEntry.CPE_VARIABLE: return "var"; //$NON-NLS-1$ case IClasspathEntry.CPE_CONTAINER: return "con"; //$NON-NLS-1$ case ClasspathEntry.K_OUTPUT: return "output"; //$NON-NLS-1$ default: return "unknown"; //$NON-NLS-1$ } }
From source file:com.codenvy.ide.ext.java.server.internal.core.ClasspathEntry.java
License:Open Source License
/** * Returns a printable representation of this classpath entry. *//*w w w. ja v a2 s . c om*/ public String toString() { StringBuffer buffer = new StringBuffer(); Object target = JavaModel.getTarget(getPath(), true); if (target instanceof File) buffer.append(getPath().toOSString()); else buffer.append(String.valueOf(getPath())); buffer.append('['); switch (getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: buffer.append("CPE_LIBRARY"); //$NON-NLS-1$ break; case IClasspathEntry.CPE_PROJECT: buffer.append("CPE_PROJECT"); //$NON-NLS-1$ break; case IClasspathEntry.CPE_SOURCE: buffer.append("CPE_SOURCE"); //$NON-NLS-1$ break; case IClasspathEntry.CPE_VARIABLE: buffer.append("CPE_VARIABLE"); //$NON-NLS-1$ break; case IClasspathEntry.CPE_CONTAINER: buffer.append("CPE_CONTAINER"); //$NON-NLS-1$ break; } buffer.append("]["); //$NON-NLS-1$ switch (getContentKind()) { case IPackageFragmentRoot.K_BINARY: buffer.append("K_BINARY"); //$NON-NLS-1$ break; case IPackageFragmentRoot.K_SOURCE: buffer.append("K_SOURCE"); //$NON-NLS-1$ break; case ClasspathEntry.K_OUTPUT: buffer.append("K_OUTPUT"); //$NON-NLS-1$ break; } buffer.append(']'); if (getSourceAttachmentPath() != null) { buffer.append("[sourcePath:"); //$NON-NLS-1$ buffer.append(getSourceAttachmentPath()); buffer.append(']'); } if (getSourceAttachmentRootPath() != null) { buffer.append("[rootPath:"); //$NON-NLS-1$ buffer.append(getSourceAttachmentRootPath()); buffer.append(']'); } buffer.append("[isExported:"); //$NON-NLS-1$ buffer.append(this.isExported); buffer.append(']'); IPath[] patterns = this.inclusionPatterns; int length; if ((length = patterns == null ? 0 : patterns.length) > 0) { buffer.append("[including:"); //$NON-NLS-1$ for (int i = 0; i < length; i++) { buffer.append(patterns[i]); if (i != length - 1) { buffer.append('|'); } } buffer.append(']'); } patterns = this.exclusionPatterns; if ((length = patterns == null ? 0 : patterns.length) > 0) { buffer.append("[excluding:"); //$NON-NLS-1$ for (int i = 0; i < length; i++) { buffer.append(patterns[i]); if (i != length - 1) { buffer.append('|'); } } buffer.append(']'); } if (this.accessRuleSet != null) { buffer.append('['); buffer.append(this.accessRuleSet.toString(false/*on one line*/)); buffer.append(']'); } if (this.entryKind == CPE_PROJECT) { buffer.append("[combine access rules:"); //$NON-NLS-1$ buffer.append(this.combineAccessRules); buffer.append(']'); } if (getOutputLocation() != null) { buffer.append("[output:"); //$NON-NLS-1$ buffer.append(getOutputLocation()); buffer.append(']'); } if ((length = this.extraAttributes == null ? 0 : this.extraAttributes.length) > 0) { buffer.append("[attributes:"); //$NON-NLS-1$ for (int i = 0; i < length; i++) { buffer.append(this.extraAttributes[i]); if (i != length - 1) { buffer.append(','); } } buffer.append(']'); } return buffer.toString(); }
From source file:com.codenvy.ide.ext.java.server.internal.core.ClasspathEntry.java
License:Open Source License
/** * Answers an ID which is used to distinguish entries during package * fragment root computations/*from www. jav a 2 s . com*/ */ public String rootID() { if (this.rootID == null) { switch (this.entryKind) { case IClasspathEntry.CPE_LIBRARY: this.rootID = "[LIB]" + this.path; //$NON-NLS-1$ break; case IClasspathEntry.CPE_PROJECT: this.rootID = "[PRJ]" + this.path; //$NON-NLS-1$ break; case IClasspathEntry.CPE_SOURCE: this.rootID = "[SRC]" + this.path; //$NON-NLS-1$ break; case IClasspathEntry.CPE_VARIABLE: this.rootID = "[VAR]" + this.path; //$NON-NLS-1$ break; case IClasspathEntry.CPE_CONTAINER: this.rootID = "[CON]" + this.path; //$NON-NLS-1$ break; default: this.rootID = ""; //$NON-NLS-1$ break; } } return this.rootID; }
From source file:com.codenvy.ide.ext.java.server.internal.core.ClasspathEntry.java
License:Open Source License
/** * This function computes the URL of the index location for this classpath entry. It returns null if the URL is * invalid./*from www . ja v a 2s .c o m*/ */ public URL getLibraryIndexLocation() { switch (getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_VARIABLE: break; default: return null; } if (this.extraAttributes == null) return null; for (int i = 0; i < this.extraAttributes.length; i++) { IClasspathAttribute attrib = this.extraAttributes[i]; if (IClasspathAttribute.INDEX_LOCATION_ATTRIBUTE_NAME.equals(attrib.getName())) { String value = attrib.getValue(); try { return new URL(value); } catch (MalformedURLException e) { return null; } } } return null; }
From source file:com.codenvy.ide.ext.java.server.internal.core.DeltaProcessingState.java
License:Open Source License
private HashMap[] getRootInfos(boolean usePreviousSession) { HashMap newRoots = new HashMap(); HashMap newOtherRoots = new HashMap(); HashMap newSourceAttachments = new HashMap(); HashMap newProjectDependencies = new HashMap(); IJavaModel model = manager.getJavaModel(); IJavaProject[] projects;/*from w w w. j av a 2 s. co m*/ try { projects = model.getJavaProjects(); } catch (JavaModelException e) { // nothing can be done return null; } for (int i = 0, length = projects.length; i < length; i++) { JavaProject project = (JavaProject) projects[i]; IClasspathEntry[] classpath; try { // if (usePreviousSession) { // PerProjectInfo perProjectInfo = project.getPerProjectInfo(); // project.resolveClasspath(perProjectInfo, true/*use previous session values*/, false/*don't add classpath change*/); // classpath = perProjectInfo.resolvedClasspath; // } else { classpath = project.getResolvedClasspath(); // } } catch (JavaModelException e) { // continue with next project continue; } for (int j = 0, classpathLength = classpath.length; j < classpathLength; j++) { IClasspathEntry entry = classpath[j]; if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IJavaProject key = model.getJavaProject(entry.getPath().segment(0)); // TODO (jerome) reuse handle IJavaProject[] dependents = (IJavaProject[]) newProjectDependencies.get(key); if (dependents == null) { dependents = new IJavaProject[] { project }; } else { int dependentsLength = dependents.length; System.arraycopy(dependents, 0, dependents = new IJavaProject[dependentsLength + 1], 0, dependentsLength); dependents[dependentsLength] = project; } newProjectDependencies.put(key, dependents); continue; } // root path IPath path = entry.getPath(); if (newRoots.get(path) == null) { newRoots.put(path, new DeltaProcessor.RootInfo(project, path, ((ClasspathEntry) entry).fullInclusionPatternChars(), ((ClasspathEntry) entry).fullExclusionPatternChars(), entry.getEntryKind())); } else { ArrayList rootList = (ArrayList) newOtherRoots.get(path); if (rootList == null) { rootList = new ArrayList(); newOtherRoots.put(path, rootList); } rootList.add(new DeltaProcessor.RootInfo(project, path, ((ClasspathEntry) entry).fullInclusionPatternChars(), ((ClasspathEntry) entry).fullExclusionPatternChars(), entry.getEntryKind())); } // source attachment path if (entry.getEntryKind() != IClasspathEntry.CPE_LIBRARY) continue; String propertyString = null; // try { // propertyString = Util.getSourceAttachmentProperty(path); // } catch (JavaModelException e) { // e.printStackTrace(); // } IPath sourceAttachmentPath; if (propertyString != null) { int index = propertyString.lastIndexOf(PackageFragmentRoot.ATTACHMENT_PROPERTY_DELIMITER); sourceAttachmentPath = (index < 0) ? new Path(propertyString) : new Path(propertyString.substring(0, index)); } else { sourceAttachmentPath = entry.getSourceAttachmentPath(); } if (sourceAttachmentPath != null) { newSourceAttachments.put(sourceAttachmentPath, path); } } } return new HashMap[] { newRoots, newOtherRoots, newSourceAttachments, newProjectDependencies }; }
From source file:com.codenvy.ide.ext.java.server.internal.core.DeltaProcessor.java
License:Open Source License
private boolean createExternalArchiveDelta(HashSet refreshedElements, IProgressMonitor monitor) { HashMap externalArchivesStatus = new HashMap(); boolean hasDelta = false; // find JARs to refresh HashSet archivePathsToRefresh = new HashSet(); Iterator iterator = refreshedElements.iterator(); while (iterator.hasNext()) { IJavaElement element = (IJavaElement) iterator.next(); switch (element.getElementType()) { case IJavaElement.PACKAGE_FRAGMENT_ROOT: archivePathsToRefresh.add(element.getPath()); break; case IJavaElement.JAVA_PROJECT: JavaProject javaProject = (JavaProject) element; if (!JavaProject.hasJavaNature(javaProject.getProject())) { // project is not accessible or has lost its Java nature break; }//from w w w. j a va 2s. c o m IClasspathEntry[] classpath; try { classpath = javaProject.getResolvedClasspath(); for (int j = 0, cpLength = classpath.length; j < cpLength; j++) { if (classpath[j].getEntryKind() == IClasspathEntry.CPE_LIBRARY) { archivePathsToRefresh.add(classpath[j].getPath()); } } } catch (JavaModelException e) { // project doesn't exist -> ignore } break; case IJavaElement.JAVA_MODEL: // Iterator projectNames = this.state.getOldJavaProjecNames().iterator(); // while (projectNames.hasNext()) { // String projectName = (String) projectNames.next(); // IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); // if (!JavaProject.hasJavaNature(project)) { // // project is not accessible or has lost its Java nature // continue; // } // javaProject = (JavaProject) JavaCore.create(project); // try { // classpath = javaProject.getResolvedClasspath(); // for (int k = 0, cpLength = classpath.length; k < cpLength; k++){ // if (classpath[k].getEntryKind() == IClasspathEntry.CPE_LIBRARY){ // archivePathsToRefresh.add(classpath[k].getPath()); // } // } // } catch (JavaModelException e2) { // // project doesn't exist -> ignore // continue; // } // } throw new UnsupportedOperationException(); // break; } } // // perform refresh // Iterator projectNames = this.state.getOldJavaProjecNames().iterator(); // IWorkspaceRoot wksRoot = ResourcesPlugin.getWorkspace().getRoot(); // while (projectNames.hasNext()) { // // if (monitor != null && monitor.isCanceled()) break; // // String projectName = (String) projectNames.next(); // IProject project = wksRoot.getProject(projectName); // if (!JavaProject.hasJavaNature(project)) { // // project is not accessible or has lost its Java nature // continue; // } // JavaProject javaProject = (JavaProject) JavaCore.create(project); // IClasspathEntry[] entries; // try { // entries = javaProject.getResolvedClasspath(); // } catch (JavaModelException e1) { // // project does not exist -> ignore // continue; // } // boolean deltaContainsModifiedJar = false; // for (int j = 0; j < entries.length; j++){ // if (entries[j].getEntryKind() == IClasspathEntry.CPE_LIBRARY) { // IPath entryPath = entries[j].getPath(); // // if (!archivePathsToRefresh.contains(entryPath)) continue; // not supposed to be refreshed // // String status = (String)externalArchivesStatus.get(entryPath); // if (status == null){ // // // Clear the external file state for this path, since this method is responsible for updating it. // this.manager.clearExternalFileState(entryPath); // // // compute shared status // Object targetLibrary = JavaModel.getTarget(entryPath, true); // // if (targetLibrary == null){ // missing JAR // if (this.state.getExternalLibTimeStamps().remove(entryPath) != null /* file was known*/ // && this.state.roots.get(entryPath) != null /* and it was on the classpath*/) { // externalArchivesStatus.put(entryPath, EXTERNAL_JAR_REMOVED); // // the jar was physically removed: remove the index // this.manager.indexManager.removeIndex(entryPath); // } // // } else if (targetLibrary instanceof File){ // external JAR // // File externalFile = (File)targetLibrary; // // // check timestamp to figure if JAR has changed in some way // Long oldTimestamp =(Long) this.state.getExternalLibTimeStamps().get(entryPath); // long newTimeStamp = getTimeStamp(externalFile); // if (oldTimestamp != null){ // // if (newTimeStamp == 0){ // file doesn't exist // externalArchivesStatus.put(entryPath, EXTERNAL_JAR_REMOVED); // this.state.getExternalLibTimeStamps().remove(entryPath); // // remove the index // this.manager.indexManager.removeIndex(entryPath); // // } else if (oldTimestamp.longValue() != newTimeStamp){ // externalArchivesStatus.put(entryPath, EXTERNAL_JAR_CHANGED); // this.state.getExternalLibTimeStamps().put(entryPath, new Long(newTimeStamp)); // // first remove the index so that it is forced to be re-indexed // this.manager.indexManager.removeIndex(entryPath); // // then index the jar // this.manager.indexManager.indexLibrary(entryPath, project.getProject(), ((ClasspathEntry)entries[j]).getLibraryIndexLocation(), true); // } else { // URL indexLocation = ((ClasspathEntry)entries[j]).getLibraryIndexLocation(); // if (indexLocation != null) { // force reindexing, this could be faster rather than maintaining the list // this.manager.indexManager.indexLibrary(entryPath, project.getProject(), indexLocation); // } // externalArchivesStatus.put(entryPath, EXTERNAL_JAR_UNCHANGED); // } // } else { // if (newTimeStamp == 0){ // jar still doesn't exist // externalArchivesStatus.put(entryPath, EXTERNAL_JAR_UNCHANGED); // } else { // externalArchivesStatus.put(entryPath, EXTERNAL_JAR_ADDED); // this.state.getExternalLibTimeStamps().put(entryPath, new Long(newTimeStamp)); // // index the new jar // this.manager.indexManager.removeIndex(entryPath); // this.manager.indexManager.indexLibrary(entryPath, project.getProject(), ((ClasspathEntry)entries[j]).getLibraryIndexLocation()); // } // } // } else { // internal JAR // externalArchivesStatus.put(entryPath, INTERNAL_JAR_IGNORE); // } // } // // according to computed status, generate a delta // status = (String)externalArchivesStatus.get(entryPath); // if (status != null){ // if (status == EXTERNAL_JAR_ADDED){ // PackageFragmentRoot root = (PackageFragmentRoot) javaProject.getPackageFragmentRoot(entryPath.toString()); // if (VERBOSE){ // System.out.println("- External JAR ADDED, affecting root: "+root.getElementName()); //$NON-NLS-1$ // } // elementAdded(root, null, null); // deltaContainsModifiedJar = true; // this.state.addClasspathValidation(javaProject); // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=185733 // hasDelta = true; // } else if (status == EXTERNAL_JAR_CHANGED) { // PackageFragmentRoot root = (PackageFragmentRoot) javaProject.getPackageFragmentRoot(entryPath.toString()); // if (VERBOSE){ // System.out.println("- External JAR CHANGED, affecting root: "+root.getElementName()); //$NON-NLS-1$ // } // contentChanged(root); // deltaContainsModifiedJar = true; // hasDelta = true; // } else if (status == EXTERNAL_JAR_REMOVED) { // PackageFragmentRoot root = (PackageFragmentRoot) javaProject.getPackageFragmentRoot(entryPath.toString()); // if (VERBOSE){ // System.out.println("- External JAR REMOVED, affecting root: "+root.getElementName()); //$NON-NLS-1$ // } // elementRemoved(root, null, null); // deltaContainsModifiedJar = true; // this.state.addClasspathValidation(javaProject); // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=185733 // hasDelta = true; // } // } // } // } // // if (deltaContainsModifiedJar) { // javaProject.resetResolvedClasspath(); // } // } // // if (hasDelta){ // // flush jar type cache // JavaModelManager.getJavaModelManager().resetJarTypeCache(); // } return hasDelta; }