List of usage examples for org.eclipse.jdt.core IJavaProject getOutputLocation
IPath getOutputLocation() throws JavaModelException;
From source file:org.eclipse.team.svn.resource.ignore.rules.jdt.JDTIgnoreRecommendations.java
License:Open Source License
public boolean isOutput(IResource resource) throws CoreException { IProject project = resource.getProject(); if (project == null) { return false; }/*from ww w . j ava 2s . c o m*/ IJavaProject javaProject = JavaCore.create(project); IPath output = javaProject.getOutputLocation(); // if this resource not in the output folder or the project itself is the output folder then no need to ignore it if (!output.isPrefixOf(resource.getFullPath()) || output.equals(project.getFullPath())) { return false; } if (!"bin".equals(output.lastSegment())) { //default folder name used in eclipse while creating project with separate source and binary folders IOpenable openable = javaProject.getOpenable(); if (openable.isOpen()) { // do not start any time consuming process IPackageFragmentRoot[] roots = JavaCore.create(project).getPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) { if (output.isPrefixOf(roots[i].getPath())) { return false; } } } } return true; }
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;/* w ww . j a va2 s . co m*/ } 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}. *///ww 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 a v a 2 s . 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; }
From source file:org.eclipse.virgo.ide.facet.core.FacetUtils.java
License:Open Source License
/** * Gets all the plan files found in the given project. * * @param project// w w w . j a va2 s. c o m * @return */ public static Collection<IFile> getPlansInPlanProject(IProject project) { if (!isPlanProject(project)) { return Collections.emptyList(); } final List<IFile> planFiles = new ArrayList<IFile>(); // Collect output locations if java project final Set<IPath> outputLocations = new HashSet<IPath>(); try { if (FacetUtils.hasNature(project, JavaCore.NATURE_ID)) { IJavaProject je = JavaCore.create(project); try { outputLocations.add(je.getOutputLocation()); for (IClasspathEntry entry : je.getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (entry.getOutputLocation() != null) { outputLocations.add(entry.getOutputLocation()); } } } } catch (JavaModelException e) { // safe to ignore } } project.accept(new IResourceVisitor() { public boolean visit(IResource resource) throws CoreException { if (resource.isTeamPrivateMember() || resource.isDerived()) { return false; } if (resource instanceof IFile && "plan".equals(resource.getFileExtension())) { planFiles.add((IFile) resource); } else if (resource instanceof IContainer) { IPath path = ((IContainer) resource).getFullPath(); for (IPath outputLocation : outputLocations) { if (outputLocation.isPrefixOf(path)) { return false; } } return true; } return true; } }); } catch (CoreException e) { // TODO CD log exception } return planFiles; }
From source file:org.eclipse.virgo.ide.module.core.ServerModuleDelegate.java
License:Open Source License
/** * Get all resources from project's output locations *//*from w w w . ja v a 2 s . c o m*/ private Set<IModuleResource> getMembers(IProject project, IPath moduleRelativePath) throws JavaModelException, CoreException { Set<IModuleResource> resources = new LinkedHashSet<IModuleResource>(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IJavaProject javaProject = JavaCore.create(project); // Add default output location IResource defaultBinFolder = root.findMember(javaProject.getOutputLocation()); if (defaultBinFolder instanceof IContainer) { resources.addAll(Arrays.asList(getModuleResources(moduleRelativePath, (IContainer) defaultBinFolder))); } // Add output for every source entry for (IClasspathEntry entry : getSourceClasspathEntries(project, false)) { IResource binFolder = root.findMember(entry.getOutputLocation()); if (binFolder instanceof IContainer && !(binFolder instanceof IWorkspaceRoot)) { resources.addAll( Arrays.asList(getModuleResources(moduleRelativePath, (IContainer) defaultBinFolder))); } } // Add Bundle-ClassPath entries BundleManifest manifest = BundleManifestCorePlugin.getBundleManifestManager() .getBundleManifest(javaProject); if (manifest != null) { List<String> bundleClassPathEntries = manifest.getBundleClasspath(); if (bundleClassPathEntries != null) { // remove the . for the class folder from the bundle classpath entries bundleClassPathEntries.remove("."); // get all resources that match the given Bundle-ClassPath header resources.addAll(Arrays.asList( getModuleResources(moduleRelativePath, javaProject.getProject(), bundleClassPathEntries))); } } return resources; }
From source file:org.eclipse.virgo.ide.module.core.ServerModuleFactoryDelegate.java
License:Open Source License
/** * {@inheritDoc}//w ww. j av a 2 s .c o m */ @Override protected IModule[] createModules(final IProject project) { final Set<IModule> modules = new HashSet<IModule>(); if (FacetUtils.isBundleProject(project)) { // Add module for bundle deployment modules.add(createModule(project.getName(), project.getName(), FacetCorePlugin.BUNDLE_FACET_ID, "1.0", project)); // Add module for par deployment for (IProject parProject : FacetUtils.getParProjects(project)) { modules.add(createModule(parProject.getName() + "$" + project.getName(), project.getName(), FacetCorePlugin.BUNDLE_FACET_ID, "1.0", project)); } } else if (FacetUtils.isParProject(project)) { modules.add(createModule(project.getName(), project.getName(), FacetCorePlugin.PAR_FACET_ID, "1.0", project)); } // Every project can also be a plan project if (FacetUtils.isPlanProject(project)) { // Collect output locations if java project final Set<IPath> outputLocations = new HashSet<IPath>(); if (JdtUtils.isJavaProject(project)) { IJavaProject je = JdtUtils.getJavaProject(project); try { outputLocations.add(je.getOutputLocation()); for (IClasspathEntry entry : je.getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (entry.getOutputLocation() != null) { outputLocations.add(entry.getOutputLocation()); } } } } catch (JavaModelException e) { } } try { project.accept(new IResourceVisitor() { public boolean visit(IResource resource) throws CoreException { if (resource instanceof IFile && resource.getName().endsWith(".plan")) { modules.add(createModule(resource.getFullPath().toString(), resource.getProject().getName() + "/" + resource.getProjectRelativePath().toString(), FacetCorePlugin.PLAN_FACET_ID, "2.0", project)); } else if (resource instanceof IContainer) { IPath path = ((IContainer) resource).getFullPath(); for (IPath outputLocation : outputLocations) { if (outputLocation.isPrefixOf(path)) { return false; } } return true; } return true; } }); } catch (CoreException e) { // TODO CD log exception } } return (IModule[]) modules.toArray(new IModule[modules.size()]); }
From source file:org.eclipse.virgo.ide.pde.core.internal.Helper.java
License:Open Source License
/** * Gets the output location of the project. Either returns the global output location or the first output location * found for a source folder.//from w w w.j a va 2 s .c om * * @return * @throws CoreException */ /* package */ static IPath getOutputLocation(IProject project) throws CoreException { IJavaProject jp = (IJavaProject) project.getNature(JavaCore.NATURE_ID); IPath outputLocation = jp.getOutputLocation(); if (outputLocation == null) { IClasspathEntry[] entries = jp.getRawClasspath(); for (IClasspathEntry iClasspathEntry : entries) { if (iClasspathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { outputLocation = iClasspathEntry.getOutputLocation(); if (outputLocation != null) { break; } } } } if (outputLocation == null) { throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, Messages.Helper_BinFolderError)); } return outputLocation; }
From source file:org.eclipse.vjet.eclipse.javalaunch.utils.EclipseResourceUtils.java
License:Open Source License
public static String getQualifiedClassName(IResource pResource) { String qualifiedClassName = null; IProject project = pResource.getProject(); try {// w ww. j av a2 s. c o m IJavaProject proj = JavaCore.create(project); String filePathName = pResource.getLocation().toString(); if (pResource.getFileExtension().toLowerCase().equals("class")) { String outputPath = proj.getOutputLocation().toString(); String projectPath = project.getLocation().toString(); outputPath = projectPath + outputPath.substring(project.getName().length()); qualifiedClassName = filePathName.substring(outputPath.length(), filePathName.length() - 6); return qualifiedClassName = qualifiedClassName.replace('/', '.'); } IPath resourcePath = EclipseResourceUtils.getResourcePackagePath(pResource, proj); String resName = pResource.getName(); String resExtension = pResource.getFileExtension(); qualifiedClassName = resourcePath.toString(); qualifiedClassName = qualifiedClassName.replace('/', '.'); qualifiedClassName = qualifiedClassName + "." + resName.substring(0, resName.length() - (resExtension.length() + 1)); } catch (JavaModelException e) { e.printStackTrace(); } return qualifiedClassName; }
From source file:org.eclipse.wb.internal.core.utils.reflect.ProjectClassLoader.java
License:Open Source License
private static void addRuntimeClassPathEntries(List<String> entries, IJavaProject javaProject, Set<IJavaProject> visitedProjects, boolean fullClassPath) throws Exception { IProject project = javaProject.getProject(); // not Java project if (!javaProject.exists()) { // add its location for resources if (project.exists()) { String path = project.getLocation().toPortableString(); entries.add(path);//from www .j a va 2s.c o m } // done return; } // check for recursion if (visitedProjects.contains(javaProject)) { return; } visitedProjects.add(javaProject); // do add classpath entries if (fullClassPath) { CollectionUtils.addAll(entries, getClasspath(javaProject)); } else { IPath outputLocation = javaProject.getOutputLocation(); addAbsoluteLocation(entries, outputLocation); } // include fragments addFragments(entries, project, visitedProjects); }