List of usage examples for org.eclipse.jdt.core IJavaProject setRawClasspath
void setRawClasspath(IClasspathEntry[] entries, IProgressMonitor monitor) throws JavaModelException;
From source file:com.google.gdt.eclipse.appengine.rpc.wizards.helpers.RpcServiceLayerCreator.java
License:Open Source License
private void addClasspathContainer(IJavaProject project, IPath containerPath) throws JavaModelException { IClasspathEntry[] entries = project.getRawClasspath(); IClasspathEntry entry = JavaCore.newContainerEntry(containerPath); entries = CodegenUtils.addEntryToClasspath(entries, entry); project.setRawClasspath(entries, new NullProgressMonitor()); }
From source file:com.google.gdt.eclipse.core.ClasspathUtilities.java
License:Open Source License
/** * Replaces a project's classpath container entry with a new one or appends it * to the classpath if none were found.// ww w. j av a2 s . co m * * @param javaProject The target project * @param containerId the identifier of the classpath container type * @param newContainerPath the path for the new classpath. Note: this path * should be partial, not including the initial segment which should * in all cases be the value in containerId * @throws JavaModelException thrown by the call to getRawClasspath() */ public static void replaceOrAppendContainer(IJavaProject javaProject, String containerId, IPath newContainerPath, IProgressMonitor monitor) throws JavaModelException { IClasspathEntry[] classpathEntries = javaProject.getRawClasspath(); int indexOfClasspathEntryContainer = ClasspathUtilities.indexOfClasspathEntryContainer(classpathEntries, containerId); IClasspathEntry newContainer = JavaCore.newContainerEntry(new Path(containerId).append(newContainerPath)); List<IClasspathEntry> newClasspathEntries = new ArrayList<IClasspathEntry>(Arrays.asList(classpathEntries)); if (indexOfClasspathEntryContainer >= 0) { // Replace the entry newClasspathEntries.set(indexOfClasspathEntryContainer, newContainer); } else { // Append the entry newClasspathEntries.add(newContainer); } javaProject.setRawClasspath(newClasspathEntries.toArray(new IClasspathEntry[newClasspathEntries.size()]), monitor); }
From source file:com.google.gdt.eclipse.core.ClasspathUtilities.java
License:Open Source License
/** * Use this method to set the raw classpath of an IJavaProject. This method * should be used in favor of IJavaProject.setRawClasspath(IJavaProject, * IClasspathEntry [], IProgressMonitor) due to an odd interaction with * certain source control systems, such as Perforce. See the following URL for * more information: <a//from w w w.jav a 2 s . c o m * href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=243692" * >http://bugs.eclipse.org/bugs/show_bug.cgi?id=243692</a> * * <p> * Note that this method is asynchronous, so the caller will regain control * immediately, and the raw classpath will be set at some future time. Right * now, there is no way to tell the caller when the operation has completed. * If this becomes a concern in the future, a callback parameter can be * introduced. * </p> * * <p> * This method does not accept an IProgressMonitor, unlike the equivalent * method in IJavaProject, because there is an implicit progress monitor * provided when running the setRawClasspath operation as a task. In the * future, this method could be modified to accept a user-specified progress * monitor. * </p> * * NOTE: If you are already running in a job, you probably don't want to call * this method. */ public static void setRawClasspath(final IJavaProject javaProject, final IClasspathEntry[] newClasspathEntries) { IWorkspaceRunnable runnable = new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException, OperationCanceledException { javaProject.setRawClasspath(newClasspathEntries, monitor); } }; WorkbenchRunnableAdapter op = new WorkbenchRunnableAdapter(runnable); op.runAsUserJob("Updating classpath of Java project '" + javaProject.getProject().getName() + "'", null); }
From source file:com.google.gdt.eclipse.core.JavaProjectTestUtilities.java
License:Open Source License
/** * Adds the specified classpath to the Java project's existing classpath. * //from w w w . j ava 2s. c o m * @param javaProject project to update * @param rawClasspathEntry new raw classpath entry * @throws JavaModelException */ public static void addRawClassPathEntry(IJavaProject javaProject, IClasspathEntry rawClasspathEntry) throws JavaModelException { IClasspathEntry[] oldEntries = javaProject.getRawClasspath(); IProgressMonitor monitor = new NullProgressMonitor(); List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>(Arrays.asList(oldEntries)); newEntries.add(rawClasspathEntry); javaProject.setRawClasspath(newEntries.toArray(NO_ICLASSPATH_ENTRIES), monitor); }
From source file:com.google.gdt.eclipse.core.JavaProjectTestUtilities.java
License:Open Source License
/** * Creates a Java project with the specified name and raw classpath. * //from w ww .j av a 2s. c om * @param projectName * @param rawClasspaths * @return a new project * @throws CoreException */ public static IJavaProject createProject(String projectName, IClasspathEntry[] rawClasspaths) throws CoreException { IProject project = ProjectTestUtilities.createProject(projectName); NullProgressMonitor monitor = new NullProgressMonitor(); BuildPathsBlock.addJavaNature(project, monitor); IJavaProject javaProject = JavaCore.create(project); javaProject.setRawClasspath(rawClasspaths, monitor); javaProject.open(monitor); return javaProject; }
From source file:com.google.gdt.eclipse.core.JavaProjectUtilities.java
License:Open Source License
/** * Adds the specified classpath to the Java project's existing classpath. * <p>/*from w ww . j a v a 2 s . co m*/ * To instantiate classpath entries, see the helper methods in JavaCore (e.g. * {@link JavaCore#newSourceEntry(org.eclipse.core.runtime.IPath)}). * * @param javaProject project to update * @param rawClasspathEntry new raw classpath entry * @throws JavaModelException */ public static void addRawClassPathEntry(IJavaProject javaProject, IClasspathEntry rawClasspathEntry) throws JavaModelException { IClasspathEntry[] oldEntries = javaProject.getRawClasspath(); IProgressMonitor monitor = new NullProgressMonitor(); List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>(Arrays.asList(oldEntries)); newEntries.add(rawClasspathEntry); javaProject.setRawClasspath(newEntries.toArray(NO_ICLASSPATH_ENTRIES), monitor); try { ClasspathUtilities.waitUntilEntriesAreOnClasspath(javaProject, newEntries); } catch (InterruptedException e) { // Continue, with a note CorePluginLog.logWarning(e, "Interrupted while waiting to ensure classpath entries were added"); } }
From source file:com.google.gdt.eclipse.core.JavaProjectUtilities.java
License:Open Source License
/** * Creates a Java project with the specified name and raw classpath. * * @param projectName/*from ww w . jav a 2s . c o m*/ * @param rawClasspaths * @return a new project * @throws CoreException */ private static IJavaProject createProject(String projectName, IClasspathEntry[] rawClasspaths) throws CoreException { IProject project = ProjectUtilities.createProject(projectName); NullProgressMonitor monitor = new NullProgressMonitor(); BuildPathsBlock.addJavaNature(project, monitor); IJavaProject javaProject = JavaCore.create(project); javaProject.setRawClasspath(rawClasspaths, monitor); javaProject.open(monitor); /* * Should only need a single waitForIdle() call, even though we make 3 * separate calls to asynchronous JDT methods above. The reason is that each * operation creates a Java workspace job with the same scheduling rule, so * they should end up running in FIFO order, meaning that each operation * will have its prerequisites met before it begins execution. */ // Removing this wait significantly speeds up test execution time, because the Java // indexing jobs for the GWT_ROOT-imported projects can take over 5 minutes to complete. // This seems to run with no flakiness, but if flakiness continues, try figuring out // if there is a Job family for the classpath modify operations that can be waited on instead. // JobsUtilities.waitForIdle(); return javaProject; }
From source file:com.google.gdt.eclipse.mobile.android.wizards.helpers.AndroidProjectCreator.java
License:Open Source License
/** * Add the given library to the project's class path * //from ww w. j a v a 2 s. c o m * @param javaProject * @param libraryPath * @param monitor * @throws JavaModelException */ private void setupLibraryPath(IJavaProject javaProject, IPath libraryPath, IProgressMonitor monitor) throws JavaModelException { // get the list of entries. IClasspathEntry[] entries = javaProject.getRawClasspath(); entries = addEntryToClasspath(entries, JavaCore.newLibraryEntry(libraryPath, null, null)); javaProject.setRawClasspath(entries, new SubProgressMonitor(monitor, 10)); }
From source file:com.google.gdt.eclipse.mobile.android.wizards.helpers.AndroidProjectCreator.java
License:Open Source License
/** * Adds the given folder to the project's class path. * /*from ww w. j av a 2 s.com*/ * @param javaProject The Java Project to update. * @param sourceFolder Template Parameters. * @param monitor An existing monitor. * @throws CoreException */ private void setupSourceFolders(IJavaProject javaProject, String[] sourceFolders, IProgressMonitor monitor) throws CoreException { IProject project = javaProject.getProject(); // get the list of entries. IClasspathEntry[] entries = javaProject.getRawClasspath(); // remove the project as a source folder (This is the default) entries = removeSourceClasspath(entries, project); // add the source folders. for (String sourceFolder : sourceFolders) { IFolder srcFolder = project.getFolder(sourceFolder); // remove it first in case. entries = removeSourceClasspath(entries, srcFolder); entries = addEntryToClasspath(entries, JavaCore.newSourceEntry(srcFolder.getFullPath())); } IProject gaeProject = ResourcesPlugin.getWorkspace().getRoot() .getProject(projectName + AppEngineRPCPlugin.GAE_PROJECT_NAME_SUFFIX); IFolder sharedFolder = gaeProject.getFolder(ProjectCreationConstants.SHARED_FOLDER_NAME); if (sharedFolder.exists()) { IFolder androidLinkedFolder = androidProject.getFolder(ProjectCreationConstants.SHARED_FOLDER_NAME); /* The variable workspaceLoc is required only for Eclipse 3.5. * For Eclipses after 3.5, the project specific path variable WORKSPACE_LOC * can be used instead. */ String workspaceLoc = ResourcesPlugin.getWorkspace().getRoot().getLocation().toString(); // use variables for shared folder path IPath sharedFolderPath = new Path(workspaceLoc + "/" + gaeProject.getName() + "/" //$NON-NLS-N$ + ProjectCreationConstants.SHARED_FOLDER_NAME); androidLinkedFolder.createLink(sharedFolderPath, IResource.ALLOW_MISSING_LOCAL, new SubProgressMonitor(monitor, 1)); entries = addEntryToClasspath(entries, JavaCore.newSourceEntry(androidLinkedFolder.getFullPath())); } // add .apt_generated to classpath IClasspathAttribute[] attributes = new IClasspathAttribute[] { JavaCore.newClasspathAttribute("optional", "true") }; //$NON-NLS-N$ IFolder aptFolder = project.getFolder(ProjectCreationConstants.APT_FOLDER); IClasspathEntry entry = JavaCore.newSourceEntry(aptFolder.getFullPath(), ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE, null, attributes); entries = addEntryToClasspath(entries, entry); javaProject.setRawClasspath(entries, new SubProgressMonitor(monitor, 10)); }
From source file:com.google.gdt.eclipse.suite.wizards.WebAppProjectCreator.java
License:Open Source License
protected void setProjectClasspath(IJavaProject javaProject, IFolder srcFolder, IProgressMonitor monitor) throws JavaModelException { List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>(); classpathEntries.add(JavaCore.newSourceEntry(srcFolder.getFullPath())); // Add the "test" folder as a src path, if it exists IProject project = javaProject.getProject(); IFolder testFolder = project.getFolder("test"); if (testFolder.exists()) { classpathEntries.add(JavaCore.newSourceEntry(testFolder.getFullPath(), new IPath[0], project.getFullPath().append("test-classes"))); }//from w w w . j a v a 2 s .c o m // Add our container entries to the path for (IPath containerPath : containerPaths) { classpathEntries.add(JavaCore.newContainerEntry(containerPath)); } classpathEntries.addAll(Arrays.asList(PreferenceConstants.getDefaultJRELibrary())); javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[0]), monitor); }