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.apache.ivyde.eclipse.cp.IvyClasspathContainerHelper.java
License:Apache License
public static List<IvyClasspathContainer> getContainersFromIvySettings(IFile ivySettings) { IJavaProject javaProject = JavaCore.create(ivySettings.getProject()); List<IvyClasspathContainer> containers = new ArrayList<IvyClasspathContainer>(); if (javaProject == null || !javaProject.exists()) { return containers; }// w w w .j a v a 2s .c om try { IClasspathEntry[] entries = javaProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IPath path = entry.getPath(); if (isIvyClasspathContainer(path)) { IClasspathContainer cp = JavaCore.getClasspathContainer(path, javaProject); if (cp instanceof IvyClasspathContainerImpl) { IvyClasspathContainerImpl ivycp = (IvyClasspathContainerImpl) cp; ResolvedPath settingsPath; try { settingsPath = ivycp.getConf().getInheritedSettingsSetup() .getResolvedIvySettingsPath(ivycp.getConf().getProject()); } catch (IvyDEException e) { // cannot resolve the ivy settings so just ignore continue; } if (settingsPath.getResolvedPath() .equals(ivySettings.getProjectRelativePath().toString())) { containers.add(ivycp); } } } } } } catch (JavaModelException e) { // unless there are issues with the JDT, this should never happen IvyPlugin.log(e); } return containers; }
From source file:org.apache.ivyde.eclipse.cp.IvyClasspathContainerHelper.java
License:Apache License
/** * Search the Ivy classpath entry within the specified Java project with the specific path * //from w w w . java 2s. co m * @param containerPath * the path of the container * @param javaProject * the project to search into * @return the Ivy classpath container if found, otherwise return <code>null</code> */ public static IClasspathEntry getEntry(IPath containerPath, IJavaProject javaProject) { if (javaProject == null || !javaProject.exists()) { return null; } try { IClasspathEntry[] entries = javaProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (containerPath.equals(entry.getPath())) { return entry; } } } } catch (JavaModelException e) { // unless there are issues with the JDT, this should never happen IvyPlugin.log(e); } return null; }
From source file:org.azzyzt.jee.tools.project.JavaProject.java
License:EUPL
protected void moveJreToEndOfClassPath() throws JavaModelException { IClasspathEntry[] rawClasspath = jp.getRawClasspath(); IClasspathEntry[] newRawClassPath = new IClasspathEntry[rawClasspath.length]; for (int i = 0, offset = 0; i < rawClasspath.length; i++) { IClasspathEntry cpe = rawClasspath[i]; if (cpe.getEntryKind() == IClasspathEntry.CPE_CONTAINER && cpe.getPath().toString().startsWith("org.eclipse.jdt.launching.JRE_CONTAINER")) { if (newRawClassPath[rawClasspath.length - 1] == null) { newRawClassPath[rawClasspath.length - 1] = cpe; offset = 1;/*w ww .j ava2s. c o m*/ } else { Common.getDefault().log( "FacetedProject " + getP().getName() + " has more than one JRE class path entry!!"); newRawClassPath[i - offset] = cpe; } } else { newRawClassPath[i - offset] = cpe; } } jp.setRawClasspath(newRawClassPath, null); }
From source file:org.bndtools.builder.BndProjectNature.java
License:Open Source License
private void installBndClasspath() throws CoreException { IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] classpath = javaProject.getRawClasspath(); for (IClasspathEntry entry : classpath) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && BndtoolsConstants.BND_CLASSPATH_ID.equals(entry.getPath())) return; // already installed }//ww w . j av a2 s .com IClasspathEntry[] newEntries = new IClasspathEntry[classpath.length + 1]; System.arraycopy(classpath, 0, newEntries, 0, classpath.length); newEntries[classpath.length] = JavaCore.newContainerEntry(BndtoolsConstants.BND_CLASSPATH_ID); javaProject.setRawClasspath(newEntries, null); }
From source file:org.bndtools.builder.BndProjectNature.java
License:Open Source License
private void removeBndClasspath() throws CoreException { IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] classpath = javaProject.getRawClasspath(); List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>(classpath.length); boolean changed = false; for (IClasspathEntry entry : classpath) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && BndtoolsConstants.BND_CLASSPATH_ID.equals(entry.getPath())) { changed = true;/*from ww w .j a v a 2s .c o m*/ } else { newEntries.add(entry); } } if (changed) javaProject.setRawClasspath(newEntries.toArray(new IClasspathEntry[0]), null); }
From source file:org.checkthread.plugin.eclipse.CheckThreadRunner.java
License:Open Source License
private static void loadDirFromProject(HashMap<IProject, Boolean> projectSearchMap, boolean isrecursed, IProject project, ArrayList<IPath> srcDirList, ArrayList<URI> targetFileList, ArrayList<URI> classPathList) { // if we already searched this project if (projectSearchMap.get(project) != null) { return;/*from w w w . ja v a2 s. c o m*/ // we haven't searched this project yet } else { // add to cache projectSearchMap.put(project, true); } // recursive traverse referenced projects // stopping condition: project already searched try { IProject[] projectList = project.getReferencedProjects(); for (IProject p : projectList) { loadDirFromProject(projectSearchMap, true, p, srcDirList, targetFileList, classPathList); } } catch (Exception e) { e.printStackTrace(); } IJavaProject javaProject = JavaCore.create(project); IPath defaultOutputLocationRelative = null; try { defaultOutputLocationRelative = javaProject.getOutputLocation(); } catch (Exception e) { e.printStackTrace(); return; } sLogger.info("DEFAULT OUTPUT LOCATION RELATIVE: " + defaultOutputLocationRelative); IPath projectLocationAbsolute = project.getLocation(); sLogger.info("PROJECT LOCATION: " + projectLocationAbsolute); // Make path absolute IPath defaultOutputLocationAbsolute = projectLocationAbsolute .append(defaultOutputLocationRelative.removeFirstSegments(1)); sLogger.info("DEFAULT OUTPUT LOCATION ABSOLUTE: " + defaultOutputLocationAbsolute); // Work around, stomp over target java files. Instead, just give the // root directory sLogger.info("WORKAROUND: IGNORE CHANGED CLASS FILES< RECHECK EVERYTHING"); if (!isrecursed) { URI uri = defaultOutputLocationAbsolute.toFile().toURI(); if (uri != null) { targetFileList.add(uri); } } // Add to input URI cURI = defaultOutputLocationAbsolute.toFile().toURI(); if (cURI != null) { classPathList.add(cURI); } // Loop through classpath entries and get src directory list IClasspathEntry[] rawClassPathList = null; try { rawClassPathList = javaProject.getRawClasspath(); } catch (JavaModelException e) { e.printStackTrace(); } if (rawClassPathList != null) { for (IClasspathEntry classPathEntry : rawClassPathList) { switch (classPathEntry.getEntryKind()) { // Source Directory case IClasspathEntry.CPE_SOURCE: { if (!isrecursed) { IPath p = classPathEntry.getPath().removeFirstSegments(1); if (p != null) { srcDirList.add(p); sLogger.info("CPE_SOURCE: " + p); } } break; } // external libraries used case IClasspathEntry.CPE_LIBRARY: { File file = classPathEntry.getPath().toFile(); IPath p; // The entry may be a relative path to the project root // or it could be an absolute path to a library. if (file.isFile() || file.isDirectory()) { p = classPathEntry.getPath(); } else { p = projectLocationAbsolute.append(classPathEntry.getPath().removeFirstSegments(1)); } URI uri = p.toFile().toURI(); if (uri != null) { classPathList.add(uri); } sLogger.info("CPE_LIBRARY: " + uri); break; } // ignore case IClasspathEntry.CPE_CONTAINER: sLogger.info("CPE_CONTAINER: " + classPathEntry); break; //ignore case IClasspathEntry.CPE_PROJECT: sLogger.info("CPE_PROJECT: " + classPathEntry); break; } } } }
From source file:org.cloudfoundry.ide.eclipse.internal.server.core.CloudUtil.java
License:Open Source License
public static String getFramework(IProject project) { if (project != null) { IJavaProject javaProject = CloudFoundryProjectUtil.getJavaProject(project); if (javaProject != null) { if (CloudFoundryProjectUtil.hasNature(project, DeploymentConstants.GRAILS_NATURE)) { return CloudApplication.GRAILS; }// ww w .jav a 2s.com // in case user has Grails projects without the nature // attached if (project.isAccessible() && project.getFolder("grails-app").exists() && project.getFile("application.properties").exists()) { return CloudApplication.GRAILS; } IClasspathEntry[] entries; boolean foundSpringLibrary = false; try { entries = javaProject.getRawClasspath(); for (IClasspathEntry entry : entries) { if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { if (isLiftLibrary(entry)) { return DeploymentConstants.LIFT; } if (isSpringLibrary(entry)) { foundSpringLibrary = true; } } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject); if (container != null) { for (IClasspathEntry childEntry : container.getClasspathEntries()) { if (isLiftLibrary(childEntry)) { return DeploymentConstants.LIFT; } if (isSpringLibrary(childEntry)) { foundSpringLibrary = true; } } } } } } catch (JavaModelException e) { CloudFoundryPlugin.logError(new Status(IStatus.WARNING, CloudFoundryPlugin.PLUGIN_ID, "Unexpected error during auto detection of application type", e)); } if (CloudFoundryProjectUtil.isSpringProject(project)) { return CloudApplication.SPRING; } if (foundSpringLibrary) { return CloudApplication.SPRING; } } } return null; }
From source file:org.cloudfoundry.ide.eclipse.internal.server.ui.wizards.CloudFoundryApplicationWizardPage.java
License:Open Source License
private static String getFramework(ApplicationModule module) { if (module != null && module.getLocalModule() != null) { IProject project = module.getLocalModule().getProject(); if (project != null) { IJavaProject javaProject = CloudFoundryProjectUtil.getJavaProject(project); if (javaProject != null) { if (CloudFoundryProjectUtil.hasNature(project, GRAILS_NATURE)) { return CloudApplication.GRAILS; }//from w w w. java 2s . c o m // in case user has Grails projects without the nature // attached if (project.isAccessible() && project.getFolder("grails-app").exists() && project.getFile("application.properties").exists()) { return CloudApplication.GRAILS; } IClasspathEntry[] entries; boolean foundSpringLibrary = false; try { entries = javaProject.getRawClasspath(); for (IClasspathEntry entry : entries) { if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { if (isLiftLibrary(entry)) { return LIFT; } if (isSpringLibrary(entry)) { foundSpringLibrary = true; } } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject); if (container != null) { for (IClasspathEntry childEntry : container.getClasspathEntries()) { if (isLiftLibrary(childEntry)) { return LIFT; } if (isSpringLibrary(childEntry)) { foundSpringLibrary = true; } } } } } } catch (JavaModelException e) { CloudFoundryServerUiPlugin.getDefault().getLog() .log(new Status(IStatus.WARNING, CloudFoundryServerUiPlugin.PLUGIN_ID, "Unexpected error during auto detection of application type", e)); } if (CloudFoundryProjectUtil.isSpringProject(project)) { return CloudApplication.SPRING; } if (foundSpringLibrary) { return CloudApplication.SPRING; } } } } return CloudApplication.JAVA_WEB; }
From source file:org.cloudfoundry.ide.eclipse.server.core.internal.application.JavaWebApplicationDelegate.java
License:Open Source License
/** * Attempts to determine the framework based on the contents and nature of * the project. Returns null if no framework was determined. * @param project/* w w w . ja va 2s .c o m*/ * @return Framework type or null if framework was not determined. * @deprecated kept for reference as to how application type was being * determined from a Java project for legacy v1 CF servers. v2 Servers no * longer require a framework for an application, as frameworks have been * replaced with buildpacks. */ protected String getFramework(IProject project) { if (project != null) { IJavaProject javaProject = CloudFoundryProjectUtil.getJavaProject(project); if (javaProject != null) { if (CloudFoundryProjectUtil.hasNature(project, CloudFoundryConstants.GRAILS_NATURE)) { return CloudFoundryConstants.GRAILS; } // in case user has Grails projects without the nature // attached if (project.isAccessible() && project.getFolder("grails-app").exists() //$NON-NLS-1$ && project.getFile("application.properties").exists()) { //$NON-NLS-1$ return CloudFoundryConstants.GRAILS; } IClasspathEntry[] entries; boolean foundSpringLibrary = false; try { entries = javaProject.getRawClasspath(); for (IClasspathEntry entry : entries) { if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { if (isLiftLibrary(entry)) { return CloudFoundryConstants.LIFT; } if (isSpringLibrary(entry)) { foundSpringLibrary = true; } } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject); if (container != null) { for (IClasspathEntry childEntry : container.getClasspathEntries()) { if (isLiftLibrary(childEntry)) { return CloudFoundryConstants.LIFT; } if (isSpringLibrary(childEntry)) { foundSpringLibrary = true; } } } } } } catch (JavaModelException e) { // Log the error but don't throw it again as there may be // other ways to detect the framework CloudFoundryPlugin.log(new Status(IStatus.WARNING, CloudFoundryPlugin.PLUGIN_ID, "Unexpected error during auto detection of application type", e)); //$NON-NLS-1$ } if (CloudFoundryProjectUtil.isSpringProject(project)) { return CloudFoundryConstants.SPRING; } if (foundSpringLibrary) { return CloudFoundryConstants.SPRING; } } } return null; }
From source file:org.codehaus.groovy.eclipse.core.model.GroovyRuntime.java
License:Apache License
public static boolean hasClasspathContainer(final IJavaProject javaProject, final IPath libraryPath) throws CoreException { if (javaProject == null || !javaProject.getProject().isAccessible()) return false; final IClasspathEntry[] entries = javaProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { final IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (ObjectUtils.equals(entry.getPath(), libraryPath) || libraryPath.isPrefixOf(entry.getPath())) { return true; }/* ww w. j a va2 s . c o m*/ } } return false; }