List of usage examples for org.eclipse.jdt.core IJavaProject getRawClasspath
IClasspathEntry[] getRawClasspath() throws JavaModelException;
From source file:org.eclipse.buildship.core.launch.internal.GradleClasspathProvider.java
License:Open Source License
private static IRuntimeClasspathEntry[] resolveOutputLocations(IRuntimeClasspathEntry projectEntry, IJavaProject project, LaunchConfigurationScope configurationScopes) throws CoreException { List<IPath> outputLocations = Lists.newArrayList(); boolean hasSourceFolderWithoutCustomOutput = false; if (project.exists() && project.getProject().isOpen()) { for (IClasspathEntry entry : project.getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { // only add the output location if it's in the same source set if (configurationScopes.isEntryIncluded(entry)) { IPath path = entry.getOutputLocation(); if (path != null) { outputLocations.add(path); } else { // only use the default output if there's at least one source folder that doesn't have a custom output location hasSourceFolderWithoutCustomOutput = true; }/*ww w.j ava 2s . c o m*/ } } } } if (outputLocations.isEmpty()) { return new IRuntimeClasspathEntry[] { projectEntry }; } IPath defaultOutputLocation = project.getOutputLocation(); if (!outputLocations.contains(defaultOutputLocation) && hasSourceFolderWithoutCustomOutput) { outputLocations.add(defaultOutputLocation); } IRuntimeClasspathEntry[] result = new IRuntimeClasspathEntry[outputLocations.size()]; for (int i = 0; i < result.length; i++) { result[i] = new RuntimeClasspathEntry(JavaCore.newLibraryEntry(outputLocations.get(i), null, null)); result[i].setClasspathProperty(projectEntry.getClasspathProperty()); } return result; }
From source file:org.eclipse.buildship.core.workspace.internal.LibraryFilter.java
License:Open Source License
public static void update(IJavaProject eclipseProject, OmniEclipseProject modelProject, IProgressMonitor monitor) throws JavaModelException { if (supportsClasspathCustomization(modelProject)) { IClasspathEntry[] newClasspath = filterLibraries(eclipseProject.getRawClasspath()); eclipseProject.setRawClasspath(newClasspath, monitor); }//from w ww . ja va 2 s . c o m }
From source file:org.eclipse.buildship.core.workspace.internal.WtpClasspathUpdater.java
License:Open Source License
private static void replaceGradleClasspathContainerAttribute(IJavaProject project, String plusKey, String plusValue, String minusKey, SubMonitor progress) throws JavaModelException { IClasspathEntry[] oldClasspath = project.getRawClasspath(); IClasspathEntry[] newClasspath = new IClasspathEntry[oldClasspath.length]; for (int i = 0; i < oldClasspath.length; i++) { IClasspathEntry entry = oldClasspath[i]; if (isGradleClasspathContainer(entry)) { IClasspathAttribute[] attributes = replaceClasspathAttribute(entry.getExtraAttributes(), plusKey, plusValue, minusKey); newClasspath[i] = JavaCore.newContainerEntry(entry.getPath(), entry.getAccessRules(), attributes, entry.isExported()); } else {// w w w . jav a2s . c o m newClasspath[i] = entry; } } project.setRawClasspath(newClasspath, progress); }
From source file:org.eclipse.buildship.wtp.core.configurator.WebApplicationConfigurator.java
License:Open Source License
/** * Makes the Gradle container deployable by modifying its classpath entry. *//* w w w.j a va 2 s .co m*/ private void makeGradleContainerDeployable(ProjectConfigurationRequest projectConfigurationRequest, IProgressMonitor monitor) throws JavaModelException { IProject workspaceProject = projectConfigurationRequest.getWorkspaceProject(); IJavaProject javaProject = JavaCore.create(workspaceProject); List<IClasspathEntry> classpathEntries = Arrays.asList(javaProject.getRawClasspath()); List<IClasspathEntry> newEntries = FluentIterable.from(classpathEntries) .transform(new Function<IClasspathEntry, IClasspathEntry>() { @Override public IClasspathEntry apply(IClasspathEntry entry) { String path = entry.getPath().toString(); if (path.equals(GRADLE_CLASSPATH_CONTAINER_PATH)) { IClasspathEntry newGradleContainerEntry = markAsDeployable(entry); return newGradleContainerEntry; } else { return entry; } } }).toList(); javaProject.setRawClasspath(newEntries.toArray(new IClasspathEntry[newEntries.size()]), monitor); }
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 ww w .jav a 2 s .c o m 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);/*www . j ava2s .com*/ } 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.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);//w w w . j a 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; }//from w w w . j av a 2s .com } 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.plugin.java.plain.server.projecttype.ClasspathBuilderTest.java
License:Open Source License
@Test public void rawClasspathShouldBeContained3Arguments() throws Exception { createTestProject();//from ww w . java 2s .c om library.add("/lib"); sourceFolders.add("/src"); IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("/project"); IJavaProject iJavaProject = JavaCore.create(project); classpathBuilder.generateClasspath(iJavaProject, sourceFolders, library); List<IClasspathEntry> classpathEntries = Arrays.asList(iJavaProject.getRawClasspath()); assertThat(classpathEntries).onProperty("path").containsOnly( new Path(JREContainerInitializer.JRE_CONTAINER), new Path("/project/src"), new Path(root + "/project/lib/a.jar")); }
From source file:org.eclipse.che.plugin.java.plain.server.projecttype.PlainJavaInitHandler.java
License:Open Source License
@Override protected void initializeClasspath(IJavaProject javaProject) throws ServerException { IClasspathEntry[] projectClasspath;//from ww w . ja v a 2s .c o m try { projectClasspath = javaProject.getRawClasspath(); } catch (JavaModelException e) { LOG.warn("Can't get classpath for: " + javaProject.getProject().getFullPath().toOSString(), e); throw new ServerException(e); } //default classpath IClasspathEntry[] defaultClasspath = new IClasspathEntry[] { JavaCore.newSourceEntry(javaProject.getPath()) }; if (!Arrays.equals(defaultClasspath, projectClasspath)) { //classpath is already initialized return; } RegisteredProject project = projectRegistryProvider.get().getProject(javaProject.getPath().toOSString()); List<String> sourceFolders = project.getAttributes().get(Constants.SOURCE_FOLDER); List<String> library = project.getAttributes().get(LIBRARY_FOLDER); classpathBuilder.generateClasspath(javaProject, sourceFolders, library); }