List of usage examples for org.eclipse.jdt.core IJavaProject getRequiredProjectNames
String[] getRequiredProjectNames() throws JavaModelException;
From source file:com.android.ide.eclipse.adt.internal.project.ProjectHelper.java
License:Open Source License
/** * Find the list of projects on which this JavaProject is dependent on at the compilation level. * * @param javaProject Java project that we are looking for the dependencies. * @return A list of Java projects for which javaProject depend on. * @throws JavaModelException//from ww w . j a v a2 s . c o m */ public static List<IJavaProject> getAndroidProjectDependencies(IJavaProject javaProject) throws JavaModelException { String[] requiredProjectNames = javaProject.getRequiredProjectNames(); // Go from java project name to JavaProject name IJavaModel javaModel = javaProject.getJavaModel(); // loop through all dependent projects and keep only those that are Android projects List<IJavaProject> projectList = new ArrayList<IJavaProject>(requiredProjectNames.length); for (String javaProjectName : requiredProjectNames) { IJavaProject androidJavaProject = javaModel.getJavaProject(javaProjectName); //Verify that the project has also the Android Nature try { if (!androidJavaProject.getProject().hasNature(AdtConstants.NATURE_DEFAULT)) { continue; } } catch (CoreException e) { continue; } projectList.add(androidJavaProject); } return projectList; }
From source file:com.android.ide.eclipse.adt.project.ProjectHelper.java
License:Open Source License
/** * Find the list of projects on which this JavaProject is dependent on at the compilation level. * //w ww .j ava2 s. c o m * @param javaProject Java project that we are looking for the dependencies. * @return A list of Java projects for which javaProject depend on. * @throws JavaModelException */ public static List<IJavaProject> getAndroidProjectDependencies(IJavaProject javaProject) throws JavaModelException { String[] requiredProjectNames = javaProject.getRequiredProjectNames(); // Go from java project name to JavaProject name IJavaModel javaModel = javaProject.getJavaModel(); // loop through all dependent projects and keep only those that are Android projects List<IJavaProject> projectList = new ArrayList<IJavaProject>(requiredProjectNames.length); for (String javaProjectName : requiredProjectNames) { IJavaProject androidJavaProject = javaModel.getJavaProject(javaProjectName); //Verify that the project has also the Android Nature try { if (!androidJavaProject.getProject().hasNature(AndroidConstants.NATURE)) { continue; } } catch (CoreException e) { continue; } projectList.add(androidJavaProject); } return projectList; }
From source file:com.cisco.yangide.core.indexing.IndexAllProject.java
License:Open Source License
@Override public boolean execute(IProgressMonitor progressMonitor) { System.err.println("[I] Project: " + project.getName()); if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) { return true; }/*from w w w . j a v a 2 s .co m*/ if (!this.project.isAccessible()) { return true; } final HashSet<IPath> ignoredPath = new HashSet<IPath>(); final HashSet<IPath> externalJarsPath = new HashSet<IPath>(); try { JavaProject proj = (JavaProject) JavaCore.create(project); final HashSet<String> projectScope = new HashSet<>(); projectScope.add(project.getName()); if (proj != null) { IClasspathEntry[] classpath = proj.getResolvedClasspath(); for (int i = 0, length = classpath.length; i < length; i++) { IClasspathEntry entry = classpath[i]; IPath entryPath = entry.getPath(); IPath output = entry.getOutputLocation(); if (output != null && !entryPath.equals(output)) { ignoredPath.add(output); } // index dependencies projects if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { IProject prj = ResourcesPlugin.getWorkspace().getRoot() .getProject(entry.getPath().lastSegment()); if (prj != null && prj.exists()) { this.manager.indexAll(prj); projectScope.add(prj.getName()); } } } IPackageFragmentRoot[] roots = proj.getAllPackageFragmentRoots(); for (int i = 0, length = roots.length; i < length; i++) { IPath entryPath = roots[i].getPath(); if (entryPath != null && entryPath.toFile().exists() && entryPath.lastSegment().toLowerCase().endsWith(".jar")) { externalJarsPath.add(entryPath); } } // Update project information with set of project dependencies YangProjectInfo yangProjectInfo = (YangProjectInfo) YangCorePlugin.create(project) .getElementInfo(null); yangProjectInfo.setProjectScope(projectScope); // fill indirect scope HashSet<String> indirectScope = new HashSet<String>(); indirectScope.add(project.getName()); for (IJavaProject jproj : JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()) .getJavaProjects()) { if (jproj != proj) { for (String name : jproj.getRequiredProjectNames()) { if (name.equals(project.getName())) { indirectScope.add(jproj.getProject().getName()); } } } } yangProjectInfo.setIndirectScope(indirectScope); } } catch (JavaModelException | YangModelException e) { // java project doesn't exist: ignore } for (IPath iPath : externalJarsPath) { try (JarFile jarFile = new JarFile(iPath.toFile())) { ZipEntry entry = jarFile.getEntry("META-INF/yang/"); if (entry != null) { this.manager.addJarFile(project, iPath); } } catch (IOException e) { YangCorePlugin.log(e); } } try { final HashSet<IFile> indexedFiles = new HashSet<IFile>(); project.accept(new IResourceProxyVisitor() { @Override public boolean visit(IResourceProxy proxy) { if (IndexAllProject.this.isCancelled) { return false; } if (!ignoredPath.isEmpty() && ignoredPath.contains(proxy.requestFullPath())) { return false; } if (proxy.getType() == IResource.FILE) { if (CoreUtil.isYangLikeFileName(proxy.getName())) { IFile file = (IFile) proxy.requestResource(); indexedFiles.add(file); } return false; } return true; } }, IResource.NONE); for (IFile iFile : indexedFiles) { this.manager.addSource(iFile); } } catch (CoreException e) { this.manager.removeIndexFamily(project); return false; } return true; }
From source file:com.ebmwebsourcing.petals.common.internal.provisional.utils.JavaUtils.java
License:Open Source License
/** * Get the referenced projects from a Java project. * <p>The result includes the argument project.</p> * * @param javaProject/*from w ww . j av a 2 s . c o m*/ * @return */ public static List<IJavaProject> getJavaProjectDependencies(IJavaProject javaProject) { if (javaProject == null) return Collections.emptyList(); List<IJavaProject> result = new ArrayList<IJavaProject>(); result.add(javaProject); String[] projectNames; try { projectNames = javaProject.getRequiredProjectNames(); } catch (JavaModelException e1) { PetalsCommonPlugin.log(e1, IStatus.WARNING); projectNames = new String[0]; } for (String projectName : projectNames) { IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); try { if (!project.exists() || !project.isOpen() || !project.hasNature(JavaCore.NATURE_ID)) continue; } catch (CoreException e) { PetalsCommonPlugin.log(e, IStatus.ERROR); continue; } IJavaProject p = JavaCore.create(project); result.add(p); } return result; }
From source file:com.google.gdt.eclipse.core.JavaProjectUtilities.java
License:Open Source License
private static void fillTransitivelyRequiredProjects(IJavaProject javaProject, List<? super IJavaProject> requiredProjects) throws JavaModelException { if (requiredProjects.contains(javaProject)) { return;//from w w w. j av a2 s. c o m } requiredProjects.add(javaProject); for (String projectName : javaProject.getRequiredProjectNames()) { IJavaProject curJavaProject = JavaProjectUtilities.findJavaProject(projectName); if (curJavaProject == null) { continue; } fillTransitivelyRequiredProjects(curJavaProject, requiredProjects); } }
From source file:com.technophobia.substeps.junit.action.OpenEditorAction.java
License:Open Source License
private IType internalFindType(final IJavaProject project, final String testClassName, final Set<IJavaProject> visitedProjects, final IProgressMonitor monitor) throws JavaModelException { try {/*from ww w. j a va2 s .co m*/ if (visitedProjects.contains(project)) return null; monitor.beginTask("", 2); //$NON-NLS-1$ IType type = project.findType(testClassName, new SubProgressMonitor(monitor, 1)); if (type != null) return type; // fix for bug 87492: visit required projects explicitly to also // find not exported types visitedProjects.add(project); final IJavaModel javaModel = project.getJavaModel(); final String[] requiredProjectNames = project.getRequiredProjectNames(); final IProgressMonitor reqMonitor = new SubProgressMonitor(monitor, 1); reqMonitor.beginTask("", requiredProjectNames.length); //$NON-NLS-1$ for (final String requiredProjectName : requiredProjectNames) { final IJavaProject requiredProject = javaModel.getJavaProject(requiredProjectName); if (requiredProject.exists()) { type = internalFindType(requiredProject, testClassName, visitedProjects, new SubProgressMonitor(reqMonitor, 1)); if (type != null) return type; } } return null; } finally { monitor.done(); } }
From source file:de.devboost.eclipse.jdtutilities.ProjectUtility.java
License:Open Source License
private String[] getRequiredProjects(IProject project) { JDTUtility jdtUtility = new JDTUtility() { @Override/* w ww . jav a 2 s.c o m*/ protected void logWarning(String message, Exception e) { ProjectUtility.this.logWarning(message, e); } }; IJavaProject javaProject = jdtUtility.getJavaProject(project); if (javaProject != null) { try { String[] requiredProjectNames = javaProject.getRequiredProjectNames(); return requiredProjectNames; } catch (JavaModelException e) { logError("Exception while determining project dependencies.", e); } } return new String[0]; }
From source file:de.devboost.eclipse.jloop.LoopRunner.java
License:Open Source License
private Set<String> getRequiredProjects(IType type) { Set<String> requiredProjects; try {// w w w . j a v a 2 s. co m IJavaProject javaProject = type.getJavaProject(); List<String> projectNames = Arrays.asList(javaProject.getRequiredProjectNames()); requiredProjects = new LinkedHashSet<String>(projectNames); requiredProjects.add(javaProject.getProject().getName()); } catch (JavaModelException e) { JLoopPlugin.logError("Can't determine list of required projects.", e); return null; } return requiredProjects; }
From source file:edu.brown.cs.bubbles.bedrock.BedrockJava.java
License:Open Source License
private void addProjectElements(IJavaProject jp, Set<IJavaProject> done, List<IJavaElement> rslt) { if (done.contains(jp)) return;/*from w w w . j ava 2s.c om*/ done.add(jp); try { for (IPackageFragmentRoot pfr : jp.getPackageFragmentRoots()) { if (!pfr.isArchive() && !pfr.isExternal() && pfr.getKind() == IPackageFragmentRoot.K_SOURCE) { rslt.add(pfr); } } for (String pn : jp.getRequiredProjectNames()) { try { IJavaProject rjp = getJavaProject(pn); if (rjp != null) addProjectElements(rjp, done, rslt); } catch (BedrockException e) { } } } catch (JavaModelException e) { } }
From source file:fr.imag.exschema.Util.java
License:Open Source License
/** * Get the package fragments associated to the specified project and its * required projects./*from w w w . j a v a 2 s .c o m*/ * * @param project * @throws CoreException */ private static List<IPackageFragment> getPackageFragments(final IJavaProject project) throws CoreException { IProject requiredProject; String[] requiredProjects; IWorkspaceRoot workspaceRoot; List<IPackageFragment> returnValue; // Project fragments returnValue = new ArrayList<IPackageFragment>(); returnValue.addAll(Arrays.asList(project.getPackageFragments())); // Required projects fragments requiredProjects = project.getRequiredProjectNames(); if ((requiredProjects != null) && (requiredProjects.length > 0)) { workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); for (String currentProject : requiredProjects) { requiredProject = workspaceRoot.getProject(currentProject); if (requiredProject.hasNature(JavaCore.NATURE_ID)) { returnValue.addAll(Arrays.asList((JavaCore.create(requiredProject)).getPackageFragments())); } } } return returnValue; }