List of usage examples for org.eclipse.jdt.core IJavaProject getResolvedClasspath
IClasspathEntry[] getResolvedClasspath(boolean ignoreUnresolvedEntry) throws JavaModelException;
From source file:org.granite.builder.util.ProjectUtil.java
License:Open Source License
public static List<CpEntry> getFullResolvedClasspath(IJavaProject project) throws CoreException { return getFullClasspath(project, project.getResolvedClasspath(true)); }
From source file:org.hammurapi.eclipse.plugin.HammurapiBuilder.java
License:Open Source License
/** * @author Daniel Berg jdt-dev@eclipse.org. * @param javaProject/*w w w .j ava 2s . c om*/ * @return */ private List getClasspathURLs(IJavaProject javaProject, boolean exportedOnly) throws JavaModelException, MalformedURLException, CoreException { HashSet urls = new HashSet(); IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); boolean defaultOutputAdded = false; for (int i = 0; i < entries.length; i++) { // Source entries are apparently always assumed to be exported - but don't // report themselves as such. if (!exportedOnly || entries[i].isExported() || entries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { switch (entries[i].getEntryKind()) { case IClasspathEntry.CPE_SOURCE: { IPath outputLocation = null; if (isEclipse_2_1_Safe()) { outputLocation = entries[i].getOutputLocation(); } if (outputLocation == null) { // // If the output location is null then the project's // default output location is being used. // if (!defaultOutputAdded) { defaultOutputAdded = true; outputLocation = javaProject.getOutputLocation(); } } if (outputLocation != null) { // When the output location is the project itself, the project // can't resolve the file - therefore just get the project's // location. if (outputLocation.segmentCount() == 1) { outputLocation = javaProject.getProject().getLocation(); } else { // Output locations are always workspace relative. Do this mess // to get a fully qualified location. outputLocation = javaProject.getProject().getParent().getFile(outputLocation) .getLocation(); } urls.add(outputLocation.addTrailingSeparator().toFile().toURL()); } break; } case IClasspathEntry.CPE_LIBRARY: { // Jars always come with a nice fully specified path. urls.add(new URL("file:/" + entries[i].getPath().toOSString())); break; } case IClasspathEntry.CPE_PROJECT: { IJavaProject dependentProject = (IJavaProject) (ResourcesPlugin.getWorkspace().getRoot() .getProject(entries[i].getPath().segment(0))).getAdapter(IJavaElement.class); urls.addAll(getClasspathURLs(dependentProject, true)); break; } default: { String msg = "Encountered unexpected classpath entry : " + entries[i].getEntryKind(); HammurapiPlugin.report2LogError(msg, null); Status status = new Status(IStatus.ERROR, "HammurapiPlugin", IStatus.ERROR, msg, null); throw new CoreException(status); } } } } return new ArrayList(urls); }
From source file:org.hibernate.eclipse.console.utils.ClassLoaderHelper.java
License:Open Source License
static public List<URL> getProjectClassPathURLs(IJavaProject project) { List<URL> pathElements = new ArrayList<URL>(); try {// www . jav a2 s.co m IClasspathEntry paths[] = project.getResolvedClasspath(true); if (paths != null) { for (int i = 0; i < paths.length; i++) { IClasspathEntry path = paths[i]; if (path.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath simplePath = path.getPath(); URL url = getRawLocationURL(simplePath); pathElements.add(url); } } } IPath location = getProjectLocation(project.getProject()); IPath outputPath = location.append(project.getOutputLocation().removeFirstSegments(1)); pathElements.add(outputPath.toFile().toURI().toURL()); } catch (JavaModelException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } return pathElements; }
From source file:org.infinitest.eclipse.workspace.JavaProjectTestSupport.java
License:Open Source License
public static void expectClasspathFor(IJavaProject project, IClasspathEntry... entries) throws JavaModelException { when(project.getResolvedClasspath(true)).thenReturn(entries); }
From source file:org.jactr.eclipse.core.parser.ProjectSensitiveParserImportDelegate.java
License:Open Source License
@Override public URL resolveURL(String url, URL baseURL) { try {/*from www .j ava 2s . co m*/ IJavaProject javaProject = JavaCore.create(_project); IClasspathEntry[] entries = javaProject.getResolvedClasspath(false); for (IClasspathEntry entry : entries) if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT && entry.getContentKind() == IPackageFragmentRoot.K_SOURCE) { IPath path = entry.getPath(); if (LOGGER.isDebugEnabled()) LOGGER.debug("checking " + entry + " at " + path); IProject tmpProject = ResourcesPlugin.getWorkspace().getRoot().getProject(path.lastSegment()); IFolder modelsFolder = tmpProject.getFolder("models"); if (modelsFolder == null || !modelsFolder.exists()) continue; IFile modelFile = modelsFolder.getFile(url); if (modelFile == null || !modelFile.exists()) continue; // CorePlugin.debug("Found a matching file at " // + modelFile.getFullPath()); if (javaProject.isOnClasspath(modelFile)) { if (LOGGER.isDebugEnabled()) LOGGER.debug("Is on classpath, returning url"); URL rtn = modelFile.getLocation().toFile().toURI().toURL(); // CorePlugin.debug(String.format("On path at %s", // rtn.toExternalForm())); return rtn; } else if (LOGGER.isDebugEnabled()) LOGGER.debug("is not on classpath"); } } catch (Exception e) { CorePlugin.error("Failed to extract location info for " + url, e); } return super.resolveURL(url, baseURL); }
From source file:org.jactr.eclipse.runtime.ui.tabs.normal.StartStopTab.java
License:Open Source License
private void testProject(String className, ILaunchConfiguration configuration) throws ClassNotFoundException, IllegalArgumentException { try {//from www. j a v a 2 s. c o m IProject project = ACTRLaunchConfigurationUtils.getProject(configuration); IJavaProject jProject = JavaCore.create(project); IType type = jProject.findType(className); if (type == null) { RuntimePlugin.info("Could not find " + className + " on classpath of " + project.getName() + ". Checked : " + Arrays.toString(jProject.getResolvedClasspath(false))); throw new ClassNotFoundException(); } } catch (CoreException ce) { throw new IllegalArgumentException(); } }
From source file:org.jboss.ide.eclipse.as.test.classpath.JBIDE1657Test.java
License:Open Source License
public void testJBIDE1657() { try {/* w ww . j av a 2 s . c om*/ IJavaProject jp = JavaCore.create(project); // lets try a runtime IRuntime createdRuntime = ProjectRuntimeUtil.createRuntime("runtime1", IJBossToolingConstants.AS_42, ASTest.JBOSS_AS_HOME); ProjectRuntimeUtil.setTargetRuntime(createdRuntime, project); IClasspathEntry[] raw1 = jp.getRawClasspath(); IClasspathEntry[] resolved1 = jp.getResolvedClasspath(false); IClasspathEntry[] raw2 = new IClasspathEntry[raw1.length]; for (int i = 0; i < raw1.length; i++) { if (!raw1[i].getPath().segment(0).equals("org.eclipse.jst.server.core.container")) { raw2[i] = raw1[i]; } else { IPath containerPath = new Path( "org.jboss.ide.eclipse.as.classpath.core.runtime.ProjectRuntimeInitializer"); containerPath = containerPath.append("runtime1"); raw2[i] = JavaCore.newContainerEntry(containerPath); } } jp.setRawClasspath(raw2, new NullProgressMonitor()); IClasspathEntry[] resolved2 = jp.getResolvedClasspath(false); assertEquals("New classpath container path should return the same classpath entries as the old. ", resolved1.length, resolved2.length); assertTrue("Should be more than one classpath entry", resolved1.length > 0); } catch (CoreException ce) { ce.printStackTrace(); fail(ce.getMessage()); } }
From source file:org.jboss.ide.eclipse.as.test.classpath.JEEClasspathContainerTest.java
License:Open Source License
protected void testGenericClasspathContainer(String containerPath, int expectedEntries) { try {//from www . jav a 2s . c o m IJavaProject jproject = JavaCore.create(project); IPath path = new Path(containerPath); verifyContainerEntries(path, jproject, expectedEntries); verifyRawClasspathCount(jproject, ORIGINAL_ENTRIES); verifyNotIncludedEntry(jproject, path); int beforeRawCount = jproject.getRawClasspath().length; int beforeResolvedCount = jproject.getResolvedClasspath(true).length; addContainer(jproject, path); assertEquals(beforeRawCount + 1, jproject.getRawClasspath().length); assertEquals(beforeResolvedCount + expectedEntries, jproject.getResolvedClasspath(true).length); beforeRawCount = jproject.getRawClasspath().length; beforeResolvedCount = jproject.getResolvedClasspath(true).length; removeContainer(jproject, path); assertEquals(beforeRawCount - 1, jproject.getRawClasspath().length); assertEquals(beforeResolvedCount - expectedEntries, jproject.getResolvedClasspath(true).length); } catch (JavaModelException jme) { fail("Exception: " + jme.getMessage()); } catch (CoreException ce) { fail("Exception: " + ce.getMessage()); } }
From source file:org.jboss.ide.eclipse.as.test.classpath.ProjectRuntimeTest.java
License:Open Source License
protected void verifyPostRuntimeCPE(IJavaProject jp) throws CoreException { IClasspathEntry[] entries = jp.getRawClasspath(); assertEquals(4, entries.length);//w w w .ja v a 2 s.com jp.getResolvedClasspath(false); // make sure it can resolve all String[] required = new String[] { "org.eclipse.jst.server.core.container", "basicwebproject", "org.eclipse.jst.j2ee.internal.web.container", "org.eclipse.jdt.launching.JRE_CONTAINER" }; verifyClasspathEntries(entries, required); }
From source file:org.jboss.ide.eclipse.as.test.classpath.ProjectRuntimeTest.java
License:Open Source License
protected void verifyInitialClasspathEntries(IJavaProject jp) throws CoreException { IClasspathEntry[] entries = jp.getRawClasspath(); jp.getResolvedClasspath(false); // make sure it can resolve all String[] required = new String[] { "org.eclipse.jst.j2ee.internal.web.container", "basicwebproject" }; verifyClasspathEntries(entries, required); }