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.gmt.mod.infra.common.core.internal.utils.FileUtils.java
License:Open Source License
/** * Whether the given workspace file is in its project's output location * (e.g. "bin" directory)//from ww w . j ava 2 s . c o m */ public static boolean isInOutputLocation(final IFile file) { try { IJavaProject javaProject = JavaCore.create(file.getProject()); if (javaProject != null) { if (javaProject.getOutputLocation().isPrefixOf(file.getFullPath())) { return true; } IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); for (IClasspathEntry classpathEntry : rawClasspath) { if (classpathEntry.getContentKind() == IPackageFragmentRoot.K_SOURCE) { IPath outputLocation = classpathEntry.getOutputLocation(); if (outputLocation != null && outputLocation.isPrefixOf(file.getFullPath())) { return true; } } } } } catch (JavaModelException e) { log.error(e.toString()); //FP } return false; }
From source file:org.eclipse.imp.smapifier.builder.SmapieBuilder.java
License:Open Source License
/** * @param origSrcFile the workspace-relative path to a source file in the top-level * language (from which Java source is generated) * @return the OS-specific-format filesystem-absolute path to the "main" corresponding .java file *///from w w w.j a v a 2s .co m private String getMainGeneratedFile(final IFile origSrcFile) { IWorkspaceRoot wsRoot = fProject.getWorkspace().getRoot(); final IPath wsRelativeFilePath = origSrcFile.getFullPath(); // First, try the same folder as the original src file -- the .java file might live there final IPath javaSrcPath = wsRelativeFilePath.removeFileExtension().addFileExtension("java"); final IFileStore fileStore = EFS.getLocalFileSystem() .getStore(wsRoot.getFile(javaSrcPath).getLocationURI()); if (fileStore.fetchInfo().exists()) { return javaSrcPath.toOSString(); } final IPath wsLocation = wsRoot.getRawLocation(); final IPath projRelJavaFilePath = wsRelativeFilePath.removeFirstSegments(1).removeFileExtension() .addFileExtension("java").makeAbsolute(); try { for (final IClasspathEntry cpEntry : fJavaProject.getRawClasspath()) { if (cpEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE && cpEntry.getPath().isPrefixOf(origSrcFile.getFullPath()) && !BuildPathUtils.isExcluded(origSrcFile.getFullPath(), cpEntry)) { // Skip if this source entry isn't the entry containing 'origSrcFile'. final IPath srcPath = cpEntry.getPath(); if (!srcPath.isPrefixOf(wsRelativeFilePath)) { continue; } // Now look in the output locations - the one for this classpath entry, if any, // or, failing that, the project's output location. final IPath outputLocation; if (cpEntry.getOutputLocation() == null) { outputLocation = fJavaProject.getOutputLocation(); } else { outputLocation = cpEntry.getOutputLocation(); } final int srcPathCount = srcPath.removeFirstSegments(1).segmentCount(); // discounting the project name final IPath generatedFilePath = wsLocation .append(outputLocation.append(projRelJavaFilePath.removeFirstSegments(srcPathCount))); final String generatedFilePathStr = generatedFilePath.toOSString(); if (new File(generatedFilePathStr).exists()) { return generatedFilePath.toOSString(); } } } } catch (CoreException e) { SMAPifierPlugin.getInstance().logException(e.getMessage(), e); } return null; }
From source file:org.eclipse.incquery.patternlanguage.emf.ui.builder.OldVersionHelper.java
License:Open Source License
private URI getCopiedURI(IProject project, IPath relativePath) throws JavaModelException { try {// ww w .j a v a 2 s.co m if (!copiedURIMap.containsKey(relativePath)) { IJavaProject javaProject = JavaCore.create(project); IClasspathEntry sourceEntry = Iterators.find( Iterators.forArray(javaProject.getResolvedClasspath(true)), new SourceFolderFinder(relativePath)); IPath outputLocation = sourceEntry.getOutputLocation(); if (outputLocation == null) { outputLocation = javaProject.getOutputLocation(); } IPath path = outputLocation.append(relativePath.makeRelativeTo(sourceEntry.getPath())); URI copiedURI = (project.getWorkspace().getRoot().findMember(path) != null) ? URI.createPlatformResourceURI(path.toString(), true) : null; if (copiedURI != null) { copiedURIMap.put(relativePath, copiedURI); } return copiedURI; } return copiedURIMap.get(relativePath); } catch (NoSuchElementException e) { return null; } }
From source file:org.eclipse.jdt.internal.core.JavaModelManager.java
License:Open Source License
/** * Returns whether the given full path (for a package) conflicts with the output location * of the given project.//from www . j a v a2 s .c o m */ public static boolean conflictsWithOutputLocation(IPath folderPath, JavaProject project) { try { IPath outputLocation = project.getOutputLocation(); if (outputLocation == null) { // in doubt, there is a conflict return true; } if (outputLocation.isPrefixOf(folderPath)) { // only allow nesting in project's output if there is a corresponding source folder // or if the project's output is not used (in other words, if all source folders have their custom output) IClasspathEntry[] classpath = project.getResolvedClasspath(); boolean isOutputUsed = false; for (int i = 0, length = classpath.length; i < length; i++) { IClasspathEntry entry = classpath[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (entry.getPath().equals(outputLocation)) { return false; } if (entry.getOutputLocation() == null) { isOutputUsed = true; } } } return isOutputUsed; } return false; } catch (JavaModelException e) { // in doubt, there is a conflict return true; } }
From source file:org.eclipse.jpt.common.core.internal.resource.SimpleJavaResourceLocator.java
License:Open Source License
protected boolean locationIsValid_(IProject project, IContainer container) throws JavaModelException { IJavaProject javaProject = this.getJavaProject(project); if (javaProject.isOnClasspath(container)) { return true; }//from ww w . j ava 2s . com Set<IPath> outputPaths = new LinkedHashSet<IPath>(); outputPaths.add(javaProject.getOutputLocation()); IClasspathEntry[] entries = javaProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE && entry.getOutputLocation() != null) { outputPaths.add(entry.getOutputLocation()); } } IPath containerPath = container.getFullPath(); for (IPath outputPath : outputPaths) { if (container.equals(project) && outputPath.isPrefixOf(containerPath)) { return true; } if (outputPath.isPrefixOf(containerPath)) { return false; } } for (Object resource : javaProject.getNonJavaResources()) { if (resource instanceof IFolder) { IFolder folder = (IFolder) resource; if (folder.getFullPath().isPrefixOf(containerPath)) { return true; } } } return false; }
From source file:org.eclipse.jst.common.jdt.internal.classpath.FlexibleProjectContainer.java
License:Open Source License
private boolean isSourceOrOutputDirectory(final IPath aPath) { if (isJavaProject(this.project)) { try {/*from w w w . j a va2s .c o m*/ final IJavaProject jproject = JavaCore.create(this.project); final IClasspathEntry[] cp = jproject.getRawClasspath(); for (int i = 0; i < cp.length; i++) { final IClasspathEntry cpe = cp[i]; if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) { final IPath src = cpe.getPath(); final IPath output = cpe.getOutputLocation(); if (src.equals(aPath) || output != null && output.equals(aPath)) { return true; } } } if (jproject.getOutputLocation().equals(aPath)) { return true; } } catch (JavaModelException e) { CommonFrameworksPlugin.log(e); } } return false; }
From source file:org.eclipse.jst.common.jdt.internal.javalite.JavaLiteUtilities.java
License:Open Source License
/** * Returns the Java output (i.e. where the compiled .class files go) * IContainer for the specified IClasspathEntry * /*from w w w. j a v a 2 s . c om*/ * @param javaProjectLite * @param entry * @return */ public static IContainer getJavaOutputContainer(IJavaProjectLite javaProjectLite, IClasspathEntry entry) { IProject project = javaProjectLite.getProject(); IPath outputPath = entry.getOutputLocation(); if (outputPath != null) { return project.getFolder(outputPath.removeFirstSegments(1)); } return getDefaultJavaOutputContainer(javaProjectLite); }
From source file:org.eclipse.jst.common.project.facet.core.internal.ClasspathUtil.java
License:Open Source License
private static IClasspathEntry setOwners(final IClasspathEntry cpe, final String owners) { final List<IClasspathAttribute> attrs = new ArrayList<IClasspathAttribute>(); for (IClasspathAttribute attr : cpe.getExtraAttributes()) { if (!attr.getName().equals(OWNER_PROJECT_FACETS_ATTR)) { attrs.add(attr);/*from ww w . ja va 2 s .co m*/ } } if (owners != null) { attrs.add(JavaCore.newClasspathAttribute(OWNER_PROJECT_FACETS_ATTR, owners)); } return new ClasspathEntry(cpe.getContentKind(), cpe.getEntryKind(), cpe.getPath(), cpe.getInclusionPatterns(), cpe.getExclusionPatterns(), cpe.getSourceAttachmentPath(), cpe.getSourceAttachmentRootPath(), cpe.getOutputLocation(), cpe.isExported(), cpe.getAccessRules(), cpe.combineAccessRules(), attrs.toArray(new IClasspathAttribute[attrs.size()])); }
From source file:org.eclipse.jst.common.project.facet.core.internal.JavaFacetUninstallDelegate.java
License:Open Source License
public void execute(final IProject project, final IProjectFacetVersion fv, final Object cfg, final IProgressMonitor monitor) throws CoreException { final RelevantFiles files = new RelevantFiles(project); validateEdit(files);//ww w. ja v a 2 s .co m // Find output directories. They will be removed later. final List<IPath> outputFolders = new ArrayList<IPath>(); try { final IJavaProject jproj = JavaCore.create(project); outputFolders.add(jproj.getOutputLocation()); for (IClasspathEntry cpe : jproj.getRawClasspath()) { outputFolders.add(cpe.getOutputLocation()); } } catch (Exception e) { // Ignore the exception since we tearing down and the user might be doing this // because the project is corrupted. } // Remove java nature. This will automatically remove the builder. final IProjectDescription desc = project.getDescription(); final List<String> natures = new ArrayList<String>(); for (String nature : desc.getNatureIds()) { if (!nature.equals(JavaCore.NATURE_ID)) { natures.add(nature); } } desc.setNatureIds(natures.toArray(new String[natures.size()])); project.setDescription(desc, null); // Delete various metadata files. files.dotClasspathFile.delete(true, null); files.jdtCorePrefsFile.delete(true, null); files.jstFacetCorePrefsFile.delete(true, null); // Delete all the output folders and their contents. final IWorkspace ws = ResourcesPlugin.getWorkspace(); for (IPath path : outputFolders) { if (path != null) { delete(ws.getRoot().getFolder(path)); } } }
From source file:org.eclipse.jst.j2ee.classpathdep.ClasspathDependencyUtil.java
License:Open Source License
public static IClasspathEntry modifyDependencyPath(IClasspathEntry entry, IPath dependencyPath) { IClasspathEntry newEntry = null;//w w w. j a va 2s .co m IClasspathAttribute[] newAttributes = modifyDependencyPath(entry.getExtraAttributes(), dependencyPath); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_CONTAINER: newEntry = JavaCore.newContainerEntry(entry.getPath(), entry.getAccessRules(), newAttributes, entry.isExported()); break; case IClasspathEntry.CPE_LIBRARY: newEntry = JavaCore.newLibraryEntry(entry.getPath(), entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), entry.getAccessRules(), newAttributes, entry.isExported()); break; case IClasspathEntry.CPE_VARIABLE: newEntry = JavaCore.newVariableEntry(entry.getPath(), entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), entry.getAccessRules(), newAttributes, entry.isExported()); break; case IClasspathEntry.CPE_PROJECT: newEntry = JavaCore.newProjectEntry(entry.getPath(), entry.getAccessRules(), entry.combineAccessRules(), newAttributes, entry.isExported()); break; case IClasspathEntry.CPE_SOURCE: newEntry = JavaCore.newSourceEntry(entry.getPath(), entry.getInclusionPatterns(), entry.getExclusionPatterns(), entry.getOutputLocation(), newAttributes); break; } return newEntry; }