List of usage examples for org.eclipse.jdt.core IJavaProject setRawClasspath
void setRawClasspath(IClasspathEntry[] entries, IProgressMonitor monitor) throws JavaModelException;
From source file:org.eclipse.capra.testsuite.TestHelper.java
License:Open Source License
public static IType createJavaProjectWithASingleJavaClass(String projectName) throws CoreException { IProject project = getProject(projectName); // Create project IProgressMonitor progressMonitor = new NullProgressMonitor(); project.create(progressMonitor);//from w w w. j ava 2 s .c om project.open(progressMonitor); // Add Java nature IProjectDescription description = project.getDescription(); description.setNatureIds(new String[] { JavaCore.NATURE_ID }); project.setDescription(description, null); // Create as Java project and set up build path etc. IJavaProject javaProject = JavaCore.create(project); IFolder binFolder = project.getFolder("bin"); binFolder.create(false, true, null); javaProject.setOutputLocation(binFolder.getFullPath(), null); List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); IVMInstall vmInstall = JavaRuntime.getDefaultVMInstall(); LibraryLocation[] locations = JavaRuntime.getLibraryLocations(vmInstall); for (LibraryLocation element : locations) entries.add(JavaCore.newLibraryEntry(element.getSystemLibraryPath(), null, null)); javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null); // Create a src file IFolder sourceFolder = project.getFolder("src"); sourceFolder.create(false, true, null); IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(sourceFolder); IClasspathEntry[] oldEntries = javaProject.getRawClasspath(); IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 1]; System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length); newEntries[oldEntries.length] = JavaCore.newSourceEntry(root.getPath()); javaProject.setRawClasspath(newEntries, null); IPackageFragment pack = javaProject.getPackageFragmentRoot(sourceFolder) .createPackageFragment("org.amalthea.test", false, null); StringBuffer buffer = new StringBuffer(); buffer.append("package " + pack.getElementName() + ";\n"); buffer.append("\n"); buffer.append("public class TestClass {}"); ICompilationUnit icu = pack.createCompilationUnit("TestClass.java", buffer.toString(), false, null); return icu.getType("TestClass"); }
From source file:org.eclipse.che.jdt.refactoring.RefactoringTest.java
License:Open Source License
private void restoreTestProject() throws Exception { IJavaProject javaProject = getRoot().getJavaProject(); if (javaProject.exists()) { IClasspathEntry srcEntry = getRoot().getRawClasspathEntry(); IClasspathEntry jreEntry = RefactoringTestSetup.getJRELibrary().getRawClasspathEntry(); IClasspathEntry[] cpes = javaProject.getRawClasspath(); ArrayList newCPEs = new ArrayList(); boolean cpChanged = false; for (int i = 0; i < cpes.length; i++) { IClasspathEntry cpe = cpes[i]; if (cpe.equals(srcEntry) || cpe.equals(jreEntry)) { newCPEs.add(cpe);//from w ww . ja v a 2 s. c o m } else { cpChanged = true; } } if (cpChanged) { IClasspathEntry[] newCPEsArray = (IClasspathEntry[]) newCPEs .toArray(new IClasspathEntry[newCPEs.size()]); javaProject.setRawClasspath(newCPEsArray, null); } Object[] nonJavaResources = javaProject.getNonJavaResources(); for (int i = 0; i < nonJavaResources.length; i++) { Object kid = nonJavaResources[i]; if (kid instanceof IResource) { IResource resource = (IResource) kid; if (!PROJECT_RESOURCE_CHILDREN.contains(resource.getName())) { JavaProjectHelper.delete(resource); } } } } }
From source file:org.eclipse.che.jdt.testplugin.Java17ProjectTestSetup.java
License:Open Source License
protected IJavaProject createAndInitializeProject() throws CoreException { IJavaProject javaProject = JavaProjectHelper.createJavaProject(PROJECT_NAME17, "bin"); javaProject.setRawClasspath(getDefaultClasspath(), null); JavaProjectHelper.set17CompilerOptions(javaProject); return javaProject; }
From source file:org.eclipse.che.jdt.testplugin.Java18ProjectTestSetup.java
License:Open Source License
@Override protected IJavaProject createAndInitializeProject() throws CoreException { IJavaProject javaProject = JavaProjectHelper.createJavaProject(PROJECT_NAME18, "bin"); javaProject.setRawClasspath(getDefaultClasspath(), null); JavaProjectHelper.set18CompilerOptions(javaProject); return javaProject; }
From source file:org.eclipse.che.jdt.testplugin.JavaProjectHelper.java
License:Open Source License
/** * Creates a IJavaProject.//w ww. j a v a 2 s . co m * @param projectName The name of the project * @param binFolderName Name of the output folder * @return Returns the Java project handle * @throws CoreException Project creation failed */ public static IJavaProject createJavaProject(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(); } IFolder codenvyFolder = project.getFolder(".codenvy"); if (!codenvyFolder.exists()) { CoreUtility.createFolder(codenvyFolder, false, true, null); } // if (!project.hasNature(JavaCore.NATURE_ID)) { // addNatureToProject(project, JavaCore.NATURE_ID, null); // } IJavaProject jproject = JavaCore.create(project); // jproject.setOutputLocation(outputLocation, null); jproject.setRawClasspath(new IClasspathEntry[0], null); IFolder folder = project.getFolder(JavaProject.INNER_DIR); CoreUtility.createFolder(folder, true, true, null); return jproject; }
From source file:org.eclipse.che.jdt.testplugin.JavaProjectHelper.java
License:Open Source License
/** * Removes all files in the project and sets the given classpath * @param jproject The project to clear/*w ww .j a v a2s . co m*/ * @param entries The default class path to set * @throws Exception Clearing the project failed */ public static void clear(final IJavaProject jproject, final IClasspathEntry[] entries) throws Exception { // performDummySearch(); IWorkspaceRunnable runnable = new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { jproject.setRawClasspath(entries, null); IResource[] resources = jproject.getProject().members(); for (int i = 0; i < resources.length; i++) { // if (!resources[i].getName().startsWith(".")) { delete(resources[i]); // } } } }; ResourcesPlugin.getWorkspace().run(runnable, null); // JavaProjectHelper.emptyDisplayLoop(); }
From source file:org.eclipse.che.jdt.testplugin.JavaProjectHelper.java
License:Open Source License
public static void removeFromClasspath(IJavaProject jproject, IPath path) throws JavaModelException { IClasspathEntry[] oldEntries = jproject.getRawClasspath(); int nEntries = oldEntries.length; ArrayList list = new ArrayList(nEntries); for (int i = 0; i < nEntries; i++) { IClasspathEntry curr = oldEntries[i]; if (!path.equals(curr.getPath())) { list.add(curr);/* ww w . ja v a 2 s. c o m*/ } } IClasspathEntry[] newEntries = (IClasspathEntry[]) list.toArray(new IClasspathEntry[list.size()]); jproject.setRawClasspath(newEntries, null); }
From source file:org.eclipse.che.jdt.testplugin.JavaProjectHelper.java
License:Open Source License
public static void addToClasspath(IJavaProject jproject, IClasspathEntry cpe) throws JavaModelException { IClasspathEntry[] oldEntries = jproject.getRawClasspath(); for (int i = 0; i < oldEntries.length; i++) { if (oldEntries[i].equals(cpe)) { return; }/* w w w. j a va 2s. co m*/ } int nEntries = oldEntries.length; IClasspathEntry[] newEntries = new IClasspathEntry[nEntries + 1]; System.arraycopy(oldEntries, 0, newEntries, 0, nEntries); newEntries[nEntries] = cpe; jproject.setRawClasspath(newEntries, null); }
From source file:org.eclipse.che.jdt.testplugin.ProjectTestSetup.java
License:Open Source License
protected IJavaProject createAndInitializeProject() throws CoreException { IJavaProject javaProject = JavaProjectHelper.createJavaProject(PROJECT_NAME, "bin"); javaProject.setRawClasspath(getDefaultClasspath(), null); TestOptions.initializeProjectOptions(javaProject); return javaProject; }
From source file:org.eclipse.che.plugin.java.plain.server.projecttype.ClasspathBuilder.java
License:Open Source License
/** * Generates classpath with default entries. * * @param project//from w ww . j ava2 s . c o m * java project which need to contain classpath * @param sourceFolders * list of the project's source folders * @param library * list of the project's library folders * @throws ServerException * happens when some problems with setting classpath */ public void generateClasspath(IJavaProject project, List<String> sourceFolders, List<String> library) throws ServerException { List<IClasspathEntry> classpathEntries = new ArrayList<>(); //create classpath container for default JRE IClasspathEntry jreContainer = JavaCore.newContainerEntry(new Path(JREContainerInitializer.JRE_CONTAINER)); classpathEntries.add(jreContainer); addSourceFolders(project, sourceFolders, classpathEntries); addJars(project, library, classpathEntries); try { project.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]), null); } catch (JavaModelException e) { LOG.warn("Can't set classpath for: " + project.getProject().getFullPath().toOSString(), e); throw new ServerException(e); } }