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:org.codehaus.groovy.eclipse.core.model.GroovyRuntime.java
License:Apache License
/** * Adds a library/folder that already exists in the project to the * classpath. Only added if it is not already on the classpath. * * @param javaProject//from w w w.j a v a2s .co m * The project to add add the classpath entry to. * @param libraryPath * The path to add to the classpath. * @param isExported TODO * @throws JavaModelException */ public static void addLibraryToClasspath(final IJavaProject javaProject, final IPath libraryPath, boolean isExported) throws JavaModelException { boolean alreadyExists = includesClasspathEntry(javaProject, libraryPath.lastSegment()); if (alreadyExists) { return; } addClassPathEntry(javaProject, new ClasspathEntry(IPackageFragmentRoot.K_BINARY, IClasspathEntry.CPE_CONTAINER, libraryPath, ClasspathEntry.INCLUDE_ALL, // inclusion patterns ClasspathEntry.EXCLUDE_NONE, // exclusion patterns null, null, null, // specific output folder true, // exported ClasspathEntry.NO_ACCESS_RULES, false, // no access rules to // combine ClasspathEntry.NO_EXTRA_ATTRIBUTES)); }
From source file:org.codehaus.groovy.eclipse.test.TestProject.java
License:Apache License
public boolean hasGroovyContainer() throws JavaModelException { IClasspathEntry[] entries = javaProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { if (entries[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER && entries[i].getPath().equals(GroovyClasspathContainer.CONTAINER_ID)) { return true; }// w w w . j a v a2s . com } return false; }
From source file:org.compiere.mfg_scm.eclipse.db.DbfBootstrap.java
License:Apache License
private void getClassPathEntries(IJavaProject prj, ArrayList data, List selectedPaths, ArrayList visitedProjects) { IClasspathEntry[] entries = null;//from ww w . jav a 2 s .c o m IPath outputPath = null; try { outputPath = prj.getOutputLocation(); if (selectedPaths.contains(outputPath.toFile().toString().replace('\\', '/'))) { add(data, prj.getProject().getWorkspace().getRoot().findMember(outputPath)); } entries = prj.getRawClasspath(); } catch (JavaModelException e) { DbfLauncherPlugin.log(e); } if (entries == null) return; for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; IPath path = entry.getPath(); if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { path = entry.getOutputLocation(); if (path == null) continue; } if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { String prjName = entry.getPath().lastSegment(); if (!visitedProjects.contains(prjName)) { visitedProjects.add(prjName); getClassPathEntries(prj.getJavaModel().getJavaProject(prjName), data, selectedPaths, visitedProjects); } continue; } else if (!selectedPaths.contains(path.toFile().toString().replace('\\', '/'))) continue; IClasspathEntry[] tmpEntry = null; if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { try { tmpEntry = JavaCore.getClasspathContainer(path, prj).getClasspathEntries(); } catch (JavaModelException e1) { DbfLauncherPlugin.log(e1); continue; } } else { tmpEntry = new IClasspathEntry[1]; tmpEntry[0] = JavaCore.getResolvedClasspathEntry(entry); } for (int j = 0; j < tmpEntry.length; j++) { if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IResource res = prj.getProject().getWorkspace().getRoot().findMember(tmpEntry[j].getPath()); if (res != null) add(data, res); else add(data, tmpEntry[j].getPath()); } else if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath srcPath = entry.getOutputLocation(); if (srcPath != null && !srcPath.equals(outputPath)) { add(data, prj.getProject().getWorkspace().getRoot().findMember(srcPath)); } } else { add(data, tmpEntry[j].getPath()); } } } }
From source file:org.ebayopensource.turmeric.eclipse.errorlibrary.buildsystem.core.ErrorLibraryBuildSystemConfigurer.java
License:Open Source License
/** * Adds the java support.// w w w .ja v a2s . com * * @param errorLibraryProject the error library project * @param outputLocation the output location * @param monitor the monitor * @throws CoreException the core exception */ public static void addJavaSupport(SOAErrorLibraryProject errorLibraryProject, String outputLocation, IProgressMonitor monitor) throws CoreException { final IProject project = errorLibraryProject.getProject(); boolean changedClasspath = false; if (JDTUtil.addJavaNature(project, monitor)) { changedClasspath = true; } // Configuring the Java Project final IJavaProject javaProject = JavaCore.create(project); final List<IClasspathEntry> classpath = JDTUtil.rawClasspath(javaProject, true); final List<IClasspathEntry> classpathContainers = new ArrayList<IClasspathEntry>(); // TODO Lets see if we need this if (outputLocation.equals(javaProject.getOutputLocation()) == false) { final IFolder outputDirClasses = project.getFolder(outputLocation); javaProject.setOutputLocation(outputDirClasses.getFullPath(), monitor); changedClasspath = true; } // Dealing with the case where the root of the project is set to be the // src and bin destinations... bad... bad... for (final Iterator<IClasspathEntry> iterator = classpath.iterator(); iterator.hasNext();) { final IClasspathEntry entry = iterator.next(); if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { classpathContainers.add(entry); } if (entry.getEntryKind() != IClasspathEntry.CPE_SOURCE || !entry.getPath().equals(new Path("/" + project.getName()))) continue; iterator.remove(); changedClasspath |= true; } for (final SOAProjectSourceDirectory dir : errorLibraryProject.getSourceDirectories()) { if (!WorkspaceUtil.isDotDirectory(dir.getLocation())) { final IFolder source = project.getFolder(dir.getLocation()); // If the Java project existed previously, checking if // directories // already exist in // its classpath. boolean found = false; for (final IClasspathEntry entry : classpath) { if (!entry.getPath().equals(source.getFullPath())) continue; found = true; break; } if (found) continue; changedClasspath |= true; IPath[] excludePatterns = ClasspathEntry.EXCLUDE_NONE; if (dir.getExcludePatterns() != null) { int length = dir.getExcludePatterns().length; excludePatterns = new Path[length]; for (int i = 0; i < length; i++) { excludePatterns[i] = new Path(dir.getExcludePatterns()[i]); } } IPath outputPath = dir.getOutputLocation() != null ? project.getFolder(dir.getOutputLocation()).getFullPath() : null; final IClasspathEntry entry = JavaCore.newSourceEntry(source.getFullPath(), excludePatterns, outputPath); classpath.add(entry); } } ProgressUtil.progressOneStep(monitor); // Adding the runtime library boolean found = false; for (final IClasspathEntry entry : classpath) { // All JRE Containers should have a prefix of // org.eclipse.jdt.launching.JRE_CONTAINER if (JavaRuntime.newDefaultJREContainerPath().isPrefixOf(entry.getPath()) && JavaRuntime.newDefaultJREContainerPath().equals(entry.getPath())) { found = true; break; } } if (!found) { changedClasspath = true; classpath.add(JavaRuntime.getDefaultJREContainerEntry()); } // we want all classpath containers to be the end of .classpath file classpath.removeAll(classpathContainers); classpath.addAll(classpathContainers); ProgressUtil.progressOneStep(monitor); // Configuring the classpath of the Java Project if (changedClasspath) { javaProject.setRawClasspath(classpath.toArray(new IClasspathEntry[0]), null); } }
From source file:org.ebayopensource.turmeric.eclipse.maven.core.utils.MavenCoreUtils.java
License:Open Source License
/** * Gets the maven2 classpath container./* ww w.j a va 2 s . c o m*/ * * @param project the project * @return the maven2 classpath container * @throws JavaModelException the java model exception */ public static IClasspathContainer getMaven2ClasspathContainer(IJavaProject project) throws JavaModelException { IClasspathEntry[] entries = project.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && isMaven2ClasspathContainer(entry.getPath())) { return JavaCore.getClasspathContainer(entry.getPath(), project); } } return null; }
From source file:org.ebayopensource.turmeric.eclipse.utils.plugin.JDTUtil.java
License:Open Source License
/** * Checks if is classpath container.// w w w . j a v a2 s . c om * * @param entry the entry * @param path the path * @return true, if is classpath container */ public static boolean isClasspathContainer(final IClasspathEntry entry, final String path) { return entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && (path.equals(entry.getPath().segment(0))); }
From source file:org.ebayopensource.turmeric.eclipse.utils.test.plugin.TestJDTUtil.java
License:Open Source License
/** * Test method for {@link org.ebayopensource.turmeric.eclipse.utils.plugin.JDTUtil#isClasspathContainer(org.eclipse.jdt.core.IClasspathEntry, java.lang.String)}. * Test method for {@link org.ebayopensource.turmeric.eclipse.utils.plugin.JDTUtil#isJREClasspathContainer(org.eclipse.jdt.core.IClasspathEntry)}. * @throws JavaModelException /*from w w w . ja va 2s . c o m*/ */ @Test public void testIsClasspathContainer() throws JavaModelException { for (IClasspathEntry entry : JDTUtil.rawClasspath(project, true)) { switch (entry.getContentKind()) { case IClasspathEntry.CPE_CONTAINER: Assert.assertTrue(JDTUtil.isClasspathContainer(entry, entry.getPath().toString())); break; default: //Assert.assertFalse(JDTUtil.isClasspathContainer(entry, entry.getPath().toString())); break; } } }
From source file:org.ebayopensource.turmeric.repositorysystem.imp.impl.TurmericProjectConfigurer.java
License:Open Source License
private void mavenizeAndCleanUp(final IProject project, final ProjectMavenizationRequest request, final IProgressMonitor monitor) throws CoreException, MavenEclipseApiException, IOException, InterruptedException, TemplateException { if (SOALogger.DEBUG) logger.entering(project, request); final IMavenEclipseApi api = MavenCoreUtils.mavenEclipseAPI(); try {/*w w w . j a v a2 s .c o m*/ // It seems that the pom.xml is not updated in the Eclipse Workspace by the mavenize project operation // Util.refresh( project.getFile( "pom.xml" ) ); // Project Mavenization doesn't seem to care that the output directory is set here and set in the pom.xml // it will use the maven default of target-eclipse no matter what. IJavaProject javaProject = null; try { api.mavenizeProject(request, monitor); logger.info("Mavenization finished->" + project); ProgressUtil.progressOneStep(monitor); javaProject = JavaCore.create(project); //javaProject.setOutputLocation( project.getFolder( SOAProjectConstants.FOLDER_OUTPUT_DIR).getFullPath(), null ); FileUtils.deleteDirectory(project.getFolder("target-eclipse").getLocation().toFile()); //Util.delete( project.getFolder( "target-eclipse" ), null ); final Map<?, ?> options = javaProject.getOptions(false); options.clear(); javaProject.setOptions(options); } catch (NullPointerException e) { throw new CoreException(EclipseMessageUtils.createErrorStatus( "NPE occured during projects mavenization.\n\n" + "The possible cause is that the M2Eclipse Maven indexes in your current workspace might be corrupted. " + "Please remove folder {workspace}/.metadata/.plugins/org.maven.ide.eclipse/, and then restart your IDE.", e)); } // The Mavenization also seemed to take the META-SRC src directory and add an exclusion pattern along with // setting its output location to itself. Maybe they wanted to do a class library folder? Either way its // no good for us. Secondly, we are setting the Maven classpath container to have its entries exported by default. // Finally, we are adding the classpath entry attribute 'org.eclipse.jst.component.dependency' in case the project // is a WTP web project so that WTP will use the maven classpath container when deploying to its runtime servers. boolean changed = false; final List<IClasspathEntry> newEntries = ListUtil.list(); final IPath containerPath = new Path(SOAMavenConstants.MAVEN_CLASSPATH_CONTAINER_ID); for (final IClasspathEntry cpEntry : JDTUtil.rawClasspath(javaProject, true)) { if (cpEntry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (cpEntry.getPath().equals(containerPath)) { newEntries.add(JavaCore.newContainerEntry(containerPath, true)); changed |= true; } } else if (cpEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (!ArrayUtils.isEmpty(cpEntry.getExclusionPatterns()) || cpEntry.getOutputLocation() != null) { newEntries.add(JavaCore.newSourceEntry(cpEntry.getPath())); changed |= true; } else { newEntries.add(cpEntry); } } else { newEntries.add(cpEntry); } } ProgressUtil.progressOneStep(monitor, 15); if (changed) { javaProject.setRawClasspath(newEntries.toArray(new IClasspathEntry[0]), null); ProgressUtil.progressOneStep(monitor); //This is a hot fix for the Maven classpath container issue, //should be removed as soon as the M2Eclipse guys fix it int count = 0; //we only go to sleep 5 times. while (MavenCoreUtils.getMaven2ClasspathContainer(javaProject).getClasspathEntries().length == 0 && count < 5) { logger.warning("Maven Classpath is empty->", SOAMavenConstants.MAVEN_CLASSPATH_CONTAINER_ID, ", going to sleep..."); Thread.sleep(1000); ProgressUtil.progressOneStep(monitor, 10); count++; } } } finally { if (SOALogger.DEBUG) logger.exiting(); } }
From source file:org.ebayopensource.turmeric.repositorysystem.imp.impl.TurmericProjectConfigurer.java
License:Open Source License
/** * {@inheritDoc}//w ww . j av a 2 s . c o m * */ public void addBuildSystemClasspathContainer(IJavaProject javaProject, IProgressMonitor monitor) throws CoreException { boolean found = false; final List<IClasspathEntry> newEntries = JDTUtil.rawClasspath(javaProject, true); final IPath containerPath = new Path(SOAMavenConstants.MAVEN_CLASSPATH_CONTAINER_ID); for (final IClasspathEntry cpEntry : newEntries) { if (cpEntry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (cpEntry.getPath().equals(containerPath)) { found = true; break; } } } ProgressUtil.progressOneStep(monitor, 15); if (found == false) { newEntries.add(JavaCore.newContainerEntry(containerPath, true)); javaProject.setRawClasspath(newEntries.toArray(new IClasspathEntry[0]), null); ProgressUtil.progressOneStep(monitor); } }
From source file:org.ebayopensource.vjet.eclipse.core.PiggyBackClassPathUtil.java
License:Open Source License
public static URL[] getProjectDependencyUrls_bak(List<IJavaProject> javaProjectList, List<URL> currentUrlList, HashMap<String, String> projectMap) throws JavaModelException, MalformedURLException { List<URL> projectDependencyUrlList = currentUrlList; if (projectDependencyUrlList == null) { projectDependencyUrlList = new ArrayList<URL>(); }/*from www . j av a 2 s . c om*/ for (IJavaProject project : javaProjectList) { if (projectMap.containsKey(project.getElementName()) == true) { continue; } else { projectMap.put(project.getElementName(), project.getElementName()); } // Add the dependencies to the URL list // IClasspathEntry[] entries; // entries = project.getResolvedClasspath(true); IClasspathEntry[] entries2; entries2 = project.getRawClasspath(); for (IClasspathEntry entry : entries2) { IPath path = entry.getPath(); File f = path.toFile(); URL entryUrl; entryUrl = f.toURL(); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_VARIABLE: case IClasspathEntry.CPE_LIBRARY: addEntryToList(entry, projectDependencyUrlList); case IClasspathEntry.CPE_PROJECT: List<IJavaProject> subjavaProjectList = new ArrayList<IJavaProject>(); IResource subResource = ResourcesPlugin.getWorkspace().getRoot().findMember(entry.getPath()); if (subResource == null) { String projectName = entry.getPath().toString(); String parentProjectName = project.getElementName(); } if (subResource != null && subResource.getType() == IResource.PROJECT) { IProject subProject = (IProject) subResource; IJavaProject subJavaProject = JavaCore.create(subProject); if (subJavaProject != null && subJavaProject.exists()) { subjavaProjectList.add(subJavaProject); // Recursively call our selves to populate the // project // dependency's for the sub projects. getProjectDependencyUrls_bak(subjavaProjectList, projectDependencyUrlList, projectMap); } } break; case IClasspathEntry.CPE_CONTAINER: if (!JavaRuntime.JRE_CONTAINER.equals(path.toOSString())) { IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), project); if (container != null) { IClasspathEntry[] entries = container.getClasspathEntries(); for (int i = 0; i < entries.length; i++) { addEntryToList(entries[i], projectDependencyUrlList); } } } break; default: break; } } // // IPath path = project.getOutputLocation(); // IPath projectResourceLocation = // project.getResource().getLocation(); // File projectFilePath = projectResourceLocation.append( // path.removeFirstSegments(1)).toFile(); // URL projectOutputUrl; // projectOutputUrl = projectFilePath.toURL(); // // if (projectDependencyUrlList.contains(projectOutputUrl) == false) // { // projectDependencyUrlList.add(projectOutputUrl); // } } URL[] arrayList = new URL[projectDependencyUrlList.size()]; URL[] returnURLArray = projectDependencyUrlList.toArray(arrayList); return returnURLArray; }