List of usage examples for org.eclipse.jdt.core IClasspathEntry getOutputLocation
IPath getOutputLocation();
.class
files generated for this source entry (entry kind #CPE_SOURCE ). From source file:org.eclipse.pde.api.tools.internal.model.ProjectComponent.java
License:Open Source License
/** * Finds and returns an {@link IApiTypeContainer} for the specified source * folder, or <code>null</code> if it does not exist. If the source folder * shares an output location with a previous source folder, the output * location is shared (a new one is not created). * //from ww w . j a v a 2 s. c o m * @param location project relative path to the source folder * @return {@link IApiTypeContainer} or <code>null</code> */ private IApiTypeContainer getApiTypeContainer(String location, IApiComponent component) throws CoreException { if (this.fOutputLocationToContainer == null) { baselineDisposed(getBaseline()); } IResource res = fProject.getProject().findMember(new Path(location)); if (res != null) { IPackageFragmentRoot root = fProject.getPackageFragmentRoot(res); if (root.exists()) { if (root.getKind() == IPackageFragmentRoot.K_BINARY) { if (res.getType() == IResource.FOLDER) { // class file folder IPath location2 = res.getLocation(); IApiTypeContainer cfc = fOutputLocationToContainer.get(location2); if (cfc == null) { cfc = new ProjectTypeContainer(component, (IContainer) res); fOutputLocationToContainer.put(location2, cfc); } return cfc; } } else { IClasspathEntry entry = root.getRawClasspathEntry(); IPath outputLocation = entry.getOutputLocation(); if (outputLocation == null) { outputLocation = fProject.getOutputLocation(); } IApiTypeContainer cfc = fOutputLocationToContainer.get(outputLocation); if (cfc == null) { IPath projectFullPath = fProject.getProject().getFullPath(); IContainer container = null; if (projectFullPath.equals(outputLocation)) { // The project is its own output location container = fProject.getProject(); } else { container = fProject.getProject().getWorkspace().getRoot().getFolder(outputLocation); } cfc = new ProjectTypeContainer(component, container); fOutputLocationToContainer.put(outputLocation, cfc); } return cfc; } } } return null; }
From source file:org.eclipse.pde.internal.ui.editor.build.RuntimeInfoSection.java
License:Open Source License
private void refreshOutputKeys() { if (!isJavaProject()) return;//from w ww . j av a2s .c om IBuildEntry buildEntry = getLibrarySelection(); if (buildEntry == null) return; Set<String> outputFolders = new HashSet<String>(); String[] jarFolders = buildEntry.getTokens(); IPackageFragmentRoot[] sourceFolders = computeSourceFolders(); for (int j = 0; j < jarFolders.length; j++) { IPackageFragmentRoot sourceFolder = getSourceFolder(jarFolders[j], sourceFolders); if (sourceFolder != null) { try { IClasspathEntry entry = sourceFolder.getRawClasspathEntry(); IPath outputPath = entry.getOutputLocation(); if (outputPath == null) { outputFolders.add("bin"); //$NON-NLS-1$ } else { outputPath = outputPath.removeFirstSegments(1); outputFolders.add(outputPath.toString()); } } catch (JavaModelException e) { PDEPlugin.logException(e); } } } if (outputFolders.size() != 0) { String libName = buildEntry.getName().substring(7); IBuildModel buildModel = getBuildModel(); IBuild build = buildModel.getBuild(); String outputName = PROPERTY_OUTPUT_PREFIX + libName; IBuildEntry outputEntry = build.getEntry(outputName); if (outputEntry == null) { outputEntry = buildModel.getFactory().createEntry(outputName); try { build.add(outputEntry); } catch (CoreException e) { PDEPlugin.logException(e); } } setOutputEntryTokens(outputFolders, outputEntry); } }
From source file:org.eclipse.pde.internal.ui.properties.SelfHostingPropertyPage.java
License:Open Source License
private String[] getOutputFolders() { IProject project = (IProject) getElement().getAdapter(IProject.class); ArrayList<String> list = new ArrayList<String>(); try {/* ww w.j ava 2 s.co m*/ if (project.hasNature(JavaCore.NATURE_ID)) { IJavaProject jProject = JavaCore.create(project); list.add(jProject.getOutputLocation().toString()); IClasspathEntry[] entries = jProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE && entry.getContentKind() == IPackageFragmentRoot.K_SOURCE) { IPath path = entry.getOutputLocation(); if (path != null) list.add(path.toString()); } } } } catch (JavaModelException e) { } catch (CoreException e) { } return list.toArray(new String[list.size()]); }
From source file:org.eclipse.qvt.declarative.execution.ui.launching.configuration.DeclarativeQVTMainTab.java
License:Open Source License
private static IFile getASTFile(IFile sourceFile) { IJavaProject javaProject = JavaCore.create(sourceFile.getProject()); IClasspathEntry srcContainer = null; IPath currentTransformationPath = sourceFile.getFullPath(); try {//from w ww.java 2 s.co m for (IClasspathEntry classpathEntry : javaProject.getRawClasspath()) { if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath classPathEntryPath = classpathEntry.getPath(); if (classPathEntryPath.isPrefixOf(currentTransformationPath)) { srcContainer = classpathEntry; } } } if (srcContainer != null) { IPath relativeTransformationPath = currentTransformationPath .removeFirstSegments(srcContainer.getPath().segmentCount()); IPath binPath = srcContainer.getOutputLocation(); IPath ASTPath = binPath.append(relativeTransformationPath).removeFileExtension() .addFileExtension("eqvtrelation"); IFile ASTFile = getWorkspaceRoot().getFile(ASTPath); return ASTFile; } } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:org.eclipse.qvt.declarative.execution.ui.launching.configuration.DeclarativeQVTMainTab.java
License:Open Source License
private String getTraceabilityMM(String absoluteExecutablePath) { IPath path = new Path(absoluteExecutablePath); String projectName = path.segment(0); IProject project = getWorkspaceRoot().getProject(projectName); try {/*from w w w . ja v a2 s .c o m*/ for (IClasspathEntry classpathEntry : JavaCore.create(project).getRawClasspath()) { if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath sourcePath = classpathEntry.getPath(); if (sourcePath.isPrefixOf(path)) { IPath sourceFolderRelativePath = path.makeRelativeTo(sourcePath); String traceabilityMetamodelFileName = "T" + sourceFolderRelativePath.removeFileExtension().lastSegment() + ".ecore"; IPath result = classpathEntry.getOutputLocation(); result = result.append(sourceFolderRelativePath.removeLastSegments(1)); result = result.append(traceabilityMetamodelFileName); return URI.createPlatformResourceURI(result.toString(), true).toString(); } } } } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:org.eclipse.qvt.declarative.relations.atlvm.ATLVMExecutor.java
License:Open Source License
private static IFile getExecutableFile(IFile sourceFile, String direction) { IJavaProject javaProject = JavaCore.create(sourceFile.getProject()); IClasspathEntry srcContainer = null; IPath currentTransformationPath = sourceFile.getFullPath(); try {//from w w w .j a v a2 s . c om for (IClasspathEntry classpathEntry : javaProject.getRawClasspath()) { if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath classPathEntryPath = classpathEntry.getPath(); if (classPathEntryPath.isPrefixOf(currentTransformationPath)) { srcContainer = classpathEntry; } } } IPath relativeTransformationPath = currentTransformationPath .removeFirstSegments(srcContainer.getPath().segmentCount()); IPath binPath = srcContainer.getOutputLocation(); IPath relativeExecutablePath = binPath.append(relativeTransformationPath).removeFileExtension() .addFileExtension(direction).addFileExtension("asm"); IFile executableFile = ResourcesPlugin.getWorkspace().getRoot().getFile(relativeExecutablePath); return executableFile; } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:org.eclipse.sirius.editor.utils.WorkspaceClassLoading.java
License:Open Source License
private void computeURLs(IProject project, List<URL> uRLs) { final IJavaProject javaProject = JavaCore.create(project); try {//from ww w . ja v a2 s.c o m for (IClasspathEntry entry : javaProject.getResolvedClasspath(true)) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { final IPath output = entry.getOutputLocation(); if (output != null) { IFile reference = ResourcesPlugin.getWorkspace().getRoot().getFile(output); if (reference.exists()) { URL url; try { url = reference.getLocation().toFile().toURI().toURL(); uRLs.add(url); } catch (MalformedURLException e) { /* * We don't know how to handle this class path * entry. */ } } } } } /* * Add the default output location to the classpath anyway since * source folders are not required to have their own */ final IPath output = javaProject.getOutputLocation(); if (output != null) { IFolder reference = ResourcesPlugin.getWorkspace().getRoot().getFolder(output); if (reference.exists() && reference.getLocation() != null) { URL url; File file = reference.getLocation().toFile(); try { if (file != null && file.exists()) { url = file.toURI().toURL(); uRLs.add(url); } } catch (MalformedURLException e) { /* * the given path does not map to a file which can * actually be mapped to an url, ignore it. */ } } } } catch (JavaModelException e) { } }
From source file:org.eclipse.virgo.ide.bundlor.internal.core.BundlorProjectBuilder.java
License:Open Source License
private void doGetAffectedResources(IResource resource, int kind, int deltaKind) throws CoreException { IJavaProject project = JavaCore.create(getProject()); if (project == null) { return;/*from ww w. j a v a 2 s . com*/ } IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); // Get the source folders Set<IClasspathEntry> classpathEntries = ServerModuleDelegate .getSourceClasspathEntries(resource.getProject(), false); Set<IClasspathEntry> testClasspathEntries = ServerModuleDelegate .getSourceClasspathEntries(resource.getProject(), true); // Java source files if (!this.scanByteCode && resource.getName().endsWith("java")) { //$NON-NLS-1$ IJavaElement element = JavaCore.create(resource); if (element != null && element.getJavaProject().isOnClasspath(element)) { IPackageFragmentRoot root = (IPackageFragmentRoot) element .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); try { IClasspathEntry classpathEntry = root.getRawClasspathEntry(); for (IClasspathEntry entry : classpathEntries) { if (classpathEntry.equals(entry)) { if (deltaKind == IResourceDelta.REMOVED) { this.deletedSourceResources.add(resource); } else { this.sourceResources.add(resource); } break; } } for (IClasspathEntry entry : testClasspathEntries) { if (classpathEntry.equals(entry)) { if (deltaKind == IResourceDelta.REMOVED) { this.deletedTestResources.add(resource); } else { this.testResources.add(resource); } break; } } } catch (JavaModelException e) { // This can happen in case of .java resources not on the // classpath of the project } } } // Java byte code else if (this.scanByteCode && resource.getName().endsWith(CLASS_FILE_EXTENSION)) { IPath classFilePath = resource.getFullPath(); // Check default output folders IPath defaultOutputLocation = project.getOutputLocation(); if (defaultOutputLocation.isPrefixOf(classFilePath)) { // Ok we know that the file is a class in the default output // location; let's get the class name String className = classFilePath.removeFirstSegments(defaultOutputLocation.segmentCount()) .toString(); className = className.substring(0, className.length() - CLASS_FILE_EXTENSION.length()); int ix = className.indexOf('$'); if (ix > 0) { className = className.substring(0, ix); } className = className + ".java"; if (deltaKind == IResourceDelta.REMOVED) { this.deletedSourceResources.add(resource); this.deletedTestResources.add(resource); } else { for (IClasspathEntry entry : classpathEntries) { IPath sourceLocation = entry.getPath(); IResource sourceFolder = wsRoot.findMember(sourceLocation); if (sourceFolder instanceof IFolder) { if (((IFolder) sourceFolder).findMember(className) != null) { this.sourceResources.add(resource); break; } } } for (IClasspathEntry entry : testClasspathEntries) { IPath sourceLocation = entry.getPath(); IResource sourceFolder = wsRoot.findMember(sourceLocation); if (sourceFolder instanceof IFolder) { if (((IFolder) sourceFolder).findMember(className) != null) { this.testResources.add(resource); break; } } } } } // Check output folders of source folders for (IClasspathEntry entry : classpathEntries) { IPath outputLocation = entry.getOutputLocation(); if (outputLocation != null && outputLocation.isPrefixOf(classFilePath)) { if (deltaKind == IResourceDelta.REMOVED) { this.deletedSourceResources.add(resource); } else { this.sourceResources.add(resource); } break; } } // Check output folders for test source folders for (IClasspathEntry entry : testClasspathEntries) { IPath outputLocation = entry.getOutputLocation(); if (outputLocation != null && outputLocation.isPrefixOf(classFilePath)) { if (deltaKind == IResourceDelta.REMOVED) { this.deletedTestResources.add(resource); } else { this.testResources.add(resource); } break; } } } // Some template or actual manifest file (whether or not it actually // affects packaged build) has changed. Note that this is different // behavior than // pre-Virgo server. Still, it seems reasonably conservative as worst // case we'll be re-building the project when we really don't need to, // and best case we'll catch an edge case that we would have otherwise // missed. else if (resource.getName().equals("template.mf") || resource.getName().equals("MANIFEST.MF")) { this.forceFullBuild = true; } // Hibernate mapping files else if (resource.getName().endsWith(".hbm")) { addResourceIfInSourceFolder(resource, classpathEntries, testClasspathEntries); } // JPA persistence descriptor else if (resource.getName().equals("persistence.xml") && resource.getParent() != null && resource.getParent().getName().equals("META-INF")) { addResourceIfInSourceFolder(resource, classpathEntries, testClasspathEntries); } else if (isWebXML(resource)) { this.sourceResources.add(resource); } // Spring configuration file else if (resource.getName().endsWith(".xml")) { addResourceIfInSourceFolder(resource, classpathEntries, testClasspathEntries); } }
From source file:org.eclipse.virgo.ide.bundlor.internal.core.BundlorProjectBuilder.java
License:Open Source License
/** * Returns the source folders of the given {@link IJavaProject}. *///from w w w. j a v a 2s. c o m private Set<String> getSourceFolders(IJavaProject javaProject, IWorkspaceRoot root, boolean testFolders) throws JavaModelException { Set<String> folders = new HashSet<String>(); for (IClasspathEntry entry : ServerModuleDelegate.getSourceClasspathEntries(getProject(), testFolders)) { IResource sourceFolder = root.findMember(entry.getPath()); if (sourceFolder instanceof IFolder && !(sourceFolder instanceof IWorkspaceRoot)) { folders.add(((IFolder) sourceFolder).getRawLocation().toString()); } if (this.scanByteCode && entry.getOutputLocation() != null) { IResource classFolder = root.findMember(entry.getOutputLocation()); if (classFolder instanceof IFolder && !(classFolder instanceof IWorkspaceRoot)) { folders.add(((IFolder) classFolder).getRawLocation().toString()); } } } if (this.scanByteCode) { IResource sourceFolder = root.findMember(javaProject.getOutputLocation()); if (sourceFolder instanceof IFolder && !(sourceFolder instanceof IWorkspaceRoot)) { folders.add(((IFolder) sourceFolder).getRawLocation().toString()); } } // Add parent folder of web.xml if (!testFolders && FacetUtils.hasProjectFacet(getProject(), FacetCorePlugin.WEB_FACET_ID)) { // We're really cheating a bit here, as we aren't handling the case // where the user has multiple WEB-INF dirs, but that seems like an // edge case. IResource resource = getProject().findMember(WEB_XML_PATH); if (resource != null) { folders.add(resource.getRawLocation().removeLastSegments(2).toString()); } } return folders; }
From source file:org.eclipse.virgo.ide.export.BundleExportUtils.java
License:Open Source License
/** * Find manifest file given a java project * * @param project//from w w w.j av a 2s.c o m * @return */ public static IResource getOutputManifestFile(IJavaProject project) { try { Set<IPath> outputPaths = new HashSet<IPath>(); outputPaths.add(project.getOutputLocation()); IPackageFragmentRoot[] roots = project.getPackageFragmentRoots(); for (IPackageFragmentRoot root : roots) { if (root != null) { IClasspathEntry cpEntry = root.getRawClasspathEntry(); if (cpEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath location = cpEntry.getOutputLocation(); if (location != null) { outputPaths.add(location); } } } } for (IPath outputPath : outputPaths) { IResource manifest = getManifestFile(outputPath, project.getProject()); if (manifest != null) { return manifest; } } } catch (JavaModelException e) { // No error handling existed before. Are these expected?! throw new RuntimeException(e); } catch (MalformedURLException e) { // No error handling existed before. Are these expected?! throw new RuntimeException(e); } return null; }