List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_CONTAINER
int CPE_CONTAINER
To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_CONTAINER.
Click Source Link
From source file:com.threecrickets.creel.eclipse.internal.EclipseUtil.java
License:LGPL
/** * Sets a classpath container in a project. If the classpath container is * already there, will recreate it. (Assumes that the path is only used * once.)/* w ww . ja v a 2 s. c om*/ * * @param project * The project * @param container * The classpath container * @throws JavaModelException * In case of an Eclipse JDT error */ public static void setClasspathContainer(IJavaProject project, IClasspathContainer container) throws JavaModelException { IPath path = container.getPath(); IClasspathEntry[] entries = project.getRawClasspath(); int found = -1; for (int i = 0, length = entries.length; i < length; i++) { IClasspathEntry entry = entries[i]; if ((entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) && (entry.getPath().equals(path))) { found = i; break; } } if (found == -1) { IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1]; System.arraycopy(entries, 0, newEntries, 0, entries.length); newEntries[entries.length] = JavaCore.newContainerEntry(container.getPath()); project.setRawClasspath(newEntries, null); } else { entries[found] = JavaCore.newContainerEntry(path); project.setRawClasspath(entries, null); } JavaCore.setClasspathContainer(Classpath.PATH, new IJavaProject[] { project }, new IClasspathContainer[] { container }, null); }
From source file:com.threecrickets.creel.eclipse.internal.EclipseUtil.java
License:LGPL
/** * Removes a classpath container from project if it is there. (Assumes that * the path is only used once.)//from w w w .j a v a2s.c om * * @param project * The project * @param path * The path * @throws JavaModelException * In case of an Eclipse JDT error */ public static void removeClasspathContainer(IJavaProject project, IPath path) throws JavaModelException { IClasspathEntry[] entries = project.getRawClasspath(); int found = -1; for (int i = 0, length = entries.length; i < length; i++) { IClasspathEntry entry = entries[i]; if ((entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) && (entry.getPath().equals(path))) { found = i; break; } } if (found != -1) { IClasspathEntry[] newEntries = new IClasspathEntry[entries.length - 1]; System.arraycopy(entries, 0, newEntries, 0, found); if (found != entries.length) System.arraycopy(entries, found + 1, newEntries, found, entries.length - found - 1); project.setRawClasspath(newEntries, null); } }
From source file:com.windowtester.eclipse.ui.convert.WTAPIUsage.java
License:Open Source License
private void collectPluginsReferencedByClasspathEntry(PrintWriter writer, Collection<String> pluginIds, IJavaProject proj, IClasspathEntry entry) throws IOException { IPath path = entry.getPath();//w ww .ja v a2 s.co m switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_VARIABLE: for (int i = path.segmentCount() - 1; i >= 0; i--) { String segment = path.segment(i); if (segment.startsWith("com.windowtester.")) { String id = segment; i++; while (i < path.segmentCount()) id += "/" + path.segment(i++); pluginIds.add(id); break; } } break; case IClasspathEntry.CPE_CONTAINER: if (path.segmentCount() >= 1 && path.segment(0).equals("org.eclipse.pde.core.requiredPlugins")) collectPluginsReferencedInManifest(pluginIds, proj); break; case IClasspathEntry.CPE_SOURCE: case IClasspathEntry.CPE_PROJECT: // ignored break; default: pluginIds.add("unknown " + entry.getEntryKind() + " - " + entry); break; } }
From source file:com.windowtester.swt.codegen.wizards.NewTestTypeWizard.java
License:Open Source License
private void updateClasspath(IResource resource) { try {/*from w w w . j a v a 2 s . co m*/ if (_wizardPage.isRcpApplication()) { IPath requiredPluginsPath = new Path("org.eclipse.pde.core.requiredPlugins"); IJavaProject javaProject = JavaCore.create(resource.getProject()); IClasspathEntry[] entries = javaProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (entry.getPath().equals(requiredPluginsPath)) { return; // no need to process } } } IClasspathEntry requiredPlugins = JavaCore.newContainerEntry(requiredPluginsPath); IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1]; System.arraycopy(entries, 0, newEntries, 0, entries.length); newEntries[entries.length] = requiredPlugins; javaProject.setRawClasspath(newEntries, null); } } catch (CoreException e) { Logger.log(e); } }
From source file:de.ovgu.featureide.aspectj.AspectJComposer.java
License:Open Source License
private void addClasspathFile(IProject project, String buildPath) { if (buildPath == null) { if (featureProject == null || featureProject.getBuildPath() == null) { buildPath = IFeatureProject.DEFAULT_SOURCE_PATH; } else {/*from ww w .java2 s . c o m*/ buildPath = featureProject.getBuildPath(); } } try { JavaProject javaProject = new JavaProject(project, null); IClasspathEntry[] oldEntries = javaProject.getRawClasspath(); boolean sourceAdded = false; boolean containerAdded = false; boolean ajContainerAdded = false; /** check if entries already exist **/ for (int i = 0; i < oldEntries.length; i++) { if (!sourceAdded && oldEntries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { /** correct the source entry **/ oldEntries[i] = getSourceEntry(buildPath); sourceAdded = true; } else if ((!containerAdded || !ajContainerAdded) && oldEntries[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) { /** check the container entries **/ if (oldEntries[i].getPath().equals(JRE_CONTAINER)) { containerAdded = true; } if (oldEntries[i].getPath().equals(ASPECTJRT_CONTAINER)) { ajContainerAdded = true; } } } /** case: no new entries **/ if (sourceAdded && containerAdded && ajContainerAdded) { javaProject.setRawClasspath(oldEntries, null); return; } /** add the new entries **/ IClasspathEntry[] entries = new IClasspathEntry[(sourceAdded ? 0 : 1) + (containerAdded ? 0 : 1) + (containerAdded ? 0 : 1) + oldEntries.length]; System.arraycopy(oldEntries, 0, entries, 0, oldEntries.length); if (!sourceAdded) { entries[oldEntries.length] = getSourceEntry(buildPath); } if (!containerAdded) { int position = (sourceAdded ? 0 : 1) + oldEntries.length; entries[position] = getContainerEntry(); } if (!ajContainerAdded) { int position = (sourceAdded ? 0 : 1) + (containerAdded ? 0 : 1) + oldEntries.length; entries[position] = getAJContainerEntry(); } javaProject.setRawClasspath(entries, null); } catch (JavaModelException e) { CorePlugin.getDefault().logError(e); } }
From source file:de.ovgu.featureide.aspectj.AspectJComposer.java
License:Open Source License
/** * @return The ClasspathEnttry for the AspectJ container *//*from w ww .ja v a2 s . co m*/ private IClasspathEntry getAJContainerEntry() { return new ClasspathEntry(IPackageFragmentRoot.K_SOURCE, IClasspathEntry.CPE_CONTAINER, ASPECTJRT_CONTAINER, new IPath[0], new IPath[0], null, null, null, false, null, false, new IClasspathAttribute[0]); }
From source file:de.ovgu.featureide.core.builder.ComposerExtensionClass.java
License:Open Source License
private void addClasspathFile(IProject project, String buildPath) { try {/*w w w .ja va 2s . com*/ JavaProject javaProject = new JavaProject(project, null); IClasspathEntry[] oldEntries = javaProject.getRawClasspath(); boolean sourceAdded = false; boolean containerAdded = false; /** check if entries already exist **/ for (int i = 0; i < oldEntries.length; i++) { if (!sourceAdded && oldEntries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { /** correct the source entry **/ // XXX the source entry should be equivalent to the build path, // but e.g. at FeatureHouse the real build path is src/config -> Builder problems // -> is it necessary to correct the path? if (oldEntries[i].getPath().toString().equals("/" + project.getName())) { /** necessary after creating a new FeatureIDE project **/ oldEntries[i] = setSourceEntry(buildPath, oldEntries[i]); } /** find source entry **/ sourceAdded = true; } else if (!containerAdded && oldEntries[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) { /** check the container entries **/ if (oldEntries[i].getPath().equals(JRE_CONTAINER)) { containerAdded = true; } } } /** case: no new entries **/ if (sourceAdded && containerAdded) { javaProject.setRawClasspath(oldEntries, null); return; } /** add the new entries **/ IClasspathEntry[] entries = new IClasspathEntry[(sourceAdded ? 0 : 1) + (containerAdded ? 0 : 1) + oldEntries.length]; System.arraycopy(oldEntries, 0, entries, 0, oldEntries.length); if (!sourceAdded) { entries[oldEntries.length] = getSourceEntry(buildPath); } if (!containerAdded) { int position = (sourceAdded ? 0 : 1) + oldEntries.length; entries[position] = getContainerEntry(); } javaProject.setRawClasspath(entries, null); } catch (JavaModelException e) { CorePlugin.getDefault().logError(e); } }
From source file:de.ovgu.featureide.core.builder.ComposerExtensionClass.java
License:Open Source License
/** * @return A default JRE container entry *///from w ww . ja va 2 s. c om public IClasspathEntry getContainerEntry() { return new ClasspathEntry(IPackageFragmentRoot.K_SOURCE, IClasspathEntry.CPE_CONTAINER, JRE_CONTAINER, new IPath[0], new IPath[0], null, null, null, false, null, false, new IClasspathAttribute[0]); }
From source file:de.ovgu.featureide.migration.impl.DefaultSPLMigrator.java
License:Open Source License
/** * @param newJavaProject/*from w ww . j a va 2s .c o m*/ * @param classpathToMigrate * @param newClassPath * @throws JavaModelException */ private void migrateLibraryAndContainerEntries(JavaProject newJavaProject, IClasspathEntry[] classpathToMigrate, List<IClasspathEntry> newClassPath) throws JavaModelException { for (IClasspathEntry entry : classpathToMigrate) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER || entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) if (!newClassPath.contains(entry)) newClassPath.add(entry); } newJavaProject.setRawClasspath(newClassPath.toArray(new IClasspathEntry[newClassPath.size()]), null); }
From source file:de.se_rwth.langeditor.util.ResourceLocator.java
License:Open Source License
public static Optional<IClasspathEntry> getModelPathClasspathEntry(IJavaProject javaProject) { try {/*from w w w.java 2 s. c o m*/ return Arrays.stream(javaProject.getRawClasspath()) .filter(classpathEntry -> classpathEntry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) .filter(classpathEntry -> classpathEntry.getPath().equals(Constants.MODELPATH)).findFirst(); } catch (JavaModelException e) { return Optional.empty(); } }