List of usage examples for org.eclipse.jdt.core IClasspathEntry getPath
IPath getPath();
From source file:com.tasktop.dropwizard.launcher.DropwizardRuntimeClasspathProvider.java
License:Open Source License
protected void addProjectEntries(Set<IRuntimeClasspathEntry> resolved, IPath path, int scope, String classifier, ILaunchConfiguration launchConfiguration, final IProgressMonitor monitor) throws CoreException { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject project = root.getProject(path.segment(0)); IMavenProjectFacade projectFacade = projectManager.create(project, monitor); if (projectFacade == null) { return;/*www . j a v a 2 s .c om*/ } ResolverConfiguration configuration = projectFacade.getResolverConfiguration(); if (configuration == null) { return; } IJavaProject javaProject = JavaCore.create(project); boolean projectResolved = false; for (IClasspathEntry entry : javaProject.getRawClasspath()) { IRuntimeClasspathEntry rce = null; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: if (!projectResolved) { IMavenClassifierManager mavenClassifierManager = MavenJdtPlugin.getDefault() .getMavenClassifierManager(); IClassifierClasspathProvider classifierClasspathProvider = mavenClassifierManager .getClassifierClasspathProvider(projectFacade, classifier); if (IClasspathManager.CLASSPATH_TEST == scope) { classifierClasspathProvider.setTestClasspath(resolved, projectFacade, monitor); } else { classifierClasspathProvider.setRuntimeClasspath(resolved, projectFacade, monitor); } projectResolved = true; } break; case IClasspathEntry.CPE_CONTAINER: IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject); if (container != null && !MavenClasspathHelpers.isMaven2ClasspathContainer(entry.getPath())) { switch (container.getKind()) { case IClasspathContainer.K_APPLICATION: rce = JavaRuntime.newRuntimeContainerClasspathEntry(container.getPath(), IRuntimeClasspathEntry.USER_CLASSES, javaProject); break; default: break; } } break; case IClasspathEntry.CPE_LIBRARY: rce = JavaRuntime.newArchiveRuntimeClasspathEntry(entry.getPath()); break; case IClasspathEntry.CPE_VARIABLE: if (!JavaRuntime.JRELIB_VARIABLE.equals(entry.getPath().segment(0))) { rce = JavaRuntime.newVariableRuntimeClasspathEntry(entry.getPath()); } break; case IClasspathEntry.CPE_PROJECT: IProject res = root.getProject(entry.getPath().segment(0)); if (res != null) { IJavaProject otherProject = JavaCore.create(res); if (otherProject != null) { rce = JavaRuntime.newDefaultProjectClasspathEntry(otherProject); } } break; default: break; } if (rce != null) { addStandardClasspathEntries(resolved, rce, launchConfiguration); } } }
From source file:com.temenos.ds.op.xtext.ui.internal.se.JdtBasedProcessorProvider.java
License:Open Source License
protected URLClassLoader createClassLoaderForJavaProject(final IJavaProject projectToUse) { try {//from w w w . ja v a 2 s . c o m final IClasspathEntry[] resolvedClasspath = projectToUse.getResolvedClasspath(true); final List<URL> urls = CollectionLiterals.<URL>newArrayList(); List<URL> _outputFolders = this.getOutputFolders(projectToUse); urls.addAll(_outputFolders); for (final IClasspathEntry entry : resolvedClasspath) { { URL url = null; int _entryKind = entry.getEntryKind(); switch (_entryKind) { case IClasspathEntry.CPE_SOURCE: break; case IClasspathEntry.CPE_PROJECT: IPath path = entry.getPath(); IWorkspaceRoot _workspaceRoot = this.getWorkspaceRoot(projectToUse); final IResource project = _workspaceRoot.findMember(path); IProject _project = project.getProject(); IJavaProject _create = JavaCore.create(_project); List<URL> _outputFolders_1 = this.getOutputFolders(_create); urls.addAll(_outputFolders_1); break; case IClasspathEntry.CPE_LIBRARY: IPath path_1 = entry.getPath(); IWorkspaceRoot _workspaceRoot_1 = this.getWorkspaceRoot(projectToUse); final IResource library = _workspaceRoot_1.findMember(path_1); URL _xifexpression = null; boolean _notEquals = (!Objects.equal(library, null)); if (_notEquals) { URI _rawLocationURI = library.getRawLocationURI(); _xifexpression = _rawLocationURI.toURL(); } else { File _file = path_1.toFile(); URI _uRI = _file.toURI(); _xifexpression = _uRI.toURL(); } url = _xifexpression; break; default: { IPath path_2 = entry.getPath(); File _file_1 = path_2.toFile(); URI _uRI_1 = _file_1.toURI(); URL _uRL = _uRI_1.toURL(); url = _uRL; } break; } boolean _notEquals_1 = (!Objects.equal(url, null)); if (_notEquals_1) { urls.add(url); } } } ClassLoader _parentClassLoader = this.getParentClassLoader(); return new URLClassLoader(((URL[]) Conversions.unwrapArray(urls, URL.class)), _parentClassLoader); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
From source file:com.threecrickets.creel.eclipse.internal.EclipseUtil.java
License:LGPL
/** * Gets a classpath container from a project. (Assumes that the path is only * used once.)//from w w w.j a va2 s .com * * @param project * The project * @param path * The path * @return The classpath container or null * @throws JavaModelException * In case of an Eclipse JDT error */ public static IClasspathContainer getClasspathContainer(IJavaProject project, IPath path) throws JavaModelException { IClasspathEntry[] entries = project.getRawClasspath(); for (IClasspathEntry entry : entries) if ((entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) && (entry.getPath().equals(path))) return (IClasspathContainer) entry; return null; }
From source file:com.threecrickets.creel.eclipse.internal.EclipseUtil.java
License:LGPL
/** * Sets a classpath container in a project. If the classpath container is * already there, will recreate it. (Assumes that the path is only used * once.)//www .j a v a 2s . c o m * * @param project * The project * @param container * The classpath container * @throws JavaModelException * In case of an Eclipse JDT error */ public static void setClasspathContainer(IJavaProject project, IClasspathContainer container) throws JavaModelException { IPath path = container.getPath(); IClasspathEntry[] entries = project.getRawClasspath(); int found = -1; for (int i = 0, length = entries.length; i < length; i++) { IClasspathEntry entry = entries[i]; if ((entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) && (entry.getPath().equals(path))) { found = i; break; } } if (found == -1) { IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1]; System.arraycopy(entries, 0, newEntries, 0, entries.length); newEntries[entries.length] = JavaCore.newContainerEntry(container.getPath()); project.setRawClasspath(newEntries, null); } else { entries[found] = JavaCore.newContainerEntry(path); project.setRawClasspath(entries, null); } JavaCore.setClasspathContainer(Classpath.PATH, new IJavaProject[] { project }, new IClasspathContainer[] { container }, null); }
From source file:com.threecrickets.creel.eclipse.internal.EclipseUtil.java
License:LGPL
/** * Removes a classpath container from project if it is there. (Assumes that * the path is only used once.)// ww w. jav a 2 s .com * * @param project * The project * @param path * The path * @throws JavaModelException * In case of an Eclipse JDT error */ public static void removeClasspathContainer(IJavaProject project, IPath path) throws JavaModelException { IClasspathEntry[] entries = project.getRawClasspath(); int found = -1; for (int i = 0, length = entries.length; i < length; i++) { IClasspathEntry entry = entries[i]; if ((entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) && (entry.getPath().equals(path))) { found = i; break; } } if (found != -1) { IClasspathEntry[] newEntries = new IClasspathEntry[entries.length - 1]; System.arraycopy(entries, 0, newEntries, 0, found); if (found != entries.length) System.arraycopy(entries, found + 1, newEntries, found, entries.length - found - 1); project.setRawClasspath(newEntries, null); } }
From source file:com.vmware.vfabric.ide.eclipse.tcserver.internal.core.TcServerRuntimeClasspathProviderTest.java
License:Open Source License
private void assertHasServletApi(IPath path, IClasspathEntry[] cp) { boolean hasServlet = false; for (IClasspathEntry entry : cp) { assertTrue("Expected entry to start with '" + path + "', got '" + entry.getPath() + "'", path.isPrefixOf(entry.getPath())); if (entry.getPath().toString().endsWith("servlet-api.jar")) { hasServlet = true;//ww w . jav a 2 s .c o m } } if (!hasServlet) { fail("Expected servlet-api.jar in '" + Arrays.asList(cp) + "'"); } }
From source file:com.windowtester.codegen.util.BuildPathUtil.java
License:Open Source License
public static IClasspathEntry getRuntimeContainerEntry(IJavaProject targetProject) throws JavaModelException { // add WindowTester Runtime Classpath container and give it to handle all dependencies IClasspathEntry entry = JavaCore.newContainerEntry(new Path(CLASSPATH_CONTAINER_ID), false); IClasspathEntry[] entries = BuildPathUtil.getRuntimeClasspathEntries(targetProject); JavaCore.setClasspathContainer(entry.getPath(), new IJavaProject[] { targetProject }, new IClasspathContainer[] { new RuntimeClasspathContainer(entries, entry.getPath()) }, null); return entry; }
From source file:com.windowtester.eclipse.ui.convert.WTAPIUsage.java
License:Open Source License
private void collectPluginsReferencedByClasspathEntry(PrintWriter writer, Collection<String> pluginIds, IJavaProject proj, IClasspathEntry entry) throws IOException { IPath path = entry.getPath(); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_VARIABLE: for (int i = path.segmentCount() - 1; i >= 0; i--) { String segment = path.segment(i); if (segment.startsWith("com.windowtester.")) { String id = segment; i++;//ww w .j a va 2 s . c om while (i < path.segmentCount()) id += "/" + path.segment(i++); pluginIds.add(id); break; } } break; case IClasspathEntry.CPE_CONTAINER: if (path.segmentCount() >= 1 && path.segment(0).equals("org.eclipse.pde.core.requiredPlugins")) collectPluginsReferencedInManifest(pluginIds, proj); break; case IClasspathEntry.CPE_SOURCE: case IClasspathEntry.CPE_PROJECT: // ignored break; default: pluginIds.add("unknown " + entry.getEntryKind() + " - " + entry); break; } }
From source file:com.windowtester.eclipse.ui.wizard.NewExampleProjectWizard.java
License:Open Source License
private void importProject(String projectName, IProgressMonitor monitor) throws CoreException { final IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IProject project = workspace.getRoot().getProject(projectName); IProjectDescription description = workspace.newProjectDescription(projectName); description.setLocation(null);/*from www. ja va 2 s . co m*/ project.create(description, new SubProgressMonitor(monitor, 1)); project.open(new SubProgressMonitor(monitor, 1)); // Direct ECLIPSE_HOME references are different each Eclipse installation // so adjust the classpath accordingly IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] classpath = javaProject.getRawClasspath(); boolean modified = false; for (int i = 0; i < classpath.length; i++) { IClasspathEntry entry = classpath[i]; if (entry.getEntryKind() != IClasspathEntry.CPE_VARIABLE) continue; IPath path = entry.getPath(); if (path.segmentCount() != 3) continue; if (!path.segment(0).equals("ECLIPSE_HOME")) continue; if (!path.segment(1).equals("plugins")) continue; String jarName = path.segment(2); path = path.removeLastSegments(1); IPath pluginsPath = JavaCore.getResolvedVariablePath(path); if (pluginsPath == null) { Logger.log("Failed to resolve " + path); continue; } File pluginsDir = pluginsPath.toFile(); String jarPrefix = jarName.substring(0, jarName.indexOf('_') + 1); String[] childNames = pluginsDir.list(); if (childNames == null) { Logger.log("Failed to obtain children for " + pluginsDir.getPath()); continue; } for (int j = 0; j < childNames.length; j++) { String name = childNames[j]; if (name.startsWith(jarPrefix)) { modified = true; classpath[i] = JavaCore.newVariableEntry(path.append(name), null, null); break; } } } if (modified) javaProject.setRawClasspath(classpath, new NullProgressMonitor()); }
From source file:com.windowtester.swt.codegen.wizards.NewTestTypeWizard.java
License:Open Source License
private void updateClasspath(IResource resource) { try {/*from www . j av a 2 s . c o m*/ if (_wizardPage.isRcpApplication()) { IPath requiredPluginsPath = new Path("org.eclipse.pde.core.requiredPlugins"); IJavaProject javaProject = JavaCore.create(resource.getProject()); IClasspathEntry[] entries = javaProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (entry.getPath().equals(requiredPluginsPath)) { return; // no need to process } } } IClasspathEntry requiredPlugins = JavaCore.newContainerEntry(requiredPluginsPath); IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1]; System.arraycopy(entries, 0, newEntries, 0, entries.length); newEntries[entries.length] = requiredPlugins; javaProject.setRawClasspath(newEntries, null); } } catch (CoreException e) { Logger.log(e); } }