@Override public IClasspathEntry[] getClasspathEntries() { try { return project.getResolvedClasspath(true); } catch (JavaModelException e) { throw new RuntimeException(e); } }
/** * Computes and returns a CRC of the projects resolved build path, or -1 if * unknown. * * @param project project * @return build path CRC or -1 */ public static long computeBuildPathCRC(IProject project) { IJavaProject jp = JavaCore.create(project); try { IClasspathEntry[] classpath = jp.getResolvedClasspath(true); CRC32 crc32 = new CRC32(); for (IClasspathEntry entry : classpath) { crc32.update(entry.getPath().toPortableString().getBytes()); } return crc32.getValue(); } catch (JavaModelException e) { ApiPlugin.log("Failed to compute project CRC for " + project, e); //$NON-NLS-1$ } return -1L; } }
private IRuntimeClasspathEntry[] filterUnusedDependencies(ILaunchConfiguration configuration, IRuntimeClasspathEntry[] entriesToFilter) throws CoreException { // if the run configuration uses Java 9 then the library dependencies are already present in the // unresolved classpath. That is because the Java 9 support calculates the class/module path from // the result of IJavaProject.getResolvedClasspath(true). Unfortunately, the runtime entries don't // have the source set attribute, so we have to filter them base on entry paths. IJavaProject project = JavaRuntime.getJavaProject(configuration); IClasspathEntry[] classpath = project.getResolvedClasspath(true); LaunchConfigurationScope configurationScopes = LaunchConfigurationScope.from(configuration); Set<IPath> excludedPaths = Sets.newHashSet(); for (IClasspathEntry entry : classpath) { if (!configurationScopes.isEntryIncluded(entry)) { excludedPaths.add(entry.getPath()); } } List<IRuntimeClasspathEntry> result = new ArrayList<>(entriesToFilter.length); for (IRuntimeClasspathEntry entry : entriesToFilter) { if (!excludedPaths.contains(entry.getPath())) { result.add(entry); } } return result.toArray(new IRuntimeClasspathEntry[0]); }
private String[] getClasspathForJavaProject(IJavaProject javaProject) { ArrayList projectClasspath = new ArrayList(); try { IClasspathEntry[] buildPath = javaProject.getResolvedClasspath(true); for (int i = 0; i < buildPath.length; i++) { String[] buildPathString = classpathEntry2String( buildPath[i], javaProject.getProject()); for (int j = 0; j < buildPathString.length; j++) { projectClasspath.add(buildPathString[j]); } } } catch (JavaModelException jme) { } String[] utilityJarsClasspath; IProject project = javaProject.getProject(); IProject[] referencingProjects = project.getReferencingProjects(); for (int i = 0; i < referencingProjects.length; i++) { utilityJarsClasspath = getUtilityJarClasspath(referencingProjects[i]); for (int j = 0; j < utilityJarsClasspath.length; j++) { projectClasspath.add(utilityJarsClasspath[j]); } } return (String[]) projectClasspath.toArray(new String[projectClasspath.size()]); }
IJavaProject javaProject = JavaCore.create(fProject); if (javaProject.exists()) { IClasspathEntry[] classPathEntries = javaProject.getResolvedClasspath(true);
static private void addRequiredJavaProjectNames(String projectName, Collection projects, boolean exportedOnly) throws Exception { if (projects.contains(projectName)) { return; } projects.add(projectName); IJavaProject javaProject = getJavaProject(projectName); if (javaProject == null) { return; } boolean ignoreUnresolvedEntry = true; IClasspathEntry[] classpathEntries = javaProject.getResolvedClasspath(ignoreUnresolvedEntry); for (int i = 0; i < classpathEntries.length; i++) { switch (classpathEntries[i].getEntryKind()) { case IClasspathEntry.CPE_PROJECT: if (exportedOnly && !classpathEntries[i].isExported()) { continue; } String requiredProjectName = classpathEntries[i].getPath().lastSegment(); boolean exportedOnlyForNonRootProject = true; addRequiredJavaProjectNames(requiredProjectName, projects, exportedOnlyForNonRootProject); break; } } }
private void ensureUpTodate() { if (!fBuildPathIsDirty) { /* * Double-check that the number of build path entries has not * changed. This should cover most cases such as when a library is * added into or removed from a container. */ try { IJavaProject jproject = JavaCore.create(fProject); if (jproject != null && jproject.exists()) { IClasspathEntry[] entries = jproject.getResolvedClasspath(true); fBuildPathIsDirty = (fBuildPathEntryCount != entries.length); } } catch (JavaModelException e) { Logger.logException(e); } } if (fBuildPathIsDirty) { indexClasspath(); fBuildPathIsDirty = false; } }
/** * @param javaProject */ private void indexClasspath(IJavaProject javaProject) { if (javaProject == null) return; IProject project = javaProject.getProject(); if (project.equals(fProject)) { try { IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); fBuildPathEntryCount = entries.length; for (int i = 0; i < entries.length; i++) { indexClasspath(entries[i]); } } catch (JavaModelException e) { Logger.logException("Error searching Java Build Path + (" + fProject.getName() + ") for tag libraries", e); //$NON-NLS-1$ //$NON-NLS-2$ } } }
static private void addJavaLibraries(IJavaProject javaProject, Collection classpath, boolean exportedOnly) throws Exception { // UtilBase util = new UtilBase(); IPath defaultOutputLocation = javaProject.getOutputLocation(); IClasspathEntry[] classpathEntries = javaProject.getResolvedClasspath(true); for (int i = 0; i < classpathEntries.length; i++) { IPath path = null; switch (classpathEntries[i].getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: if (exportedOnly && !classpathEntries[i].isExported()) { continue; } path = classpathEntries[i].getPath(); break; case IClasspathEntry.CPE_SOURCE: path = classpathEntries[i].getOutputLocation(); if (path == null) { path = defaultOutputLocation; } break; } if (path == null) { continue; } String path2 = ResourceUtil.toCanonicalUrl(javaProject.getProject(), path); if (!classpath.contains(path2)) { classpath.add(path2); } } }
private static IClasspathEntry getReferencingClassPathEntry(IJavaProject referencingProject, IJavaProject referencedProject) throws JavaModelException { IClasspathEntry result = null; IPath path = referencedProject.getProject().getFullPath(); IClasspathEntry[] classpath = referencingProject.getResolvedClasspath(true); for (int i = 0; i < classpath.length; i++) { IClasspathEntry entry = classpath[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT && path.equals(entry.getPath())) { if (entry.isExported()) { return entry; } // Consider it as a candidate. May be there is another entry that is // exported. result = entry; } } return result; }
private static IClasspathEntry getReferencingClassPathEntry(IJavaProject referencingProject, IJavaProject referencedProject) throws JavaModelException { IClasspathEntry result= null; IPath path= referencedProject.getProject().getFullPath(); IClasspathEntry[] classpath= referencingProject.getResolvedClasspath(true); for (int i= 0; i < classpath.length; i++) { IClasspathEntry entry= classpath[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT && path.equals(entry.getPath())) { if (entry.isExported()) return entry; // Consider it as a candidate. May be there is another entry that is // exported. result= entry; } } return result; }
private static IClasspathEntry getReferencingClassPathEntry(IJavaProject referencingProject, IJavaProject referencedProject) throws JavaModelException { IClasspathEntry result= null; IPath path= referencedProject.getProject().getFullPath(); IClasspathEntry[] classpath= referencingProject.getResolvedClasspath(true); for (int i= 0; i < classpath.length; i++) { IClasspathEntry entry= classpath[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT && path.equals(entry.getPath())) { if (entry.isExported()) return entry; // Consider it as a candidate. May be there is another entry that is // exported. result= entry; } } return result; }
private static IClasspathEntry getReferencingClassPathEntry(IJavaProject referencingProject, IJavaProject referencedProject) throws JavaModelException { IClasspathEntry result= null; IPath path= referencedProject.getProject().getFullPath(); IClasspathEntry[] classpath= referencingProject.getResolvedClasspath(true); for (int i= 0; i < classpath.length; i++) { IClasspathEntry entry= classpath[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT && path.equals(entry.getPath())) { if (entry.isExported()) return entry; // Consider it as a candidate. May be there is another entry that is // exported. result= entry; } } return result; }
private boolean isTestSource(IJavaProject project, ICompilationUnit cu) { try { IClasspathEntry[] resolvedClasspath= project.getResolvedClasspath(true); final IPath resourcePath= cu.getResource().getFullPath(); for (IClasspathEntry e : resolvedClasspath) { if (e.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (e.isTest()) { if (e.getPath().isPrefixOf(resourcePath)) { return true; } } } } } catch (JavaModelException e) { return false; } return false; }
private boolean isTestSource(IJavaProject project, ICompilationUnit cu) { if (project == null) { return true; } try { IClasspathEntry[] resolvedClasspath = project.getResolvedClasspath(true); final IPath resourcePath = cu.getResource().getFullPath(); for (IClasspathEntry e : resolvedClasspath) { if (e.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (e.isTest()) { if (e.getPath().isPrefixOf(resourcePath)) { return true; } } } } } catch (JavaModelException e) { } return false; }
private static boolean isTestSource(ICompilationUnit cu) { try { IJavaProject javaProject = cu.getJavaProject(); if (javaProject == null) { return false; } IClasspathEntry[] resolvedClasspath = javaProject.getResolvedClasspath(true); final IPath resourcePath = cu.getResource().getFullPath(); for (IClasspathEntry e : resolvedClasspath) { if (e.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (e.isTest()) { if (e.getPath().isPrefixOf(resourcePath)) { return true; } } } } } catch (JavaModelException e) { return false; } return false; }
private static boolean isTestSource(ICompilationUnit cu) { try { IJavaProject javaProject= cu.getJavaProject(); if(javaProject==null) { return false; } IClasspathEntry[] resolvedClasspath= javaProject.getResolvedClasspath(true); final IPath resourcePath= cu.getResource().getFullPath(); for (IClasspathEntry e : resolvedClasspath) { if (e.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (e.isTest()) { if (e.getPath().isPrefixOf(resourcePath)) { return true; } } } } } catch (JavaModelException e) { return false; } return false; }
private static boolean isTestSource(IJavaProject project, ICompilationUnit cu) { try { IClasspathEntry[] resolvedClasspath = project.getResolvedClasspath(true); final IPath resourcePath = cu.getResource().getFullPath(); for (IClasspathEntry e : resolvedClasspath) { if (e.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (e.isTest()) { if (e.getPath().isPrefixOf(resourcePath)) { return true; } } } } } catch (JavaModelException e) { Util.log(e, "Exception while determining if compilation unit \"" + cu.getElementName() //$NON-NLS-1$ + "\" is test source"); //$NON-NLS-1$ } return false; }
try { IClasspathEntry[] classpathEntries = jProject .getResolvedClasspath(false); for (int i = 0; i < classpathEntries.length; i++) { IClasspathEntry cpEntry = classpathEntries[i];
protected boolean containsDebugFiles(IJavaProject project) { try { IClasspathEntry[] entries = project.getResolvedClasspath(true); if (entries != null) { for (IClasspathEntry entry : entries) { if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath projectPath = project.getPath(); IPath relativePath = entry.getPath().makeRelativeTo(projectPath); IFolder folder = project.getProject().getFolder(relativePath); if (getFile(folder, ".profile.d", "ngrok.sh") != null) {//$NON-NLS-1$ //$NON-NLS-2$ return true; } } } } } catch (JavaModelException e) { CloudFoundryPlugin.logError(e); } catch (CoreException ce) { CloudFoundryPlugin.logError(ce); } return false; }