List of usage examples for org.eclipse.jdt.core IJavaProject setRawClasspath
void setRawClasspath(IClasspathEntry[] entries, IPath outputLocation, IProgressMonitor monitor) throws JavaModelException;
From source file:org.eclipse.jst.j2ee.internal.web.operations.WebPropertiesUtil.java
License:Open Source License
/** * Update the classpath entries and Server Root Name for this web project only. * // w ww . jav a 2 s . c o m * @param project * @param webContentName * @return */ public static void updateWebContentNamePropertiesOnly(IProject project, String webContentName, IProgressMonitor progressMonitor) throws CoreException { IPath newPath = new Path(webContentName); if (getModuleServerRoot(project).equals(newPath)) return; if (!getModuleServerRoot(project).equals(webContentName)) { // if (webModuleArtifact.isJ2EE) { // Update the library references IJavaProject javaProject = JemProjectUtilities.getJavaProject(project); IClasspathEntry[] classpath = javaProject.getRawClasspath(); IClasspathEntry[] newClasspath = new IClasspathEntry[classpath.length]; for (int i = 0; i < classpath.length; i++) { if (classpath[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IClasspathEntry library = classpath[i]; IPath libpath = library.getPath(); IPath modServerRootPath = getModuleServerRoot(project).getFullPath(); if (modServerRootPath.isPrefixOf(libpath)) { IPath prunedPath = libpath.removeFirstSegments(modServerRootPath.segmentCount()); IPath relWebContentPath = new Path(webContentName + "/" + prunedPath.toString()); //$NON-NLS-1$ IResource absWebContentPath = project.getFile(relWebContentPath); IPath srcAttachmentPath = library.getSourceAttachmentPath(); if (null != srcAttachmentPath) { prunedPath = srcAttachmentPath.removeFirstSegments(modServerRootPath.segmentCount()); } IResource absWebContentSrcAttachmentPath = project.getFile(relWebContentPath); newClasspath[i] = JavaCore.newLibraryEntry(absWebContentPath.getFullPath(), absWebContentSrcAttachmentPath.getFullPath(), library.getSourceAttachmentRootPath(), library.isExported()); } else { newClasspath[i] = classpath[i]; } } else { newClasspath[i] = classpath[i]; } // } // Set the java output folder IFolder outputFolder = project.getFolder(getModuleServerRoot(project).getFullPath()); javaProject.setRawClasspath(newClasspath, outputFolder.getFullPath(), new SubProgressMonitor(progressMonitor, 1)); } // update websettings // TODO add to WebArtifactEdit // webNature.setModuleServerRootName(webContentName); } }
From source file:org.eclipse.jst.jsp.core.tests.taglibindex.BundleResourceUtil.java
License:Open Source License
public static IProject createJavaWebProject(String name) throws CoreException { // Create new project IProject project = BundleResourceUtil.createSimpleProject(name, null, new String[] { JavaCore.NATURE_ID }); IJavaProject javaProject = JavaCore.create(project); List buildPath = new ArrayList(Arrays.asList(javaProject.getRawClasspath())); Iterator i = buildPath.iterator(); while (i.hasNext()) { IClasspathEntry entry = (IClasspathEntry) i.next(); if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && "org.eclipse.jdt.launching.JRE_CONTAINER".equals(entry.getPath().segment(0))) { i.remove();// w ww. j av a2 s . c o m } } buildPath.add( JavaCore.newContainerEntry(new Path("org.eclipse.jst.jsp.core.tests.webContainerInitializer"))); buildPath.add(JavaCore.newContainerEntry(new Path( "org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"))); javaProject.setRawClasspath((IClasspathEntry[]) buildPath.toArray(new IClasspathEntry[buildPath.size()]), new Path("/" + name + "/WebContent/WEB-INF/classes"), new NullProgressMonitor()); return project; }
From source file:org.eclipse.m2e.jdt.internal.AbstractJavaProjectConfigurator.java
License:Open Source License
public void configure(ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException { IProject project = request.getProject(); monitor.setTaskName(Messages.AbstractJavaProjectConfigurator_task_name + project.getName()); addJavaNature(project, monitor);/*from w ww .j av a 2 s . c o m*/ IJavaProject javaProject = JavaCore.create(project); Map<String, String> options = new HashMap<String, String>(); addJavaProjectOptions(options, request, monitor); IClasspathDescriptor classpath = new ClasspathDescriptor(javaProject); addProjectSourceFolders(classpath, request, monitor); String environmentId = getExecutionEnvironmentId(options); addJREClasspathContainer(classpath, environmentId); addMavenClasspathContainer(classpath); addCustomClasspathEntries(javaProject, classpath); invokeJavaProjectConfigurators(classpath, request, monitor); // now apply new configuration // A single setOptions call erases everything else from an existing settings file. // Must invoke setOption individually to preserve previous options. for (Map.Entry<String, String> option : options.entrySet()) { javaProject.setOption(option.getKey(), option.getValue()); } IContainer classesFolder = getOutputLocation(request, project); javaProject.setRawClasspath(classpath.getEntries(), classesFolder.getFullPath(), monitor); MavenJdtPlugin.getDefault().getBuildpathManager().updateClasspath(project, monitor); }
From source file:org.eclipse.pde.api.tools.tests.util.ProjectUtils.java
License:Open Source License
/** * Adds the specified classpath entry to the specified java project * //w ww . j av a 2 s . c o m * @param jproject * @param cpe * @throws JavaModelException */ public static void addToClasspath(IJavaProject jproject, IClasspathEntry cpe) throws JavaModelException { boolean found = false; IClasspathEntry[] entries = jproject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { if (entriesEqual(entries[i], cpe)) { entries[i] = cpe; found = true; } } if (!found) { int nEntries = entries.length; IClasspathEntry[] newEntries = new IClasspathEntry[nEntries + 1]; System.arraycopy(entries, 0, newEntries, 0, nEntries); newEntries[nEntries] = cpe; entries = newEntries; } jproject.setRawClasspath(entries, true, new NullProgressMonitor()); }
From source file:org.eclipse.rap.ui.tests.TestPluginProject.java
License:Open Source License
private IJavaProject createJavaProjectLayout() throws CoreException { project.open(new NullProgressMonitor()); IJavaProject result = JavaCore.create(project); IFolder srcFolder = project.getFolder(DEFAULT_SOURCE_FOLDER); if (!srcFolder.exists()) { srcFolder.create(false, true, new NullProgressMonitor()); }//from w w w.java 2 s . c o m IPath srcPath = srcFolder.getFullPath(); IClasspathEntry srcEntry = JavaCore.newSourceEntry(srcPath); IPath jrePath = JavaRuntime.getDefaultJREContainerEntry().getPath(); IClasspathEntry jreEntry = JavaCore.newContainerEntry(jrePath); IPath binPath = project.getFullPath().append(DEFAULT_OUTPUT_FOLDER); IClasspathEntry[] cpes = new IClasspathEntry[] { srcEntry, jreEntry }; result.setRawClasspath(cpes, binPath, new NullProgressMonitor()); return result; }
From source file:org.hibernate.eclipse.console.test.project.xpl.JavaProjectHelper.java
License:Open Source License
/** * Removes a IJavaElement/*from w w w . j a v a2 s . c o m*/ * * @param elem The element to remove * @throws CoreException Removing failed * @see #ASSERT_NO_MIXED_LINE_DELIMIERS */ public static void delete(final IJavaElement elem) throws CoreException { IWorkspaceRunnable runnable = new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { performDummySearch(); if (elem instanceof IJavaProject) { IJavaProject jproject = (IJavaProject) elem; jproject.setRawClasspath(new IClasspathEntry[0], jproject.getProject().getFullPath(), null); } for (int i = 0; i < MAX_RETRY; i++) { try { elem.getResource().delete(true, null); i = MAX_RETRY; } catch (CoreException e) { if (i == MAX_RETRY - 1) { JavaPlugin.log(e); throw e; } try { Thread.sleep(1000); // sleep a second } catch (InterruptedException e1) { } } } } }; ResourcesPlugin.getWorkspace().run(runnable, null); }