List of usage examples for org.eclipse.jdt.core IClasspathEntry getEntryKind
int getEntryKind();
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 w w w. j a va 2 s. c om } else { newEntries.add(entry); } } if (changed) javaProject.setRawClasspath(newEntries.toArray(new IClasspathEntry[0]), null); }
From source file:org.bonitasoft.studio.common.repository.Repository.java
License:Open Source License
@Override public URLClassLoader createProjectClassloader() { final List<URL> jars = new ArrayList<URL>(); try {//w w w . j a va2 s. co m if (!classpathExists()) { initClasspath(getProject()); } //Synchronize with build jobs Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD, NULL_PROGRESS_MONITOR); Job.getJobManager().join(ResourcesPlugin.FAMILY_MANUAL_BUILD, NULL_PROGRESS_MONITOR); IProject project = getProject(); String workspacePath = project.getLocation().toFile().getParent(); String outputPath = workspacePath + getJavaProject().getOutputLocation().toString(); jars.add(new File(outputPath).toURI().toURL()); for (IClasspathEntry entry : getJavaProject().getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { File jar = entry.getPath().toFile(); if (!jar.exists()) { // jar location relative to project jar = new File(workspacePath + File.separator + jar); } jars.add(jar.toURI().toURL()); } } } catch (Exception e) { BonitaStudioLog.error(e); } return new NonLockingJarFileClassLoader(getName() + "_URLClassLoader", jars.toArray(new URL[jars.size()]), BusinessArchive.class.getClassLoader()); }
From source file:org.bonitasoft.studio.repository.test.TestExtensionProject.java
License:Open Source License
public void testExtensionProjectClasspathDoesNotContainAbsoluteFile() throws JavaModelException { for (IClasspathEntry entry : RepositoryManager.getInstance().getCurrentRepository().getJavaProject() .getRawClasspath()) {/* ww w . j a v a2 s .c o m*/ if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { File file = new File(entry.getPath().toString()); if (file.exists() && file.isAbsolute() && !Platform.inDevelopmentMode()) { fail("Classpath should not contain absolute entry: " + entry.getPath().toString()); } } } }
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 . j a v a 2 s .com*/ // 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; }//from w ww . j a v a 2 s. c om // 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.core.standalone.StandaloneRuntimeResolver.java
License:Open Source License
/** * Returns either test sources, or non-test sources, based on a flag * setting. If nothing is found, returns empty list. *//* w w w . java2 s . c o m*/ protected Collection<IClasspathEntry> getSourceEntries(boolean istest) { try { IClasspathEntry[] rawEntries = javaProject.getRawClasspath(); if (rawEntries != null) { Collection<IClasspathEntry> sourceEntries = new HashSet<IClasspathEntry>(); for (IClasspathEntry entry : rawEntries) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath path = entry.getPath(); if (path != null) { boolean isTestSource = isTestSource(path.toOSString()); if ((istest && isTestSource) || (!istest && !isTestSource)) { sourceEntries.add(entry); } } } } return sourceEntries; } } catch (JavaModelException e) { CloudFoundryPlugin.logError(e); } return Collections.emptyList(); }
From source file:org.cloudfoundry.ide.eclipse.internal.server.ui.standalone.JavaUIHelper.java
License:Open Source License
public IPackageFragment getDefaultPackageFragment() { IJavaProject javaProject = getJavaProject(); if (getJavaProject() == null) { return null; }//from ww w .j a v a 2 s .c om IPackageFragmentRoot[] roots = null; try { IClasspathEntry[] entries = javaProject.getRawClasspath(); for (IClasspathEntry entry : entries) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { roots = javaProject.findPackageFragmentRoots(entry); if (roots != null) { break; } } } } catch (JavaModelException e) { CloudFoundryPlugin.logError(e); } if (roots != null) { IPackageFragment fragment = null; for (IPackageFragmentRoot root : roots) { try { IJavaElement[] members = root.getChildren(); if (members != null) { for (IJavaElement element : members) { if (element instanceof IPackageFragment) { IPackageFragment frag = (IPackageFragment) element; if (frag.isDefaultPackage()) { fragment = frag; break; } } } } if (fragment != null) { break; } } catch (JavaModelException e) { CloudFoundryPlugin.logError(e); } } return fragment; } 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; }/* w w w . j a va2 s. 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 . j a v a2s . 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.cloudfoundry.ide.eclipse.server.core.internal.CloudFoundryProjectUtil.java
License:Open Source License
private static boolean hasBootDependencies(IClasspathEntry e) { if (e.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath path = e.getPath();//from ww w . j ava2 s.com String name = path.lastSegment(); return name.endsWith(".jar") && name.startsWith("spring-boot"); //$NON-NLS-1$ //$NON-NLS-2$ } return false; }