List of usage examples for org.eclipse.jdt.core IJavaProject getRawClasspath
IClasspathEntry[] getRawClasspath() throws JavaModelException;
From source file:com.google.gwt.eclipse.core.launch.processors.codeserver.SuperDevModeSrcArgumentProcessor.java
License:Open Source License
/** * Get a comma delimited list of the source directories relative to project. * * @param javaProject The java project./*from w w w .ja v a2 s. c o m*/ * @return csv of the source directories. */ private String getSrcDirectories(IJavaProject javaProject) { String src = ""; IClasspathEntry[] cp = null; try { cp = javaProject.getRawClasspath(); } catch (JavaModelException e) { e.printStackTrace(); } // TODO maybe do a constant or some better error // Something had to go wrong with class path entries if (cp == null || cp.length == 0) { return "REPLACE_ME_WITH_src_dir"; } for (int i = 0; i < cp.length; i++) { String path = getPathIfDir(javaProject, cp[i]); if (path != null && src.length() == 0) { src = path; } else if (path != null && src.length() > 0) { src = src + " -src " + path; } } // Something had to go wrong with the classpath entries, no source paths. if (src.length() == 0) { src = "REPLACE_ME_WITH_src_dir"; } return src; }
From source file:com.google.gwt.eclipse.core.runtime.AbstractGWTRuntimeTest.java
License:Open Source License
protected void addClasspathEntryToTestProject(IClasspathEntry entry) throws JavaModelException { IJavaProject project = getTestProject(); List<IClasspathEntry> cpEntries = new ArrayList<IClasspathEntry>(); cpEntries.addAll(Arrays.asList(project.getRawClasspath())); cpEntries.add(entry);/* ww w.j av a 2 s .c o m*/ ClasspathUtilities.setRawClasspath(project, cpEntries); JobsUtilities.waitForIdle(); }
From source file:com.google.gwt.eclipse.core.runtime.AbstractGWTRuntimeTest.java
License:Open Source License
protected void removeGWTRuntimeFromTestProject() throws Exception { IJavaProject project = getTestProject(); // Replace GWT runtime classpath entry with gwt-user.jar and // gwt-dev-PLAT.jar List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>(); for (IClasspathEntry entry : project.getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (GWTRuntimeContainer.isPathForGWTRuntimeContainer(entry.getPath())) { GWTJarsRuntime defaultSdk = GwtRuntimeTestUtilities.getDefaultRuntime(); IPath gwtUserJar = defaultSdk.getInstallationPath().append(GWTRuntime.GWT_USER_JAR); newEntries.add(JavaCore.newLibraryEntry(gwtUserJar, null, null)); IPath gwtDevJar = defaultSdk.getInstallationPath() .append(Util.getDevJarName(defaultSdk.getInstallationPath())); newEntries.add(JavaCore.newLibraryEntry(gwtDevJar, null, null)); continue; }/*from ww w .j a v a 2s .c om*/ } // Leave non-GWT runtime entries on the classpath as is newEntries.add(entry); } ClasspathUtilities.setRawClasspath(project, newEntries); JobsUtilities.waitForIdle(); }
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 a va2 s .com*/ 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; }
From source file:com.google.gwt.eclipse.core.runtime.GWTProjectsRuntime.java
License:Open Source License
@Override public File getDevJar() throws SdkException /* throws Exception */, JavaModelException { IStringVariableManager variableManager = getVariableManager(); IValueVariable valueVariable = variableManager.getValueVariable("gwt_devjar"); if (valueVariable != null) { String value = valueVariable.getValue(); if (value != null) { IPath path = new Path(value); File file = path.toFile(); if (!file.exists()) { throw new SdkException("gwt_devjar Run/Debug variable points to a non-existent jar: " + value); }/*from www . ja v a 2 s .c o m*/ return file; } } // We're going to have to search down the trunk to find the built gwt-dev // .jar. This assumes that the user has built the trunk at least once // TODO: can we remove the check for gwt.devjar from applicationCreator? IProject userProject = ResourcesPlugin.getWorkspace().getRoot().getProject(GWT_USER_PROJECT_NAME); if (!userProject.exists()) { throw new SdkException("The project ' " + userProject.getName() + "' does not exist in the workspace."); } IJavaProject javaUserProject = JavaCore.create(userProject); if (!javaUserProject.exists()) { throw new SdkException("The project ' " + userProject.getName() + "' is not a Java project."); } IClasspathEntry[] rawClasspaths = javaUserProject.getRawClasspath(); File stagingDir = null; IPath stagingPathLocation = null; for (IClasspathEntry rawClasspath : rawClasspaths) { if (rawClasspath.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath sourcePathLocation = getAbsoluteLocation(rawClasspath.getPath(), userProject); stagingPathLocation = sourcePathLocation.removeLastSegments(2) .append(STAGING_FOLDER_RELATIVE_LOCATION); stagingDir = stagingPathLocation.toFile(); if (stagingDir.exists()) { break; } } } if (stagingPathLocation == null) { throw new SdkException("Contributor SDK build directory not found; Project '" + userProject.getName() + "' does not have any source folders."); } if (stagingDir == null || !stagingDir.exists()) { throw new SdkException("Contributor SDK build directory not found (expected at " + stagingPathLocation.toString() + ")"); } // Find the staging output directory: gwt-<platform>-<version> final File[] buildDirs = stagingDir.listFiles(new FileFilter() { @Override public boolean accept(File file) { return (file.isDirectory() && file.getName().startsWith("gwt-")); } }); if (buildDirs.length == 0) { throw new SdkException("Contributor SDK build directory not found (expected at " + stagingDir.toString() + File.separator + "gwt-<platform>-<version>)"); } // Find the gwt-dev .jar File[] gwtDevJars = buildDirs[0].listFiles(new FileFilter() { @Override public boolean accept(File file) { String name = file.getName(); IPath sdkLocationPath = Path.fromOSString(buildDirs[0].getAbsolutePath()); return (name.equalsIgnoreCase(Util.getDevJarName(sdkLocationPath))); } }); if (gwtDevJars.length == 0) { throw new SdkException("Contributor SDK build directory missing required JAR files"); } return gwtDevJars[0]; }
From source file:com.google.gwt.eclipse.core.runtime.GWTRuntimeContainerTest.java
License:Open Source License
public void testUpdateProjectClasspathWithGWTJars() throws Exception { IJavaProject project = getTestProject(); // Start with gwt-user.jar and gwt-dev-PLAT.jar on the classpath for this // test//from w w w.j a v a2s .c o m removeGWTRuntimeFromTestProject(); GWTRuntime sdk = GWTPreferences.getSdkManager().findSdkForPath(specificRuntimePath); // Replace existing gwt-user.jar with GWT runtime GWTUpdateProjectSdkCommand command = new GWTUpdateProjectSdkCommand(project, null, sdk, UpdateType.NAMED_CONTAINER, null); command.execute(); JobsUtilities.waitForIdle(); assertGWTRuntimeEntry(specificRuntimePath, project.getRawClasspath()); }
From source file:com.google.gwt.eclipse.core.runtime.GWTRuntimeContainerTest.java
License:Open Source License
public void testUpdateProjectClasspathWithGWTRuntime() throws Exception { // Update existing GWT runtime IJavaProject project = getTestProject(); GWTRuntime oldSdk = GWTRuntime.findSdkFor(project); GWTRuntime newSdk = GWTPreferences.getSdkManager().findSdkForPath(specificRuntimePath); // Replace existing gwt-user.jar with GWT runtime GWTUpdateProjectSdkCommand command = new GWTUpdateProjectSdkCommand(project, oldSdk, newSdk, UpdateType.NAMED_CONTAINER, null); command.execute();/*from w ww .j av a 2 s . c o m*/ JobsUtilities.waitForIdle(); assertGWTRuntimeEntry(specificRuntimePath, project.getRawClasspath()); }
From source file:com.google.test.metric.eclipse.internal.core.TestabilityLauncher.java
License:Apache License
public String[] getClassPaths(IJavaProject javaProject, String projectLocation) throws JavaModelException { IClasspathEntry[] classPathEntries = javaProject.getRawClasspath(); String[] classPaths = new String[classPathEntries.length + 1]; for (int i = 0; i < classPathEntries.length; i++) { IClasspathEntry classPathEntry = classPathEntries[i]; String classPathString = null; IPath outputPath = classPathEntry.getOutputLocation(); if (outputPath != null) { classPathString = projectLocation + outputPath.toOSString(); } else {//from w w w .j a va 2s .com IPath classPath = classPathEntry.getPath(); classPathString = classPath.toOSString(); if (!classPathString.startsWith(System.getProperty("file.separator"))) { classPathString = System.getProperty("file.separator") + classPathString; } classPathString = projectLocation + classPathString; } classPathString = classPathString.replace("\\", "/"); classPaths[i] = classPathString; } String defaultOutputPath = javaProject.getOutputLocation().toOSString(); defaultOutputPath = defaultOutputPath.replace("\\", "/"); classPaths[classPathEntries.length] = projectLocation + defaultOutputPath; return classPaths; }
From source file:com.ibm.wala.ide.util.JavaEclipseProjectPath.java
License:Open Source License
@Override protected void resolveProjectClasspathEntries(IJavaProject project, boolean includeSource) { try {/*from w ww . j a v a2 s . c om*/ resolveClasspathEntries(project, Arrays.asList(project.getRawClasspath()), Loader.EXTENSION, includeSource, true); File output = makeAbsolute(project.getOutputLocation()).toFile(); if (!includeSource) { if (output.exists()) { List<Module> s = MapUtil.findOrCreateList(modules, Loader.APPLICATION); s.add(new BinaryDirectoryTreeModule(output)); } } } catch (JavaModelException e) { e.printStackTrace(); Assertions.UNREACHABLE(); } }
From source file:com.ifedorenko.m2e.binaryproject.tests.BinaryProjectTest.java
License:Open Source License
public void testBasic() throws Exception { IProject project = BinaryProjectPlugin.getInstance().create("org.apache.maven", "maven-core", "3.0.4", null, monitor);/*from w w w . ja v a 2 s. c o m*/ assertTrue(project.hasNature(IMavenConstants.NATURE_ID)); assertTrue(project.hasNature(JavaCore.NATURE_ID)); assertNotNull(BuildPathManager.getMaven2ClasspathContainer(JavaCore.create(project))); assertFalse(hasBuilder(project, JavaCore.BUILDER_ID)); IMavenProjectFacade facade = MavenPlugin.getMavenProjectRegistry().create(project, monitor); assertNotNull(facade); assertEquals(BinaryProjectPlugin.LIFECYCLE_MAPPING_ID, facade.getLifecycleMappingId()); IJavaProject javaProject = JavaCore.create(project); ClasspathHelpers.assertClasspath( new String[] { "org.eclipse.jdt.launching.JRE_CONTAINER/.*", "org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER", ".*/maven-core-3.0.4.jar" }, javaProject.getRawClasspath()); IClasspathEntry[] mavenClasspath = BuildPathManager.getMaven2ClasspathContainer(javaProject) .getClasspathEntries(); assertTrue(mavenClasspath.length > 0); }