List of usage examples for org.eclipse.jdt.core IClasspathEntry isExported
boolean isExported();
From source file:org.eclipse.buckminster.jdt.internal.ClasspathEmitter.java
License:Open Source License
private static void appendPaths(IJavaModel model, IProject project, String target, List<IPath> path, HashSet<IPath> seenPaths, HashSet<String> seenProjects, boolean atTop) throws CoreException { Logger log = Buckminster.getLogger(); String projectName = project.getName(); if (seenProjects.contains(projectName)) return;//from w ww. j av a2 s. com seenProjects.add(projectName); log.debug("Emitting classpath for project %s...", projectName); //$NON-NLS-1$ IJavaProject javaProject = model.getJavaProject(projectName); IClasspathEntry[] entries; if (javaProject == null || !javaProject.exists()) { // The project may still be a component that exports jar files. // BMClasspathContainer container = new BMClasspathContainer(project, target); entries = container.getClasspathEntries(); log.debug(" not a java project, contains %d entries", Integer.valueOf(entries.length)); //$NON-NLS-1$ } else { entries = (atTop && target != null) ? changeClasspathForTarget(javaProject, target) : javaProject.getResolvedClasspath(false); log.debug(" java project, contains %d entries", Integer.valueOf(entries.length)); //$NON-NLS-1$ } for (IClasspathEntry entry : entries) { IPath entryPath; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: log.debug(" found library with path: %s", entry.getPath()); //$NON-NLS-1$ if (!(atTop || entry.isExported())) { log.debug(" skipping path %s. It's neither at top nor exported", entry.getPath()); //$NON-NLS-1$ continue; } entryPath = entry.getPath(); break; case IClasspathEntry.CPE_SOURCE: entryPath = entry.getOutputLocation(); if (entryPath == null) { // Uses default output location // IJavaProject proj = model.getJavaProject(entry.getPath().segment(0)); if (proj == null) continue; entryPath = proj.getOutputLocation(); } log.debug(" found source with path: %s", entryPath); //$NON-NLS-1$ break; case IClasspathEntry.CPE_PROJECT: projectName = entry.getPath().segment(0); log.debug(" found project: %s", projectName); //$NON-NLS-1$ if (!(atTop || entry.isExported())) { log.debug(" skipping project %s. It's neither at top nor exported", projectName); //$NON-NLS-1$ continue; } IProject conProject = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); appendPaths(model, conProject, null, path, seenPaths, seenProjects, false); continue; default: throw BuckminsterException.fromMessage(Messages.unexpected_classpath_entry_kind); } IResource folder = ResourcesPlugin.getWorkspace().getRoot().findMember(entryPath); if (folder != null) { log.debug(" path %s is inside workspace, switching to %s", entryPath, folder.getLocation()); //$NON-NLS-1$ entryPath = folder.getLocation(); } if (!seenPaths.contains(entryPath)) { seenPaths.add(entryPath); path.add(entryPath); log.debug(" path %s added", entryPath); //$NON-NLS-1$ } } }
From source file:org.eclipse.buildship.core.workspace.internal.GradleClasspathContainerRuntimeClasspathEntryResolver.java
License:Open Source License
private void collectContainerRuntimeClasspath(IClasspathContainer container, List<IRuntimeClasspathEntry> result, boolean includeExportedEntriesOnly, LaunchConfigurationScope configurationScopes) throws CoreException { for (final IClasspathEntry cpe : container.getClasspathEntries()) { if (!includeExportedEntriesOnly || cpe.isExported()) { if (cpe.getEntryKind() == IClasspathEntry.CPE_LIBRARY && configurationScopes.isEntryIncluded(cpe)) { result.add(JavaRuntime.newArchiveRuntimeClasspathEntry(cpe.getPath())); } else if (cpe.getEntryKind() == IClasspathEntry.CPE_PROJECT) { Optional<IProject> candidate = findAccessibleJavaProject(cpe.getPath().segment(0)); if (candidate.isPresent()) { IJavaProject dependencyProject = JavaCore.create(candidate.get()); IRuntimeClasspathEntry projectRuntimeEntry = JavaRuntime .newProjectRuntimeClasspathEntry(dependencyProject); // add the project entry itself so that the source lookup can find the classes // see https://github.com/eclipse/buildship/issues/383 result.add(projectRuntimeEntry); Collections.addAll(result, JavaRuntime.resolveRuntimeClasspathEntry(projectRuntimeEntry, dependencyProject)); collectContainerRuntimeClasspathIfPresent(dependencyProject, result, true, configurationScopes); }/* www . j av a2 s .co m*/ } } } }
From source file:org.eclipse.buildship.core.workspace.internal.GradleClasspathContainerUpdater.java
License:Open Source License
private ImmutableList<IClasspathEntry> collectClasspathContainerEntries() { List<IClasspathEntry> externalDependencies = collectExternalDependencies(); List<IClasspathEntry> projectDependencies = collectProjectDependencies(); boolean hasExportedEntry = FluentIterable.from(externalDependencies) .anyMatch(new Predicate<IClasspathEntry>() { @Override//from w w w . j av a 2 s.c om public boolean apply(IClasspathEntry entry) { return entry.isExported(); } }); // Gradle distributions <2.5 rely on exports to define the project classpath. Unfortunately // that logic is broken if dependency excludes are defined in the build scripts. To work // around that, external dependencies must be defined before project dependencies. For more // details, visit Bug 473348. if (hasExportedEntry) { return ImmutableList.<IClasspathEntry>builder().addAll(externalDependencies).addAll(projectDependencies) .build(); } else { return ImmutableList.<IClasspathEntry>builder().addAll(projectDependencies).addAll(externalDependencies) .build(); } }
From source file:org.eclipse.buildship.core.workspace.internal.WtpClasspathUpdater.java
License:Open Source License
private static void replaceGradleClasspathContainerAttribute(IJavaProject project, String plusKey, String plusValue, String minusKey, SubMonitor progress) throws JavaModelException { IClasspathEntry[] oldClasspath = project.getRawClasspath(); IClasspathEntry[] newClasspath = new IClasspathEntry[oldClasspath.length]; for (int i = 0; i < oldClasspath.length; i++) { IClasspathEntry entry = oldClasspath[i]; if (isGradleClasspathContainer(entry)) { IClasspathAttribute[] attributes = replaceClasspathAttribute(entry.getExtraAttributes(), plusKey, plusValue, minusKey); newClasspath[i] = JavaCore.newContainerEntry(entry.getPath(), entry.getAccessRules(), attributes, entry.isExported()); } else {// www . j av a 2s .co m newClasspath[i] = entry; } } project.setRawClasspath(newClasspath, progress); }
From source file:org.eclipse.buildship.wtp.core.configurator.WebApplicationConfigurator.java
License:Open Source License
/** * TODO: Refactor this and markAsNonDeployable. * TODO: Test to ensure duplicate attributes aren't allowed. *///from ww w . j ava 2 s . c om private IClasspathEntry markAsDeployable(IClasspathEntry entry) { IClasspathAttribute newAttribute = JavaCore.newClasspathAttribute( IClasspathDependencyConstants.CLASSPATH_COMPONENT_DEPENDENCY, "/WEB-INF/lib"); if (Arrays.asList(entry.getExtraAttributes()).contains(newAttribute)) { return entry; } List<IClasspathAttribute> gradleContainerAttributes = new ArrayList<IClasspathAttribute>( Arrays.asList(entry.getExtraAttributes())); gradleContainerAttributes.add(newAttribute); return JavaCore.newContainerEntry(entry.getPath(), entry.getAccessRules(), gradleContainerAttributes.toArray(new IClasspathAttribute[gradleContainerAttributes.size()]), entry.isExported()); }
From source file:org.eclipse.buildship.wtp.core.configurator.WebApplicationConfigurator.java
License:Open Source License
private IClasspathEntry markAsNonDeployable(IClasspathEntry entry) { IClasspathAttribute newAttribute = JavaCore.newClasspathAttribute( IClasspathDependencyConstants.CLASSPATH_COMPONENT_NON_DEPENDENCY, "/WEB-INF/lib"); if (Arrays.asList(entry.getExtraAttributes()).contains(newAttribute)) { return entry; }/* w w w . j av a 2 s .c o m*/ List<IClasspathAttribute> gradleContainerAttributes = new ArrayList<IClasspathAttribute>( Arrays.asList(entry.getExtraAttributes())); gradleContainerAttributes.add(newAttribute); return JavaCore.newContainerEntry(entry.getPath(), entry.getAccessRules(), gradleContainerAttributes.toArray(new IClasspathAttribute[gradleContainerAttributes.size()]), entry.isExported()); }
From source file:org.eclipse.che.jdt.internal.core.JavaProject.java
License:Open Source License
/** * Returns the package fragment roots identified by the given entry. In case it refers to * a project, it will follow its classpath so as to find exported roots as well. * Only works with resolved entry/* w ww . j a v a2 s . c o m*/ * * @param resolvedEntry * IClasspathEntry * @param accumulatedRoots * ObjectVector * @param rootIDs * HashSet * @param referringEntry * the CP entry (project) referring to this entry, or null if initial project * @param retrieveExportedRoots * boolean * @throws JavaModelException */ public void computePackageFragmentRoots(IClasspathEntry resolvedEntry, ObjectVector accumulatedRoots, HashSet rootIDs, IClasspathEntry referringEntry, boolean retrieveExportedRoots, Map rootToResolvedEntries) throws JavaModelException { String rootID = ((ClasspathEntry) resolvedEntry).rootID(); if (rootIDs.contains(rootID)) return; IPath projectPath = this.getFullPath(); IPath entryPath = resolvedEntry.getPath(); // IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IPackageFragmentRoot root = null; switch (resolvedEntry.getEntryKind()) { // source folder case IClasspathEntry.CPE_SOURCE: // if (projectPath.isPrefixOf(entryPath)) { Object target1 = JavaModelManager.getTarget(entryPath, true/*check existency*/); if (target1 == null) return; if (target1 instanceof File && ((File) target1).isDirectory()) { root = getPackageFragmentRoot((File) target1); } // } break; // internal/external JAR or folder case IClasspathEntry.CPE_LIBRARY: if (referringEntry != null && !resolvedEntry.isExported()) return; Object target = JavaModelManager.getTarget(entryPath, true/*check existency*/); if (target == null) return; // if (target instanceof IResource){ // // internal target // } else if (target instanceof File) { // external target if (JavaModelManager.isFile(target)) { root = new JarPackageFragmentRoot((File) target, this, manager); } else if (((File) target).isDirectory()) { root = getPackageFragmentRoot((File) target, entryPath); // root = new ExternalPackageFragmentRoot(entryPath, this); } } break; // recurse into required project case IClasspathEntry.CPE_PROJECT: if (!retrieveExportedRoots) return; if (referringEntry != null && !resolvedEntry.isExported()) return; //todo multiproject // IResource member = workspaceRoot.findMember(entryPath); // if (member != null && member.getType() == IResource.PROJECT) {// double check if bound to project (23977) // IProject requiredProjectRsc = (IProject)member; // if (JavaProject.hasJavaNature(requiredProjectRsc)) { // special builder binary output // rootIDs.add(rootID); // JavaProject requiredProject = (JavaProject)JavaCore.create(requiredProjectRsc); // requiredProject.computePackageFragmentRoots( // requiredProject.getResolvedClasspath(), // accumulatedRoots, // rootIDs, // rootToResolvedEntries == null ? resolvedEntry // : ((org.eclipse.jdt.internal.core.ClasspathEntry)resolvedEntry) // .combineWith((org.eclipse.jdt.internal.core.ClasspathEntry)referringEntry), // // only combine if need to build the reverse map // retrieveExportedRoots, // rootToResolvedEntries); // } // break; // } } if (root != null) { accumulatedRoots.add(root); rootIDs.add(rootID); if (rootToResolvedEntries != null) rootToResolvedEntries.put(root, ((ClasspathEntry) resolvedEntry).combineWith((ClasspathEntry) referringEntry)); } }
From source file:org.eclipse.che.jdt.internal.core.search.JavaSearchScope.java
License:Open Source License
/** * Add a path to current java search scope or all project fragment roots if null. * Use project resolved classpath to retrieve and store access restriction on each classpath entry. * Recurse if dependent projects are found. * * @param javaProject//from w ww . j a v a2 s.c o m * Project used to get resolved classpath entries * @param pathToAdd * Path to add in case of single element or null if user want to add all project package fragment roots * @param includeMask * Mask to apply on classpath entries * @param projectsToBeAdded * Set to avoid infinite recursion * @param visitedProjects * Set to avoid adding twice the same project * @param referringEntry * Project raw entry in referring project classpath * @throws org.eclipse.jdt.core.JavaModelException * May happen while getting java model info */ void add(JavaProject javaProject, IPath pathToAdd, int includeMask, HashSet projectsToBeAdded, HashSet visitedProjects, IClasspathEntry referringEntry) throws JavaModelException { // IProject project = javaProject.getProject(); // if (!project.isAccessible() || !visitedProjects.add(project)) return; IPath projectPath = javaProject.getFullPath(); String projectPathString = projectPath.toString(); addEnclosingProjectOrJar(projectPath); IClasspathEntry[] entries = javaProject.getResolvedClasspath(); // IJavaModel model = javaProject.getJavaModel(); // JavaModelManager.PerProjectInfo perProjectInfo = javaProject.getPerProjectInfo(); for (int i = 0, length = entries.length; i < length; i++) { IClasspathEntry entry = entries[i]; AccessRuleSet access = null; ClasspathEntry cpEntry = (ClasspathEntry) entry; if (referringEntry != null) { // Add only exported entries. // Source folder are implicitly exported. if (!entry.isExported() && entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) { continue; } cpEntry = cpEntry.combineWith((ClasspathEntry) referringEntry); // cpEntry = ((ClasspathEntry)referringEntry).combineWith(cpEntry); } access = cpEntry.getAccessRuleSet(); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: IClasspathEntry rawEntry = null; // Map rootPathToRawEntries = perProjectInfo.rootPathToRawEntries; // if (rootPathToRawEntries != null) { // rawEntry = (IClasspathEntry)rootPathToRawEntries.get(entry.getPath()); // } // if (rawEntry == null) break; rawKind: switch (cpEntry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_VARIABLE: if ((includeMask & APPLICATION_LIBRARIES) != 0) { IPath path = entry.getPath(); if (pathToAdd == null || pathToAdd.equals(path)) { // Object target = JavaModel.getTarget(path, false/*don't check existence*/); // if (target instanceof IFolder) // case of an external folder // path = ((IFolder)target).getFullPath(); String pathToString = path.getDevice() == null ? path.toString() : path.toOSString(); add(projectPath.toString(), "", pathToString, false/*not a package*/, access); //$NON-NLS-1$ addEnclosingProjectOrJar(entry.getPath()); } } break; case IClasspathEntry.CPE_CONTAINER: IClasspathContainer container = JavaCore.getClasspathContainer(rawEntry.getPath(), javaProject); if (container == null) break; switch (container.getKind()) { case IClasspathContainer.K_APPLICATION: if ((includeMask & APPLICATION_LIBRARIES) == 0) break rawKind; break; case IClasspathContainer.K_SYSTEM: case IClasspathContainer.K_DEFAULT_SYSTEM: if ((includeMask & SYSTEM_LIBRARIES) == 0) break rawKind; break; default: break rawKind; } IPath path = entry.getPath(); if (pathToAdd == null || pathToAdd.equals(path)) { Object target = JavaModel.getTarget(path, false/*don't check existence*/); if (target instanceof IFolder) // case of an external folder path = ((IFolder) target).getFullPath(); String pathToString = path.getDevice() == null ? path.toString() : path.toOSString(); add(projectPath.toString(), "", pathToString, false/*not a package*/, access); //$NON-NLS-1$ addEnclosingProjectOrJar(entry.getPath()); } break; } break; case IClasspathEntry.CPE_PROJECT: // if ((includeMask & REFERENCED_PROJECTS) != 0) { // IPath path = entry.getPath(); // if (pathToAdd == null || pathToAdd.equals(path)) { // JavaProject referencedProject = (JavaProject)model.getJavaProject(path.lastSegment()); // if (!projectsToBeAdded // .contains(referencedProject)) { // do not recurse if depending project was used to create the scope // add(referencedProject, null, includeMask, projectsToBeAdded, visitedProjects, cpEntry); // } // } // } break; case IClasspathEntry.CPE_SOURCE: if ((includeMask & SOURCES) != 0) { IPath path = entry.getPath(); if (pathToAdd == null || pathToAdd.equals(path)) { add(projectPath.toString(), path.toOSString() .substring(projectPath.toString().length() + 1)/*Util.relativePath(path, 1*//*remove project segment*//*)*/, projectPathString, false/*not a package*/, access); } } break; } } }
From source file:org.eclipse.che.plugin.maven.server.core.classpath.ClasspathEntryHelper.java
License:Open Source License
private void setClasspathEntry(IClasspathEntry entry) { this.kind = entry.getEntryKind(); this.path = entry.getPath(); this.exported = entry.isExported(); this.outputLocation = entry.getOutputLocation(); this.accessRules = new ArrayList<>(); for (IAccessRule rule : entry.getAccessRules()) { this.accessRules.add(rule); }/*from ww w .ja va2 s . c o m*/ this.attributes = new HashMap<>(); for (IClasspathAttribute attribute : entry.getExtraAttributes()) { attributes.put(attribute.getName(), attribute.getValue()); } this.sourcePath = entry.getSourceAttachmentPath(); this.sourceRootPath = entry.getSourceAttachmentRootPath(); setInclusionPatterns(entry.getInclusionPatterns()); setExclusionPatterns(entry.getExclusionPatterns()); this.combineAccessRules = entry.combineAccessRules(); String groupId = attributes.get(ClasspathManager.GROUP_ID_ATTRIBUTE); String artifactId = attributes.get(ClasspathManager.ARTIFACT_ID_ATTRIBUTE); String version = attributes.get(ClasspathManager.VERSION_ATTRIBUTE); String packaging = attributes.get(ClasspathManager.PACKAGING_ATTRIBUTE); String classifier = attributes.get(ClasspathManager.CLASSIFIER_ATTRIBUTE); if (groupId != null && artifactId != null && version != null) { this.artifactKey = new MavenArtifactKey(groupId, artifactId, version, packaging, classifier); } }
From source file:org.eclipse.datatools.enablement.jdt.classpath.internal.DriverClasspathContainerPage.java
License:Open Source License
public void setSelection(IClasspathEntry containerEntry) { fIsExported = containerEntry != null && containerEntry.isExported(); if (containerEntry != null) { fUsedPaths.remove(containerEntry.getPath()); IPath path = containerEntry.getPath(); if (isDriverContainer(path)) { initialSelectName = path.segment(1); }/* w w w.j a va 2 s . c o m*/ } }