List of usage examples for org.eclipse.jdt.core IClasspathEntry isExported
boolean isExported();
From source file:org.eclipse.e4.tools.ui.designer.utils.ClassLoaderHelper.java
License:Open Source License
private static URL findResourceURL(IJavaProject javaProject, Set<IJavaProject> visited, boolean isFirstProject, String name) {/*www. ja v a 2s.c om*/ if (visited.contains(javaProject)) return null; visited.add(javaProject); try { IPath outPath = javaProject.getProject().getLocation().removeLastSegments(1) .append(javaProject.getOutputLocation()); outPath = outPath.addTrailingSeparator(); { URL url = toURL(outPath.append(name)); if (url != null) { return url; } } for (IPackageFragmentRoot fragment : javaProject.getPackageFragmentRoots()) { if (fragment.getKind() == IPackageFragmentRoot.K_SOURCE) { URL url = toURL(fragment.getResource().getLocation().append(name)); if (url != null) { return url; } } } // urls.add(out); IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); for (IClasspathEntry entry : entries) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: { // TODO IClasspathEntry resolveEntry = JavaCore.getResolvedClasspathEntry(entry); File file = resolveEntry.getPath().toFile(); IPath path = resolveEntry.getPath(); if (!file.exists()) { String projectName = path.segment(0); IProject project = javaProject.getProject().getWorkspace().getRoot() .getProject(projectName); path = project.getLocation().append(path.removeFirstSegments(1)); } String spec = "jar:file:" + path.toString() + "!/" + name; try { URL url2 = new URL(spec); url2.getContent(); return url2; } catch (Exception e) { } } break; case IClasspathEntry.CPE_CONTAINER: break; case IClasspathEntry.CPE_VARIABLE: { { // TODO URL url = toURL(outPath.append(name)); if (url != null) { return url; } } } break; case IClasspathEntry.CPE_PROJECT: { if (isFirstProject || entry.isExported()) { URL url = findResourceURL(getJavaProject(entry), visited, false, name); if (url != null) { return url; } } break; } } } } catch (JavaModelException e) { e.printStackTrace(); } return null; }
From source file:org.eclipse.e4.tools.ui.designer.utils.ClassLoaderHelper.java
License:Open Source License
private static void collectClasspathURLs(IJavaProject javaProject, List<URL> urls, Set<IJavaProject> visited, boolean isFirstProject) { if (visited.contains(javaProject)) return;/*from w w w . ja v a2 s . co m*/ visited.add(javaProject); try { IPath outPath = javaProject.getProject().getWorkspace().getRoot().getFullPath() .append(javaProject.getOutputLocation()); outPath = outPath.addTrailingSeparator(); URL out = createFileURL(outPath); urls.add(out); IClasspathEntry[] entries = null; entries = javaProject.getResolvedClasspath(true); for (IClasspathEntry entry : entries) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_CONTAINER: case IClasspathEntry.CPE_VARIABLE: collectClasspathEntryURL(entry, urls); break; case IClasspathEntry.CPE_PROJECT: { if (isFirstProject || entry.isExported()) collectClasspathURLs(getJavaProject(entry), urls, visited, false); break; } } } } catch (JavaModelException e) { return; } }
From source file:org.eclipse.jdt.internal.core.JavaModelManager.java
License:Open Source License
public IClasspathEntry resolveVariableEntry(IClasspathEntry entry, boolean usePreviousSession) { if (entry.getEntryKind() != IClasspathEntry.CPE_VARIABLE) return entry; IPath resolvedPath = getResolvedVariablePath(entry.getPath(), usePreviousSession); if (resolvedPath == null) return null; // By passing a null reference path, we keep it relative to workspace root. resolvedPath = ClasspathEntry.resolveDotDot(null, resolvedPath); Object target = JavaModel.getTarget(resolvedPath, false); if (target == null) return null; // inside the workspace if (target instanceof IResource) { IResource resolvedResource = (IResource) target; switch (resolvedResource.getType()) { case IResource.PROJECT: // internal project return JavaCore.newProjectEntry(resolvedPath, entry.getAccessRules(), entry.combineAccessRules(), entry.getExtraAttributes(), entry.isExported()); case IResource.FILE: // internal binary archive return JavaCore.newLibraryEntry(resolvedPath, getResolvedVariablePath(entry.getSourceAttachmentPath(), usePreviousSession), getResolvedVariablePath(entry.getSourceAttachmentRootPath(), usePreviousSession), entry.getAccessRules(), entry.getExtraAttributes(), entry.isExported()); case IResource.FOLDER: // internal binary folder return JavaCore.newLibraryEntry(resolvedPath, getResolvedVariablePath(entry.getSourceAttachmentPath(), usePreviousSession), getResolvedVariablePath(entry.getSourceAttachmentRootPath(), usePreviousSession), entry.getAccessRules(), entry.getExtraAttributes(), entry.isExported()); }/*from w w w . j a va 2 s . c om*/ } if (target instanceof File) { File externalFile = JavaModel.getFile(target); if (externalFile != null) { // external binary archive return JavaCore.newLibraryEntry(resolvedPath, getResolvedVariablePath(entry.getSourceAttachmentPath(), usePreviousSession), getResolvedVariablePath(entry.getSourceAttachmentRootPath(), usePreviousSession), entry.getAccessRules(), entry.getExtraAttributes(), entry.isExported()); } else { // non-existing file if (resolvedPath.isAbsolute()) { return JavaCore.newLibraryEntry(resolvedPath, getResolvedVariablePath(entry.getSourceAttachmentPath(), usePreviousSession), getResolvedVariablePath(entry.getSourceAttachmentRootPath(), usePreviousSession), entry.getAccessRules(), entry.getExtraAttributes(), entry.isExported()); } } } return null; }
From source file:org.eclipse.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//from w w w . j a va 2s . 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.project.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 target = JavaModel.getTarget(entryPath, true/*check existency*/); if (target == null) return; if (target instanceof IFolder || target instanceof IProject) { root = getPackageFragmentRoot((IResource) target); } } break; // internal/external JAR or folder case IClasspathEntry.CPE_LIBRARY: if (referringEntry != null && !resolvedEntry.isExported()) return; Object target = JavaModel.getTarget(entryPath, true/*check existency*/); if (target == null) return; if (target instanceof IResource) { // internal target root = getPackageFragmentRoot((IResource) target, entryPath); } else if (target instanceof File) { // external target if (JavaModel.isFile(target)) { root = new JarPackageFragmentRoot(entryPath, this); } else if (((File) target).isDirectory()) { root = new ExternalPackageFragmentRoot(entryPath, this); } } break; // recurse into required project case IClasspathEntry.CPE_PROJECT: if (!retrieveExportedRoots) return; if (referringEntry != null && !resolvedEntry.isExported()) return; 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 : ((ClasspathEntry) resolvedEntry).combineWith((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.jem.internal.proxy.core.ProxyPlugin.java
License:Open Source License
private void expandProject(IPath projectPath, FoundIDs foundIds, boolean visible, boolean first) throws JavaModelException { IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(projectPath.lastSegment()); if (res == null) return; // Not exist so don't delve into it. IJavaProject project = (IJavaProject) JavaCore.create(res); if (project == null || !project.exists() || !project.getProject().isOpen()) return; // Not exist as a java project or not open, so don't delve into it. IClasspathEntry[] entries = project.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; Boolean currentFlag = null; // Current setting value. boolean newFlag; // The new setting value. switch (entry.getEntryKind()) { case IClasspathEntry.CPE_PROJECT: // Force true if already true, or this is the first project, or this project is visible and the entry is exported. These override a previous false. currentFlag = (Boolean) foundIds.projects.get(entry.getPath()); newFlag = (currentFlag != null && currentFlag.booleanValue()) || first || (visible && entry.isExported()); if (currentFlag == null || currentFlag.booleanValue() != newFlag) foundIds.projects.put(entry.getPath(), newFlag ? Boolean.TRUE : Boolean.FALSE); if (currentFlag == null) expandProject(entry.getPath(), foundIds, visible && entry.isExported(), false); break; case IClasspathEntry.CPE_CONTAINER: if (!first && JavaRuntime.JRE_CONTAINER.equals(entry.getPath().segment(0))) //$NON-NLS-1$ break; // The first project determines the JRE, so any subsequent ones can be ignored. Map[] paths = (Map[]) foundIds.containerIds.get(entry.getPath().segment(0)); if (paths == null) { paths = new Map[] { new HashMap(2), new HashMap(2) }; foundIds.containerIds.put(entry.getPath().segment(0), paths); }// w w w .ja va2 s . c o m currentFlag = null; if (paths[0].containsKey(entry.getPath())) currentFlag = Boolean.TRUE; else if (paths[1].containsKey(entry.getPath())) currentFlag = Boolean.FALSE; newFlag = (currentFlag != null && currentFlag.booleanValue()) || first || (visible && entry.isExported()); if (currentFlag == null || currentFlag.booleanValue() != newFlag) { if (newFlag) { // It is visible, remove from hidden, if there, and add to visible. paths[1].remove(entry.getPath()); paths[0].put(entry.getPath(), entry.getPath().toString()); } else { // It is hidden, remove from visible, if there, and add to hidden. paths[0].remove(entry.getPath()); paths[1].put(entry.getPath(), entry.getPath().toString()); } } IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), project); // Force true if already true, or this is the first project, or this project is visible and the entry is exported. These override a previous false. currentFlag = (Boolean) foundIds.containers.get(container); newFlag = (currentFlag != null && currentFlag.booleanValue()) || first || (visible && entry.isExported()); if (currentFlag == null || currentFlag.booleanValue() != newFlag) foundIds.containers.put(container, newFlag ? Boolean.TRUE : Boolean.FALSE); break; case IClasspathEntry.CPE_VARIABLE: // We only care about JRE_LIB. If we have that, then we will treat it as JRE_CONTAINER. Only // care about first project too, because the first project is the one that determines the JRE type. if (first && JavaRuntime.JRELIB_VARIABLE.equals(entry.getPath().segment(0))) { //$NON-NLS-1$ paths = (Map[]) foundIds.containerIds.get(JavaRuntime.JRE_CONTAINER); if (paths == null) { paths = new Map[] { new HashMap(2), new HashMap(2) }; foundIds.containerIds.put(JavaRuntime.JRE_CONTAINER, paths); } currentFlag = null; if (paths[0].containsKey(JRE_CONTAINER_PATH)) currentFlag = Boolean.TRUE; else if (paths[1].containsKey(JRE_CONTAINER_PATH)) currentFlag = Boolean.FALSE; newFlag = (currentFlag != null && currentFlag.booleanValue()) || first || (visible && entry.isExported()); if (currentFlag == null || currentFlag.booleanValue() != newFlag) { if (newFlag) { // It is visible, remove from hidden, if there, and add to visible. paths[1].remove(JRE_CONTAINER_PATH); paths[0].put(JRE_CONTAINER_PATH, JavaRuntime.JRE_CONTAINER); } else { // It is hidden, remove from visible, if there, and add to hidden. paths[0].remove(JRE_CONTAINER_PATH); paths[1].put(JRE_CONTAINER_PATH, JavaRuntime.JRE_CONTAINER); } } } break; default: break; } } findPlugins(foundIds, visible, first, project); }
From source file:org.eclipse.jem.workbench.utility.JavaModelListener.java
License:Open Source License
private IJavaProject getVisibleJavaProject(IClasspathEntry entry, boolean isFirstLevel) { if (isFirstLevel || entry.isExported()) { IClasspathEntry resEntry = JavaCore.getResolvedClasspathEntry(entry); return getJavaProject(resEntry); }//from w ww .jav a 2s. co m return null; }
From source file:org.eclipse.jem.workbench.utility.JemProjectUtilities.java
License:Open Source License
private static void collectClasspathURLs(IJavaProject javaProject, List urls, Set visited, boolean isFirstProject) { if (visited.contains(javaProject)) return;//from w w w. j a va2s.co m visited.add(javaProject); IPath outPath = getJavaProjectOutputAbsoluteLocation(javaProject.getProject()); outPath = outPath.addTrailingSeparator(); URL out = ProjectUtilities.createFileURL(outPath); urls.add(out); IClasspathEntry[] entries = null; try { entries = javaProject.getResolvedClasspath(true); } catch (JavaModelException e) { return; } IClasspathEntry entry; for (int i = 0; i < entries.length; i++) { entry = entries[i]; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_CONTAINER: case IClasspathEntry.CPE_VARIABLE: collectClasspathEntryURL(entry, urls); break; case IClasspathEntry.CPE_PROJECT: { if (isFirstProject || entry.isExported()) collectClasspathURLs(getJavaProject(entry), urls, visited, false); break; } } } }
From source file:org.eclipse.jst.common.project.facet.core.internal.ClasspathUtil.java
License:Open Source License
private static IClasspathEntry setOwners(final IClasspathEntry cpe, final String owners) { final List<IClasspathAttribute> attrs = new ArrayList<IClasspathAttribute>(); for (IClasspathAttribute attr : cpe.getExtraAttributes()) { if (!attr.getName().equals(OWNER_PROJECT_FACETS_ATTR)) { attrs.add(attr);/* w w w.j a v a 2s .c o m*/ } } if (owners != null) { attrs.add(JavaCore.newClasspathAttribute(OWNER_PROJECT_FACETS_ATTR, owners)); } return new ClasspathEntry(cpe.getContentKind(), cpe.getEntryKind(), cpe.getPath(), cpe.getInclusionPatterns(), cpe.getExclusionPatterns(), cpe.getSourceAttachmentPath(), cpe.getSourceAttachmentRootPath(), cpe.getOutputLocation(), cpe.isExported(), cpe.getAccessRules(), cpe.combineAccessRules(), attrs.toArray(new IClasspathAttribute[attrs.size()])); }
From source file:org.eclipse.jst.j2ee.classpathdep.ClasspathDependencyUtil.java
License:Open Source License
public static IClasspathEntry modifyDependencyPath(IClasspathEntry entry, IPath dependencyPath) { IClasspathEntry newEntry = null;/*w w w.ja v a 2 s . com*/ IClasspathAttribute[] newAttributes = modifyDependencyPath(entry.getExtraAttributes(), dependencyPath); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_CONTAINER: newEntry = JavaCore.newContainerEntry(entry.getPath(), entry.getAccessRules(), newAttributes, entry.isExported()); break; case IClasspathEntry.CPE_LIBRARY: newEntry = JavaCore.newLibraryEntry(entry.getPath(), entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), entry.getAccessRules(), newAttributes, entry.isExported()); break; case IClasspathEntry.CPE_VARIABLE: newEntry = JavaCore.newVariableEntry(entry.getPath(), entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), entry.getAccessRules(), newAttributes, entry.isExported()); break; case IClasspathEntry.CPE_PROJECT: newEntry = JavaCore.newProjectEntry(entry.getPath(), entry.getAccessRules(), entry.combineAccessRules(), newAttributes, entry.isExported()); break; case IClasspathEntry.CPE_SOURCE: newEntry = JavaCore.newSourceEntry(entry.getPath(), entry.getInclusionPatterns(), entry.getExclusionPatterns(), entry.getOutputLocation(), newAttributes); break; } return newEntry; }
From source file:org.eclipse.jst.j2ee.internal.classpathdep.ClasspathDependencyValidator.java
License:Open Source License
public IStatus validateInJob(IValidationContext helper, IReporter reporter) throws ValidationException { _reporter = reporter;//from ww w .j av a2 s .c o m //Remove all markers related to this validator _reporter.removeAllMessages(this); //Using the helper class, load the module model final Set archiveNames = new HashSet(); final IProject proj = ((ClasspathDependencyValidatorHelper) helper).getProject(); try { if (ModuleCoreNature.isFlexibleProject(proj) && proj.hasNature(JavaCoreLite.NATURE_ID)) { final boolean isWebApp = JavaEEProjectUtilities.isDynamicWebProject(proj); final IVirtualComponent component = ComponentCore.createComponent(proj); final boolean isLegacyJ2EE = JavaEEProjectUtilities.isLegacyJ2EEComponent(component); final IJavaProjectLite javaProjectLite = JavaCoreLite.create(proj); final Map referencedRawEntries = ClasspathDependencyUtil.getRawComponentClasspathDependencies( javaProjectLite, DependencyAttributeType.CLASSPATH_COMPONENT_DEPENDENCY, isLegacyJ2EE); final List potentialRawEntries = ClasspathDependencyUtil .getPotentialComponentClasspathDependencies(javaProjectLite, isLegacyJ2EE); final ClasspathDependencyValidatorData data = new ClasspathDependencyValidatorData(proj); ClasspathDependencyExtensionManager extensionManger = ClasspathDependencyExtensionManager .instance(); // validate the raw referenced container entries Iterator i = referencedRawEntries.keySet().iterator(); boolean hasRootMapping = false; while (i.hasNext()) { final IClasspathEntry entry = (IClasspathEntry) i.next(); final boolean isClassFolder = ClasspathDependencyUtil.isClassFolderEntry(entry); final IClasspathAttribute attrib = (IClasspathAttribute) referencedRawEntries.get(entry); final IPath runtimePath = ClasspathDependencyUtil.getRuntimePath(attrib, isWebApp, isClassFolder); if (runtimePath.equals(IClasspathDependencyConstants.RUNTIME_MAPPING_INTO_CONTAINER_PATH)) { hasRootMapping = true; } IMessage[] msgs = validateVirtualComponentEntry(entry, attrib, isWebApp, proj, data); final String cpEntryPath = entry.getPath().toString(); for (int j = 0; j < msgs.length; j++) { msgs[j].setGroupName(cpEntryPath); } reportMessages(msgs); // if not a web app, warn if associated cp entry is not exported if (!isWebApp && !entry.isExported() && !extensionManger.doesProjectHandleExport(proj, entry)) { _reporter.addMessage(this, new Message("classpathdependencyvalidator", //$NON-NLS-1$ IMessage.NORMAL_SEVERITY, NonWebNonExported, new String[] { cpEntryPath }, proj)); } } if (!referencedRawEntries.isEmpty()) { // if (JavaEEProjectUtilities.isApplicationClientProject(proj)) { // // classpath component dependencies are not supported for application client projects // final IMessage msg = new Message("classpathdependencyvalidator", //$NON-NLS-1$ // IMessage.HIGH_SEVERITY, AppClientProject, null, proj); // _reporter.addMessage(this, msg); // } // are there any root mappings if (hasRootMapping && component != null) { boolean referencedFromEARorWAR = false; final List earWarRefs = new ArrayList(); final IVirtualComponent[] refComponents = component.getReferencingComponents(); for (int j = 0; j < refComponents.length; j++) { if (JavaEEProjectUtilities.isEARProject(refComponents[j].getProject()) || JavaEEProjectUtilities.isDynamicWebProject(refComponents[j].getProject())) { referencedFromEARorWAR = true; earWarRefs.add(refComponents[j]); } } if (!referencedFromEARorWAR) { // warn if there are root mappings and the project is not referenced by an EAR or a WAR final IMessage msg = new Message("classpathdependencyvalidator", //$NON-NLS-1$ IMessage.NORMAL_SEVERITY, RootMappingNonEARWARRef, null, proj); _reporter.addMessage(this, msg); } } } // generate warning messages for any potential entries; we warn for these since // the classes are being exposed but will not be bundled into the exported/published module and // therefore will not be available at runtime. i = potentialRawEntries.iterator(); while (i.hasNext()) { final IClasspathEntry entry = (IClasspathEntry) i.next(); final IMessage msg = new Message("classpathdependencyvalidator", //$NON-NLS-1$ IMessage.NORMAL_SEVERITY, NonTaggedExportedClasses, new String[] { entry.getPath().toString() }, proj); msg.setGroupName(entry.getPath().toString()); _reporter.addMessage(this, msg); } // validate all resolved entries (only perform this if there are raw referenced entries) if (!referencedRawEntries.isEmpty()) { final Map referencedResolvedEntries = ClasspathDependencyUtil .getComponentClasspathDependencies(javaProjectLite, isWebApp, false); i = referencedResolvedEntries.keySet().iterator(); while (i.hasNext()) { final IClasspathEntry entry = (IClasspathEntry) i.next(); final IClasspathAttribute attrib = (IClasspathAttribute) referencedResolvedEntries .get(entry); // compute the archive name final String archivePath = ClasspathDependencyUtil.getArchiveName(entry); if (archiveNames.contains(archivePath)) { // Project cp entry final IMessage msg = new Message("classpathdependencyvalidator", //$NON-NLS-1$ IMessage.HIGH_SEVERITY, DuplicateArchiveName, new String[] { entry.getPath().toString() }, proj); _reporter.addMessage(this, msg); } else { archiveNames.add(archivePath); } // validate the resolved entry if we didn't already validate as part of the raw entries if (!referencedRawEntries.containsKey(entry)) { IMessage[] msgs = validateVirtualComponentEntry(entry, attrib, isWebApp, proj, data); reportMessages(msgs); } } } } } catch (CoreException e) { J2EEPlugin.logError(e); } return Status.OK_STATUS; }