List of usage examples for org.eclipse.jdt.core IJavaProject getOutputLocation
IPath getOutputLocation() throws JavaModelException;
From source file:org.springframework.ide.eclipse.boot.properties.editor.StsConfigMetadataRepositoryJsonLoader.java
License:Open Source License
private void loadFromOutputFolder(IJavaProject project) { try {//w w w. j a v a 2 s .co m IPath outputLoc = project.getOutputLocation(); if (outputLoc != null) { IFolder outputFolder = ResourcesPlugin.getWorkspace().getRoot().getFolder(outputLoc); for (String mdLoc : META_DATA_LOCATIONS) { IFile mdf = outputFolder.getFile(new Path(mdLoc)); loadFromJsonFile(mdf); } } } catch (Exception e) { SpringPropertiesEditorPlugin.log(e); } }
From source file:org.springframework.ide.eclipse.boot.util.JavaProjectUtil.java
License:Open Source License
public static IFile getOutputFile(IJavaProject jp, IPath relativePath) { try {/*from ww w. j a v a2 s . c om*/ IPath loc = jp.getOutputLocation().append(relativePath); String pname = loc.segment(0); return ResourcesPlugin.getWorkspace().getRoot().getProject(pname).getFile(loc.removeFirstSegments(1)); } catch (Exception e) { BootActivator.log(e); } return null; }
From source file:org.springframework.ide.eclipse.core.java.JdtUtils.java
License:Open Source License
public static IResource getSourceResource(IResource classFile) { try {/*from w w w . j a v a2s. c o m*/ if (isJavaProject(classFile) && classFile.getName().endsWith(CLASS_FILE_EXTENSION)) { IPath classFilePath = classFile.getFullPath(); String classFileName = null; IJavaProject project = getJavaProject(classFile); IPath defaultOutput = project.getOutputLocation(); if (defaultOutput.isPrefixOf(classFilePath)) { classFileName = classFilePath.removeFirstSegments(defaultOutput.segmentCount()).toString(); } else { for (IClasspathEntry entry : project.getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath output = entry.getOutputLocation(); if (output != null) { if (classFilePath.isPrefixOf(output)) { classFileName = classFilePath.removeFirstSegments(output.segmentCount()) .toString(); } } } } } if (classFileName != null) { // Replace file extension String sourceFileName = classFileName.replace(".class", ".java"); for (IClasspathEntry entry : project.getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath path = entry.getPath().append(sourceFileName).removeFirstSegments(1); IResource resource = project.getProject().findMember(path); if (resource != null) { return resource; } } } } } } catch (JavaModelException e) { } return null; }
From source file:org.springframework.ide.eclipse.core.java.ProjectClassLoaderCache.java
License:Open Source License
/** * Add {@link URL}s to the given set of <code>paths</code>. *///from w w w . j ava 2 s . c o m private static void addClassPathUrls(IProject project, List<URL> paths, Set<IProject> resolvedProjects) { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); // add project to local cache to prevent adding its classpaths multiple times if (resolvedProjects.contains(project)) { return; } else { resolvedProjects.add(project); } try { if (JdtUtils.isJavaProject(project)) { IJavaProject jp = JavaCore.create(project); // configured classpath IClasspathEntry[] classpath = jp.getResolvedClasspath(true); // add class path entries for (int i = 0; i < classpath.length; i++) { IClasspathEntry path = classpath[i]; if (path.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath entryPath = path.getPath(); File file = entryPath.toFile(); if (file.exists()) { paths.add(file.toURI().toURL()); } else { // case for project relative links String projectName = entryPath.segment(0); IProject pathProject = root.getProject(projectName); covertPathToUrl(pathProject, paths, entryPath); } } else if (path.getEntryKind() == IClasspathEntry.CPE_SOURCE) { // add source path as well for non java resources IPath sourcePath = path.getPath(); covertPathToUrl(project, paths, sourcePath); // add source output locations for different source // folders IPath sourceOutputPath = path.getOutputLocation(); covertPathToUrl(project, paths, sourceOutputPath); } } // add all depending java projects for (IJavaProject p : JdtUtils.getAllDependingJavaProjects(jp)) { addClassPathUrls(p.getProject(), paths, resolvedProjects); } // get default output directory IPath outputPath = jp.getOutputLocation(); covertPathToUrl(project, paths, outputPath); } else { for (IProject p : project.getReferencedProjects()) { addClassPathUrls(p, paths, resolvedProjects); } } } catch (Exception e) { // ignore } }
From source file:org.springframework.ide.eclipse.core.java.TypeStructureCache.java
License:Open Source License
private static ClassFileReader getClassFileReaderForClassName(String className, IProject project) throws JavaModelException, MalformedURLException { IJavaProject jp = JavaCore.create(project); File outputDirectory = convertPathToFile(project, jp.getOutputLocation()); File classFile = new File(outputDirectory, ClassUtils.getClassFileName(className)); if (classFile.exists() && classFile.canRead()) { try {//from w ww . j av a 2s . c om return ClassFileReader.read(classFile); } catch (ClassFormatException e) { } catch (IOException e) { } } IClasspathEntry[] classpath = jp.getRawClasspath(); for (int i = 0; i < classpath.length; i++) { IClasspathEntry path = classpath[i]; if (path.getEntryKind() == IClasspathEntry.CPE_SOURCE) { outputDirectory = convertPathToFile(project, path.getOutputLocation()); classFile = new File(outputDirectory, ClassUtils.getClassFileName(className)); if (classFile.exists() && classFile.canRead()) { try { return ClassFileReader.read(classFile); } catch (ClassFormatException e) { } catch (IOException e) { } } } } return null; }
From source file:org.springframework.ide.eclipse.core.SpringCoreUtils.java
License:Open Source License
/** * Checks if the given {@link IResource} is a OSGi bundle manifest. * <p>/*from ww w . ja v a2 s. com*/ * Note: only the name and last segment of the folder name are checked. * @since 2.0.5 */ public static boolean isManifest(IResource resource) { // check if it is a MANIFEST.MF file in META-INF if (resource != null // && resource.isAccessible() && resource.getType() == IResource.FILE && resource.getName().equals(BUNDLE_MANIFEST_FILE) && resource.getParent() != null && resource.getParent().getProjectRelativePath() != null && resource.getParent().getProjectRelativePath().lastSegment() != null && resource.getParent().getProjectRelativePath().lastSegment().equals(BUNDLE_MANIFEST_FOLDER)) { // check if the manifest is not in an output folder IPath filePath = resource.getFullPath(); IJavaProject javaProject = JdtUtils.getJavaProject(resource); if (javaProject != null) { try { IPath defaultOutputLocation = javaProject.getOutputLocation(); if (defaultOutputLocation != null && defaultOutputLocation.isPrefixOf(filePath)) { return false; } for (IClasspathEntry entry : javaProject.getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath outputLocation = entry.getOutputLocation(); if (outputLocation != null && outputLocation.isPrefixOf(filePath)) { return false; } } } } catch (JavaModelException e) { // don't care here } return true; } else { // if the project is not a java project -> it is the manifest return true; } } return false; }
From source file:org.springframework.tooling.jdt.ls.commons.classpath.ClasspathUtil.java
License:Open Source License
private static CPE createSourceCPE(IJavaProject javaProject, IClasspathEntry entry) throws JavaModelException { IPath sourcePath = entry.getPath();//w w w.j a v a2 s . c om // log("source entry =" + sourcePath); IPath absoluteSourcePath = resolveWorkspacePath(sourcePath); // log("absoluteSourcePath =" + absoluteSourcePath); if (absoluteSourcePath != null) { IPath of = entry.getOutputLocation(); // log("outputFolder =" + of); IPath absoluteOutFolder; if (of != null) { absoluteOutFolder = resolveWorkspacePath(of); } else { absoluteOutFolder = resolveWorkspacePath(javaProject.getOutputLocation()); } return CPE.source(absoluteSourcePath.toFile(), absoluteOutFolder.toFile()); } return null; }
From source file:org.summer.dsl.ui.shared.JdtHelper.java
License:Open Source License
public boolean isFromOutputPath(IResource resource) { IProject project = resource.getProject(); IJavaProject javaProject = JavaCore.create(project); if (javaProject != null && javaProject.exists()) { try {/*w w w. ja va 2s .co m*/ IPath defaultOutputLocation = javaProject.getOutputLocation(); IPath resourcePath = resource.getFullPath(); if (defaultOutputLocation != null && !defaultOutputLocation.isEmpty() && defaultOutputLocation.isPrefixOf(resourcePath)) { return true; } IClasspathEntry[] classpathEntries = javaProject.getRawClasspath(); for (IClasspathEntry classpathEntry : classpathEntries) { if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath specializedOutputLocation = classpathEntry.getOutputLocation(); if (specializedOutputLocation != null) { if (!specializedOutputLocation.equals(classpathEntry.getPath()) && specializedOutputLocation.isPrefixOf(resourcePath)) { return true; } } } } } catch (CoreException e) { if (log.isDebugEnabled()) log.debug("Error in isJavaTargetFolder():" + e.getMessage(), e); } } return false; }
From source file:org.switchyard.tools.cxf.Activator.java
License:Open Source License
static ClassLoader getProjectBuildClassLoader(IJavaProject javaProject) throws Exception { IProject project = javaProject.getProject(); IWorkspaceRoot root = project.getWorkspace().getRoot(); List<URL> urls = new ArrayList<URL>(); urls.add(/* w w w.j a va 2 s. c o m*/ new File(project.getLocation() + "/" + javaProject.getOutputLocation().removeFirstSegments(1) + "/") //$NON-NLS-1$ //$NON-NLS-2$ .toURI().toURL()); for (IClasspathEntry classpathEntry : javaProject.getResolvedClasspath(true)) { if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IPath projectPath = classpathEntry.getPath(); IProject otherProject = root.getProject(projectPath.segment(0)); IJavaProject otherJavaProject = JavaCore.create(otherProject); urls.add(new File(otherProject.getLocation() + "/" //$NON-NLS-1$ + otherJavaProject.getOutputLocation().removeFirstSegments(1) + "/").toURI().toURL()); //$NON-NLS-1$ } else if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath path = classpathEntry.getPath(); if (!BLACKLIST.matcher(path.lastSegment()).find()) { urls.add(new File(path.toOSString()).toURI().toURL()); } } } return new URLClassLoader(urls.toArray(new URL[urls.size()]), Activator.class.getClassLoader()); }
From source file:org.switchyard.tools.cxf.Java2WSDLOperation.java
License:Open Source License
private ClassLoader getProjectBuildClassLoader(IType interfaceType) throws Exception { IJavaProject javaProject = interfaceType.getJavaProject(); IProject project = javaProject.getProject(); IWorkspaceRoot root = project.getWorkspace().getRoot(); List<URL> urls = new ArrayList<URL>(); urls.add(/*from w ww. jav a 2s . c o m*/ new File(project.getLocation() + "/" + javaProject.getOutputLocation().removeFirstSegments(1) + "/") .toURI().toURL()); for (IClasspathEntry classpathEntry : javaProject.getResolvedClasspath(true)) { if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IPath projectPath = classpathEntry.getPath(); IProject otherProject = root.getProject(projectPath.segment(0)); IJavaProject otherJavaProject = JavaCore.create(otherProject); urls.add(new File(otherProject.getLocation() + "/" + otherJavaProject.getOutputLocation().removeFirstSegments(1) + "/").toURI().toURL()); } else if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { urls.add(new File(classpathEntry.getPath().toOSString()).toURI().toURL()); } } return new URLClassLoader(urls.toArray(new URL[urls.size()]), getClass().getClassLoader()); }