public static boolean projectContainsClasspathEntry(IJavaProject project, IClasspathEntry entry) throws JavaModelException { IClasspathEntry[] oldEntries = project.getRawClasspath(); for (IClasspathEntry oldEntry : oldEntries) { if (oldEntry.equals(entry)) { return true; } } return false; }
@Override public void run(IProgressMonitor monitor) throws CoreException { IClasspathEntry[] oldClasspath= javaProject.getRawClasspath(); int nEntries= oldClasspath.length; IClasspathEntry[] newEntries= Arrays.copyOf(oldClasspath, nEntries+1); newEntries[nEntries]= newEntry; javaProject.setRawClasspath(newEntries, monitor); } };
protected static void addToClasspath(final IJavaProject jproj, final IClasspathEntry entry) throws CoreException { final IClasspathEntry[] current = jproj.getRawClasspath(); final IClasspathEntry[] updated = new IClasspathEntry[current.length + 1]; System.arraycopy(current, 0, updated, 0, current.length); updated[current.length] = entry; jproj.setRawClasspath(updated, null); }
private IClasspathEntry[] getNewClasspathEntries() throws JavaModelException{ IClasspathEntry[] entries= getJavaProject().getRawClasspath(); List cp= new ArrayList(entries.length + 1); cp.addAll(Arrays.asList(entries)); cp.add(fEntryToAdd); return (IClasspathEntry[])cp.toArray(new IClasspathEntry[cp.size()]); }
public static CPListElement[] createFromExisting(IJavaProject project) throws JavaModelException { IClasspathEntry[] rawClasspath= project.getRawClasspath(); CPListElement[] result= new CPListElement[rawClasspath.length]; for (int i= 0; i < rawClasspath.length; i++) { result[i]= CPListElement.createFromExisting(rawClasspath[i], project); } return result; }
public static IPath[] listSourcePaths(IJavaProject project) throws JavaModelException { List<IPath> result = new ArrayList<>(); for (IClasspathEntry entry : project.getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { result.add(entry.getPath()); } } return result.toArray(new IPath[0]); }
public static IPath[] getOutputLocations(IJavaProject project) throws CoreException { List<IPath> result = new ArrayList<IPath>(); result.add(project.getOutputLocation()); IClasspathEntry[] entries = project.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { result.add(entry.getOutputLocation()); } } return result.toArray(new IPath[result.size()]); }
public static ClasspathChange addEntryChange(IJavaProject project, IClasspathEntry entryToAdd) throws JavaModelException { IClasspathEntry[] rawClasspath= project.getRawClasspath(); IClasspathEntry[] newClasspath= new IClasspathEntry[rawClasspath.length + 1]; System.arraycopy(rawClasspath, 0, newClasspath, 0, rawClasspath.length); newClasspath[rawClasspath.length]= entryToAdd; IPath outputLocation= project.getOutputLocation(); return newChange(project, newClasspath, outputLocation); }
public static ClasspathChange addEntryChange(IJavaProject project, IClasspathEntry entryToAdd) throws JavaModelException { IClasspathEntry[] rawClasspath= project.getRawClasspath(); IClasspathEntry[] newClasspath= new IClasspathEntry[rawClasspath.length + 1]; System.arraycopy(rawClasspath, 0, newClasspath, 0, rawClasspath.length); newClasspath[rawClasspath.length]= entryToAdd; IPath outputLocation= project.getOutputLocation(); return newChange(project, newClasspath, outputLocation); }
private void updateSourceFolders(IProgressMonitor monitor) throws JavaModelException { List<IClasspathEntry> classpath = Lists.newArrayList(this.project.getRawClasspath()); updateExistingSourceFolders(classpath); addNewSourceFolders(classpath); this.project.setRawClasspath(classpath.toArray(new IClasspathEntry[0]), monitor); }
private void addToClassPath(IJavaProject project, IPath jarPath, IProgressMonitor monitor) throws JavaModelException { if (monitor.isCanceled()) throw new OperationCanceledException(); IClasspathEntry[] entries= project.getRawClasspath(); IClasspathEntry[] newEntries= new IClasspathEntry[entries.length + 1]; System.arraycopy(entries, 0, newEntries, 0, entries.length); newEntries[entries.length]= JavaCore.newLibraryEntry(jarPath, null, null, false); project.setRawClasspath(newEntries, monitor); } };
public static boolean isOnSourcePath(IPath sourcePath, IJavaProject project) throws JavaModelException { for (IClasspathEntry entry : project.getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE && entry.getPath().equals(sourcePath)) { return true; } } return false; }
public static void update(IJavaProject eclipseProject, EclipseProject modelProject, IProgressMonitor monitor) throws JavaModelException { if (supportsClasspathCustomization(modelProject)) { IClasspathEntry[] newClasspath = filterLibraries(eclipseProject.getRawClasspath()); eclipseProject.setRawClasspath(newClasspath, monitor); } }
public static ClasspathChange removeEntryChange(IJavaProject project, IClasspathEntry entryToRemove) throws JavaModelException { IClasspathEntry[] rawClasspath= project.getRawClasspath(); ArrayList<IClasspathEntry> newClasspath= new ArrayList<>(); for (int i= 0; i < rawClasspath.length; i++) { IClasspathEntry curr= rawClasspath[i]; if (curr.getEntryKind() != entryToRemove.getEntryKind() || !curr.getPath().equals(entryToRemove.getPath())) { newClasspath.add(curr); } } IClasspathEntry[] entries= newClasspath.toArray(new IClasspathEntry[newClasspath.size()]); IPath outputLocation= project.getOutputLocation(); return newChange(project, entries, outputLocation); }
private void createPackageFragmentRoot(IPackageFragmentRoot root) throws CoreException { final IJavaProject project= root.getJavaProject(); if (!project.exists()) { // createJavaProject(project.getProject()); } final IFolder folder= project.getProject().getFolder(root.getElementName()); if (!folder.exists()) { ResourceUtil.createFolder(folder, true, true, new NullProgressMonitor()); } final List<IClasspathEntry> list= Arrays.asList(project.getRawClasspath()); list.add(JavaCore.newSourceEntry(folder.getFullPath())); project.setRawClasspath(list.toArray(new IClasspathEntry[list.size()]), new NullProgressMonitor()); }
private void createPackageFragmentRoot(IPackageFragmentRoot root) throws CoreException { final IJavaProject project= root.getJavaProject(); if (!project.exists()) createJavaProject(project.getProject()); final IFolder folder= project.getProject().getFolder(root.getElementName()); if (!folder.exists()) CoreUtility.createFolder(folder, true, true, new NullProgressMonitor()); final List<IClasspathEntry> list= Arrays.asList(project.getRawClasspath()); list.add(JavaCore.newSourceEntry(folder.getFullPath())); project.setRawClasspath(list.toArray(new IClasspathEntry[list.size()]), new NullProgressMonitor()); }
private void createPackageFragmentRoot(IPackageFragmentRoot root) throws CoreException { final IJavaProject project= root.getJavaProject(); if (!project.exists()) createJavaProject(project.getProject()); final IFolder folder= project.getProject().getFolder(root.getElementName()); if (!folder.exists()) CoreUtility.createFolder(folder, true, true, new NullProgressMonitor()); final List list= Arrays.asList(project.getRawClasspath()); list.add(JavaCore.newSourceEntry(folder.getFullPath())); project.setRawClasspath((IClasspathEntry[]) list.toArray(new IClasspathEntry[list.size()]), new NullProgressMonitor()); }
private boolean isEEOnClasspath(IExecutionEnvironment ee) throws JavaModelException { IPath eePath= JavaRuntime.newJREContainerPath(ee); for (IClasspathEntry entry: fProject.getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && entry.getPath().equals(eePath)) return true; } return false; }
private static void updateReferencedClasspathEntry(IJavaProject javaProject, IClasspathEntry newEntry, IProgressMonitor monitor) throws JavaModelException { List<IClasspathEntry> newEntries = updateElements(javaProject.getReferencedClasspathEntries(), newEntry, (entry) -> { return entry.getEntryKind() == newEntry.getEntryKind() && entry.getPath().equals(newEntry.getPath()); }); javaProject.setRawClasspath(javaProject.getRawClasspath(), newEntries.toArray(new IClasspathEntry[0]), javaProject.getOutputLocation(), monitor); }
private static void updateProjectClasspath(IJavaProject javaProject, IClasspathEntry newEntry, IProgressMonitor monitor) throws JavaModelException { List<IClasspathEntry> newEntries = updateElements(javaProject.getRawClasspath(), newEntry, (entry) -> { return entry.getEntryKind() == newEntry.getEntryKind() && entry.getPath().equals(newEntry.getPath()); }); JavaLanguageServerPlugin.logInfo("Update source attachment " + (newEntry.getSourceAttachmentPath() == null ? null : newEntry.getSourceAttachmentPath().toOSString()) + " to the file " + newEntry.getPath().toOSString()); javaProject.setRawClasspath(newEntries.toArray(new IClasspathEntry[0]), monitor); }