List of usage examples for org.eclipse.jdt.core IClasspathEntry getEntryKind
int getEntryKind();
From source file:com.drgarbage.bytecode.jdi.dialogs.ProjectBuildPathViewer.java
License:Apache License
/** * Fills the list of existing class folders in the project. */// ww w.j a v a 2 s.c o m private void fillLibList() { libs = new HashSet<IFolder>(); /* fill a set with classpath entries */ IClasspathEntry[] classpathEntries = fJavaProject.readRawClasspath(); for (IClasspathEntry ice : classpathEntries) { if (ice.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IResource resource = root.findMember(ice.getPath()); if (resource instanceof IFolder) { IFolder f = (IFolder) resource; libs.add(f); } } } }
From source file:com.drgarbage.bytecodevisualizer.editors.NoSourceViewer.java
License:Apache License
private void createSourceAttachmentControls(Composite composite, IPackageFragmentRoot root) throws JavaModelException { IClasspathEntry entry; try {//w w w . j av a 2 s . c o m entry = root.getRawClasspathEntry(); } catch (JavaModelException ex) { if (ex.isDoesNotExist()) entry = null; else throw ex; } IPath containerPath = null; if (entry == null || root.getKind() != IPackageFragmentRoot.K_BINARY) { String s = CoreMessages.SourceAttachmentForm_message_noSource; createLabel(composite, MessageFormat.format(s, new Object[] { fFile.getElementName() })); return; } IJavaProject jproject = root.getJavaProject(); if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { containerPath = entry.getPath(); ClasspathContainerInitializer initializer = JavaCore .getClasspathContainerInitializer(containerPath.segment(0)); IClasspathContainer container = JavaCore.getClasspathContainer(containerPath, jproject); if (initializer == null || container == null) { createLabel(composite, MessageFormat.format(CoreMessages.SourceAttachmentForm_cannotconfigure, new Object[] { containerPath.toString() })); return; } String containerName = container.getDescription(); IStatus status = initializer.getSourceAttachmentStatus(containerPath, jproject); if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED) { createLabel(composite, MessageFormat.format(CoreMessages.SourceAttachmentForm_notsupported, new Object[] { containerName })); return; } if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) { createLabel(composite, MessageFormat.format(CoreMessages.SourceAttachmentForm_readonly, new Object[] { containerName })); return; } entry = JavaModelUtil.findEntryInContainer(container, root.getPath()); Assert.isNotNull(entry); } Button button; String msg = null; String btnText = null; IPath path = entry.getSourceAttachmentPath(); if (path == null || path.isEmpty()) { msg = MessageFormat.format(CoreMessages.SourceAttachmentForm_message_noSourceAttachment, new Object[] { root.getElementName() }); btnText = CoreMessages.SourceAttachmentForm_button_attachSource; } else { msg = MessageFormat.format(CoreMessages.SourceAttachmentForm_message_noSourceInAttachment, new Object[] { fFile.getElementName() }); btnText = CoreMessages.SourceAttachmentForm_button_changeAttachedSource; } createLabel(composite, msg); createLabel(composite, CoreMessages.SourceAttachmentForm_message_pressButtonToAttach); createLabel(composite, null); button = createButton(composite, btnText); button.addSelectionListener(createButtonListener(entry, containerPath, jproject)); }
From source file:com.ebmwebsourcing.petals.common.internal.provisional.utils.JavaUtils.java
License:Open Source License
/** * Makes an Eclipse project a Java project. * <p>//from w w w .j a va 2s .c om * If the project does not exist, or is not accessible, then nothing is done.<br /> * If the project does not have the Java nature, this nature is added. * </p> * <p> * The default output directory is "bin". If this directory does not exist, it is created. * If the creation fails, then no output directory is set. * </p> * <p> * The default source directory is "src/main/java". If this directory does not exist, it is created. * If the creation fails, then no source directory is set. * </p> * * @param project the project to transform into a Java project * @return the created Java project * @throws CoreException if something went wrong */ public static IJavaProject createJavaProject(IProject project) throws CoreException { IJavaProject jp = null; if (project.isAccessible()) { // Add the Java nature? if (!project.hasNature(JavaCore.NATURE_ID)) { IProjectDescription description = project.getDescription(); String[] natures = description.getNatureIds(); String[] newNatures = new String[natures.length + 1]; System.arraycopy(natures, 0, newNatures, 0, natures.length); newNatures[natures.length] = JavaCore.NATURE_ID; description.setNatureIds(newNatures); project.setDescription(description, null); } // Set the default class path jp = JavaCore.create(project); IProgressMonitor monitor = new NullProgressMonitor(); // // Output location IPath ppath = project.getFullPath(); IPath binPath = ppath.append(PetalsConstants.LOC_BIN_FOLDER); File binFile = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(binPath).toFile(); if (binFile.exists() && binFile.isDirectory() || !binFile.exists() && binFile.mkdirs()) { jp.setOutputLocation(binPath, monitor); } Set<IClasspathEntry> entries = new HashSet<IClasspathEntry>(); entries.addAll(Arrays.asList(jp.getRawClasspath())); entries.add(JavaRuntime.getDefaultJREContainerEntry()); // // Remove the "src" entry IClasspathEntry srcEntry = null; for (IClasspathEntry entry : entries) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { srcEntry = entry; break; } } // // Specify a new source entry if (srcEntry != null) entries.remove(srcEntry); String[] srcPaths = new String[] { PetalsConstants.LOC_SRC_FOLDER, PetalsConstants.LOC_JAVA_RES_FOLDER }; for (String s : srcPaths) { IPath srcPath = ppath.append(s); File srcFile = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(srcPath).toFile(); if (srcFile.exists() && srcFile.isDirectory() || !srcFile.exists() && srcFile.mkdirs()) { project.refreshLocal(IResource.DEPTH_INFINITE, monitor); srcEntry = JavaCore.newSourceEntry(srcPath); entries.add(srcEntry); } else { PetalsCommonPlugin.log("Could not set '" + s + "' as a source folder.", IStatus.ERROR); } } jp.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), monitor); } return jp; }
From source file:com.ebmwebsourcing.petals.common.internal.provisional.utils.JavaUtils.java
License:Open Source License
/** * Gets the source folders of a IJavaProject. * @param javaProject//from w w w . j av a2 s . co m * @return the list of source folders in this Java project */ public static List<IClasspathEntry> getSourceFolders(IJavaProject javaProject) { List<IClasspathEntry> result = new ArrayList<IClasspathEntry>(); try { for (IClasspathEntry entry : javaProject.getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) result.add(entry); } } catch (JavaModelException e) { PetalsCommonPlugin.log(e, IStatus.ERROR); } return result; }
From source file:com.ebmwebsourcing.petals.common.internal.provisional.utils.JavaUtils.java
License:Open Source License
/** * Get the class path from Java project. * * @param javaProject//from ww w . jav a 2 s .c om * @param getReferencedProjectClasspath * @param binaryDirectory * @return the class path as a list of string locations. */ public static List<String> getClasspath(IJavaProject javaProject, boolean getReferencedProjectClasspath, boolean binaryDirectory) { List<String> paths = new ArrayList<String>(); try { if (javaProject != null) { // Get the raw class path IClasspathEntry[] entries = javaProject.getRawClasspath(); for (IClasspathEntry entry : entries) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_PROJECT: if (!getReferencedProjectClasspath) break; String projectName = entry.getPath().toString(); IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); IJavaProject jProject = JavaCore.create(project); List<String> subPaths = getClasspath(jProject, true, binaryDirectory); paths.addAll(subPaths); break; case IClasspathEntry.CPE_LIBRARY: IPath path = entry.getPath(); paths.add(path.toString()); break; case IClasspathEntry.CPE_VARIABLE: entry = JavaCore.getResolvedClasspathEntry(entry); if (entry != null) { path = entry.getPath(); paths.add(path.toString()); } break; } } // Add the "bin" directory? if (binaryDirectory && javaProject.getOutputLocation() != null) { IPath path = ResourcesPlugin.getWorkspace().getRoot().getLocation(); path = path.append(javaProject.getOutputLocation()); paths.add(path.toString()); } } } catch (JavaModelException e) { PetalsCommonPlugin.log(e, IStatus.ERROR); } return paths; }
From source file:com.ebmwebsourcing.petals.common.internal.provisional.utils.JavaUtils.java
License:Open Source License
/** * Populates an {@link ExportableClassPath} instance from a class path entry. * @param result the {@link ExportableClassPath} instance to populate * @param entry a class path entry//w ww .ja v a 2s. co m * @param monitor the progress monitor */ private static void updateExportableResult(ExportableClassPath result, IClasspathEntry entry, IProgressMonitor monitor) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_PROJECT: String projectName = entry.getPath().toString(); IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); IJavaProject jProject = JavaCore.create(project); ExportableClassPath subResult = getExportableClasspath(jProject, monitor); result.implementationJars.addAll(subResult.implementationJars); result.libraryJars.addAll(subResult.libraryJars); monitor.worked(1); break; case IClasspathEntry.CPE_LIBRARY: IPath path = entry.getPath(); if (path != null) { File f = path.toFile(); if (f.exists()) { if (f.getName().endsWith(".zip") || f.getName().endsWith(".jar")) result.libraryJars.add(f); } } break; case IClasspathEntry.CPE_VARIABLE: entry = JavaCore.getResolvedClasspathEntry(entry); if (entry != null) updateExportableResult(result, entry, monitor); break; } }
From source file:com.github.caofangkun.bazelipse.classpath.BazelClasspathContainer.java
License:Open Source License
private boolean isSourcePath(String path) throws JavaModelException, BackingStoreException { Path pp = new File(instance.getWorkspaceRoot().toString() + File.separator + path).toPath(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); for (IClasspathEntry entry : project.getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IResource res = root.findMember(entry.getPath()); if (res != null) { String file = res.getLocation().toOSString(); if (!file.isEmpty() && pp.startsWith(file)) { IPath[] inclusionPatterns = entry.getInclusionPatterns(); if (!matchPatterns(pp, entry.getExclusionPatterns()) && (inclusionPatterns == null || inclusionPatterns.length == 0 || matchPatterns(pp, inclusionPatterns))) { return true; }// www . j a va 2s . co m } } } } return false; }
From source file:com.github.ko2ic.plugin.eclipse.taggen.core.service.WorkspaceClassLoader.java
License:Open Source License
private Set<URL> createUrls(IJavaProject javaProject) throws CoreException, MalformedURLException { Set<URL> urlList = new HashSet<>(); IClasspathEntry[] classpathEntries = javaProject.getResolvedClasspath(true); for (IClasspathEntry entry : classpathEntries) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath path = entry.getOutputLocation(); if (path != null) { IPath outputPath = javaProject.getOutputLocation().removeFirstSegments(1); IPath outputFullPath = javaProject.getProject().getFolder(outputPath).getLocation(); outputFullPath.append(System.getProperty("line.separator")); URL url = outputFullPath.toFile().toURI().toURL(); urlList.add(url);//w w w .ja va 2 s .c om } } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { URL url = entry.getPath().toFile().toURI().toURL(); urlList.add(url); } } return urlList; }
From source file:com.google.appengine.eclipse.core.orm.enhancement.AutoEnhancer.java
License:Open Source License
private Set<String> computeEnhancementPathsForFullBuild() throws CoreException { Set<IPath> scannedOutputLocations = new HashSet<IPath>(); final Set<String> pathsToEnhance = new HashSet<String>(); for (final IClasspathEntry classpathEntry : javaProject.getRawClasspath()) { if (classpathEntry.getEntryKind() != IClasspathEntry.CPE_SOURCE) { // Skip any classpath entry that is not a source entry continue; }// w w w. j a va 2 s. c o m final IPath outputLocation = getOutputLocation(classpathEntry, javaProject.getOutputLocation()); if (!scannedOutputLocations.add(outputLocation)) { // Skip the output folder if we've already scanned it continue; } IFolder outputFolder = ResourcesPlugin.getWorkspace().getRoot().getFolder(outputLocation); if (outputFolder.exists()) { outputFolder.accept(new IResourceProxyVisitor() { public boolean visit(IResourceProxy proxy) throws CoreException { if (proxy.getType() != IResource.FILE) { return true; } if (JavaUtilities.isClassFileName(proxy.getName())) { IResource classFile = proxy.requestResource(); IPath javaFilePath = computeJavaFilePath(classFile.getFullPath()); if (shouldEnhanceClass(javaFilePath)) { pathsToEnhance.add(computeEnhancementPathFromClassFile(classFile)); } } return false; } }, 0); } } return pathsToEnhance; }
From source file:com.google.appengine.eclipse.core.orm.enhancement.AutoEnhancer.java
License:Open Source License
/** * Determines the path of the Java source file that produced the given class * file path. We don't know which source folder contains the original Java * source, so we'll just try each of them until we find it. * /*from w w w .j a v a2 s . c o m*/ * @return the path of the Java source file, or <code>null</code> if a * corresponding Java source file could not be found under any of the * project's source folders. */ private IPath computeJavaFilePath(IPath classFilePath) throws JavaModelException { for (IClasspathEntry classpathEntry : javaProject.getRawClasspath()) { if (classpathEntry.getEntryKind() != IClasspathEntry.CPE_SOURCE) { // Skip any classpath entry that is not a source entry continue; } IPath outputLocation = getOutputLocation(classpathEntry, javaProject.getOutputLocation()); IPath javaFilePath = computeJavaFilePath(classFilePath, outputLocation, classpathEntry.getPath()); if (javaFilePath != null && ResourcesPlugin.getWorkspace().getRoot().findMember(javaFilePath) != null) { return javaFilePath; } } AppEngineCorePluginLog.logWarning("Could not find Java source for class file " + classFilePath.toString()); return null; }