List of usage examples for org.eclipse.jdt.core IJavaProject setRawClasspath
void setRawClasspath(IClasspathEntry[] entries, IProgressMonitor monitor) throws JavaModelException;
From source file:org.eclipse.virgo.ide.ui.wizards.NewBundleProjectWizard.java
License:Open Source License
protected void removeFromClasspath(IJavaProject javaProject, String entryPath, IProgressMonitor monitor) throws CoreException { List<IClasspathEntry> rawClasspath = new ArrayList<IClasspathEntry>(); rawClasspath.addAll(Arrays.asList(javaProject.getRawClasspath())); Iterator<IClasspathEntry> iter = rawClasspath.iterator(); while (iter.hasNext()) { IClasspathEntry entry = iter.next(); if (entry.getPath() != null && entry.getPath().toString() != null && entry.getPath().toString().equals(entryPath)) { iter.remove();//from ww w . jav a 2s . c om } } javaProject.setRawClasspath(rawClasspath.toArray(new IClasspathEntry[0]), monitor); }
From source file:org.eclipse.virgo.ide.ui.wizards.NewBundleProjectWizard.java
License:Open Source License
protected void addToClasspath(IJavaProject javaProject, IClasspathEntry entry, IProgressMonitor monitor) throws CoreException { IClasspathEntry[] current = javaProject.getRawClasspath(); IClasspathEntry[] updated = new IClasspathEntry[current.length + 1]; System.arraycopy(current, 0, updated, 0, current.length); updated[current.length] = entry;/*from w ww. j ava2 s . c o m*/ javaProject.setRawClasspath(updated, monitor); }
From source file:org.eclipse.vorto.codegen.api.tasks.eclipse.ClasspathConfiguration.java
License:Open Source License
@Override public IEclipseProjectConfiguration configure(IProject project) { IJavaProject javaProject = JavaCore.create(project); try {//from w w w .j a va 2 s .c om javaProject.setRawClasspath(getClasspathEntries(javaProject), new NullProgressMonitor()); javaProject.setOutputLocation(project.getFolder(outputLocation).getFullPath(), new NullProgressMonitor()); } catch (JavaModelException e1) { MessageDisplayFactory.getMessageDisplay().displayError(e1.getMessage()); } return this; }
From source file:org.eclipse.wb.internal.core.utils.jdt.core.ProjectUtils.java
License:Open Source License
/** * Adds {@link IClasspathEntry} to the {@link IJavaProject}. * /*from w w w . ja va 2 s . com*/ * @param javaProject * the {@link IJavaProject} to add JAR to. * @param entry * the {@link IClasspathEntry} to add. */ public static void addClasspathEntry(IJavaProject javaProject, IClasspathEntry entry) throws CoreException { IClasspathEntry[] entries = javaProject.getRawClasspath(); entries = (IClasspathEntry[]) ArrayUtils.add(entries, entry); javaProject.setRawClasspath(entries, null); }
From source file:org.eclipse.wb.internal.core.utils.jdt.core.ProjectUtils.java
License:Open Source License
/** * Requires <code>requiredProject</code> in <code>project</code>. *//*from www . ja v a 2s .c om*/ public static void requireProject(IJavaProject project, IJavaProject requiredProject) throws JavaModelException { IClasspathEntry[] rawClasspath = project.getRawClasspath(); rawClasspath = (IClasspathEntry[]) ArrayUtils.add(rawClasspath, JavaCore.newProjectEntry(requiredProject.getPath())); project.setRawClasspath(rawClasspath, null); }
From source file:org.eclipse.wb.internal.core.utils.jdt.core.ProjectUtils.java
License:Open Source License
/** * Calls {@link IJavaProject#setRawClasspath(IClasspathEntry[], IProgressMonitor)}. *///from w w w . j ava2 s . co m private static void setRawClasspath(IJavaProject javaProject, List<IClasspathEntry> entries) throws JavaModelException { javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null); }
From source file:org.eclipse.wb.tests.designer.core.PdeProjectConversionUtils.java
License:Open Source License
private void loadClasspathEntries(IProject project, IProgressMonitor monitor) { IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] currentClassPath = new IClasspathEntry[0]; List<String> sources = Lists.newArrayList(); List<String> libraries = Lists.newArrayList(); try {/*from ww w . j a v a 2s.c o m*/ currentClassPath = javaProject.getRawClasspath(); } catch (JavaModelException e) { } for (int i = 0; i < currentClassPath.length; i++) { int contentType = currentClassPath[i].getEntryKind(); if (contentType == IClasspathEntry.CPE_SOURCE) { String relativePath = getRelativePath(currentClassPath[i], project); if (relativePath.equals("")) { //$NON-NLS-1$ sources.add("."); //$NON-NLS-1$ } else { sources.add(relativePath + "/"); //$NON-NLS-1$ } } else if (contentType == IClasspathEntry.CPE_LIBRARY) { String path = getRelativePath(currentClassPath[i], project); if (path.length() > 0) { libraries.add(path); } else { libraries.add("."); //$NON-NLS-1$ } } } fSrcEntries = sources.toArray(new String[sources.size()]); fLibEntries = libraries.toArray(new String[libraries.size()]); // IClasspathEntry[] classPath = new IClasspathEntry[currentClassPath.length + 1]; System.arraycopy(currentClassPath, 0, classPath, 0, currentClassPath.length); try { classPath[classPath.length - 1] = createContainerEntry(); javaProject.setRawClasspath(classPath, monitor); } catch (Throwable e) { } }
From source file:org.eclipse.wb.tests.designer.core.util.jdt.core.CodeUtilsTest.java
License:Open Source License
/** * {@link IJavaProject} as element, but no separate source folders, so {@link IJavaProject} itself * is source folder./*w w w. j a v a 2 s . c o m*/ */ public void test_getPackageFragmentRoot_3() throws Exception { try { IJavaProject javaProject = m_testProject.getJavaProject(); // remove "src" { IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); rawClasspath = (IClasspathEntry[]) ArrayUtils.remove(rawClasspath, rawClasspath.length - 1); javaProject.setRawClasspath(rawClasspath, new NullProgressMonitor()); } // add "" { IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); rawClasspath = (IClasspathEntry[]) ArrayUtils.add(rawClasspath, JavaCore.newSourceEntry(new Path("/TestProject"))); javaProject.setRawClasspath(rawClasspath, new NullProgressMonitor()); } // IJavaProject as element { IJavaElement element = javaProject; IPackageFragmentRoot packageFragmentRoot = CodeUtils.getPackageFragmentRoot(element); assertPackageFragmentRootPath("/TestProject", packageFragmentRoot); } } finally { do_projectDispose(); do_projectCreate(); } }
From source file:org.eclipse.xtend.ide.buildpath.XtendLibClasspathAdder.java
License:Open Source License
protected boolean addToClasspath(IJavaProject javaProject, IProgressMonitor monitor) throws JavaModelException { IClasspathEntry xtendContainerEntry = JavaCore .newContainerEntry(XtendContainerInitializer.XTEND_LIBRARY_PATH); IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); IClasspathEntry[] newRawClasspath = new IClasspathEntry[rawClasspath.length + 1]; for (int i = 0; i < rawClasspath.length; ++i) { IClasspathEntry entry = rawClasspath[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && entry.getPath().equals(xtendContainerEntry.getPath())) { return false; }/*from w w w . ja v a 2 s. c o m*/ newRawClasspath[i + 1] = entry; } newRawClasspath[0] = xtendContainerEntry; javaProject.setRawClasspath(newRawClasspath, monitor); return true; }
From source file:org.eclipse.xtend.ide.tests.builder.SameClassNamesTest.java
License:Open Source License
@Test public void testDuplicateNames_04() { try {/*from w ww. j ava2s . c om*/ final IJavaProject javaProject = JavaCore.create(this.second); final IClasspathEntry[] cp = javaProject.getRawClasspath(); final List<IClasspathEntry> reversed = ListExtensions .<IClasspathEntry>reverse(((List<IClasspathEntry>) Conversions.doWrapArray(cp))); javaProject.setRawClasspath( ((IClasspathEntry[]) Conversions.unwrapArray(reversed, IClasspathEntry.class)), null); IResourcesSetupUtil.reallyWaitForAutoBuild(); this.testHelper.createFileImpl("first/src/com/acme/A.xtend", "package com.acme class A { new(String s) {} }"); this.testHelper.createFileImpl("second/src/com/acme/A.xtend", "package com.acme class A { new(int i) {} }"); this.testHelper.createFileImpl("second/src/com/acme/B.xtend", "package com.acme class B extends A { new() { super(1) } }"); this.testHelper.createFileImpl("third/src/com/acme/A.xtend", "package com.acme class A {}"); IResourcesSetupUtil.waitForBuild(); IResourcesSetupUtil.assertNoErrorsInWorkspace(); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }