List of usage examples for org.eclipse.jdt.core IClasspathEntry getPath
IPath getPath();
From source file:com.android.ide.eclipse.common.project.BaseProjectHelper.java
License:Open Source License
/** * returns a list of source classpath for a specified project * @param javaProject/* www .ja v a 2s. c o m*/ * @return a list of path relative to the workspace root. */ public static ArrayList<IPath> getSourceClasspaths(IJavaProject javaProject) { ArrayList<IPath> sourceList = new ArrayList<IPath>(); IClasspathEntry[] classpaths = javaProject.readRawClasspath(); if (classpaths != null) { for (IClasspathEntry e : classpaths) { if (e.getEntryKind() == IClasspathEntry.CPE_SOURCE) { sourceList.add(e.getPath()); } } } return sourceList; }
From source file:com.android.ide.eclipse.editors.resources.manager.ProjectClassLoader.java
License:Open Source License
/** * Returns an array of external jar files used by the project. * @return an array of OS-specific absolute file paths *//*from www .j a v a 2 s . c om*/ private final URL[] getExternalJars() { // get a java project from it IJavaProject javaProject = JavaCore.create(mJavaProject.getProject()); IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); ArrayList<URL> oslibraryList = new ArrayList<URL>(); IClasspathEntry[] classpaths = javaProject.readRawClasspath(); if (classpaths != null) { for (IClasspathEntry e : classpaths) { if (e.getEntryKind() == IClasspathEntry.CPE_LIBRARY || e.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { // if this is a classpath variable reference, we resolve it. if (e.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { e = JavaCore.getResolvedClasspathEntry(e); } // get the IPath IPath path = e.getPath(); // check the name ends with .jar if (AndroidConstants.EXT_JAR.equalsIgnoreCase(path.getFileExtension())) { boolean local = false; IResource resource = wsRoot.findMember(path); if (resource != null && resource.exists() && resource.getType() == IResource.FILE) { local = true; try { oslibraryList.add(new File(resource.getLocation().toOSString()).toURL()); } catch (MalformedURLException mue) { // pass } } if (local == false) { // if the jar path doesn't match a workspace resource, // then we get an OSString and check if this links to a valid file. String osFullPath = path.toOSString(); File f = new File(osFullPath); if (f.exists()) { try { oslibraryList.add(f.toURL()); } catch (MalformedURLException mue) { // pass } } } } } } } return oslibraryList.toArray(new URL[oslibraryList.size()]); }
From source file:com.android.ide.eclipse.mock.Mocks.java
License:Open Source License
/** * Creates a mock implementation of an {@link IClasspathEntry}, which supports * {@link IClasspathEntry#getEntryKind} and {@link IClasspathEntry#getPath}. *//*from w w w . j a v a 2 s . c o m*/ public static IClasspathEntry createClasspathEntry(IPath path, int kind) { IClasspathEntry entry = createNiceMock(IClasspathEntry.class); expect(entry.getEntryKind()).andReturn(kind).anyTimes(); expect(entry.getPath()).andReturn(path).anyTimes(); replay(entry); return entry; }
From source file:com.annotatedsql.classlibrary.ClassPathContainerPage.java
License:Open Source License
public void initialize(IJavaProject project, IClasspathEntry[] currentEntries) { for (int i = 0; i < currentEntries.length; i++) { IClasspathEntry curr = currentEntries[i]; if (curr.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { fUsedPaths.add(curr.getPath()); }/*w w w. jav a2 s .c om*/ } }
From source file:com.annotatedsql.classlibrary.ClassPathContainerPage.java
License:Open Source License
public void setSelection(IClasspathEntry containerEntry) { if (containerEntry != null) { fUsedPaths.remove(containerEntry.getPath()); fEntryField.setText(containerEntry.getPath().toString()); } else {//from w ww . j a v a 2s . co m fEntryField.setText(ClassPathContainerImpl.ID.toString()); //$NON-NLS-1$ } }
From source file:com.appnativa.studio.builder.J2ObjCHelper.java
static String getSourcePath(IProject p, StringBuilder sb) { try {/*from w ww . j a va 2 s .c om*/ sb.setLength(0); IJavaProject javaProject = JavaCore.create(p); IClasspathEntry[] classpathEntries = null; classpathEntries = javaProject.getResolvedClasspath(true); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); for (int i = 0; i < classpathEntries.length; i++) { IClasspathEntry entry = classpathEntries[i]; if (entry.getContentKind() == IPackageFragmentRoot.K_SOURCE) { IPath path = entry.getPath(); IResource res = root.findMember(path); if (res != null) { String srcPath = res.getLocation().toOSString(); sb.append(srcPath).append(File.pathSeparator); } } } if (sb.charAt(sb.length() - 1) == File.pathSeparatorChar) { sb.setLength(sb.length() - 1); return sb.toString(); } } catch (Exception ignore) { ignore.printStackTrace(); } return ""; }
From source file:com.brandmaker.m2e.jaxws.tests.JaxwsImportGenerationTest.java
License:Open Source License
protected void checkClassPathPresent(IProject project, String path) throws Exception { IClasspathEntry[] cpes = JavaCore.create(project).getRawClasspath(); Path p = new Path(path); for (IClasspathEntry cpe : cpes) { if (cpe.getPath().equals(p)) { return; }/* w ww . ja va 2 s.c o m*/ } fail("Classpath entry " + path + " was not found."); }
From source file:com.centimia.orm.jaqu.plugin.ToggleNatureAction.java
License:Open Source License
private void configureClassPath(IProject project) throws CoreException { IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] classpathEntries = javaProject.getRawClasspath(); for (IClasspathEntry entry : classpathEntries) { if (CLASSPATH_CONTAINER_PATH.equals(entry.getPath().toString())) { return; }// w ww . ja v a 2s . c o m } // Add the Jaqu library. ClassPathInitializer classPathInitializer = new ClassPathInitializer(); classPathInitializer.initialize(new Path(CLASSPATH_CONTAINER_PATH), javaProject); //JavaCore.setClasspathContainer(new Path(CLASSPATH_CONTAINER_PATH), new IJavaProject[] { javaProject }, new IClasspathContainer[] { new JaquClasspathContainer(javaProject, new Path(CLASSPATH_CONTAINER_PATH))}, null); List<IClasspathEntry> list = new ArrayList<IClasspathEntry>(); list.addAll(Arrays.asList(javaProject.getRawClasspath())); list.add(JavaCore.newContainerEntry(new Path(CLASSPATH_CONTAINER_PATH))); javaProject.setRawClasspath(list.toArray(new IClasspathEntry[list.size()]), null); }
From source file:com.centimia.orm.jaqu.plugin.ToggleNatureAction.java
License:Open Source License
private void deconfigureClassPath(IProject project) throws JavaModelException { IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] classpathEntries = javaProject.getRawClasspath(); for (IClasspathEntry entry : classpathEntries) { if (CLASSPATH_CONTAINER_PATH.equals(entry.getPath().toString())) { List<IClasspathEntry> list = new ArrayList<IClasspathEntry>(); list.addAll(Arrays.asList(javaProject.getRawClasspath())); list.remove(entry);//from w w w .j ava 2s.c o m javaProject.setRawClasspath(list.toArray(new IClasspathEntry[list.size()]), null); } } }
From source file:com.centurylink.mdw.plugin.project.assembly.ProjectConfigurator.java
License:Apache License
public void addJavaProjectSourceFolder(String sourceFolder, String outputFolder, IProgressMonitor monitor) throws CoreException, JavaModelException { if (!isJavaCapable()) return;// ww w . j ava2s. c o m IFolder folder = project.getSourceProject().getFolder(sourceFolder); if (!folder.exists()) folder.create(true, true, monitor); // projects with newly-added Java Nature contain root source entry, // which must be removed IClasspathEntry rootEntry = JavaCore.newSourceEntry(project.getSourceProject().getFullPath()); IPath outputPath = outputFolder == null ? null : project.getSourceProject().getFolder(outputFolder).getFullPath(); IClasspathEntry newEntry = JavaCore.newSourceEntry(folder.getFullPath(), ClasspathEntry.EXCLUDE_NONE, outputPath); boolean includesContainer = false; List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>(); IClasspathEntry toRemove = null; for (IClasspathEntry existingEntry : project.getSourceJavaProject().getRawClasspath()) { if (newEntry.equals(existingEntry)) return; // already on classpath else if (newEntry.getPath().equals(existingEntry.getPath()) && newEntry.getEntryKind() == existingEntry.getEntryKind()) toRemove = existingEntry; // to be replaced with new entry if (!rootEntry.equals(existingEntry)) classpathEntries.add(existingEntry); if (existingEntry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && String.valueOf(existingEntry.getPath()).indexOf("JRE_CONTAINER") >= 0) includesContainer = true; } if (toRemove != null) classpathEntries.remove(toRemove); classpathEntries.add(newEntry); if (!includesContainer) { IClasspathEntry jre = getJreContainerClasspathEntry(project.getJavaVersion()); if (jre == null) jre = JavaRuntime.getDefaultJREContainerEntry(); // fallback to // any // available classpathEntries.add(jre); } project.getSourceJavaProject().setRawClasspath(classpathEntries.toArray(new IClasspathEntry[0]), monitor); J2EEComponentClasspathUpdater.getInstance().queueUpdate(project.getSourceProject()); }