List of usage examples for org.eclipse.jdt.core IJavaProject getResolvedClasspath
IClasspathEntry[] getResolvedClasspath(boolean ignoreUnresolvedEntry) throws JavaModelException;
From source file:cfgrecognition.loader.SootClasspath.java
License:Open Source License
/** * This is an addition to the original SootClasspath class where * bug due to '\\' in the path string has been resolved. * // w w w. ja v a 2 s . c o m * @param javaProject The JavaProject to be analyzed. * @return An array of {@link URL}s corresponding to the classpath of the supplied project. */ public static URL[] projectClassPath2(IJavaProject javaProject) { IWorkspace workspace = Activator.getWorkspaceRoot().getWorkspace(); IClasspathEntry[] cp; try { cp = javaProject.getResolvedClasspath(true); Set<URL> urls = new HashSet<URL>(); String uriString = workspace.getRoot().getFile(javaProject.getOutputLocation()).getLocationURI() .toString() + "/"; urls.add(new URI(uriString).toURL()); for (IClasspathEntry entry : cp) { File file = entry.getPath().toFile(); if (file.getPath().startsWith("\\")) { file = workspace.getRoot().getLocation().append(file.getPath()).toFile(); } URL url = file.toURI().toURL(); urls.add(url); } URL[] array = new URL[urls.size()]; urls.toArray(array); return array; } catch (JavaModelException e) { e.printStackTrace(); return new URL[0]; } catch (MalformedURLException e) { e.printStackTrace(); return new URL[0]; } catch (URISyntaxException e) { e.printStackTrace(); return new URL[0]; } }
From source file:cn.dockerfoundry.ide.eclipse.server.core.internal.debug.DebugProvider.java
License:Open Source License
/** * Returns either test sources, or non-test sources, based on a flag * setting. If nothing is found, returns empty list. *///from w w w.j a v a 2s . com protected boolean containsDebugFiles(IJavaProject project) { try { IClasspathEntry[] entries = project.getResolvedClasspath(true); if (entries != null) { for (IClasspathEntry entry : entries) { if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath projectPath = project.getPath(); IPath relativePath = entry.getPath().makeRelativeTo(projectPath); IFolder folder = project.getProject().getFolder(relativePath); if (containsResource(folder, ".profile.d")) {//$NON-NLS-1$ return true; } } } } } catch (JavaModelException e) { DockerFoundryPlugin.logError(e); } catch (CoreException ce) { DockerFoundryPlugin.logError(ce); } return false; }
From source file:com.android.ide.eclipse.adt.internal.sourcelookup.AdtSourceLookupDirector.java
License:Open Source License
@Override public void initializeDefaults(ILaunchConfiguration configuration) throws CoreException { dispose();/*from ww w. j av a2 s . co m*/ setLaunchConfiguration(configuration); String projectName = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); //$NON-NLS-1$ if (projectName != null && projectName.length() > 0) { IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); if (project != null && project.isOpen()) { ProjectState state = Sdk.getProjectState(project); if (state == null) { initDefaults(); return; } IAndroidTarget target = state.getTarget(); if (target == null) { initDefaults(); return; } String path = target.getPath(IAndroidTarget.ANDROID_JAR); if (path == null) { initDefaults(); return; } IJavaProject javaProject = JavaCore.create(project); if (javaProject != null && javaProject.isOpen()) { IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); IClasspathEntry androidEntry = null; for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && path.equals(entry.getPath().toString())) { androidEntry = entry; break; } } if (androidEntry != null) { IPath sourceAttachmentPath = androidEntry.getSourceAttachmentPath(); if (sourceAttachmentPath != null) { String androidSrc = sourceAttachmentPath.toString(); if (androidSrc != null && androidSrc.trim().length() > 0) { File srcFile = new File(androidSrc); ISourceContainer adtContainer = null; if (srcFile.isFile()) { adtContainer = new ExternalArchiveSourceContainer(androidSrc, true); } if (srcFile.isDirectory()) { adtContainer = new DirectorySourceContainer(srcFile, false); } if (adtContainer != null) { ISourceContainer defaultContainer = new DefaultSourceContainer(); setSourceContainers(new ISourceContainer[] { adtContainer, defaultContainer }); initializeParticipants(); return; } } } } } } } initDefaults(); }
From source file:com.android.ide.eclipse.auidt.internal.sourcelookup.AdtSourceLookupDirector.java
License:Open Source License
@Override public void initializeDefaults(ILaunchConfiguration configuration) throws CoreException { dispose();// w w w . j a v a 2 s . co m setLaunchConfiguration(configuration); String projectName = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); //$NON-NLS-1$ if (projectName != null && projectName.length() > 0) { IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); if (project != null && project.isOpen()) { ProjectState state = Sdk.getProjectState(project); if (state == null) { initDefaults(); return; } IAndroidTarget target = state.getTarget(); if (target == null) { initDefaults(); return; } // String path = target.getPath(IAndroidTarget.ANDROID_JAR); String path = AdtPlugin.getAuidtJar(); if (path == null) { initDefaults(); return; } IJavaProject javaProject = JavaCore.create(project); if (javaProject != null && javaProject.isOpen()) { IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); IClasspathEntry androidEntry = null; for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && path.equals(entry.getPath().toString())) { androidEntry = entry; break; } } if (androidEntry != null) { IPath sourceAttachmentPath = androidEntry.getSourceAttachmentPath(); if (sourceAttachmentPath != null) { String androidSrc = sourceAttachmentPath.toString(); if (androidSrc != null && androidSrc.trim().length() > 0) { File srcFile = new File(androidSrc); ISourceContainer adtContainer = null; if (srcFile.isFile()) { adtContainer = new ExternalArchiveSourceContainer(androidSrc, true); } if (srcFile.isDirectory()) { adtContainer = new DirectorySourceContainer(srcFile, false); } if (adtContainer != null) { ISourceContainer defaultContainer = new DefaultSourceContainer(); setSourceContainers(new ISourceContainer[] { adtContainer, defaultContainer }); initializeParticipants(); return; } } } } } } } initDefaults(); }
From source file:com.appnativa.studio.builder.J2ObjCHelper.java
static String getSourcePath(IProject p, StringBuilder sb) { try {//from www.j a v a2 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.cisco.yangide.core.model.YangProject.java
License:Open Source License
@Override protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map<IOpenable, OpenableElementInfo> newElements, IResource underlyingResource) throws YangModelException { final HashSet<IResource> resources = new HashSet<IResource>(); final HashSet<IPath> externalJarsPath = new HashSet<IPath>(); IJavaProject javaProject = JavaCore.create(project); try {//from www. ja v a 2s.c o m project.accept(new IResourceVisitor() { @Override public boolean visit(IResource resource) throws CoreException { if (CoreUtil.isYangLikeFileName(resource.getName())) { resources.add(resource.getParent()); } return true; } }); if (javaProject.isOpen()) { IClasspathEntry[] classpath = javaProject.getResolvedClasspath(true); for (int i = 0, length = classpath.length; i < length; i++) { IClasspathEntry entry = classpath[i]; IPath entryPath = entry.getPath(); if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { externalJarsPath.add(entryPath); } } } } catch (CoreException e) { throw new YangModelException(e); } ArrayList<IOpenable> result = new ArrayList<IOpenable>(); for (IResource resource : resources) { if (resource.getType() == IResource.FOLDER) { result.add(new YangFolder(resource, this)); } } for (IPath iPath : externalJarsPath) { try (JarFile jarFile = new JarFile(iPath.toFile())) { ZipEntry entry = jarFile.getEntry("META-INF/yang/"); if (entry != null) { result.add(new YangJarFile(iPath, this)); } } catch (IOException e) { YangCorePlugin.log(e); } } info.setChildren(result.toArray(new IOpenable[result.size()])); return javaProject.isOpen(); }
From source file:com.ecfeed.ui.common.EclipseLoaderProvider.java
License:Open Source License
public ModelClassLoader getLoader(boolean create, ClassLoader parent) { if ((fLoader == null) || create) { List<URL> urls = new ArrayList<URL>(); try {/*w w w . jav a 2 s.c o m*/ IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); for (IProject project : projects) { if (project.isOpen() && project.hasNature(JavaCore.NATURE_ID)) { IJavaProject javaProject = JavaCore.create(project); IPath path = project.getLocation() .append(javaProject.getOutputLocation().removeFirstSegments(1)); urls.add(new URL("file", null, path.toOSString() + "/")); IClasspathEntry table[] = javaProject.getResolvedClasspath(true); for (int i = 0; i < table.length; ++i) { if (table[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) { urls.add(new URL("file", null, table[i].getPath().toOSString())); path = project.getLocation(); path = path.append(table[i].getPath().removeFirstSegments(1)); urls.add(new URL("file", null, path.toOSString())); } } } } if (fLoader != null) { fLoader.close(); } } catch (Throwable e) { } fLoader = new ModelClassLoader(urls.toArray(new URL[] {}), parent); } return fLoader; }
From source file:com.github.ko2ic.plugin.eclipse.taggen.core.service.WorkspaceClassLoader.java
License:Open Source License
private Set<URL> createUrls(IJavaProject javaProject) throws CoreException, MalformedURLException { Set<URL> urlList = new HashSet<>(); IClasspathEntry[] classpathEntries = javaProject.getResolvedClasspath(true); for (IClasspathEntry entry : classpathEntries) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath path = entry.getOutputLocation(); if (path != null) { IPath outputPath = javaProject.getOutputLocation().removeFirstSegments(1); IPath outputFullPath = javaProject.getProject().getFolder(outputPath).getLocation(); outputFullPath.append(System.getProperty("line.separator")); URL url = outputFullPath.toFile().toURI().toURL(); urlList.add(url);//from www. ja va 2 s . co m } } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { URL url = entry.getPath().toFile().toURI().toURL(); urlList.add(url); } } return urlList; }
From source file:com.google.gdt.eclipse.core.projects.ProjectChangeTimestampTracker.java
License:Open Source License
private static boolean isResourceInAnOutputPath(IResource resource) throws JavaModelException { IProject project = resource.getProject(); IJavaProject javaProject = JavaCore.create(project); if (javaProject != null) { IPath resourcePath = resource.getFullPath(); if (WebAppUtilities.isWebApp(project)) { if (WebAppUtilities.hasManagedWarOut(project) && WebAppUtilities.getManagedWarOut(project).getFullPath().isPrefixOf(resourcePath)) { return true; }//from w w w .j a v a 2s .c om IPath previousWarOutAbsPath = WebAppProjectProperties.getLastUsedWarOutLocation(project); if (previousWarOutAbsPath != null && previousWarOutAbsPath.isPrefixOf(resource.getLocation())) { return true; } } if (javaProject.getOutputLocation().isPrefixOf(resourcePath)) { return true; } IClasspathEntry[] resolvedClasspath = javaProject.getResolvedClasspath(false); for (IClasspathEntry classpathEntry : resolvedClasspath) { IPath outputLocation = classpathEntry.getOutputLocation(); if (outputLocation != null && outputLocation.isPrefixOf(resourcePath)) { return true; } } } return false; }
From source file:com.google.gwt.eclipse.core.speedtracer.ViewSourceServlet.java
License:Open Source License
private IPackageFragmentRoot getPackageFragmentRoot(String jarPathString, String preferredProjectName) throws IOException { try {//from w w w.jav a 2s . co m IFile jarIFile = getFile(jarPathString); // The JAR is in the workspace return JavaCore.createJarPackageFragmentRootFrom(jarIFile); } catch (IOException e) { // JAR must not be in the workspace (or is not a file), continue.. } File jarFile = new File(jarPathString); // Iterate projects to find the external JAR IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); List<IProject> projects = new ArrayList<IProject>(Arrays.asList(root.getProjects())); IProject preferredProject = preferredProjectName != null ? root.getProject(preferredProjectName) : null; if (preferredProject != null && preferredProject.exists()) { // Search the preferred project first projects.remove(preferredProject); projects.add(0, preferredProject); } for (IProject project : projects) { IJavaProject javaProject = JavaCore.create(project); if (!javaProject.exists()) { continue; } try { IClasspathEntry[] classpathEntries = javaProject.getResolvedClasspath(true); for (IClasspathEntry classpathEntry : classpathEntries) { IPath path = classpathEntry.getPath(); if (jarFile.equals(path.toFile())) { return javaProject.getPackageFragmentRoot(path.toOSString()); } } } catch (JavaModelException e) { GWTPluginLog.logWarning(e, "Could not check " + project.getName() + " for JAR file"); continue; } } return null; }