List of usage examples for org.eclipse.jdt.core IJavaProject getRawClasspath
IClasspathEntry[] getRawClasspath() throws JavaModelException;
From source file:org.eclipse.edt.ide.ui.wizards.EGLProjectUtility.java
License:Open Source License
/** * Return whether or not a classpath entry exists in the project's Java * build path./* www.j a va2 s. com*/ * * @param javaProject * @param entry * @return * @throws JavaModelException */ public static boolean classpathEntryExists(IJavaProject javaProject, IClasspathEntry entry) throws JavaModelException { int jarIndex = -1; IClasspathEntry curEntry; IClasspathEntry[] oldEntries = javaProject.getRawClasspath(); // Look for the jar file in the current build path for (int i = 0; i < oldEntries.length; i++) { curEntry = oldEntries[i]; if (curEntry.getPath() != null) { if (curEntry.getPath().toString().equalsIgnoreCase(entry.getPath().toString())) { jarIndex = i; break; } } } // We will add a new entry if the entry does not exist. if (jarIndex < 0) { return false; } else { return true; } }
From source file:org.eclipse.edt.ide.ui.wizards.EGLProjectUtility.java
License:Open Source License
/** * Return whether a source entry exists in the classpath. * (Don't count a source entry that only has a segment with the * project name, as found in general projects.) * //from w ww . j ava2 s.c o m * @param project * @return * @throws JavaModelException */ public static boolean classpathEntriesExist(IJavaProject javaProject) throws JavaModelException { IClasspathEntry[] entries = javaProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { if (entries[i].getPath().segmentCount() > 1) { return true; } } return false; }
From source file:org.eclipse.edt.ide.ui.wizards.EGLProjectUtility.java
License:Open Source License
public static boolean sourceClasspathEntryExists(IJavaProject javaProject) throws JavaModelException { IClasspathEntry[] entries = javaProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { if (entries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE && entries[i].getPath().segmentCount() > 1) { return true; }//w w w . j a va 2 s . c om } return false; }
From source file:org.eclipse.edt.ide.ui.wizards.EGLProjectUtility.java
License:Open Source License
public static void addClasspathEntriesIfNecessary(IProject project, IClasspathEntry[] classpathEntries) throws CoreException { IJavaProject javaProject; //The Java "view" of the project. if (project.hasNature(JavaCore.NATURE_ID)) { javaProject = JavaCore.create(project); int index = -1; IClasspathEntry curEntry;/*ww w . j a v a 2 s . c om*/ List<IClasspathEntry> newClasspaths = new ArrayList<IClasspathEntry>(); IClasspathEntry[] oldEntries = javaProject.getRawClasspath(); for (IClasspathEntry pathEntry : classpathEntries) { // Look for the jar file in the current build path for (int i = 0; i < oldEntries.length; i++) { curEntry = oldEntries[i]; if (curEntry.getPath() != null) { if (curEntry.getPath().toOSString().equalsIgnoreCase(pathEntry.getPath().toOSString())) { index = i; break; } } } // We will add a new entry if the entry does not exist. if (index < 0) { newClasspaths.add(pathEntry); } } addClasspathLibraryEntries(javaProject, newClasspaths.toArray(new IClasspathEntry[newClasspaths.size()])); } }
From source file:org.eclipse.edt.ide.ui.wizards.EGLProjectUtility.java
License:Open Source License
public static void addClasspathLibraryEntries(IJavaProject javaProject, IClasspathEntry[] classpathEntries) throws CoreException { IClasspathEntry[] oldEntries = javaProject.getRawClasspath(); IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + classpathEntries.length]; System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length); for (int i = 0; i < classpathEntries.length; i++) { newEntries[oldEntries.length + i] = classpathEntries[i]; }//w w w.ja v a 2s . com javaProject.setRawClasspath(newEntries, null); }
From source file:org.eclipse.edt.ide.ui.wizards.EGLProjectUtility.java
License:Open Source License
public static void removeClasspathLibraryEntriesIfNecessary(IProject project, IPath[] jarPaths) throws CoreException { IJavaProject javaProject; //The Java "view" of the project. if (project.hasNature(JavaCore.NATURE_ID)) { javaProject = JavaCore.create(project); int jarIndex = -1; IClasspathEntry curEntry;// ww w .j ava2s.co m List<IPath> delJarPaths = new ArrayList<IPath>(); for (IPath jarPath : jarPaths) { // String jarFile = jarPath.lastSegment(); IClasspathEntry[] oldEntries = javaProject.getRawClasspath(); // Look for the jar file in the current build path for (int i = 0; i < oldEntries.length; i++) { curEntry = oldEntries[i]; if (curEntry.getPath() != null) { if (curEntry.getPath().equals(jarPath)) { jarIndex = i; break; } } } // We will add a new entry into delJarPaths if the entry does exist. if (jarIndex > 0) { delJarPaths.add(jarPath); } } removeClasspathLibraryEntries(javaProject, delJarPaths.toArray(new IPath[delJarPaths.size()])); } }
From source file:org.eclipse.edt.ide.ui.wizards.EGLProjectUtility.java
License:Open Source License
public static void removeClasspathLibraryEntries(IJavaProject javaProject, IPath[] jarPaths) throws CoreException { IClasspathEntry[] oldEntries = javaProject.getRawClasspath(); if (oldEntries.length < jarPaths.length) return; //there are more paths to be deleted than the existing paths, should not reach here IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length - jarPaths.length]; int k = 0;//from w w w .java 2 s. com for (int i = 0; i < oldEntries.length; i++) { boolean isEntryKept = true; for (int j = 0; j < jarPaths.length; j++) { if (jarPaths[j].toString().equalsIgnoreCase(oldEntries[i].getPath().toString())) { isEntryKept = false; break; } } if (isEntryKept) { newEntries[k++] = oldEntries[i]; } } javaProject.setRawClasspath(newEntries, null); }
From source file:org.eclipse.edt.ide.ui.wizards.EGLProjectUtility.java
License:Open Source License
public static void modifyClasspathLibraryEntry(IProject project, IClasspathEntry[] modifiedEntries) throws CoreException { IJavaProject javaProject; //The Java "view" of the project. if (project.hasNature(JavaCore.NATURE_ID)) { javaProject = JavaCore.create(project); IClasspathEntry[] entries = javaProject.getRawClasspath(); IClasspathEntry[] newEntries = entries; for (int j = 0; j < modifiedEntries.length; j++) { for (int i = 0; i < entries.length; i++) { if (modifiedEntries[j].getPath().toOSString() .equalsIgnoreCase(entries[i].getPath().toOSString())) { newEntries[i] = modifiedEntries[j]; break; }/*from w w w . ja va2 s . c om*/ } } javaProject.setRawClasspath(newEntries, null); } }
From source file:org.eclipse.edt.ide.ui.wizards.ProjectConfigurationOperation.java
License:Open Source License
private void postAddingJavaBuildPathEntry(IEGLPathEntry[] selectedEntries, IProject curProject, IProgressMonitor monitor) {//from ww w. j av a 2 s. com try { if (curProject.hasNature(JavaCore.NATURE_ID)) { IJavaProject javaProject = JavaCore.create(curProject); IClasspathEntry[] javaClassPathEntries = javaProject.getRawClasspath(); List<IClasspathEntry> afterChangeEntries = new ArrayList<IClasspathEntry>(); Set ipathSet = new HashSet<IPath>(); for (IClasspathEntry icpEntry : javaClassPathEntries) { ipathSet.add(icpEntry.getPath()); afterChangeEntries.add(icpEntry); } for (IEGLPathEntry iEGLpathEntry : selectedEntries) { if (iEGLpathEntry.getEntryKind() == IEGLPathEntry.CPE_PROJECT) { IPath eglProjectPath = iEGLpathEntry.getPath(); IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(eglProjectPath); if (resource != null && resource.exists()) { if (resource.getProject().hasNature(JavaCore.NATURE_ID) && !ipathSet.contains(eglProjectPath)) { ipathSet.add(eglProjectPath); afterChangeEntries.add(JavaCore.newProjectEntry(eglProjectPath)); } } } } javaProject.setRawClasspath( afterChangeEntries.toArray(new IClasspathEntry[afterChangeEntries.size()]), monitor); } } catch (CoreException e) { e.printStackTrace(); } }
From source file:org.eclipse.emf.cdo.dawn.codegen.util.ProjectCreationHelper.java
License:Open Source License
/** * @param javaProject//from w w w . ja v a 2s. com * @param newEntry * @throws JavaModelException */ public final static void addToClasspath(IJavaProject javaProject, IClasspathEntry newEntry) throws JavaModelException { if (newEntry == null) { return; } IClasspathEntry[] oldEntries = javaProject.getRawClasspath(); IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 1]; System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length); newEntries[oldEntries.length] = newEntry; javaProject.setRawClasspath(newEntries, null); }