List of usage examples for org.eclipse.jdt.core IJavaProject getRawClasspath
IClasspathEntry[] getRawClasspath() throws JavaModelException;
From source file:org.apache.felix.sigil.eclipse.ui.internal.handlers.project.ConvertProjectCommandHandler.java
License:Apache License
public Object execute(IResource[] resources, ExecutionEvent event) throws ExecutionException { for (IResource r : resources) { final IProject project = (IProject) r; if (project != null) { WorkspaceModifyOperation op = new WorkspaceModifyOperation() { @Override// w w w .ja v a 2s . co m protected void execute(IProgressMonitor monitor) throws CoreException { SigilCore.makeSigilProject(project, monitor); IJavaProject java = JavaCore.create(project); ISigilProjectModel sigil = SigilCore.create(project); String bsn = project.getName(); sigil.getBundle().getBundleInfo().setSymbolicName(bsn); IClasspathEntry[] entries = java.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { String encodedClasspath = sigil.getJavaModel().encodeClasspathEntry(entry); sigil.getBundle().addClasspathEntry(encodedClasspath); } } sigil.save(monitor); } }; SigilUI.runWorkspaceOperation(op, null); } } return null; }
From source file:org.apache.felix.sigil.ui.eclipse.handlers.project.ConvertProjectCommandHandler.java
License:Apache License
public Object execute(IResource[] resources, ExecutionEvent event) throws ExecutionException { for (IResource r : resources) { final IProject project = (IProject) r; if (project != null) { WorkspaceModifyOperation op = new WorkspaceModifyOperation() { @Override/*from ww w .java 2 s .c om*/ protected void execute(IProgressMonitor monitor) throws CoreException { SigilCore.makeSigilProject(project, monitor); IJavaProject java = JavaCore.create(project); ISigilProjectModel sigil = SigilCore.create(project); IClasspathEntry[] entries = java.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { String encodedClasspath = sigil.getJavaModel().encodeClasspathEntry(entry); sigil.getBundle().addClasspathEntry(encodedClasspath); } } sigil.save(monitor); } }; SigilUI.runWorkspaceOperation(op, null); } } return null; }
From source file:org.apache.hadoop.eclipse.MapReduceNature.java
License:Apache License
/** * Configures an Eclipse project as a Map/Reduce project by adding the * Hadoop libraries to a project's classpath. *///from w w w. j av a 2 s .co m public void configure() throws CoreException { String path = project.getPersistentProperty(new QualifiedName(Activator.PLUGIN_ID, "hadoop.runtime.path")); File dir = new File(path); final ArrayList<File> coreJars = new ArrayList<File>(); dir.listFiles(new FileFilter() { public boolean accept(File pathname) { String fileName = pathname.getName(); // get the hadoop core jar without touching test or examples // older version of hadoop don't use the word "core" -- eyhung if ((fileName.indexOf("hadoop") != -1) && (fileName.endsWith("jar")) && (fileName.indexOf("test") == -1) && (fileName.indexOf("examples") == -1)) { coreJars.add(pathname); } return false; // we don't care what this returns } }); File dir2 = new File(path + File.separatorChar + "lib"); if (dir2.exists() && dir2.isDirectory()) { dir2.listFiles(new FileFilter() { public boolean accept(File pathname) { if ((!pathname.isDirectory()) && (pathname.getName().endsWith("jar"))) { coreJars.add(pathname); } return false; // we don't care what this returns } }); } // Add Hadoop libraries onto classpath IJavaProject javaProject = JavaCore.create(getProject()); // Bundle bundle = Activator.getDefault().getBundle(); try { IClasspathEntry[] currentCp = javaProject.getRawClasspath(); IClasspathEntry[] newCp = new IClasspathEntry[currentCp.length + coreJars.size()]; System.arraycopy(currentCp, 0, newCp, 0, currentCp.length); final Iterator<File> i = coreJars.iterator(); int count = 0; while (i.hasNext()) { // for (int i = 0; i < s_coreJarNames.length; i++) { final File f = (File) i.next(); // URL url = FileLocator.toFileURL(FileLocator.find(bundle, new // Path("lib/" + s_coreJarNames[i]), null)); URL url = f.toURI().toURL(); log.finer("hadoop library url.getPath() = " + url.getPath()); newCp[newCp.length - 1 - count] = JavaCore.newLibraryEntry(new Path(url.getPath()), null, null); count++; } javaProject.setRawClasspath(newCp, new NullProgressMonitor()); } catch (Exception e) { log.log(Level.SEVERE, "IOException generated in " + this.getClass().getCanonicalName(), e); } }
From source file:org.apache.hdt.core.natures.MapReduceNature.java
License:Apache License
/** * Configures an Eclipse project as a Map/Reduce project by adding the * Hadoop libraries to a project's classpath. *//* w w w . j a va2s . c o m*/ /* * TODO Versioning connector needed here */ public void configure() throws CoreException { String path = project.getPersistentProperty(new QualifiedName(Activator.PLUGIN_ID, "hadoop.runtime.path")); File dir = new File(path); final ArrayList<File> coreJars = new ArrayList<File>(); dir.listFiles(new FileFilter() { public boolean accept(File pathname) { String fileName = pathname.getName(); // get the hadoop core jar without touching test or examples // older version of hadoop don't use the word "core" -- eyhung if ((fileName.indexOf("hadoop-core") != -1) && (fileName.endsWith("jar")) && (fileName.indexOf("test") == -1) && (fileName.indexOf("examples") == -1)) { coreJars.add(pathname); } return false; // we don't care what this returns } }); // Add Hadoop libraries onto classpath IJavaProject javaProject = JavaCore.create(getProject()); // Bundle bundle = Activator.getDefault().getBundle(); try { IClasspathEntry[] currentCp = javaProject.getRawClasspath(); IClasspathEntry[] newCp = new IClasspathEntry[currentCp.length + coreJars.size()]; System.arraycopy(currentCp, 0, newCp, 0, currentCp.length); final Iterator<File> i = coreJars.iterator(); int count = 0; while (i.hasNext()) { // for (int i = 0; i < s_coreJarNames.length; i++) { final File f = (File) i.next(); // URL url = FileLocator.toFileURL(FileLocator.find(bundle, new // Path("lib/" + s_coreJarNames[i]), null)); URL url = f.toURI().toURL(); log.finer("hadoop library url.getPath() = " + url.getPath()); newCp[newCp.length - 1 - count] = JavaCore.newLibraryEntry(new Path(url.getPath()), null, null); count++; } javaProject.setRawClasspath(newCp, new NullProgressMonitor()); } catch (Exception e) { log.log(Level.SEVERE, "IOException generated in " + this.getClass().getCanonicalName(), e); } }
From source file:org.apache.ivyde.eclipse.cp.IvyClasspathContainerHelper.java
License:Apache License
/** * Search the Ivy classpath containers within the specified Java project * /*from w ww .j a va 2s . com*/ * @param javaProject * the project to search into * @return the Ivy classpath container if found */ public static List<IvyClasspathContainer> getContainers(IJavaProject javaProject) { List<IvyClasspathContainer> containers = new ArrayList<IvyClasspathContainer>(); if (javaProject == null || !javaProject.exists()) { return containers; } 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 IvyClasspathContainer) { containers.add((IvyClasspathContainer) cp); } } } } } 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
public static List<IvyClasspathContainer> getContainersFromIvyFile(IFile ivyfile) { IJavaProject javaProject = JavaCore.create(ivyfile.getProject()); List<IvyClasspathContainer> containers = new ArrayList<IvyClasspathContainer>(); if (javaProject == null || !javaProject.exists()) { return containers; }//from w ww.j a v a 2 s. 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; if (ivycp.getConf().getIvyXmlPath() .equals(ivyfile.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
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; }//from w w w . j ava 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 2 s . c o 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.apache.ivyde.internal.eclipse.cpcontainer.IvyClasspathInitializer.java
License:Apache License
private void updateIvyDEContainerPath(final IJavaProject project, final IClasspathEntry entry, final IClasspathAttribute[] attributes, final boolean exported, final IPath updatedPath) { Display.getDefault().asyncExec(new Runnable() { public void run() { try { // update the classpath of the project by updating the IvyDE container IClasspathEntry newEntry = JavaCore.newContainerEntry(updatedPath, null, attributes, exported); IClasspathEntry[] entries; entries = project.getRawClasspath(); List newEntries = new ArrayList(Arrays.asList(entries)); for (int i = 0; i < newEntries.size(); i++) { IClasspathEntry e = (IClasspathEntry) newEntries.get(i); if (e == entry) { newEntries.set(i, newEntry); break; }//from www . j a v a 2 s . com } entries = (IClasspathEntry[]) newEntries.toArray(new IClasspathEntry[newEntries.size()]); project.setRawClasspath(entries, project.getOutputLocation(), null); } catch (JavaModelException e) { IvyPlugin.logError("Unable to update the container path", e); } } }); }
From source file:org.apache.ivyde.internal.eclipse.IvyNature.java
License:Apache License
public void deconfigure() throws CoreException { IJavaProject javaProject = JavaCore.create(project); if (!javaProject.exists()) { return;/*from ww w. jav a2 s.c o m*/ } IClasspathEntry[] classpathEntries = javaProject.getRawClasspath(); List newEntries = new ArrayList(); for (int i = 0; i < classpathEntries.length; i++) { if (!IvyClasspathContainerHelper.isIvyClasspathContainer(classpathEntries[i].getPath())) { newEntries.add(classpathEntries[i]); } } if (newEntries.size() != classpathEntries.length) { IClasspathEntry[] newClasspathEntries = (IClasspathEntry[]) newEntries .toArray(new IClasspathEntry[newEntries.size()]); javaProject.setRawClasspath(newClasspathEntries, null); } IvyMarkerManager ivyMarkerManager = IvyPlugin.getDefault().getIvyMarkerManager(); ivyMarkerManager.removeMarkers(project); }