List of usage examples for org.eclipse.jdt.core IClasspathEntry getPath
IPath getPath();
From source file:com.google.cloud.tools.eclipse.appengine.libraries.persistence.SerializableClasspathEntry.java
License:Apache License
public SerializableClasspathEntry(IClasspathEntry entry, IPath baseDirectory) { setAttributes(entry.getExtraAttributes()); setAccessRules(entry.getAccessRules()); setSourcePath(entry.getSourceAttachmentPath()); setPath(PathUtil.relativizePath(entry.getPath(), baseDirectory).toString()); }
From source file:com.google.cloud.tools.eclipse.appengine.libraries.repository.LibraryClasspathContainerResolverService.java
License:Apache License
public IStatus resolveAll(IJavaProject javaProject, IProgressMonitor monitor) { IStatus status = null;//w w w .j a v a2s.c om try { IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); SubMonitor subMonitor = SubMonitor.convert(monitor, Messages.getString("TaskResolveLibraries"), getTotalwork(rawClasspath)); for (IClasspathEntry classpathEntry : rawClasspath) { if (classpathEntry.getPath().segment(0).equals(Library.CONTAINER_PATH_PREFIX)) { status = StatusUtil.merge(status, resolveContainer(javaProject, classpathEntry.getPath(), subMonitor.newChild(1))); } } } catch (CoreException ex) { return StatusUtil.error(this, Messages.getString("TaskResolveLibrariesError"), ex); } return status == null ? Status.OK_STATUS : status; }
From source file:com.google.cloud.tools.eclipse.appengine.localserver.ServletClasspathProviderTest.java
License:Apache License
private Library getMockApi(String libraryId) throws LibraryRepositoryServiceException { Library servletApi = new Library(libraryId); LibraryFile libraryFile = mock(LibraryFile.class); servletApi.setLibraryFiles(Collections.singletonList(libraryFile)); IClasspathEntry classpathEntry = mock(IClasspathEntry.class); when(classpathEntry.getPath()).thenReturn(new Path("/path/to/" + libraryId + ".jar")); when(repositoryService.getLibraryClasspathEntry(libraryFile)).thenReturn(classpathEntry); return servletApi; }
From source file:com.google.cloud.tools.eclipse.appengine.newproject.CreateAppEngineStandardWtpProjectTest.java
License:Apache License
private void assertAppEngineContainerOnClasspath(Library library) throws CoreException { assertTrue(project.hasNature(JavaCore.NATURE_ID)); IJavaProject javaProject = JavaCore.create(project); for (IClasspathEntry iClasspathEntry : javaProject.getRawClasspath()) { if (iClasspathEntry.getPath().equals(library.getContainerPath())) { return; }//from w ww. ja va 2s . co m } fail("Classpath container " + APP_ENGINE_API + " was not added to the build path"); }
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 ww. j av a2 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;/* w w w . ja 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 av a 2 s . co 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 w w . ja va 2 s .c o m*/ * * @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.ClasspathUtilities.java
License:Open Source License
/** * Replace an {@link IClasspathEntry#CPE_CONTAINER} entry with the given * container ID, with its corresponding resolved classpath entries. * /*from w w w .j a v a 2 s.c o m*/ * @param javaProject java project * @param containerId container ID to replace * @return true if a container was replaced * * @throws JavaModelException */ public static boolean replaceContainerWithClasspathEntries(IJavaProject javaProject, String containerId) throws JavaModelException { IClasspathEntry[] classpathEntries = javaProject.getRawClasspath(); int containerIndex = ClasspathUtilities.indexOfClasspathEntryContainer(classpathEntries, containerId); if (containerIndex != -1) { List<IClasspathEntry> newClasspathEntries = new ArrayList<IClasspathEntry>( Arrays.asList(classpathEntries)); IClasspathEntry classpathContainerEntry = newClasspathEntries.remove(containerIndex); IClasspathContainer classpathContainer = JavaCore .getClasspathContainer(classpathContainerEntry.getPath(), javaProject); if (classpathContainer != null) { newClasspathEntries.addAll(containerIndex, Arrays.asList(classpathContainer.getClasspathEntries())); ClasspathUtilities.setRawClasspath(javaProject, newClasspathEntries); return true; } } return false; }
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 {//w ww. ja v a2s. 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."); } }