List of usage examples for org.eclipse.jdt.core IClasspathEntry getPath
IPath getPath();
From source file:org.apache.easyant4e.natures.EasyAntNature.java
License:Apache License
private void removeIvyClasspathContainer() { IJavaProject javaProject = JavaCore.create(project); ArrayList<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>(); //FIXME call IvyDE command try {//from w w w .j a v a2 s .co m 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 (IvyClasspathContainerHelper.isIvyClasspathContainer(path)) { continue; } } newEntries.add(entry); } // TODO add progress monitor IClasspathEntry[] newClasspathEntries = newEntries.toArray(new IClasspathEntry[newEntries.size()]); javaProject.setRawClasspath(newClasspathEntries, null); } catch (JavaModelException e) { Activator.getEasyAntPlugin().log(IStatus.ERROR, "Cannot remove Ivy ClassPath container", e); } }
From source file:org.apache.easyant4e.tests.ImportProjectTest.java
License:Apache License
private void assertSourceFolders(IProject project) throws Exception { assertTrue(project.hasNature(JavaCore.NATURE_ID)); IJavaProject javaProject = (IJavaProject) project.getNature(JavaCore.NATURE_ID); assertNotNull(javaProject);// w w w .j a v a 2 s .c om List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); entries.addAll(Arrays.asList(javaProject.getRawClasspath())); assertTrue(entries.size() > 0); HashSet<String> sourceFolders = new HashSet<String>(); for (IClasspathEntry entry : entries) { if (IClasspathEntry.CPE_SOURCE == entry.getEntryKind()) { String path = entry.getPath().toOSString(); assertNotNull(path); sourceFolders.add(path); } } assertTrue(sourceFolders.contains("/simplejavaproject/src/main/java")); assertTrue(sourceFolders.contains("/simplejavaproject/src/test/java")); assertTrue(sourceFolders.contains("/simplejavaproject/src/main/resources")); assertTrue(sourceFolders.contains("/simplejavaproject/src/test/resources")); }
From source file:org.apache.felix.sigil.eclipse.internal.builders.SigilIncrementalProjectBuilder.java
License:Apache License
private void convertVariable(IClasspathEntry cp, List<File> files) { cp = JavaCore.getResolvedClasspathEntry(cp); if (cp != null) { IPath p = cp.getPath(); files.add(p.toFile());//from w w w . j av a 2 s . c o m } }
From source file:org.apache.felix.sigil.eclipse.internal.builders.SigilIncrementalProjectBuilder.java
License:Apache License
private void convertLibrary(ISigilProjectModel sigil, IClasspathEntry cp, List<File> files) { IPath p = cp.getPath(); IProject project = sigil.getProject().getWorkspace().getRoot().getProject(p.segment(0)); if (project.exists()) { p = project.getLocation().append(p.removeFirstSegments(1)); }/*from w w w . j av a 2 s . c o m*/ files.add(p.toFile()); }
From source file:org.apache.felix.sigil.eclipse.internal.builders.SigilIncrementalProjectBuilder.java
License:Apache License
private void convertProject(IClasspathEntry cp, List<File> files) throws CoreException { IProject p = findProject(cp.getPath()); ISigilProjectModel project = SigilCore.create(p); if (project.getBundle().getClasspathEntrys().isEmpty()) { // ew this is pretty messy - if a dependent bundle specifies it's dependencies // via package statements vs source directories then we need to add // the classpath path of that bundle for (IClasspathEntry rp : project.getJavaModel().getResolvedClasspath(true)) { convert(rp, project, files); }//from www. j av a 2 s. c om } else { for (String scp : project.getBundle().getClasspathEntrys()) { IClasspathEntry jcp = project.getJavaModel().decodeClasspathEntry(scp); convert(jcp, project, files); } } }
From source file:org.apache.felix.sigil.eclipse.internal.model.project.SigilProject.java
License:Apache License
public boolean isInClasspath(ISigilBundle bundle) { for (String path : getBundle().getClasspathEntrys()) { IClasspathEntry cp = getJavaModel().decodeClasspathEntry(path); switch (cp.getEntryKind()) { case IClasspathEntry.CPE_PROJECT: ISigilProjectModel p = bundle.getAncestor(ISigilProjectModel.class); return p != null && cp.getPath().equals(p.getProject().getFullPath()); case IClasspathEntry.CPE_LIBRARY: return cp.getPath().equals(bundle.getLocation()); }// w w w . j av a2s. c o m } return false; }
From source file:org.apache.felix.sigil.eclipse.model.util.JavaHelper.java
License:Apache License
private static Collection<IClasspathEntry> newProjectEntry(ISigilProjectModel n, IAccessRule[] rules, IClasspathAttribute[] attributes, boolean export) throws CoreException { ArrayList<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); entries.add(JavaCore.newProjectEntry(n.getProject().getFullPath(), rules, false, attributes, export)); for (IClasspathEntry e : n.getJavaModel().getRawClasspath()) { String encoded = n.getJavaModel().encodeClasspathEntry(e); if (n.getBundle().getClasspathEntrys().contains(encoded)) { switch (e.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: entries.add(JavaCore.newLibraryEntry(e.getPath(), e.getSourceAttachmentPath(), e.getSourceAttachmentRootPath(), rules, attributes, export)); break; case IClasspathEntry.CPE_VARIABLE: IPath path = JavaCore.getResolvedVariablePath(e.getPath()); if (path != null) { IPath spath = e.getSourceAttachmentPath(); if (spath != null) { spath = JavaCore.getResolvedVariablePath(spath); }//from w w w .jav a 2s. com entries.add(JavaCore.newLibraryEntry(path, spath, e.getSourceAttachmentRootPath(), rules, attributes, export)); } break; } } } return entries; }
From source file:org.apache.felix.sigil.eclipse.model.util.JavaHelper.java
License:Apache License
private static void findIndirectReferences(Set<String> indirect, String pckg, IParent parent, IJavaProject p) throws JavaModelException { for (IJavaElement e : parent.getChildren()) { boolean skip = false; switch (e.getElementType()) { case IJavaElement.PACKAGE_FRAGMENT_ROOT: IPackageFragmentRoot rt = (IPackageFragmentRoot) e; IClasspathEntry ce = rt.getRawClasspathEntry(); IPath path = ce.getPath(); skip = "org.eclipse.jdt.launching.JRE_CONTAINER".equals(path.toString()); break; case IJavaElement.CLASS_FILE: IClassFile cf = (IClassFile) e; if (cf.getElementName().startsWith(pckg)) { findIndirectReferences(indirect, findPackage(cf.getType().getSuperclassName()), p, p); }/*from ww w. j a va2 s. co m*/ break; case IJavaElement.COMPILATION_UNIT: ICompilationUnit cu = (ICompilationUnit) e; break; } if (!skip && e instanceof IParent) { IParent newParent = (IParent) e; findIndirectReferences(indirect, pckg, newParent, p); } } }
From source file:org.apache.felix.sigil.eclipse.SigilCore.java
License:Apache License
/** * @param cp//from w ww .jav a 2s .co m * @return */ private static boolean isSigilOnClasspath(IClasspathEntry[] cp) { for (IClasspathEntry e : cp) { if (e.getEntryKind() == IClasspathEntry.CPE_CONTAINER && e.getPath().segment(0).equals(SigilCore.CLASSPATH_CONTAINER_PATH)) { return true; } } return false; }
From source file:org.apache.felix.sigil.eclipse.ui.internal.editors.project.ClasspathSection.java
License:Apache License
private void handleAdd() { try {/*from w ww . j av a2s . co m*/ BackgroundLoadingSelectionDialog<IClasspathEntry> dialog = new BackgroundLoadingSelectionDialog<IClasspathEntry>( getSection().getShell(), "Classpath Entry:", true); dialog.setDescriptor(new IElementDescriptor<IClasspathEntry>() { public String getName(IClasspathEntry element) { return element.getPath().toString(); } public String getLabel(IClasspathEntry element) { return getName(element); } }); dialog.setLabelProvider(new ModelLabelProvider()); dialog.setFilter(new IFilter<IClasspathEntry>() { public boolean select(IClasspathEntry cp) { switch (cp.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_VARIABLE: case IClasspathEntry.CPE_SOURCE: return !getBundle().getClasspathEntrys().contains(encode(cp)); default: return false; } } }); dialog.setComparator(CLASSPATH_COMPARATOR); IClasspathEntry[] classpath = getProjectModel().getJavaModel().getRawClasspath(); dialog.addElements(Arrays.asList(classpath)); if (dialog.open() == Window.OK) { List<IClasspathEntry> selectedElements = dialog.getSelectedElements(); Object[] added = selectedElements.toArray(); for (IClasspathEntry entry : selectedElements) { getBundle().addClasspathEntry(encode(entry)); } viewer.add(added); viewer.refresh(); markDirty(); } } catch (JavaModelException e) { ErrorDialog.openError(getSection().getShell(), "Error", null, e.getStatus()); } }