List of usage examples for org.eclipse.jdt.core IJavaProject getPackageFragmentRoots
IPackageFragmentRoot[] getPackageFragmentRoots() throws JavaModelException;
From source file:com.google.gdt.eclipse.designer.util.DefaultModuleProvider.java
License:Open Source License
/** * @return all module files in given {@link IJavaProject}. *///from ww w .ja v a 2 s . c o m private static List<IFile> getModuleFiles(IJavaProject javaProject) throws Exception { List<IFile> moduleFiles = Lists.newArrayList(); for (IPackageFragmentRoot packageFragmentRoot : javaProject.getPackageFragmentRoots()) { // check only in source folders if (packageFragmentRoot.getKind() != IPackageFragmentRoot.K_SOURCE) { continue; } // check packages for (IJavaElement rootChild : packageFragmentRoot.getChildren()) { // check only packages if (rootChild instanceof IPackageFragment) { IPackageFragment pkg = (IPackageFragment) rootChild; for (Object object : pkg.getNonJavaResources()) { // check only files if (object instanceof IFile) { IFile file = (IFile) object; // check that file is GWT module file if (isModuleFile(file)) { moduleFiles.add(file); } } } } } } return moduleFiles; }
From source file:com.google.gdt.eclipse.designer.util.resources.DefaultResourcesProvider.java
License:Open Source License
/** * Appends source {@link IPackageFragmentRoot}'s, because {@link DefaultResourcesProvider} should * provide access not only to the binary resources (i.e. just resources in classpath), but also to * the source resources.// w w w. ja v a 2s. com */ private static void addSourceFolders(Set<IProject> visitedProjects, List<String> entries, IProject project) throws Exception { // may be not exists if (!project.exists()) { return; } // may be already visited if (visitedProjects.contains(project)) { return; } visitedProjects.add(project); // add source folders for IJavaProject { IJavaProject javaProject = JavaCore.create(project); if (javaProject.exists()) { for (IPackageFragmentRoot packageFragmentRoot : javaProject.getPackageFragmentRoots()) { if (packageFragmentRoot.getKind() == IPackageFragmentRoot.K_SOURCE) { entries.add(packageFragmentRoot.getResource().getLocation().toPortableString()); } } } } // process required projects for (IProject referencedProject : project.getReferencedProjects()) { addSourceFolders(visitedProjects, entries, referencedProject); } }
From source file:com.google.gwt.eclipse.core.clientbundle.ui.AddResourcesToClientBundleDialog.java
License:Open Source License
private void setPackageFragmentForTypeCompletion() { IPackageFragment pckgFragment = null; IJavaProject javaProject = getJavaProject(); if (javaProject != null) { try {// ww w .j ava 2 s. c o m IPackageFragmentRoot[] srcRoots = javaProject.getPackageFragmentRoots(); if (srcRoots.length > 0) { // Just use the default package of the first source root we find pckgFragment = srcRoots[0].getPackageFragment(""); } } catch (JavaModelException e) { GWTPluginLog.logError(e); } } resourceTypeCompletionProcessor.setPackageFragment(pckgFragment); }
From source file:com.google.gwt.eclipse.core.modules.ModuleUtils.java
License:Open Source License
/** * Scans the package fragments (including jars if includeJars is true) invoking the visitor * callback./*from w ww.j a v a 2 s .com*/ * * Stops if the callback returns a non-null result, and passes that result back to the caller. */ private static <T> T visitFragments(IJavaProject project, boolean includeJars, IPackageFragmentVisitor<T> visitor) { try { for (IPackageFragmentRoot pckgRoot : project.getPackageFragmentRoots()) { if (pckgRoot.isArchive() && !includeJars) { continue; } for (IJavaElement elem : pckgRoot.getChildren()) { T result = visitor.visit((IPackageFragment) elem); if (result != null) { return result; } } } } catch (JavaModelException e) { GWTPluginLog.logError(e); } return null; }
From source file:com.google.gwt.eclipse.devtoolsgen.actions.PopulateGwtDevTools.java
License:Open Source License
private static IFile findFileOnClasspath(IJavaProject javaProject, IPath classpathRelativePath) throws JavaModelException { for (IPackageFragmentRoot pckgFragmentRoot : javaProject.getPackageFragmentRoots()) { if (pckgFragmentRoot.isArchive()) { continue; }/* w ww. j a va 2 s . c om*/ IPath filepath = pckgFragmentRoot.getPath().append(classpathRelativePath); IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(filepath); if (res instanceof IFile) { return (IFile) res; } } return null; }
From source file:com.google.test.metric.eclipse.internal.util.JavaProjectHelper.java
License:Apache License
public List<String> getAllJavaPackages(IJavaProject javaProject) throws JavaModelException, CoreException { List<String> allJavaPackages = new ArrayList<String>(); IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots(); for (IPackageFragmentRoot root : roots) { if (!root.isArchive()) { IResource rootResource = root.getCorrespondingResource(); String rootURL = rootResource.getFullPath().toOSString(); rootResource.accept(new JavaPackageVisitor(allJavaPackages, rootURL), IContainer.NONE); }/*from ww w . j ava2 s . c om*/ } return allJavaPackages; }
From source file:com.google.test.metric.eclipse.internal.util.JavaProjectHelper.java
License:Apache License
public List<IPackageFragmentRoot> getAllJavaPackageFragmentRoots(IJavaProject javaProject) throws JavaModelException, CoreException { List<IPackageFragmentRoot> allJavaPackageFragmentRoot = new ArrayList<IPackageFragmentRoot>(); IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots(); for (IPackageFragmentRoot root : roots) { if (!root.isArchive() && !root.getElementName().equals("")) { allJavaPackageFragmentRoot.add(root); }//from w w w .j a v a 2s .c o m } return allJavaPackageFragmentRoot; }
From source file:com.google.test.metric.eclipse.ui.internal.TestabilityReportLaunchListener.java
License:Apache License
private void createMarkersFromClassIssues(List<ClassIssues> classIssues, IJavaProject javaProject) throws CoreException { javaProject.getProject().deleteMarkers(TestabilityConstants.TESTABILITY_COLLABORATOR_MARKER_TYPE, true, IResource.DEPTH_INFINITE);/*from w w w . j a v a 2s. co m*/ javaProject.getProject().deleteMarkers(TestabilityConstants.TESTABILITY_CONSTRUCTOR_MARKER_TYPE, true, IResource.DEPTH_INFINITE); javaProject.getProject().deleteMarkers(TestabilityConstants.TESTABILITY_DIRECT_COST_MARKER_TYPE, true, IResource.DEPTH_INFINITE); IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots(); List<IPath> sourceFolderPaths = new ArrayList<IPath>(); for (IPackageFragmentRoot root : roots) { if (!root.isArchive()) { IResource rootResource = root.getCorrespondingResource(); sourceFolderPaths.add(rootResource.getFullPath().removeFirstSegments(1)); } } for (ClassIssues classIssue : classIssues) { IResource resource = getAbsolutePathFromJavaFile(classIssue.getClassName(), sourceFolderPaths, javaProject.getProject()); if (resource != null) { for (Issue issue : classIssue.getMostImportantIssues()) { Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put(IMarker.SEVERITY, IMarker.SEVERITY_ERROR); attributes.put(IMarker.LINE_NUMBER, issue.getLocation().getLineNumber()); attributes.put(IMarker.MESSAGE, retriever.getSuggestion(issue.getType(), issue.getSubType())); IssueType issueType = issue.getType(); attributes.put(TestabilityConstants.ISSUE_TYPE, issue.getType().toString()); String markerType = null; if (IssueType.COLLABORATOR.equals(issueType)) { markerType = TestabilityConstants.TESTABILITY_COLLABORATOR_MARKER_TYPE; } else if (IssueType.CONSTRUCTION.equals(issueType)) { markerType = TestabilityConstants.TESTABILITY_CONSTRUCTOR_MARKER_TYPE; } else if (IssueType.DIRECT_COST.equals(issueType)) { markerType = TestabilityConstants.TESTABILITY_DIRECT_COST_MARKER_TYPE; } if (markerType != null) { MarkerUtilities.createMarker(resource, attributes, markerType); } } } else { logger.logException("No Resource found for Class : " + classIssue.getClassName(), null); } } }
From source file:com.ifedorenko.m2e.sourcelookup.internal.JavaProjectSources.java
License:Open Source License
private void addJavaProject(IJavaProject project) throws CoreException { if (project != null) { final Map<File, IPackageFragmentRoot> classpath = new LinkedHashMap<File, IPackageFragmentRoot>(); for (IPackageFragmentRoot fragment : project.getPackageFragmentRoots()) { if (fragment.getKind() == IPackageFragmentRoot.K_BINARY && fragment.getSourceAttachmentPath() != null) { File classpathLocation; if (fragment.isExternal()) { classpathLocation = fragment.getPath().toFile(); } else { classpathLocation = toFile(fragment.getPath()); }//from w ww .j av a 2 s. c o m if (classpathLocation != null) { classpath.put(classpathLocation, fragment); } } } final JavaProjectInfo projectInfo = new JavaProjectInfo(project, classpath); final Set<File> projectLocations = new HashSet<File>(); final String jarLocation = project.getProject().getPersistentProperty(BinaryProjectPlugin.QNAME_JAR); if (jarLocation != null) { // maven binary project projectLocations.add(new File(jarLocation)); } else { // regular project projectLocations.add(toFile(project.getOutputLocation())); for (IClasspathEntry cpe : project.getRawClasspath()) { if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) { projectLocations.add(toFile(cpe.getOutputLocation())); } } } synchronized (lock) { projects.put(project, projectLocations); for (File projectLocation : projectLocations) { locations.put(projectLocation, projectInfo); } } } }
From source file:com.iw.plugins.spindle.core.util.JarEntryFileUtil.java
License:Mozilla Public License
private static IPackageFragmentRoot getPackageFragmentRoot(IJavaProject project, IJarEntryResource entry, boolean includeOtherProjects) throws CoreException { String path = getJarPath(entry); IPackageFragmentRoot[] roots = includeOtherProjects ? project.getAllPackageFragmentRoots() : project.getPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) { if (roots[i] instanceof JarPackageFragmentRoot) if (((JarPackageFragmentRoot) roots[i]).getJar().getName().equals(path)) return roots[i]; }/*www .ja v a 2 s .co m*/ return null; }