List of usage examples for org.eclipse.jdt.core IJavaProject getRawClasspath
IClasspathEntry[] getRawClasspath() throws JavaModelException;
From source file:edu.uci.lighthouse.core.util.WorkbenchUtility.java
License:Open Source License
public static String[] getSourceFolders(IJavaProject project) { List<String> result = new LinkedList<String>(); try {/*from ww w . j a va 2s . c o m*/ IClasspathEntry[] classPaths = project.getRawClasspath(); for (IClasspathEntry cp : classPaths) { if (cp.getEntryKind() == IClasspathEntry.CPE_SOURCE) { result.add(cp.getPath().toPortableString()); } } } catch (JavaModelException e) { logger.error(e, e); } return result.toArray(new String[0]); }
From source file:edu.uci.lighthouse.services.persistence.ThreadTest.java
License:Open Source License
public static String[] getSourceFolders(IJavaProject project) { List<String> result = new LinkedList<String>(); try {// w w w .j av a 2 s .com IClasspathEntry[] classPaths = project.getRawClasspath(); for (IClasspathEntry cp : classPaths) { if (cp.getEntryKind() == IClasspathEntry.CPE_SOURCE) { result.add(cp.getPath().toString()); } } } catch (JavaModelException e) { //logger.error(e,e); } return result.toArray(new String[0]); }
From source file:edu.washington.cs.cupid.scripting.java.internal.UpdateClasspathJob.java
License:Open Source License
@Override public IStatus runInWorkspace(final IProgressMonitor monitor) { try {/*w w w. j ava 2 s .co m*/ IJavaProject project = CupidScriptingPlugin.getDefault().getCupidJavaProject(); int classpathSize = project.getRawClasspath().length; monitor.beginTask("Update Cupid Classpath", classpathSize + 2); List<IClasspathEntry> updatedClasspath = Lists.newArrayList(); List<IClasspathEntry> updatedEntries = Lists.newArrayList(); List<String> allResolved = Lists.newArrayList(); for (IClasspathEntry entry : project.getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { File file = entry.getPath().toFile(); if (file.exists()) { // the entry is valid allResolved.add(entry.getPath().toString()); updatedClasspath.add(entry); } else { // try to find bundle with same name IPath path = entry.getPath(); String filename = path.segment(path.segmentCount() - 1); String[] parts = filename.split("_"); if (parts.length == 2) { Bundle bundle = Platform.getBundle(parts[0]); if (bundle != null) { // we found a bundle with the same name IPath replacement = ClasspathUtil.bundlePath(bundle); IClasspathEntry newEntry = JavaCore.newLibraryEntry(replacement, null, null); updatedClasspath.add(newEntry); updatedEntries.add(newEntry); } else { CupidScriptingPlugin.getDefault() .logWarning("Can't find updated bundle for Cupid Project classpath entry: " + entry.getPath()); updatedClasspath.add(entry); } } else if (filename.startsWith("guava")) { CodeSource guavaSrc = Lists.class.getProtectionDomain().getCodeSource(); IClasspathEntry newEntry = JavaCore .newLibraryEntry(ClasspathUtil.urlToPath(guavaSrc.getLocation()), null, null); updatedClasspath.add(newEntry); updatedEntries.add(newEntry); } else { // TODO handle other internal JARs besides Guava CupidScriptingPlugin.getDefault() .logWarning("Can't find updated library for Cupid Project classpath entry: " + entry.getPath()); // we don't know how to find the name updatedClasspath.add(entry); } } } else { // don't try to handle variables / projects updatedClasspath.add(entry); allResolved.add(entry.getPath().toString()); } monitor.worked(1); } CupidScriptingPlugin.getDefault().logInformation("Found " + allResolved.size() + " valid Cupid classpath entries (see log for details)" + System.getProperty("line.separator") + Joiner.on(System.getProperty("line.separator")).join(allResolved)); if (!updatedEntries.isEmpty()) { // perform update project.setRawClasspath(updatedClasspath.toArray(new IClasspathEntry[] {}), new SubProgressMonitor(monitor, 1)); for (IClasspathEntry entry : updatedEntries) { CupidScriptingPlugin.getDefault() .logInformation("Updated Cupid classpath entry " + entry.getPath()); } } else { CupidScriptingPlugin.getDefault().logInformation("Cupid Project classpath is up-to-date"); } return Status.OK_STATUS; } catch (Exception ex) { return new Status(IStatus.ERROR, CupidScriptingPlugin.PLUGIN_ID, "Error updating Cupid scripting classpath", ex); } finally { monitor.done(); } }
From source file:edu.washington.cs.cupid.scripting.java.JavaProjectManager.java
License:Open Source License
/** * Add the JAR providing <tt>inputType</tt> to the Cupid project classpath, if it is not already present * @param inputType/* w ww. ja va 2 s .c o m*/ * @throws JavaModelException * @throws IOException * @throws ClassNotFoundException */ public static void ensureClasspath(TypeToken<?> inputType) throws JavaModelException, IOException, ClassNotFoundException { IJavaProject project = CupidScriptingPlugin.getDefault().getCupidJavaProject(); Bundle bundle = ClasspathUtil.bundleForClass(inputType.getRawType().getName()); if (bundle == null) return; // Java core classes don't have bundles IPath path = ClasspathUtil.bundlePath(bundle); if (!path.toFile().exists()) { CupidScriptingPlugin.getDefault() .logInformation("Bundle path for " + bundle.getSymbolicName() + " does not exist: " + path); return; } List<IClasspathEntry> cp = Lists.newArrayList(project.getRawClasspath()); for (IClasspathEntry old : cp) { if (old.getPath().equals(path)) { return; } } if (path != null) { cp.add(JavaCore.newLibraryEntry(path, null, null)); } project.setRawClasspath(cp.toArray(new IClasspathEntry[] {}), null); }
From source file:edu.washington.cs.cupid.scripting.java.wizards.JavaCapabilityWizard.java
License:Open Source License
/** * The worker method. It will find the container, create the * file if missing or just replace its contents, and open * the editor on the newly created file. * @throws IOException /*www.j av a2s .co m*/ */ private void doFinish(final String name, final String description, final Class<?> parameterType, final Class<?> returnType, final List<IPath> classpath, final IProgressMonitor monitor) throws Exception { CupidEventBuilder event = new CupidEventBuilder(EventConstants.FINISH_WHAT, getClass(), CupidScriptingPlugin.getDefault()).addData("name", name) .addData("parameterType", parameterType.getName()) .addData("returnType", returnType.getName()); CupidDataCollector.record(event.create()); // create a sample file String className = formClassName(name); monitor.beginTask("Creating " + name, 2); IProject cupid = CupidScriptingPlugin.getDefault().getCupidProject(); final IFile file = cupid.getFolder("src").getFile(new Path(className + ".java")); file.create(openContents(name, description, parameterType, returnType, cupid.getDefaultCharset()), true, monitor); IJavaProject proj = JavaCore.create(cupid); List<IClasspathEntry> cp = Lists.newArrayList(proj.getRawClasspath()); for (IPath path : classpath) { if (path != null && !inClasspath(cp, path)) { cp.add(JavaCore.newLibraryEntry(path, null, null)); } } proj.setRawClasspath(cp.toArray(new IClasspathEntry[] {}), null); monitor.worked(1); monitor.setTaskName("Opening file for editing..."); getShell().getDisplay().asyncExec(new Runnable() { public void run() { IWorkbenchPage active = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); try { IDE.openEditor(active, file); } catch (PartInitException e) { throw new RuntimeException("Error opening script editor", e); } } }); monitor.done(); }
From source file:egovframework.hdev.imp.ide.common.DeviceAPIIdeUtils.java
License:Apache License
/** * ? ?/* ww w .ja va 2s . c o m*/ * @param classpathEntry * @param append * @throws CoreException */ public static void assignClasspathEntryToJavaProject(IProject project, IClasspathEntry classpathEntry, boolean append) throws CoreException { IJavaProject javaProject = JavaCore.create(project); if ((javaProject == null) || (!javaProject.exists())) return; try { IClasspathEntry[] classpath; ArrayList<IClasspathEntry> entries; if (append) { classpath = javaProject.getRawClasspath(); entries = new ArrayList<IClasspathEntry>(Arrays.asList(classpath)); } else { entries = new ArrayList<IClasspathEntry>(); } entries.add(classpathEntry); classpath = entries.toArray(new IClasspathEntry[entries.size()]); javaProject.setRawClasspath(classpath, null); } catch (JavaModelException e) { DeviceAPIIdeLog.logError(e); } }
From source file:egovframework.hdev.imp.ide.common.DeviceAPIIdeUtils.java
License:Apache License
/** * ? ?/*from www . jav a2 s .c o m*/ * @param project * @param collection * @param append * @throws CoreException */ public static void assignClasspathEntryToJavaProject(IProject project, Collection<IClasspathEntry> collection, boolean append) throws CoreException { IJavaProject javaProject = JavaCore.create(project); if ((javaProject == null) || (!javaProject.exists())) return; try { IClasspathEntry[] classpath; ArrayList<IClasspathEntry> entries; if (append) { classpath = javaProject.getRawClasspath(); entries = new ArrayList<IClasspathEntry>(Arrays.asList(classpath)); } else { entries = new ArrayList<IClasspathEntry>(); } entries.addAll(collection); classpath = entries.toArray(new IClasspathEntry[entries.size()]); javaProject.setRawClasspath(classpath, null); } catch (JavaModelException e) { DeviceAPIIdeLog.logError(e); } }
From source file:egovframework.hdev.imp.ide.common.DeviceAPIIdeUtils.java
License:Apache License
/** * ? /*from w w w. ja va 2 s . com*/ * @param project * @throws CoreException */ @SuppressWarnings("unchecked") public static void sortClasspathEntry(IProject project) throws CoreException { IJavaProject javaProject = JavaCore.create(project); if ((javaProject == null) || (!javaProject.exists())) return; try { IClasspathEntry[] classpath; ArrayList<IClasspathEntry> entries; classpath = javaProject.getRawClasspath(); entries = new ArrayList<IClasspathEntry>(Arrays.asList(classpath)); DeviceAPIIdeUtils utils = new DeviceAPIIdeUtils(); ClasspathComparator classpathComparator = utils.new ClasspathComparator(); Collections.sort(entries, classpathComparator); classpath = entries.toArray(new IClasspathEntry[entries.size()]); javaProject.setRawClasspath(classpath, null); } catch (JavaModelException e) { DeviceAPIIdeLog.logError(e); } }
From source file:egovframework.hdev.imp.ide.common.DeviceAPIIdeUtils.java
License:Apache License
/** * ? // ww w . j a v a 2 s . co m * @param project * @throws CoreException */ public static void removeClasspathEntry(IProject project, IClasspathEntry classpathEntry) throws CoreException { IJavaProject javaProject = JavaCore.create(project); if ((javaProject == null) || (!javaProject.exists())) return; try { IClasspathEntry[] classpath; ArrayList<IClasspathEntry> entries; classpath = javaProject.getRawClasspath(); entries = new ArrayList<IClasspathEntry>(Arrays.asList(classpath)); for (int i = 0; i < entries.size(); i++) { if (entries.get(i).getPath().toString().compareTo(classpathEntry.getPath().toString()) == 0) { entries.remove(i); } } classpath = entries.toArray(new IClasspathEntry[entries.size()]); javaProject.setRawClasspath(classpath, null); } catch (JavaModelException e) { DeviceAPIIdeLog.logError(e); } }
From source file:eldaEditor.wizards.DSCDiagramCreationPage_ChooseName.java
License:Open Source License
private void modifyProject(IFile newFile) { IProject project = newFile.getProject(); IProjectDescription description;//from ww w . j av a2s .c o m try { description = project.getDescription(); String[] currentNatures = description.getNatureIds(); String[] newNatures = new String[currentNatures.length + 1]; System.arraycopy(currentNatures, 0, newNatures, 0, currentNatures.length); newNatures[newNatures.length - 1] = JavaCore.NATURE_ID; description.setNatureIds(newNatures); try { project.setDescription(description, new NullProgressMonitor()); } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } IJavaProject javaProj = JavaCore.create(project); IFolder binDir = project.getFolder("bin"); IPath binPath = binDir.getFullPath(); javaProj.setOutputLocation(binPath, null); IClasspathEntry cpeFramework = JavaCore.newVariableEntry(CodeGenerator.frameworkPath, null, null); IClasspathEntry cpeJade = JavaCore.newVariableEntry(CodeGeneratorForJADE.jadePath, null, null); IClasspathEntry cpeJava = JavaRuntime.getDefaultJREContainerEntry(); //recupero le classpath entry originali IClasspathEntry[] dscEntries = null; try { dscEntries = javaProj.getRawClasspath(); } catch (JavaModelException e4) { // TODO Auto-generated catch block e4.printStackTrace(); } boolean frameworkEntryExists = false; boolean jadeEntryExists = false; boolean javaEntryExists = false; for (int i = 0; i < dscEntries.length; i++) { //vedo se ELDAFramework gi stato aggiunto al progetto originario if (dscEntries[i].equals(JavaCore.newVariableEntry(CodeGenerator.frameworkPath, null, null))) frameworkEntryExists = true; //vedo se JADE gi stato aggiunto al progetto originario if (dscEntries[i].equals(JavaCore.newVariableEntry(CodeGeneratorForJADE.jadePath, null, null))) jadeEntryExists = true; //vedo se Java gi stato aggiunto al progetto originario if (dscEntries[i].equals(JavaRuntime.getDefaultJREContainerEntry())) javaEntryExists = true; } IClasspathEntry[] newEntries = null; if (frameworkEntryExists && javaEntryExists && jadeEntryExists) { newEntries = new IClasspathEntry[dscEntries.length]; for (int i = 0; i < dscEntries.length; i++) newEntries[i] = dscEntries[i]; } else { ArrayList<IClasspathEntry> list = new ArrayList<IClasspathEntry>(); if (!frameworkEntryExists) { list.add(cpeFramework); } if (!javaEntryExists) { list.add(cpeJava); } if (!jadeEntryExists) { list.add(cpeJade); } newEntries = new IClasspathEntry[dscEntries.length + list.size()]; for (int i = 0; i < dscEntries.length; i++) { newEntries[i] = dscEntries[i]; } for (int i = 0; i < list.size(); i++) { newEntries[dscEntries.length + i] = list.get(i); } } javaProj.setRawClasspath(newEntries, new NullProgressMonitor()); } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } }