List of usage examples for org.eclipse.jdt.core IClasspathEntry getEntryKind
int getEntryKind();
From source file:org.ebayopensource.turmeric.eclipse.resources.util.SOAImplUtil.java
License:Open Source License
/** * Fill metadata.//from w w w . java 2 s .com * * @param eclipseMetadata the eclipse metadata * @param implProject the impl project * @return the sOA impl project * @throws Exception the exception */ public static SOAImplProject fillMetadata(final SOAProjectEclipseMetadata eclipseMetadata, final SOAImplProject implProject) throws Exception { if (SOALogger.DEBUG) logger.entering(eclipseMetadata, implProject); final List<SOAProjectSourceDirectory> entries = new ArrayList<SOAProjectSourceDirectory>(); for (final IClasspathEntry entry : JDTUtil.rawClasspath(implProject.getProject(), false)) { if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { final String path = entry.getPath().removeFirstSegments(1).toString(); entries.add(new SOAProjectSourceDirectory(path)); } } if (SOALogger.DEBUG) logger.debug("Setting source directories->", entries, " to the impl project->", implProject.getProject()); implProject.setSourceDirectories(entries); final String serviceName = implProject.getMetadata().getServiceName(); if (serviceName != null) { final IProject intfProject = WorkspaceUtil.getProject(serviceName); if (intfProject != null && intfProject.isAccessible()) { SOAServiceUtil.getSOAIntfMetadata(SOAServiceUtil.getSOAEclipseMetadata(intfProject), implProject.getMetadata().getIntfMetadata()); SOAIntfUtil.fillMetadata(intfProject, implProject.getMetadata().getIntfMetadata()); } else { logger.warning("The interface project is not accessible->", intfProject); } } else { if (SOALogger.DEBUG) logger.debug("The interface project/service name for the implementation project", implProject.getProject(), " is null->"); } return implProject; }
From source file:org.ebayopensource.turmeric.eclipse.utils.plugin.JDTUtil.java
License:Open Source License
/** * Adds the java support to eclipse project. * ie soa nature is added here.//from ww w. jav a 2s .co m * Class Path container related linking etc.. * * @param project the project * @param sourceDirectories the source directories * @param defaultCompilerLevel the default compiler level * @param outputLocation the output location * @param monitor the monitor * @throws CoreException the core exception */ public static void addJavaSupport(IProject project, List<String> sourceDirectories, String defaultCompilerLevel, String outputLocation, IProgressMonitor monitor) throws CoreException { boolean changedClasspath = false; if (addJavaNature(project, monitor)) { changedClasspath = true; } // Configuring the Java Project final IJavaProject javaProject = JavaCore.create(project); final List<IClasspathEntry> classpath = JDTUtil.rawClasspath(javaProject, true); 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_SOURCE || !entry.getPath().equals(new Path("/" + project.getName()))) continue; iterator.remove(); changedClasspath |= true; } for (final String dir : sourceDirectories) { final IFolder source = project.getFolder(dir); // 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; classpath.add(JavaCore.newSourceEntry(source.getFullPath())); } ProgressUtil.progressOneStep(monitor, 10); // 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()); } ProgressUtil.progressOneStep(monitor); // Configuring the classpath of the Java Project if (changedClasspath) { javaProject.setRawClasspath(classpath.toArray(new IClasspathEntry[0]), null); } IProjectFacetVersion projectFacetVersion = JavaFacetUtils.JAVA_60; if (StringUtils.isNotBlank(defaultCompilerLevel)) { try { projectFacetVersion = JavaFacetUtils.compilerLevelToFacet(defaultCompilerLevel); } catch (Exception e) { Logger.getLogger(JDTUtil.class.getName()).throwing(JDTUtil.class.getName(), "addJavaSupport", e); } } JavaFacetUtils.setCompilerLevel(project, projectFacetVersion); }
From source file:org.ebayopensource.turmeric.eclipse.utils.plugin.JDTUtil.java
License:Open Source License
private static void resolveClasspathToURLs(final IJavaProject javaProject, final Set<URL> resolvedEntries, final Set<String> visited) throws JavaModelException, IOException { if (javaProject == null || !javaProject.exists()) return;/*from www. j av a2 s. co m*/ final String projectName = javaProject.getProject().getName(); if (visited.contains(projectName)) return; visited.add(projectName); for (final IClasspathEntry entry : javaProject.getResolvedClasspath(true)) { if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { resolveClasspathToURLs(JavaCore.create(WorkspaceUtil.getProject(entry.getPath())), resolvedEntries, visited); } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { resolvedEntries.add(WorkspaceUtil.getLocation(entry.getPath()).toFile().toURI().toURL()); } else if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath location = entry.getOutputLocation() != null ? entry.getOutputLocation() : javaProject.getOutputLocation(); if (location.toString().startsWith(WorkspaceUtil.PATH_SEPERATOR + projectName)) { //it happens that the path is not absolute location = javaProject.getProject().getFolder(location.removeFirstSegments(1)).getLocation(); } resolvedEntries.add(location.toFile().toURI().toURL()); } } }
From source file:org.ebayopensource.turmeric.eclipse.utils.plugin.JDTUtil.java
License:Open Source License
/** * Checks if is classpath container./*from w w w.j a va 2 s. c o m*/ * * @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.plugin.JDTUtil.java
License:Open Source License
/** * Gets the source directories./*from w w w. j a v a 2 s.c om*/ * * @param project the project * @return the source directories */ public static List<IPath> getSourceDirectories(final IProject project) { final IJavaProject jProject = JavaCore.create(project); final List<IPath> srcEntries = new ArrayList<IPath>(); for (final IClasspathEntry entry : jProject.readRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { srcEntries.add(entry.getPath()); } } return srcEntries; }
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 {/*from w w w.j a va2s. co 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 . ja va2 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.ClassPathUtils.java
License:Open Source License
public static URL[] getProjectDependencyUrls(List<IJavaProject> javaProjectList, List<URL> currentUrlList, HashMap<String, String> projectMap) throws JavaModelException, MalformedURLException { List<URL> projectDependencyUrlList = currentUrlList; if (projectDependencyUrlList == null) { projectDependencyUrlList = new ArrayList<URL>(); }// w w w . j ava 2s . co m 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); for (IClasspathEntry entry : entries) { IPath path = entry.getPath(); File f = path.toFile(); URL entryUrl; entryUrl = f.toURI().toURL(); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: if (projectDependencyUrlList.contains(entryUrl) == false) { projectDependencyUrlList.add(entryUrl); } break; 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(); // throw new EclipseProjectNotFoundException( // projectName, // MessageFormat // .format( // "The dependent project {0} of project {1} is not // available.\nPlease update your workspace to include // this project", // projectName, parentProjectName)); } 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(subjavaProjectList, projectDependencyUrlList, projectMap); } } break; default: break; } } IPath path = project.getOutputLocation(); IPath projectResourceLocation = project.getResource().getLocation(); File projectFilePath = projectResourceLocation.append(path.removeFirstSegments(1)).toFile(); URL projectOutputUrl; projectOutputUrl = projectFilePath.toURI().toURL(); if (projectDependencyUrlList.contains(projectOutputUrl) == false) { projectDependencyUrlList.add(projectOutputUrl); } } URL[] arrayList = new URL[projectDependencyUrlList.size()]; URL[] returnURLArray = projectDependencyUrlList.toArray(arrayList); return returnURLArray; }
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>(); }// w ww . ja v a 2s . com 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; }
From source file:org.ebayopensource.vjet.eclipse.core.PiggyBackClassPathUtil.java
License:Open Source License
public static List<IBuildpathEntry> fetchBuildEntryFromJavaProject(IJavaProject javaProject) { // Project entry List<IBuildpathEntry> vEntries = new ArrayList<IBuildpathEntry>(); List<String> duplicateChecker = new ArrayList<String>(); IClasspathEntry[] entries2;//www .j av a 2 s . c om try { entries2 = javaProject.getRawClasspath(); } catch (JavaModelException e) { VjetPlugin.error("Failed to resolve Java prjoect classpath: " + javaProject.getElementName(), e, IStatus.WARNING); return Collections.emptyList(); } for (IClasspathEntry entry : entries2) { IPath path = entry.getPath(); String sPath = path.toString(); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_VARIABLE: case IClasspathEntry.CPE_LIBRARY: addEntryToVJETEntry(entry, vEntries, duplicateChecker); case IClasspathEntry.CPE_PROJECT: IResource subResource = ResourcesPlugin.getWorkspace().getRoot().findMember(entry.getPath()); if (subResource != null && subResource.getType() == IResource.PROJECT) { addProjectEntry(entry.getPath(), vEntries, duplicateChecker); } break; case IClasspathEntry.CPE_CONTAINER: if (!JavaRuntime.JRE_CONTAINER.equals(path.segment(0))) { IClasspathContainer container; try { container = JavaCore.getClasspathContainer(path, javaProject); if (container != null) { IClasspathEntry[] entries = container.getClasspathEntries(); for (int i = 0; i < entries.length; i++) { addEntryToVJETEntry(entries[i], vEntries, duplicateChecker); } } } catch (JavaModelException e) { VjetPlugin.error("Failed to resolve Java classpath container: " + sPath, e, IStatus.WARNING); } } break; default: break; } } return vEntries; }