List of usage examples for org.eclipse.jdt.core IClasspathEntry getEntryKind
int getEntryKind();
From source file:com.google.cloud.tools.eclipse.appengine.libraries.persistence.LibraryClasspathContainerSerializerTest.java
License:Apache License
private void compare(LibraryClasspathContainer container, LibraryClasspathContainer otherContainer) { assertEquals(container.getPath(), otherContainer.getPath()); assertEquals(container.getKind(), otherContainer.getKind()); assertEquals(container.getDescription(), otherContainer.getDescription()); for (int i = 0; i < container.getClasspathEntries().length; i++) { IClasspathEntry classpathEntry = container.getClasspathEntries()[i]; IClasspathEntry otherClasspathEntry = otherContainer.getClasspathEntries()[i]; assertEquals(classpathEntry.getPath(), otherClasspathEntry.getPath()); assertEquals(classpathEntry.getEntryKind(), otherClasspathEntry.getEntryKind()); assertEquals(classpathEntry.getSourceAttachmentPath(), otherClasspathEntry.getSourceAttachmentPath()); assertEquals(classpathEntry.isExported(), otherClasspathEntry.isExported()); for (int j = 0; j < classpathEntry.getAccessRules().length; j++) { IAccessRule accessRule = classpathEntry.getAccessRules()[j]; IAccessRule otherAccessRule = otherClasspathEntry.getAccessRules()[j]; assertEquals(accessRule.getKind(), otherAccessRule.getKind()); assertEquals(accessRule.getPattern(), otherAccessRule.getPattern()); }/* w ww . ja va 2 s . c om*/ for (int k = 0; k < classpathEntry.getExtraAttributes().length; k++) { IClasspathAttribute classpathAttribute = classpathEntry.getExtraAttributes()[k]; IClasspathAttribute otherClasspathAttribute = otherClasspathEntry.getExtraAttributes()[k]; assertEquals(classpathAttribute.getName(), otherClasspathAttribute.getName()); assertEquals(classpathAttribute.getValue(), otherClasspathAttribute.getValue()); } } }
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 w w w .j ava2 s . co 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.appengine.rpc.wizards.helpers.RpcServiceLayerCreator.java
License:Open Source License
private String getGwtContainerPath(IJavaProject javaProject) throws CoreException { IClasspathEntry[] entries = null;/*from w w w . j a va2 s. c o m*/ entries = javaProject.getRawClasspath(); for (IClasspathEntry entry : entries) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && entry.getPath().toString().equals("com.google.gwt.eclipse.core.GWT_CONTAINER")) { //$NON-NLS-N$ IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject); if (container instanceof GWTRuntimeContainer) { IPath path = ((GWTRuntimeContainer) container).getSdk().getInstallationPath(); return path.toString(); } } } // gwt not on classpath, add to it, set nature GWTRuntime gwt = GWTPreferences.getDefaultRuntime(); IPath containerPath = SdkClasspathContainer.computeContainerPath(GWTRuntimeContainer.CONTAINER_ID, gwt, SdkClasspathContainer.Type.DEFAULT); if (GaeNature.isGaeProject(javaProject.getProject())) { addClasspathContainer(javaProject, containerPath); GWTNature.addNatureToProject(javaProject.getProject()); } return gwt.getInstallationPath().toString(); }
From source file:com.google.gdt.eclipse.core.ClasspathUtilities.java
License:Open Source License
/** * Finds all the classpath containers in the specified project that match the * provided container ID./*from w ww . j a va 2 s .c o m*/ * * @param javaProject the project to query * @param containerId The container ID we are trying to match. * @return an array of matching classpath containers. */ public static IClasspathEntry[] findClasspathContainersWithContainerId(IJavaProject javaProject, final String containerId) throws JavaModelException { Predicate<IClasspathEntry> matchPredicate = new Predicate<IClasspathEntry>() { public boolean apply(IClasspathEntry entry) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IPath containerPath = entry.getPath(); if (containerPath.segmentCount() > 0 && containerPath.segment(0).equals(containerId)) { return true; } } return false; } }; IClasspathEntry[] classpathEntries = javaProject.getRawClasspath(); int matchCount = 0; for (int i = 0; i < classpathEntries.length; i++) { if (matchPredicate.apply(classpathEntries[i])) { matchCount++; } } IClasspathEntry[] matchingClasspathEntries = new IClasspathEntry[matchCount]; int matchingClasspathEntriesIdx = 0; for (int i = 0; i < classpathEntries.length; i++) { if (matchPredicate.apply(classpathEntries[i])) { matchingClasspathEntries[matchingClasspathEntriesIdx] = classpathEntries[i]; matchingClasspathEntriesIdx++; } } return matchingClasspathEntries; }
From source file:com.google.gdt.eclipse.core.ClasspathUtilities.java
License:Open Source License
/** * Returns the first index of the specified * {@link IClasspathEntry#CPE_CONTAINER} entry with the specified container ID * or -1 if one could not be found./*w ww . j a v a2s . c om*/ * * @param classpathEntries array of classpath entries * @param containerId container ID * @return index of the specified {@link IClasspathEntry#CPE_CONTAINER} entry * with the specified container ID or -1 */ public static int indexOfClasspathEntryContainer(IClasspathEntry[] classpathEntries, String containerId) { for (int i = 0; i < classpathEntries.length; ++i) { IClasspathEntry classpathEntry = classpathEntries[i]; if (classpathEntry.getEntryKind() != IClasspathEntry.CPE_CONTAINER) { // Skip anything that is not a container continue; } IPath containerPath = classpathEntry.getPath(); if (containerPath.segmentCount() > 0 && containerPath.segment(0).equals(containerId)) { return i; } } return -1; }
From source file:com.google.gdt.eclipse.core.markers.quickfixes.CopyToServerClasspathMarkerResolution.java
License:Open Source License
public void run(IMarker marker) { String buildClasspathFileName = buildClasspathFilePath.lastSegment(); IProject project = marker.getResource().getProject(); IPath projRelativeWebInfLibFolderPath = null; try {//from www .ja v a 2s . co m WebAppUtilities.verifyHasManagedWarOut(project); projRelativeWebInfLibFolderPath = WebAppUtilities.getWebInfLib(project).getProjectRelativePath(); ResourceUtils.createFolderStructure(project, projRelativeWebInfLibFolderPath); } catch (CoreException e) { CorePluginLog.logError(e); MessageDialog.openError(CorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(), "Error While Attempting to Copy " + buildClasspathFileName, "Unable to create <WAR>/WEB-INF/lib directory. See the Error Log for more details."); return; } IFolder webInfLibFolder = project.getFolder(projRelativeWebInfLibFolderPath); assert (webInfLibFolder.exists()); IFile serverClasspathFile = webInfLibFolder.getFile(buildClasspathFileName); try { serverClasspathFile.create(new FileInputStream(buildClasspathFilePath.toFile()), false, null); } catch (FileNotFoundException e) { MessageDialog.openError(CorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(), "Error While Attempting to Copy " + buildClasspathFileName, "The file " + buildClasspathFilePath.toOSString() + " does not exist."); return; } catch (CoreException e) { CorePluginLog.logError(e); MessageDialog.openError(CorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(), "Error While Attempting to Copy " + buildClasspathFileName, "Unable to copy " + buildClasspathFilePath.toOSString() + " to " + projRelativeWebInfLibFolderPath.toString() + ". See the Error Log for more details."); return; } // Update the project's classpath to use the file copied into // <WAR>/WEB-INF/lib IJavaProject javaProject = JavaCore.create(project); if (!JavaProjectUtilities.isJavaProjectNonNullAndExists(javaProject)) { MessageDialog.openError(CorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(), "Error While Attempting to Update Project Classpath", "Unable to update project " + project.getName() + "'s classpath."); return; } try { List<IClasspathEntry> newRawClasspath = new ArrayList<IClasspathEntry>(); for (IClasspathEntry entry : javaProject.getRawClasspath()) { IClasspathEntry resolvedEntry = JavaCore.getResolvedClasspathEntry(entry); IPath resolvedEntryPath = ResourceUtils.resolveToAbsoluteFileSystemPath(resolvedEntry.getPath()); if (resolvedEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && resolvedEntryPath.equals(buildClasspathFilePath)) { newRawClasspath.add(JavaCore.newLibraryEntry(serverClasspathFile.getFullPath(), null, null)); } else { newRawClasspath.add(entry); } } ClasspathUtilities.setRawClasspath(javaProject, newRawClasspath.toArray(new IClasspathEntry[0])); } catch (JavaModelException e) { CorePluginLog.logError(e); MessageDialog.openError(CorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(), "Error While Attempting to Update Project Classpath", "Unable to update project " + project.getName() + "'s classpath. See the Error Log for more details."); } }
From source file:com.google.gdt.eclipse.core.properties.ui.BuildpathJarSelectionDialog.java
License:Open Source License
/** * Returns the absolute file system paths of all JAR files on the project's * build classpath, which are not part of a classpath container. *///from w w w . j a va2s. c o m private List<IPath> getJarsOnBuildPath() { List<IPath> jars = new ArrayList<IPath>(); try { IClasspathEntry[] rawClasspaths = javaProject.getRawClasspath(); for (IClasspathEntry rawClasspath : rawClasspaths) { rawClasspath = JavaCore.getResolvedClasspathEntry(rawClasspath); if (rawClasspath.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath jarPath = ResourceUtils.resolveToAbsoluteFileSystemPath(rawClasspath.getPath()); jars.add(jarPath); } } } catch (JavaModelException e) { CorePluginLog.logError(e); } return jars; }
From source file:com.google.gdt.eclipse.core.sdk.ClasspathContainerUpdateJob.java
License:Open Source License
@Override protected IStatus run(IProgressMonitor jobMonitor) { try {//from w ww. j a v a 2 s .co m IWorkspaceRunnable runnable = new IWorkspaceRunnable() { public void run(IProgressMonitor runnableMonitor) throws CoreException { IJavaProject[] projects = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()) .getJavaProjects(); runnableMonitor.beginTask(LaunchingMessages.LaunchingPlugin_0, projects.length + 1); rebindContainers(runnableMonitor, projects); runnableMonitor.done(); } /** * Rebind all of the classpath containers whose comparison ID matches * the expected ID. */ private void rebindContainers(IProgressMonitor runnableMonitor, IJavaProject[] projects) throws CoreException { for (IJavaProject project : projects) { // Update the progress monitor runnableMonitor.worked(1); IClasspathEntry[] rawClasspathEntries = project.getRawClasspath(); for (IClasspathEntry rawClasspathEntry : rawClasspathEntries) { if (rawClasspathEntry.getEntryKind() != IClasspathEntry.CPE_CONTAINER) { continue; } IPath path = rawClasspathEntry.getPath(); if (path == null || path.segmentCount() == 0) { continue; } Object actualComparisonId = classpathContainerInitializer.getComparisonID(path, project); if (!actualComparisonId.equals(expectedComparisonId)) { continue; } classpathContainerInitializer.initialize(path, project); } } } }; JavaCore.run(runnable, null, jobMonitor); return Status.OK_STATUS; } catch (CoreException e) { return e.getStatus(); } }
From source file:com.google.gdt.eclipse.core.sdk.SdkClasspathContainer.java
License:Open Source License
/** * Returns <code>true</code> if the classpath entry is an * {@link IClasspathEntry#CPE_CONTAINER} and it has the specified container * ID.//from w ww. j a v a 2 s . c o m * * @param containerId * @param classpathEntry * @return whether the classpathEntry is a container and has the containerId */ public static boolean isContainerClasspathEntry(String containerId, IClasspathEntry classpathEntry) { if (classpathEntry.getEntryKind() != IClasspathEntry.CPE_CONTAINER) { return false; } return isContainerPath(containerId, classpathEntry.getPath()); }
From source file:com.google.gdt.eclipse.core.validators.WebAppProjectValidator.java
License:Open Source License
private boolean validateBuildClasspath(IJavaProject javaProject) throws CoreException { IPath webInfLibFolderLocation = null; IFolder webInfLibFolder = WebAppUtilities.getWebInfOut(getProject()).getFolder("lib"); if (webInfLibFolder.exists()) { webInfLibFolderLocation = webInfLibFolder.getLocation(); }//from w w w . j a va 2s .c o m IClasspathEntry[] rawClasspaths = javaProject.getRawClasspath(); boolean isOk = true; List<IPath> excludedJars = WebAppProjectProperties.getJarsExcludedFromWebInfLib(javaProject.getProject()); for (IClasspathEntry rawClasspath : rawClasspaths) { rawClasspath = JavaCore.getResolvedClasspathEntry(rawClasspath); if (rawClasspath.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath entryPath = ResourceUtils.resolveToAbsoluteFileSystemPath(rawClasspath.getPath()); if (excludedJars.contains(entryPath)) { continue; } if (webInfLibFolderLocation == null || !webInfLibFolderLocation.isPrefixOf(entryPath)) { MarkerUtilities.createQuickFixMarker(PROBLEM_MARKER_ID, ProjectStructureOrSdkProblemType.JAR_OUTSIDE_WEBINF_LIB, entryPath.toPortableString(), javaProject.getProject(), entryPath.toOSString()); isOk = false; } } } return isOk; }