List of usage examples for org.eclipse.jdt.core IJavaProject setRawClasspath
void setRawClasspath(IClasspathEntry[] entries, IProgressMonitor monitor) throws JavaModelException;
From source file:org.eclipse.m2m.internal.qvt.oml.ui.wizards.project.NewProjectCreationOperation.java
License:Open Source License
private void setupJava(IProject project, boolean pde, IProgressMonitor monitor) throws CoreException, JavaModelException { addNatureToProject(project, JavaCore.NATURE_ID, monitor); IContainer srcContainer = createJavaFolder(fData.getSourceFolderName(), monitor); IContainer binContainer = createJavaFolder(fData.getOutFolderName(), monitor); IJavaProject javaProject = JavaCore.create(project); javaProject.setOutputLocation(binContainer.getFullPath(), monitor); monitor.subTask(Messages.NewProjectCreationOperation_SetClassPathTask); IClasspathEntry[] entries = new IClasspathEntry[pde ? 3 : 1]; if (pde) {//w w w. j a v a 2 s . c o m String executionEnvironment = BUNDLE_EXEC_ENV; setComplianceOptions(javaProject, executionEnvironment, true); entries[0] = createJREEntry(executionEnvironment); entries[1] = createContainerEntry(); } entries[entries.length - 1] = JavaCore.newSourceEntry(srcContainer.getFullPath()); javaProject.setRawClasspath(entries, monitor); if (fData.isDoGenerateClass()) { generateTopLevelPluginClass(new SubProgressMonitor(monitor, 1)); } monitor.worked(1); }
From source file:org.eclipse.mylyn.reviews.r4e.ui.tests.utils.TestUtils.java
License:Open Source License
private static IJavaProject setProjectAsJava(IProject aProject) throws CoreException, IOException { IJavaProject javaProject = JavaCore.create(aProject); IFolder binFolder = aProject.getFolder("bin"); binFolder.create(false, true, null); IProjectDescription description = aProject.getDescription(); description.setNatureIds(new String[] { JavaCore.NATURE_ID }); aProject.setDescription(description, null); javaProject.setRawClasspath(new IClasspathEntry[0], null); IPath outputLocation = binFolder.getFullPath(); javaProject.setOutputLocation(outputLocation, null); IClasspathEntry[] oldEntries = javaProject.getRawClasspath(); IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 1]; System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length); newEntries[oldEntries.length] = JavaRuntime.getDefaultJREContainerEntry(); javaProject.setRawClasspath(newEntries, null); return javaProject; }
From source file:org.eclipse.objectteams.otdt.core.ext.OTREContainer.java
License:Open Source License
/** * Add the object teams foundation classes to the classpath. *//* ww w .j a v a 2 s .co m*/ private static void addOTREToClasspath(IJavaProject javaPrj, IClasspathEntry[] classpath) throws JavaModelException, CoreException { IClasspathEntry[] newClasspath = new IClasspathEntry[classpath.length + 1]; System.arraycopy(classpath, 0, newClasspath, 0, classpath.length); newClasspath[classpath.length] = JavaCore.newContainerEntry(OTRE_CONTAINER_PATH, false); if (newClasspath[classpath.length] != null) javaPrj.setRawClasspath(newClasspath, null); else throw new CoreException(new Status(IStatus.ERROR, OTDTPlugin.PLUGIN_ID, IStatus.OK, OTCoreExtMessages.OTREContainer_otre_not_found, null)); }
From source file:org.eclipse.objectteams.otdt.tests.AbstractJavaModelTests.java
License:Open Source License
protected void addClasspathEntry(IJavaProject project, IClasspathEntry entry) throws JavaModelException { IClasspathEntry[] entries = project.getRawClasspath(); int length = entries.length; System.arraycopy(entries, 0, entries = new IClasspathEntry[length + 1], 0, length); entries[length] = entry;/* w w w. java 2 s .c o m*/ project.setRawClasspath(entries, null); }
From source file:org.eclipse.objectteams.otdt.tests.AbstractJavaModelTests.java
License:Open Source License
/** * Attaches a source zip to the given jar package fragment root. *//* www. j a v a2 s .co m*/ protected void attachSource(IPackageFragmentRoot root, String sourcePath, String sourceRoot) throws JavaModelException { IJavaProject javaProject = root.getJavaProject(); IClasspathEntry[] entries = (IClasspathEntry[]) javaProject.getRawClasspath().clone(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getPath().toOSString().toLowerCase().equals(root.getPath().toOSString().toLowerCase())) { entries[i] = JavaCore.newLibraryEntry(root.getPath(), sourcePath == null ? null : new Path(sourcePath), sourceRoot == null ? null : new Path(sourceRoot), false); break; } } javaProject.setRawClasspath(entries, null); }
From source file:org.eclipse.objectteams.otdt.tests.AbstractJavaModelTests.java
License:Open Source License
protected void removeClasspathEntry(IJavaProject project, IPath path) throws JavaModelException { IClasspathEntry[] entries = project.getRawClasspath(); int length = entries.length; IClasspathEntry[] newEntries = null; for (int i = 0; i < length; i++) { IClasspathEntry entry = entries[i]; if (entry.getPath().equals(path)) { newEntries = new IClasspathEntry[length - 1]; if (i > 0) System.arraycopy(entries, 0, newEntries, 0, i); if (i < length - 1) System.arraycopy(entries, i + 1, newEntries, i, length - 1 - i); break; }/* w w w. j av a 2 s.c o m*/ } if (newEntries != null) project.setRawClasspath(newEntries, null); }
From source file:org.eclipse.objectteams.otdt.tests.AbstractJavaModelTests.java
License:Open Source License
/** * Sets the class path of the Java project. *///from w ww .j a v a 2 s . co m public void setClasspath(IJavaProject javaProject, IClasspathEntry[] classpath) { try { javaProject.setRawClasspath(classpath, null); } catch (JavaModelException e) { e.printStackTrace(); assertTrue("failed to set classpath", false); } }
From source file:org.eclipse.objectteams.otdt.tests.AbstractJavaModelTests.java
License:Open Source License
protected void setUpProjectCompliance(IJavaProject javaProject, String compliance) throws JavaModelException, IOException { // Look for version to set and return if that's already done String version = compliance; // assume that the values of CompilerOptions.VERSION_* are used if (version.equals(javaProject.getOption(CompilerOptions.OPTION_Compliance, false))) { return;//from w w w . j a va 2 s .com } String jclLibString; String newJclLibString; String newJclSrcString; if (compliance.charAt(2) > '4') { jclLibString = "JCL_LIB"; newJclLibString = "JCL15_LIB"; newJclSrcString = "JCL15_SRC"; } else { jclLibString = "JCL15_LIB"; newJclLibString = "JCL_LIB"; newJclSrcString = "JCL_SRC"; } // ensure variables are set setUpJCLClasspathVariables(compliance); // set options Map options = new HashMap(); options.put(CompilerOptions.OPTION_Compliance, version); options.put(CompilerOptions.OPTION_Source, version); options.put(CompilerOptions.OPTION_TargetPlatform, version); javaProject.setOptions(options); // replace JCL_LIB with JCL15_LIB, and JCL_SRC with JCL15_SRC IClasspathEntry[] classpath = javaProject.getRawClasspath(); IPath jclLib = new Path(jclLibString); for (int i = 0, length = classpath.length; i < length; i++) { IClasspathEntry entry = classpath[i]; if (entry.getPath().equals(jclLib)) { classpath[i] = JavaCore.newVariableEntry(new Path(newJclLibString), new Path(newJclSrcString), entry.getSourceAttachmentRootPath(), entry.getAccessRules(), new IClasspathAttribute[0], entry.isExported()); break; } } javaProject.setRawClasspath(classpath, null); }
From source file:org.eclipse.objectteams.otdt.ui.tests.util.JavaProjectHelper.java
License:Open Source License
/** * OT: new method: OT specific project creation. * Creates a IJavaProject.//from w w w . j a v a2s . co m */ public static IJavaProject createOTJavaProject(String projectName, String binFolderName) throws CoreException { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject project = root.getProject(projectName); if (!project.exists()) { project.create(null); } else { project.refreshLocal(IResource.DEPTH_INFINITE, null); } if (!project.isOpen()) { project.open(null); } IPath outputLocation; if (binFolderName != null && binFolderName.length() > 0) { IFolder binFolder = project.getFolder(binFolderName); if (!binFolder.exists()) { CoreUtility.createFolder(binFolder, false, true, null); } outputLocation = binFolder.getFullPath(); } else { outputLocation = project.getFullPath(); } if (!project.hasNature(JavaCore.NATURE_ID) && !project.hasNature(JavaCore.OTJ_NATURE_ID)) { addNatureToProject(project, JavaCore.NATURE_ID, null); //add OT nature to project addNatureToProject(project, JavaCore.OTJ_NATURE_ID, null); } IProjectDescription description = project.getDescription(); //add OT build spec to project description.setBuildSpec(OTDTPlugin.createProjectBuildCommands(description)); project.setDescription(description, null); IJavaProject jproject = JavaCore.create(project); jproject.setOutputLocation(outputLocation, null); jproject.setRawClasspath(new IClasspathEntry[0], null); OTREContainer.initializeOTJProject(project); return jproject; }
From source file:org.eclipse.pde.api.tools.tests.util.ProjectUtils.java
License:Open Source License
/** * creates a java project with the specified name and additional project * natures//from w ww . j ava 2s . c om * * @param projectName * @param additionalNatures * @return a new java project * @throws CoreException */ public static IJavaProject createJavaProject(String projectName, String[] additionalNatures) throws CoreException { IProgressMonitor monitor = new NullProgressMonitor(); IProject project = createProject(projectName, monitor); if (!project.hasNature(JavaCore.NATURE_ID)) { addNatureToProject(project, JavaCore.NATURE_ID, monitor); } if (additionalNatures != null) { for (int i = 0; i < additionalNatures.length; i++) { addNatureToProject(project, additionalNatures[i], monitor); } } IJavaProject jproject = JavaCore.create(project); jproject.setOutputLocation(getDefaultProjectOutputLocation(project), monitor); jproject.setRawClasspath(new IClasspathEntry[0], monitor); addContainerEntry(jproject, JavaRuntime.newDefaultJREContainerPath()); return jproject; }