List of usage examples for org.eclipse.jdt.core IClasspathEntry isExported
boolean isExported();
From source file:net.sf.fjep.fatjar.popup.actions.BuildFatJar.java
License:Open Source License
private void getChildProjects(IJavaProject jproject, Vector projects, boolean exportedOnly) { IClasspathEntry[] cpes = jproject.readRawClasspath(); if (cpes != null) { for (int i = 0; i < cpes.length; i++) { IClasspathEntry cpe = JavaCore.getResolvedClasspathEntry(cpes[i]); if (cpe == null) { System.err.println("Error: cpes[" + i + "]=" + cpes[i] + " does not resolve"); continue; }//from w w w. j a va2 s .co m int kind = cpe.getEntryKind(); String name = relPath(cpe.getPath()); if (kind == IClasspathEntry.CPE_CONTAINER) { try { IClasspathContainer container = JavaCore.getClasspathContainer(cpe.getPath(), jproject); if ((container.getKind() == IClasspathContainer.K_APPLICATION) || (container.getKind() == IClasspathContainer.K_SYSTEM)) { IClasspathEntry[] cpes2 = container.getClasspathEntries(); for (int j = 0; j < cpes2.length; j++) { IClasspathEntry cpe2 = cpes2[j]; int kind2 = cpe2.getEntryKind(); String name2 = relPath(cpe2.getPath()); if (name2 == null) { System.err.println("invalid classpath entry: " + cpe2.toString()); } else { if (kind2 == IClasspathEntry.CPE_PROJECT) { if (!exportedOnly || cpe2.isExported()) { if (!projects.contains(name2)) { IJavaProject jChildProject2 = jproject.getJavaModel() .getJavaProject(name2); projects.add(jChildProject2); getChildProjects(jChildProject2, projects, true); } } } } } } } catch (JavaModelException e) { } } else if (kind == IClasspathEntry.CPE_PROJECT) { if (name == null) { System.err.println("invalid classpath entry: " + cpe.toString()); } else { if (!exportedOnly || cpe.isExported()) { if (!projects.contains(name)) { IJavaProject jChildProject = jproject.getJavaModel().getJavaProject(name); projects.add(jChildProject); getChildProjects(jChildProject, projects, true); } } } } } } }
From source file:net.sf.fjep.fatjar.popup.actions.BuildFatJar.java
License:Open Source License
/** * Add all jars and class-folders referenced by jproject to jarfiles / * classesDirs. If exportedOnly is true, then only jars/class-folders which * are marked as exported will be added. * /*from w w w . j a v a 2 s. com*/ * JRE_LIB (.../jre/lib/rt.jar) is ignored and not added to jarfiles * * @param jproject * @param jarfiles * @param classesDirs * @param exportedOnly */ private void getClassPathJars(IJavaProject jproject, Vector jarfiles, Vector classesDirs, boolean exportedOnly) { IProject project = jproject.getProject(); IWorkspace workspace = project.getWorkspace(); IWorkspaceRoot workspaceRoot = workspace.getRoot(); String rootDir = absPath(workspaceRoot.getLocation()); IClasspathEntry[] cpes = jproject.readRawClasspath(); // cpes = jproject.getResolvedClasspath(true); if (cpes != null) { for (int i = 0; i < cpes.length; i++) { IClasspathEntry cpe = JavaCore.getResolvedClasspathEntry(cpes[i]); if ((cpe != null) && (!exportedOnly || cpe.isExported())) { int kind = cpe.getEntryKind(); String dir = relPath(cpe.getPath()); if (kind == IClasspathEntry.CPE_CONTAINER) { try { IClasspathContainer container = JavaCore.getClasspathContainer(cpe.getPath(), jproject); if ((container.getKind() == IClasspathContainer.K_APPLICATION) || (container.getKind() == IClasspathContainer.K_SYSTEM)) { IClasspathEntry[] cpes2 = container.getClasspathEntries(); for (int j = 0; j < cpes2.length; j++) { IClasspathEntry cpe2 = cpes2[j]; int kind2 = cpe2.getEntryKind(); String dir2 = relPath(cpe2.getPath()); String jar2 = absOrProjectPath(workspaceRoot, dir2); if (jar2 == null) { System.err.println("invalid classpath entry: " + cpe2.toString()); } else { File f2 = new File(jar2); if (f2.isDirectory()) { if (!classesDirs.contains(jar2)) { classesDirs.add(jar2); } } else { // assume jar file if (!jarfiles.contains(jar2)) { jarfiles.add(jar2); } } } } } } catch (JavaModelException e) { } } else if (kind == IClasspathEntry.CPE_LIBRARY) { String jar = absOrProjectPath(workspaceRoot, dir); if (jar == null) { System.err.println("invalid classpath entry: " + cpe.toString()); } else { // ignore JRE_LIB if (!jar.replace(File.separatorChar, '/').toLowerCase().endsWith("/jre/lib/rt.jar")) { File f = new File(jar); if (f.isDirectory()) { if (!classesDirs.contains(jar)) { classesDirs.add(jar); } } else { // assume jar file if (!jarfiles.contains(jar)) { jarfiles.add(jar); } } } } } } } } }
From source file:net.sf.fjep.fatjar.wizards.export.JProjectConfiguration.java
License:Open Source License
/** * Add all jars and class-folders referenced by jproject to jarfiles / * classesDirs. If exportedOnly is true, then only jars/class-folders which * are marked as exported will be added. * /*from www . j a v a 2s.c o m*/ * JRE_LIB (.../jre/lib/rt.jar) is ignored and not added to jarfiles * * @param jarfiles * @param classesDirs * @param exportedOnly */ public void addClassPathEntries(Vector jarfiles, Vector classesDirs, Vector projects, boolean exportedOnly) { IClasspathEntry[] cpes = getRawClasspathEntries(); if (cpes != null) { for (int i = 0; i < cpes.length; i++) { IClasspathEntry cpe = JavaCore.getResolvedClasspathEntry(cpes[i]); if ((cpe != null) && (!exportedOnly || cpe.isExported())) { int kind = cpe.getEntryKind(); String dir = relPath(cpe.getPath()); if (kind == IClasspathEntry.CPE_CONTAINER) { try { IClasspathContainer container = JavaCore.getClasspathContainer(cpe.getPath(), jproject); if ((container.getKind() == IClasspathContainer.K_APPLICATION) || (container.getKind() == IClasspathContainer.K_SYSTEM)) { IClasspathEntry[] cpes2 = container.getClasspathEntries(); for (int j = 0; j < cpes2.length; j++) { IClasspathEntry cpe2 = cpes2[j]; int kind2 = cpe2.getEntryKind(); String dir2 = relPath(cpe2.getPath()); String jar2 = getAbsOrProjectPath(dir2); if (jar2 == null) { System.err.println("invalid classpath entry: " + cpe2.toString()); } else { File f2 = new File(jar2); if (f2.isDirectory()) { if (!classesDirs.contains(jar2)) { classesDirs.add(jar2); } } else { // assume jar file if (!jarfiles.contains(jar2)) { jarfiles.add(jar2); } } } } } } catch (JavaModelException e) { } } else if (kind == IClasspathEntry.CPE_LIBRARY) { String jar = getAbsOrProjectPath(dir); if (jar == null) { System.err.println("invalid classpath entry: " + cpe.toString()); } else { // ignore JRE_LIB if (!jar.replace(File.separatorChar, '/').toLowerCase().endsWith("/jre/lib/rt.jar")) { File f = new File(jar); if (f.isDirectory()) { if (!classesDirs.contains(jar)) { classesDirs.add(jar); } } else { // assume jar file if (!jarfiles.contains(jar)) { jarfiles.add(jar); } } } } } else if (kind == IClasspathEntry.CPE_PROJECT) { if (!exportedOnly || cpe.isExported()) { IJavaProject jPro = jproject.getJavaModel().getJavaProject(dir); JProjectConfiguration jProCon = new JProjectConfiguration(jPro, null); if (!projects.contains(jProCon)) { projects.add(jProCon); } } } } } } }
From source file:net.sf.fjep.fatjar.wizards.export.JProjectConfiguration.java
License:Open Source License
/** * Add all jars and class-folders referenced by jproject to jarfiles / * classesDirs. If exportedOnly is true, then only jars/class-folders which * are marked as exported will be added. * /*from w w w.j av a2 s . co m*/ * JRE_LIB (.../jre/lib/rt.jar) is ignored and not added to jarfiles * * @param jarfiles * @param classesDirs * @param exportedOnly */ public void getClassPathJars(Vector jarfiles, Vector classesDirs, boolean exportedOnly) { IClasspathEntry[] cpes = getRawClasspathEntries(); if (cpes != null) { for (int i = 0; i < cpes.length; i++) { IClasspathEntry cpe = JavaCore.getResolvedClasspathEntry(cpes[i]); if ((cpe != null) && (!exportedOnly || cpe.isExported())) { int kind = cpe.getEntryKind(); String dir = relPath(cpe.getPath()); if (kind == IClasspathEntry.CPE_CONTAINER) { try { IClasspathContainer container = JavaCore.getClasspathContainer(cpe.getPath(), jproject); if ((container.getKind() == IClasspathContainer.K_APPLICATION) || (container.getKind() == IClasspathContainer.K_SYSTEM)) { IClasspathEntry[] cpes2 = container.getClasspathEntries(); for (int j = 0; j < cpes2.length; j++) { IClasspathEntry cpe2 = cpes2[j]; int kind2 = cpe2.getEntryKind(); String dir2 = relPath(cpe2.getPath()); String jar2 = getAbsOrProjectPath(dir2); if (jar2 == null) { System.err.println("invalid classpath entry: " + cpe2.toString()); } else { File f2 = new File(jar2); if (f2.isDirectory()) { if (!classesDirs.contains(jar2)) { classesDirs.add(jar2); } } else { // assume jar file if (!jarfiles.contains(jar2)) { jarfiles.add(jar2); } } } } } } catch (JavaModelException e) { } } else if (kind == IClasspathEntry.CPE_LIBRARY) { String jar = getAbsOrProjectPath(dir); if (jar == null) { System.err.println("invalid classpath entry: " + cpe.toString()); } else { // ignore JRE_LIB if (!jar.replace(File.separatorChar, '/').toLowerCase().endsWith("/jre/lib/rt.jar")) { File f = new File(jar); if (f.isDirectory()) { if (!classesDirs.contains(jar)) { classesDirs.add(jar); } } else { // assume jar file if (!jarfiles.contains(jar)) { jarfiles.add(jar); } } } } } } } } }
From source file:net.sf.fjep.fatjar.wizards.export.JProjectConfiguration.java
License:Open Source License
public void getChildProjects(Vector projects, boolean exportedOnly) { IClasspathEntry[] cpes = this.getRawClasspathEntries(); if (cpes != null) { for (int i = 0; i < cpes.length; i++) { IClasspathEntry cpe = JavaCore.getResolvedClasspathEntry(cpes[i]); if (cpe == null) { System.err.println("Error: cpes[" + i + "]=" + cpes[i] + " does not resolve"); continue; }//from www . jav a 2s . c o m int kind = cpe.getEntryKind(); String name = relPath(cpe.getPath()); if (kind == IClasspathEntry.CPE_CONTAINER) { try { IClasspathContainer container = JavaCore.getClasspathContainer(cpe.getPath(), jproject); if ((container.getKind() == IClasspathContainer.K_APPLICATION) || (container.getKind() == IClasspathContainer.K_SYSTEM)) { IClasspathEntry[] cpes2 = container.getClasspathEntries(); for (int j = 0; j < cpes2.length; j++) { IClasspathEntry cpe2 = cpes2[j]; int kind2 = cpe2.getEntryKind(); String name2 = relPath(cpe2.getPath()); if (name2 == null) { System.err.println("invalid classpath entry: " + cpe2.toString()); } else { if (kind2 == IClasspathEntry.CPE_PROJECT) { if (!exportedOnly || cpe2.isExported()) { if (!projects.contains(name2)) { IJavaProject jChildProject2 = jproject.getJavaModel() .getJavaProject(name2); JProjectConfiguration jpcChild2 = new JProjectConfiguration( jChildProject2, null); projects.add(jpcChild2); jpcChild2.getChildProjects(projects, true); } } } } } } } catch (JavaModelException e) { } } else if (kind == IClasspathEntry.CPE_PROJECT) { if (name == null) { System.err.println("invalid classpath entry: " + cpe.toString()); } else { if (!exportedOnly || cpe.isExported()) { if (!projects.contains(name)) { IJavaProject jChildProject = jproject.getJavaModel().getJavaProject(name); JProjectConfiguration jpcChild = new JProjectConfiguration(jChildProject, null); projects.add(jpcChild); jpcChild.getChildProjects(projects, true); } } } } } } }
From source file:net.sourceforge.floggy.eclipse.builder.MTJBuilder.java
License:Open Source License
/** * This is where the classpool is actually set. The typical case only requires adding the required jar files * to the classpool (classPool and classPoolList), however if the project is dependent on other projects then * not only do we need the jar files from these dependencies but we also need the output folders. * @TODO EXPERIMENTAL - Dependencies support should be considered experimental at this time because it isn't fully tested ! */// ww w .j av a2 s . co m private void configureClassPool(ClassPool classPool, List classPoolList, IClasspathEntry[] entries, IProject project, boolean isRootProject) throws NotFoundException, JavaModelException { IClasspathEntry classpathEntry; String pathName; for (int i = 0; i < entries.length; i++) { classpathEntry = JavaCore.getResolvedClasspathEntry(entries[i]); IPath classIPath = classpathEntry.getPath(); if ((isRootProject || classpathEntry.isExported()) && classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { pathName = getAccessablePathName(classIPath, project); } else if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { classIPath = classpathEntry.getOutputLocation(); if (classIPath == null) { classIPath = JavaCore.create(project).getOutputLocation(); } pathName = getAccessablePathName(classIPath, project); } else { // Currently we only add : All source folders, All libs in the root project & Exported libs in other projects continue; } if (pathName.contains("floggy-persistence-framework-impl.jar")) { continue; } if (pathName != null && !classPoolList.contains(pathName)) { LOG.debug(pathName + " added to classPool"); classPoolList.add(pathName); classPool.appendClassPath(pathName); } else { LOG.debug(pathName + " alreaded added to classPool"); } } }
From source file:org.apache.ivyde.internal.eclipse.cpcontainer.IvyClasspathInitializer.java
License:Apache License
/** * Initialize the container with the "persisted" classpath entries, and then schedule the * refresh// w ww. j av a 2 s. c om */ public void initialize(IPath containerPath, IJavaProject project) throws CoreException { if (IvyClasspathContainerHelper.isIvyClasspathContainer(containerPath)) { IvyDEMessage.info("Initializing container " + containerPath); // try to get an existing one IClasspathContainer container = null; try { container = JavaCore.getClasspathContainer(containerPath, project); } catch (JavaModelException ex) { // unless there are issues with the JDT, this should never happen IvyPlugin.logError("Unable to get container for " + containerPath.toString(), ex); return; } try { boolean refresh = false; IvyClasspathContainerImpl ivycp = null; IClasspathEntry entry = IvyClasspathContainerHelper.getEntry(containerPath, project); IClasspathAttribute[] attributes; boolean exported; if (entry != null) { attributes = entry.getExtraAttributes(); exported = entry.isExported(); } else { exported = false; attributes = new IClasspathAttribute[0]; } if (container instanceof IvyClasspathContainerImpl) { IvyDEMessage.debug("Container already configured"); ivycp = (IvyClasspathContainerImpl) container; } else { if (container == null) { IvyDEMessage.debug("No saved container"); // try what the IvyDE plugin saved IvyClasspathContainerSerializer serializer = IvyPlugin.getDefault() .getIvyClasspathContainerSerializer(); Map ivycps = serializer.read(project); if (ivycps != null) { IvyDEMessage.debug("Found serialized containers"); ivycp = (IvyClasspathContainerImpl) ivycps.get(containerPath); } if (ivycp == null) { IvyDEMessage.debug("No serialized containers match the expected container path"); // still bad luck or just a new classpath container ivycp = new IvyClasspathContainerImpl(project, containerPath, new IClasspathEntry[0], attributes); // empty, so force refresh at least refresh = true; } } else { IvyDEMessage.debug("Loading from a saved container"); // this might be the persisted one : reuse the persisted entries ivycp = new IvyClasspathContainerImpl(project, containerPath, container.getClasspathEntries(), attributes); } } // FIXME : container path upgrade removed since it seems to make some trouble: // containers get either uninitialized or initialized twice... // recompute the path as it may have been "upgraded" // IPath updatedPath = IvyClasspathContainerConfAdapter.getPath(ivycp.getConf()); // if (!updatedPath.equals(containerPath)) { // IvyDEMessage.verbose("Upgrading container path from " + containerPath + " to " + // updatedPath); // updateIvyDEContainerPath(project, entry, attributes, exported, updatedPath); // return; // } IvyDEMessage.verbose("Setting container in JDT model"); JavaCore.setClasspathContainer(containerPath, new IJavaProject[] { project }, new IClasspathContainer[] { ivycp }, null); int startupMode = IvyPlugin.getPreferenceStoreHelper().getResolveOnStartup(); if (startupMode == ON_STARTUP_NOTHING) { if (!refresh) { IvyDEMessage.verbose("Doing nothing on startup"); // unless we force a refresh, actually do nothing return; } } else { refresh = startupMode == ON_STARTUP_REFRESH; } if (refresh) { IvyDEMessage.info("Scheduling a refresh of the container"); } else { IvyDEMessage.info("Scheduling a resolve of the container"); } // now refresh the container to be synchronized with the ivy.xml ivycp.launchResolve(refresh, null); } catch (Exception ex) { IStatus status = new Status(IStatus.ERROR, IvyPlugin.ID, IStatus.OK, "Unable to set container for " + containerPath.toString(), ex); throw new CoreException(status); } } }
From source file:org.apache.ivyde.internal.eclipse.cpcontainer.IvydeContainerPage.java
License:Apache License
public void setSelection(IClasspathEntry entry) { if (entry == null) { conf = new IvyClasspathContainerConfiguration(project, "ivy.xml", true); } else {//from w ww . j a va 2s . co m conf = new IvyClasspathContainerConfiguration(project, entry.getPath(), true, entry.getExtraAttributes()); exported = entry.isExported(); } state = new IvyClasspathContainerState(conf); oldIvyFile = conf.getIvyXmlPath(); oldConfs = conf.getConfs(); }
From source file:org.continuousassurance.swamp.eclipse.ImprovedClasspathHandler.java
License:Apache License
/** * Handles a library entry in the classpath * @param entry the classpath entry/* w ww. j a v a 2 s . c o m*/ * @param root the workspace root * @throws IOException */ private void handleLibrary(IClasspathEntry entry, IWorkspaceRoot root) throws IOException { // 3 types of library entries: internal (this project), internal (another project), and external // (1) Rooted absolute path // (2) Rooted absolute path (but with different project directory) --> Need to copy this to swampbin // (3) Actual absolute path to somewhere else on the filesystem --> Need to copy this to swampbin System.out.println("\n\n\n\n"); System.out.println("Library absolute path: " + entry.getPath().makeAbsolute()); //System.out.println("First segment: " + entry.getPath().segment(0)); IFile file = root.getFile(entry.getPath()); System.out.println("File project: " + file.getProject().getName()); if (file.getProject().equals(this.project.getProject())) { System.out.println("Is inside project"); libs.add(entry); } else { System.out.println("Is outside project"); IFile libFile = root.getFile(entry.getPath()); IProject libProject = libFile.getProject(); String filename = getLibraryFileName(entry.getPath()); IPath destPath; if (libProject.exists()) { if (libProject.isOpen()) { try { System.out.println("Local project"); destPath = copyWorkspacePathIntoBinDir(libFile, filename, SWAMPBIN_PATH); } catch (Exception e) { System.out.println("Local project that failed"); String srcPath = getProjectLibraryLocation(libProject, entry.getPath()); destPath = copyAbsolutePathIntoBinDir(srcPath, filename, SWAMPBIN_PATH); } } else { System.out.println("Local project that's closed"); String srcPath = getProjectLibraryLocation(libProject, entry.getPath()); destPath = copyAbsolutePathIntoBinDir(srcPath, filename, SWAMPBIN_PATH); } } else { System.out.println("Not a project - just an absolute path"); destPath = copyAbsolutePathIntoBinDir(entry.getPath().toOSString(), filename, SWAMPBIN_PATH); } hasSwampbinDependencies = true; System.out.println("SWAMPBIN path: " + destPath); IClasspathEntry newEntry = JavaCore.newLibraryEntry(destPath, entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath()); System.out.println("New entry path: " + newEntry.getPath()); libs.add(newEntry); if (entry.isExported()) { exportedEntries.add(newEntry); } } }
From source file:org.continuousassurance.swamp.eclipse.ImprovedClasspathHandler.java
License:Apache License
/** * Handles a project entry in the classpath. If not already processed, recursively create a new ImprovedClasspathHandler object for the dependent project * @param entry the project entry//from w w w .ja va 2s. co m * @param root the workspace root */ private void handleProject(IClasspathEntry entry, IWorkspaceRoot root) { String path = entry.getPath().toOSString(); ImprovedClasspathHandler ich; if (visitedProjects.containsKey(path)) { ich = visitedProjects.get(path); dependentProjects.add(ich); } else { IProject project = root.getProject(entry.getPath().toOSString()); ich = new ImprovedClasspathHandler(JavaCore.create(project), this.root, this.root.excludeSysLibs, null); dependentProjects.add(ich); visitedProjects.put(path, ich); } for (IClasspathEntry e : ich.getExportedEntries()) { this.libs.add(e); if (entry.isExported()) { this.exportedEntries.add(e); } } }