List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE
int CPE_SOURCE
To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE.
Click Source Link
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/* ww w. jav a 2s. c om*/ * @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.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; }/*from w ww . j ava2s.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);//ww w .j av a2s. c o m } } 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. * /*w w w. ja va 2s .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; }
From source file:com.google.devtools.bazel.e4b.BazelProjectSupport.java
License:Open Source License
/** * Convert an Eclipse JDT project into an IntelliJ project view *//*from ww w . j a va2 s. c o m*/ public static ProjectView getProjectView(IProject project) throws BackingStoreException, JavaModelException { com.google.devtools.bazel.e4b.projectviews.Builder builder = ProjectView.builder(); IScopeContext projectScope = new ProjectScope(project); Preferences projectNode = projectScope.getNode(Activator.PLUGIN_ID); for (String s : projectNode.keys()) { if (s.startsWith("buildArgs")) { builder.addBuildFlag(projectNode.get(s, "")); } else if (s.startsWith("target")) { builder.addTarget(projectNode.get(s, "")); } } IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); for (IClasspathEntry entry : ((IJavaProject) project).getRawClasspath()) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: IResource res = root.findMember(entry.getPath()); if (res != null) { builder.addDirectory(res.getProjectRelativePath().removeFirstSegments(1).toOSString()); } break; case IClasspathEntry.CPE_CONTAINER: String path = entry.getPath().toOSString(); if (path.startsWith(STANDARD_VM_CONTAINER_PREFIX)) { builder.setJavaLanguageLevel( Integer.parseInt(path.substring(STANDARD_VM_CONTAINER_PREFIX.length()))); } break; } } return builder.build(); }
From source file:com.google.gdt.eclipse.designer.wizards.ui.JUnitWizardPage.java
License:Open Source License
private IPackageFragmentRoot handleTestSourceFolder(IJavaProject javaProject) throws Exception { String testSourceFolderName = com.google.gdt.eclipse.designer.Activator.getStore() .getString(Constants.P_GWT_TESTS_SOURCE_FOLDER); IFolder testSourceFolder = javaProject.getProject().getFolder(testSourceFolderName); IPackageFragmentRoot testSourceFragmentRoot = (IPackageFragmentRoot) JavaCore.create(testSourceFolder); // check create if (!testSourceFolder.exists() || testSourceFragmentRoot == null || !testSourceFragmentRoot.exists()) { // create folder if (!testSourceFolder.exists()) { testSourceFolder.create(true, false, null); }//from w ww . jav a 2s . c o m IClasspathEntry[] classpath = javaProject.getRawClasspath(); // find last source entry int insertIndex = -1; for (int i = 0; i < classpath.length; i++) { if (classpath[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { insertIndex = i + 1; } } // insert new source to entries IClasspathEntry testSourceEntry = JavaCore.newSourceEntry(testSourceFolder.getFullPath()); if (insertIndex == -1) { classpath = (IClasspathEntry[]) ArrayUtils.add(classpath, testSourceEntry); } else { classpath = (IClasspathEntry[]) ArrayUtils.add(classpath, insertIndex, testSourceEntry); } // modify classpath javaProject.setRawClasspath(classpath, javaProject.getOutputLocation(), null); testSourceFragmentRoot = (IPackageFragmentRoot) JavaCore.create(testSourceFolder); } // setPackageFragmentRoot(testSourceFragmentRoot, true); return testSourceFragmentRoot; }
From source file:com.google.gwt.eclipse.core.GWTProjectUtilities.java
License:Open Source License
/** * Returns the GWT-applicable source folder paths from a project (note: this * will not traverse into the project's dependencies, for this behavior, see * {@link #getGWTSourceFolderPathsFromProjectAndDependencies(IJavaProject, boolean)} * )./*from w w w.j a v a 2 s .c o m*/ * * @param javaProject Reference to the project * @param sourceEntries The list to be filled with the entries corresponding * to the source folder paths * @param includeTestSourceEntries Whether to include the entries for test * source * @throws SdkException */ private static void fillGWTSourceFolderPathsFromProject(IJavaProject javaProject, Collection<? super IRuntimeClasspathEntry> sourceEntries, boolean includeTestSourceEntries) throws SdkException { assert (javaProject != null); if (GWTProjectsRuntime.isGWTRuntimeProject(javaProject)) { // TODO: Do we still need to handle this here since Sdk's report their // own runtime classpath entries? sourceEntries.addAll( GWTProjectsRuntime.getGWTRuntimeProjectSourceEntries(javaProject, includeTestSourceEntries)); } else { try { for (IClasspathEntry curClasspathEntry : javaProject.getRawClasspath()) { if (curClasspathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath sourcePath = curClasspathEntry.getPath(); // If including tests, include all source, or if not including tests, ensure // it is not a test path if (includeTestSourceEntries || !GWTProjectUtilities.isTestPath(sourcePath)) { if (!isOptional(curClasspathEntry) || exists(sourcePath)) { sourceEntries.add(JavaRuntime.newArchiveRuntimeClasspathEntry(sourcePath)); } } } } IFolder folder = javaProject.getProject().getFolder("super"); if (folder.exists()) { sourceEntries.add(JavaRuntime.newArchiveRuntimeClasspathEntry(folder.getFullPath())); } } catch (JavaModelException jme) { GWTPluginLog.logError(jme, "Unable to retrieve raw classpath for project " + javaProject.getProject().getName()); } } }
From source file:com.google.gwt.eclipse.core.launch.processors.codeserver.SuperDevModeSrcArgumentProcessor.java
License:Open Source License
/** * Get the class path entries that are the source. * * @param javaProject the java project.//from w ww. j av a2s . c o m * @param entry classpath entry value. * @return the path. */ private String getPathIfDir(IJavaProject javaProject, IClasspathEntry entry) { IPath p = entry.getPath(); String projectName = javaProject.getProject().getName(); String path = null; // src directories don't have an output // cpe source are src,test directories if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE && (entry.getOutputLocation() == null || (entry.getOutputLocation() != null && !entry.getOutputLocation().lastSegment().toString().equals("test-classes")))) { String dir = p.toString(); // if the base segment has the project name, // lets remove that so its relative to project if (dir.contains(projectName)) { IPath relative = p.removeFirstSegments(1); path = relative.toString(); } } return path; }
From source file:com.google.gwt.eclipse.core.runtime.GWTProjectsRuntime.java
License:Open Source License
/** * FIXME - Were it not for the super source stuff, we would need this method. Can't we provide a * way for users to state which folders are super-source, etc? *//*from w w w .j av a2 s . c om*/ public static List<IRuntimeClasspathEntry> getGWTRuntimeProjectSourceEntries(IJavaProject project, boolean includeTestSourceEntries) throws SdkException { assert (isGWTRuntimeProject(project) && project.exists()); String projectName = project.getProject().getName(); List<IRuntimeClasspathEntry> sourceEntries = new ArrayList<IRuntimeClasspathEntry>(); IClasspathEntry[] gwtUserJavaProjClasspathEntries = null; try { gwtUserJavaProjClasspathEntries = project.getRawClasspath(); } catch (JavaModelException e) { throw new SdkException("Cannot extract raw classpath from " + projectName + " project."); } Set<IPath> absoluteSuperSourcePaths = new HashSet<IPath>(); for (IClasspathEntry curClasspathEntry : gwtUserJavaProjClasspathEntries) { if (curClasspathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath sourcePath = curClasspathEntry.getPath(); if (isJavadocPath(sourcePath)) { // Ignore javadoc paths. continue; } if (GWTProjectUtilities.isTestPath(sourcePath) && !includeTestSourceEntries) { // Ignore test paths, unless it is specified explicitly that we should // include them. continue; } sourceEntries.add(JavaRuntime.newArchiveRuntimeClasspathEntry(sourcePath)); // Figure out the location of the super source path. IPath absoluteSuperSourcePath = sourcePath.removeLastSegments(1).append(SUPER_SOURCE_FOLDER_NAME); IPath relativeSuperSourcePath = absoluteSuperSourcePath.removeFirstSegments(1); if (absoluteSuperSourcePaths.contains(absoluteSuperSourcePath)) { // I've already included this path. continue; } if (project.getProject().getFolder(relativeSuperSourcePath).exists()) { /* * We've found the super source path, and we've not added it already. The existence test * uses a relative path, but the creation of a runtime classpath entry requires an * absolute path. */ sourceEntries.add(JavaRuntime.newArchiveRuntimeClasspathEntry(absoluteSuperSourcePath)); absoluteSuperSourcePaths.add(absoluteSuperSourcePath); } IPath absoluteTestSuperSourcePath = sourcePath.removeLastSegments(1) .append(TEST_SUPER_SOURCE_FOLDER_NAME); IPath relativeTestSuperSourcePath = absoluteTestSuperSourcePath.removeFirstSegments(1); if (absoluteSuperSourcePaths.contains(absoluteTestSuperSourcePath)) { // I've already included this path. continue; } if (includeTestSourceEntries && project.getProject().getFolder(relativeTestSuperSourcePath).exists()) { /* * We've found the super source path, and we've not added it already. The existence test * uses a relative path, but the creation of a runtime classpath entry requires an * absolute path. */ sourceEntries.add(JavaRuntime.newArchiveRuntimeClasspathEntry(absoluteTestSuperSourcePath)); absoluteSuperSourcePaths.add(absoluteTestSuperSourcePath); } } } if (absoluteSuperSourcePaths.isEmpty()) { GWTPluginLog.logError("There were no super source folders found for the project '{0}'", project.getProject().getName()); } return sourceEntries; }